---
eip: 2045
label: EIP-2045
title: Particle gas costs for EVM opcodes
status: Stagnant
type: Standards Track
category: Core
created: 2019-05-17
official: https://eips.ethereum.org/EIPS/eip-2045
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2045.md
canonical: https://eips.huatuo.xyz/zh/eip-2045/
lang: zh
tldr: 提议引入一个比 gas 更小的单位，称为 particle（1 gas = 10,000 particles），使 ADD、DUP 等廉价的计算类 opcode 的价格可以低于 1 gas。
tags: [gas, evm, opcodes, pricing, core]
---

# EIP-2045: Particle gas costs for EVM opcodes

> According to recent benchmarks, EVM opcodes for computation (ADD, SUB, MUL, etc.) are generally overpriced relative to opcodes for storage I/O (SLOAD, SSTORE, etc.). Currently the minimum gas cost is 1 (i.e. one unit of gas), and most computational opcodes have a cost near to 1 (e.g.

**TL;DR:** 提议引入一个比 gas 更小的单位，称为 particle（1 gas = 10,000 particles），使 ADD、DUP 等廉价的计算类 opcode 的价格可以低于 1 gas。

## 它解决什么问题？

对优化后的 EVM 实现做的基准测试表明，纯计算（`ADD`、`MUL`、`DUP`、`SWAP` 等）相对于存储访问（`SLOAD`、`SSTORE`）定价偏高。让计算更便宜，就能在不提高 gas 上限的情况下让更多交易装进区块，这也会加快状态增长。

但可压缩的空间很小：最低成本是 1 gas，而这些 opcode 已经只要 2–8 gas。当 `DUP` 只要 3 gas 时，你不可能让它便宜 10 倍。

EIP-2045 引入了更精细的单位，使成本可以低于 1 gas。

## 它如何运作

- 新增计数器 `particlesUsed`，与 `gasUsed` 并行运行。**1 gas = 10,000 particles**（`PARTICLES_PER_GAS`）。
- 以 particle 计价的 opcode 累加到 `particlesUsed`。每当它达到 10,000，就把 1 gas 转入 `gasUsed`，余数留在 particle 计数器中。
- 以整数 gas 计价的 opcode 与以前一样。
- 规范建议的新价格：`DUP`/`SWAP` 从 3 gas 改为 3,000 particles（0.3 gas）；`ADD`/`SUB` 从 3 gas 改为 6,000 particles；`MUL` 从 5 gas 改为 5,000 particles。

particle 是 EVM 内部细节。交易 gas 上限、区块 gas 上限、区块头和收据都仍以整数 gas 表示，因此用户和大多数合约作者不会看到它们。

规范指出，更快的实现可以只保留一个放大 10,000 倍的计数器，并在最后向上取整，而且 2 的幂比例（8192 或 16384）可能更高效。这些数字明确只是草案。

## 示例代码

核心计费循环，改编自规范：

```python
PARTICLES_PER_GAS = 10_000

def charge(state, opcode):
    if opcode.gas_fee:
        state.gas_used += opcode.gas_fee
    elif opcode.particle_fee:
        state.particles_used += opcode.particle_fee
        if state.particles_used >= PARTICLES_PER_GAS:
            state.gas_used += 1
            state.particles_used %= PARTICLES_PER_GAS
    if state.gas_used > state.gas_limit:
        raise OutOfGas()

# e.g. ten DUP1s at 3,000 particles each = 30,000 particles = 3 gas (vs 30 today)
```

## 需要注意

- 状态为 **Stagnant**；它从未被排入硬分叉。由于改变了 gas 计费方式，实施它需要一次硬分叉。
- "particle" 这个名称来自早期的 Ewasm gas 计价工作，但本提案针对的是 EVM，而非 Ewasm。
- 以太坊并没有让计算变便宜，而是主要提高了状态访问的成本（[EIP-1884](/eip-1884/)、[EIP-2929](/eip-2929/)），以纠正同样的失衡。
- [EIP-2035](/eip-2035/) 是相关的提案，同样处于 Stagnant，内容是为无状态客户端重新定价 `SLOAD`/`SSTORE`。


---

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