Reentrancy Attacks
Key Problem in the Vulnerable Code
solidity
function withdraw(uint256 _amount) public {
require(balances[msg.sender] >= _amount, "Insufficient balance");
// Sending Ether before updating the balance (vulnerable)
(bool success, ) = msg.sender.call{value: _amount}("");
require(success, "Transfer failed");
// Updating balance after sending Ether
balances[msg.sender] -= _amount;
}How Reentrancy Attacks Work
Last updated
