Skip to content

Commit

Permalink
Make Churner work on v2 smart contracts (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored Jan 30, 2024
1 parent 0f83d13 commit 5e911e0
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions api/proto/churner/churner.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ message ChurnRequest {
// - If any of the quorum fails to register, this entire request will fail.
// The IDs must be in range [0, 255].
repeated uint32 quorum_ids = 5;
// The Ethereum address (in hex like "0x123abcdef...") of the operator.
string operator_address = 6;
}

message ChurnReply {
Expand Down
21 changes: 8 additions & 13 deletions churner/churner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
)

type ChurnRequest struct {
OperatorAddress gethcommon.Address
OperatorToRegisterPubkeyG1 *core.G1Point
OperatorToRegisterPubkeyG2 *core.G2Point
OperatorRequestSignature *core.Signature
Expand Down Expand Up @@ -78,14 +79,7 @@ func NewChurner(
}

func (c *churner) VerifyRequestSignature(ctx context.Context, churnRequest *ChurnRequest) (gethcommon.Address, error) {
operatorToRegisterAddress, err := c.Transactor.OperatorIDToAddress(ctx, churnRequest.OperatorToRegisterPubkeyG1.GetOperatorID())
if err != nil {
return gethcommon.Address{}, err
}
if operatorToRegisterAddress == gethcommon.HexToAddress(zeroAddressString) {
return gethcommon.Address{}, errors.New("operatorToRegisterPubkey is not registered with bls pubkey compendium")
}

operatorToRegisterAddress := churnRequest.OperatorAddress
isEqual, err := churnRequest.OperatorToRegisterPubkeyG1.VerifyEquivalence(churnRequest.OperatorToRegisterPubkeyG2)
if err != nil {
return gethcommon.Address{}, err
Expand Down Expand Up @@ -121,7 +115,7 @@ func (c *churner) ProcessChurnRequest(ctx context.Context, operatorToRegisterAdd
}
}

return c.createChurnResponse(ctx, operatorToRegisterId, operatorToRegisterAddress, churnRequest.QuorumIDs)
return c.createChurnResponse(ctx, operatorToRegisterAddress, operatorToRegisterId, churnRequest.QuorumIDs)
}

func (c *churner) UpdateQuorumCount(ctx context.Context) error {
Expand All @@ -142,8 +136,8 @@ func (c *churner) UpdateQuorumCount(ctx context.Context) error {

func (c *churner) createChurnResponse(
ctx context.Context,
operatorToRegisterId core.OperatorID,
operatorToRegisterAddress gethcommon.Address,
operatorToRegisterId core.OperatorID,
quorumIDs []core.QuorumID,
) (*ChurnResponse, error) {
currentBlockNumber, err := c.Transactor.GetCurrentBlockNumber(ctx)
Expand All @@ -163,7 +157,7 @@ func (c *churner) createChurnResponse(
return nil, err
}

signatureWithSaltAndExpiry, err := c.sign(ctx, operatorToRegisterId, operatorsToChurn)
signatureWithSaltAndExpiry, err := c.sign(ctx, operatorToRegisterAddress, operatorToRegisterId, operatorsToChurn)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -256,7 +250,7 @@ func (c *churner) getOperatorsToChurn(ctx context.Context, quorumIDs []uint8, op
return operatorsToChurn, nil
}

func (c *churner) sign(ctx context.Context, operatorToRegisterId core.OperatorID, operatorsToChurn []core.OperatorToChurn) (*SignatureWithSaltAndExpiry, error) {
func (c *churner) sign(ctx context.Context, operatorToRegisterAddress gethcommon.Address, operatorToRegisterId core.OperatorID, operatorsToChurn []core.OperatorToChurn) (*SignatureWithSaltAndExpiry, error) {
now := time.Now()
privateKeyBytes := crypto.FromECDSA(c.privateKey)
saltKeccak256 := crypto.Keccak256([]byte("churn"), []byte(now.String()), operatorToRegisterId[:], privateKeyBytes)
Expand All @@ -268,7 +262,7 @@ func (c *churner) sign(ctx context.Context, operatorToRegisterId core.OperatorID
expiry := big.NewInt(now.Add(secondsTillExpiry).Unix())

// sign and return signature
hashToSign, err := c.Transactor.CalculateOperatorChurnApprovalDigestHash(ctx, operatorToRegisterId, operatorsToChurn, salt, expiry)
hashToSign, err := c.Transactor.CalculateOperatorChurnApprovalDigestHash(ctx, operatorToRegisterAddress, operatorToRegisterId, operatorsToChurn, salt, expiry)
if err != nil {
return nil, err
}
Expand All @@ -290,6 +284,7 @@ func CalculateRequestHash(churnRequest *ChurnRequest) [32]byte {
var requestHash [32]byte
requestHashBytes := crypto.Keccak256(
[]byte("ChurnRequest"),
[]byte(churnRequest.OperatorAddress.Hex()),
churnRequest.OperatorToRegisterPubkeyG1.Serialize(),
churnRequest.OperatorToRegisterPubkeyG2.Serialize(),
churnRequest.Salt[:],
Expand Down
4 changes: 4 additions & 0 deletions churner/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
pb "github.com/Layr-Labs/eigenda/api/grpc/churner"
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/core"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -161,6 +162,8 @@ func (s *Server) validateChurnRequest(ctx context.Context, req *pb.ChurnRequest)
func createChurnRequest(req *pb.ChurnRequest) *ChurnRequest {
signature := &core.Signature{G1Point: new(core.G1Point).Deserialize(req.GetOperatorRequestSignature())}

address := gethcommon.HexToAddress(req.GetOperatorAddress())

salt := [32]byte{}
copy(salt[:], req.GetSalt())

Expand All @@ -170,6 +173,7 @@ func createChurnRequest(req *pb.ChurnRequest) *ChurnRequest {
}

return &ChurnRequest{
OperatorAddress: address,
OperatorToRegisterPubkeyG1: new(core.G1Point).Deserialize(req.GetOperatorToRegisterPubkeyG1()),
OperatorToRegisterPubkeyG2: new(core.G2Point).Deserialize(req.GetOperatorToRegisterPubkeyG2()),
OperatorRequestSignature: signature,
Expand Down
3 changes: 2 additions & 1 deletion core/eth/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func (t *Transactor) WeightOfOperatorForQuorum(ctx context.Context, quorumID cor

func (t *Transactor) CalculateOperatorChurnApprovalDigestHash(
ctx context.Context,
operatorAddress gethcommon.Address,
operatorId core.OperatorID,
operatorsToChurn []core.OperatorToChurn,
salt [32]byte,
Expand All @@ -585,7 +586,7 @@ func (t *Transactor) CalculateOperatorChurnApprovalDigestHash(
}
return t.Bindings.RegistryCoordinator.CalculateOperatorChurnApprovalDigestHash(&bind.CallOpts{
Context: ctx,
}, operatorId, opKickParams, salt, expiry)
}, operatorAddress, operatorId, opKickParams, salt, expiry)
}

func (t *Transactor) GetCurrentBlockNumber(ctx context.Context) (uint32, error) {
Expand Down
1 change: 1 addition & 0 deletions core/mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (t *MockTransactor) WeightOfOperatorForQuorum(ctx context.Context, quorumID

func (t *MockTransactor) CalculateOperatorChurnApprovalDigestHash(
ctx context.Context,
operatorAddress gethcommon.Address,
operatorId core.OperatorID,
operatorsToChurn []core.OperatorToChurn,
salt [32]byte,
Expand Down
1 change: 1 addition & 0 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type Transactor interface {
// CalculateOperatorChurnApprovalDigestHash returns calculated operator churn approval digest hash.
CalculateOperatorChurnApprovalDigestHash(
ctx context.Context,
operatorAddress gethcommon.Address,
operatorId OperatorID,
operatorsToChurn []OperatorToChurn,
salt [32]byte,
Expand Down
6 changes: 4 additions & 2 deletions node/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

type Operator struct {
Address string
Socket string
Timeout time.Duration
PrivKey *ecdsa.PrivateKey
Expand Down Expand Up @@ -140,14 +141,15 @@ func requestChurnApproval(ctx context.Context, operator *Operator, churnerUrl st
ctx, cancel := context.WithTimeout(ctx, operator.Timeout)
defer cancel()

request := newChurnRequest(operator.KeyPair, operator.QuorumIDs)
request := newChurnRequest(operator.Address, operator.KeyPair, operator.QuorumIDs)
opt := grpc.MaxCallSendMsgSize(1024 * 1024 * 300)

return gc.Churn(ctx, request, opt)
}

func newChurnRequest(KeyPair *core.KeyPair, QuorumIDs []core.QuorumID) *grpcchurner.ChurnRequest {
func newChurnRequest(address string, KeyPair *core.KeyPair, QuorumIDs []core.QuorumID) *grpcchurner.ChurnRequest {
churnRequest := &churner.ChurnRequest{
OperatorAddress: address,
OperatorToRegisterPubkeyG1: KeyPair.PubKey,
OperatorToRegisterPubkeyG2: KeyPair.GetPubKeyG2(),
QuorumIDs: QuorumIDs,
Expand Down
1 change: 1 addition & 0 deletions node/plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func pluginOps(ctx *cli.Context) {
}

operator := &node.Operator{
Address: config.Address,
Socket: socket,
Timeout: 10 * time.Second,
PrivKey: sk.PrivateKey,
Expand Down
10 changes: 10 additions & 0 deletions node/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ var (
EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "BLS_KEY_PASSWORD"),
}

// The address of the operator.
AddressFlag = cli.StringFlag{
Name: "address",
Required: true,
Usage: "The address of the operator to register in EigenDA",
EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "ADDRESS"),
}

// The socket and the quorums to register.
SocketFlag = cli.StringFlag{
Name: "socket",
Expand Down Expand Up @@ -112,6 +120,7 @@ type Config struct {
BlsKeyFile string
EcdsaKeyPassword string
BlsKeyPassword string
Address string
Socket string
QuorumIDList []core.QuorumID
ChainRpcUrl string
Expand Down Expand Up @@ -144,6 +153,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
BlsKeyPassword: ctx.GlobalString(BlsKeyPasswordFlag.Name),
EcdsaKeyFile: ctx.GlobalString(EcdsaKeyFileFlag.Name),
BlsKeyFile: ctx.GlobalString(BlsKeyFileFlag.Name),
Address: ctx.GlobalString(AddressFlag.Name),
Socket: ctx.GlobalString(SocketFlag.Name),
QuorumIDList: ids,
ChainRpcUrl: ctx.GlobalString(ChainRpcUrlFlag.Name),
Expand Down

0 comments on commit 5e911e0

Please sign in to comment.