Skip to content
Lattice

CrosschainLink

Git Source

Inherits: IERC7786Recipient, ICrosschainLink

Title: CrosschainLink

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Adapted for EIP-2535 from OpenZeppelin CrosschainLinked + ERC7786Recipient v5.6.1 (https://github.com/OpenZeppelin/openzeppelin-contracts)

(https://github.com/OpenZeppelin/openzeppelin-contracts/tree/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/crosschain)

Diamond facet that owns the single ERC-7786 receiveMessage selector. It authenticates the calling gateway + source against a per-chain link registry, de-duplicates receiveId, and routes the message to a handler registered for the payload's leading 4-byte tag. Also exposes the send path (sendMessage) to a registered counterpart.

Stateless delegator — all logic and storage live in CrosschainLinkLib. Consumers inherit this facet and add AccessControl + an initializer that calls CrosschainLinkLib.__CrosschainLink_init.

Notes:

  • lattice-version: 0.1.0
  • lattice-source: OpenZeppelin

Functions

receiveMessage

This function may be called directly by the gateway.

Endpoint for receiving cross-chain message.

function receiveMessage(bytes32 receiveId, bytes calldata sender, bytes calldata payload)
        external
        payable
        virtual
        override
        returns (bytes4);

Parameters

NameTypeDescription
receiveIdbytes32
senderbytes
payloadbytes

Returns

NameTypeDescription
<none>bytes4

Returns the gateway and counterpart registered for a source chain.

function getLink(bytes calldata chain)
        external
        view
        virtual
        override
        returns (address gateway, bytes memory counterpart);

Parameters

NameTypeDescription
chainbytesA "chain-only" ERC-7930 interoperable address (empty address).

Returns

NameTypeDescription
gatewayaddressThe ERC-7786 gateway trusted for chain.
counterpartbytesThe full interoperable address authorized to send from chain.

getHandler

Returns the handler registered for a message tag (zero if none).

function getHandler(bytes4 tag) external view virtual override returns (address handler);

Parameters

NameTypeDescription
tagbytes4

Returns

NameTypeDescription
handleraddress

isProcessed

Returns whether a receiveId from gateway has already been processed (keyed per-gateway, as ERC-7786 only guarantees receiveId uniqueness for the calling gateway).

function isProcessed(address gateway, bytes32 receiveId) external view virtual override returns (bool);

Parameters

NameTypeDescription
gatewayaddress
receiveIdbytes32

Returns

NameTypeDescription
<none>bool

Registers (or overrides) the gateway + counterpart for the counterpart's source chain.

Caller must hold DEFAULT_ADMIN_ROLE. Reverts CrosschainLinkAlreadyRegistered if a link exists and allowOverride is false.

function setLink(address gateway, bytes calldata counterpart, bool allowOverride) external virtual override;

Parameters

NameTypeDescription
gatewayaddressThe ERC-7786 gateway for this chain (must implement supportsAttribute).
counterpartbytesThe full interoperable address of the remote counterpart.
allowOverrideboolWhether to overwrite an existing link for the chain.

setHandler

Registers a handler for inbound messages whose payload starts with tag (zero to clear).

Caller must hold DEFAULT_ADMIN_ROLE.

function setHandler(bytes4 tag, address handler) external virtual override;

Parameters

NameTypeDescription
tagbytes4
handleraddress

sendMessage

Sends a message to the counterpart registered for chain via its ERC-7786 gateway.

Caller must hold DEFAULT_ADMIN_ROLE.

function sendMessage(bytes calldata chain, bytes calldata payload, bytes[] calldata attributes)
        external
        virtual
        override
        returns (bytes32 sendId);

Parameters

NameTypeDescription
chainbytesA "chain-only" interoperable address selecting the destination link.
payloadbytesThe message payload (handlers expect a leading 4-byte tag on the receiving side).
attributesbytes[]ERC-7786 gateway attributes (may be empty).

Returns

NameTypeDescription
sendIdbytes32The gateway-assigned send id (zero if no further processing is needed).

exportSelectors

ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).

Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches forge inspect CrosschainLink methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: getHandler(bytes4) 0x6dd99bde getLink(bytes) 0x09b0b794 isProcessed(address,bytes32) 0xffe32a6e receiveMessage(bytes32,bytes,bytes) 0x2432ef26 sendMessage(bytes,bytes,bytes[]) 0xcdfe7f5c setHandler(bytes4,address) 0x42b26650 setLink(address,bytes,bool) 0xf54640d0

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes