Skip to content

Latest commit

 

History

History
31 lines (19 loc) · 1.69 KB

Puzzle2.md

File metadata and controls

31 lines (19 loc) · 1.69 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. CODESIZE (38): This opcode pushes the size of the code (in bytes) onto the stack.

  3. SUB (03): This opcode pops two values from the stack, subtracts the second one from the first, and pushes the result back onto the stack.

  4. JUMP (56): This opcode alters the program counter to the location specified by the top stack item. It jumps to the location if it's a valid JUMPDEST.

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

  6. STOP (00): Halts execution.

Execution

  • At byte 00, CALLVALUE pushes a value (let's call it V) onto the stack.
  • At byte 01, CODESIZE pushes the size of the code onto the stack. Since the code is 10 bytes long, the value 10 (in hexadecimal, '0A') is pushed onto the stack.
  • At byte 02, SUB subtracts the top two values on the stack. The stack has 0A (from CODESIZE) and V (from CALLVALUE). The operation is 0A - V, and the result is pushed back onto the stack.
  • At byte 03, JUMP uses the result of SUB to determine where to jump. For a valid jump, this result must match the address of a JUMPDEST. In this code, the only JUMPDEST is at byte 06.

To find the answer, we need to determine the value of V such that 0A - V equals 06. This calculation is straightforward:

    0A - V = 06 (hex)
    10 - V = 06 (decimal)
    V = 10 - 06
    V = 04

The answer is 4 (in decimal) or 04 (in hexadecimal), as this would be the value pushed by CALLVALUE that allows the JUMP to successfully target the JUMPDEST at byte 06.