Skip to content

fix: proper error msg for incorrect bridge chainids #594

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

Draft
wants to merge 1 commit into
base: mock-l1-chainid
Choose a base branch
from
Draft
Changes from all 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
40 changes: 40 additions & 0 deletions bridge/standard/pkg/transfer/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func NewTransferToSettlement(
if err != nil {
return nil, fmt.Errorf("failed to dial settlement rpc: %s", err)
}
settlementChainID, err := settlementClient.ChainID(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to get settlement chain id: %s", err)
}
initialBlock, err := settlementClient.BlockNumber(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to get initial block: %s", err)
Expand All @@ -85,6 +89,13 @@ func NewTransferToSettlement(
return nil, fmt.Errorf("failed to create settlement filterer: %s", err)
}

if err := validateChainIDs(
l1ChainID, // src
settlementChainID, // dest
); err != nil {
return nil, fmt.Errorf("invalid chain ids: %s", err)
}

return &Transfer{
signer: signer,
amount: amount,
Expand All @@ -111,6 +122,10 @@ func NewTransferToL1(
if err != nil {
return nil, fmt.Errorf("failed to dial l1 rpc: %s", err)
}
l1ChainID, err := l1Client.ChainID(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to get l1 chain id: %s", err)
}
initialBlock, err := l1Client.BlockNumber(context.Background())
if err != nil {
return nil, fmt.Errorf("failed to get initial block: %s", err)
Expand Down Expand Up @@ -143,6 +158,13 @@ func NewTransferToL1(
return nil, fmt.Errorf("failed to create settlement filterer: %s", err)
}

if err := validateChainIDs(
settlementChainID, // src
l1ChainID, // dest
); err != nil {
return nil, fmt.Errorf("invalid chain ids: %s", err)
}

return &Transfer{
amount: amount,
destAddress: destAddress,
Expand All @@ -156,6 +178,24 @@ func NewTransferToL1(
}, nil
}

func validateChainIDs(srcChainID *big.Int, destChainID *big.Int) error {
allowedPairs := map[int64]int64{
1: 8855, // mainnet -> mainnet mev-commit
8855: 1, // mainnet mev-commit -> mainnet
17000: 17864, // holesky -> testnet mev-commit
17864: 17000, // testnet mev-commit -> holesky
}
expectedDest, ok := allowedPairs[srcChainID.Int64()]
if !ok {
return fmt.Errorf("source chain ID %d not recognized. Options are: %v", srcChainID.Int64(), allowedPairs)
}
if expectedDest != destChainID.Int64() {
return fmt.Errorf("invalid destination chain ID %d for source %d. Expected is %d",
destChainID.Int64(), srcChainID.Int64(), expectedDest)
}
return nil
}

func (t *Transfer) Do(ctx context.Context) <-chan TransferStatus {
statusChan := make(chan TransferStatus)
go func() {
Expand Down
Loading