---
eip: 3416
label: EIP-3416
title: Median Gas Premium
status: Stagnant
type: Standards Track
category: Core
created: 2021-03-18
official: https://eips.ethereum.org/EIPS/eip-3416
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3416.md
canonical: https://eips.huatuo.xyz/zh/eip-3416/
lang: zh
tldr: 一项已停滞的 EIP-1559 替代方案：区块内所有人都支付基础费用加上按 gas 加权的中位数溢价，目标是在不新增交易字段的情况下平滑费用飙升。
tags: [gas, fees, core, fee-market, stagnant]
---

# EIP-3416: Median Gas Premium

> A transaction pricing mechanism with a fixed-per-block network fee and a median inclusion fee with additive updates.

**TL;DR:** 一项已停滞的 EIP-1559 替代方案：区块内所有人都支付基础费用加上按 gas 加权的中位数溢价，目标是在不新增交易字段的情况下平滑费用飙升。

## 它解决什么问题？

2021 年之前，以太坊采用第一价格拍卖：每笔交易恰好支付它所出价的 `gasPrice`。用户必须猜测别人会出什么价，费用每分钟都在跳动，许多人付多了。

[EIP-1559](/eip-1559/) 是当时领先的解决方案。EIP-3416 的作者认为 1559 并没有真正平滑价格中的**小费**（优先费）部分，于是提出了另一种设计。它保留协议的基础费用，但用由中位数得出的、全区块统一的单一溢价取代各笔交易各自的小费，因此最终价格更难被操纵，而且通常低于用户的出价。

## 它如何运作

- **基础费用**：由协议每个区块根据父区块的 gas 使用量设定，但采用的是**加法**更新规则，而不是 1559 的乘法规则：
  `BASE_FEE = PARENT_BASE_FEE + GAS_DELTA * BASE_FEE_MAX_CHANGE`，其中 `BASE_FEE_MAX_CHANGE = 1/8`。作者选择这样做，是为了抵御模拟中观察到的一种会把乘法式基础费用推向零的攻击。
- **没有新的交易格式**：沿用传统交易，其 `gasPrice` 被重新解释为**费用上限**。`费用上限 < 基础费用` 的交易暂时无法被包含。
- **隐含溢价**：每笔交易的溢价为 `(费用上限 - 基础费用) / 2`，即其余量的一半。
- **区块统一价格**：区块内所有人都支付 `BASE_FEE + weighted_median(premiums)`。中位数按使用的 gas 加权，价格最高的 5% gas 被作为异常值排除，以限制区块生产者的操纵。
- 用户按该价格乘以使用的 gas 被收费，未使用的 gas 照常退还。区块生产者仍然可以按费用上限贪心地填满区块，因为溢价随费用上限上升。

## 示例代码

每个区块价格的伪代码（对规范做了简化）：

```python
def block_gas_price(base_fee, txs):
    # each tx: (fee_cap, gas_used)
    units = sorted(
        ((base_fee + (cap - base_fee) // 2, gas) for cap, gas in txs if cap >= base_fee),
        key=lambda x: x[0],
    )
    total = sum(g for _, g in units)
    cutoff = total * 95 // 100        # ignore the most expensive 5 % of gas
    half, seen = cutoff // 2, 0
    for price, gas in units:
        seen += gas
        if seen >= half:
            return price              # gas-weighted median, outliers excluded
    return base_fee

def charge(tx, price, gas_used):
    return price * gas_used           # same price for every tx in the block
```

## 需要注意

- 状态：**Stagnant**。它从未被排期。以太坊转而在伦敦升级中采用了 [EIP-1559](/eip-1559/)，带有明确的 `maxFeePerGas` / `maxPriorityFeePerGas` 字段和被销毁的基础费用。
- 若干参数未定义（`FORK_BLOCK_NUMBER`，以及每个区块的 gas 目标如何得出），Test Cases 为"TBD"。
- 由于区块内所有人支付相同的价格，用户无法可靠地通过多付钱在区块内获得优先。规范认为区块生产者仍会偏好更高的费用上限，因为它们会抬高中位数。
- 如果你现在需要在链上获取实际的费用水平，请使用 [EIP-3198](/eip-3198/) 的 `BASEFEE`。


---

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