Skip to main content

Try it Live

Run Bytecode examples in the interactive playground
Fusion detection identifies multi-instruction patterns that can be optimized, statically analyzed, or replaced with synthetic opcodes. These patterns are common in compiler-generated bytecode and provide opportunities for performance improvements and deeper analysis.

What are Fusions?

Fusions are sequences of 2-4 EVM instructions that:
  1. Occur frequently in compiler output (Solidity, Vyper, etc.)
  2. Can be optimized by combining into single operations
  3. Enable static analysis (e.g., PUSH+JUMP = static jump target)
  4. Reveal semantics (e.g., function dispatch, callvalue checks)

Example

Compiles to:
This PUSH+ADD fusion can be detected and:
  • Optimized to single “add immediate” operation
  • Recognized as constant addition pattern
  • Analyzed for gas savings

Fusion Categories

1. Arithmetic Fusions

Immediate arithmetic operations: Example:

2. Bitwise Fusions

Immediate bitwise operations: Common use: Masking (e.g., PUSH 0xFF, AND = mask to byte)

3. Memory Fusions

Immediate memory access: Example:

4. Control Flow Fusions

Static control flow:
PUSH+JUMP fusions reveal compile-time jump targets. This enables:
  • Control flow graph construction without execution
  • Dead code detection
  • Function boundary identification
  • Jump target validation at compile time
Example:

5. Stack Manipulation Fusions

Complex stack patterns: These patterns appear in:
  • ABI encoding/decoding
  • Struct field access
  • Array element computation
  • Memory copying

6. Multi-Instruction Fusions

Sequences of same instruction: Example:

7. Solidity-Specific Patterns

High-level language patterns:

FUNCTION_DISPATCH

Extracts function selectors from Solidity function dispatcher:
This enables:
  • ABI reconstruction from bytecode alone
  • Function boundary detection for decompilation
  • Selector collision detection
  • Gas profiling per function

CALLVALUE_CHECK

Detects non-payable function checks:
Indicates Solidity function without payable modifier.

Detection API

Fusion detection integrates with iteration:

Options

Selective Detection

Usage Patterns

Fusion Statistics

Optimization Opportunities

Control Flow Graph from Fusions

Function Extraction

Pattern Frequency Analysis

Integration with Other APIs

With prettyPrint

Pretty print annotates fusions with ⚡ symbol:

With analyzeBlocks

Detect fusions within blocks:

With analyzeGas

Estimate gas savings from fusion optimization:

Advanced Patterns

Custom Fusion Detection

Implement custom pattern matching:

Fusion-Based Decompilation

Use fusions to identify high-level constructs:

Compiler Fingerprinting

Different compilers generate different fusion patterns:

Performance

Detection Overhead

Fusion detection adds minimal overhead:
  • Disabled: ~0.5ms per 1KB bytecode
  • Enabled: ~0.8ms per 1KB bytecode
  • Overhead: ~60% (still sub-millisecond for most contracts)
Enable fusion detection only when needed. For simple iteration, leave disabled for maximum performance.

Caching

Fusion analysis is deterministic - results can be cached:

Limitations

Fusion detection is based on sequential pattern matching and cannot:
  • Detect patterns across basic blocks - Limited to same block
  • Handle data dependencies - Only structural patterns
  • Account for runtime values - Only compile-time constants
  • Detect semantically equivalent variants - Only exact patterns
Results represent syntactic patterns, not semantic equivalence.

What’s Detected

✅ Sequential instruction patterns (2-4 instructions) ✅ Immediate values in PUSH instructions ✅ Static jump targets ✅ Function selectors (4-byte constants) ✅ Common compiler idioms

What’s Not Detected

❌ Semantically equivalent but structurally different patterns ❌ Patterns spanning multiple basic blocks ❌ Data-dependent patterns ❌ Runtime-computed patterns

Use Cases

1. Bytecode Optimization

Identify patterns for optimization passes:

2. Security Analysis

Detect suspicious patterns:

3. Reverse Engineering

Reconstruct contract structure:

See Also