BreakInvariantBounty.sol 2.2 KB

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