Skip to content

Commit

Permalink
Use big int for chain ID in offchain config (#9784)
Browse files Browse the repository at this point in the history
* Use big int for chain ID in offchain config

* Add mercury codeowners
  • Loading branch information
samsondav authored Jul 13, 2023
1 parent 1362a98 commit 8ce28f1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 2 additions & 4 deletions core/services/relay/evm/mercury/config_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion core/services/relay/evm/mercury/config_digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions core/services/relay/evm/mercury/offchain_config_digester.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mercury
import (
"crypto/ed25519"
"encoding/hex"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
Expand All @@ -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
}

Expand Down
11 changes: 6 additions & 5 deletions core/services/relay/evm/mercury/offchain_config_digester_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mercury

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8ce28f1

Please sign in to comment.