Reentrancy Attacks
A Reentrancy Attack is a common vulnerability in smart contracts that occurs when a malicious contract repeatedly calls a function (often the withdraw
function) in another contract before the initial execution is complete. This allows the attacker to drain funds from the vulnerable contract before it has a chance to update its state (like account balances).
Key Problem in the Vulnerable Code
The vulnerable function performs Interactions (sending Ether) before Effects (updating the contract’s state). Here’s an example:
How Reentrancy Attacks Work
Setup: The attacker deposits Ether into the vulnerable contract.
Withdrawal: The attacker calls the vulnerable contract’s
withdraw
function to withdraw their deposit.Reentrant Call: During the withdrawal, the vulnerable contract sends Ether to the attacker’s contract. The attacker’s contract triggers a reentrant call to the
withdraw
function before the vulnerable contract updates its balance.Repeat and Drain: The attacker repeats this process in a loop, withdrawing funds multiple times, until the vulnerable contract runs out of Ether.
Last updated