Skip to content

Commit 2a822fb

Browse files
authored
fix: fix operator set registration command (#333)
1 parent 3facd18 commit 2a822fb

File tree

7 files changed

+111
-57
lines changed

7 files changed

+111
-57
lines changed

pkg/internal/common/flags/general.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,16 @@ var (
132132
Usage: "Used to execute an action on behalf of another user. See User Access Management documents for more details.",
133133
EnvVars: []string{"CALLER_ADDRESS"},
134134
}
135+
RegistryCoordinatorAddressFlag = cli.StringFlag{
136+
Name: "registry-coordinator-address",
137+
Aliases: []string{"rca"},
138+
Usage: "Address of the registry coordinator contract. This is required for registering an operator for operator sets",
139+
EnvVars: []string{"REGISTRY_COORDINATOR_ADDRESS"},
140+
}
141+
BlsPrivateKeyFlag = cli.StringFlag{
142+
Name: "bls-private-key",
143+
Aliases: []string{"bls"},
144+
Usage: "BLS private key of Operator for Operator Set registration",
145+
EnvVars: []string{"BLS_PRIVATE_KEY"},
146+
}
135147
)

pkg/internal/common/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func GetTransactionLink(txHash string, chainId *big.Int) string {
379379
if !ok {
380380
return txHash
381381
} else {
382-
return fmt.Sprintf("%s/%s", chainMetadata.BlockExplorerUrl, txHash)
382+
return fmt.Sprintf("%s/tx/%s", chainMetadata.BlockExplorerUrl, txHash)
383383
}
384384
}
385385

pkg/internal/common/helper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ func TestGetTransactionLink(t *testing.T) {
2424
name: "valid mainnet tx hash",
2525
chainID: big.NewInt(1),
2626
txHash: "0x123",
27-
expectedTxLink: fmt.Sprintf("%s/%s", utils.MainnetBlockExplorerUrl, "0x123"),
27+
expectedTxLink: fmt.Sprintf("%s/tx/%s", utils.MainnetBlockExplorerUrl, "0x123"),
2828
},
2929
{
3030
name: "valid holesky tx hash",
3131
chainID: big.NewInt(17000),
3232
txHash: "0x123",
33-
expectedTxLink: fmt.Sprintf("%s/%s", utils.HoleskyBlockExplorerUrl, "0x123"),
33+
expectedTxLink: fmt.Sprintf("%s/tx/%s", utils.HoleskyBlockExplorerUrl, "0x123"),
3434
},
3535
{
3636
name: "valid custom chain tx hash",

pkg/keys/import.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package keys
33
import (
44
"crypto/ecdsa"
55
"fmt"
6-
"math/big"
76
"strings"
87

98
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
109
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
1110
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
1211

13-
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
1412
"github.com/ethereum/go-ethereum/crypto"
1513
"github.com/urfave/cli/v2"
1614
)
@@ -104,29 +102,9 @@ This command will import keys in $HOME/.eigenlayer/operator_keys/ location
104102
}
105103
return saveEcdsaKey(keyName, p, privateKeyPair, insecure, stdInPassword, readFromPipe, "")
106104
case KeyTypeBLS:
107-
privateKeyBigInt := new(big.Int)
108-
_, ok := privateKeyBigInt.SetString(privateKey, 10)
109-
var blsKeyPair *bls.KeyPair
110-
var err error
111-
if ok {
112-
fmt.Println("Importing from large integer")
113-
blsKeyPair, err = bls.NewKeyPairFromString(privateKey)
114-
if err != nil {
115-
return err
116-
}
117-
} else {
118-
// Try to parse as hex
119-
fmt.Println("Importing from hex")
120-
z := new(big.Int)
121-
privateKey = common.Trim0x(privateKey)
122-
_, ok := z.SetString(privateKey, 16)
123-
if !ok {
124-
return ErrInvalidHexPrivateKey
125-
}
126-
blsKeyPair, err = bls.NewKeyPairFromString(z.String())
127-
if err != nil {
128-
return err
129-
}
105+
blsKeyPair, err := ParseBlsPrivateKey(privateKey)
106+
if err != nil {
107+
return err
130108
}
131109
return saveBlsKey(keyName, p, blsKeyPair, insecure, stdInPassword, readFromPipe)
132110
default:

pkg/keys/utils.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package keys
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
7+
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
8+
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
9+
)
10+
11+
// ParseBlsPrivateKey parses a BLS private key from a string either in hex or large integer format.
12+
func ParseBlsPrivateKey(privateKey string) (*bls.KeyPair, error) {
13+
privateKeyBigInt := new(big.Int)
14+
_, ok := privateKeyBigInt.SetString(privateKey, 10)
15+
var blsKeyPair *bls.KeyPair
16+
var err error
17+
if ok {
18+
fmt.Println("Importing from large integer")
19+
blsKeyPair, err = bls.NewKeyPairFromString(privateKey)
20+
if err != nil {
21+
return nil, err
22+
}
23+
} else {
24+
// Try to parse as hex
25+
fmt.Println("Importing from hex")
26+
z := new(big.Int)
27+
privateKey = common.Trim0x(privateKey)
28+
_, ok := z.SetString(privateKey, 16)
29+
if !ok {
30+
return nil, ErrInvalidHexPrivateKey
31+
}
32+
blsKeyPair, err = bls.NewKeyPairFromString(z.String())
33+
if err != nil {
34+
return nil, err
35+
}
36+
}
37+
return blsKeyPair, nil
38+
}

