Skip to content

Instantly share code, notes, and snippets.

@craigmayhew
Created January 1, 2019 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigmayhew/b59b9d0a400c196287bd60f3050c7c78 to your computer and use it in GitHub Desktop.
Save craigmayhew/b59b9d0a400c196287bd60f3050c7c78 to your computer and use it in GitHub Desktop.
pragma solidity ^0.5;
contract owned {
constructor() public { owner = msg.sender; }
address payable owner;
modifier onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
_;
}
}
contract ethForAnswersBounty is owned {
int256 winningAnswer;
constructor(int256 _winningAnswer) public payable {
winningAnswer = _winningAnswer;
}
function () external payable { }
function attempt(int256 a, int256 b, int256 c) public returns (bool) {
int256 result = safeFormula(a, b, c);
if (winningAnswer == result) {
payout();
}
return false;
}
function withdrawEther() public onlyOwner {
selfdestruct(owner);
}
function safeFormula(int256 a, int256 b, int256 c) internal pure returns (int256) {
assert(a < 7237005577332262213973186563042994240829374041602535252466099000494570602495);
assert(b < 7237005577332262213973186563042994240829374041602535252466099000494570602495);
assert(c < 7237005577332262213973186563042994240829374041602535252466099000494570602495);
assert(a > -7237005577332262213973186563042994240829374041602535252466099000494570602495);
assert(b > -7237005577332262213973186563042994240829374041602535252466099000494570602495);
assert(c > -7237005577332262213973186563042994240829374041602535252466099000494570602495);
return (a*a*a) + (b*b*b) + (c*c*c);
}
function payout() internal {
msg.sender.transfer(address(this).balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment