Created
April 29, 2024 05:42
-
-
Save cassc/19882c3be886293d65be1113dd0a10c8 to your computer and use it in GitHub Desktop.
reentrancy bug test
This file contains 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: MIT | |
pragma solidity >0.8.0; | |
contract MyTestContract { | |
mapping(address => uint) public balances; | |
address public owner ; | |
constructor() payable { | |
owner = msg.sender; | |
balances[msg.sender] = msg.value; | |
} | |
function deposit() public payable { | |
balances[msg.sender] += msg.value; | |
} | |
function withdraw() public { | |
assert (balances[msg.sender] > 0); | |
payable(msg.sender).call{value: (balances[msg.sender])}(""); | |
balances[msg.sender] = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment