Created
November 16, 2023 23:36
-
-
Save ptrcarta/6796652bf7d66025b22c7a0470fc71b5 to your computer and use it in GitHub Desktop.
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
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