EIP-3521 · Stagnant · Core · 2021-04-15
EIP-3521: Reduce access list cost
Proposed charging tx.to in an access list only as calldata instead of the full 2400-gas address cost, since it is warm anyway, making access lists worthwhile far sooner.
What problem does it solve?
EIP-2929 made the first access to an address or storage slot in a transaction "cold" and expensive, and later accesses "warm" and cheap. EIP-2930 added access lists: a transaction can declare up front which addresses and slots it will touch, paying a fixed price per entry so they start warm.
For storage in the contract being called (tx.to) this rarely pays off. To pre-warm its slots you must list the address, paying ACCESS_LIST_ADDRESS_COST (2400 gas), even though tx.to is already warm by default. According to the spec, a transaction had to read about 25 distinct slots in tx.to before an access list became cheaper than not using one.
EIP-3521 removes that double charge.
How it works
- The first occurrence of
tx.toin an access list is not chargedACCESS_LIST_ADDRESS_COST. Instead, its 20 bytes are charged like calldata (per EIP-2028: 16 gas per non-zero byte, 4 per zero byte). - Storage keys under that address are charged as before (
ACCESS_LIST_STORAGE_KEY_COST). - Any repeat of
tx.to, and every other address, is charged the normal address cost. - For contract-creation transactions (
tx.to == nil),tx.tomeans the address of the contract being created.
Calldata pricing was chosen as the floor: listing tx.to adds no work for clients, since it is already in the accessed-addresses set, so only the data itself should be paid for.
The spec says this cuts the break-even point from roughly 25 slots to about 5 unique reads.
Sample code
Access-list gas under EIP-3521, for the list part only (pseudocode, matching the spec's test cases):
ACCESS_LIST_ADDRESS_COST = 2400
ACCESS_LIST_STORAGE_KEY_COST = 1900
def calldata_cost(b: bytes) -> int:
return sum(16 if x else 4 for x in b)
def access_list_cost(access_list, tx_to: bytes) -> int:
cost, seen_to = 0, False
for address, keys in access_list:
if address == tx_to and not seen_to:
cost += calldata_cost(address) # e.g. 20 non-zero bytes -> 320
seen_to = True
else:
cost += ACCESS_LIST_ADDRESS_COST
cost += ACCESS_LIST_STORAGE_KEY_COST * len(keys)
return cost
to = bytes.fromhex("ff" * 20)
assert access_list_cost([(to, [])], to) == 320
assert access_list_cost([(to, []), (to, [])], to) == 2720
assert access_list_cost([(to, [b"\x00"]), (to, [b"\x00"])], to) == 6520
Things to know
- Status is Stagnant. It was not included in any upgrade; access lists are still priced as in EIP-2930.
- Under current rules you can check whether an access list helps a given transaction with
eth_createAccessListand comparing gas estimates with and without it. - The change only affects how much the access list itself costs; warm/cold access pricing during execution stays as EIP-2929 defines.