---
eip: 7778
label: EIP-7778
title: Block Gas Accounting without Refunds
status: Last Call
type: Standards Track
category: Core
created: 2024-10-01
official: https://eips.ethereum.org/EIPS/eip-7778
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7778.md
canonical: https://eips.huatuo.xyz/zh/eip-7778/
lang: zh
tldr: 阻止 gas 退款减少计入区块 gas 上限的 gas，使区块无法携带超出上限允许的实际工作量，同时用户仍然能拿到退款。
tags: [gas, refunds, block-limit, core, dos]
---

# EIP-7778: Block Gas Accounting without Refunds

> Prevent Block Gas Limit Circumvention by Excluding Refunds from Block Gas Accounting

**TL;DR:** 阻止 gas 退款减少计入区块 gas 上限的 gas，使区块无法携带超出上限允许的实际工作量，同时用户仍然能拿到退款。

## 它解决什么问题？

有些操作，最典型的是用 `SSTORE` 把存储槽重置为零，会获得 **gas 退款**。目前这笔退款被扣了两次：一次从用户支付的费用中扣除，另一次从该交易计入**区块 gas 上限**的 gas 中扣除。

问题出在第二次。区块 gas 上限的作用是限制一个区块所包含的计算量。如果退款缩减了被计入的 gas，区块就可能包含比上限本意更多的实际工作。规范引用了主网区块 `20878522`：净使用 gas 为 2850 万，但退款有 401 万，所以在上限为 3000 万的区块里实际工作量约为 3250 万 gas。

这个差距可能被用来制造超大区块和拒绝服务攻击，也让区块处理时间更难预测。

## 它如何运作

该 EIP 把用户支付的部分与区块计入的部分分开。

**用户侧（不变）：**

```
gas_spent = max(tx_gas_used - gas_refund, calldata_floor_gas_cost)
```

**区块侧（新）：**不扣除退款。

```
block.gas_used += max(tx_gas_used, calldata_floor_gas_cost)
```

`calldata_floor_gas_cost` 这一项来自 [EIP-7623](/eip-7623/)。

只有*退款*被排除在外。真正反映工作量减少的折扣，例如热存储访问，或在净 gas 计量（[EIP-2200](/eip-2200/)）下把某个槽恢复为原始值，仍然按折后成本计入。

## 示例代码

构建区块时应用一笔交易的伪代码：

```python
def apply_transaction(block, tx):
    result = execute(tx)                      # result.gas_used is before refunds
    floor = calldata_floor_gas_cost(tx)       # EIP-7623

    # What the sender pays: refunds still apply
    user_gas = max(result.gas_used - result.gas_refund, floor)
    charge_sender(tx, user_gas)

    # What counts toward the block gas limit: refunds ignored
    block_gas = max(result.gas_used, floor)
    if block.gas_used + block_gas > block.gas_limit:
        raise InvalidBlock("gas limit exceeded")
    block.gas_used += block_gas
```

## 需要注意

- **状态：Last Call**（截止日期 2026-11-01）。尚未 Final，激活需要一次硬分叉。
- 单个用户支付的费用没有任何区别；退款与现在一样生效。
- 区块构建者必须改变交易选择方式。按旧的净额计算"已满"的区块，在新规则下可能超过上限，因此退款多的交易会比以前占用更多区块空间。
- 变更之后，区块头中的 `gasUsed` 不再等于用户被收取的费用之和，这对假定两者相等的工具有影响。
- 退款此前已被 [EIP-3529](/eip-3529/) 设置了上限；本 EIP 则彻底消除了退款对区块容量的影响。


---

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