Message Bridge

Brevis message bridge enables trust-free cross-chain message passing secured by ZK proof. This section introduces how to integrate dApp contracts with the Brevis message passing framework.
App contracts need to interact with the MessageBridge contract to send and receive cross-chain messages. We provide a dApp contract framework for easier integration. By inheriting the app framework MessageApp.sol, developers only need to focus on the app-specific cross-chain logic.

Send Message

To send cross-chain messages, the dApp contract should call the _sendMessage function of the inherited MessageSenderApp contract.
* @notice Send a message to a contract on another chain.
* @param dstChainId - The destination chain ID.
* @param receiver - The address of the destination app contract.
* @param message - Arbitrary message bytes to the destination app contract.
* @return messageId - Message Id computed by MessageBridge
function _sendMessage(
uint64 dstChainId,
address receiver,
bytes memory message
) internal returns (bytes32)
The function returns the unique message Id computed as a hash of <nonce, sender, receiver, srcChainId, dstChainId, message>, where nonce is maintained and incremented by the MessageBridge contract.

Receive Message

To receive cross-chain messages, the dApp contract should implement the _handleMessage internal function.
* @notice Internally called by the executeMessage function to execute a message
* @param srcChainId - The source chain ID where the message originated from
* @param sender - The address of the source chain message sender
* @param message - Arbitrary message bytes from the source chain sender
* @param executor - Address who called the MessageBridge execution function
function _handleMessage(
uint64 srcChainId,
address sender,
bytes calldata message,
address executor
) internal virtual;