---
eip: 8125
label: EIP-8125
title: Temporary Contract Storage
status: Draft
type: Standards Track
category: Core
created: 2026-01-14
requires: 2200, 2929
official: https://eips.ethereum.org/EIPS/eip-8125
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-8125.md
canonical: https://eips.huatuo.xyz/zh/eip-8125/
lang: zh
tldr: 新增 TMPLOAD/TMPSTORE 操作码，提供一种可跨交易和区块保留、但会按固定周期自动清除的合约存储，让短期数据有了一个不会让以太坊状态永远增长的存放处。
tags: [evm, storage, state-growth, opcodes, core]
---

# EIP-8125: Temporary Contract Storage

> Adds bounded-lifetime contract storage via TMPLOAD/TMPSTORE opcodes that is automatically cleared on a fixed schedule.

**TL;DR:** 新增 TMPLOAD/TMPSTORE 操作码，提供一种可跨交易和区块保留、但会按固定周期自动清除的合约存储，让短期数据有了一个不会让以太坊状态永远增长的存放处。

## 它解决什么问题？

目前合约有两个地方可以存数据：永久存储（`SSTORE`），除非显式删除否则永远留在状态中；以及瞬态存储（transient storage，[EIP-1153](/eip-1153/)），在交易结束时消失。许多应用需要介于两者之间的东西：在一段时间内（几分钟、几天）重要、之后就没用的数据。它们把这类数据放进永久存储，而大部分永远不会被清理。规范引用的数据显示，超过 60 % 的存储槽只被写入一次，之后再也没有被访问过。

临时存储（temporary storage）为这类数据设定有限的生命周期，节点就不必永远携带它们。

## 它如何运作

- 两个新操作码：`TMPSTORE(key, value)` 和 `TMPLOAD(key)`，与 `SSTORE`/`SLOAD` 一样作用域限定于正在执行的合约。
- 值存放在**两个保留系统账户**的存储 trie 中，槽位为 `keccak256(contract_address || key)`。
- 时间被划分为每段 `TEMP_STORAGE_PERIOD` 个区块的**周期（period）**。两个系统账户轮流充当“当前（current）”和“上一个（previous）”。在新周期的第一个区块，即将成为当前的那个账户的 `storageRoot` 被重置为空，这是一个常数时间的操作。
- `TMPSTORE` 把非零值写入当前账户；写入 `0` 则会从两个账户中删除该槽位。
- `TMPLOAD` 从当前账户读取，读不到时回退到上一个账户。

结果是：无论写入发生在周期中的什么时候，写入的内容都**至少可读一个完整周期，最多两个周期**。gas 的设计目标是远低于 `SSTORE`/`SLOAD`，但高于 `TSTORE`/`TLOAD`，且清除时没有退款；具体数值仍待确定（TBD）。

## 示例代码

这些操作码目前还没有 Solidity 语法；轮换逻辑的伪代码如下：

```python
def period_index(n):
    return (n - FORK_BLOCK) // TEMP_STORAGE_PERIOD

def accounts(n):
    if period_index(n) % 2 == 0:
        return ADDR_0, ADDR_1    # (current, previous)
    return ADDR_1, ADDR_0

def on_block_start(block, parent):
    if period_index(block.number) > period_index(parent.number):
        current, _ = accounts(block.number)
        state[current].storage_root = EMPTY_TRIE_ROOT   # drop data older than one period

def tmpload(contract, key, n):
    cur, prev = accounts(n)
    slot = keccak256(contract + key)
    return state[cur].storage.get(slot) or state[prev].storage.get(slot, 0)
```

## 需要注意

- 状态为 **Draft**。周期长度、系统地址、分叉区块和所有 gas 成本都仍待确定。
- 合约必须把临时存储视为易失的，并处理已经过期的条目。
- 与瞬态存储不同，数据确实会跨交易和区块保留，因此仍会给节点带来一定成本；gas 必须经过校准，以避免磁盘 I/O 类的 DoS。
- 需要硬分叉；现有操作码不变。


---

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