---
eip: 7666
label: EIP-7666
title: EVM-ify the identity precompile
status: Draft
type: Standards Track
category: Core
created: 2024-03-31
requires: 3855
official: https://eips.ethereum.org/EIPS/eip-7666
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7666.md
canonical: https://eips.huatuo.xyz/zh/eip-7666/
lang: zh
tldr: 草案提案：废除位于 0x04 的 identity precompile，用七个字节、功能相同的普通 EVM 代码取而代之，作为移除很少使用的 precompile 的第一步。
tags: [evm, precompiles, core, simplification]
---

# EIP-7666: EVM-ify the identity precompile

> Remove the identity precompile, and put into place a piece of EVM code that has equivalent functionality

**TL;DR:** 草案提案：废除位于 0x04 的 identity precompile，用七个字节、功能相同的普通 EVM 代码取而代之，作为移除很少使用的 precompile 的第一步。

## 它解决什么问题？

以太坊有许多 precompile：这些特殊地址的行为是硬编码在每个客户端中的，而不是用 EVM 字节码编写的。其中近一半很少被使用，但每一个都会增加维护负担、共识 bug 风险，以及每个新客户端（尤其是 ZK-EVM 和经过形式化验证的实现）的工作量。

identity precompile（`0x04`）只是原样返回它的输入。它存在是因为早期没有廉价的内存复制方式。自从 [EIP-5656](/eip-5656/) 加入 `MCOPY` 之后，这个理由就不复存在了。EIP-7666 提议把它移除，并用普通 EVM 代码取代，作为日后废除更复杂的 precompile（例如很少使用的哈希函数和 MODEXP）的模板。

## 它如何运作

在分叉区块开始时：

- 地址 `0x0000000000000000000000000000000000000004` 的代码被设置为 `0x365f5f37365ff3`。
- 从该区块起，`0x04` 不再被当作 precompile；对它的调用会像其他合约一样运行这段字节码。

这段字节码反汇编如下：

```
36  CALLDATASIZE      ; size
5f  PUSH0             ; offset in calldata = 0
5f  PUSH0             ; destination in memory = 0
37  CALLDATACOPY      ; memory[0:size] = calldata
36  CALLDATASIZE      ; size
5f  PUSH0             ; offset = 0
f3  RETURN            ; return memory[0:size]
```

它依赖 [EIP-3855](/eip-3855/) 中的 `PUSH0`，因此存在这一依赖关系。

## 示例代码

调用者无需做任何改动；在分叉前后，这段代码仍会返回 `data` 的副本：

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

contract CopyViaIdentity {
    function copy(bytes memory data) external view returns (bytes memory out) {
        (bool ok, bytes memory ret) = address(0x04).staticcall(data);
        require(ok, "identity call failed");
        out = ret;
    }
}
```

只是需要复制内存的新代码应当改用 `MCOPY`：

```solidity
function copyMem(uint256 dst, uint256 src, uint256 len) internal pure {
    assembly { mcopy(dst, src, len) }
}
```

## 需要注意

- **状态：Draft。** 尚未被安排进任何网络升级。
- 功能完全相同，但 gas 成本会略有变化，因为调用现在执行的是普通 opcode，而不是 precompile 的固定定价。向 `0x04` 传入精确计算的 gas 限额的合约应当检查。
- 没有增加任何新功能，也没有让任何功能变便宜，因此规范认为不存在新的安全风险。
- 如果被采纳，同样的"用 EVM 代码取代"模式可以在今后的提案中应用于其他 precompile。


---

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