From c942910b69fa46bd34e2c19917b93b100e812348 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Thu, 25 Apr 2024 14:22:50 -0700 Subject: [PATCH 1/3] make ecdsa optional for certain operations --- node/plugin/cmd/main.go | 34 ++++++++++++++++++++++------------ node/plugin/config.go | 8 ++++++-- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index c50aa88b61..35d8973fb3 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "log" "os" "strings" @@ -15,6 +16,8 @@ import ( "github.com/Layr-Labs/eigenda/node" "github.com/Layr-Labs/eigenda/node/plugin" "github.com/Layr-Labs/eigensdk-go/crypto/bls" + + "github.com/ethereum/go-ethereum/accounts/keystore" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/urfave/cli" ) @@ -69,12 +72,16 @@ func pluginOps(ctx *cli.Context) { operatorID := keyPair.GetPubKeyG1().GetOperatorID() - sk, privateKey, err := plugin.GetECDSAPrivateKey(config.EcdsaKeyFile, config.EcdsaKeyPassword) - if err != nil { - log.Printf("Error: failed to read or decrypt the ECDSA private key: %v", err) - return + var sk *keystore.Key + var privateKey *string + if config.Operation != plugin.OperationListQuorums { + sk, privateKey, err = plugin.GetECDSAPrivateKey(config.EcdsaKeyFile, config.EcdsaKeyPassword) + if err != nil { + log.Printf("Error: failed to read or decrypt the ECDSA private key: %v", err) + return + } + log.Printf("Info: ECDSA key read and decrypted from %s", config.EcdsaKeyFile) } - log.Printf("Info: ECDSA key read and decrypted from %s", config.EcdsaKeyFile) loggerConfig := common.DefaultLoggerConfig() logger, err := common.NewLogger(loggerConfig) @@ -117,6 +124,16 @@ func pluginOps(ctx *cli.Context) { } } + if config.Operation == plugin.OperationListQuorums { + quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID) + if err != nil { + log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err) + return + } + log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, sk.Address, quorumIds) + return + } + operator := &node.Operator{ Address: sk.Address.Hex(), Socket: socket, @@ -152,13 +169,6 @@ func pluginOps(ctx *cli.Context) { return } log.Printf("Info: successfully updated socket, for operator ID: %x, operator address: %x, socket: %s", operatorID, sk.Address, config.Socket) - } else if config.Operation == plugin.OperationListQuorums { - quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID) - if err != nil { - log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err) - return - } - log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, sk.Address, quorumIds) } else { log.Fatalf("Fatal: unsupported operation: %s", config.Operation) } diff --git a/node/plugin/config.go b/node/plugin/config.go index 1c3ee1ad9c..b987b0f239 100644 --- a/node/plugin/config.go +++ b/node/plugin/config.go @@ -39,7 +39,7 @@ var ( // The files for encrypted private keys. EcdsaKeyFileFlag = cli.StringFlag{ Name: "ecdsa-key-file", - Required: true, + Required: false, Usage: "Path to the encrypted ecdsa key", EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "ECDSA_KEY_FILE"), } @@ -53,7 +53,7 @@ var ( // The passwords to decrypt the private keys. EcdsaKeyPasswordFlag = cli.StringFlag{ Name: "ecdsa-key-password", - Required: true, + Required: false, Usage: "Password to decrypt the ecdsa key", EnvVar: common.PrefixEnvVar(flags.EnvVarPrefix, "ECDSA_KEY_PASSWORD"), } @@ -150,6 +150,10 @@ func NewConfig(ctx *cli.Context) (*Config, error) { return nil, errors.New("unsupported operation type") } + if op != OperationListQuorums && len(ctx.GlobalString(EcdsaKeyFileFlag.Name)) == 0 && len(ctx.GlobalString(EcdsaKeyPasswordFlag.Name)) == 0 { + return nil, errors.New("opt-in, opt-out and update-socket operations require ECDSA key file and password") + } + return &Config{ PubIPProvider: ctx.GlobalString(PubIPProviderFlag.Name), Operation: op, From 602fe252af9847bf56ecc4d5e412cbb146ae3070 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Thu, 25 Apr 2024 16:09:46 -0700 Subject: [PATCH 2/3] get operator address from smart contract --- node/plugin/cmd/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index 35d8973fb3..57cb496d03 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -125,12 +125,17 @@ func pluginOps(ctx *cli.Context) { } if config.Operation == plugin.OperationListQuorums { + operatorAddress, err := tx.OperatorIDToAddress(context.Background(), operatorID) + if err != nil { + log.Printf("Error: failed to get operator address for operatorID: %x, error: %v", operatorID, err) + return + } quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID) if err != nil { log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err) return } - log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, sk.Address, quorumIds) + log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, operatorAddress, quorumIds) return } From cca159bf8fd31d7356f648cc6908bcdae59a2ca7 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Thu, 25 Apr 2024 17:13:37 -0700 Subject: [PATCH 3/3] address some comments --- node/plugin/cmd/main.go | 4 ++-- node/plugin/config.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/node/plugin/cmd/main.go b/node/plugin/cmd/main.go index 57cb496d03..f6af705c1d 100644 --- a/node/plugin/cmd/main.go +++ b/node/plugin/cmd/main.go @@ -132,10 +132,10 @@ func pluginOps(ctx *cli.Context) { } quorumIds, err := tx.GetRegisteredQuorumIdsForOperator(context.Background(), operatorID) if err != nil { - log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, sk.Address, err) + log.Printf("Error: failed to get quorum(s) for operatorID: %x, operator address: %x, error: %v", operatorID, operatorAddress.Hex(), err) return } - log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, operatorAddress, quorumIds) + log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, operatorAddress.Hex(), quorumIds) return } diff --git a/node/plugin/config.go b/node/plugin/config.go index b987b0f239..df3e9f1efa 100644 --- a/node/plugin/config.go +++ b/node/plugin/config.go @@ -150,7 +150,10 @@ func NewConfig(ctx *cli.Context) (*Config, error) { return nil, errors.New("unsupported operation type") } - if op != OperationListQuorums && len(ctx.GlobalString(EcdsaKeyFileFlag.Name)) == 0 && len(ctx.GlobalString(EcdsaKeyPasswordFlag.Name)) == 0 { + // ECDSA key is only required for opt-in, opt-out and update-socket operations + if (op == OperationOptIn || op == OperationOptOut || op == OperationUpdateSocket) && + len(ctx.GlobalString(EcdsaKeyFileFlag.Name)) == 0 && + len(ctx.GlobalString(EcdsaKeyPasswordFlag.Name)) == 0 { return nil, errors.New("opt-in, opt-out and update-socket operations require ECDSA key file and password") }