Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Validate ChainId #494

Merged
merged 10 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
11 changes: 10 additions & 1 deletion chains/ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The writer recieves the message and creates a proposals on-chain. Once a proposa
package ethereum

import (
"fmt"
"math/big"

bridge "github.com/ChainSafe/ChainBridge/bindings/Bridge"
Expand Down Expand Up @@ -111,7 +112,6 @@ func InitializeChain(chainCfg *core.ChainConfig, logger log15.Logger, sysErr cha
if err != nil {
return nil, err
}

err = conn.EnsureHasBytecode(cfg.bridgeContract)
if err != nil {
return nil, err
Expand All @@ -130,6 +130,15 @@ func InitializeChain(chainCfg *core.ChainConfig, logger log15.Logger, sysErr cha
return nil, err
}

chainId, err := bridgeContract.ChainID(conn.CallOpts())
if err != nil {
return nil, err
}

if chainId != uint8(chainCfg.Id) {
return nil, fmt.Errorf("chainId and configuration chainId do not match")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("chainId and configuration chainId do not match")
return nil, fmt.Errorf("chainId (%s) and configuration chainId (%s) do not match", chainId, chainCfg.Id)

}

erc20HandlerContract, err := erc20Handler.NewERC20Handler(cfg.erc20HandlerContract, conn.Client())
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion chains/ethereum/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestChain_ListenerShutdownOnFailure(t *testing.T) {
client := ethtest.NewClient(t, TestEndpoint, AliceKp)
contracts := deployTestContracts(t, client, msg.ChainId(1))
cfg := &core.ChainConfig{
Id: msg.ChainId(0),
Id: msg.ChainId(1),
Name: "alice",
Endpoint: TestEndpoint,
From: keystore.AliceKey,
Expand Down