EIPs Explained

ERC-6170 · Draft · ERC · 2022-12-19

ERC-6170: Cross-Chain Messaging Interface

A draft common interface for cross-chain message bridges, with one sendMessage and one receiveMessage function using bytes everywhere so apps can switch bridges and reach non-EVM chains.

What problem does it solve?

Cross-chain apps send messages through arbitrary message bridges (AMBs), and each bridge has its own API, its own replay protection and its own security assumptions. An app written against one bridge is effectively locked in: if that bridge goes down or is compromised, moving to another means rewriting integration code and possibly migrating state.

ERC-6170 proposes a minimal shared interface for bridges, so an application can talk to any compliant bridge the same way and swap or combine bridges by changing an address.

How it works

A compliant bridge exposes two functions and two events:

Member Role
sendMessage(chainId, receiver, message, data) Send message to receiver on chain chainId. Payable to cover relaying fees.
receiveMessage(chainId, sender, message, data) Deliver an incoming message from sender on chain chainId.
MessageSent(to, toChainId, message, extraData) Must fire on every send, even zero-byte messages
MessageReceived(from, fromChainId, message) Must fire on every successful receive

Design choices:

  • Everything is bytes. Chain IDs and addresses are bytes rather than uint256 / address, so the same interface can address non-EVM chains whose addresses are not 20 bytes. The draft suggests encoding a chain ID as the ABI-encoded name of its native token (for example abi.encode("ETH")).
  • data is bridge-specific. On send it carries whatever the bridge's relayers need; on receive it can carry security data such as a nonce or proof.
  • Both functions return a bool status.

Authentication is out of scope: the receiving side must validate the sender and message itself before acting.

Sample code

The interface and an app that only accepts messages from a known peer:

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

interface IEIP6170 {
    event MessageSent(bytes to, bytes toChainId, bytes message, bytes extraData);
    event MessageReceived(bytes from, bytes fromChainId, bytes message);

    function sendMessage(bytes memory chainId_, bytes memory receiver_, bytes memory message_, bytes memory data_)
        external payable returns (bool);
    function receiveMessage(bytes memory chainId_, bytes memory sender_, bytes memory message_, bytes memory data_)
        external payable returns (bool);
}

contract Pinger {
    IEIP6170 public bridge;
    bytes public peerChain;
    bytes public peer;

    constructor(IEIP6170 b, bytes memory chain, bytes memory p) { bridge = b; peerChain = chain; peer = p; }

    function ping(bytes calldata relayerData) external payable {
        bridge.sendMessage{value: msg.value}(peerChain, peer, abi.encode("ping"), relayerData);
    }

    // called by the bridge on delivery
    function onMessage(bytes calldata fromChain, bytes calldata from, bytes calldata message) external {
        require(msg.sender == address(bridge), "only bridge");
        require(keccak256(fromChain) == keccak256(peerChain) && keccak256(from) == keccak256(peer), "unknown peer");
        // handle message...
    }
}

How the bridge calls into the destination app (onMessage above) is not specified by the draft; each bridge defines its own delivery hook.

Things to know

  • Status is Draft: the interface is not finalized and may change. Check whether a given bridge actually implements it before relying on it.
  • Without sender authentication, anyone could inject messages into the receiving contract. Always check origin chain and sender.
  • Using several bridges through one interface reduces single-point-of-failure risk only if the app also checks each bridge's security model.
  • A related effort at a standard cross-chain execution interface is ERC-5164.

#cross-chain #bridge #messaging #interoperability

Details

Authors
Sujith Somraaj (@sujithsomraaj)
Status
Draft
Type
Standards Track / ERC
Created
2022-12-19

Machine-readable: Markdown · JSON