Created
September 14, 2020 21:19
-
-
Save hackingbeauty/571b4c50658347717b25db91085482fc to your computer and use it in GitHub Desktop.
Reentrance.sol (www.SmartContractSecurity.com)
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
pragma solidity ^0.6.10; | |
import "https://github.com/OpenZeppelin/zeppelin-solidity/contracts/math/SafeMath.sol"; | |
contract Reentrance { | |
using SafeMath for uint256; | |
mapping(address => uint) public balances; | |
function donate(address _to) public payable { | |
balances[_to] = balances[_to].add(msg.value); | |
} | |
function balanceOf(address _who) public view returns (uint balance) { | |
return balances[_who]; | |
} | |
function withdraw(uint _amount) public { | |
if(balances[msg.sender] >= _amount) { | |
(bool result, bytes memory data) = msg.sender.call.value(_amount)(""); | |
if(result) { | |
_amount; | |
} | |
balances[msg.sender] -= _amount; | |
} | |
} | |
fallback() external payable {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment