---
eip: 7904
label: EIP-7904
title: Compute Gas Cost Analysis
status: Last Call
type: Informational
created: 2025-02-05
official: https://eips.ethereum.org/EIPS/eip-7904
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7904.md
canonical: https://eips.huatuo.xyz/zh/eip-7904/
lang: zh
tldr: 一项实证研究，考察主要客户端上 EVM 计算类操作码和预编译的耗时，结论是在 100 Mgas/s 的目标下，它们都不需要提高 gas 成本。
tags: [gas, benchmarks, opcodes, precompiles, informational]
---

# EIP-7904: Compute Gas Cost Analysis

> Empirical analysis of EVM compute operation runtimes concluding that no compute gas cost needs repricing at the target throughput

**TL;DR:** 一项实证研究，考察主要客户端上 EVM 计算类操作码和预编译的耗时，结论是在 100 Mgas/s 的目标下，它们都不需要提高 gas 成本。

## 它解决什么问题？

只有在没有任何单一操作能让攻击者用执行耗时远超其 gas 所暗示的工作量填满一个区块时，提高以太坊的 gas 上限才是安全的。EIP-7904 的早期版本是一项 Standards Track 提案，旨在*提高*一组操作码和预编译的价格，这些操作码和预编译经基准测试证明相对于其 gas 成本而言执行较慢，从而消除它们作为瓶颈的问题。

在区块级访问列表（[EIP-7928](/eip-7928/)）所带来的客户端优化（并行磁盘读取、并行交易验证、无需执行的状态更新）稳定之后，作者重新进行了测量。定价过低的情况消失了，因此该文档被改为一份 **Informational** EIP，用来记录方法、数据和结论：无需更改任何计算类 gas 成本。

## 它如何运作

- **目标吞吐量：**如果按其当前 gas 成本，客户端执行某个操作的速度达到或超过每秒 1 亿 gas，则认为该操作定价合理。
- **数据收集：**合成区块每次只对一个操作施压，并改变次数和输入（来自 EEST 基准套件）。Benchmarkoor 工具测量 Besu、Erigon、ethrex、Geth、Nethermind 和 Reth 上的区块执行时间，每个区块运行多次。
- **估算：**用非负最小二乘回归把固定开销与每次操作的运行时间分离开（对于可变成本的操作，还包括每字节/每轮的项）。只使用 R² > 0.5 且 p < 0.05 的拟合结果。
- **以最慢的客户端为准：**每个操作中最慢的客户端决定该操作对整个网络的成本。
- **换算：**把运行时间按目标速率换算为隐含的 gas 成本。

在所考察的 18 个参数（`DIV`、`MOD`、`ADDMOD`、`MULMOD`、`KECCAK256`、`ECRECOVER`、BLS 和 BN254 预编译、点求值、`P256VERIFY` 等）中，16 个测得的结果比现在的价格*更低*，1 个保持不变。唯一更高的值是 `BLAKE2F` 的基础成本，目前为 0，测得为 94 gas，被判定为可以忽略。

## 示例代码

分析中使用的、从测得运行时间到隐含 gas 的换算：

```python
ANCHOR_RATE = 100_000_000  # gas per second (100 Mgas/s)

def implied_gas(runtime_ms: float) -> float:
    """Gas an operation 'should' cost if it must run at the anchor rate."""
    return ANCHOR_RATE * runtime_ms / 1000

# Model for a simple opcode, fitted per client with NNLS:
#   block_runtime = intercept + slope * op_count
# slope (ms per op) is the per-operation runtime.
slope_ms = 0.00000841          # illustrative value
print(implied_gas(slope_ms))   # ≈ 0.84 gas -> compare with the current price
```

## 需要注意

- **状态：Last Call。**它是 Informational 的：对协议或 gas 表**不做任何**更改。它是未来重新定价工作的参考。
- 结论取决于客户端保持 EIP-7928 时代的优化。作者指出，如果这些优化发生变化，或者新增了操作，就应重新进行分析。
- 降低 gas 成本明确不在范围之内，即使有些操作测得的结果比其价格更低。
- 它只测量 CPU 时间。状态访问、存储增长和 ZK 证明成本都不在涵盖范围内。
- 所引用的相关工作包括 [EIP-7883](/eip-7883/) 中的 ModExp 重新定价，其采用了一致的测量方法。


---

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