MessageRecipient

Git Source

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

NameTypeDescription
origin_uint32
nonceuint32Message nonce on the origin domain
senderbytes32Sender address on origin chain
proofMaturityuint256Message's merkle proof age in seconds
versionuint32Message version specified by sender
contentbytesRaw 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

NameTypeDescription
destination_uint32Domain of the destination chain
recipientbytes32Address of the recipient on destination chain
optimisticPerioduint32Optimistic period for the message
tipsValueuint256Tips to be paid for sending the message
requestMessageRequestMessage execution request on destination chain
contentbytesThe 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

NameTypeDescription
destination_uint32Domain of the destination chain
requestMessageRequestMessage execution request on destination chain
contentLengthuint256Length 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

NameTypeDescription
requestMessageRequestMessage execution request on destination chain

Returns

NameTypeDescription
paddedRequestuint256Encoded request

Structs

MessageRequest

struct MessageRequest {
    uint96 gasDrop;
    uint64 gasLimit;
    uint32 version;
}