---
eip: 7612
label: EIP-7612
title: Verkle state transition via an overlay tree
status: Stagnant
type: Standards Track
category: Core
created: 2024-01-25
requires: 4762, 6800, 7545
official: https://eips.ethereum.org/EIPS/eip-7612
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7612.md
canonical: https://eips.huatuo.xyz/zh/eip-7612/
lang: zh
tldr: "提议把以太坊的状态切换为 Verkle 树：冻结现有的 Merkle Patricia 树，把所有新状态写入其上的 Verkle\"叠加层\"，将旧数据缓慢的迁移推迟到后续步骤。"
tags: [verkle, state, stateless, migration, core]
---

# EIP-7612: Verkle state transition via an overlay tree

> Describes the use of an overlay tree to use the verkle tree structure, while leaving the historical state untouched.

**TL;DR:** 提议把以太坊的状态切换为 Verkle 树：冻结现有的 Merkle Patricia 树，把所有新状态写入其上的 Verkle"叠加层"，将旧数据缓慢的迁移推迟到后续步骤。

## 它解决什么问题？

把以太坊的状态从十六叉 Merkle Patricia 树（MPT）迁移到 Verkle 树（[EIP-6800](/eip-6800/)），是实现无状态客户端的前提条件。但转换整个状态很困难：存储量巨大的合约在被转换的同时仍在被读写，漫长的转换会拖慢全量同步、重组和客户端的发布周期。而且状态越大，任何转换所需的时间就越长。

EIP-7612 提供了一个权宜之计：*现在*就让 MPT 停止增长，之后再转换历史数据。

## 它如何运作

- 在 `FORK_TIME`（从未设定）时，MPT 被**冻结**。创建一棵新的、最初为空的 **Verkle 叠加树**。
- **写入**（账户、存储槽、代码块）只进入叠加树，使用 EIP-6800 的键推导方式。账户基本数据（版本、代码大小、nonce、余额）被打包进一个叶子，代码哈希放在相邻的叶子中。
- **读取**先检查叠加层，如果键不在其中，则回退到冻结的 MPT。
- 从分叉区块开始，区块头中的 `stateRoot` 是 **Verkle 根**，而不是 MPT 根。
- 一旦冻结区块被最终确定，客户端就可以删除 MPT 的内部节点以节省磁盘空间。在叶子数据被迁移之前，仍然需要保留它们。

把冻结的 MPT 数据迁移到 Verkle 树，被明确留给后续的 EIP（[EIP-7748](/eip-7748/) 描述了一种这样的转换）。不需要共识层的变更。

## 示例代码

修改后的状态访问器，根据规范中 execution-spec 的 diff 简化而来：

```python
def get_account_optional(state, address):
    acct = verkle_get_account(state._overlay_tree, get_tree_key_for_version(address))
    if acct is not None:
        return acct
    return trie_get(state._main_trie, address)          # frozen MPT fallback

def set_account(state, address, account):
    verkle_set_account(state._overlay_tree, get_tree_key_for_version(address), account)

def get_storage(state, address, slot):
    v = state._overlay_tree.get(get_tree_key_for_storage_slot(address, slot))
    if v is not None:
        return v
    trie = state._storage_tries.get(address)
    return U256(0) if trie is None else trie_get(trie, slot)

def set_storage(state, address, slot, value):
    state._overlay_tree.set(get_tree_key_for_storage_slot(address, slot), value)
```

## 需要注意

- 状态为 **Stagnant**。`FORK_TIME` 为 TBD，安全性一节写的是"needs discussion"。
- 它依赖于 [EIP-6800](/eip-6800/)（Verkle 状态，同样处于 Stagnant）、[EIP-4762](/eip-4762/)（无状态 gas 成本）和 [EIP-7545](/eip-7545/)（证明预编译，Stagnant）。此后，统一的**二叉**树（[EIP-7864](/eip-7864/)，Draft）已被提议作为目标状态结构。
- 在旧状态完全迁移之前，双重查找（先叠加层，再 MPT）会带来额外的读取开销。
- 参考实现是 go-ethereum 的一个研究分支，而不是已发布的客户端功能。


---

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