Created
January 1, 2019 21:41
-
-
Save craigmayhew/b59b9d0a400c196287bd60f3050c7c78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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