Skip to content
Lattice

L2ToL2CrossDomainMessengerGatewayAdapter

Git Source

Inherits: IERC7786GatewaySource, IL2ToL2CrossDomainMessengerGatewayAdapter

Title: L2ToL2CrossDomainMessengerGatewayAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Optimism (https://github.com/ethereum-optimism/optimism)

ERC-7786 cross-chain gateway facet over the OP Superchain L2ToL2CrossDomainMessenger predeploy. sendMessage dispatches a message via the messenger (no fee); receiveCrossChainMessage is the messenger-invoked delivery callback on the destination adapter. EVM (Superchain) chains only.

Stateless delegator — logic/storage live in L2ToL2CrossDomainMessengerGatewayAdapterLib. The messenger routes by BARE EVM chainId (no eid/selector map); the trusted-remote registry is a single chainId ⇒ remoteAdapter mapping. INVERTED INBOUND AUTH: the messenger CALLs receiveCrossChainMessage as the _target during relayMessage, so msg.sender is the messenger predeploy — the remote gateway is authenticated out-of-band via crossDomainMessageContext, not from msg.sender.

Notes:

  • lattice-version: 0.1.0
  • lattice-source: Optimism

Functions

sendMessage

If any of the attributes is not supported, this function SHOULD revert with an

UnsupportedAttribute error. Other errors SHOULD revert with errors not specified in ERC-7786.

Endpoint for creating a new message. If the message requires further (gateway specific) processing before it can be sent to the destination chain, then a non-zero sendId must be returned. Otherwise, the message MUST be sent and this function must return 0.

function sendMessage(bytes calldata recipient, bytes calldata payload, bytes[] calldata attributes)
        external
        payable
        virtual
        returns (bytes32);

Parameters

NameTypeDescription
recipientbytes
payloadbytes
attributesbytes[]

Returns

NameTypeDescription
<none>bytes32

supportsAttribute

Getter to check whether an attribute is supported or not.

function supportsAttribute(bytes4 selector) external pure virtual returns (bool);

Parameters

NameTypeDescription
selectorbytes4

Returns

NameTypeDescription
<none>bool

receiveCrossChainMessage

Inbound delivery callback the messenger invokes on THIS adapter during relayMessage. Authenticates the messenger + the authenticated cross-domain (source, sender) against the registered remote adapter, de-dups, then hands off to the ERC-7930 recipient via the IERC7786Recipient handshake.

function receiveCrossChainMessage(
        bytes calldata sender,
        bytes calldata recipient,
        bytes calldata payload,
        uint256 nonce
    ) external virtual;

Parameters

NameTypeDescription
senderbytesThe ERC-7930 sender interoperable address (origin chain + caller).
recipientbytesThe ERC-7930 recipient interoperable address (must target THIS chain).
payloadbytesThe opaque message payload delivered to the recipient.
nonceuint256The source-minted monotonic nonce; (source, nonce) forms the globally-unique delivery id.

messenger

The fixed OP Superchain L2ToL2CrossDomainMessenger predeploy this adapter sends to / accepts deliveries from (0x4200000000000000000000000000000000000023).

function messenger() external view virtual returns (address);

Returns

NameTypeDescription
<none>address

getRemoteAdapter

The trusted remote gateway adapter registered for chainId (0 = unset).

function getRemoteAdapter(uint256 chainId) external view virtual returns (address);

Parameters

NameTypeDescription
chainIduint256

Returns

NameTypeDescription
<none>address

registerRemoteAdapter

Registers a trusted remote gateway adapter (the sibling adapter) for a chain. One-shot. Admin only.

function registerRemoteAdapter(uint256 chainId, address remoteAdapter) external virtual;

Parameters

NameTypeDescription
chainIduint256
remoteAdapteraddress

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 L2ToL2CrossDomainMessengerGatewayAdapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: getRemoteAdapter(uint256) 0xa87c3775 messenger() 0x3cb747bf receiveCrossChainMessage(bytes,bytes,bytes,uint256) 0x610683bc registerRemoteAdapter(uint256,address) 0xa2719d9c sendMessage(bytes,bytes,bytes[]) 0xcdfe7f5c supportsAttribute(bytes4) 0xdc680a0f

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

Returns

NameTypeDescription
selectorsbytes