Skip to main content

Try it Live

Run Opcode examples in the interactive playground

Opcode.parse()

Parse bytecode into array of instructions with offsets and immediates.

Parameters

  • bytecode: Uint8Array - Raw contract bytecode to parse

Returns

Instruction[] - Array of parsed instructions

Behavior

  • Automatic PUSH skipping: Correctly skips PUSH immediate bytes (1-32 bytes depending on PUSH opcode)
  • Incomplete data handling: If bytecode ends mid-PUSH, returns instruction with partial immediate data
  • No validation: Does not validate if opcodes are valid - use isValid() to check
  • Zero-copy: Returns views into original bytecode for immediate data (efficient)

Use Cases

Disassemble Bytecode

Count Instruction Types

Extract All Constants

Track Stack Depth

Performance

  • O(n) time complexity where n is bytecode length
  • Zero allocation for non-PUSH opcodes (just offset tracking)
  • Single pass through bytecode
  • No recursion - simple linear scan