44 "context"
55 "errors"
66 "fmt"
7+ "math"
78 "math/big"
89 "strings"
910
@@ -71,13 +72,8 @@ func (h *MessageHasherV1) Hash(ctx context.Context, msg ccipocr3common.Message)
7172 return [32 ]byte {}, fmt .Errorf ("failed to decode dest exec data: %w" , err )
7273 }
7374
74- destGasAmountValue , ok := destExecDataDecodedMap ["destGasAmount" ]
75- if ! ok {
76- return [32 ]byte {}, errors .New ("destGasAmount not found in destExecDataDecodedMap" )
77- }
78-
79- destGasAmount , ok := destGasAmountValue .(uint32 )
80- if ! ok {
75+ destGasAmount , err := extractDestGasAmountFromMap (destExecDataDecodedMap )
76+ if err != nil {
8177 return [32 ]byte {}, fmt .Errorf ("invalid type for destGasAmount, expected uint32, got %T" , destGasAmount )
8278 }
8379
@@ -306,10 +302,20 @@ func parseExtraDataMap(input map[string]any) (*big.Int, [32]byte, error) {
306302 if ! ok {
307303 return nil , [32 ]byte {}, errors .New ("token receiver not found in extra data map" )
308304 }
309- tokenReceiverBytes , ok := tokenReceiver .([32 ]byte )
310- if ! ok {
311- return nil , [32 ]byte {}, errors .New ("token receiver not a [32]byte" )
305+
306+ tokenReceiverBytes := [32 ]byte {}
307+ switch v := tokenReceiver .(type ) {
308+ case [32 ]byte :
309+ tokenReceiverBytes = v
310+ case []byte : // LOOP gRPC converts [32]byte -> []byte
311+ if len (v ) != 32 {
312+ return nil , [32 ]byte {}, fmt .Errorf ("invalid length for TokenReceiver: expected 32, got %d" , len (v ))
313+ }
314+ copy (tokenReceiverBytes [:], v )
315+ default :
316+ return nil , [32 ]byte {}, fmt .Errorf ("invalid type for TokenReceiver, expected [32]byte, got %T" , tokenReceiver )
312317 }
318+
313319 return outputGasInt , tokenReceiverBytes , nil
314320}
315321
@@ -319,11 +325,17 @@ func extractDestGasAmountFromMap(input map[string]any) (uint32, error) {
319325 lowercase := strings .ToLower (fieldName )
320326 switch lowercase {
321327 case "destgasamount" :
322- // Expect uint32
323- if val , ok := fieldValue .(uint32 ); ok {
324- return val , nil
328+ switch v := fieldValue .(type ) {
329+ case uint32 :
330+ return v , nil
331+ case int64 : // LOOP converts expected uint32 to int64
332+ if v > math .MaxUint32 {
333+ return 0 , fmt .Errorf ("destGasAmount exceeds uint32 max, got %d" , v )
334+ }
335+ return uint32 (v ), nil //nolint:gosec // G115: validated to be within uint32 max above
336+ default :
337+ return 0 , errors .New ("invalid type for destgasamount, expected uint32 or int64" )
325338 }
326- return 0 , errors .New ("invalid type for destgasamount, expected uint32" )
327339 default :
328340 }
329341 }
0 commit comments