Technical definition
A reentrancy attack occurs when a malicious contract calls back into a victim contract before the victim’s state changes are finalized. This exploits the victim’s assumption that external calls complete atomically. For example, if a victim contract checks a user’s balance, then sends funds to an attacker-controlled address, the attacker’s contract can recursively call the victim’s withdrawal function before the balance is updated. The attack relies on the victim’s failure to follow the Checks-Effects-Interactions pattern, where state changes occur before external calls.
An analogy
Imagine a vending machine that checks your wallet balance, then dispenses a snack, but before updating its inventory, an attacker repeatedly inserts coins while the machine is still processing the first transaction. The machine keeps dispensing snacks without realizing the balance was already spent.
Why it matters
Reentrancy attacks can lead to catastrophic financial losses, as seen in the DAO hack of 2016, where $60 million was drained. They highlight the importance of secure smart contract design and rigorous testing.
Where it came from
The concept gained prominence after the 2016 DAO hack, which exploited a reentrancy vulnerability in Ethereum’s smart contracts. However, similar attacks predate Ethereum, appearing in other systems where state and external calls are not properly synchronized.
Example in practice
In 2016, the DAO (Decentralized Autonomous Organization) was hacked via a reentrancy attack. The attacker exploited a flaw in the DAO’s smart contract, which allowed them to repeatedly withdraw funds before the contract updated its balance, resulting in the theft of approximately 3.6 million ETH.
Common misconceptions
- Reentrancy attacks only affect Ethereum → Correction: They can affect any blockchain with smart contracts that handle external calls before state updates, including Ethereum, Binance Smart Chain, and others.
- Reentrancy attacks are rare → Correction: While less common today due to improved practices, they still occur, as seen in the 2022 Mango Markets exploit on Solana.
Risks & limitations
- Financial loss due to drained funds
- Irreversible state corruption in smart contracts
- Loss of user trust in blockchain applications
- Legal and regulatory repercussions for project teams
- Exploitation leading to protocol failures or insolvency