BreakInvariantBounty.sol 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 private claimed_;
  9. mapping(address => address) private 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 Determine if the bounty was claimed.
  19. * @return true if the bounty was claimed, false otherwise.
  20. */
  21. function claimed() public view returns(bool) {
  22. return claimed_;
  23. }
  24. /**
  25. * @dev Create and deploy the target contract (extension of Target contract), and sets the
  26. * msg.sender as a researcher
  27. * @return A target contract
  28. */
  29. function createTarget() public returns(Target) {
  30. Target target = Target(_deployContract());
  31. researchers[target] = msg.sender;
  32. emit TargetCreated(target);
  33. return target;
  34. }
  35. /**
  36. * @dev Transfers the contract funds to the researcher that proved the contract is broken.
  37. * @param _target contract
  38. */
  39. function claim(Target _target) public {
  40. address researcher = researchers[_target];
  41. require(researcher != address(0));
  42. // Check Target contract invariants
  43. require(!_target.checkInvariant());
  44. _asyncTransfer(researcher, address(this).balance);
  45. claimed_ = true;
  46. }
  47. /**
  48. * @dev Transfers the current balance to the owner and terminates the contract.
  49. */
  50. function destroy() public onlyOwner {
  51. selfdestruct(owner());
  52. }
  53. /**
  54. * @dev Internal function to deploy the target contract.
  55. * @return A target contract address
  56. */
  57. function _deployContract() internal returns(address);
  58. }
  59. /**
  60. * @title Target
  61. * @dev Your main contract should inherit from this class and implement the checkInvariant method.
  62. */
  63. contract Target {
  64. /**
  65. * @dev Checks all values a contract assumes to be true all the time. If this function returns
  66. * false, the contract is broken in some way and is in an inconsistent state.
  67. * In order to win the bounty, security researchers will try to cause this broken state.
  68. * @return True if all invariant values are correct, false otherwise.
  69. */
  70. function checkInvariant() public returns(bool);
  71. }