all files / contracts/test/ TestReEntryAttack.sol

66.67% Statements 4/6
0% Branches 0/2
83.33% Functions 5/6
70% Lines 7/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                 
import "../ROSCATest.sol";
 
pragma solidity ^0.4.4;
 
/**
 * A test attack contract that tries to do a re-entry attack on a ROSCA contract.
 * Essentially it's just a proxy for different operations on the ROSCA contract, but
 * its fallback function tries to call withdraw() to invoke this attack.
 *
 * It emits an event saying whether the call to ROSCA.withdraw() was succesful (hence the attack
 * succeeded).
 */
contract TestReEntryAttack {
  event LogWithdraw(bool success);
 
  ROSCATest rosca;
  bool reEnter = false;
 
  function setRoscaAddress(address ROSCAContract_) {
      rosca = ROSCATest(ROSCAContract_);
  }
 
  function() {
    if (reEnter) {
        rosca.withdraw();
        reEnter = false;
    }
  }
 
  function withdrawTwice() {
      reEnter = true;
      bool result = rosca.withdraw();
      LogWithdraw(result);
  }
 
  function contribute() payable {
      rosca.contribute.value(msg.value)();
  }
 
  function bid(uint256 bid) {
      rosca.bid(bid);
  }
 
  function startRound() {
      rosca.startRound();
  }
}