---
eip: 7841
label: ERC-7841
title: Cross-chain Message Format and Mailbox
status: Draft
type: Standards Track
category: ERC
created: 2024-12-12
official: https://eips.ethereum.org/EIPS/eip-7841
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7841.md
canonical: https://eips.huatuo.xyz/ko/eip-7841/
lang: ko
tldr: VM에 독립적인 크로스체인 메시지 형식과 Mailbox 컨트랙트 API(send, populate inbox, recv)를 정의하여, 기반 프로토콜이 동기식이든 비동기식이든 앱이 같은 방식으로 L2 간 메시지를 주고받게 한다.
tags: [cross-chain, l2, messaging, interoperability, rollups]
---

# ERC-7841: Cross-chain Message Format and Mailbox

> A mailbox API and message format to provide a unified cross-chain developer experience

**TL;DR:** VM에 독립적인 크로스체인 메시지 형식과 Mailbox 컨트랙트 API(send, populate inbox, recv)를 정의하여, 기반 프로토콜이 동기식이든 비동기식이든 앱이 같은 방식으로 L2 간 메시지를 주고받게 한다.

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

L2 메시징이나 브리지 프로토콜은 저마다 고유한 메시지 레이아웃과 송수신 흐름을 가지고 있어, 크로스체인 앱(인텐트 브리지, 롤업 간 유동성을 공유하는 DEX, 크로스체인 대출 시장)은 프로토콜마다 다시 만들어야 합니다. 동기식 프로토콜(공유 시퀀서, 같은 슬롯 내 메시징)과 비동기식 프로토콜(먼저 정산하고 나중에 전달)은 차이가 더 큽니다.

ERC-7841은 "인터넷 프로토콜처럼" 낮은 계층만 표준화합니다. 메시지 형식 하나와 Mailbox 인터페이스 하나입니다. 그러면 앱이 코드를 바꾸지 않고도 체인과 조정 프로토콜이 그 아래에서 발전할 수 있습니다.

## 어떻게 동작하나요?

**메시지 형식.** `Message`는 `Metadata`와 불투명한 `payload`로 이루어집니다.

| 필드 | 의미 |
| --- | --- |
| `srcChainId`, `destChainId` | `uint32` 체인 식별자 |
| `srcAddress`, `destAddress` | `bytes32`이므로 비 EVM 계정(예: Ed25519 키)도 담을 수 있음. EVM 주소는 패딩됨 |
| `sessionId` | 한 번의 크로스체인 상호작용을 나타내는 `uint128` ID |
| `nonce` | 세션 내 `uint128` 카운터(미사용 시 0) |

**Mailbox.** 각 체인은 동기식용과 비동기식용으로 **정규 mailbox 두 개**를 운영해야 하며, 앱은 주소를 고르는 것만으로 모드를 선택합니다. 권장 API는 다음과 같습니다.

- `send(metadata, payload)`: `srcChainId == chain_id()`와 `srcAddress == msg.sender`를 확인한 뒤 outbox 다이제스트를 갱신해야 합니다.
- `populateInbox(messages, aux)`: 코디네이터나 릴레이어가 들어오는 메시지를 inbox에 쓰기 위해 호출하며, 이를 뒷받침하는 선택적 `aux`(예: 릴레이어 서명)를 함께 줄 수 있습니다.
- `recv(metadata)`: `getMetadataDigest(metadata)`(메타데이터의 *모든* 필드의 해시)로 payload를 찾고, 없으면 revert합니다. 필요한 것은 메타데이터뿐이며, payload를 런타임에야 알 수 있는 동기식 흐름에서 이것이 중요합니다.
- `inboxDigest(src)` / `outboxDigest(dest)`: 계속 누적되는 어큐뮬레이터. 정산 시 체인 A의 B에 대한 inbox 다이제스트는 B의 A에 대한 outbox 다이제스트와 같아야 합니다.
- `randSessionId()`: 새로운 고유 세션 ID.

## 샘플 코드

메시지를 보내고 응답을 읽는 앱(설명용. `IMailbox`는 사양의 인터페이스를 따름):

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

struct Metadata {
    uint32 srcChainId; uint32 destChainId;
    bytes32 srcAddress; bytes32 destAddress;
    uint128 sessionId; uint128 nonce;
}

interface IMailbox {
    function chain_id() external view returns (uint32);
    function send(Metadata calldata m, bytes memory payload) external;
    function recv(Metadata calldata m) external returns (bytes memory);
    function randSessionId() external returns (uint128);
}

contract Pinger {
    IMailbox public immutable mailbox;
    constructor(IMailbox m) { mailbox = m; }

    function ping(uint32 dest, address peer) external returns (uint128 sid) {
        sid = mailbox.randSessionId();
        mailbox.send(Metadata(mailbox.chain_id(), dest,
            bytes32(uint256(uint160(address(this)))), bytes32(uint256(uint160(peer))),
            sid, 0), abi.encode("ping"));
    }

    function readReply(uint32 src, address peer, uint128 sid) external returns (bytes memory) {
        return mailbox.recv(Metadata(src, mailbox.chain_id(),
            bytes32(uint256(uint160(peer))), bytes32(uint256(uint160(address(this)))),
            sid, 1));
    }
}
```

## 알아둘 점

- 상태는 **Draft**입니다.
- inbox를 어떻게 인증하는지(릴레이어 서명, 증명, 정산 시 지연 검사)는 조정 프로토콜에 달려 있습니다. 앱은 그 신뢰 모델을 그대로 물려받습니다.
- inbox를 미리 채우면 목적지 체인에서 가스가 추가로 듭니다. 작성자들은 L2에서는 이를 감수할 만하다고 봅니다.
- 사용자가 고른 `sessionId`가 충돌할 수 있다면, 매핑 기반 inbox는 메시지가 서로 덮어쓰지 않도록 nullifier 집합이 필요합니다.
- 모든 브리지를 위한 게이트웨이 인터페이스인 [ERC-7786](/eip-7786/)과, 작성자들이 이 mailbox 위에 구축할 수 있다고 말하는 크로스체인 인텐트 [ERC-7683](/eip-7683/)도 비교해 보세요.


---

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