Overview
TheMessageTransmitter contract is the core component of CCTP that handles cross-chain message transmission. It manages message dispatch, receipt, and validation, ensuring secure communication between different blockchain domains.
State Variables
Domain of the chain on which the contract is deployed. This is an immutable value set during contract deployment.
Message format version. This is an immutable value that defines the structure of messages handled by this contract.
Maximum size of message body in bytes. This value can be updated by the contract owner to accommodate larger messages.
Next available nonce from this source domain. This counter increments with each message sent to ensure uniqueness.
Functions
sendMessage
Sends a message to the destination domain and recipient.Domain of destination chain
Address of message recipient on destination chain as bytes32
Raw bytes content of message
uint64 - The nonce reserved by the message
Behavior:
- Increments the nonce counter
- Formats the message with version, domains, nonce, sender, and recipient
- Emits a
MessageSentevent with the complete message - Reverts if the contract is paused
- Reverts if message body exceeds
maxMessageBodySize
sendMessageWithCaller
Sends a message to the destination domain and recipient, specifying adestinationCaller that is authorized to receive the message on the destination domain.
Domain of destination chain
Address of message recipient on destination chain as bytes32
Caller on the destination domain, as bytes32. Must be nonzero.
Raw bytes content of message
uint64 - The nonce reserved by the message
receiveMessage
Receives a message from a source domain. Messages with a given nonce can only be broadcast once for a (sourceDomain, destinationDomain) pair.Message bytes containing:
- version (4 bytes, uint32)
- sourceDomain (4 bytes, uint32)
- destinationDomain (4 bytes, uint32)
- nonce (8 bytes, uint64)
- sender (32 bytes, bytes32)
- recipient (32 bytes, bytes32)
- destinationCaller (32 bytes, bytes32)
- messageBody (dynamic bytes)
Concatenated 65-byte signature(s) of
message, in increasing order of the attester address recovered from signatures. Must contain exactly the threshold number of valid signatures.bool - true if successful
Message Format:
| Field | Bytes | Type | Index |
|---|---|---|---|
| version | 4 | uint32 | 0 |
| sourceDomain | 4 | uint32 | 4 |
| destinationDomain | 4 | uint32 | 8 |
| nonce | 8 | uint64 | 12 |
| sender | 32 | bytes32 | 20 |
| recipient | 32 | bytes32 | 52 |
| destinationCaller | 32 | bytes32 | 84 |
| messageBody | dynamic | bytes | 116 |
- Verifies attestation signatures
- Validates message format
- Checks destination domain matches local domain
- Validates destination caller (if specified)
- Validates message version
- Ensures nonce has not been used before
- Marks nonce as used upon successful receipt
- Calls
handleReceiveMessage()on the recipient contract
replaceMessage
Replaces a message with a new message body and/or destination caller. Allows the sender of a previous message to send a new message with the same nonce.Original message to replace
Valid attestation of
originalMessageNew message body of replaced message
The new destination caller, which may be the same as the original destination caller, a new destination caller, or an empty destination caller (bytes32(0), indicating that any destination caller is valid)
- Validates the original attestation signatures
- Verifies msg.sender matches the sender of the original message
- Verifies the source domain of the original message matches local domain
- Reuses the original message’s nonce
- Emits a new
MessageSentevent with the replacement message
The new message will reuse the original message’s nonce. For a given nonce, all replacement message(s) and the original message are valid to broadcast on the destination domain, until the first message at the nonce confirms, at which point all others are invalidated.
setMaxMessageBodySize
Sets the maximum message body size. Only callable by the contract owner.New maximum message body size, in bytes
Events
MessageSent
Emitted when a new message is dispatched.Raw bytes of the complete message including all headers and body
MessageReceived
Emitted when a new message is received.Caller (msg.sender) on destination domain
The source domain this message originated from
The nonce unique to this message
The sender of this message
Message body bytes
MaxMessageBodySizeUpdated
Emitted when the maximum message body size is updated.New maximum message body size, in bytes