SimpleTokenBounty.sol 1.3 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 if you can cause a SimpleToken's balance
  7. * to be lower than its totalSupply, which would mean that it doesn't
  8. * have sufficient ether for everyone to withdraw.
  9. */
  10. contract Factory {
  11. function deployContract() returns (address);
  12. }
  13. contract Target {
  14. function checkInvariant() returns(bool);
  15. }
  16. contract SimpleTokenBounty is PullPayment, Killable {
  17. Target target;
  18. bool public claimed;
  19. address public factoryAddress;
  20. mapping(address => address) public researchers;
  21. event TargetCreated(address createdAddress);
  22. function() payable {
  23. if (claimed) throw;
  24. }
  25. function SimpleTokenBounty(address _factoryAddress){
  26. factoryAddress = _factoryAddress;
  27. }
  28. function createTarget() returns(Target) {
  29. target = Target(Factory(factoryAddress).deployContract());
  30. researchers[target] = msg.sender;
  31. TargetCreated(target);
  32. return target;
  33. }
  34. function checkInvariant() returns(bool){
  35. return target.checkInvariant();
  36. }
  37. function claim(Target target) {
  38. address researcher = researchers[target];
  39. if (researcher == 0) throw;
  40. // Check Target contract invariants
  41. if (target.checkInvariant()) {
  42. throw;
  43. }
  44. asyncSend(researcher, this.balance);
  45. claimed = true;
  46. }
  47. }