@@ -82,6 +82,10 @@ func (h *MessageHasherV1) Hash(ctx context.Context, report *codec.ExecutionRepor
8282 return [32 ]byte {}, fmt .Errorf ("compute metadata hash: %w" , err )
8383 }
8484
85+ if len (report .Message .Header .MessageID ) != 32 {
86+ h .lggr .Warnw ("Invalid message ID length, messageID will be padded or truncated" , "messageID" , report .Message .Header .MessageID )
87+ }
88+
8589 var messageID [32 ]byte
8690 copy (messageID [:], report .Message .Header .MessageID )
8791
@@ -169,13 +173,21 @@ func computeMessageDataHash(
169173
170174 // Manually encode tokens to match the Move implementation
171175 var tokenHashData []byte
172- tokenHashData = append (tokenHashData , encodeUint256 (big .NewInt (int64 (len (tokenAmounts ))))... )
176+ encodedLen , err := encodeUint256 (big .NewInt (int64 (len (tokenAmounts ))))
177+ if err != nil {
178+ return [32 ]byte {}, fmt .Errorf ("failed to encode token length: %w" , err )
179+ }
180+ tokenHashData = append (tokenHashData , encodedLen ... )
173181 for _ , token := range tokenAmounts {
174182 tokenHashData = append (tokenHashData , encodeBytes (token .SourcePoolAddress )... )
175183 tokenHashData = append (tokenHashData , token .DestTokenAddress [:]... )
176184 tokenHashData = append (tokenHashData , encodeUint32 (token .DestGasAmount )... )
177185 tokenHashData = append (tokenHashData , encodeBytes (token .ExtraData )... )
178- tokenHashData = append (tokenHashData , encodeUint256 (token .Amount )... )
186+ encodedAmount , err := encodeUint256 (token .Amount )
187+ if err != nil {
188+ return [32 ]byte {}, fmt .Errorf ("failed to encode token amount: %w" , err )
189+ }
190+ tokenHashData = append (tokenHashData , encodedAmount ... )
179191 }
180192 tokenAmountsHash := crypto .Keccak256Hash (tokenHashData )
181193
@@ -242,8 +254,12 @@ func computeMetadataHash(
242254 return metadataHash , nil
243255}
244256
245- func encodeUint256 (n * big.Int ) []byte {
246- return common .LeftPadBytes (n .Bytes (), 32 )
257+ func encodeUint256 (n * big.Int ) ([]byte , error ) {
258+ if n == nil {
259+ return []byte {}, fmt .Errorf ("nil big.Int cannot be encoded" )
260+ }
261+
262+ return common .LeftPadBytes (n .Bytes (), 32 ), nil
247263}
248264
249265func encodeUint32 (n uint32 ) []byte {
0 commit comments