---
eip: 8317
label: EIP-8317
title: Contract Storage Layout Descriptor Format
status: Draft
type: Standards Track
category: Interface
created: 2026-06-25
requires: 7201, 7730, 8042
official: https://eips.ethereum.org/EIPS/eip-8317
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8317.md
canonical: https://eips.huatuo.xyz/zh/eip-8317/
lang: zh
tldr: 一种与语言无关的 JSON 格式，用来描述合约每个变量在存储中的位置，包括带命名空间和 diamond 的布局，让钱包和浏览器能把原始的存储槽变化翻译成“Alice 的余额从 10 变成了 5”。
tags: [storage, tooling, wallets, clear-signing, json]
---

# EIP-8317: Contract Storage Layout Descriptor Format

> Defines a language-neutral, extensible JSON format for describing the storage layout of EVM contracts

**TL;DR:** 一种与语言无关的 JSON 格式，用来描述合约每个变量在存储中的位置，包括带命名空间和 diamond 的布局，让钱包和浏览器能把原始的存储槽变化翻译成“Alice 的余额从 10 变成了 5”。

## 它解决什么问题？

交易模拟会告诉你哪些原始存储槽发生了变化：`(contract, slot, old, new)`。要向用户展示有意义的内容，钱包必须知道每个存储槽属于哪个变量。目前工具依赖 Solidity 编译器输出的 `storageLayout`，它存在一些问题：

- 它是 Solidity 专属的（类型 ID 如 `t_uint256`），其他语言不会生成。
- Solidity 把它标注为实验性的，可能会更改。
- 它无法描述编译器不了解的布局，例如 [ERC-7201](/eip-7201/) 的命名空间存储或 [ERC-8042](/eip-8042/) 的 diamond 存储，也无法描述手写汇编的合约。

这个 EIP 为存储布局定义了一个稳定的模式（schema），让钱包、浏览器、调试器和安全工具可以共享描述文件，例如用来解释一笔交易或 [EIP-7906](/eip-7906/) 交易断言的效果。

## 它如何运作

布局文件是一个 JSON，包含三个必需部分：

- `compiler`：`language`（`"Solidity"`、`"Vyper"`，或用于 Huff/Yul/汇编的 `"manual"`），以及可选的版本和设置。
- `storage`：有序的条目，每个条目包含 `label`、`slot`（十进制字符串）、字节 `offset`、`type`，以及可选的 `path`、`source`（`"compiler"` 或 `"manual"`）、`baseSlotDerivation` 和 `display`。
- `types`：类型定义，包含 `encoding`（`inplace`、`inplace_struct`、`mapping`、`dynamic_array`、`bytes`）、源码级别的 `label` 和 `numberOfBytes`。

关键思路：

- **可验证的基础存储槽。** `baseSlotDerivation` 指明方案（`erc7201`、`erc8042` 或 `custom`）和命名空间 ID，所以使用方可以重新计算存储槽，而不必盲目相信它。
- 按语言和编码给出的**规范性推导公式**，例如 Solidity 的 mapping 位于 `keccak256(abi.encode(key, baseSlot))`，以及 Vyper 的差异（内联 `bytes`，Vyper 0.3.0 之前键的顺序相反）。
- **打包变量**通过 `offset` 和 `numberOfBytes` 提取。
- **显示注解**复用 [ERC-7730](/eip-7730/) 的词汇：带有 `{key[N]}`/`{index[N]}` 占位符的标签、`tokenAmount` 之类的值格式化器，以及带 JSON Logic 条件的模板。
- 瞬态存储不在范围内，因为它的寿命不超过该笔交易。

## 示例代码

一个 ERC-20 余额 mapping 的最小描述文件：

```json
{
  "compiler": { "language": "Solidity", "version": "0.8.24" },
  "storage": [
    {
      "label": "_balances",
      "slot": "0",
      "offset": 0,
      "type": "t_mapping(t_address,t_uint256)",
      "display": {
        "label": "Balance of {key[0]}",
        "keyFormats": [{ "format": "addressName" }],
        "template": "{label} changed from {oldValue} to {newValue}"
      }
    }
  ],
  "types": {
    "t_address": { "encoding": "inplace", "label": "address", "numberOfBytes": "20" },
    "t_uint256": { "encoding": "inplace", "label": "uint256", "numberOfBytes": "32" },
    "t_mapping(t_address,t_uint256)": {
      "encoding": "mapping", "label": "mapping(address => uint256)",
      "numberOfBytes": "32", "key": "t_address", "value": "t_uint256"
    }
  }
}
```

## 需要注意

- 状态为 **Draft**；模式和支持的语言可能会变化。新增语言必须通过更新这个 ERC 来加入。
- 该文件格式没有定义信任模型。恶意的描述文件可能会错误标注一次真实的存储变化，因此使用它的标准（如 ERC-7730）必须在钱包依赖它之前确立其真实性。
- `display.description` 仅供参考，不得用来驱动安全决策。
- 描述文件可以混合编译器生成的条目和手工编写的条目，这对代理、diamond 和 EIP-7702 delegate 很重要。


---

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