Bounty.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. pragma solidity ^0.4.0;
  2. import './PullPayment.sol';
  3. import './Killable.sol';
  4. /*
  5. * Bounty
  6. * This bounty will pay out to a researcher if he/she breaks invariant logic of
  7. * the contract you bet reward against.
  8. */
  9. contract Factory {
  10. function deployContract() returns (address);
  11. }
  12. contract Target {
  13. function checkInvariant() returns(bool);
  14. }
  15. contract Bounty is PullPayment, Killable {
  16. Target target;
  17. bool public claimed;
  18. address public factoryAddress;
  19. mapping(address => address) public researchers;
  20. event TargetCreated(address createdAddress);
  21. function() payable {
  22. if (claimed) throw;
  23. }
  24. modifier withAddress(address _address) {
  25. if(_address == 0) throw;
  26. _;
  27. }
  28. function Bounty(address _factoryAddress) withAddress(_factoryAddress){
  29. factoryAddress = _factoryAddress;
  30. }
  31. function createTarget() returns(Target) {
  32. target = Target(Factory(factoryAddress).deployContract());
  33. researchers[target] = msg.sender;
  34. TargetCreated(target);
  35. return target;
  36. }
  37. function checkInvariant() returns(bool){
  38. return target.checkInvariant();
  39. }
  40. function claim(Target target) {
  41. address researcher = researchers[target];
  42. if (researcher == 0) throw;
  43. // Check Target contract invariants
  44. if (target.checkInvariant()) {
  45. throw;
  46. }
  47. asyncSend(researcher, this.balance);
  48. claimed = true;
  49. }
  50. }