MessageRecipient
Inherits: IMessageRecipient
State Variables
origin
Local chain Origin: used for sending messages
address public immutable origin;
destination
Local chain Destination: used for receiving messages
address public immutable destination;
Functions
constructor
constructor(address origin_, address destination_);
receiveBaseMessage
Message recipient needs to implement this function in order to receive cross-chain messages.
Message recipient needs to ensure that merkle proof for the message is at least as old as the optimistic period that the recipient is using. Note: as this point it is checked that the "message optimistic period" has passed, however the period value itself could be anything, and thus could differ from the one that the recipient would like to enforce.
function receiveBaseMessage(
uint32 origin_,
uint32 nonce,
bytes32 sender,
uint256 proofMaturity,
uint32 version,
bytes memory content
) external payable;
Parameters
Name | Type | Description |
---|---|---|
origin_ | uint32 | |
nonce | uint32 | Message nonce on the origin domain |
sender | bytes32 | Sender address on origin chain |
proofMaturity | uint256 | Message's merkle proof age in seconds |
version | uint32 | Message version specified by sender |
content | bytes | Raw bytes content of message |
_receiveBaseMessageUnsafe
*Child contracts should implement the logic for receiving a Base Message in an "unsafe way". Following checks HAVE been performed:
- receiveBaseMessage() was called by Destination (i.e. this is a legit base message).
- Nonce is not zero.
- Message sender on origin chain is not a zero address.
- Proof maturity is not zero. Following checks HAVE NOT been performed (thus "unsafe"):
- Message sender on origin chain could be anything non-zero at this point.
- Proof maturity could be anything non-zero at this point.*
function _receiveBaseMessageUnsafe(
uint32 origin_,
uint32 nonce,
bytes32 sender,
uint256 proofMaturity,
uint32 version,
bytes memory content
) internal virtual;
_sendBaseMessage
Sends a message to given destination chain. Full msg.value
is used to pay for the message tips.
_getMinimumTipsValue()
could be used to calculate the minimum required tips value, and should be also
exposed as a public view function to estimate the tips value before sending a message off-chain.
This function is not exposed in MessageRecipient, as the message encoding is implemented by the child contract.
function _sendBaseMessage(
uint32 destination_,
bytes32 recipient,
uint32 optimisticPeriod,
uint256 tipsValue,
MessageRequest memory request,
bytes memory content
) internal returns (uint32 messageNonce, bytes32 messageHash);
Parameters
Name | Type | Description |
---|---|---|
destination_ | uint32 | Domain of the destination chain |
recipient | bytes32 | Address of the recipient on destination chain |
optimisticPeriod | uint32 | Optimistic period for the message |
tipsValue | uint256 | Tips to be paid for sending the message |
request | MessageRequest | Message execution request on destination chain |
content | bytes | The message content |
_getMinimumTipsValue
Returns the minimum tips value for sending a message to given destination chain.
function _getMinimumTipsValue(uint32 destination_, MessageRequest memory request, uint256 contentLength)
internal
view
returns (uint256 tipsValue);
Parameters
Name | Type | Description |
---|---|---|
destination_ | uint32 | Domain of the destination chain |
request | MessageRequest | Message execution request on destination chain |
contentLength | uint256 | Length of the message content |
_encodeRequest
Encodes a message execution request into format that Origin contract is using.
function _encodeRequest(MessageRequest memory request) internal pure returns (uint256 paddedRequest);
Parameters
Name | Type | Description |
---|---|---|
request | MessageRequest | Message execution request on destination chain |
Returns
Name | Type | Description |
---|---|---|
paddedRequest | uint256 | Encoded request |
Structs
MessageRequest
struct MessageRequest {
uint96 gasDrop;
uint64 gasLimit;
uint32 version;
}