What Is Reentrancy Attack?
Also known as: Reentrancy Attack, Reentrancy, Reentrancy Exploit
In short
A reentrancy attack is a type of vulnerability in which, at the moment a smart contract makes a call to an external address, the attacker's contract calls the same function repeatedly before the first execution finishes, draining the funds.
The attack exploits the contract performing steps in the wrong order. For example, if a withdrawal function first sends ETH to the user and then zeroes out their balance, the attacker's contract calls the withdrawal function again with code triggered the moment it receives the ETH. Because the balance has not yet been zeroed, the contract makes the payment again, and the loop continues until the funds run out or the gas is exhausted.
The most famous example of this vulnerability is the 2016 attack on The DAO. The attacker used this bug in the contract of The DAO, a decentralized investment fund, to move a large amount of ETH into a child contract under their control. After the incident, the Ethereum community carried out a hard fork to recover the funds; the chain that did not accept the change continued as Ethereum Classic.
To protect against it, the 'checks-effects-interactions' pattern is used: conditions are checked first, then state changes such as balance updates are made, and the external call is left to the very end. Locking mechanisms such as OpenZeppelin's ReentrancyGuard also prevent re-entering the same function. Because reentrancy can also occur across different functions or contracts, it is examined as a priority in security audits.
Last updated: · This content is for information purposes only and is not investment advice.

