WEB3
01
Reentrancy Attacks
CriticalWhat it is
A reentrancy attack occurs when an external contract call is made before the calling contract has updated its internal state. The called contract can recursively re-enter the caller, draining funds before any balance checks take effect. This remains the most well-known vulnerability in Solidity because it directly violates the mental model most developers have about sequential execution.
Real-world exploit
The 2016 DAO hack — the exploit that triggered Ethereum's hard fork — drained roughly $60 million by recursively calling a withdrawal function before balances were zeroed. More recently, Cream Finance lost $18.8 million in October 2021 via a reentrancy path in their AMP token integration. Both cases shared the same root cause: state mutations happening after external calls.
Mitigation
Apply the Checks-Effects-Interactions (CEI) pattern rigorously: validate inputs, update state, then make external calls — in that order. Use OpenZeppelin's ReentrancyGuard modifier on any function that transfers value or interacts with arbitrary external addresses.