pkg/operator/register_operator_sets.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/command"
77
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
88
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
9+
"github.com/Layr-Labs/eigenlayer-cli/pkg/keys"
910
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
1011

1112
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
@@ -75,11 +76,12 @@ func (r RegisterOperatorSetCmd) Execute(cCtx *cli.Context) error {
7576
}
7677
receipt, err := eLWriter.RegisterForOperatorSets(
7778
ctx,
78-
config.callerAddress,
79+
config.registryCoordinatorAddress,
7980
elcontracts.RegistrationRequest{
8081
OperatorAddress: config.operatorAddress,
8182
AVSAddress: config.avsAddress,
8283
OperatorSetIds: config.operatorSetIds,
84+
BlsKeyPair: config.blsKeyPair,
8385
WaitForReceipt: true,
8486
})
8587
if err != nil {
@@ -183,27 +185,46 @@ func readAndValidateRegisterOperatorSetsConfig(cCtx *cli.Context, logger logging
183185
}
184186
}
185187

188+
registryCoordinatorAddress := cCtx.String(flags.RegistryCoordinatorAddressFlag.Name)
189+
if common.IsEmptyString(registryCoordinatorAddress) {
190+
logger.Error("--registry-coordinator-address flag must be set")
191+
return nil, fmt.Errorf("Empty registry coordinator address provided")
192+
}
193+
186194
operatorSetIdsString := cCtx.Uint64Slice(flags.OperatorSetIdsFlag.Name)
187195
operatorSetIds := make([]uint32, len(operatorSetIdsString))
188196
for i, id := range operatorSetIdsString {
189197
operatorSetIds[i] = uint32(id)
190198
}
191199

200+
blsPrivateKey := cCtx.String(flags.BlsPrivateKeyFlag.Name)
201+
if common.IsEmptyString(blsPrivateKey) {
202+
logger.Error("--bls-private-key flag must be set")
203+
return nil, fmt.Errorf("Empty BLS private key provided")
204+
}
205+
206+
blsKeyPair, err := keys.ParseBlsPrivateKey(blsPrivateKey)
207+
if err != nil {
208+
return nil, err
209+
}
210+
192211
config := &RegisterConfig{
193-
avsAddress: avsAddress,
194-
operatorSetIds: operatorSetIds,
195-
operatorAddress: operatorAddress,
196-
callerAddress: callerAddress,
197-
network: network,
198-
environment: environment,
199-
broadcast: broadcast,
200-
rpcUrl: rpcUrl,
201-
chainID: chainId,
202-
signerConfig: signerConfig,
203-
output: output,
204-
outputType: outputType,
205-
delegationManagerAddress: gethcommon.HexToAddress(delegationManagerAddress),
206-
isSilent: isSilent,
212+
avsAddress: avsAddress,
213+
operatorSetIds: operatorSetIds,
214+
operatorAddress: operatorAddress,
215+
callerAddress: callerAddress,
216+
network: network,
217+
environment: environment,
218+
broadcast: broadcast,
219+
rpcUrl: rpcUrl,
220+
chainID: chainId,
221+
signerConfig: signerConfig,
222+
output: output,
223+
outputType: outputType,
224+
delegationManagerAddress: gethcommon.HexToAddress(delegationManagerAddress),
225+
isSilent: isSilent,
226+
registryCoordinatorAddress: gethcommon.HexToAddress(registryCoordinatorAddress),
227+
blsKeyPair: blsKeyPair,
207228
}
208229

209230
return config, nil
@@ -220,5 +241,7 @@ func getRegistrationFlags() []cli.Flag {
220241
&flags.OperatorSetIdsFlag,
221242
&flags.DelegationManagerAddressFlag,
222243
&flags.SilentFlag,
244+
&flags.RegistryCoordinatorAddressFlag,
245+
&flags.BlsPrivateKeyFlag,
223246
}
224247
}

pkg/operator/types.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"math/big"
55

66
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
7+
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
78
"github.com/ethereum/go-ethereum/common"
89
)
910

@@ -25,18 +26,20 @@ type DeregisterConfig struct {
2526
}
2627

2728
type RegisterConfig struct {
28-
avsAddress common.Address
29-
operatorSetIds []uint32
30-
operatorAddress common.Address
31-
callerAddress common.Address
32-
network string
33-
environment string
34-
broadcast bool
35-
rpcUrl string
36-
chainID *big.Int
37-
signerConfig *types.SignerConfig
38-
output string
39-
outputType string
40-
delegationManagerAddress common.Address
41-
isSilent bool
29+
avsAddress common.Address
30+
operatorSetIds []uint32
31+
operatorAddress common.Address
32+
callerAddress common.Address
33+
network string
34+
environment string
35+
broadcast bool
36+
rpcUrl string
37+
chainID *big.Int
38+
signerConfig *types.SignerConfig
39+
output string
40+
outputType string
41+
delegationManagerAddress common.Address
42+
isSilent bool
43+
registryCoordinatorAddress common.Address
44+
blsKeyPair *bls.KeyPair
4245
}

0 commit comments

Comments
 (0)