BaseMessageLib

Git Source

BaseMessage structure represents a base message sent via the Origin-Destination contracts.

  • It only contains data relevant to the base message, the rest of data is encoded in the message header.
  • sender and recipient for EVM chains are EVM addresses casted to bytes32, while preserving left-alignment.
  • tips and request parameters are specified by a message sender

Origin will calculate minimum tips for given request and content length, and will reject messages with tips lower than that.

Memory layout of BaseMessage fields

PositionFieldTypeBytesDescription
[000..032)tipsuint25632Encoded tips paid on origin chain
[032..064)senderbytes3232Sender address on origin chain
[064..096)recipientbytes3232Recipient address on destination chain
[096..116)requestuint16020Encoded request for message execution
[104..AAA)contentbytes??Content to be passed to recipient

State Variables

OFFSET_TIPS

The variables below are not supposed to be used outside of the library directly.

uint256 private constant OFFSET_TIPS = 0;

OFFSET_SENDER

uint256 private constant OFFSET_SENDER = 32;

OFFSET_RECIPIENT

uint256 private constant OFFSET_RECIPIENT = 64;

OFFSET_REQUEST

uint256 private constant OFFSET_REQUEST = OFFSET_RECIPIENT + TIPS_LENGTH;

OFFSET_CONTENT

uint256 private constant OFFSET_CONTENT = OFFSET_REQUEST + REQUEST_LENGTH;

Functions

formatBaseMessage

Returns a formatted BaseMessage payload with provided fields.

function formatBaseMessage(Tips tips_, bytes32 sender_, bytes32 recipient_, Request request_, bytes memory content_)
    internal
    pure
    returns (bytes memory);

Parameters

NameTypeDescription
tips_TipsEncoded tips information
sender_bytes32Sender address on origin chain
recipient_bytes32Recipient address on destination chain
request_RequestEncoded request for message execution
content_bytesRaw content to be passed to recipient on destination chain

Returns

NameTypeDescription
<none>bytesFormatted base message

castToBaseMessage

Returns a BaseMessage view over the given payload.

Will revert if the payload is not a base message.

function castToBaseMessage(bytes memory payload) internal pure returns (BaseMessage);

castToBaseMessage

Casts a memory view to a BaseMessage view.

Will revert if the memory view is not over a base message payload.

function castToBaseMessage(MemView memView) internal pure returns (BaseMessage);

isBaseMessage

Checks that a payload is a formatted BaseMessage.

function isBaseMessage(MemView memView) internal pure returns (bool);

unwrap

Convenience shortcut for unwrapping a view.

function unwrap(BaseMessage baseMessage) internal pure returns (MemView);

leaf

Returns baseMessage's hash: a leaf to be inserted in the "Message mini-Merkle tree".

function leaf(BaseMessage baseMessage) internal pure returns (bytes32);

bodyLeaf

Returns hash for the "everything but tips" part of the base message.

function bodyLeaf(BaseMessage baseMessage) internal pure returns (bytes32);

tips

Returns encoded tips paid on origin chain.

function tips(BaseMessage baseMessage) internal pure returns (Tips);

sender

Returns sender address on origin chain.

function sender(BaseMessage baseMessage) internal pure returns (bytes32);

recipient

Returns recipient address on destination chain.

function recipient(BaseMessage baseMessage) internal pure returns (bytes32);

request

Returns an encoded request for message execution on destination chain.

function request(BaseMessage baseMessage) internal pure returns (Request);

content

Returns an untyped memory view over the content to be passed to recipient.

function content(BaseMessage baseMessage) internal pure returns (MemView);