Skip to content

Commit

Permalink
add more validation checks
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Dec 2, 2024
1 parent a41ccbb commit a1fd4dd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
28 changes: 21 additions & 7 deletions core/capabilities/ccip/ccipevm/executecodecv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions core/capabilities/ccip/ccipevm/executecodecv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestExecutePluginCodecV2(t *testing.T) {
assert.Error(t, err)
return
}
assert.NoError(t, err)
require.NoError(t, err)

testSetup(t)

Expand All @@ -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)
})
}
Expand Down

0 comments on commit a1fd4dd

Please sign in to comment.