ReceiptLib

Git Source

Receipt structure represents a Notary statement that a certain message has been executed in ExecutionHub.

  • It is possible to prove the correctness of the tips payload using the message hash, therefore tips are not included in the receipt.
  • Receipt is signed by a Notary and submitted to Summit in order to initiate the tips distribution for an executed message.
  • If a message execution fails the first time, the finalExecutor field will be set to zero address. In this case, when the message is finally executed successfully, the finalExecutor field will be updated. Both receipts will be considered valid.

Memory layout of Receipt fields

PositionFieldTypeBytesDescription
[000..004)originuint324Domain where message originated
[004..008)destinationuint324Domain where message was executed
[008..040)messageHashbytes3232Hash of the message
[040..072)snapshotRootbytes3232Snapshot root used for proving the message
[072..073)stateIndexuint81Index of state used for the snapshot proof
[073..093)attNotaryaddress20Notary who posted attestation with snapshot root
[093..113)firstExecutoraddress20Executor who performed first valid execution
[113..133)finalExecutoraddress20Executor who successfully executed the message

State Variables

OFFSET_ORIGIN

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

uint256 private constant OFFSET_ORIGIN = 0;

OFFSET_DESTINATION

uint256 private constant OFFSET_DESTINATION = 4;

OFFSET_MESSAGE_HASH

uint256 private constant OFFSET_MESSAGE_HASH = 8;

OFFSET_SNAPSHOT_ROOT

uint256 private constant OFFSET_SNAPSHOT_ROOT = 40;

OFFSET_STATE_INDEX

uint256 private constant OFFSET_STATE_INDEX = 72;

OFFSET_ATT_NOTARY

uint256 private constant OFFSET_ATT_NOTARY = 73;

OFFSET_FIRST_EXECUTOR

uint256 private constant OFFSET_FIRST_EXECUTOR = 93;

OFFSET_FINAL_EXECUTOR

uint256 private constant OFFSET_FINAL_EXECUTOR = 113;

Functions

formatReceipt

Returns a formatted Receipt payload with provided fields.

function formatReceipt(
    uint32 origin_,
    uint32 destination_,
    bytes32 messageHash_,
    bytes32 snapshotRoot_,
    uint8 stateIndex_,
    address attNotary_,
    address firstExecutor_,
    address finalExecutor_
) internal pure returns (bytes memory);

Parameters

NameTypeDescription
origin_uint32Domain where message originated
destination_uint32Domain where message was executed
messageHash_bytes32Hash of the message
snapshotRoot_bytes32Snapshot root used for proving the message
stateIndex_uint8Index of state used for the snapshot proof
attNotary_addressNotary who posted attestation with snapshot root
firstExecutor_addressExecutor who performed first valid execution attempt
finalExecutor_addressExecutor who successfully executed the message

Returns

NameTypeDescription
<none>bytesFormatted receipt

castToReceipt

Returns a Receipt view over the given payload.

Will revert if the payload is not a receipt.

function castToReceipt(bytes memory payload) internal pure returns (Receipt);

castToReceipt

Casts a memory view to a Receipt view.

Will revert if the memory view is not over a receipt.

function castToReceipt(MemView memView) internal pure returns (Receipt);

isReceipt

Checks that a payload is a formatted Receipt.

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

hashValid

Returns the hash of an Receipt, that could be later signed by a Notary to signal that the receipt is valid.

function hashValid(Receipt receipt) internal pure returns (bytes32);

hashInvalid

Returns the hash of a Receipt, that could be later signed by a Guard to signal that the receipt is invalid.

function hashInvalid(Receipt receipt) internal pure returns (bytes32);

unwrap

Convenience shortcut for unwrapping a view.

function unwrap(Receipt receipt) internal pure returns (MemView);

equals

Compares two Receipt structures.

function equals(Receipt a, Receipt b) internal pure returns (bool);

origin

Returns receipt's origin field

function origin(Receipt receipt) internal pure returns (uint32);

destination

Returns receipt's destination field

function destination(Receipt receipt) internal pure returns (uint32);

messageHash

Returns receipt's "message hash" field

function messageHash(Receipt receipt) internal pure returns (bytes32);

snapshotRoot

Returns receipt's "snapshot root" field

function snapshotRoot(Receipt receipt) internal pure returns (bytes32);

stateIndex

Returns receipt's "state index" field

function stateIndex(Receipt receipt) internal pure returns (uint8);

attNotary

Returns receipt's "attestation notary" field

function attNotary(Receipt receipt) internal pure returns (address);

firstExecutor

Returns receipt's "first executor" field

function firstExecutor(Receipt receipt) internal pure returns (address);

finalExecutor

Returns receipt's "final executor" field

function finalExecutor(Receipt receipt) internal pure returns (address);