---
eip: 5022
label: EIP-5022
title: Increase price of SSTORE from zero to non-zero to 40k gas
status: Stagnant
type: Standards Track
category: Core
created: 2022-04-20
official: https://eips.ethereum.org/EIPS/eip-5022
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5022.md
canonical: https://eips.huatuo.xyz/zh/eip-5022/
lang: zh
tldr: 提议将 SSTORE 创建新存储槽（从零变为非零）时的 gas 成本从 20,000 翻倍到 40,000，以更真实地为状态增长定价。
tags: [gas, sstore, state-growth, core]
---

# EIP-5022: Increase price of SSTORE from zero to non-zero to 40k gas

> Increase the price of the SSTORE opcode from 20000 gas to 40000 gas when the original slot is zero and the resultant slot is non-zero.

**TL;DR:** 提议将 SSTORE 创建新存储槽（从零变为非零）时的 gas 成本从 20,000 翻倍到 40,000，以更真实地为状态增长定价。

## 它解决什么问题？

每个新的存储槽都会永久增加以太坊的状态，所有全节点都必须保存它。状态越大，每个新增的槽都会让节点运行得更慢、成本更高。然而创建一个槽的价格一直固定在 20,000 gas。

作者认为这被低估了：由于所有资源共享同一个 gas 上限，其他所有操作码的使用者实际上都在补贴状态的创建。状态增长也是 gas 上限没有被提高的主要原因之一。更准确地为新存储定价，会让提高 gas 上限更可行。

## 它如何运作

从某个分叉区块起对 gas 计价表做一处修改（规范将其留作 `TBD`）：

| 情形 | 之前 | 之后 |
| --- | --- | --- |
| `SSTORE` 从零到非零（`SSTORE_SET_GAS`） | 20,000 | **40,000** |
| 其他所有 `SSTORE` 情形 | 不变 | 不变 |

刻意不改变的部分：

- **非零到非零**的写入：它们不会增加状态，因此保持不变。更高的创建价格也会促使开发者复用存储槽。
- **清除存储槽的退款**：留待进一步讨论。

规范把它作为短期补丁提出，同时对状态租金或状态过期等长期想法仍在研究中。

## 示例代码

这一变化在合约中会体现在哪里：对 mapping 条目的第一次写入会创建一个存储槽。

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Registry {
    mapping(address => uint256) public score;

    function set(uint256 v) external {
        // First write for msg.sender: zero -> non-zero.
        //   Today: SSTORE_SET_GAS = 20,000 (plus cold-access cost).
        //   Under EIP-5022: 40,000.
        // Later writes (non-zero -> non-zero) are unaffected.
        score[msg.sender] = v;
    }
}
```

## 需要注意

- 状态为 **Stagnant**：该修改未被采纳。
- 规范承认这会大幅提高许多应用的成本，并且硬编码了 gas 数量且会创建存储的合约会失效。
- `SSTORE` 的完整成本还取决于净 gas 计量（[EIP-2200](/eip-2200/)）、冷/热访问（[EIP-2929](/eip-2929/)）和退款规则（[EIP-3529](/eip-3529/)）；这个 EIP 只改动创建存储槽的常量。
- 规范的安全考虑部分为空（`TODO`）。


---

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