---
eip: 7676
label: EIP-7676
title: EOF - Prepare for Address Space Extension
status: Stagnant
type: Standards Track
category: Core
created: 2024-04-03
requires: 3540, 3670, 7069
official: https://eips.ethereum.org/EIPS/eip-7676
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7676.md
canonical: https://eips.huatuo.xyz/zh/eip-7676/
lang: zh
tldr: 让 EOF 合约拒绝高 12 字节非零的地址，而不是悄悄截断，为将来从 20 字节地址迁移到 32 字节地址留出空间。
tags: [eof, evm, addresses, opcodes, core]
---

# EIP-7676: EOF - Prepare for Address Space Extension

> Update EOF opcodes so addresses are not trimmed during execution

**TL;DR:** 让 EOF 合约拒绝高 12 字节非零的地址，而不是悄悄截断，为将来从 20 字节地址迁移到 32 字节地址留出空间。

## 它解决什么问题？

EVM 地址是 20 字节，而栈字是 32 字节。当 `BALANCE` 或 `CALL` 等旧版 opcode 从栈中取地址时，会悄悄丢弃高 12 字节，只使用低 20 字节。参考测试甚至会检查这种行为。

这种掩码处理会阻碍把地址扩展到 32 字节的计划（例如为状态过期而提出的"地址空间扩展"）。如果旧代码已经把 `0xFFFF…<20 字节>` 与 `0x0000…<20 字节>` 视为同一个账户，那么以后就无法在不改变现有合约行为的前提下，赋予高位字节任何含义。

EVM 对象格式（EOF，[EIP-3540](/eip-3540/)）是全新的容器格式，因此可以从第一天起内置更严格的规则，而不会破坏旧版合约。本 EIP 针对地址操作数正是这样做的。

## 它如何运作

大多数接收地址的 opcode 在 EOF 中已被移除或替换：`EXTCODESIZE`、`EXTCODECOPY`、`EXTCODEHASH`、`CALLCODE` 和 `SELFDESTRUCT` 被禁用，call 系列被 `EXTCALL`、`EXTDELEGATECALL` 和 `EXTSTATICCALL`（[EIP-7069](/eip-7069/)）取代。剩下的缺口是 `BALANCE`。

提案内容：

- **新增 `EXTBALANCE`**（规范中 opcode 编号仍为"tbd"）。它弹出一个地址并压入该账户的余额。gas 沿用 [EIP-2929](/eip-2929/) 中 `BALANCE` 的规则：cold 地址 2600（随后加入 `accessed_addresses`），warm 地址 100。
- **遇到脏地址即停机。** 如果操作数的高 12 字节中有任何一个非零，`EXTBALANCE` 会引发异常停机，并耗尽当前帧的全部 gas。
- **对 `EXTCALL`、`EXTDELEGATECALL`、`EXTSTATICCALL` 增加同样的检查**，在内存扩展检查之前执行。

旧版 `BALANCE` opcode 保持不变，因此在旧版代码和 EOF 代码中行为一致。规范否决了把脏地址当作"空账户"处理的替代方案，因为那会迫使客户端在 access list 中跟踪 256 位地址，并可能使发往不可达账户的 ETH 无法取回。

## 示例代码

行为示意（新地址检查的伪代码）：

```python
def check_address(operand: int) -> int:
    # operand is a 256-bit stack word
    if operand >> 160 != 0:
        raise ExceptionalHalt  # all remaining gas in the frame is consumed
    return operand            # no masking: the value is used as-is

# EXTBALANCE
addr = check_address(stack.pop())
charge_gas(100 if addr in accessed_addresses else 2600)
accessed_addresses.add(addr)
stack.push(state.get_balance(addr))
```

编译器应在使用来自 calldata 的地址之前先将其清理干净，就像 Solidity 对 `address` 类型已经做的那样：

```solidity
// Solidity masks to 160 bits when decoding an `address` parameter,
// so `who` can never carry dirty upper bytes into EXTBALANCE / EXTCALL.
function balanceOfAccount(address who) external view returns (uint256) {
    return who.balance;
}
```

## 需要注意

- **状态：Stagnant。** 近期没有任何进展，opcode 编号也从未分配。
- 它完全依赖 EOF（[EIP-3540](/eip-3540/)、[EIP-3670](/eip-3670/)、[EIP-7069](/eip-7069/)），对旧版合约没有影响。
- 这里的停机只是占位设计。规范指出，未来的地址扩展 EIP 很可能会改变它，因此合约不应依赖这种停机行为。
- 旧合约可以继续运行，但可能永远无法与扩展空间中的地址交互。


---

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