Skip to content

Instantly share code, notes, and snippets.

@noeleon930
Created October 22, 2016 05:55
Show Gist options
  • Select an option

  • Save noeleon930/21d2b64749450ba3fcb91f0b8dc62dc7 to your computer and use it in GitHub Desktop.

Select an option

Save noeleon930/21d2b64749450ba3fcb91f0b8dc62dc7 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.0;
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
contract Fund {
/// Mapping of ether shares of the contract.
mapping(address => uint) shares;
/// Withdraw your share.
function withdraw() {
if (msg.sender.send(shares[msg.sender]))
shares[msg.sender] = 0;
}
}
contract Fund2 {
/// Mapping of ether shares of the contract.
mapping(address => uint) shares;
/// Withdraw your share.
function withdraw() {
var share = shares[msg.sender];
shares[msg.sender] = 0;
if (!msg.sender.send(share))
throw;
}
}
@noeleon930
Copy link
Copy Markdown
Author

contract Attacker {
    function() {
        // 使執行一直被卡在第9行,造成遞迴
        msg.sender.call("withdraw");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment