---
eip: 7650
label: EIP-7650
title: Programmable access lists
status: Stagnant
type: Standards Track
category: Core
created: 2024-03-10
requires: 2929, 2930
official: https://eips.ethereum.org/EIPS/eip-7650
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7650.md
canonical: https://eips.huatuo.xyz/zh/eip-7650/
lang: zh
tldr: 提议一个预取（prefetch）预编译，让合约以折扣价批量预热自身的存储槽和其他地址，从而使客户端可以并行加载它们。
tags: [gas, access-lists, precompile, storage, core]
---

# EIP-7650: Programmable access lists

> Add a precompiled contract that add access lists programmatically

**TL;DR:** 提议一个预取（prefetch）预编译，让合约以折扣价批量预热自身的存储槽和其他地址，从而使客户端可以并行加载它们。

## 它解决什么问题？

自 [EIP-2929](/eip-2929/) 起，交易中首次读取某个存储槽需要 2,100 gas（冷），首次访问某个地址需要 2,600 gas；之后的访问很便宜（热）。[EIP-2930](/eip-2930/) 允许*交易*预先声明访问列表，使这些项目以小幅折扣从热状态开始。

但访问列表必须由发送交易的人在执行之前构建，而许多合约其实已经知道自己将需要哪些槽。与此同时，客户端按顺序逐个支付冷读取的费用，尽管磁盘和 CPU 可以一次取回许多项目。

EIP-7650 让*合约自己*声明即将访问的内容，并按节点并行取回这些项目的方式为该声明定价。

## 它如何运作

一个新的预编译 `prefetch`，其地址仍标注为 `TBD`。其输入为：

```text
[32 bytes: n][n × 32-byte storage keys][32 bytes: m][m × 32-byte addresses]
```

- 存储键是**本地的**，即调用合约自己的槽。其他合约的键被有意排除，因为合约不应依赖另一个合约的存储布局。
- 每个尚未变热的键和地址都会被加入 `accessed_storage_keys` / `accessed_addresses`，并期望客户端并发加载它们。
- 该调用的费用为 `2100 × ceil(N / CONCURRENCY) + 2600 × ceil(M / CONCURRENCY)`，其中 `N` 和 `M` 只统计原本为冷的项目。`CONCURRENCY` 是协议常量，同样为 `TBD`。
- 预取之后，读取遵循常规的热访问成本（`WARM_STORAGE_READ_COST`）。
- 与 EIP-2930 一样，允许重复项。

## 示例代码

在 Solidity 中调用该预编译。由于规范尚未分配地址，这里的地址是占位符：

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

abstract contract Prefetching {
    address internal constant PREFETCH = address(0); // TBD in EIP-7650

    function _prefetch(bytes32[] memory keys, address[] memory addrs) internal {
        bytes memory input = abi.encodePacked(uint256(keys.length));
        for (uint256 i; i < keys.length; ++i) input = abi.encodePacked(input, keys[i]);
        input = abi.encodePacked(input, uint256(addrs.length));
        for (uint256 i; i < addrs.length; ++i) input = abi.encodePacked(input, uint256(uint160(addrs[i])));
        // Per the spec, calling it before activation should simply do nothing.
        (bool ok, ) = PREFETCH.call(input);
        ok;
    }
}
```

假设 `CONCURRENCY = 4`（仅作示意，真实值尚未设定）的成本对比：

```text
8 cold slots, 2 cold addresses
without prefetch: 8*2100 + 2*2600            = 22,000 gas
with prefetch:    2100*ceil(8/4) + 2600*ceil(2/4) = 4,200 + 2,600 = 6,800 gas (+ warm reads)
```

## 需要注意

- 状态为 **Stagnant**。预编译地址、分叉区块和 `CONCURRENCY` 的值从未确定，也没有被排入任何升级。
- 折扣的前提是节点确实并发取回；实际节省多少取决于那个常量。
- [EIP-7928](/eip-7928/) 提出了另一种区块级的访问列表方案。
- 规范提到未来可能的扩展：预取对外部合约的静态调用的结果。


---

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