Skip to main content
Solidity Bug Hunt Hard +35 XP

Reentrancy Vulnerability

This withdraw function is vulnerable to reentrancy.

SolidityFind the bug
1function withdraw(uint amt) external {
2 require(balances[msg.sender] >= amt);
3 msg.sender.call{value: amt}("");
4 balances[msg.sender] -= amt;
5}
The bug is on line 3

Select the correct fix

Show answer and explanation

Answer: All of the above

Reentrancy: always update state before external calls. Use checks-effects-interactions pattern and ReentrancyGuard.

Hint: State should change before calling external contracts.

What this challenge tests

Bug Hunt in Solidity: security, reentrancy.

Related challenges