Skip to main content

Try it Live

Run Bytecode examples in the interactive playground

    Instruction Object

    Each iteration yields an Instruction object matching the OpcodeData union type:

    Options

    Usage Patterns

    Basic Iteration

    With Gas Costs

    With Stack Tracking

    Filter by Type

    Detect PUSH Values

    Fusion Detection

    Partial Iteration

    Early Exit

    Collect to Array

    Performance

    scan() uses lazy iteration for memory efficiency:
    • Lazy evaluation - Instructions computed on demand
    • O(1) memory - Only current instruction in memory
    • Streaming - Supports early exit without parsing entire bytecode
    • Efficient PUSH handling - Skips over immediate data bytes
    • Bitmap lookups - O(1) JUMPDEST validation
    For large bytecode (10KB+), use scan() instead of parseInstructions() which materializes the entire array.

    PUSH Data Handling

    scan() correctly handles PUSH immediate data:

    Fusion Patterns

    When detectFusions: true (default), multi-instruction patterns are detected:
    See Fusion Detection for all 20+ patterns.

    Error Handling

    scan() validates bytecode structure during iteration. Malformed PUSH instructions (truncated data) will throw during iteration at the problematic position.

    Comparison with parseInstructions

    Use scan() when:
    • Processing large bytecode (memory efficiency)
    • Need early exit capability
    • Streaming analysis
    • Real-time disassembly
    Use parseInstructions() when:
    • Need random access to instructions
    • Multiple passes over same data
    • Small bytecode (<1KB)
    • Caching full instruction list

    See Also