---
eip: 5164
label: ERC-5164
title: Cross-Chain Execution
status: Last Call
type: Standards Track
category: ERC
created: 2022-06-14
official: https://eips.ethereum.org/EIPS/eip-5164
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5164.md
canonical: https://eips.huatuo.xyz/ko/eip-5164/
lang: ko
tldr: 다른 EVM 체인의 컨트랙트를 호출하기 위한, 브리지에 구애받지 않는 최소 인터페이스. MessageDispatcher가 호출을 보내고, MessageExecutor가 이를 한 번만 실행하며 수신자에게 보낸 쪽이 누구인지 알려 준다.
tags: [cross-chain, bridge, messaging, interoperability]
---

# ERC-5164: Cross-Chain Execution

> Defines an interface that supports execution across EVM networks.

**TL;DR:** 다른 EVM 체인의 컨트랙트를 호출하기 위한, 브리지에 구애받지 않는 최소 인터페이스. MessageDispatcher가 호출을 보내고, MessageExecutor가 이를 한 번만 실행하며 수신자에게 보낸 쪽이 누구인지 알려 준다.

## 어떤 문제를 해결하나요?

여러 체인(L1, 롤업, 사이드체인)에 배포된 프로토콜은 서로 조율해야 합니다. 이더리움의 DAO가 L2의 컨트랙트를 거버넌스하거나, 프로토콜이 배포본 사이에서 상태를 동기화하는 경우입니다. 네이티브 브리지와 서드파티 브리지는 이런 호출을 전달할 수 있지만, 각자 API, 신뢰 모델, 특이점이 달라서 연동마다 맞춤 코드가 필요합니다.

ERC-5164는 "체인 X에서 이 호출을 실행하라"를 위한 아주 작은 공통 인터페이스를 정의합니다. 애플리케이션은 이에 맞춰 한 번만 작성하면 되고, 기반 브리지를 바꾸는 일은 다른 dispatcher/executor 쌍을 쓰는 문제가 됩니다.

## 어떻게 동작하나요?

두 가지 구성 요소가 있으며, 구현은 둘 다 제공해야 합니다.

**MessageDispatcher**(출발 체인)

```solidity
function dispatchMessage(uint256 toChainId, address to, bytes calldata data)
    external payable returns (bytes32 messageId);
event MessageDispatched(bytes32 indexed messageId, address indexed from,
    uint256 indexed toChainId, address to, bytes data);
```

- 지원하지 않는 `toChainId`에 대해서는 revert해야 하고 `MessageDispatched`를 emit해야 합니다.
- 체인과 dispatcher를 통틀어 고유한 `messageId`(예: `(chainId, dispatcherAddress, nonce)`의 해시)를 반환해야 합니다.
- 수수료를 받을 수 있으며, 그래서 `payable`입니다.

**MessageExecutor**(도착 체인)

- 브리지의 전송 계층으로 메시지를 검증해야 합니다(SHOULD).
- 원래의 `data`로 `to`를 호출하고, `messageId`, `fromChainId`, `from`(ABI 패킹)을 calldata 끝에 **덧붙여** 수신자가 크로스체인 발신자를 인증할 수 있게 합니다.
- 각 `messageId`를 최대 한 번만 실행하지만(그렇지 않으면 `MessageIdAlreadyExecuted` 오류) **순서는 보장하지 않습니다**.
- 실패하면 revert해야 하며(`MessageFailure` 오류), 그래서 나중에 메시지를 재시도할 수 있습니다.
- 성공하면 `MessageIdExecuted(fromChainId, messageId)`를 emit합니다.

## 샘플 코드

알려진 executor와 알려진 체인의 알려진 발신자로부터 온 호출만 받는 수신자:

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

contract CrossChainReceiver {
    address public immutable executor;   // ERC-5164 MessageExecutor on this chain
    uint256 public immutable originChainId;
    address public immutable originSender;
    uint256 public value;

    constructor(address _executor, uint256 _originChainId, address _originSender) {
        executor = _executor;
        originChainId = _originChainId;
        originSender = _originSender;
    }

    function setValue(uint256 v) external {
        require(msg.sender == executor, "not executor");
        (, uint256 fromChainId, address from) = _context();
        require(fromChainId == originChainId && from == originSender, "bad origin");
        value = v;
    }

    // Last 84 bytes of calldata: messageId (32) | fromChainId (32) | from (20)
    function _context() internal pure returns (bytes32 id, uint256 chainId, address from) {
        require(msg.data.length >= 84);
        assembly {
            let end := calldatasize()
            id := calldataload(sub(end, 84))
            chainId := calldataload(sub(end, 52))
            from := shr(96, calldataload(sub(end, 20)))
        }
    }
}
```

출발 체인에서는 발신자가 `dispatcher.dispatchMessage{value: fee}(destChainId, receiver, abi.encodeCall(CrossChainReceiver.setValue, (42)))`를 호출합니다.

## 알아둘 점

- 상태는 **Last Call**(마감 2023-11-15)이며 Final이 아닙니다. 인터페이스는 여전히 바뀔 수 있습니다.
- 보안은 전적으로 기반 브리지의 것입니다. 이 표준이 통일하는 것은 API이지 신뢰 모델이 아닙니다.
- 항상 `msg.sender == executor`와 덧붙은 `(fromChainId, from)`을 모두 확인하세요. 그렇지 않으면 어느 체인의 누구든 여러분의 함수를 실행할 수 있습니다.
- 메시지는 순서가 뒤바뀌어 도착할 수 있습니다. 수신자를 순서와 무관하게 설계하거나 자체 시퀀싱을 추가하세요.
- 본문은 "메시지 배치"를 언급하지만 단일 메시지용 `dispatchMessage`만 정의합니다.
- [ERC-7786](/eip-7786/)은 이후에 나온 Final 상태의 크로스체인 메시징 게이트웨이 인터페이스로, 비교해 볼 만합니다.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-5164
