{"eip":5164,"title":"Cross-Chain Execution","description":"Defines an interface that supports execution across EVM networks.","authors":["Brendan Asselstine (@asselstine)","Pierrick Turelier (@PierrickGT)","Chris Whinfrey (@cwhinfrey)"],"status":"Last Call","type":"Standards Track","category":"ERC","created":"2022-06-14","discussionsTo":"https://ethereum-magicians.org/t/eip-5164-cross-chain-execution/9658","repo":"ERCs","label":"ERC-5164","officialUrl":"https://eips.ethereum.org/EIPS/eip-5164","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5164.md","url":"https://eips.huatuo.xyz/eip-5164/","tldr":{"en":"A minimal bridge-agnostic interface for calling a contract on another EVM chain: a MessageDispatcher sends the call, a MessageExecutor runs it once and tells the receiver who sent it.","ja":"別の EVM チェーン上のコントラクトを呼び出すための、ブリッジに依存しない最小限のインターフェース。MessageDispatcher が呼び出しを送り、MessageExecutor がそれを 1 回だけ実行して、受信側に送信者を伝える。","ko":"다른 EVM 체인의 컨트랙트를 호출하기 위한, 브리지에 구애받지 않는 최소 인터페이스. MessageDispatcher가 호출을 보내고, MessageExecutor가 이를 한 번만 실행하며 수신자에게 보낸 쪽이 누구인지 알려 준다.","zh":"一个与桥无关的极简接口，用于调用另一条 EVM 链上的合约：MessageDispatcher 发送调用，MessageExecutor 只执行一次，并告诉接收方发送者是谁。"},"tags":["cross-chain","bridge","messaging","interoperability"],"explainers":{"en":{"lang":"en","tldr":"A minimal bridge-agnostic interface for calling a contract on another EVM chain: a MessageDispatcher sends the call, a MessageExecutor runs it once and tells the receiver who sent it.","tags":["cross-chain","bridge","messaging","interoperability"],"related":[7786],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5164/","markdown":"## What problem does it solve?\n\nProtocols deployed on several chains (L1, rollups, sidechains) need to coordinate: a DAO on Ethereum governing contracts on an L2, or a protocol syncing state between deployments. Native and third-party bridges can carry such calls, but each has its own API, trust model and quirks, so every integration is custom code.\n\nERC-5164 defines a tiny common interface for \"execute this call on chain X\". Applications write against it once, and swapping the underlying bridge becomes a matter of using a different dispatcher/executor pair.\n\n## How it works\n\nThere are two components, and an implementation must provide both:\n\n**MessageDispatcher** (origin chain)\n\n```solidity\nfunction dispatchMessage(uint256 toChainId, address to, bytes calldata data)\n    external payable returns (bytes32 messageId);\nevent MessageDispatched(bytes32 indexed messageId, address indexed from,\n    uint256 indexed toChainId, address to, bytes data);\n```\n\n- Must revert for unsupported `toChainId` and must emit `MessageDispatched`.\n- Must return a `messageId` unique across chains and dispatchers, e.g. a hash of `(chainId, dispatcherAddress, nonce)`.\n- May charge a fee, which is why it is `payable`.\n\n**MessageExecutor** (destination chain)\n\n- Should verify the message with the bridge's transport layer.\n- Calls `to` with the original `data` and **appends** `messageId`, `fromChainId` and `from` (ABI-packed) to the calldata, so the receiver can authenticate the cross-chain sender.\n- Executes each `messageId` at most once (`MessageIdAlreadyExecuted` error otherwise) but makes **no ordering guarantee**.\n- On failure it must revert (`MessageFailure` error) so the message can be retried later.\n- Emits `MessageIdExecuted(fromChainId, messageId)` on success.\n\n## Sample code\n\nA receiver that only accepts calls from a known executor and a known sender on a known chain:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CrossChainReceiver {\n    address public immutable executor;   // ERC-5164 MessageExecutor on this chain\n    uint256 public immutable originChainId;\n    address public immutable originSender;\n    uint256 public value;\n\n    constructor(address _executor, uint256 _originChainId, address _originSender) {\n        executor = _executor;\n        originChainId = _originChainId;\n        originSender = _originSender;\n    }\n\n    function setValue(uint256 v) external {\n        require(msg.sender == executor, \"not executor\");\n        (, uint256 fromChainId, address from) = _context();\n        require(fromChainId == originChainId \u0026\u0026 from == originSender, \"bad origin\");\n        value = v;\n    }\n\n    // Last 84 bytes of calldata: messageId (32) | fromChainId (32) | from (20)\n    function _context() internal pure returns (bytes32 id, uint256 chainId, address from) {\n        require(msg.data.length \u003e= 84);\n        assembly {\n            let end := calldatasize()\n            id := calldataload(sub(end, 84))\n            chainId := calldataload(sub(end, 52))\n            from := shr(96, calldataload(sub(end, 20)))\n        }\n    }\n}\n```\n\nOn the origin chain the sender calls `dispatcher.dispatchMessage{value: fee}(destChainId, receiver, abi.encodeCall(CrossChainReceiver.setValue, (42)))`.\n\n## Things to know\n\n- Status is **Last Call** (deadline 2023-11-15), not Final; the interface could still change.\n- Security is entirely that of the underlying bridge. The standard unifies the API, not the trust model.\n- Always check both `msg.sender == executor` and the appended `(fromChainId, from)`; otherwise anyone on any chain can trigger your function.\n- Messages may arrive out of order. Design receivers so order does not matter, or add your own sequencing.\n- The text mentions \"message batches\" but only defines the single-message `dispatchMessage`.\n- [ERC-7786](/eip-7786/) is a later, Final cross-chain messaging gateway interface worth comparing.\n"},"ja":{"lang":"ja","tldr":"別の EVM チェーン上のコントラクトを呼び出すための、ブリッジに依存しない最小限のインターフェース。MessageDispatcher が呼び出しを送り、MessageExecutor がそれを 1 回だけ実行して、受信側に送信者を伝える。","tags":["cross-chain","bridge","messaging","interoperability"],"related":[7786],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5164/","markdown":"## 何を解決するのか\n\n複数のチェーン（L1、ロールアップ、サイドチェーン）にデプロイされたプロトコルは連携する必要があります。たとえば、Ethereum 上の DAO が L2 上のコントラクトを統治する場合や、プロトコルがデプロイ間でステートを同期する場合です。ネイティブブリッジやサードパーティのブリッジはこうした呼び出しを運べますが、それぞれが独自の API、信頼モデル、癖を持つため、統合のたびに独自のコードが必要になります。\n\nERC-5164 は、「チェーン X でこの呼び出しを実行する」ための、ごく小さな共通インターフェースを定義します。アプリケーションはそれに対して一度書けば済み、下層のブリッジの入れ替えは、別の dispatcher / executor のペアを使うだけの話になります。\n\n## 仕組み\n\n2 つのコンポーネントがあり、実装は両方を提供しなければなりません。\n\n**MessageDispatcher**（送信元チェーン）\n\n```solidity\nfunction dispatchMessage(uint256 toChainId, address to, bytes calldata data)\n    external payable returns (bytes32 messageId);\nevent MessageDispatched(bytes32 indexed messageId, address indexed from,\n    uint256 indexed toChainId, address to, bytes data);\n```\n\n- サポートされていない `toChainId` に対しては revert しなければならず、`MessageDispatched` を emit しなければなりません。\n- チェーンとディスパッチャーをまたいで一意な `messageId`（例: `(chainId, dispatcherAddress, nonce)` のハッシュ）を返さなければなりません。\n- 手数料を徴収してもよく、そのため `payable` になっています。\n\n**MessageExecutor**（宛先チェーン）\n\n- ブリッジのトランスポート層でメッセージを検証すべきです（SHOULD）。\n- 元の `data` で `to` を呼び出し、`messageId`、`fromChainId`、`from`（ABI パック形式）を calldata の末尾に**追加**します。これにより、受信側はクロスチェーンの送信者を認証できます。\n- 各 `messageId` を最大 1 回だけ実行しますが（それ以外の場合は `MessageIdAlreadyExecuted` エラー）、**順序は保証しません**。\n- 失敗した場合は revert しなければならず（`MessageFailure` エラー）、後でメッセージを再試行できます。\n- 成功時に `MessageIdExecuted(fromChainId, messageId)` を emit します。\n\n## サンプルコード\n\n既知の executor と、既知のチェーン上の既知の送信者からの呼び出しのみを受け付けるレシーバー:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CrossChainReceiver {\n    address public immutable executor;   // ERC-5164 MessageExecutor on this chain\n    uint256 public immutable originChainId;\n    address public immutable originSender;\n    uint256 public value;\n\n    constructor(address _executor, uint256 _originChainId, address _originSender) {\n        executor = _executor;\n        originChainId = _originChainId;\n        originSender = _originSender;\n    }\n\n    function setValue(uint256 v) external {\n        require(msg.sender == executor, \"not executor\");\n        (, uint256 fromChainId, address from) = _context();\n        require(fromChainId == originChainId \u0026\u0026 from == originSender, \"bad origin\");\n        value = v;\n    }\n\n    // Last 84 bytes of calldata: messageId (32) | fromChainId (32) | from (20)\n    function _context() internal pure returns (bytes32 id, uint256 chainId, address from) {\n        require(msg.data.length \u003e= 84);\n        assembly {\n            let end := calldatasize()\n            id := calldataload(sub(end, 84))\n            chainId := calldataload(sub(end, 52))\n            from := shr(96, calldataload(sub(end, 20)))\n        }\n    }\n}\n```\n\n送信元チェーンでは、送信者が `dispatcher.dispatchMessage{value: fee}(destChainId, receiver, abi.encodeCall(CrossChainReceiver.setValue, (42)))` を呼び出します。\n\n## 知っておくべきこと\n\n- ステータスは **Last Call**（期限 2023-11-15）で、Final ではありません。インターフェースは今後も変わる可能性があります。\n- セキュリティは完全に下層のブリッジのものです。この標準が統一するのは API であり、信頼モデルではありません。\n- 必ず `msg.sender == executor` と、追加された `(fromChainId, from)` の両方を確認してください。そうしないと、どのチェーンの誰でも関数を呼び出せてしまいます。\n- メッセージは順序が入れ替わって届くことがあります。順序が関係ないようにレシーバーを設計するか、独自のシーケンス制御を追加してください。\n- 本文は「メッセージバッチ」に言及していますが、定義しているのは単一メッセージの `dispatchMessage` だけです。\n- [ERC-7786](/eip-7786/) は、後から出た Final のクロスチェーンメッセージングゲートウェイのインターフェースで、比較する価値があります。\n"},"ko":{"lang":"ko","tldr":"다른 EVM 체인의 컨트랙트를 호출하기 위한, 브리지에 구애받지 않는 최소 인터페이스. MessageDispatcher가 호출을 보내고, MessageExecutor가 이를 한 번만 실행하며 수신자에게 보낸 쪽이 누구인지 알려 준다.","tags":["cross-chain","bridge","messaging","interoperability"],"related":[7786],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5164/","markdown":"## 어떤 문제를 해결하나요?\n\n여러 체인(L1, 롤업, 사이드체인)에 배포된 프로토콜은 서로 조율해야 합니다. 이더리움의 DAO가 L2의 컨트랙트를 거버넌스하거나, 프로토콜이 배포본 사이에서 상태를 동기화하는 경우입니다. 네이티브 브리지와 서드파티 브리지는 이런 호출을 전달할 수 있지만, 각자 API, 신뢰 모델, 특이점이 달라서 연동마다 맞춤 코드가 필요합니다.\n\nERC-5164는 \"체인 X에서 이 호출을 실행하라\"를 위한 아주 작은 공통 인터페이스를 정의합니다. 애플리케이션은 이에 맞춰 한 번만 작성하면 되고, 기반 브리지를 바꾸는 일은 다른 dispatcher/executor 쌍을 쓰는 문제가 됩니다.\n\n## 어떻게 동작하나요?\n\n두 가지 구성 요소가 있으며, 구현은 둘 다 제공해야 합니다.\n\n**MessageDispatcher**(출발 체인)\n\n```solidity\nfunction dispatchMessage(uint256 toChainId, address to, bytes calldata data)\n    external payable returns (bytes32 messageId);\nevent MessageDispatched(bytes32 indexed messageId, address indexed from,\n    uint256 indexed toChainId, address to, bytes data);\n```\n\n- 지원하지 않는 `toChainId`에 대해서는 revert해야 하고 `MessageDispatched`를 emit해야 합니다.\n- 체인과 dispatcher를 통틀어 고유한 `messageId`(예: `(chainId, dispatcherAddress, nonce)`의 해시)를 반환해야 합니다.\n- 수수료를 받을 수 있으며, 그래서 `payable`입니다.\n\n**MessageExecutor**(도착 체인)\n\n- 브리지의 전송 계층으로 메시지를 검증해야 합니다(SHOULD).\n- 원래의 `data`로 `to`를 호출하고, `messageId`, `fromChainId`, `from`(ABI 패킹)을 calldata 끝에 **덧붙여** 수신자가 크로스체인 발신자를 인증할 수 있게 합니다.\n- 각 `messageId`를 최대 한 번만 실행하지만(그렇지 않으면 `MessageIdAlreadyExecuted` 오류) **순서는 보장하지 않습니다**.\n- 실패하면 revert해야 하며(`MessageFailure` 오류), 그래서 나중에 메시지를 재시도할 수 있습니다.\n- 성공하면 `MessageIdExecuted(fromChainId, messageId)`를 emit합니다.\n\n## 샘플 코드\n\n알려진 executor와 알려진 체인의 알려진 발신자로부터 온 호출만 받는 수신자:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CrossChainReceiver {\n    address public immutable executor;   // ERC-5164 MessageExecutor on this chain\n    uint256 public immutable originChainId;\n    address public immutable originSender;\n    uint256 public value;\n\n    constructor(address _executor, uint256 _originChainId, address _originSender) {\n        executor = _executor;\n        originChainId = _originChainId;\n        originSender = _originSender;\n    }\n\n    function setValue(uint256 v) external {\n        require(msg.sender == executor, \"not executor\");\n        (, uint256 fromChainId, address from) = _context();\n        require(fromChainId == originChainId \u0026\u0026 from == originSender, \"bad origin\");\n        value = v;\n    }\n\n    // Last 84 bytes of calldata: messageId (32) | fromChainId (32) | from (20)\n    function _context() internal pure returns (bytes32 id, uint256 chainId, address from) {\n        require(msg.data.length \u003e= 84);\n        assembly {\n            let end := calldatasize()\n            id := calldataload(sub(end, 84))\n            chainId := calldataload(sub(end, 52))\n            from := shr(96, calldataload(sub(end, 20)))\n        }\n    }\n}\n```\n\n출발 체인에서는 발신자가 `dispatcher.dispatchMessage{value: fee}(destChainId, receiver, abi.encodeCall(CrossChainReceiver.setValue, (42)))`를 호출합니다.\n\n## 알아둘 점\n\n- 상태는 **Last Call**(마감 2023-11-15)이며 Final이 아닙니다. 인터페이스는 여전히 바뀔 수 있습니다.\n- 보안은 전적으로 기반 브리지의 것입니다. 이 표준이 통일하는 것은 API이지 신뢰 모델이 아닙니다.\n- 항상 `msg.sender == executor`와 덧붙은 `(fromChainId, from)`을 모두 확인하세요. 그렇지 않으면 어느 체인의 누구든 여러분의 함수를 실행할 수 있습니다.\n- 메시지는 순서가 뒤바뀌어 도착할 수 있습니다. 수신자를 순서와 무관하게 설계하거나 자체 시퀀싱을 추가하세요.\n- 본문은 \"메시지 배치\"를 언급하지만 단일 메시지용 `dispatchMessage`만 정의합니다.\n- [ERC-7786](/eip-7786/)은 이후에 나온 Final 상태의 크로스체인 메시징 게이트웨이 인터페이스로, 비교해 볼 만합니다.\n"},"zh":{"lang":"zh","tldr":"一个与桥无关的极简接口，用于调用另一条 EVM 链上的合约：MessageDispatcher 发送调用，MessageExecutor 只执行一次，并告诉接收方发送者是谁。","tags":["cross-chain","bridge","messaging","interoperability"],"related":[7786],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5164/","markdown":"## 它解决什么问题？\n\n部署在多条链（L1、rollup、侧链）上的协议需要协同：例如以太坊上的 DAO 治理 L2 上的合约，或某个协议在各个部署之间同步状态。原生桥和第三方桥都可以传递这类调用，但每一个都有自己的 API、信任模型和怪癖，所以每次集成都要写定制代码。\n\nERC-5164 为\"在链 X 上执行这个调用\"定义了一个极小的通用接口。应用只需针对它编写一次，更换底层的桥就只是改用另一对 dispatcher / executor 的事。\n\n## 它如何运作\n\n有两个组件，实现必须同时提供：\n\n**MessageDispatcher**（源链）\n\n```solidity\nfunction dispatchMessage(uint256 toChainId, address to, bytes calldata data)\n    external payable returns (bytes32 messageId);\nevent MessageDispatched(bytes32 indexed messageId, address indexed from,\n    uint256 indexed toChainId, address to, bytes data);\n```\n\n- 对不支持的 `toChainId` 必须 revert，并且必须 emit `MessageDispatched`。\n- 必须返回一个在各条链和各个 dispatcher 之间唯一的 `messageId`，例如 `(chainId, dispatcherAddress, nonce)` 的哈希。\n- 可以收取费用，这就是它是 `payable` 的原因。\n\n**MessageExecutor**（目标链）\n\n- 应当通过桥的传输层验证消息。\n- 使用原始 `data` 调用 `to`，并把 `messageId`、`fromChainId` 和 `from`（ABI 紧凑编码）**追加**到 calldata 末尾，使接收方能够验证跨链发送者。\n- 每个 `messageId` 最多执行一次（否则抛出 `MessageIdAlreadyExecuted` 错误），但**不保证顺序**。\n- 失败时必须 revert（`MessageFailure` 错误），以便之后可以重试该消息。\n- 成功时 emit `MessageIdExecuted(fromChainId, messageId)`。\n\n## 示例代码\n\n一个只接受来自已知 executor 以及已知链上已知发送者的调用的接收方：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CrossChainReceiver {\n    address public immutable executor;   // ERC-5164 MessageExecutor on this chain\n    uint256 public immutable originChainId;\n    address public immutable originSender;\n    uint256 public value;\n\n    constructor(address _executor, uint256 _originChainId, address _originSender) {\n        executor = _executor;\n        originChainId = _originChainId;\n        originSender = _originSender;\n    }\n\n    function setValue(uint256 v) external {\n        require(msg.sender == executor, \"not executor\");\n        (, uint256 fromChainId, address from) = _context();\n        require(fromChainId == originChainId \u0026\u0026 from == originSender, \"bad origin\");\n        value = v;\n    }\n\n    // Last 84 bytes of calldata: messageId (32) | fromChainId (32) | from (20)\n    function _context() internal pure returns (bytes32 id, uint256 chainId, address from) {\n        require(msg.data.length \u003e= 84);\n        assembly {\n            let end := calldatasize()\n            id := calldataload(sub(end, 84))\n            chainId := calldataload(sub(end, 52))\n            from := shr(96, calldataload(sub(end, 20)))\n        }\n    }\n}\n```\n\n在源链上，发送者调用 `dispatcher.dispatchMessage{value: fee}(destChainId, receiver, abi.encodeCall(CrossChainReceiver.setValue, (42)))`。\n\n## 需要注意\n\n- 状态为 **Last Call**（截止日期 2023-11-15），尚未 Final；接口仍有可能变化。\n- 安全性完全取决于底层的桥。该标准统一的是 API，而不是信任模型。\n- 务必同时检查 `msg.sender == executor` 和追加的 `(fromChainId, from)`；否则任何链上的任何人都可以触发你的函数。\n- 消息可能乱序到达。请把接收方设计成与顺序无关，或自行增加排序机制。\n- 文本提到了\"消息批次\"，但只定义了单条消息的 `dispatchMessage`。\n- [ERC-7786](/eip-7786/) 是后来出现的、已 Final 的跨链消息网关接口，值得对比。\n"}}}
