BaseClient

Git Source

Inherits: MessageRecipient

*Implementation of IMessageRecipient interface, to be used as the recipient of base messages passed by the Destination contract. BaseClient could be used as a backbone for cross-chain apps:

  • A single BaseClient contract per chain (aka trusted sender)
  • Only BaseClient instances from other chains are able to send messages to this contract
  • BaseClient enforces a common optimistic period for all types of messages Note: BaseClient is forever stateless, meaning it can be potentially used as a parent for the upgradeable contract without worrying about storage collision.*

Functions

constructor

constructor(address origin_, address destination_) MessageRecipient(origin_, destination_);

optimisticPeriod

Period of time since the root was submitted to Destination. Once this period is over, root can be used for proving and executing a message though this Client.

function optimisticPeriod() public view virtual returns (uint32);

trustedSender

Address of the trusted sender on the destination chain. The trusted sender will be able to:

  • Send messages to this contract from other chains.
  • Receive messages from this contract on other chains.
function trustedSender(uint32 destination) public view virtual returns (bytes32);

_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 override;

_receiveBaseMessage

*Child contracts should implement the logic for receiving a Base Message. 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 a trusted sender (and is not zero).
  • Optimistic period for the message have passed (and is not zero).*
function _receiveBaseMessage(uint32 origin_, uint32 nonce, 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 BaseClient, as the message encoding is implemented by the child contract.

Will revert if the trusted sender is not set for the destination domain.*

function _sendBaseMessage(uint32 destination_, uint256 tipsValue, MessageRequest memory request, bytes memory content)
    internal
    returns (uint32 messageNonce, bytes32 messageHash);

Parameters

NameTypeDescription
destination_uint32Domain of the destination chain
tipsValueuint256Tips to be paid for sending the message
requestMessageRequestEncoded message execution request on destination chain
contentbytesThe message content