Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make ecdsa optional for certain operations #522

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions node/plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"

"log"
"os"
"strings"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -117,6 +124,21 @@ func pluginOps(ctx *cli.Context) {
}
}

if config.Operation == plugin.OperationListQuorums {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting this operation before operator is initialized since that require us to have private key. I am making minimal changes to make sure we make ecdsa optional here too.

shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we put this block before declaring sk and privateKey? Then we don't need the block in L77, right?

Copy link
Contributor Author

@shrimalmadhur shrimalmadhur Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but the reason is - this still require transactor which requires ethConfig which requires privateKey - well privateKey is just passed as config. One way is I create ethConfig without privateKey and if we get to a point where privateKey is needed for other ops and we read ecdsa key then I can add that config. would that be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh but that won't work since transactor will already be created by then. I don't think we want to create transactor again.

operatorAddress, err := tx.OperatorIDToAddress(context.Background(), operatorID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should just use this to get address for all cases and not rely on private key?

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)
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved
return
}
log.Printf("Info: operator ID: %x, operator address: %x, current quorums: %v", operatorID, operatorAddress, quorumIds)
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved
return
}

operator := &node.Operator{
Address: sk.Address.Hex(),
Socket: socket,
Expand Down Expand Up @@ -152,13 +174,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)
}
Expand Down
8 changes: 6 additions & 2 deletions node/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand All @@ -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"),
}
Expand Down Expand Up @@ -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 {
shrimalmadhur marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down
Loading