From 3942678964387a07827fd154dd9ad3a3039620b0 Mon Sep 17 00:00:00 2001 From: wwestgarth Date: Tue, 23 Apr 2024 09:55:13 +0100 Subject: [PATCH 1/3] feat: update signer scheme for second bridge --- cmd/ethereum.go | 2 ++ ethereum/commands.go | 18 +++++++++++++++--- ethereum/multisig.go | 29 +++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/cmd/ethereum.go b/cmd/ethereum.go index 6d0122bb..029f180c 100644 --- a/cmd/ethereum.go +++ b/cmd/ethereum.go @@ -127,6 +127,7 @@ var ethereumMultisigSetupCmd = &cobra.Command{ ChainID: primaryChainID, EthereumAddress: netState.Config.Network.Ethereum.Endpoint, SmartContractsInfo: *primarySmartContracts, + IsPrimary: true, }) if err != nil { return fmt.Errorf("failed to create primary ethereum client: %w", err) @@ -155,6 +156,7 @@ var ethereumMultisigSetupCmd = &cobra.Command{ ChainID: secondaryChainID, EthereumAddress: netState.Config.Network.SecondaryEthereum.Endpoint, SmartContractsInfo: *secondarySmartContracts, + IsPrimary: false, }) if err != nil { return fmt.Errorf("failed to create secondary ethereum client: %w", err) diff --git a/ethereum/commands.go b/ethereum/commands.go index f72cd5cd..1eae0573 100644 --- a/ethereum/commands.go +++ b/ethereum/commands.go @@ -19,7 +19,7 @@ func getEthereumWalletArgs(signer Signer) []string { } } -func setThresholdSignature(vegaBinary string, newThreshold int, nonce uint64, submitter string, signers SignersList) (string, error) { +func setThresholdSignature(vegaBinary string, newThreshold int, nonce uint64, submitter string, signers SignersList, chainID *int64) (string, error) { result := "0x" for _, signer := range signers { @@ -31,6 +31,10 @@ func setThresholdSignature(vegaBinary string, newThreshold int, nonce uint64, su "--nonce", fmt.Sprintf("%d", nonce), } + if chainID != nil { + args = append(args, "--chain_id", fmt.Sprintf("%d", *chainID)) + } + args = append(args, getEthereumWalletArgs(signer)...) signature, err := callVegaBridgeERC20(vegaBinary, args) @@ -47,7 +51,7 @@ func setThresholdSignature(vegaBinary string, newThreshold int, nonce uint64, su return result, nil } -func addSignerSignature(vegaBinary string, newSigner string, nonce uint64, submitter string, signers SignersList) (string, error) { +func addSignerSignature(vegaBinary string, newSigner string, nonce uint64, submitter string, signers SignersList, chainID *int64) (string, error) { result := "0x" for _, signer := range signers { @@ -59,6 +63,10 @@ func addSignerSignature(vegaBinary string, newSigner string, nonce uint64, submi "--nonce", fmt.Sprintf("%d", nonce), } + if chainID != nil { + args = append(args, "--chain_id", fmt.Sprintf("%d", *chainID)) + } + args = append(args, getEthereumWalletArgs(signer)...) signature, err := callVegaBridgeERC20(vegaBinary, args) @@ -75,7 +83,7 @@ func addSignerSignature(vegaBinary string, newSigner string, nonce uint64, submi return result, nil } -func removeSignerSignature(vegaBinary string, oldSigner string, nonce uint64, submitter string, signers SignersList) (string, error) { +func removeSignerSignature(vegaBinary string, oldSigner string, nonce uint64, submitter string, signers SignersList, chainID *int64) (string, error) { result := "0x" for _, signer := range signers { @@ -87,6 +95,10 @@ func removeSignerSignature(vegaBinary string, oldSigner string, nonce uint64, su "--nonce", fmt.Sprintf("%d", nonce), } + if chainID != nil { + args = append(args, "--chain_id", fmt.Sprintf("%d", *chainID)) + } + args = append(args, getEthereumWalletArgs(signer)...) signature, err := callVegaBridgeERC20(vegaBinary, args) diff --git a/ethereum/multisig.go b/ethereum/multisig.go index cdbe740a..30ec99cc 100644 --- a/ethereum/multisig.go +++ b/ethereum/multisig.go @@ -16,8 +16,9 @@ import ( ) type EthereumMultisigClient struct { - client *ethclient.Client - chainID int64 + client *ethclient.Client + chainID int64 + isPrimary bool multisig *multisig.MultisigControl @@ -48,6 +49,7 @@ type EthereumMultisigClientParameters struct { ChainID int EthereumAddress string SmartContractsInfo types.SmartContractsInfo + IsPrimary bool VegaBinary string VegaHome string @@ -74,6 +76,7 @@ func NewEthereumMultisigClient(ctx context.Context, params EthereumMultisigClien chainID: int64(params.ChainID), vegaBinary: params.VegaBinary, vegaHome: params.VegaHome, + isPrimary: params.IsPrimary, }, nil } @@ -161,12 +164,18 @@ func (ec EthereumMultisigClient) multisigSetThreshold(ctx context.Context, sessi return fmt.Errorf("failed to get nonce: %w", err) } + var chainID *int64 + if !ec.isPrimary { + chainID = &ec.chainID + } + signature, err := setThresholdSignature( ec.vegaBinary, newThreshold, nonce.Uint64(), session.CallOpts.From.Hex(), signers, + chainID, ) if err != nil { return fmt.Errorf("failed computing signature: %w", err) @@ -212,12 +221,18 @@ func (ec EthereumMultisigClient) multisigAddSigners(ctx context.Context, session if err != nil { return fmt.Errorf("failed to get nonce: %w", err) } + + var chainID *int64 + if !ec.isPrimary { + chainID = &ec.chainID + } signature, err := addSignerSignature( ec.vegaBinary, validator.KeyPair.Address, nonce.Uint64(), session.CallOpts.From.Hex(), - signers) + signers, + chainID) if err != nil { return fmt.Errorf("failed generate the add_signer signature for %s signer: %w", validator.KeyPair.Address, err) } @@ -257,12 +272,18 @@ func (ec EthereumMultisigClient) multisigRemoveSigner(ctx context.Context, sessi if err != nil { return fmt.Errorf("failed to get nonce: %w", err) } + + var chainID *int64 + if !ec.isPrimary { + chainID = &ec.chainID + } signature, err := removeSignerSignature( ec.vegaBinary, oldSigner, nonce.Uint64(), session.CallOpts.From.Hex(), - signers) + signers, + chainID) if err != nil { return fmt.Errorf("failed generate signature: %w", err) } From 3987aef1db70d31dbdd8f0142f071a1bf322ed3e Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Wed, 24 Apr 2024 09:34:05 +0100 Subject: [PATCH 2/3] chore: Update ethereum/commands.go change argument from --chain_id to --chain-id --- ethereum/commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/commands.go b/ethereum/commands.go index 1eae0573..70e34a79 100644 --- a/ethereum/commands.go +++ b/ethereum/commands.go @@ -96,7 +96,7 @@ func removeSignerSignature(vegaBinary string, oldSigner string, nonce uint64, su } if chainID != nil { - args = append(args, "--chain_id", fmt.Sprintf("%d", *chainID)) + args = append(args, "--chain-id", fmt.Sprintf("%d", *chainID)) } args = append(args, getEthereumWalletArgs(signer)...) From 301254e75bd896ee04162ab8268adf829b1ec9e8 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Wed, 24 Apr 2024 09:35:18 +0100 Subject: [PATCH 3/3] chore: chain --chain_id to --chain-id --- ethereum/commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/commands.go b/ethereum/commands.go index 70e34a79..74d8c603 100644 --- a/ethereum/commands.go +++ b/ethereum/commands.go @@ -32,7 +32,7 @@ func setThresholdSignature(vegaBinary string, newThreshold int, nonce uint64, su } if chainID != nil { - args = append(args, "--chain_id", fmt.Sprintf("%d", *chainID)) + args = append(args, "--chain-id", fmt.Sprintf("%d", *chainID)) } args = append(args, getEthereumWalletArgs(signer)...) @@ -64,7 +64,7 @@ func addSignerSignature(vegaBinary string, newSigner string, nonce uint64, submi } if chainID != nil { - args = append(args, "--chain_id", fmt.Sprintf("%d", *chainID)) + args = append(args, "--chain-id", fmt.Sprintf("%d", *chainID)) } args = append(args, getEthereumWalletArgs(signer)...)