Receive a message
To deliver interchain messages, the relayer calls Mailbox.process()
.
This function takes as parameters the message to deliver, as well as arbitrary metadata that can be specified by the relayer.
The Mailbox
will pass the message and metadata to the recipient's Interchain Security Module (ISM) for verification. If the ISM successfully verifies the message, the Mailbox
delivers the message to the recipient by calling recipient.handle()
.
See Message.sol
for more details on Hyperlane message encoding
Handle
This function is called by the Mailbox
contract when a message is received.
To ensure only valid interchain messages are accepted, it is important to restrict access control to the Mailbox address.
- Solidity
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _message
) external payable;
Parameters
origin
: Domain of origin chainsender
: Address of sender on origin chain as bytes32messageBody
: Raw bytes content of message body
Sender addresses are left-padded to bytes32
for compatibility with virtual machines that are addressed differently. The following utility is provided in the TypeCasts
library for convenience.
// alignment preserving cast
function bytes32ToAddress(bytes32 _buf) internal pure returns (address) {
require(
uint256(_buf) <= uint256(type(uint160).max),
Access Control
The handle
function should be restricted to the Mailbox address if the contract should only accept calls from interchain messages.
The following utility is provided in the MailboxClient
library for convenience.
- Solidity
require(
Address.isContract(_contract),
"MailboxClient: invalid mailbox"
);
_;
}
Examples
- Solidity
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _data
) external payable virtual override {
emit ReceivedMessage(_origin, _sender, msg.value, string(_data));
lastSender = _sender;
lastData = _data;
}
Verify
When a message is received, the Mailbox will verify security with an Interchain Security Module before calling the message recipient's handle
.
Default Security
To query the default ISM address, you can call the defaultIsm
function.
- Solidity
function defaultHook() external view returns (IPostDispatchHook);
Modular Security
To leverage Hyperlane's modular security, message recipients can specify a custom Interchain Security Module to verify anything about incoming messages. The Mailbox will defer to this ISM when specified.