FV-SOL-1-C1 Single Function
TLDR
Attacker calls a vulnerable function repeatedly within itself, exploiting incomplete state updates to drain funds
Game
Try to find what's wrong with the withdraw
function, how would you turn this code secure?
// SPDX-License-Identifier: MIT
// Open me in VSCode and really think before opening the hints!
// Add @audit tags wherever suspicious
// Go to the solidity docs to complete missing knowledge of what's happening here
// Solve by drafting a fix!
pragma solidity ^0.8.0;
contract ReentrancyGame {
mapping(address => uint256) public balances;
function deposit() public payable {
balances[msg.sender] += msg.value;
}
function withdraw() public {
require(balances[msg.sender] > 0, "Insufficient balance");
(bool success, ) = msg.sender.call{value: balances[msg.sender]}("");
require(success, "Transfer failed");
balances[msg.sender] = 0;
}
}
Last updated
Was this helpful?