Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/capabilities/ccip/ccipaptos/msghasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ func parseExtraDataMap(input map[string]any) (*big.Int, error) {
lowercase := strings.ToLower(fieldName)
switch lowercase {
case "gaslimit":
// Expect [][32]byte
if val, ok := fieldValue.(*big.Int); ok {
outputGas = val
return outputGas, nil
Expand Down
40 changes: 26 additions & 14 deletions core/capabilities/ccip/ccipsui/msghasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"math/big"
"strings"

Expand Down Expand Up @@ -71,13 +72,8 @@ func (h *MessageHasherV1) Hash(ctx context.Context, msg ccipocr3common.Message)
return [32]byte{}, fmt.Errorf("failed to decode dest exec data: %w", err)
}

destGasAmountValue, ok := destExecDataDecodedMap["destGasAmount"]
if !ok {
return [32]byte{}, errors.New("destGasAmount not found in destExecDataDecodedMap")
}

destGasAmount, ok := destGasAmountValue.(uint32)
if !ok {
destGasAmount, err := extractDestGasAmountFromMap(destExecDataDecodedMap)
if err != nil {
return [32]byte{}, fmt.Errorf("invalid type for destGasAmount, expected uint32, got %T", destGasAmount)
}

Expand Down Expand Up @@ -306,10 +302,20 @@ func parseExtraDataMap(input map[string]any) (*big.Int, [32]byte, error) {
if !ok {
return nil, [32]byte{}, errors.New("token receiver not found in extra data map")
}
tokenReceiverBytes, ok := tokenReceiver.([32]byte)
if !ok {
return nil, [32]byte{}, errors.New("token receiver not a [32]byte")

tokenReceiverBytes := [32]byte{}
switch v := tokenReceiver.(type) {
case [32]byte:
tokenReceiverBytes = v
case []byte: // LOOP gRPC converts [32]byte -> []byte
if len(v) != 32 {
return nil, [32]byte{}, fmt.Errorf("invalid length for TokenReceiver: expected 32, got %d", len(v))
}
copy(tokenReceiverBytes[:], v)
default:
return nil, [32]byte{}, fmt.Errorf("invalid type for TokenReceiver, expected [32]byte, got %T", tokenReceiver)
}

return outputGasInt, tokenReceiverBytes, nil
}

Expand All @@ -319,11 +325,17 @@ func extractDestGasAmountFromMap(input map[string]any) (uint32, error) {
lowercase := strings.ToLower(fieldName)
switch lowercase {
case "destgasamount":
// Expect uint32
if val, ok := fieldValue.(uint32); ok {
return val, nil
switch v := fieldValue.(type) {
case uint32:
return v, nil
case int64: // LOOP converts expected uint32 to int64
if v > math.MaxUint32 {
return 0, fmt.Errorf("destGasAmount exceeds uint32 max, got %d", v)
}
return uint32(v), nil //nolint:gosec // G115: validated to be within uint32 max above
Comment thread
krebernisak marked this conversation as resolved.
default:
return 0, errors.New("invalid type for destgasamount, expected uint32 or int64")
}
Comment on lines +328 to 338
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior is added here to accept LOOP-converted destGasAmount values (int64uint32 with bounds checks), but there are no tests covering this conversion (including boundary cases like negative values and values > MaxUint32). Please add unit tests for extractDestGasAmountFromMap similar to the existing parseExtraDataMap tests.

Copilot generated this review using guidance from repository custom instructions.
return 0, errors.New("invalid type for destgasamount, expected uint32")
default:
}
}
Expand Down
77 changes: 77 additions & 0 deletions core/capabilities/ccip/ccipsui/msghasher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package ccipsui

import (
"math/big"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestParseExtraDataMap(t *testing.T) {
tokenReceiverExample := [32]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20}

tests := []struct {
name string
input map[string]any
want *struct {
gasLimit *big.Int
tokenReceiver [32]byte
}
expectErr bool
}{
{
name: "valid input with [32]byte for tokenReceiver",
input: map[string]any{
"gasLimit": new(big.Int).SetInt64(500000),
"tokenReceiver": [32]byte{0x01},
},
want: &struct {
gasLimit *big.Int
tokenReceiver [32]byte
}{
gasLimit: new(big.Int).SetInt64(500000),
tokenReceiver: [32]byte{0x01},
},
expectErr: false,
},
{
name: "valid input with []byte for tokenReceiver",
input: map[string]any{
"gasLimit": new(big.Int).SetInt64(500000),
"tokenReceiver": tokenReceiverExample[:], // convert to slice for input
},
want: &struct {
gasLimit *big.Int
tokenReceiver [32]byte
}{
gasLimit: new(big.Int).SetInt64(500000),
tokenReceiver: tokenReceiverExample,
},
expectErr: false,
},
{
name: "invalid input with []byte for tokenReceiver",
input: map[string]any{
"gasLimit": new(big.Int).SetInt64(500000),
"tokenReceiver": tokenReceiverExample[:16], // 16 bytes, we expect an error due to length
},
want: nil,
expectErr: true,
},
}

// Run tests
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gasLimit, tokenReceiver, err := parseExtraDataMap(tt.input)
if tt.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tt.want.gasLimit, gasLimit)
assert.Equal(t, tt.want.tokenReceiver, tokenReceiver)
}
})
}
}
2 changes: 1 addition & 1 deletion deployment/ccip/shared/stateview/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,10 @@ func (c CCIPOnChainState) SupportedChains() map[uint64]struct{} {
for chain := range c.SuiChains {
chains[chain] = struct{}{}
}

for chain := range c.TonChains {
chains[chain] = struct{}{}
}

return chains
}

Expand Down
Loading