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

feat: update signer scheme for second bridge #436

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions cmd/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions ethereum/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
jeremyletang marked this conversation as resolved.
Show resolved Hide resolved
}

args = append(args, getEthereumWalletArgs(signer)...)

signature, err := callVegaBridgeERC20(vegaBinary, args)
Expand All @@ -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 {
Expand All @@ -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))
jeremyletang marked this conversation as resolved.
Show resolved Hide resolved
}

args = append(args, getEthereumWalletArgs(signer)...)

signature, err := callVegaBridgeERC20(vegaBinary, args)
Expand All @@ -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 {
Expand All @@ -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))
jeremyletang marked this conversation as resolved.
Show resolved Hide resolved
}

args = append(args, getEthereumWalletArgs(signer)...)

signature, err := callVegaBridgeERC20(vegaBinary, args)
Expand Down
29 changes: 25 additions & 4 deletions ethereum/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
)

type EthereumMultisigClient struct {
client *ethclient.Client
chainID int64
client *ethclient.Client
chainID int64
isPrimary bool

multisig *multisig.MultisigControl

Expand Down Expand Up @@ -48,6 +49,7 @@ type EthereumMultisigClientParameters struct {
ChainID int
EthereumAddress string
SmartContractsInfo types.SmartContractsInfo
IsPrimary bool

VegaBinary string
VegaHome string
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
Loading