Message Structure
Messages contain metadata about the cross-chain transfer and routing information:uint32
required
Message format version (4 bytes)
uint32
required
Domain identifier of the source chain (4 bytes)
uint32
required
Domain identifier of the destination chain (4 bytes)
uint64
required
Destination-specific nonce for replay protection (8 bytes)
In V2, this is expanded to bytes32 (32 bytes)
bytes32
required
Address of sender on source chain as bytes32 (32 bytes, starting at index 20)
bytes32
required
Address of recipient on destination chain as bytes32 (32 bytes, starting at index 52)
bytes32
required
Address authorized to call receiveMessage on destination chain (32 bytes, starting at index 84)Set to bytes32(0) to allow any caller
bytes
required
Dynamic bytes payload containing the burn message or custom data (starting at index 116)
Memory Layout (V1)
Fields use specific padding:
uintNN fields are left-padded, and bytesNN fields are right-padded. This ensures fixed-size encoding and prevents hash collisions.Message V2 Format
Version 2 introduces additional fields for finality control:V2 Key Differences
- nonce: Expanded from
uint64(8 bytes) tobytes32(32 bytes) - minFinalityThreshold: Minimum finality level required for attestation
- finalityThresholdExecuted: Finality level at which message was executed
Encoding Functions
Format Message (V1)
Source: ~/workspace/source/src/messages/Message.sol:66-87abi.encodePacked.
Format Message for Relay (V2)
Source: ~/workspace/source/src/messages/v2/MessageV2.sol:78-101Decoding Functions
All getter functions use TypedMemView for zero-copy operations:V1 Getters
V2 Getters
V2 uses_get prefix and includes additional fields:
Address Conversion
Convert between EVM addresses and bytes32:Address to Bytes32
Source: ~/workspace/source/src/messages/Message.sol:146-148Bytes32 to Address
Source: ~/workspace/source/src/messages/Message.sol:156-158Validation
V1 Validation
Source: ~/workspace/source/src/messages/Message.sol:164-170V2 Validation
Source: ~/workspace/source/src/messages/v2/MessageV2.sol:170-176TypedMemView Usage
Messages use the TypedMemView library for efficient, zero-copy memory operations:bytes29: Efficient memory view type that avoids copying dataindexUint(): Reads uint values at specific byte offsetsindex(): Reads bytes32 values at specific byte offsetsslice(): Creates sub-views without copying data
Example Usage
Encoding a Message
Decoding a Message
See Also
- BurnMessage Format - Message body format for token transfers
- AddressUtils - Address conversion utilities
- MessageTransmitter - Contract that processes messages