Created
April 20, 2023 14:55
-
-
Save pcaversaccio/1e9916aab15a881fc85ac9a4176fc018 to your computer and use it in GitHub Desktop.
A simple Solidity contract that entails a reentrancy attack vector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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