Created
February 2, 2019 15:53
-
-
Save MatthewDLudwig/4be2a46655234bc2057814dca44c4eaf to your computer and use it in GitHub Desktop.
This file contains hidden or 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.4.99 <0.6.0; | |
library SafeMath { | |
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a * b; | |
assert(a == 0 || c / a == b); | |
return c; | |
} | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b != 0); | |
uint256 c = a / b; | |
return c; | |
} | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint256 a, uint256 b) internal pure returns (uint256) { | |
uint256 c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
contract HashedSecretLockedContract { | |
using SafeMath for uint256; | |
address owner; | |
bytes32 secret; | |
uint256 value; | |
constructor(bytes32 s) public { | |
owner = msg.sender; | |
secret = s; | |
value = 0; | |
} | |
function fill() public payable { | |
value = value.add(msg.value); | |
} | |
function retrieve(bytes32 guess) public payable { | |
require(keccak256(abi.encodePacked(guess)) == secret); | |
uint256 v = value; | |
value = 0; | |
msg.sender.transfer(v); | |
} | |
function hashForMe(bytes32 it) external pure returns (bytes32) { | |
return keccak256(abi.encodePacked(it)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment