---
eip: 5478
label: EIP-5478
title: CREATE2COPY Opcode
status: Stagnant
type: Standards Track
category: Core
created: 2022-08-17
requires: 1014, 2929
official: https://eips.ethereum.org/EIPS/eip-5478
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5478.md
canonical: https://eips.huatuo.xyz/zh/eip-5478/
lang: zh
tldr: 提议新增 CREATE2COPY 操作码，用于部署与已有合约代码一致的合约，并收取一次账户访问费用（2,600 或 100 gas），而不是按字节计费的代码存款费用。
tags: [evm, opcodes, deployment, account-abstraction, gas]
---

# EIP-5478: CREATE2COPY Opcode

> Reducing the gas cost of contract creation with existing code

**TL;DR:** 提议新增 CREATE2COPY 操作码，用于部署与已有合约代码一致的合约，并收取一次账户访问费用（2,600 或 100 gas），而不是按字节计费的代码存款费用。

## 它解决什么问题？

在账户抽象下，每个用户都有自己的智能合约钱包，其中大多数运行的是*完全相同*的代码。部署合约时仍然要按运行时代码每字节 200 gas 收取代码存款成本。规范中的例子：一个 10,000 字节的钱包，仅代码存款就要花费 2,000,000 gas，而且每次都是如此，尽管节点早已存储了这份一模一样的代码。

EIP-5478 提议只为查找已有代码付费，而不是为重新存储再付一次费。

## 它如何运作

新操作码 `CREATE2COPY`（提议使用 `0xf6`）的行为类似 `CREATE2`（[EIP-1014](/eip-1014/)），只是多了一个栈参数：

```text
CREATE2COPY(endowment, memory_start, memory_length, salt, existing_contract_address)
```

- initcode 的运行方式与 `CREATE2` 完全相同，地址的推导方式也相同。
- initcode 返回的运行时代码必须（MUST）与 `existing_contract_address` 具有相同的代码哈希。否则创建失败（"mismatched contract creation code with existing code"），并烧掉创建所用的全部 gas。
- gas 与 `CREATE2` 相同，只是代码存款项 `200 * code_size` 被替换为对已有合约执行 `EXTCODEHASH` 的成本：冷访问为 **2,600**，热访问为 **100**（[EIP-2929](/eip-2929/)）。

| 常量 | 值 |
| --- | --- |
| `CREATE_DATA_GAS_PER_BYTE` | 200 |
| `COLD_ACCOUNT_ACCESS_COST` | 2600 |
| `WARM_ACCOUNT_ACCESS_COST` | 100 |

## 示例代码

钱包工厂可能如何使用它（假设性的；没有编译器或链支持该操作码）：

```python
# Pseudocode: CREATE2COPY does not exist on mainnet.
def deploy_wallet(factory, initcode: bytes, salt: bytes, template: str) -> str:
    # Same as CREATE2(endowment=0, initcode, salt) ...
    # ... but the runtime code must hash-match `template`, and the
    # 200 gas/byte code deposit is replaced by an EXTCODEHASH-priced access.
    wallet = factory.CREATE2COPY(0, initcode, salt, template)
    assert wallet != ZERO_ADDRESS, "deploy failed"
    return wallet

# Gas for a 10,000-byte wallet code deposit:
#   CREATE2:      200 * 10_000 = 2_000_000
#   CREATE2COPY:  2_600 (template cold) or 100 (template warm)
```

## 需要注意

- 状态：**Stagnant**。分叉区块为"TBD"，Rationale 和 Security Considerations 两节从未完成。
- 它只对代码存款打折。initcode 的执行、`CREATE2` 的基础成本以及哈希计算仍然照常收费。
- 如今实现廉价的按用户部署的常用方式是 [ERC-1167](/eip-1167/) 之类的代理，它部署几十字节的代码，再 `DELEGATECALL` 到共享逻辑。这也是 [ERC-4337](/eip-4337/) 钱包工厂常用的模式。
- 与代理不同，`CREATE2COPY` 会给每个账户一份完整、独立的代码副本，没有 delegatecall 的开销。


---

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