Skip to main content

Try it Live

Run Opcode examples in the interactive playground

Utilities

Utility functions for opcode metadata, stack analysis, gas costs, and bytecode disassembly.

Metadata

Opcode.info(opcode)

Get complete opcode metadata (gas cost, stack I/O, name).
Parameters:
  • opcode: BrandedOpcode - Opcode to query
Returns: Info | undefined - Metadata or undefined if invalid opcode
Defined in: primitives/Opcode/BrandedOpcode/info.js:17

Opcode.getName(opcode)

Get opcode mnemonic name.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: string | undefined - Mnemonic name or undefined

Opcode.name(opcode)

Alias for getName().

Opcode.getDescription(opcode)

Get human-readable opcode description.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: string | undefined - Description

Opcode.getCategory(opcode)

Get opcode category.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: string | undefined - Category

Stack Analysis

Opcode.getStackInput(opcode)

Get number of stack items consumed.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Stack inputs

Opcode.getStackOutput(opcode)

Get number of stack items produced.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Stack outputs

Opcode.getStackEffect(opcode)

Get net stack effect (outputs - inputs).
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Net stack change

Gas Costs

Opcode.getGasCost(opcode)

Get static base gas cost.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Base gas cost Note: Many opcodes have dynamic gas costs depending on runtime state (e.g., SSTORE, CALL, CREATE). This returns only the base/minimum cost.

PUSH/DUP/SWAP Utilities

Opcode.pushBytes(opcode)

Get number of immediate bytes for PUSH opcode.
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Byte count or undefined

Opcode.dupPosition(opcode)

Get stack position duplicated by DUP opcode (1-16).
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Position (1-16) or undefined

Opcode.swapPosition(opcode)

Get stack position swapped by SWAP opcode (1-16).
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Position (1-16) or undefined

Opcode.logTopics(opcode)

Get number of topics for LOG opcode (0-4).
Parameters:
  • opcode: BrandedOpcode - Opcode
Returns: number | undefined - Topic count (0-4) or undefined

Disassembly

Opcode.disassemble(bytecode)

Disassemble bytecode to human-readable assembly.
Parameters:
  • bytecode: Uint8Array - Raw bytecode
Returns: string[] - Array of formatted instruction strings Format: "<offset>: <mnemonic> [immediate]"

Opcode.format(instruction)

Format single instruction as string.
Parameters:
  • instruction: Instruction - Parsed instruction
Returns: string - Formatted string

Utility Patterns

Calculate Stack Depth

Estimate Gas Cost

Group by Category

Pretty Print Assembly

Extract PUSH Values

See Also