EVM Puzzle 1 - Warm Up!

EVM Puzzle 1 - Warm Up!

Introduction

EVM puzzles provide a hands-on way to grasp the nuances of how the Ethereum Virtual Machine operates. This series will explore these puzzles, offering in-depth analysis and solutions.

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
        

The goal is to craft a transaction that executes this contract successfully (without encountering a revert).

Understanding EVM Puzzles

Before diving in, let's outline a general approach to solving EVM puzzles:

  1. Disassembly: Convert the raw bytecode into a more readable opcode format using an EVM disassembler. See above output of a disassembler. For larger contracts this can be a huge list.
  2. Analysis: Meticulously examine the opcodes. Understand their functions and how they interact. Pay close attention to jumps, conditional logic, and data manipulations.
  3. Experimentation: Test hypotheses using an EVM debugger or a local Ethereum test environment. Send transactions with varying inputs and observe the results.

Key Concepts

Reminder of relevant EVM concepts:

  • Opcodes: The building blocks of EVM execution.
  • Stack: Temporary data structure for operations.
  • Memory: Short-term storage during execution.
  • Storage: Long-term data associated with the contract.

Solution

Let's analyze the bytecode: https://www.evm.codes/

  • 34 CALLVALUE: Pushes the amount of Ether sent with the transaction onto the stack.
  • 56 JUMP: Unconditionally jumps to the location marked by JUMPDEST (opcode 5B).
  • FD REVERT: Multiple revert instructions, halting execution and rolling back state changes.
  • 5B JUMPDEST: Marks a jump destination from top of the stack.
  • 00 STOP: Terminates contract execution.

The Catch: For successful execution, you must avoid the REVERT opcodes. The JUMP immediately sends execution to the JUMPDEST. The only way to reach the STOP opcode (and succeed) is to ensure the CALLVALUE is 8.

The Stack:

[8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]        

Successful Transaction: You must send the jump destination to jumpdest so enter the location 8 solves the puzzle.

Stay tuned for Puzzle #2 in the EVM Puzzle, where the challenges intensify!

Let me know if you'd like to add extra complexity or nuances to future puzzles!

More Tools

I found tons of tools for working with the EVM. I am just going to drop them here and figure out overtime which ones are most useful

https://github.com/fvictorio/evm-puzzles

https://www.ethervm.io/


要查看或添加评论,请登录

Shiran Sukumar的更多文章

  • How to Prioritize Engineering Initiatives within Product Roadmaps

    How to Prioritize Engineering Initiatives within Product Roadmaps

    In product development, not all tasks are created equal. Without a clear framework, it’s easy to waste time on…

  • Book Review: Inclusion on Purpose by Ruchika Tulshyan

    Book Review: Inclusion on Purpose by Ruchika Tulshyan

    Inclusion on Purpose by Ruchika Tulshyan stands out as a thought-provoking guide that emphasizes that it must be…

    1 条评论
  • How to Manage a Team That Misses Deadlines

    How to Manage a Team That Misses Deadlines

    Missing deadlines isn’t just about delays; it’s about trust—the cornerstone of every successful team. Without trust…

  • Dynamic.xyz - Building dApp authentication

    Dynamic.xyz - Building dApp authentication

    As a Web3 consultant, I've been able to work on exciting projects. While I cannot go into too much detail, I was…

    2 条评论
  • Viem vs ethers vs web3 frameworks

    Viem vs ethers vs web3 frameworks

    As blockchain technology advances, developers are constantly searching for better tools to streamline the process of…

  • Capture the Ether - Token Whale

    Capture the Ether - Token Whale

    Introduction The Token Whale challenge within the Capture the Ether series highlights the dire consequences of careless…

  • EVM Puzzle #5: Stack Manipulations and Conditional Logic

    EVM Puzzle #5: Stack Manipulations and Conditional Logic

    EVM puzzles continue to push the boundaries of our understanding of the Ethereum Virtual Machine. Puzzle #5 introduces…

  • EVM Puzzle #4: XOR and Code Manipulation

    EVM Puzzle #4: XOR and Code Manipulation

    The world of EVM puzzles invites us to understand the intricate workings of the Ethereum Virtual Machine. In Puzzle #4,…

  • EVM Puzzle 3 - CALLDATASIZE

    EVM Puzzle 3 - CALLDATASIZE

    Introduction In this installment of our EVM puzzle series, we'll examine a seemingly simple yet subtly challenging…

  • EVM Puzzle 2 - Codesize

    EVM Puzzle 2 - Codesize

    Introduction EVM puzzles push our understanding of Ethereum's low-level execution. This installment presents a…

社区洞察

其他会员也浏览了