Dodging a bullet: Ethereum State Problems
Dodging a Bullet: The Ethereum State Problem and How We Fixed It
In the world of Ethereum, the state is a complex data structure that stores information about all accounts, their balances, and their storage. It's a critical component of the Ethereum network, and its health has a direct impact on the network's performance and security. However, until recently, the Ethereum state was vulnerable to a severe threat that could have brought the network to its knees.-households and businesses that rely on Ethereum for transactions and smart contracts.
The Problem: Trie Lookups and Gas Costs
The Ethereum state consists of a Patricia-merkle trie, a prefix-tree data structure that allows for efficient storage and retrieval of account information. However, as the state grows, the branches in this tree become more dense, making it increasingly difficult to perform lookups. Each lookup requires resolving multiple hashes, which can be time-consuming and gas-intensive.
To mitigate this issue, the Ethereum protocol has introduced various gas cost increases over the years. For example, in 2016, the Tangerine Whistle hardfork introduced EIP 150, which aggressively raised gas costs for certain operations. Similarly, the Istanbul upgrade in 2019 introduced EIP 1884, which increased gas costs for operations like SLOAD, BALANCE, and EXTCODEHASH.
The Exploit: Triggering Random Trie Lookups
In 2019, two Ethereum security researchers, Hubert Ritzdorf and Matthias Egli, discovered a vulnerability in the Ethereum protocol that allowed them to trigger random trie lookups. This exploit, which they submitted to the Ethereum bug bounty, could have been used to launch a denial-of-service (DoS) attack on the network.
The exploit worked by creating a simple contract that would perform a series of operations, including a jumpdest instruction, a gas instruction, an extcodesize instruction, and a pop instruction. This sequence of operations would trigger a trie lookup, which would resolve multiple hashes and consume a significant amount of gas.
The Impact: Slow Block Times and High Gas Costs
If an attacker were to deploy this exploit on the Ethereum network, it could lead to slow block times and high gas costs. The attacker could trigger a large number of trie lookups, which would consume a significant amount of gas and slow down the network. This could have a devastating impact on the network, causing widespread delays and disruptions.
The Solution: EIP-2929 and Dynamic State Snapshots
To address this vulnerability, the Ethereum community has implemented two key solutions: EIP-2929 and dynamic state snapshots.
EIP-2929, which was introduced in 2020, raises gas costs for operations that are not already accessed. This means that if an attacker were to trigger a trie lookup, the gas costs would be significantly higher, making it more expensive and less attractive to launch a DoS attack.
Dynamic state snapshots, which were introduced in 2020, provide a secondary data structure for storing the Ethereum state in a flat format. This allows for efficient storage and retrieval of account information, reducing the need for trie lookups and the associated gas costs.
The Benefits: Faster Block Times and Lower Gas Costs
The implementation of EIP-2929 and dynamic state snapshots has had a significant impact on the Ethereum network. Block times have decreased, and gas costs have decreased. The network is now more secure and more efficient, making it a better platform for users and developers.
Conclusion
The Ethereum state problem was a severe threat to the network, but the community has come together to address it. The implementation of EIP-2929 and dynamic state snapshots has made the network more secure and more efficient. As the network continues to evolve, it's essential to stay vigilant and address any new vulnerabilities that may arise. By working together, we can ensure that the Ethereum network remains a secure and reliable platform for users and developers.
Source: https://blog.ethereum.org/en/2021/05/18/eth-state-problems




