Skip to content

Latest commit

 

History

History
35 lines (21 loc) · 1.31 KB

Puzzle5.md

File metadata and controls

35 lines (21 loc) · 1.31 KB

Analysis

Let's break down the bytecode and understand the flow of execution to find the answer:

  1. CALLVALUE (34): This opcode gets the value sent with the transaction and pushes it onto the stack.

  2. DUP1 (80): Duplicates the top value of the stack.

  3. MUL (02): Multiplies the top two values on the stack and pushes the result back onto the stack.

  4. PUSH2 0100: Pushes the value 0100 (256 in decimal) onto the stack.

  5. EQ (14): Compares the top two values on the stack for equality. If equals, it pushes 1 (true) onto the stack; otherwise, it pushes 0 (false).

  6. PUSH1 0C: Pushes the value 0C (12 in decimal) onto the stack.

  7. JUMPI (57): If the top value of the stack is true (1), it alters the program counter to the value beneath it (in this case, 0C), performing a conditional jump to the JUMPDEST at byte 0C.

  8. JUMPDEST (5B): Marks a valid destination for jumps.

  9. STOP (00): Halts execution.

Execution

For the JUMPI at byte 09 to jump to the JUMPDEST at byte 0C, the result of the EQ operation must be true.

  • CALLVALUE: Let's call the value to send as X

  • DUP1: Stack now has two X

  • MUL: X * X

  • PUSH2 0100: 0100 is pushed to stack, or 256 (in decimal)

  • EQ: (because next set of op-code is JUMPI )

      X * X = 256 
      (X)^2 = 256 
      X = 16