---
eip: 7511
label: ERC-7511
title: Minimal Proxy Contract with PUSH0
status: Draft
type: Standards Track
category: ERC
created: 2023-09-04
requires: 7, 211, 1167, 3855
official: https://eips.ethereum.org/EIPS/eip-7511
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7511.md
canonical: https://eips.huatuo.xyz/zh/eip-7511/
lang: zh
tldr: 用 PUSH0 操作码重写的 ERC-1167 最小代理的 44 字节版本，行为不变，部署时节省 200 gas，每次调用节省 5 gas。
tags: [proxy, clones, bytecode, gas, push0]
---

# ERC-7511: Minimal Proxy Contract with PUSH0

> Optimizes the previous Minimal Proxy Contract with the PUSH0 opcode

**TL;DR:** 用 PUSH0 操作码重写的 ERC-1167 最小代理的 44 字节版本，行为不变，部署时节省 200 gas，每次调用节省 5 gas。

## 它解决什么问题？

[ERC-1167](/eip-1167/) 的"最小代理"（克隆）是一种很小的合约，它通过 `DELEGATECALL` 把每次调用都转发给固定的实现合约。这是部署大量廉价、逻辑相同的副本的标准方式：钱包、金库、代币实例等。

ERC-1167 写于上海升级之前，所以它用 `RETURNDATASIZE` 和 `DUP` 之类的技巧来压入零。[EIP-3855](/eip-3855/) 新增了 `PUSH0`，这是一个专门用于压入零的 2 gas 操作码。ERC-7511 用 `PUSH0` 从头重新设计了克隆合约，让它小了一个字节，稍微便宜一些，也更易读。

## 它如何运作

运行时代码正好 44 字节，20 字节的实现地址位于字节索引 9–28（此处显示为 `bebe…`）：

```
365f5f375f5f365f73bebebebebebebebebebebebebebebebebebebebe5af43d5f5f3e5f3d91602a57fd5bf3
```

它做四件事：

1. 用 `CALLDATACOPY` 把完整的 calldata 复制到内存的 0 位置。
2. 带着所有剩余 gas 对实现合约执行 `DELEGATECALL`。
3. 用 `RETURNDATACOPY` 把结果复制到内存的 0 位置。
4. 通过 `JUMPI` 判断成功与否：成功则 `RETURN` 该数据，否则带着该数据 `REVERT`。

53 字节的创建代码，是在前面加上一段 9 字节的 initcode（`602c8060095f395ff3`），它把 44 字节的运行时代码复制到内存并返回。

根据规范，与 ERC-1167 相比，部署时节省 200 gas，运行时节省 5 gas，行为完全相同。

## 示例代码

规范中用 `CREATE` 部署克隆的工厂合约：

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

contract Clone0Factory {
    error FailedCreateClone();

    function clone0(address impl) public payable returns (address addr) {
        // first 18 bytes of the creation code
        bytes memory data1 = hex"602c8060095f395ff3365f5f375f5f365f73";
        // last 15 bytes of the creation code
        bytes memory data2 = hex"5af43d5f5f3e5f3d91602a57fd5bf3";
        bytes memory code = abi.encodePacked(data1, impl, data2);

        assembly {
            addr := create(callvalue(), add(code, 0x20), mload(code))
        }
        if (addr == address(0)) revert FailedCreateClone();
    }
}
```

检查已部署的合约是否为 ERC-7511 克隆（ethers v6）：

```ts
const code = (await provider.getCode(addr)).toLowerCase();
const isClone0 =
  code.length === 2 + 44 * 2 &&
  code.startsWith("0x365f5f375f5f365f73") &&
  code.endsWith("5af43d5f5f3e5f3d91602a57fd5bf3");
const impl = isClone0 ? "0x" + code.slice(2 + 9 * 2, 2 + 29 * 2) : null;
```

## 需要注意

- 状态为 **Draft**。
- 需要 `PUSH0`，因此只适用于已激活上海（或等效）升级的链，并且 Solidity 要面向支持它的 EVM 版本。在没有 `PUSH0` 的链上，部署会产生一个损坏的合约；那里请使用 ERC-1167。
- ERC-1167 的注意事项同样适用：实现永远固定（不可升级），没有构造函数，因此部署后必须立刻调用初始化函数，实现中的漏洞会影响每一个克隆。
- 只认识 ERC-1167 字节码的浏览器和工具，可能会把这些克隆显示为未知合约。


---

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