Here comes Decipher EVM Puzzles game for all Smart Contract Devs
Featured in Week In Ethereum News [ Start Playing ] 🤾🏻♂️
- Go to Decipher EVM Puzzles github repo
- Check the Installation and set-up steps
- Start Playing
It has been quite evident in the web3 developer space that solving puzzles, CTF challenges, games, etc are one of the most effective ways to grasp any specific topic firmly.
Be it some interactive beginner-level fun game like Cryptozombies or some serious web3 security-related CTF challenges like Ethernaut or Damn Vulnerable Defi, they all help us form strong mental models around particular complicated topics & actually learn by doing(instead of just reading).
I personally have been a big fan of these challenges and puzzles. I love them. ❤️
Before starting my EVM article series, I had an amazing time solving the EVM puzzles created by Franco. And learned a hell lot of stuff.
And therefore I decided to make an EVM puzzle game myself with some more interesting puzzles, i.e., Decipher EVM Puzzles.
The Decipher EVM Puzzles game is an extended version of Franco's EVM puzzles, but with additional complexity, a difficulty-level selector to help not just senior devs but also beginners to try it out, and more interesting puzzles covering a wide range of opcodes (& interesting ways to crack these puzzles).
Start Playing 🤾🏻♂️
- Go to Decipher EVM Puzzles github repo
- Check the Installation and set-up steps
- Start Playing
How to Play?
- Clone this repository
- Install Packages
- Run the following command
git clone https://github.com/zaryab2000/decipher_EVM_Puzzles.git
npm install
npx hardhat play
That's it.
Once done, you should be prompted to do this 👇
Then, simply select the difficulty level and start playing.
What is it & What's new?
Decipher EVM puzzles are basically a collection of puzzles that includes a bunch of different opcodes which can be executed successfully only if the player provides the correct inputs.
What are the inputs?
Every puzzle might require one of the following as input from the player:
- CallData only
- CallValue only
- Both CallData & CallValue
Your main goal as a player is to provide the right set of inputs so that the transaction doesn't get reverted.
If it reverts, you FAIL...❌
If it executes successfully, You SOLVED that puzzle. ✅
What's New?
- Select your difficulty level based on your expertise
Dealing with EVM opcodes can be a bit daunting. However, you need to start somewhere.
Therefore, these puzzles aren't just for senior smart contract developers but also for beginners who recently started exploring EVM and opcodes.
Just select your difficulty level based on your expertise with opcodes and start playing right away
- Hint for Complicated Puzzles
Some puzzles might be a bit complicated to solve. For the difficult ones, there is an option for players to get some Hints and try solving them again.
Don't cheat – Use the hints only when absolutely necessary. 😁
- Interesting Puzzles with Interesting Solutions (Must be Noted)
Solutions to some puzzles can be more of a formulae instead of one specific value.
For instance, some puzzles may require a type of input where Calldata size must be n and CallValue must be n+4, in order for you to solve it correctly.
For such cases, CallData Size can be 4 or 5, or 6 and CallValue can be 8 or 9, or 10 respectively
It's imperative to understand the formulae rather than chasing 1 specific calldata size or callvalue as the right answer, for such a puzzle
Solutions to the same puzzle can also be more than 1 specific input.
- More Opcodes, More Fun
Decipher EVM puzzle includes a lot more opcodes and attempts to make developers familiar with as many opcodes as possible.
While solving these puzzles you will come across a bunch of interesting opcodes as well as concepts like Bit shifting, masking, logical operations(AND, OR), SSTORE, SLOAD, MSTORE, Contract creation using CREATE Opcode, etc, and a lot more.
Tools that can help
While you can approach the game however you wish, I would like to recommend two tools that will undoubtedly make your life easier.
- Go to EVM Playground
- Click on the dropdown and select the Bytecode option.
- Paste the opcodes into the left section of the interface.
- You can use the boxes below to pass your input values of either calldata, callvalue, or both.
- At any given time while stepping through opcodes, the section below shall represent the state of Memory, Stack, Storage, or Return values. This will help you understand and solve the puzzles quickly.
2. ETHERVM's list of Opcodes
- Secondly, visit the Ethervm site to get a list of all opcodes.
- Using this, you can quickly check what a specific opcode means and most importantly how they take input from the stack.
These two tools are enough for you to understand and solve the puzzles quickly.
A quick note on Opcodes and Puzzles
Solving these puzzles basically means you will have constantly need to check, understand and experiment with different opcodes.
This is to understand how an opcode works which will essentially help you in achieving the right solutions for the puzzles.
While you eventually will have to deal with a lot of opcodes, there are 3 opcodes that you must understand very well, JUMP, JUMPI, and JUMPDEST.
Why these 3?
At the very core of it, every puzzle is basically a challange where you need to figure out how to make the execution flow JUMP from on specicic poistion to another postition that has the JUMPDEST opcode.
If you didn't understand that yet, don't worry. You will understand more when you start exploring these opcodes or by solving the puzzles.
Alternatively, you can also quickly get the gist of these 3 opcodes by clicking this toggle bar below 👇
Quick Note on JUMP, JUMPI & JUMPDEST 📝
If you are unaware of these 3 opcodes yet, it might be better to take quick notes on what they are and what they do.
As the name suggests these opcodes mainly help in jumping and moving the execution flow to a specific location.
- JUMPDEST: This opcode simply represents a valid location to jump to. This means, although JUMP and JUMPI opcodes can shift the execution flow to any location, the target location for both of them should always contain JUMPDEST. Otherwise, it won't be considered a valid jump, and execution shall revert.
- JUMP: This opcode simply takes the topmost value from the stack and moves the execution to that particular location.
- JUMPI: This is exactly similar to JUMP, however, this is more of a conditional jump. It only jumps when a condition is met.
What Conditions?
JUMPI only jumps:
a. If the 2nd Position of the Stack is a NON-ZERO value, then JUMP
b. If the 2nd Position of the STACK is ZERO value, then DO NOT JUMP
Wrapping it up
While this is the first version of the Decipher EVM puzzle game, I shall add more challenging and difficult puzzles in the next one.
Before starting the puzzle, it's better to get a good understanding of the Ethereum virtual machine as well as opcodes.
In case you are a complete beginner, you can start from this article series to understand the basics of EVM and Opcodes.