Skip to main content

Try it Live

Run Opcode examples in the interactive playground

Constructors

Methods for working with EVM opcodes and parsing bytecode.

Opcode Identity

Opcode(value)

Identity function for type branding. Casts number to BrandedOpcode.
Parameters:
  • value: number - Opcode byte value (0x00-0xFF)
Returns: BrandedOpcode - Branded opcode Note: This is a zero-cost type branding function. No validation is performed. Use isValid() to check if byte is a valid opcode. Defined in: primitives/Opcode/Opcode.js:85

Opcode Constants

All EVM opcodes exported as pre-branded constants:
Defined in: primitives/Opcode/BrandedOpcode/constants.js

Bytecode Parsing

Opcode.parse(bytecode)

Parse bytecode into array of instructions with offsets and immediates.
Parameters:
  • bytecode: Uint8Array - Raw contract bytecode
Returns: Instruction[] - Array of parsed instructions Instruction type:
Behavior:
  • Automatically skips PUSH immediate bytes
  • Handles incomplete PUSH data at end of bytecode
  • Returns instruction with offset, opcode, and optional immediate data
Defined in: primitives/Opcode/BrandedOpcode/parse.js:21

Opcode.pushOpcode(byteCount)

Get PUSH opcode for given byte count.
Parameters:
  • byteCount: number - Number of bytes to push (1-32)
Returns: BrandedOpcode - Corresponding PUSH opcode Throws:
  • Error if byteCount < 1 or > 32
Defined in: primitives/Opcode/BrandedOpcode/pushOpcode.js

Jump Destination Analysis

Opcode.jumpDests(bytecode)

Find all valid JUMPDEST positions in bytecode.
Parameters:
  • bytecode: Uint8Array - Contract bytecode
Returns: Set<number> - Set of valid JUMPDEST offsets Behavior:
  • Correctly skips PUSH immediate data
  • Only includes JUMPDEST opcodes (0x5B) not inside PUSH data
  • Returns empty set if no valid JUMPDESTs found
Defined in: primitives/Opcode/BrandedOpcode/jumpDests.js

Common Patterns

Build PUSH Instruction

Find All PUSH Instructions

Validate Jump Targets

Extract Constants

See Also