From 8ce28f1d6d9ec85b3aff2c608fe3aeb8ee03f9ca Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 13 Jul 2023 10:27:30 -0400 Subject: [PATCH] Use big int for chain ID in offchain config (#9784) * Use big int for chain ID in offchain config * Add mercury codeowners --- CODEOWNERS | 1 + core/services/relay/evm/evm.go | 2 +- core/services/relay/evm/mercury/config_digest.go | 6 ++---- core/services/relay/evm/mercury/config_digest_test.go | 3 ++- .../relay/evm/mercury/offchain_config_digester.go | 5 +++-- .../evm/mercury/offchain_config_digester_test.go | 11 ++++++----- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 9f1a2469443..da11fb7cfdc 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -29,6 +29,7 @@ /core/services/pipeline @connorwstein @prashantkumar1982 /core/services/synchronization /core/services/telemetry +/core/services/relay/evm/mercury @samsondav @sdrug @martin-cll # VRF-related services /core/services/vrf @smartcontractkit/vrf-team diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 07179f0963f..8a9150cab33 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -286,7 +286,7 @@ func newConfigProvider(lggr logger.Logger, chainSet evm.ChainSet, args relaytype var offchainConfigDigester ocrtypes.OffchainConfigDigester if relayConfig.FeedID != nil { // Mercury - offchainConfigDigester = mercury.NewOffchainConfigDigester(*relayConfig.FeedID, chain.Config().EVM().ChainID().Uint64(), contractAddress) + offchainConfigDigester = mercury.NewOffchainConfigDigester(*relayConfig.FeedID, chain.Config().EVM().ChainID(), contractAddress) } else { // Non-mercury offchainConfigDigester = evmutil.EVMOffchainConfigDigester{ diff --git a/core/services/relay/evm/mercury/config_digest.go b/core/services/relay/evm/mercury/config_digest.go index ed99749ad49..4fb57b75f90 100644 --- a/core/services/relay/evm/mercury/config_digest.go +++ b/core/services/relay/evm/mercury/config_digest.go @@ -28,7 +28,7 @@ var configDigestArgs = makeConfigDigestArgs() func configDigest( feedID common.Hash, - chainID uint64, + chainID *big.Int, contractAddress common.Address, configCount uint64, oracles []common.Address, @@ -38,11 +38,9 @@ func configDigest( offchainConfigVersion uint64, offchainConfig []byte, ) types.ConfigDigest { - chainIDBig := new(big.Int) - chainIDBig.SetUint64(chainID) msg, err := configDigestArgs.Pack( feedID, - chainIDBig, + chainID, contractAddress, configCount, oracles, diff --git a/core/services/relay/evm/mercury/config_digest_test.go b/core/services/relay/evm/mercury/config_digest_test.go index 55d057f19f6..bfcbb7ad22a 100644 --- a/core/services/relay/evm/mercury/config_digest_test.go +++ b/core/services/relay/evm/mercury/config_digest_test.go @@ -51,9 +51,10 @@ func TestConfigCalculationMatches(t *testing.T) { offchainConfigVersion uint64, offchainConfig []byte, ) bool { + chainIDBig := new(big.Int).SetUint64(chainID) golangDigest := configDigest( feedID, - chainID, + chainIDBig, contractAddress, configCount, oracles, diff --git a/core/services/relay/evm/mercury/offchain_config_digester.go b/core/services/relay/evm/mercury/offchain_config_digester.go index ba3276d825a..7fb215c0e60 100644 --- a/core/services/relay/evm/mercury/offchain_config_digester.go +++ b/core/services/relay/evm/mercury/offchain_config_digester.go @@ -3,6 +3,7 @@ package mercury import ( "crypto/ed25519" "encoding/hex" + "math/big" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" @@ -15,13 +16,13 @@ import ( var _ ocrtypes.OffchainConfigDigester = OffchainConfigDigester{} -func NewOffchainConfigDigester(feedID [32]byte, chainID uint64, contractAddress common.Address) OffchainConfigDigester { +func NewOffchainConfigDigester(feedID [32]byte, chainID *big.Int, contractAddress common.Address) OffchainConfigDigester { return OffchainConfigDigester{feedID, chainID, contractAddress} } type OffchainConfigDigester struct { FeedID [32]byte - ChainID uint64 + ChainID *big.Int ContractAddress common.Address } diff --git a/core/services/relay/evm/mercury/offchain_config_digester_test.go b/core/services/relay/evm/mercury/offchain_config_digester_test.go index 599c30de396..c5d39926576 100644 --- a/core/services/relay/evm/mercury/offchain_config_digester_test.go +++ b/core/services/relay/evm/mercury/offchain_config_digester_test.go @@ -1,6 +1,7 @@ package mercury import ( + "math/big" "testing" "github.com/ethereum/go-ethereum/common" @@ -10,13 +11,13 @@ import ( func Test_OffchainConfigDigester_ConfigDigest(t *testing.T) { // ChainID and ContractAddress are taken into account for computation - cd1, err := OffchainConfigDigester{}.ConfigDigest(types.ContractConfig{}) + cd1, err := OffchainConfigDigester{ChainID: big.NewInt(0)}.ConfigDigest(types.ContractConfig{}) require.NoError(t, err) - cd2, err := OffchainConfigDigester{}.ConfigDigest(types.ContractConfig{}) + cd2, err := OffchainConfigDigester{ChainID: big.NewInt(0)}.ConfigDigest(types.ContractConfig{}) require.NoError(t, err) - cd3, err := OffchainConfigDigester{ChainID: 1}.ConfigDigest(types.ContractConfig{}) + cd3, err := OffchainConfigDigester{ChainID: big.NewInt(1)}.ConfigDigest(types.ContractConfig{}) require.NoError(t, err) - cd4, err := OffchainConfigDigester{ChainID: 1, ContractAddress: common.Address{1}}.ConfigDigest(types.ContractConfig{}) + cd4, err := OffchainConfigDigester{ChainID: big.NewInt(1), ContractAddress: common.Address{1}}.ConfigDigest(types.ContractConfig{}) require.NoError(t, err) require.Equal(t, cd1, cd2) @@ -47,7 +48,7 @@ func Test_OffchainConfigDigester_ConfigDigest(t *testing.T) { require.Error(t, err) // well-formed transmitters - _, err = OffchainConfigDigester{}.ConfigDigest(types.ContractConfig{ + _, err = OffchainConfigDigester{ChainID: big.NewInt(0)}.ConfigDigest(types.ContractConfig{ Transmitters: []types.Account{"7343581f55146951b0f678dc6cfa8fd360e2f353aabbccddeeffaaccddeeffaa"}, }) require.NoError(t, err)