EVM Puzzles

Challenge Overview

EVM Puzzles are a series of targeted challenges designed to help you understand how the Ethereum Virtual Machine works at a low level. Each puzzle consists of a small program of EVM bytecode that you need to analyze and solve, requiring you to deeply understand opcodes, the stack, memory, storage, and program flow within the EVM.

What You'll Learn

  • EVM bytecode fundamentals
  • Stack manipulation
  • Control flow with JUMP operations
  • Memory and storage operations
  • Gas optimizations

Prerequisites

  • Basic Solidity knowledge
  • Understanding of smart contracts
  • Familiarity with Stack data structure
  • Command line comfort

Tools Used

  • evm-puzzles repository
  • EVM disassembler
  • Ethereum Yellow Paper
  • Opcodes reference
  • Remix IDE for verification

Why Learn EVM Bytecode?

🔍

Deeper Understanding

Understanding EVM bytecode gives you insight into what your Solidity code actually does under the hood, making you a more effective and security-conscious smart contract developer.

Gas Optimization

Knowledge of EVM operations and their gas costs enables you to write more efficient contracts, reducing deployment and execution costs on the Ethereum network.

🔒

Security Expertise

Many smart contract vulnerabilities exist at the bytecode level. Learning to read and understand EVM code helps you identify and prevent potential security issues in your contracts.

🧠

Mental Challenge

EVM puzzles provide an engaging way to sharpen your problem-solving skills and develop a deeper appreciation for low-level programming concepts.

Example Puzzle

Here's a simple example of what an EVM puzzle looks like. Your goal is to analyze the bytecode and determine what input will allow the execution to complete successfully.

# Puzzle 1
# The goal is to make the execution reach the 'success' label.
# When the execution reaches 'success' it would return from the contract successfully.
# When the execution reaches any other part with the REVERT or INVALID opcode ('fail' label),
# it would 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: 0x345656FDFDFDFD5B00

Solution Hint:

This puzzle involves understanding the CALLVALUE (0x34) and JUMP (0x56) opcodes. The CALLVALUE pushes the amount of ETH sent with the transaction onto the stack. The JUMP instruction then uses that value as the destination to jump to. To reach the JUMPDEST (0x5B) at position 06, what value would you need to send?

Challenge Posts