Skip to content

Instantly share code, notes, and snippets.

@ptrcarta
Created November 16, 2023 23:36
Show Gist options
  • Save ptrcarta/6796652bf7d66025b22c7a0470fc71b5 to your computer and use it in GitHub Desktop.
Save ptrcarta/6796652bf7d66025b22c7a0470fc71b5 to your computer and use it in GitHub Desktop.
pragma solidity 0.8.21;
//vulnerable contract, do not use
contract EtherStore {
mapping(address => uint256) public balances;
constructor() payable {
require(msg.value == 1 ether);
}
function deposit() public payable {
balances[msg.sender] += msg.value;
}
function withdraw() public {
uint256 bal = balances[msg.sender];
require(bal > 0, "no balance");
(bool sent, ) = payable(msg.sender).call{value: bal}("");
require(sent, "failed to send ether");
balances[msg.sender] = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment