HeaderLib

Git Source

Library for formatting the header part of the messages used by Origin and Destination.

  • Header represents general information for routing a Message for Origin and Destination.
  • Header occupies a single storage word, and thus is stored on stack instead of being stored in memory.

Header stack layout (from highest bits to lowest)

PositionFieldTypeBytesDescription
(017..016]flaguint81Flag specifying the type of message
(016..012]originuint324Domain where message originated
(012..008]nonceuint324Message nonce on the origin domain
(008..004]destinationuint324Domain where message will be executed
(004..000]optimisticPerioduint324Optimistic period that will be enforced

State Variables

SHIFT_FLAG

Amount of bits to shift to flag field

uint136 private constant SHIFT_FLAG = 16 * 8;

SHIFT_ORIGIN

Amount of bits to shift to origin field

uint136 private constant SHIFT_ORIGIN = 12 * 8;

SHIFT_NONCE

Amount of bits to shift to nonce field

uint136 private constant SHIFT_NONCE = 8 * 8;

SHIFT_DESTINATION

Amount of bits to shift to destination field

uint136 private constant SHIFT_DESTINATION = 4 * 8;

Functions

encodeHeader

Returns an encoded header with provided fields

function encodeHeader(MessageFlag flag_, uint32 origin_, uint32 nonce_, uint32 destination_, uint32 optimisticPeriod_)
    internal
    pure
    returns (Header);

Parameters

NameTypeDescription
flag_MessageFlag
origin_uint32Domain of origin chain
nonce_uint32Message nonce on origin chain
destination_uint32Domain of destination chain
optimisticPeriod_uint32Optimistic period for message execution

isHeader

Checks that the header is a valid encoded header.

function isHeader(uint256 paddedHeader) internal pure returns (bool);

wrapPadded

Wraps the padded encoded request into a Header-typed value.

The "padded" header is simply an encoded header casted to uint256 (highest bits are set to zero). Casting to uint256 is done automatically in Solidity, so no extra actions from consumers are needed. The highest bits are discarded, so that the contracts dealing with encoded headers don't need to be updated, if a new field is added.

function wrapPadded(uint256 paddedHeader) internal pure returns (Header);

leaf

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

function leaf(Header header) internal pure returns (bytes32 hashedHeader);

flag

Returns header's flag field

function flag(Header header) internal pure returns (MessageFlag);

origin

Returns header's origin field

function origin(Header header) internal pure returns (uint32);

nonce

Returns header's nonce field

function nonce(Header header) internal pure returns (uint32);

destination

Returns header's destination field

function destination(Header header) internal pure returns (uint32);

optimisticPeriod

Returns header's optimistic seconds field

function optimisticPeriod(Header header) internal pure returns (uint32);

_flag

Returns header's flag field without casting to MessageFlag

function _flag(uint256 paddedHeader) private pure returns (uint8);