---
eip: 2028
label: EIP-2028
title: Transaction data gas cost reduction
status: Final
type: Standards Track
category: Core
created: 2019-05-03
official: https://eips.ethereum.org/EIPS/eip-2028
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2028.md
canonical: https://eips.huatuo.xyz/zh/eip-2028/
lang: zh
tldr: 将非零 calldata 字节的 gas 成本从 68 降到 16，使在链上发布数据便宜得多，而 rollup 和证明系统都依赖这一点。
tags: [gas, calldata, transactions, scaling, istanbul]
---

# EIP-2028: Transaction data gas cost reduction

> We propose to reduce the gas cost of Calldata (GTXDATANONZERO) from its current value of 68 gas per byte to 16 gas per byte, to be backed by mathematical modeling and empirical estimates.

**TL;DR:** 将非零 calldata 字节的 gas 成本从 68 降到 16，使在链上发布数据便宜得多，而 rollup 和证明系统都依赖这一点。

## 它解决什么问题？

交易输入数据（calldata）的每个字节都要消耗 gas。自 Frontier 以来，非零字节花费 68 gas（`GTXDATANONZERO`），零字节花费 4 gas。这个价格定得比较保守，使数据密集型的用途变得昂贵：

- **Layer-2 rollup** 为了数据可用性，把交易批次或状态差异作为 calldata 发布到 L1。
- **证明系统**（SNARK、STARK）需要提交大型证明和公开输入。
- **欺诈证明和无状态设计**传递的是 Merkle 证明，而不是读取存储。

作者（包括 StarkWare 团队）认为，数据消耗的主要是网络带宽和区块传播时间，而 68 gas 高估了这一成本。EIP-2028 降低了它，并随 Istanbul 升级上线。

## 它如何运作

只改变一个常量：

| 字节值 | 之前 | 之后 |
| --- | --- | --- |
| 零（`0x00`） | 4 gas | 4 gas（不变） |
| 非零 | 68 gas | **16 gas** |

这是交易固有 gas（intrinsic gas）的一部分，在执行前收取：`21000 + 4·zeroBytes + 16·nonZeroBytes`（适用时再加上合约创建和访问列表的成本）。

其依据是 Sompolinsky–Zohar 与 Pass–Seeman–Shelat 的模型，该模型把区块传播延迟与安全性联系起来：区块越大传播越慢，会让更多诚实算力浪费在过期区块上，从而降低攻击成本。该提案把延迟拆分为传输和处理两部分，并论证 calldata 主要增加的是传输延迟，在每字节 16 gas 的水平下网络可以承受。

## 示例代码

计算固有 gas 中 calldata 部分（TypeScript，ethers v6）：

```ts
import { getBytes, Interface, parseEther } from "ethers";

function calldataGas(data: string): number {
  let gas = 0;
  for (const b of getBytes(data)) gas += b === 0 ? 4 : 16; // post-EIP-2028 prices
  return gas;
}

// transfer(address,uint256) has many zero bytes from ABI padding
const erc20 = new Interface(["function transfer(address to, uint256 value)"]);
const data = erc20.encodeFunctionData("transfer", [
  "0x000000000000000000000000000000000000dEaD",
  parseEther("1"),
]);

console.log(21_000 + calldataGas(data)); // intrinsic gas for this simple call
```

## 需要注意

- 零字节仍然更便宜，因此避免非零填充（或采用零字节较多的布局）的紧凑编码可以节省 gas。
- calldata 变便宜，是早期使用 calldata 保证数据可用性的 optimistic rollup 和 ZK rollup 的重要推动力。
- rollup 数据后来通过 [EIP-4844](/eip-4844/) 转移到了拥有独立费用市场的 blob 上。
- [EIP-7623](/eip-7623/) 后来为数据密集型交易引入了更高的下限价格，因此 calldata 非常多的交易不再只按简单的 16 gas 费率付费。估算成本时，请查看目标分叉的规则。


---

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