Skip to content
Verified contractPartialMIT

Puzzle

Address0x46ca2bf8188303887d6af76ddd316afa233b2ec9
Balance

0.000054 ETH

 

Transactions

118

 

Compiler

solc 0.6.12

 

Same code

Only this contract

 

Details

Compiler
solc 0.6.12+commit.27d51765
Language
solidity
Optimization
No
EVM version
istanbul
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
11,197,028
Creation transaction
0xcf23cfccbd…b4194bb95c

browser/tests/4_Ballot_test.sol

/**
 *Submitted for verification at Etherscan.io on 2020-11-05
*/

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;

interface ERC20 {
    function balanceOf(address account) external returns (uint256);

    function transfer(address recipient, uint256 amount) external returns (bool);
}

// Adventure Awaits: find all 4 clues, solve the puzzle and claim the reward
// #0xPoland #0xPolandHeist
contract Puzzle {
    uint256 constant BLOCKS_TO_WAIT = 10;

    bytes32 public hash;
    address public winner;
    mapping(address => bytes32) public commits;
    mapping(address => uint256) public commitBlock;

    constructor(bytes32 _hash) public payable {
        hash = _hash;
    }

    function commit(bytes32 _hash) public {
        commits[msg.sender] = _hash;
        commitBlock[msg.sender] = block.number;
    }

    function reveal(string memory _solution) public {
        bytes32 solutionHash = keccak256(abi.encodePacked(_solution));
        bytes32 solutionDoubleHash = keccak256(abi.encodePacked(solutionHash));
        bytes32 commitHash = keccak256(abi.encodePacked(msg.sender, solutionHash));
        require(winner == address(0), 'Already won');
        require(block.number > commitBlock[msg.sender] + BLOCKS_TO_WAIT, 'No front-running');
        require(solutionDoubleHash == hash, 'Invalid solution');
        require(commitHash == commits[msg.sender], 'Did not commit');
        winner = msg.sender;
    }

    function withdraw() public {
        require(msg.sender == winner, 'Not a winner');
        msg.sender.transfer(address(this).balance);
    }

    function withdrawToken(ERC20 token) public {
        require(msg.sender == winner, 'Not a winner');
        token.transfer(msg.sender, token.balanceOf(address(this)));
    }

    receive() external payable {}
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "istanbul",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.