EIP-7650 · Stagnant · Core · 2024-03-10
EIP-7650: Programmable access lists
Proposed a prefetch precompile that lets a contract warm its own storage slots and other addresses in bulk at a discount, so clients can load them in parallel.
What problem does it solve?
Since EIP-2929, the first read of a storage slot in a transaction costs 2,100 gas (cold) and the first touch of an address costs 2,600 gas; later accesses are cheap (warm). EIP-2930 lets a transaction declare an access list up front so those items start warm at a small discount.
But an access list must be built by whoever sends the transaction, before execution, and many contracts already know which slots they will need. Meanwhile, clients pay cold reads one by one, in sequence, even though disks and CPUs can fetch many items at once.
EIP-7650 lets the contract itself declare what it is about to touch, and prices that declaration as if the node fetched the items in parallel.
How it works
A new precompile, prefetch, at an address still marked TBD. Its input is:
[32 bytes: n][n × 32-byte storage keys][32 bytes: m][m × 32-byte addresses]
- The storage keys are local, meaning slots of the calling contract. Keys of other contracts are deliberately excluded, since a contract should not depend on another contract's storage layout.
- Every key and address that is not already warm is added to
accessed_storage_keys/accessed_addresses, and the client is expected to load them concurrently. - The call costs
2100 × ceil(N / CONCURRENCY) + 2600 × ceil(M / CONCURRENCY), whereNandMcount only the items that were cold.CONCURRENCYis a protocol constant, alsoTBD. - After prefetching, reads follow the normal warm cost (
WARM_STORAGE_READ_COST). - Duplicates are allowed, as in EIP-2930.
Sample code
Calling the precompile from Solidity. The address is a placeholder because the spec has not assigned one:
// 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;
}
}
Cost comparison with an illustrative CONCURRENCY = 4 (the real value is not set):
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)
Things to know
- Status is Stagnant. The precompile address, fork block and
CONCURRENCYvalue were never set, and it is not scheduled for any upgrade. - The discount assumes nodes really do fetch concurrently; the actual savings depend on that constant.
- A different, block-level approach to access lists is proposed in EIP-7928.
- The spec mentions a possible future extension to prefetch the results of static calls to external contracts.