diff --git a/core/services/ocr2/plugins/ccip/commit_plugin.go b/core/services/ocr2/plugins/ccip/commit_plugin.go index 9190aabae4..bda5f3b0e0 100644 --- a/core/services/ocr2/plugins/ccip/commit_plugin.go +++ b/core/services/ocr2/plugins/ccip/commit_plugin.go @@ -94,7 +94,7 @@ func jobSpecToCommitPluginConfig(lggr logger.Logger, jb job.Job, pr pipeline.Run if err != nil { return nil, nil, err } - sourceRouter, err := router.NewRouter(onRampReader.Router(), sourceChain.Client()) + sourceRouter, err := router.NewRouter(onRampReader.RouterAddress(), sourceChain.Client()) if err != nil { return nil, nil, err } diff --git a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go index 5c0c9e4d54..fe384f93e3 100644 --- a/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go +++ b/core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go @@ -99,9 +99,9 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { commitStore, _ := testhelpers.NewFakeCommitStore(t, tc.commitStoreSeqNum) commitStore.SetPaused(tc.commitStoreIsPaused) - sourceReader := ccipdata.NewMockOnRampReader(t) + onRampReader := ccipdata.NewMockOnRampReader(t) if len(tc.sendReqs) > 0 { - sourceReader.On("GetSendRequestsGteSeqNum", ctx, tc.commitStoreSeqNum, sourceFinalityDepth). + onRampReader.On("GetSendRequestsGteSeqNum", ctx, tc.commitStoreSeqNum, sourceFinalityDepth). Return(tc.sendReqs, nil) } @@ -130,7 +130,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) { p.inflightReports = newInflightCommitReportsContainer(time.Hour) p.config.commitStore = commitStore p.offchainConfig.SourceFinalityDepth = uint32(sourceFinalityDepth) - p.config.onRampReader = sourceReader + p.config.onRampReader = onRampReader p.tokenDecimalsCache = tokenDecimalsCache p.config.priceGetter = priceGet p.config.sourceFeeEstimator = sourceFeeEst @@ -234,9 +234,9 @@ func TestCommitReportingPlugin_Report(t *testing.T) { destReader.On("GetGasPriceUpdatesCreatedAfter", ctx, destPriceRegistryAddress, uint64(sourceChainSelector), mock.Anything, 0).Return(tc.gasPriceUpdates, nil) destReader.On("GetTokenPriceUpdatesCreatedAfter", ctx, destPriceRegistryAddress, mock.Anything, 0).Return(tc.tokenPriceUpdates, nil) - sourceReader := ccipdata.NewMockOnRampReader(t) + onRampReader := ccipdata.NewMockOnRampReader(t) if len(tc.sendRequests) > 0 { - sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, 0).Return(tc.sendRequests, nil) + onRampReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, 0).Return(tc.sendRequests, nil) } p := &CommitReportingPlugin{} @@ -244,7 +244,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) { p.inflightReports = newInflightCommitReportsContainer(time.Minute) p.destPriceRegistry = destPriceRegistry p.config.destReader = destReader - p.config.onRampReader = sourceReader + p.config.onRampReader = onRampReader p.config.sourceChainSelector = uint64(sourceChainSelector) aos := make([]types.AttributedObservation, 0, len(tc.observations)) @@ -1024,7 +1024,7 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) { } } - sourceReader := ccipdata.NewMockOnRampReader(t) + onRampReader := ccipdata.NewMockOnRampReader(t) var sendReqs []ccipdata.Event[ccipdata.EVM2EVMMessage] for _, seqNum := range tc.msgSeqNums { sendReqs = append(sendReqs, ccipdata.Event[ccipdata.EVM2EVMMessage]{ @@ -1033,8 +1033,8 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) { }, }) } - sourceReader.On("GetSendRequestsGteSeqNum", ctx, tc.expQueryMin, 0).Return(sendReqs, nil) - p.config.onRampReader = sourceReader + onRampReader.On("GetSendRequestsGteSeqNum", ctx, tc.expQueryMin, 0).Return(sendReqs, nil) + p.config.onRampReader = onRampReader minSeqNum, maxSeqNum, err := p.calculateMinMaxSequenceNumbers(ctx, lggr) if tc.expErr { diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader.go index 81e164d7f6..4d24d8ed17 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader.go @@ -5,6 +5,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" "github.com/pkg/errors" @@ -25,14 +26,20 @@ const ( COMMIT_CCIP_SENDS = "Commit ccip sends" ) +type Hash [32]byte + +func (h Hash) String() string { + return hexutil.Encode(h[:]) +} + // EVM2EVMMessage is the interface for a message sent from the offramp to the onramp // Plugin can operate against any lane version which has a message satisfying this interface. type EVM2EVMMessage struct { SequenceNumber uint64 GasLimit *big.Int Nonce uint64 - MessageId [32]byte - Hash [32]byte + MessageId Hash + Hash Hash // TODO: add more fields as we abstract exec plugin // also this Log can eventually go away with destchain abstractions Log types.Log // Raw event data @@ -48,7 +55,7 @@ type OnRampReader interface { GetSendRequestsBetweenSeqNums(ctx context.Context, seqNumMin, seqNumMax uint64, confs int) ([]Event[EVM2EVMMessage], error) // Get router configured in the onRamp - Router() common.Address + RouterAddress() common.Address // TODO: temporary until we abstract offramp as well // (currently this works since all versions are compatible with the same offramp ABI) diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go index 3d1564db58..0d76638610 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader_mock.go @@ -82,8 +82,8 @@ func (_m *MockOnRampReader) GetSendRequestsGteSeqNum(ctx context.Context, seqNum return r0, r1 } -// Router provides a mock function with given fields: -func (_m *MockOnRampReader) Router() common.Address { +// RouterAddress provides a mock function with given fields: +func (_m *MockOnRampReader) RouterAddress() common.Address { ret := _m.Called() var r0 common.Address diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0.go index 425ac63eba..49232422cf 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0.go @@ -23,6 +23,11 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/utils" ) +const ( + CCIPSendRequestedEventNameV1_0_0 = "CCIPSendRequested" + MetaDataHashPrefixV1_0_0 = "EVM2EVMMessageEvent" +) + var leafDomainSeparator = [1]byte{0x00} type LeafHasherV1_0_0 struct { @@ -38,7 +43,7 @@ func getMetaDataHash[H hashlib.Hash](ctx hashlib.Ctx[H], prefix [32]byte, source func NewLeafHasherV1_0_0(sourceChainSelector uint64, destChainSelector uint64, onRampId common.Address, ctx hashlib.Ctx[[32]byte], onRamp *evm_2_evm_onramp_1_0_0.EVM2EVMOnRamp) *LeafHasherV1_0_0 { return &LeafHasherV1_0_0{ - metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMMessageEvent")), sourceChainSelector, onRampId, destChainSelector), + metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte(MetaDataHashPrefixV1_0_0)), sourceChainSelector, onRampId, destChainSelector), ctx: ctx, onRamp: onRamp, } @@ -120,7 +125,7 @@ func NewOnRampV1_0_0(lggr logger.Logger, sourceSelector, destSelector uint64, on } // Subscribe to the relevant logs name := logpoller.FilterName(COMMIT_CCIP_SENDS, onRampAddress) - eventSig := abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI) + eventSig := abihelpers.GetIDOrPanic(CCIPSendRequestedEventNameV1_0_0, onRampABI) err = sourceLP.RegisterFilter(logpoller.Filter{ Name: name, EventSigs: []common.Hash{eventSig}, @@ -194,7 +199,7 @@ func (o *OnRampV1_0_0) GetSendRequestsGteSeqNum(ctx context.Context, seqNum uint return parseLogs[EVM2EVMMessage](logs, o.lggr, o.logToMessage) } -func (o *OnRampV1_0_0) Router() common.Address { +func (o *OnRampV1_0_0) RouterAddress() common.Address { config, _ := o.onRamp.GetDynamicConfig(nil) return config.Router } diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0_test.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0_test.go index 310ad641e8..0dd306a68d 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0_test.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_0_0_test.go @@ -42,7 +42,7 @@ func TestHasherV1_0_0(t *testing.T) { MessageId: [32]byte{}, } - data, err := onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message) + data, err := onRampABI.Events[CCIPSendRequestedEventNameV1_0_0].Inputs.Pack(message) require.NoError(t, err) hash, err := hasher.HashLeaf(types.Log{Topics: []common.Hash{abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)}, Data: data}) require.NoError(t, err) @@ -68,7 +68,7 @@ func TestHasherV1_0_0(t *testing.T) { MessageId: [32]byte{}, } - data, err = onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message) + data, err = onRampABI.Events[CCIPSendRequestedEventNameV1_0_0].Inputs.Pack(message) require.NoError(t, err) hash, err = hasher.HashLeaf(types.Log{Topics: []common.Hash{abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)}, Data: data}) require.NoError(t, err) @@ -81,6 +81,6 @@ func TestMetaDataHash(t *testing.T) { sourceChainSelector, destChainSelector := uint64(1), uint64(4) onRampAddress := common.HexToAddress("0x5550000000000000000000000000000000000001") ctx := hashlib.NewKeccakCtx() - hash := getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMSubscriptionMessagePlus")), sourceChainSelector, onRampAddress, destChainSelector) - require.Equal(t, "e8b93c9d01a7a72ec6c7235e238701cf1511b267a31fdb78dd342649ee58c08d", hex.EncodeToString(hash[:])) + hash := getMetaDataHash(ctx, ctx.Hash([]byte(MetaDataHashPrefixV1_0_0)), sourceChainSelector, onRampAddress, destChainSelector) + require.Equal(t, "1409948abde219f43870c3d6d1c16beabd8878eb5039a3fa765eb56e4b8ded9e", hex.EncodeToString(hash[:])) } diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_1_0.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_1_0.go index 3d43e00408..eae5758be4 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_1_0.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_1_0.go @@ -32,7 +32,7 @@ func NewOnRampV1_1_0(lggr logger.Logger, sourceSelector, destSelector uint64, on }, nil } -func (o *OnRampV1_1_0) Router() common.Address { +func (o *OnRampV1_1_0) RouterAddress() common.Address { config, _ := o.onRamp.GetDynamicConfig(nil) return config.Router } diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go index a84962dc4a..d3a97a71cd 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go @@ -28,6 +28,9 @@ var ( const ( CCIPSendRequestSeqNumIndexV1_2_0 = 4 + CCIPSendRequestedEventNameV1_2_0 = "CCIPSendRequested" + EVM2EVMOffRampEventNameV1_2_0 = "EVM2EVMMessage" + MetaDataHashPrefixV1_2_0 = "EVM2EVMMessageHashV2" ) func init() { @@ -35,7 +38,7 @@ func init() { if err != nil { panic(err) } - CCIPSendRequestEventSigV1_2_0 = abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI) + CCIPSendRequestEventSigV1_2_0 = abihelpers.GetIDOrPanic(CCIPSendRequestedEventNameV1_2_0, onRampABI) } // Backwards compat for integration tests @@ -44,7 +47,7 @@ func DecodeOffRampMessageV1_2_0(b []byte) (*evm_2_evm_offramp.InternalEVM2EVMMes if err != nil { panic(err) } - event, ok := offRampABI.Events["EVM2EVMMessage"] + event, ok := offRampABI.Events[EVM2EVMOffRampEventNameV1_2_0] if !ok { panic("no such event") } @@ -111,7 +114,7 @@ type LeafHasherV1_2_0 struct { func NewLeafHasherV1_2_0(sourceChainSelector uint64, destChainSelector uint64, onRampId common.Address, ctx hashlib.Ctx[[32]byte], onRamp *evm_2_evm_onramp.EVM2EVMOnRamp) *LeafHasherV1_2_0 { return &LeafHasherV1_2_0{ - metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMMessageHashV2")), sourceChainSelector, onRampId, destChainSelector), + metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte(MetaDataHashPrefixV1_2_0)), sourceChainSelector, onRampId, destChainSelector), ctx: ctx, onRamp: onRamp, } @@ -270,7 +273,7 @@ func (o *OnRampV1_2_0) GetSendRequestsBetweenSeqNums(ctx context.Context, seqNum return parseLogs[EVM2EVMMessage](logs, o.lggr, o.logToMessage) } -func (o *OnRampV1_2_0) Router() common.Address { +func (o *OnRampV1_2_0) RouterAddress() common.Address { config, _ := o.onRamp.GetDynamicConfig(nil) return config.Router } diff --git a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0_test.go b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0_test.go index b50cb08fc2..d271b87654 100644 --- a/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0_test.go +++ b/core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0_test.go @@ -51,7 +51,7 @@ func TestHasherV1_2_0(t *testing.T) { MessageId: [32]byte{}, } - data, err := onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message) + data, err := onRampABI.Events[CCIPSendRequestedEventNameV1_2_0].Inputs.Pack(message) require.NoError(t, err) hash, err := hasher.HashLeaf(types.Log{Topics: []common.Hash{CCIPSendRequestEventSigV1_2_0}, Data: data}) require.NoError(t, err) @@ -78,7 +78,7 @@ func TestHasherV1_2_0(t *testing.T) { MessageId: [32]byte{}, } - data, err = onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message) + data, err = onRampABI.Events[CCIPSendRequestedEventNameV1_2_0].Inputs.Pack(message) require.NoError(t, err) hash, err = hasher.HashLeaf(types.Log{Topics: []common.Hash{CCIPSendRequestEventSigV1_2_0}, Data: data}) require.NoError(t, err)