Ethernaut Puzzle 03 Coin Flip
This puzzle is also very classic and almost appears on every solidity practice website.
It asks us to generate the correct value (_guess
in the code, true or false) and pass it as a parameter. After you guess correctly for at least 10 times, you can pass the problem.
When we take a look at this problem, we can see the source of this value is from block.number
. From the official solidity document, we can see block.number
is the current block number.
Thus we can build our own attack smart contract and run it for 10 times. Between each time we run, we should keep some time gap so that the block number for each time is different. Otherwise, the transactions will be reverted.
1 | pragma solidity ^0.7.3; |