Skip to content

Instantly share code, notes, and snippets.

@pcaversaccio
Created April 20, 2023 14:55
Show Gist options
  • Save pcaversaccio/1e9916aab15a881fc85ac9a4176fc018 to your computer and use it in GitHub Desktop.
Save pcaversaccio/1e9916aab15a881fc85ac9a4176fc018 to your computer and use it in GitHub Desktop.
A simple Solidity contract that entails a reentrancy attack vector.
// SPDX-License-Identifier: WTFPL
pragma solidity 0.8.19;
contract Victim {
mapping(address => uint256) public balanceOf;
function deposit() external payable {
balanceOf[msg.sender] += msg.value;
}
function withdraw() external {
uint256 depositedAmount = balanceOf[msg.sender];
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = payable(msg.sender).call{value: depositedAmount}("");
require(success, "Reverted");
balanceOf[msg.sender] = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment