Getting Started with EVM Puzzles
Introduction
Welcome to the EVM Puzzles challenge series! In this first post, we're going to look at a puzzle breakdown and learn how to set up our environment. This will allow us to access and solve the EVM puzzles.
Prerequisites
Before we begin, make sure you have the following installed:
- Node.js (v14 or later)
- Git
- A code editor (VS Code recommended)
- Basic understanding of Ethereum and smart contracts
Setting Up the Environment
Option 1:
Clone the repository: https://github.com/fvictorio/evm-puzzles
Run npm install to install dependencies.
Then your terminal run npx hardhat play.
This will allow you to access and solve the puzzles from your terminal.
Option 2:
Use the EVM Playground to run and test each puzzle.
When you open the playground, change the settings from 'YUL' to 'Bytecode' (as I've illustrated in the image below).
I have listed the bytecode to each puzzle right above it. You will copy and paste this bytecode right into the playground. (You may need to delete what's there first.)

Once you've added the bytecode, click Run and it will load your puzzle.
Understanding EVM Basics
The Ethereum Virtual Machine (EVM) is a stack-based machine that executes bytecode. Here are some key concepts we'll need to understand:
Key EVM Concepts
- Stack: A last-in-first-out (LIFO) data structure used for operations
- Memory: A volatile byte array used for temporary storage
- Storage: A persistent key-value store
- Program Counter: Points to the current instruction being executed
Common EVM Opcodes
Here are some essential opcodes we'll encounter in the puzzles:
| Opcode | Hex | Description |
|---|---|---|
| PUSH1 | 0x60 | Push 1 byte onto stack |
| POP | 0x50 | Remove top item from stack |
| ADD | 0x01 | Add top two stack items |
| MUL | 0x02 | Multiply top two stack items |
| JUMP | 0x56 | Jump to position |
| JUMPI | 0x57 | Conditional jump |
Running Your First Puzzle
Let's look at a simple example to understand how the puzzles work. Here's Puzzle 1:
# Puzzle 1
# The goal is to make the execution reach the 'JUMPDEST' located at position 06.
# When the execution reaches 'JUMPDEST' it will return from the contract successfully.
# When the execution reaches any other part with the REVERT or INVALID opcode ('fail' label),
# it will revert with an error.
00 34 CALLVALUE
01 56 JUMP
02 FD REVERT
03 FD REVERT
04 FD REVERT
05 FD REVERT
06 5B JUMPDEST
07 00 STOP
# Bytecode: 0x345656FDFDFDFD5B00Understanding the Puzzle
Let's break down what this puzzle is doing:
CALLVALUEpushes the amount of ETH sent with the transaction onto the stackJUMPuses that value as the destination to jump to- If we jump to position 6 (the JUMPDEST), we succeed
- If we jump anywhere else, we hit a REVERT and fail
Solution Hint:
To solve this puzzle, we need to send exactly 6 wei with the transaction. This will make the JUMP instruction jump to position 6, where the JUMPDEST is located.
Tools and Resources
Here are some helpful tools for solving EVM puzzles:
- Etherscan Opcode Tool- Interactive opcode reference
- EVM.codes- Comprehensive EVM reference
- EVM Puzzles Repository- Source code and test files
Next Steps
Now that you have your environment set up and understand the basics, you're ready to tackle the EVM puzzles! In the next post, we'll dive into Puzzles 1 and 2, which focus on stack operations and basic program flow.