The Berlin hard fork, implemented on April 14, introduced four EIPs. Two of them—EIP-2929 and EIP-2930—impact gas costs for transactions. This article explains how certain gas costs were calculated before Berlin, how EIP-2929 changes them, and how to use access lists introduced by EIP-2930.
Key Takeaways
- Gas cost adjustments: Berlin modifies gas costs for some opcodes. Hardcoded gas fees in dApps or contracts may fail unless updated.
- Access lists: Introduced by EIP-2930, these can reduce gas costs slightly but may increase total consumption in some scenarios.
- New RPC method:
gethaddedeth_createAccessListto simplify access list creation.
Pre-Berlin Gas Costs
SLOAD Before Berlin
- Fixed cost: 800 gas.
SSTORE Before Berlin
- 0 → Non-zero: 20,000 gas.
- Non-zero → Non-zero: 5,000 gas.
- Non-zero → 0: 5,000 gas (+ refund).
- Modified in same transaction: 800 gas.
Post-EIP-2929 Gas Costs
Accessed Addresses and Storage Keys
- Addresses or storage keys used earlier in a transaction are marked as accessed.
- Storage keys are tied to addresses as tuples
(address, storageKey).
Updated Gas Costs
| Opcode | Pre-Berlin | Post-Berlin (Not Accessed) | Post-Berlin (Accessed) |
|---|---|---|---|
SLOAD | 800 | 2,100 | 100 |
SSTORE (0→1) | 20,000 | 22,100 | 20,000 |
SSTORE (1→2) | 5,000 | 5,000 | 2,900 |
CALL | 700 | 2,600 | 100 |
EIP-2930: Access List Transactions
How Access Lists Work
- Declare addresses/storage keys as accessed upfront.
- Example: Adding a storage key to
accessListreducesSLOADfrom 2,100 to 100 gas but costs 1,900 gas per key. - Addresses cost 2,400 gas to add but save 2,500 gas per first use.
Optimizing with eth_createAccessList
Use
eth_createAccessList(similar toeth_estimateGas) to generate lists:{ "accessList": [{ "address": "0x...", "storageKeys": ["0x00..."] }], "gasUsed": "0x8496" }- Compare gas savings before including lists.
FAQs
1. Will access lists always reduce gas costs?
No. Overhead for adding addresses/keys may offset savings.
2. How does Berlin affect existing contracts?
Contracts relying on hardcoded gas values may break. Access lists can mitigate this.
3. Is the called contract’s address automatically accessed?
Yes. tx.to is added to accessed_addresses by default.
4. What’s the main purpose of access lists?
To prevent contract breaks due to EIP-2929’s higher gas costs.
Conclusion
- Berlin’s changes make gas costs dynamic based on access state.
- Access lists offer minor savings but require careful optimization.
- Tools like
eth_createAccessListsimplify list generation.