Try it Live
Run Bytecode examples in the interactive playground
Instruction Object
Each iteration yields anInstruction 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
scan() instead of parseInstructions() which materializes the entire array.
PUSH Data Handling
scan() correctly handles PUSH immediate data:
Fusion Patterns
WhendetectFusions: true (default), multi-instruction patterns are detected:
Error Handling
scan() validates bytecode structure during iteration. Malformed PUSH instructions (truncated data) will throw during iteration at the problematic position.Comparison with parseInstructions
Usescan() when:
- Processing large bytecode (memory efficiency)
- Need early exit capability
- Streaming analysis
- Real-time disassembly
parseInstructions() when:
- Need random access to instructions
- Multiple passes over same data
- Small bytecode (<1KB)
- Caching full instruction list
See Also
- Instruction Types - Complete OpcodeData union reference
- parseInstructions - Eager parsing to array
- Fusion Detection - Pattern detection details

