Overview
TheIMessageHandler interface defines the contract for receiving and processing cross-chain messages on the destination domain. Contracts implementing this interface can handle messages forwarded from the MessageReceiver after validation.
Interface Definition
IMessageHandler (V1)
src/interfaces/IMessageHandler.sol:31
IMessageHandlerV2
V2 introduces finality awareness with separate handlers for finalized and unfinalized messages:src/interfaces/v2/IMessageHandlerV2.sol:35
Functions
handleReceiveMessage
sourceDomain- The source domain ID where the message originatedsender- The address of the message sender on the source domain (as bytes32)messageBody- The raw bytes of the message payload
success- True if the message was processed successfully, false otherwise
handleReceiveFinalizedMessage (V2)
sourceDomain- The source domain ID where the message originatedsender- The address of the message sender on the source domain (as bytes32)finalityThresholdExecuted- The finality threshold at which the message was attested (>= 2000)messageBody- The raw bytes of the message payload
success- True if successful, false otherwise
handleReceiveUnfinalizedMessage (V2)
sourceDomain- The source domain ID where the message originatedsender- The address of the message sender on the source domain (as bytes32)finalityThresholdExecuted- The finality threshold at which the message was attested (< 2000)messageBody- The raw bytes of the message payload
success- True if successful, false otherwise
When to Implement
ImplementIMessageHandler when your contract needs to:
- Receive and process cross-chain messages from CCTP
- Handle token transfers with custom logic on the destination chain
- Act as the recipient endpoint in cross-chain communication
- Process burn messages for token minting operations
Implementation Example
TheTokenMessenger contract provides a reference implementation:
src/TokenMessenger.sol:313
Key Implementation Requirements
Security Validations
-
Caller Verification - Only accept calls from the registered MessageTransmitter:
-
Sender Verification - Validate the remote sender is authorized:
- Message Format Validation - Validate message structure and version before processing
Message Processing
- Parse the message body according to the expected format
- Extract relevant parameters (recipient, amount, token, etc.)
- Execute the intended action (mint tokens, trigger hooks, etc.)
- Return true on success, false on failure
V2 Enhancements
Version 2 introduces finality awareness:- Finalized Messages (threshold >= 2000): Messages with strong finality guarantees
- Unfinalized Messages (threshold < 2000): Messages with probabilistic finality
Related Interfaces
- IReceiver - Receives and validates messages before forwarding to handlers
- ITokenMinter - Mints and burns tokens in response to cross-chain transfers
- IRelayer - Sends messages from source to destination domains