---
eip: 8304
label: EIP-8304
title: Trustless log and transaction index
status: Draft
type: Standards Track
category: Core
created: 2026-06-17
requires: 4788
official: https://eips.ethereum.org/EIPS/eip-8304
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8304.md
canonical: https://eips.huatuo.xyz/zh/eip-8304/
lang: zh
tldr: 提出让每个区块把其交易和日志的有序索引表提交到一个系统合约中，使任何人都能获得紧凑的证明，证明某次日志或交易查询的结果既正确又完整。
tags: [logs, indexing, light-clients, proofs, core]
---

# EIP-8304: Trustless log and transaction index

> Store the root hashes of index tables in a system contract to allow efficient trustless proofs of log and transaction lookups

**TL;DR:** 提出让每个区块把其交易和日志的有序索引表提交到一个系统合约中，使任何人都能获得紧凑的证明，证明某次日志或交易查询的结果既正确又完整。

## 它解决什么问题？

日志（事件）发出的成本很低，但协议没有提供高效*搜索*它们的方法。区块头中每个区块的 bloom 过滤器已经过度饱和，如今几乎毫无用处。于是用户向 RPC 提供商请求"给我所有发到我地址的 `Transfer` 事件"，只能完全信任对方的回答：提供商无法证明结果是正确的，也无法证明没有遗漏任何内容。

EIP-8304 增加了一个维护成本低、支持无需信任的查询证明的索引。规范还提到了跨链消息（根据已知的区块哈希，证明另一条链上发出的日志），以及之后把日志用作一种廉价、易于过期的状态形式。

## 它如何运作

- **索引条目。** 对每个区块，客户端为每个交易哈希、每条日志的地址及其每个主题（topic），以及（延后一个区块）父区块哈希推导出条目。每个条目是大端字节序的 `type ‖ value ‖ position`，例如 `log.address` 条目是 `0x0002 ‖ address ‖ block number ‖ tx index ‖ log index`（38 字节）。
- **索引表。** 条目按字典序排序并哈希：每个条目做 SHA-256，表根是该 `List[Hash32]` 的 SSZ 根。排序使*排除*变得可证明：你可以证明不存在更多匹配的条目。
- **层级。** 存在 1、4、16、64 和 256 个区块的表。较大的表由下一层的四个表合并而成，并延迟 `table_size / 4` 个区块提交，这样合并可以在后台进行。
- **系统合约。** 每个区块之后，一次系统调用会存储 `(first_block, table_size, table_root)`。每一层保留一个 1024 项的环形缓冲区，因此协议内的表大约覆盖最近 2^18 个区块。任何人都可以调用 `get(first_block, table_size)` 来读取根。
- **更早的历史**预计由在协议外构建的大得多的表来覆盖，并在共用同一 `get` 接口的独立"历史索引合约"中通过 ZK 证明来证明。

区块头的 bloom 保持不变，`LOG` 的 gas 成本也不会增加。

## 示例代码

编码一个 `log.topics[0]` 条目并读取表根（合约地址在规范中仍为 TBD）：

```python
def topic0_entry(topic: bytes, block: int, tx_index: int, log_index: int) -> bytes:
    # type 3 = log.topics[0]; 2 + 32 + 8 + 4 + 4 = 50 bytes
    return (3).to_bytes(2, "big") + topic + block.to_bytes(8, "big") \
        + tx_index.to_bytes(4, "big") + log_index.to_bytes(4, "big")

entry_hash = sha256(topic0_entry(TRANSFER_TOPIC, 42, 0, 1))
```

```solidity
// get(): 64 bytes of calldata -> 32-byte table root, reverts if unknown/overwritten
function tableRoot(address index, uint256 firstBlock, uint256 tableSize) view returns (bytes32) {
    (bool ok, bytes memory ret) = index.staticcall(abi.encode(firstBlock, tableSize));
    require(ok, "no root");
    return abi.decode(ret, (bytes32));
}
```

## 需要注意

- 状态为 **Draft**。合约地址和部署细节仍为 TBD。
- [EIP-7745](/eip-7745/) 出自同一位作者，标题相同，是一个更早的、不同的设计，它取代区块头的 bloom 过滤器；本提案不动 bloom，而是着重于降低每个区块的处理成本。
- 同步之后，客户端最多只需要最近 319 个区块，就能重建它接下来必须提交的表；不需要更改同步协议。
- 如果 [EIP-8141](/eip-8141/) 的 frame 交易被激活，日志位置中会增加一个 2 字节的 frame 索引。在 [EIP-7708](/eip-7708/) 之后，可以在另一个索引合约中，连同 ETH 转账日志一起对历史重新建立索引。
- 查询证明比状态证明更大；规范预计一次典型的查询需要几十个单独的表证明。


---

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