---
eip: 6466
label: EIP-6466
title: SSZ receipts
status: Draft
type: Standards Track
category: Core
created: 2023-02-08
requires: 658, 2718, 6404, 7495, 7668, 7702, 7916, 8016, 8116
official: https://eips.ethereum.org/EIPS/eip-6466
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-6466.md
canonical: https://eips.huatuo.xyz/zh/eip-6466/
lang: zh
tldr: 一项草案计划：用 SSZ 收据取代 RLP 编码的交易收据及其 Patricia 树根，使单个日志和字段可以被低成本地证明。
tags: [ssz, receipts, logs, core, serialization]
---

# EIP-6466: SSZ receipts

> Migration of RLP receipts to SSZ

**TL;DR:** 一项草案计划：用 SSZ 收据取代 RLP 编码的交易收据及其 Patricia 树根，使单个日志和字段可以被低成本地证明。

## 它解决什么问题？

每笔交易都会产生一个收据（成功标志、gas、日志）。目前，收据采用 RLP 编码，并通过 Merkle-Patricia Trie 提交到区块头的 `receipts_root` 中。由此带来两个弱点：

- **难以证明局部。** 每个收据作为一个整体被哈希，因此要证明单个日志就必须提供整个收据。这对轻客户端、跨链桥和 L2 欺诈证明来说成本很高。
- **缺失的数据。** JSON-RPC 会返回 `from`、`gasUsed` 和 `contractAddress`，但链上收据并不包含它们，因此无法对照区块头验证（`from` 必须通过 `ecrecover` 恢复）。

EIP-6466 把收据迁移到 SSZ（Simple Serialize，共识层已经在使用的格式），它与关于 SSZ 交易的 [EIP-6404](/eip-6404/) 同属一项更广泛的工作。

## 它如何运作

`Log` 变成一个 SSZ 容器：`address`、最多 4 个 `topics` 和 `data`。

`Receipt` 是三种形态的带标签联合，它们共享同一个 Merkle 布局，因此每个字段都位于稳定的位置（generalized index）：

| 变体 | 适用于 | 字段 |
| --- | --- | --- |
| `BasicReceipt` | 普通调用、blob 交易 | `from`、`gas_used`、`logs`、`status` |
| `CreateReceipt` | 合约部署 | 增加 `contract_address` |
| `SetCodeReceipt` | [EIP-7702](/eip-7702/) 的 set-code 交易 | 增加 `authorities`（失败的授权显示为零地址） |

`status` 保持 [EIP-658](/eip-658/) 的含义。`gas_used` 仅是该笔交易自身的 gas。`logs_bloom`、旧的中间状态根和 `cumulative_gas_used` 被移除。

区块头的 `receipts_root` 变成收据列表的 SSZ `hash_tree_root`，共识的 `ExecutionPayload` 字段类型也相应改变。在 JSON-RPC 中，收据新增 `authorities` 数组，新收据不再返回 `logsBloom`，并且 `logIndex` 在收据内部而不是在区块内计数（依据 [EIP-8116](/eip-8116/)）。

## 示例代码

规范中的 SSZ 类型定义（Python 风格，与共识规范中使用的一致）：

```python
class Log(Container):
    address: ExecutionAddress            # Bytes20
    topics: List[Bytes32, 4]             # LOG0..LOG4
    data: ProgressiveByteList

class BasicReceipt(ProgressiveContainer(active_fields=[1, 1, 0, 1, 1])):
    from_: ExecutionAddress
    gas_used: GasAmount                  # uint64
    logs: ProgressiveList[Log]
    status: boolean

class Receipt(CompatibleUnion({
    0x01: BasicReceipt,
    0x02: CreateReceipt,
    0x03: SetCodeReceipt,
})):
    pass

# Header commitment
block_header.receipts_root = ProgressiveList[Receipt](*receipts).hash_tree_root()
```

## 需要注意

- **状态：Draft。** 它没有被排入任何网络升级，并且依赖若干其他草案提案（EIP-6404 交易、progressive SSZ 类型、EIP-8116 等）。
- 对于任何用 MPT 证明对照区块头验证收据的东西，以及依赖 bloom 的日志过滤，这是一项破坏性变更。
- RLP 和 SSZ 收据在编码后可能发生冲突，因此某个网络通道必须只使用一种格式；区块头会告诉你适用哪个分叉的格式。
- 提交 `from` 和 `contract_address` 使验证者可以跳过 `ecrecover`，这也让未来更换签名方案更容易。


---

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