---
eip: 7516
label: EIP-7516
title: BLOBBASEFEE instruction
status: Final
type: Standards Track
category: Core
created: 2023-09-11
requires: 3198, 4844
official: https://eips.ethereum.org/EIPS/eip-7516
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7516.md
canonical: https://eips.huatuo.xyz/zh/eip-7516/
lang: zh
tldr: 新增 BLOBBASEFEE opcode（0x4a），让合约可以读取 EIP-4844 中当前的 blob base fee，就像 BASEFEE 公开普通 base fee 一样。
tags: [opcode, evm, blobs, fees, cancun]
---

# EIP-7516: BLOBBASEFEE instruction

> Instruction that returns the current data-blob base-fee

**TL;DR:** 新增 BLOBBASEFEE opcode（0x4a），让合约可以读取 EIP-4844 中当前的 blob base fee，就像 BASEFEE 公开普通 base fee 一样。

## 它解决什么问题？

[EIP-4844](/eip-4844/) 引入了带有独立费用市场的携带 blob 的交易：blob gas 有单独的 base fee，会随 blob 需求而涨跌，与常规的 [EIP-1559](/eip-1559/) base fee 无关。合约原本就可以通过 `BASEFEE`（[EIP-3198](/eip-3198/)）读取常规 base fee，却没有办法看到 blob 的价格。

Rollup 要为 blob 数据付费，并且经常希望在链上核算或报销这些成本。如果 EVM 内部看不到这个价格，它们就只能信任链下预言机或中继者的一面之词。EIP-7516 填补了这个空白，也使得在链上构建 blob gas 对冲或期货合约之类的东西成为可能。

## 它如何运作

- 新 opcode `BLOBBASEFEE`，位于 `0x4a`。
- 不需要栈输入，压入一个值：当前区块的 blob base fee，单位为每单位 blob gas 的 wei。
- 该值正是 EIP-4844 中定义的 `get_blob_gasprice(header)`，由区块头的 `excess_blob_gas` 计算得出。
- gas 成本为 **2**，与 `BASEFEE` 相同，因为该值在执行开始前就已知，不需要访问状态。

规范中的例子：如果 blob base fee 是 7 wei，字节码 `0x4a00`（`BLOBBASEFEE`、`STOP`）会在栈上留下 `7`，并消耗 2 gas。

这个 opcode 与 EIP-4844 一起随 Cancun 执行层升级（Dencun）上线。

## 示例代码

Solidity 把它暴露为 `block.blobbasefee`（编译器为 Cancun EVM 目标增加了支持）：

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract BlobCostMeter {
    uint256 constant GAS_PER_BLOB = 131072; // 2**17, from EIP-4844

    /// Estimated cost in wei of posting `blobs` blobs in this block.
    function blobCost(uint256 blobs) external view returns (uint256) {
        return blobs * GAS_PER_BLOB * block.blobbasefee;
    }

    /// Same value via inline assembly.
    function rawBlobBaseFee() external view returns (uint256 fee) {
        assembly { fee := blobbasefee() }
    }
}
```

作为对照，用 ethers v6 在链下读取：

```ts
const block = await provider.send("eth_getBlockByNumber", ["latest", false]);
console.log("excessBlobGas:", BigInt(block.excessBlobGas));
// The contract above returns the derived blob base fee directly.
```

## 需要注意

- 状态：**Final**，自 Cancun 起已在主网上线。
- 该值适用于正在执行的区块。对 `latest` 发起的 `eth_call` 中，客户端会按待处理上下文来计算，因此结果可能与之后的交易所看到的不同。
- 编译时请把 `evmVersion` 设为 `cancun` 或更高；在尚未采用 Cancun 的旧链或 L2 上，`0x4a` 是无效 opcode。
- 当 blob 需求低于目标时，blob base fee 可以低至 1 wei；当需求持续高于目标时，它可能快速上升，所以不要硬编码预期值。


---

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