ERC-7841 Cross-chain message and mailbox standard (Cross-chain Message Format and Mailbox)
Draft · Other · created 2024-12-12
Defines a common format and Mailbox API for sending and receiving messages between different chains, allowing cross-chain apps to be built against the same interface regardless of chain, VM, or messaging protocol.
Why it is needed
Ethereum's L2s brought scalability but fragmented the ecosystem by using different messaging protocols and message formats. Since each cross-chain communication protocol defines its own format and these are incompatible with one another, developers building apps that span multiple chains must implement separate send and receive logic for each chain or protocol. Different code is also needed depending on whether the VM differs (EVM vs non-EVM), whether settlement is ZK or optimistic, and whether messaging is synchronous or asynchronous. In this situation, developers end up spending more time adapting cross-chain infrastructure than on their own app logic, and shared infrastructure such as relayers and libraries must be rebuilt separately for each protocol, making reuse difficult.
What to implement
function chain_id() virtual public view returns (uint32);: Returns the ID of the chain on which this mailbox is deployed.function inboxDigest(uint32 srcChainId) virtual public returns (bytes32);: Returns a digest accumulating all inbox messages from a specific source chain.function outboxDigest(uint32 destChainId) public returns (bytes32);: Returns a digest accumulating all outbox messages sent to a specific destination chain.function send(Metadata calldata metadata, bytes memory payload) virtual public;: Sends a message to another chain and updates the outbox digest.function randSessionId() virtual public returns (uint128);: Randomly generates a unique session ID for use with a new message.
In depth
Message format: Metadata and Message
Every message follows a Message structure consisting of Metadata and a payload. Metadata holds the source and destination chain IDs (srcChainId, destChainId), the sender and recipient addresses encoded as 32 bytes (srcAddress, destAddress), a sessionId identifying a single cross-chain interaction, and a nonce distinguishing message order within a session. Addresses are unified to 32 bytes so that account representations from other VMs (such as Ed25519 public keys), not just EVM addresses, can be accommodated. The payload can hold any form of data, such as ABI-encoded function calls, asset bridging information, or arbitrary data.
Core functions of the Mailbox interface
chain_id() returns the ID of the chain on which the mailbox is deployed. inboxDigest() and outboxDigest() each return a digest accumulating all messages going to or from a specific chain. getMetadataDigest() computes a lookup key from the metadata, and send() sends a message and updates the outbox digest. recv() retrieves the payload from the inbox using only the metadata, and populateInbox() fills the inbox with messages from other chains, optionally receiving authentication information via aux. randSessionId() generates a collision-free session ID.
Separate mailboxes for synchronous and asynchronous use
A single Mailbox contract could support both synchronous and asynchronous messaging, but this would require the application to specify a messaging mode for every interaction and would make settlement logic differ per mode, complicating the API and implementation. This standard therefore recommends that each chain have two canonical Mailbox contracts, one for synchronous and one for asynchronous messaging. An app can switch between synchronous and asynchronous messaging simply by changing which contract address it points to.
Why the inbox is pre-filled
This standard separates the act of filling the inbox (populateInbox) from the act of reading a message (recv). As a result, message lookup can be done using only the metadata rather than the full payload, which also works for synchronous messaging where the payload is only determined at execution time. It also removes the need to verify a Merkle inclusion proof for every message, allows the internal logic of populateInbox() or the settlement layer to change without requiring changes to connected apps, and allows messages to be received on the destination chain via a user's own signed transaction instead of a shared sequencer signature.
Why a metadata digest is used as the lookup key instead of the session ID
The inbox and outbox lookup key is formed from a hash of the entire metadata rather than the sessionId alone. Because sessionId generation varies by implementation, it may not be properly bound to key information such as the sender and recipient addresses, and since messaging protocols control send and receive permissions based on this metadata, the lookup key must be bound to the full metadata. If users were allowed to choose their own sessionId, values could collide, so mapping-based inboxes must maintain a separate nullifier set to prevent key collisions and message overwrites.
VM-independent design
This standard operates purely through smart contract interfaces, without any new opcodes or precompiles. Sender and recipient addresses are represented as general-purpose bytes32 rather than the EVM-specific address type, so that account schemes from other VMs, such as Ed25519 public keys, can also be supported. If needed, an optional contract such as MultiplexABIEncoder, which selects encoding logic based on the destination chain ID, can abstract away VM-specific encoding differences; for EVM-only chains, plain abi.encode() can simply be used.
Reference implementation and gas cost optimization
The reference implementation of the synchronous mailbox manages the inbox and digests as nested mappings keyed by block number, resetting at the end of each block. To convert it to the asynchronous version, the block number layer can be removed and replaced with a check at the settlement layer that the inbox is a subset of the outbox. The most gas-intensive operations are the sstore in populateInbox() and the sload in recv(), and these costs are relatively low on L2s. Further optimizations are possible by deleting inbox[key] on recv() to obtain a refund, pre-warming storage slots with an EIP-2930 access list, or batching messages together in buckets for storage.
This is not yet a finalized proposal
This proposal is currently in Draft status, and details may still change or be discontinued through further community discussion and implementation.
Things to watch out for
- Security is the responsibility of the underlying protocol, not the mailbox standard: The message format and mailbox API defined by this standard do not themselves add significant security risk. The focus is on providing a flexible interface that can accommodate various message delivery protocols, and actual security depends on the design of the coordination/settlement protocols that use it and the applications built on top of them. Verifying the security of those protocols themselves is outside the scope of this proposal.