Glossary
Reentrancy attack
A smart contract exploit in which an attacker calls back into a contract before it updates its records, withdrawing the same balance again and again.
On this page
A reentrancy attack is a bug in a smart contract that lets an attacker withdraw the same money more than once. The flawed contract sends funds first and updates the balance afterwards. If the recipient is itself a contract, it can use the moment of payment to call the withdraw function again, before the first call has finished. Each repeat call still sees the old, full balance.
The DAO, 2016
The best-known case hit The DAO, an investment fund run as contracts on Ethereum. Its token sale in April and May 2016 raised about 12 million ether. On June 17, 2016 an attacker used a recursive-call flaw of this kind to divert about 3.6 million ether, a third of the total. Ethereum's community reversed it with a hard fork on July 20, 2016 and returned the ether to the token holders, a step the chain has not repeated.
Defenses
- Update first, pay last. The contract cuts the balance to zero before sending anything.
- A lock. A guard refuses any new call into the function while one is still running.
- Audits. Reviewers look for this pattern, though an audit does not prove a contract is safe.
Reentrancy still appears in DeFi contracts today, often in subtler forms that cross several contracts.
