EIPs Explained

ERC-7533 · Draft · ERC · 2023-10-11

ERC-7533: Public Cross Port

A Draft design for a shared, permissionless SendPort contract on every EVM chain that batches outgoing cross-chain messages into Merkle roots, so bridges pull one root per chain instead of building a bridge for every chain pair.

What problem does it solve?

L2s have official bridges to L1, but not to each other. If every chain pushes messages directly to every other chain, N chains need N × (N − 1) bridges: 90 for ten chains. Each bridge project also builds its own message collection, so effort is duplicated without making anything safer.

Public Cross Port (PCP) flips this to a pull model. Each chain has one public SendPort that collects all outgoing messages; a bridge for chain X pulls the latest roots from all other chains into X in one transaction. That needs only N bridges. And because many bridges read from the same SendPort, a message can be cross-checked by several independent bridges, a bit like a multisig.

How it works

  1. Add a message. Any contract calls SendPort.addMsgHash(msgHash, toChainId). The port stores a leaf keccak256(msgHash, msg.sender, toChainId), so the sender's address is always part of the message and cannot be forged.
  2. Pack. Leaves accumulate in a pending package. It is packed into a Merkle root either automatically (enough messages, or enough time passed) or by anyone calling pack(). Packages have sequential indexes and are never modified or deleted.
  3. Carry roots. A bridge operator reads new roots from the source chains and calls receivePackages([...]) on its own IReceivePort contract on the target chain. Each bridge deploys its own receive port.
  4. Verify. An application calls verify(fromChainId, packageIndex, proof, msgHash, sender) on one or more receive ports. Only the root travels; the full message data is re-supplied by the caller and checked against it.

Interfaces in short:

  • ISendPort: addMsgHash, pack, getPackage, getPendingPackage; events MsgHashAdded, Packed.
  • IReceivePort: receivePackages, getRoot, verify; event PackageReceived.

Since all receive ports copy roots from the same SendPort, honest ports must agree. A port that disagrees signals a bug or an attack.

Sample code

A token bridge sending and later claiming a message:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface ISendPort { function addMsgHash(bytes32 msgHash, uint toChainId) external; }
interface IReceivePort {
    function verify(uint fromChainId, uint packageIndex, bytes32[] memory proof,
                    bytes32 msgHash, address sender) external view returns (bool);
}

contract MiniBridge {
    ISendPort public immutable sendPort;
    IReceivePort public immutable receivePort;
    mapping(bytes32 => bool) public used;

    constructor(ISendPort s, IReceivePort r) { sendPort = s; receivePort = r; }

    // Source chain: record the intent to move `amount` to `to` on `toChainId`
    function send(address to, uint256 amount, uint256 toChainId, uint256 nonce) external {
        // ... lock or burn the user's tokens here ...
        sendPort.addMsgHash(keccak256(abi.encode(to, amount, nonce)), toChainId);
    }

    // Target chain: prove the message was sent by our bridge on the source chain
    function claim(uint fromChainId, uint packageIndex, bytes32[] calldata proof,
                   address srcBridge, address to, uint256 amount, uint256 nonce) external {
        bytes32 msgHash = keccak256(abi.encode(to, amount, nonce));
        require(!used[msgHash], "already claimed");
        require(receivePort.verify(fromChainId, packageIndex, proof, msgHash, srcBridge), "bad proof");
        used[msgHash] = true;
        // ... release or mint tokens to `to` ...
    }
}

srcBridge must be checked against a list of trusted bridge addresses, otherwise anyone could post a matching message from their own contract.

Things to know

  • Status: Draft.
  • SendPort is permissionless, so anyone can add messages. Always check that the sender in a proof is a contract you trust.
  • Store used message hashes to prevent replaying the same proof (double spending).
  • receivePackages must be access controlled; whoever can set roots can make any proof pass.
  • There is no ordering guarantee on the target chain: messages from the same package may be consumed in any order.
  • The security of the system still rests on the bridge operators who carry roots; PCP standardises collection, not trust. For other cross-chain standards see ERC-5164 and ERC-7683.

#cross-chain #bridges #l2 #merkle #messaging

Details

Authors
George (@JXRow), Zisu (@lazy1523)
Status
Draft
Type
Standards Track / ERC
Created
2023-10-11

Machine-readable: Markdown · JSON