Bounty.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. function Bounty(address _factoryAddress){
  25. factoryAddress = _factoryAddress;
  26. }
  27. function createTarget() returns(Target) {
  28. target = Target(Factory(factoryAddress).deployContract());
  29. researchers[target] = msg.sender;
  30. TargetCreated(target);
  31. return target;
  32. }
  33. function checkInvariant() returns(bool){
  34. return target.checkInvariant();
  35. }
  36. function claim(Target target) {
  37. address researcher = researchers[target];
  38. if (researcher == 0) throw;
  39. // Check Target contract invariants
  40. if (target.checkInvariant()) {
  41. throw;
  42. }
  43. asyncSend(researcher, this.balance);
  44. claimed = true;
  45. }
  46. }