---
eip: 4844
label: EIP-4844
title: Shard Blob Transactions
status: Final
type: Standards Track
category: Core
created: 2022-02-25
requires: 1559, 2718, 2930, 4895
official: https://eips.ethereum.org/EIPS/eip-4844
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md
canonical: https://eips.huatuo.xyz/zh/eip-4844/
lang: zh
tldr: Proto-danksharding：新增携带 blob 的交易，拥有独立且廉价的费用市场，为 rollup 提供临时数据空间，大幅降低 L2 费用。
tags: [blobs, rollups, scaling, data-availability, kzg, dencun]
---

# EIP-4844: Shard Blob Transactions

> Shard Blob Transactions scale data-availability of Ethereum in a simple, forwards-compatible manner.

**TL;DR:** Proto-danksharding：新增携带 blob 的交易，拥有独立且廉价的费用市场，为 rollup 提供临时数据空间，大幅降低 L2 费用。

## 它解决什么问题？

Rollup 把交易数据发布到以太坊，让任何人都能重建 L2 状态。在这个 EIP 之前，这些数据放在 `calldata` 中，每个节点会永久存储它，其定价也和其他执行资源一样。数据发布占了用户在 L2 上所付费用的大部分。

EIP-4844（随 2024 年 3 月的 Dencun 升级上线）为 rollup 提供了一个专用、更便宜的数据存放位置：**blob**。Blob 无法被 EVM 访问，并在几周后被修剪，这足够让任何人下载并验证。这是迈向完整 danksharding 的第一步，并保持了日后数据可用性采样将使用的同一种交易格式。

## 它如何运作

- **Blob 交易**是一种新的 [EIP-2718](/eip-2718/) 类型，即 `0x03`。它们具有 [EIP-1559](/eip-1559/) 的费用字段，外加 `max_fee_per_blob_gas` 和 `blob_versioned_hashes`。必须设置 `to`，因此无法创建合约。
- **一个 blob** 是 4096 个域元素 × 32 字节 = 128 KiB。每个 blob 都有一个 KZG 承诺；交易只携带 `versioned_hash = 0x01 || sha256(commitment)[1:]`。
- **Sidecar。** Blob 随信标区块传输，而不在执行负载之内。共识层会保留它们 `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` = 4096 个 epoch（约 18 天）。在内存池中，blob 交易以 `[tx, blobs, commitments, proofs]` 的形式进行 gossip，且只做通告，从不主动推送。
- **独立的费用市场。** 每个 blob 消耗 `GAS_PER_BLOB` = 131072 blob gas。区块头新增 `blob_gas_used` 和 `excess_blob_gas`，blob 基础费用为 `fake_exponential(1, excess_blob_gas, 3338477)`：使用量持续高于目标时按指数上升，低于目标时下降。Blob 费用会被销毁，交易失败时也不退还。
- **最初的限制：** 每个区块目标 393216 / 最大 786432 blob gas，即 3 / 6 个 blob。这些数值后来已被提高（见下文）。
- **EVM 访问：** `BLOBHASH`（`0x49`，3 gas）返回指定索引处的 versioned hash；位于 `0x0A` 的**点求值预编译**（50000 gas）验证一个 KZG 证明，证明该 blob 在点 `z` 处求值为 `y`。欺诈证明或有效性证明就是这样引用 blob 内容的。

## 示例代码

一个 rollup inbox 合约，记录当前交易所附带的 blob（Solidity ≥ 0.8.24 提供 `blobhash` 和 `block.blobbasefee`）：

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

contract BlobInbox {
    event BatchPosted(uint256 indexed index, bytes32 versionedHash, uint256 blobBaseFee);

    function postBatch(uint256 numBlobs) external {
        for (uint256 i = 0; i < numBlobs; i++) {
            bytes32 h = blobhash(i);           // BLOBHASH opcode
            require(h != bytes32(0), "missing blob");
            emit BatchPosted(i, h, block.blobbasefee);
        }
    }
}
```

规范中的 blob 基础费用更新公式：

```python
def calc_excess_blob_gas(parent):
    total = parent.excess_blob_gas + parent.blob_gas_used
    return max(0, total - TARGET_BLOB_GAS_PER_BLOCK)

base_fee_per_blob_gas = fake_exponential(1, excess_blob_gas, 3338477)
```

## 需要注意

- 状态：**Final**，自 Dencun 起已在主网上线。
- Blob 容量后来已由 [EIP-7691](/eip-7691/) 提高，`BLOBBASEFEE` opcode（[EIP-7516](/eip-7516/)）让合约可以读取 blob 价格。请查看当前参数，不要依赖最初的 3/6 这组数字。
- Blob 是临时的。需要长期保存数据的人（rollup 节点、索引器、浏览器等）必须在保留窗口内将其归档。
- 合约永远无法读取 blob 的字节内容，只能读取其 versioned hash 和经 KZG 证明的求值结果。
- 发送 blob 交易需要 KZG 库来计算承诺和证明；大多数团队使用其 rollup 技术栈的 batcher 或客户端库，而不是手工完成。


---

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