Bounty.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. pragma solidity ^0.4.8;
  2. import './payment/PullPayment.sol';
  3. import './lifecycle/Destructible.sol';
  4. /**
  5. * @title Bounty
  6. * @dev This bounty will pay out to a researcher if they break invariant logic of the contract.
  7. */
  8. contract Bounty is PullPayment, Destructible {
  9. bool public claimed;
  10. mapping(address => address) public researchers;
  11. event TargetCreated(address createdAddress);
  12. /**
  13. * @dev Fallback function allowing the contract to recieve funds, if they haven't already been claimed.
  14. */
  15. function() payable {
  16. if (claimed) {
  17. throw;
  18. }
  19. }
  20. /**
  21. * @dev Create and deploy the target contract (extension of Target contract), and sets the
  22. * msg.sender as a researcher
  23. * @return A target contract
  24. */
  25. function createTarget() returns(Target) {
  26. Target target = Target(deployContract());
  27. researchers[target] = msg.sender;
  28. TargetCreated(target);
  29. return target;
  30. }
  31. /**
  32. * @dev Internal function to deploy the target contract.
  33. * @return A target contract address
  34. */
  35. function deployContract() internal returns(address);
  36. /**
  37. * @dev Sends the contract funds to the researcher that proved the contract is broken.
  38. * @param Target contract
  39. */
  40. function claim(Target target) {
  41. address researcher = researchers[target];
  42. if (researcher == 0) {
  43. throw;
  44. }
  45. // Check Target contract invariants
  46. if (target.checkInvariant()) {
  47. throw;
  48. }
  49. asyncSend(researcher, this.balance);
  50. claimed = true;
  51. }
  52. }
  53. /**
  54. * @title Target
  55. * @dev Your main contract should inherit from this class and implement the checkInvariant method.
  56. */
  57. contract Target {
  58. /**
  59. * @dev Checks all values a contract assumes to be true all the time. If this function returns
  60. * false, the contract is broken in some way and is in an inconsistent state.
  61. * In order to win the bounty, security researchers will try to cause this broken state.
  62. * @return True if all invariant values are correct, false otherwise.
  63. */
  64. function checkInvariant() returns(bool);
  65. }