---
eip: 5559
label: ERC-5559
title: Cross Chain Write Deferral Protocol
status: Stagnant
type: Standards Track
category: ERC
created: 2022-06-23
requires: 712
official: https://eips.ethereum.org/EIPS/eip-5559
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5559.md
canonical: https://eips.huatuo.xyz/ko/eip-5559/
lang: ko
tldr: CCIP Read의 쓰기 측 대응 표준을 제안했습니다. L1 컨트랙트가 타입이 지정된 에러로 리버트해, 클라이언트에게 업데이트를 대신 L2 컨트랙트나 서명된 오프체인 데이터베이스로 보내라고 알려줍니다.
tags: [cross-chain, l2, offchain, ens, ccip, eip712]
---

# ERC-5559: Cross Chain Write Deferral Protocol

> The cross chain write deferral protocol provides a mechanism to defer the storage & resolution of mutations to off-chain handlers

**TL;DR:** CCIP Read의 쓰기 측 대응 표준을 제안했습니다. L1 컨트랙트가 타입이 지정된 에러로 리버트해, 클라이언트에게 업데이트를 대신 L2 컨트랙트나 서명된 오프체인 데이터베이스로 보내라고 알려줍니다.

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

[EIP-3668](/eip-3668/)(CCIP Read)은 메인넷 컨트랙트가 "답은 오프체인에 있으니 여기서 가져와 검증하세요"라고 말할 수 있게 해주며, ENS 이름이 L2나 데이터베이스에 저장된 데이터를 해석할 수 있는 것도 이 덕분입니다. 하지만 **쓰기**에 대응하는 표준은 없었습니다. 이름의 레코드가 L2나 데이터베이스에 있다면, 지갑은 업데이트를 어디로 보내야 하는지 어떻게 알까요?

ERC-5559가 이를 정의합니다. 사용자와 앱은 익숙한 L1 컨트랙트와 같은 함수 시그니처로 계속 통신하고, 컨트랙트는 변경 작업을 더 저렴한 스토리지로 리다이렉트합니다.

## 어떻게 동작하나요?

클라이언트는 평소처럼 L1 컨트랙트를 호출합니다(예: `setAddr(node, addr)`). 보통 사전 점검용 `eth_call`이나 가스 추정으로 호출합니다. 컨트랙트는 쓰기를 직접 수행하거나, 쓰기가 실제로 어디에 속하는지 클라이언트에게 알려주는 **타입이 지정된 에러로 리버트**합니다.

- **`StorageHandledByL2(chainId, contractAddress)`**: 클라이언트는 원하는 RPC를 통해 EVM 체인 `chainId`의 `contractAddress`로 **같은 calldata**를 담은 새 트랜잭션을 보냅니다. L2 컨트랙트는 일반적인 `msg.sender` 검사를 사용할 수 있습니다.
- **`StorageHandledByOffChainDatabase(sender, url, data)`**: `sender`는 [EIP-712](/eip-712/) 도메인(name, version, chainId, verifyingContract)이고, `data`는 함수 셀렉터, 사용자 주소, 이름/값 문자열 쌍으로 된 파라미터, 만료 타임스탬프를 담은 메시지입니다. 사용자가 이를 EIP-712로 서명하고 `{ sender, data, signature }`를 JSON으로 `url`에 POST합니다. 게이트웨이는 서명과 권한을 확인해야 합니다.

위임은 연쇄될 수 있습니다. L1 컨트랙트가 L2 컨트랙트를 가리키고, 그 L2 컨트랙트가 다시 데이터베이스에 위임할 수 있습니다. 컨트랙트는 핸들러의 체인 ID, L2 주소, 데이터베이스 URL을 변경할 때 이벤트를 발생시켜야 합니다.

## 샘플 코드

L2 위임을 처리하는 클라이언트(ethers v6):

```ts
import { Contract, Interface, JsonRpcProvider, Wallet } from "ethers";

const iface = new Interface([
  "function setAddr(bytes32 node, address a)",
  "error StorageHandledByL2(uint256 chainId, address contractAddress)",
]);
const resolver = new Contract(resolverAddress, iface, l1Signer);

try {
  await resolver.setAddr.staticCall(node, newAddr);   // preflight
  await (await resolver.setAddr(node, newAddr)).wait(); // stored on L1
} catch (err: any) {
  const parsed = iface.parseError(err.data);
  if (parsed?.name !== "StorageHandledByL2") throw err;
  const [chainId, target] = parsed.args;
  const l2 = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(rpcFor(chainId)));
  // resend the original calldata, unchanged, to the L2 handler
  const data = iface.encodeFunctionData("setAddr", [node, newAddr]);
  await (await l2.sendTransaction({ to: target, data })).wait();
}
```

같은 위임의 Solidity 측:

```solidity
error StorageHandledByL2(uint256 chainId, address contractAddress);

function setAddr(bytes32, address) external view {
    revert StorageHandledByL2(l2ChainId, l2Resolver);
}
```

## 알아둘 점

- **상태: Stagnant.** 이 제안은 최종 확정되지 않았습니다. 기반이 되는 CCIP Read([EIP-3668](/eip-3668/))는 Final입니다.
- 클라이언트는 이더리움 메인넷으로 되돌아가는 위임을 거부해야 하고, L2 위임에서는 원래 calldata를 그대로 재사용해야 합니다. 다른 악성 트랜잭션에 서명하도록 속는 일을 막기 위해서입니다.
- 오프체인 데이터베이스 쓰기에는 사용자의 주소가 포함되고 사용자의 IP에서 전송되므로 지갑을 식별하는 지문이 될 수 있습니다. 명세는 사용자가 온체인 스토리지를 선택할 수 있게 하고, 클라이언트 라이브러리가 이런 요청을 프록시하거나 허용 목록에 넣거나 차단할 수 있게 할 것을 권장합니다.
- 오프체인 데이터베이스는 온체인 보장을 전혀 제공하지 않으며, 신뢰는 전적으로 게이트웨이 운영자에게 달려 있습니다.
- 이 프로토콜을 구현하지 않은 클라이언트는 단순히 리버트로 보게 됩니다.


---

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