Bounty.sol 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. pragma solidity ^0.4.23;
  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 receive funds, if they haven't already been claimed.
  14. */
  15. function() external payable {
  16. require(!claimed);
  17. }
  18. /**
  19. * @dev Create and deploy the target contract (extension of Target contract), and sets the
  20. * msg.sender as a researcher
  21. * @return A target contract
  22. */
  23. function createTarget() public returns(Target) {
  24. Target target = Target(deployContract());
  25. researchers[target] = msg.sender;
  26. emit TargetCreated(target);
  27. return target;
  28. }
  29. /**
  30. * @dev Sends the contract funds to the researcher that proved the contract is broken.
  31. * @param target contract
  32. */
  33. function claim(Target target) public {
  34. address researcher = researchers[target];
  35. require(researcher != 0);
  36. // Check Target contract invariants
  37. require(!target.checkInvariant());
  38. asyncSend(researcher, address(this).balance);
  39. claimed = true;
  40. }
  41. /**
  42. * @dev Internal function to deploy the target contract.
  43. * @return A target contract address
  44. */
  45. function deployContract() internal returns(address);
  46. }
  47. /**
  48. * @title Target
  49. * @dev Your main contract should inherit from this class and implement the checkInvariant method.
  50. */
  51. contract Target {
  52. /**
  53. * @dev Checks all values a contract assumes to be true all the time. If this function returns
  54. * false, the contract is broken in some way and is in an inconsistent state.
  55. * In order to win the bounty, security researchers will try to cause this broken state.
  56. * @return True if all invariant values are correct, false otherwise.
  57. */
  58. function checkInvariant() public returns(bool);
  59. }