ERC-7533 Public Cross Port
Draft · Other · created 2023-10-11
A common cross-chain messaging standard in which cross-chain bridges connecting multiple EVM chains gather messages into a single shared contract per chain (SendPort) and move and verify only a single Merkle tree root.
Why it is needed
Currently there are official cross-chain bridges between L2 and L1, but not between L2s. With a push model where each chain sends messages to every other chain, a separate bridge is needed for each chain pair, so 10 chains would require 10 times 9, or 90 bridges. As the number of bridges grows, the burden of building and operating them and the gas costs increase. There is also a lot of redundant construction, with multiple bridge projects separately building the same route, and because each is built differently, this redundancy does not translate into improved security. Since the message collection window and verification criteria are not standardized, even when multiple bridges carry the same message, their results cannot be cross-checked against each other, and the failure of a single bridge directly becomes an incident.
What to implement
event MsgHashAdded(uint indexed packageIndex, address sender, bytes32 msgHash, uint toChainId, bytes32 leaf);: An event emitted when an external contract adds a message hash to SendPort. It records the sender address, the destination chain ID, and the computed leaf together.event Packed(uint indexed packageIndex, uint indexed packTime, bytes32 root);: An event emitted when the collected leaves are packed into a Merkle tree and the root is finalized.function addMsgHash(bytes32 msgHash, uint toChainId) external;: An external contract sends the hash of a cross-chain message and the destination chain ID to SendPort.function pack() external;: Manually executes packing. It normally runs automatically when the last submitter submits, but if the wait becomes too long it can be called directly.function getPackage(uint packageIndex) external view returns (Package memory);: Looks up each package in SendPort, including both packed and pending ones.function getPendingPackage() external view returns (Package memory);: Looks up pending packages that have not yet been packed.event PackageReceived(uint indexed fromChainId, uint indexed packageIndex, bytes32 root);: An event emitted when IReceivePort receives and stores a root from the source chain.function receivePackages(Package[] calldata packages) external;: Receives roots gathered from the SendPort of multiple source chains at once.function getRoot(uint fromChainId, uint packageIndex) external view returns (bytes32);: Looks up the root of a specific package for a specific chain.
In depth
From push to pull, bridge count down to N
In the existing push model, each chain pushes messages to every other chain, requiring N x (N - 1) bridges for N chains. With 6 chains that is 30. In this standard's pull model, each chain pulls in the messages of the remaining chains in a single transaction and syncs them to its own chain, reducing the bridge count to N. Also, since Merkle tree compression turns any number of messages into a single byte32 root, carriers only need to move the root, keeping gas costs low.
The role of the SendPort contract
SendPort is a shared contract deployed on each chain that collects and packs cross-chain messages originating on that chain. It is public, permissionless, has no administrator, and operates automatically. Since multiple bridges can use it together, there is no need to redeploy it repeatedly per chain, and it is RECOMMENDED to have one per chain. A leaf is a hash computed from msgHash passed in by the external contract, the caller address sender that is recorded automatically, and the destination chain ID toChainId. After collecting leaves for a period of time, they are packed into a Merkle tree, and the next collection period begins.
Package structure and packing trigger
A Package consists of packageIndex (a zero-based index), root (the Merkle tree root built from the leaves), leaves, createTime (the time collection started, which is also the packing time of the previous package), and packTime (the packing time, after which no more leaves can be added). In the reference implementation, a new packing can begin once PACK_INTERVAL (6000) has elapsed, and packing executes immediately once MAX_PACKAGE_MESSAGES (100) messages have accumulated, with this condition taking priority over PACK_INTERVAL.
Root transport and multiple IReceivePorts
Once a new Merkle tree is packed, a carrier (typically a bridge project) pulls the root from multiple chains and stores it in the IReceivePort contract of each chain. Since a single root mixes messages going from one source chain to multiple destination chains, the carrier MAY decide at its discretion whether to move it to a particular chain based on relevance to itself. IReceivePort is not a single contract; each carrier implements it according to the interface, so if there are multiple carriers, multiple IReceivePort contracts exist as well.
Verification structure and multi-confirmation security
IReceivePort stores each chain's root and verifies authenticity when the full message and Merkle proof are presented. The root alone reveals nothing about the message content and only allows authenticity verification; the full message can be obtained from the source chain's SendPort. Since roots originate from the same SendPort, the roots held by different IReceivePorts SHOULD be identical, and a genuine message SHOULD verify as true at any IReceivePort. If multiple IReceivePorts verify it as true, it is likely genuine, and if some verify it as false, that can signal a hack or a malfunction of that particular bridge. Similar in principle to a multisig, this eliminates a single point of failure and turns redundant construction into improved security.
Data retention principle
SendPort preserves all roots and their sequential index numbers without deletion or modification. Each bridge's IReceivePort contract SHOULD follow the same approach. The reference implementation's ReceivePort refuses to accept a root if one already exists for the same fromChainId and packageIndex, preventing overwrites.
Three-layer ecosystem separation
This standard divides the cross-chain ecosystem into three layers and defines only the SendPort contract and IReceivePort interface at the bottommost foundational layer. Implementation of the remaining layers is left to projects participating in the ecosystem. On top of the message bridge, apps can build services such as token crossing, and if an NFT cross-chain app reuses a token message bridge or layers verification across multiple message bridges, it can significantly increase security at no extra cost. Since it does not change the consensus layer, there are no compatibility issues with Ethereum as a whole or with existing apps.
Proposal status
This proposal is still in Draft status. Its content may change, so the latest source should be checked before implementation.
Things to watch out for
- Restricting calls to receivePackages: IReceivePort.receivePackages() must not be left callable by anyone. Storing roots must be controlled by the relevant bridge.
- Preventing double payment: During verification, an already-verified msgHash must be stored so that the same message cannot be verified again and paid out twice.
- Not trusting every sender in the Merkle tree: SendPort is a public contract usable by anyone, so anyone can insert an arbitrary message. Since msg.sender is included in packing, a forged message comes bundled with the attacker's address, which can be identified during verification. Therefore, not every sender in the tree should be trusted; only trusted addresses should be accepted.
- No guarantee of message ordering: SendPort collects messages in chronological order, but ordering is not guaranteed during verification. For example, even if 10 ETH was sent first and 20 USDT later, the destination chain might find the 20 USDT first. Handling order is left to the IReceivePort implementation.