---
eip: 7960
label: EIP-7960
title: EOF - Extended types section
status: Draft
type: Standards Track
category: Core
created: 2025-05-28
requires: 3540
official: https://eips.ethereum.org/EIPS/eip-7960
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7960.md
canonical: https://eips.huatuo.xyz/zh/eip-7960/
lang: zh
tldr: 为 EOF 容器的每个代码段增加一个 type 字节，使同一个合约可以混用普通 EVM 代码与 EVM64 等其他执行模式，并把 EOF 版本升到 0x02。
tags: [eof, evm, evm64, bytecode, core]
---

# EIP-7960: EOF - Extended types section

> Extend EOF container's types section with an extra type parameter.

**TL;DR:** 为 EOF 容器的每个代码段增加一个 type 字节，使同一个合约可以混用普通 EVM 代码与 EVM64 等其他执行模式，并把 EOF 版本升到 0x02。

## 它解决什么问题？

EVM 对象格式（EOF，[EIP-3540](/eip-3540/)）把合约字节码拆分成一个带有独立代码段的结构化容器，每个代码段由 `types_section` 中的一个条目描述（输入、输出、最大栈增长）。每个代码段都被假定为普通的 EVM 代码。

有些提案希望合约的某些部分在不同的解释器下运行。其动机示例是 EVM64，这是一种带 64 位算术的变体，进行繁重计算时更快，但无法直接处理地址和余额。以后，同样的钩子还可以支持 RISC-V 等其他代码类型。EIP-7960 增加了一个字段，让解释器知道如何运行每个代码段。

## 它如何运作

每个 `types_section` 条目从

```
(inputs: uint8, outputs: uint8, max_stack_increase: uint16)        // 32 bits
```

变为

```
(type: uint8, reserved: 24 bits, inputs: uint8, outputs: uint8, max_stack_increase: uint16)  // 64 bits
```

- `type = 0x01` 是这里定义的唯一类型。其他 EIP 可能会定义更多。
- `reserved` 使条目保持 64 位对齐，且必须全为零。
- EOF 容器的 `version` 变为 `0x02`；版本 `0x01` 从此无效。

新的验证规则：未知的 `type` 验证失败，非零的 `reserved` 字段也验证失败。

预期的使用模式是：合约把处理状态的逻辑（存储、余额、调用）放在普通 EVM 代码段中，把数值计算放进更快类型的代码段，并通过普通的 EOF 函数调用在两者之间切换。

## 示例代码

按本 EIP 编码一个 `types_section` 条目（Python）：

```python
import struct

def encode_type_entry(code_type: int, inputs: int, outputs: int, max_stack_increase: int) -> bytes:
    assert code_type == 0x01, "only type 0x01 is defined by EIP-7960"
    reserved = b"\x00\x00\x00"
    return (
        bytes([code_type]) + reserved
        + struct.pack(">BBH", inputs, outputs, max_stack_increase)
    )

entry = encode_type_entry(0x01, inputs=0, outputs=0x80, max_stack_increase=2)
print(entry.hex())  # 0100000000800002  -> 8 bytes per entry
```

（`outputs = 0x80` 在 EOF 中表示不返回的代码段。）

## 需要注意

- **状态：Draft。** 测试用例、参考实现和安全分析目前都还是"待补充"。
- EOF 本身并未在以太坊主网上线：它已从 Fusaka 升级中移除，EOF 核心规范（[EIP-3540](/eip-3540/)、[EIP-7692](/eip-7692/)）处于 Stagnant 状态。只有在 EOF 回归时，这个 EIP 才有意义。
- 版本升到 `0x02`，是为了避免与可能已经部署了 EOF 版本 1 的第三方链冲突。
- 用 EVM64 等非 EVM 代码段类型编写的代码无法直接访问地址和余额；这部分工作仍留在 type `0x01` 的代码段中。


---

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