Skip to content

Instantly share code, notes, and snippets.

@DerayGa
Forked from noeleon930/re-entrancy
Created December 7, 2016 11:43
Show Gist options
  • Select an option

  • Save DerayGa/28e6658689243f2797f5f291fd1e1411 to your computer and use it in GitHub Desktop.

Select an option

Save DerayGa/28e6658689243f2797f5f291fd1e1411 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment