EVM Puzzle 1

I recently discovered that the EVM Puzzle series is an excellent set of challenges to test our understanding of EVM opcodes. The puzzles can be found at this link: https://github.com/fvictorio/evm-puzzles. In this blog post, we will focus on solving the first puzzle.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
############
# Puzzle 1 #
############

00 34 CALLVALUE
01 56 JUMP
02 FD REVERT
03 FD REVERT
04 FD REVERT
05 FD REVERT
06 FD REVERT
07 FD REVERT
08 5B JUMPDEST
09 00 STOP

According to the requirements of the puzzle, we need to jump to the target program counter (PC), which is located at address 08, the JUMPDEST opcode.

Here is the explanation of CALLVALUE

Stack output
  1. value: the value of the current call in wei.

And here is the explanation of JUMP

The program counter (PC) is a byte offset in the deployed code. It indicates which instruction will be executed next. When an ADD is executed, for example, the PC is incremented by 1, since the instruction is 1 byte. The PUSH instructions are bigger than one byte, and so will increment the counter accordingly.

The JUMP instruction alters the program counter, thus breaking the linear path of the execution to another point in the deployed code. It is used to implement functionalities like functions.

Stack input
  1. counter: byte offset in the deployed code where execution will continue from. Must be a JUMPDEST instruction.

Therefore, the target value that JUMP jumps to is our input, and the target address is 08. We simply input 8.

1
2
3
4
Puzzle solved!

Run it in evm.codes: https://www.evm.codes/playground?callValue=8&unit=Wei&callData=&codeType=Bytecode&code='3456FDFDFDFDFDFD5B00'_