---
eip: 7688
label: EIP-7688
title: Forward compatible consensus data structures
status: Review
type: Standards Track
category: Core
created: 2024-04-15
requires: 7495, 7607, 7916
official: https://eips.ethereum.org/EIPS/eip-7688
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7688.md
canonical: https://eips.huatuo.xyz/zh/eip-7688/
lang: zh
tldr: 将信标链的 SSZ 类型迁移为 ProgressiveContainer 和 ProgressiveList，使 Merkle 证明在跨分叉后依然有效，同时不改变数据的序列化方式。
tags: [consensus, ssz, merkle, proofs, core]
---

# EIP-7688: Forward compatible consensus data structures

> Transition consensus SSZ data structures to ProgressiveContainer

**TL;DR:** 将信标链的 SSZ 类型迁移为 ProgressiveContainer 和 ProgressiveList，使 Merkle 证明在跨分叉后依然有效，同时不改变数据的序列化方式。

## 它解决什么问题？

`BeaconState`、`BeaconBlockBody` 和 `ExecutionPayload` 等信标链对象都是 SSZ 的 `Container`。SSZ 既定义了它们如何序列化，也定义了如何 Merkle 化，借助 Merkle 根，任何人都可以针对区块根证明单个字段，例如某个验证者没有被 `slashed`。质押池、跨链桥和轻客户端会在智能合约或设备中验证这类证明。

问题在于：使用普通的 `Container` 时，Merkle 树的形状取决于字段数量。当某次分叉增加或移除字段时，其他字段的*广义索引*（gindex，即树中的路径）可能发生移动，所有验证方都必须随分叉计划同步更新。固定容量的 `List[T, N]` 在上限变化时也会引起类似的反复改动。

EIP-7688 为这些结构提供稳定的 Merkle 化，因此只要字段仍然存在，检查 `validator.slashed` 的验证方就能持续正常工作。

## 它如何运作

它应用了两种新的 SSZ 类型：

- **`ProgressiveContainer`**（[EIP-7495](/eip-7495/)）带有一个 `active_fields` 位图。每个字段拥有永久的位置。追加字段的分叉会在位图末尾加一个 `1`；移除字段的分叉则把该字段对应的位设为 `0`，而不是移动其他字段。
- **`ProgressiveList` / `ProgressiveBitlist`**（[EIP-7916](/eip-7916/)）取代受容量限制的列表。每个元素的 gindex 不依赖于元素数量。上限从类型中移到运行时检查里。

预计会演进的容器会被转换，包括 `Attestation`、`IndexedAttestation`、`ExecutionPayload(Header)`、`ExecutionRequests`、`BeaconBlockBody` 和 `BeaconState`。其中许多列表字段（validators、balances、attestations、withdrawals、deposits 等）会变成 progressive 列表。`Validator`、`Checkpoint` 和 `AttestationData` 等较小的构件被声明为不可变：如果将来需要不兼容的改动，就必须引入新的类型和新的字段名。

只有 Merkle 化发生变化。**受影响类型的序列化保持不变**，并且为各个主题定义了网络消息大小上限，使 gossip 限制不再依赖旧的列表容量。

## 示例代码

规范中的转换模式，采用 consensus-specs 的 Python 风格：

```python
# Before: tree shape depends on the field count
class Foo(Container):
    a: uint8
    b: uint16

# After: each field has a stable gindex
class Foo(ProgressiveContainer(active_fields=[1, 1])):
    a: uint8
    b: uint16

# A later fork appends c and drops a: positions of b and c stay stable
class Foo(ProgressiveContainer(active_fields=[0, 1, 1])):
    b: uint16
    c: uint32
```

固定容量的列表变成 progressive 列表加运行时限制：

```python
# Before
attestations: List[Attestation, MAX_ATTESTATIONS_ELECTRA]
# After
attestations: ProgressiveList[Attestation]
assert len(body.attestations) <= MAX_ATTESTATIONS_ELECTRA  # enforced in logic
```

## 需要注意

- **状态：Review。** 规范文本和被转换类型的清单仍可能变化。它依赖 EIP-7495 和 EIP-7916，这两者同样处于 Review 阶段。
- 采用后，现有的证明和验证方需要最后更新一次，因为 gindex 会变一次。好处是之后的分叉应该不会再次破坏它们。
- 一些旧的上限，例如 `MAX_TRANSACTIONS_PER_PAYLOAD`，不再由类型强制执行；其他约束（gas、网络消息大小）仍会限制实际大小。
- 如果你为信标状态编写链上验证合约，请密切关注这个 EIP：它决定了你的证明路径会有多稳定。


---

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