Skip to content

Instantly share code, notes, and snippets.

@cassc
Created April 29, 2024 05:42
Show Gist options
  • Save cassc/19882c3be886293d65be1113dd0a10c8 to your computer and use it in GitHub Desktop.
Save cassc/19882c3be886293d65be1113dd0a10c8 to your computer and use it in GitHub Desktop.
reentrancy bug test
// 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