solidity/test/compilationTests/zeppelin/Bounty.sol

79 lines
2.1 KiB
Solidity
Raw Normal View History

2017-07-05 10:28:15 +00:00
pragma solidity ^0.4.11;
import './payment/PullPayment.sol';
import './lifecycle/Destructible.sol';
/**
* @title Bounty
* @dev This bounty will pay out to a researcher if they break invariant logic of the contract.
*/
contract Bounty is PullPayment, Destructible {
bool public claimed;
mapping(address => address) public researchers;
event TargetCreated(address createdAddress);
/**
* @dev Fallback function allowing the contract to receive funds, if they haven't already been claimed.
2017-07-05 10:28:15 +00:00
*/
function() external payable {
2017-07-05 10:28:15 +00:00
if (claimed) {
revert();
2017-07-05 10:28:15 +00:00
}
}
/**
* @dev Create and deploy the target contract (extension of Target contract), and sets the
2017-07-05 10:28:15 +00:00
* msg.sender as a researcher
* @return A target contract
*/
2018-07-04 17:20:51 +00:00
function createTarget() public returns(Target) {
2017-07-05 10:28:15 +00:00
Target target = Target(deployContract());
researchers[address(target)] = msg.sender;
emit TargetCreated(address(target));
2017-07-05 10:28:15 +00:00
return target;
}
/**
* @dev Internal function to deploy the target contract.
* @return A target contract address
*/
function deployContract() internal returns(address);
/**
* @dev Sends the contract funds to the researcher that proved the contract is broken.
* @param target contract
*/
2018-07-04 17:20:51 +00:00
function claim(Target target) public {
address researcher = researchers[address(target)];
if (researcher == address(0)) {
revert();
2017-07-05 10:28:15 +00:00
}
// Check Target contract invariants
if (target.checkInvariant()) {
revert();
2017-07-05 10:28:15 +00:00
}
2018-07-05 12:32:32 +00:00
asyncSend(researcher, address(this).balance);
2017-07-05 10:28:15 +00:00
claimed = true;
}
}
/**
* @title Target
* @dev Your main contract should inherit from this class and implement the checkInvariant method.
*/
contract Target {
/**
* @dev Checks all values a contract assumes to be true all the time. If this function returns
* false, the contract is broken in some way and is in an inconsistent state.
* In order to win the bounty, security researchers will try to cause this broken state.
* @return True if all invariant values are correct, false otherwise.
2017-07-05 10:28:15 +00:00
*/
2018-07-04 17:20:51 +00:00
function checkInvariant() public returns(bool);
2017-07-05 10:28:15 +00:00
}