Skip to content

Commit

Permalink
Merge branch 'develop' into tate_k8s_test_triage
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Jul 13, 2023
2 parents edc9131 + 8ce28f1 commit a7a7935
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 86 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
14 changes: 4 additions & 10 deletions core/services/relay/evm/mercury/reportcodec/report_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
// https://github.com/smartcontractkit/offchain-reporting/blob/master/lib/offchainreporting2/reportingplugin/median/evmreportcodec/reportcodec.go

var ReportTypes = getReportTypes()
var maxReportLength = 32 * len(ReportTypes) // each arg is 256 bit EVM word

func getReportTypes() abi.Arguments {
mustNewType := func(t string) abi.Type {
Expand Down Expand Up @@ -93,17 +94,10 @@ func (r *EVMReportCodec) BuildReport(paos []relaymercury.ParsedAttributedObserva
return ocrtypes.Report(reportBytes), errors.Wrap(err, "failed to pack report blob")
}

// Maximum length in bytes of Report returned by BuildReport. Used for
// defending against spam attacks.
func (r *EVMReportCodec) MaxReportLength(n int) (int, error) {
return 8*32 + // feed ID
32 + // timestamp
192 + // benchmarkPrice
192 + // bid
192 + // ask
64 + //currentBlockNum
8*32 + // currentBlockHash
64 + // validFromBlockNum
64, // currentBlockTimestamp
nil
return maxReportLength, nil
}

func (r *EVMReportCodec) CurrentBlockNumFromReport(report ocrtypes.Report) (int64, error) {
Expand Down
128 changes: 65 additions & 63 deletions core/services/relay/evm/mercury/reportcodec/report_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,66 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

var hash = hexutil.MustDecode("0x552c2cea3ab43bae137d89ee6142a01db3ae2b5678bc3c9bd5f509f537bea57b")
var paos = []relaymercury.ParsedAttributedObservation{
{
Timestamp: uint32(42),
Observer: commontypes.OracleID(49),

BenchmarkPrice: big.NewInt(43),
Bid: big.NewInt(44),
Ask: big.NewInt(45),
PricesValid: true,

CurrentBlockNum: 48,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(123),
CurrentBlockValid: true,
},
{
Timestamp: uint32(142),
Observer: commontypes.OracleID(149),

BenchmarkPrice: big.NewInt(143),
Bid: big.NewInt(144),
Ask: big.NewInt(145),
PricesValid: true,

CurrentBlockNum: 48,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(123),
CurrentBlockValid: true,
},
{
Timestamp: uint32(242),
Observer: commontypes.OracleID(249),

BenchmarkPrice: big.NewInt(243),
Bid: big.NewInt(244),
Ask: big.NewInt(245),
PricesValid: true,

CurrentBlockNum: 248,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(789),
CurrentBlockValid: true,
},
{
Timestamp: uint32(342),
Observer: commontypes.OracleID(250),

BenchmarkPrice: big.NewInt(343),
Bid: big.NewInt(344),
Ask: big.NewInt(345),
PricesValid: true,

CurrentBlockNum: 348,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(123456),
CurrentBlockValid: true,
},
}

func Test_ReportCodec_BuildReport(t *testing.T) {
r := EVMReportCodec{}

Expand All @@ -32,66 +92,6 @@ func Test_ReportCodec_BuildReport(t *testing.T) {
t.Run("BuildReport constructs a report from observations", func(t *testing.T) {
// only need to test happy path since validations are done in relaymercury

hash := hexutil.MustDecode("0x552c2cea3ab43bae137d89ee6142a01db3ae2b5678bc3c9bd5f509f537bea57b")

paos := []relaymercury.ParsedAttributedObservation{
{
Timestamp: uint32(42),
Observer: commontypes.OracleID(49),

BenchmarkPrice: big.NewInt(43),
Bid: big.NewInt(44),
Ask: big.NewInt(45),
PricesValid: true,

CurrentBlockNum: 48,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(123),
CurrentBlockValid: true,
},
{
Timestamp: uint32(142),
Observer: commontypes.OracleID(149),

BenchmarkPrice: big.NewInt(143),
Bid: big.NewInt(144),
Ask: big.NewInt(145),
PricesValid: true,

CurrentBlockNum: 48,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(123),
CurrentBlockValid: true,
},
{
Timestamp: uint32(242),
Observer: commontypes.OracleID(249),

BenchmarkPrice: big.NewInt(243),
Bid: big.NewInt(244),
Ask: big.NewInt(245),
PricesValid: true,

CurrentBlockNum: 248,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(789),
CurrentBlockValid: true,
},
{
Timestamp: uint32(342),
Observer: commontypes.OracleID(250),

BenchmarkPrice: big.NewInt(343),
Bid: big.NewInt(344),
Ask: big.NewInt(345),
PricesValid: true,

CurrentBlockNum: 348,
CurrentBlockHash: hash,
CurrentBlockTimestamp: uint64(123456),
CurrentBlockValid: true,
},
}
report, err := r.BuildReport(paos, f, 46)
require.NoError(t, err)

Expand All @@ -117,12 +117,14 @@ func Test_ReportCodec_BuildReport(t *testing.T) {

func Test_ReportCodec_MaxReportLength(t *testing.T) {
r := EVMReportCodec{}
n := 4
n := len(paos)
report, err := r.BuildReport(paos, 1, 46)
require.NoError(t, err)

t.Run("MaxReportLength returns correct length", func(t *testing.T) {
t.Run("MaxReportLength returns length of report", func(t *testing.T) {
max, err := r.MaxReportLength(n)
require.NoError(t, err)
assert.Equal(t, 1312, max)
assert.Equal(t, len(report), max)
})
}

Expand Down

0 comments on commit a7a7935

Please sign in to comment.