Skip to main content

Overview

The IMessageHandler 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)

Source: src/interfaces/IMessageHandler.sol:31

IMessageHandlerV2

V2 introduces finality awareness with separate handlers for finalized and unfinalized messages:
Source: src/interfaces/v2/IMessageHandlerV2.sol:35

Functions

handleReceiveMessage

Handles an incoming message from a Receiver on the destination domain. Parameters:
  • sourceDomain - The source domain ID where the message originated
  • sender - The address of the message sender on the source domain (as bytes32)
  • messageBody - The raw bytes of the message payload
Returns:
  • success - True if the message was processed successfully, false otherwise

handleReceiveFinalizedMessage (V2)

Handles incoming finalized messages (finality threshold >= 2000). Parameters:
  • sourceDomain - The source domain ID where the message originated
  • sender - 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
Returns:
  • success - True if successful, false otherwise

handleReceiveUnfinalizedMessage (V2)

Handles incoming unfinalized messages (finality threshold < 2000). Parameters:
  • sourceDomain - The source domain ID where the message originated
  • sender - 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
Returns:
  • success - True if successful, false otherwise

When to Implement

Implement IMessageHandler 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

The TokenMessenger contract provides a reference implementation:
Source: src/TokenMessenger.sol:313

Key Implementation Requirements

Security Validations

  1. Caller Verification - Only accept calls from the registered MessageTransmitter:
  2. Sender Verification - Validate the remote sender is authorized:
  3. Message Format Validation - Validate message structure and version before processing

Message Processing

  1. Parse the message body according to the expected format
  2. Extract relevant parameters (recipient, amount, token, etc.)
  3. Execute the intended action (mint tokens, trigger hooks, etc.)
  4. 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
Implementations can apply different handling logic based on finality:
  • 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