ERC-7841 · Draft · ERC · 2024-12-12
ERC-7841: Cross-chain Message Format and Mailbox
Defines a VM-agnostic cross-chain message format and a Mailbox contract API (send, populate inbox, recv) so apps can message between L2s the same way whether the underlying protocol is synchronous or asynchronous.
What problem does it solve?
Each L2 messaging or bridging protocol has its own message layout and its own send/receive flow, so a cross-chain app (an intent bridge, a DEX sharing liquidity across rollups, a cross-chain lending market) has to be rebuilt for every protocol. Synchronous protocols (shared sequencers, same-slot messaging) and asynchronous ones (settle first, deliver later) differ even more.
ERC-7841 standardises only the low layer, "like the Internet Protocol": one message format and one Mailbox interface. Chains and coordination protocols can then evolve underneath without apps changing their code.
How it works
Message format. A Message is Metadata plus an opaque payload:
| Field | Meaning |
|---|---|
srcChainId, destChainId |
uint32 chain identifiers |
srcAddress, destAddress |
bytes32, so non-EVM accounts (e.g. Ed25519 keys) also fit; EVM addresses are padded |
sessionId |
uint128 ID for one cross-chain interaction |
nonce |
uint128 counter within a session (0 if unused) |
Mailbox. Each chain should run two canonical mailboxes, one for synchronous and one for asynchronous messaging; an app picks a mode just by choosing the address. The recommended API:
send(metadata, payload): should checksrcChainId == chain_id()andsrcAddress == msg.sender, then update the outbox digest.populateInbox(messages, aux): called by a coordinator or relayer to write incoming messages into the inbox, with optionalaux(for example a relayer signature) to justify them.recv(metadata): looks up the payload bygetMetadataDigest(metadata), a hash of all metadata fields, and reverts if absent. Only metadata is needed, which matters in synchronous flows where the payload is only known at runtime.inboxDigest(src)/outboxDigest(dest): running accumulators. At settlement, chain A's inbox digest for B must equal B's outbox digest for A.randSessionId(): a fresh unique session ID.
Sample code
An app sending a message and reading the reply (illustrative; IMailbox follows the spec's interface):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
struct Metadata {
uint32 srcChainId; uint32 destChainId;
bytes32 srcAddress; bytes32 destAddress;
uint128 sessionId; uint128 nonce;
}
interface IMailbox {
function chain_id() external view returns (uint32);
function send(Metadata calldata m, bytes memory payload) external;
function recv(Metadata calldata m) external returns (bytes memory);
function randSessionId() external returns (uint128);
}
contract Pinger {
IMailbox public immutable mailbox;
constructor(IMailbox m) { mailbox = m; }
function ping(uint32 dest, address peer) external returns (uint128 sid) {
sid = mailbox.randSessionId();
mailbox.send(Metadata(mailbox.chain_id(), dest,
bytes32(uint256(uint160(address(this)))), bytes32(uint256(uint160(peer))),
sid, 0), abi.encode("ping"));
}
function readReply(uint32 src, address peer, uint128 sid) external returns (bytes memory) {
return mailbox.recv(Metadata(src, mailbox.chain_id(),
bytes32(uint256(uint160(peer))), bytes32(uint256(uint160(address(this)))),
sid, 1));
}
}
Things to know
- Status is Draft.
- How the inbox is authenticated (relayer signature, proofs, or deferred checks at settlement) is up to the coordination protocol. Your app inherits its trust model.
- Pre-filling the inbox costs extra gas on the destination chain; the authors consider this acceptable on L2s.
- If user-chosen
sessionIds can collide, a mapping-based inbox needs a nullifier set to stop messages overwriting each other. - Compare ERC-7786, a gateway interface for any bridge, and ERC-7683, cross-chain intents, which the authors say can be built on top of this mailbox.