@@ -17,9 +17,6 @@ import (
1717)
1818
1919const (
20- // AddressLength is the length of a normalized Wormhole address in bytes.
21- AddressLength = 32
22-
2320 // Wormhole supports arbitrary payloads due to the variance in transaction and block sizes between chains.
2421 // However, during serialization, payload lengths are limited by Go slice length constraints and violations
2522 // of these limits can cause panics.
@@ -54,6 +51,20 @@ const (
5451 // minMsgIdLen is the minimum length of a message ID. It is used to uniquely identify
5552 // messages in the case of a duplicate message ID and is stored in the database.
5653 MinMsgIdLen = len ("1/0000000000000000000000000290fb167208af455bb137780163b7b7a9a10c16/0" )
54+
55+ // fixedFieldsLen is the minimum length of the fixed portion of a message publication.
56+ // It is the sum of the sizes of each of the fields plus length information for the Payload.
57+ // This is used to check that the data is long enough for the rest of the message after reading the TxID.
58+ fixedFieldsLen = 8 + // Timestamp (int64)
59+ 4 + // Nonce (uint32)
60+ 8 + // Sequence (uint64)
61+ 1 + // ConsistencyLevel (uint8)
62+ 2 + // EmitterChain (uint16)
63+ 32 + // EmitterAddress (32 bytes)
64+ 1 + // IsReobservation (bool)
65+ 1 + // Unreliable (bool)
66+ 1 + // verificationState (uint8)
67+ 8 // Payload length (uint64)
5768)
5869
5970var (
@@ -467,7 +478,7 @@ func UnmarshalMessagePublication(data []byte) (*MessagePublication, error) {
467478 }
468479
469480 emitterAddress := vaa.Address {}
470- if n , err := reader .Read (emitterAddress [:]); err != nil || n != AddressLength {
481+ if n , err := reader .Read (emitterAddress [:]); err != nil || n != int ( vaa . AddressLength ) {
471482 return nil , fmt .Errorf ("failed to read emitter address [%d]: %w" , n , err )
472483 }
473484 msg .EmitterAddress = emitterAddress
@@ -492,19 +503,6 @@ func UnmarshalMessagePublication(data []byte) (*MessagePublication, error) {
492503// UnmarshalBinary implements the BinaryUnmarshaler interface for MessagePublication.
493504func (m * MessagePublication ) UnmarshalBinary (data []byte ) error {
494505
495- // fixedFieldsLen is the minimum length of the fixed portion of a message publication.
496- // It is the sum of the sizes of each of the fields plus length information for the Payload.
497- // This is used to check that the data is long enough for the rest of the message after reading the TxID.
498- const fixedFieldsLen = 8 + // Timestamp (int64)
499- 4 + // Nonce (uint32)
500- 8 + // Sequence (uint64)
501- 1 + // ConsistencyLevel (uint8)
502- 2 + // EmitterChain (uint16)
503- 32 + // EmitterAddress (32 bytes)
504- 1 + // IsReobservation (bool)
505- 1 + // Unreliable (bool)
506- 8 // Payload length (uint64)
507-
508506 // Calculate minimum required length for the fixed portion
509507 // (excluding variable-length fields: TxID and Payload)
510508 if len (data ) < marshaledMsgLenMin {
0 commit comments