From a1fd4dd94ebf1dd8535d7578d97de395272dbb1c Mon Sep 17 00:00:00 2001 From: Joe Huang Date: Mon, 2 Dec 2024 17:31:30 -0600 Subject: [PATCH] add more validation checks --- .../ccip/ccipevm/executecodecv2.go | 28 ++++++++++++++----- .../ccip/ccipevm/executecodecv2_test.go | 6 ++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/capabilities/ccip/ccipevm/executecodecv2.go b/core/capabilities/ccip/ccipevm/executecodecv2.go index 8e3f4a8e065..9f52bed604d 100644 --- a/core/capabilities/ccip/ccipevm/executecodecv2.go +++ b/core/capabilities/ccip/ccipevm/executecodecv2.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math/big" commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/codec" @@ -40,17 +41,30 @@ func NewExecutePluginCodecV2() *ExecutePluginCodecV2 { } func validate(report cciptypes.ExecutePluginReport) error { - for _, chainReport := range report.ChainReports { + for i, chainReport := range report.ChainReports { if chainReport.ProofFlagBits.IsEmpty() { - return fmt.Errorf("proof flag bits are empty") + return errors.New("proof flag bits are empty") } - evmProofs := make([][32]byte, 0, len(chainReport.Proofs)) - for _, proof := range chainReport.Proofs { - evmProofs = append(evmProofs, proof) - } + for j, message := range chainReport.Messages { + // optional fields + if message.FeeToken == nil { + report.ChainReports[i].Messages[j].FeeToken = []byte{} + } + + if message.FeeValueJuels.IsEmpty() { + report.ChainReports[i].Messages[j].FeeValueJuels = cciptypes.NewBigInt(big.NewInt(0)) + } + + if message.FeeTokenAmount.IsEmpty() { + report.ChainReports[i].Messages[j].FeeTokenAmount = cciptypes.NewBigInt(big.NewInt(0)) + } + + // required fields + if message.Sender == nil { + return errors.New("message sender is nil") + } - for _, message := range chainReport.Messages { for _, tokenAmount := range message.TokenAmounts { if tokenAmount.Amount.IsEmpty() { return fmt.Errorf("empty amount for token: %s", tokenAmount.DestTokenAddress) diff --git a/core/capabilities/ccip/ccipevm/executecodecv2_test.go b/core/capabilities/ccip/ccipevm/executecodecv2_test.go index bfb150ea2af..7f22ac9a842 100644 --- a/core/capabilities/ccip/ccipevm/executecodecv2_test.go +++ b/core/capabilities/ccip/ccipevm/executecodecv2_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestCodec_ExecReportV2(t *testing.T) { +func TestExecuteCodec(t *testing.T) { d := testSetup(t) input := randomExecuteReport(t, d) c, err := codec.NewCodec(execCodecConfig) @@ -71,7 +71,7 @@ func TestExecutePluginCodecV2(t *testing.T) { assert.Error(t, err) return } - assert.NoError(t, err) + require.NoError(t, err) testSetup(t) @@ -88,7 +88,7 @@ func TestExecutePluginCodecV2(t *testing.T) { // decode using the codec codecDecoded, err := cd.Decode(ctx, bytes) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, report, codecDecoded) }) }