Skip to main content

Try it Live

Run Bytecode examples in the interactive playground

    GasAnalysis Type

    InstructionGas

    BlockGas

    ExpensiveInstruction

    ExecutionPath

    Options

    Usage Patterns

    Basic Gas Estimation

    Instruction-Level Breakdown

    Block-Level Analysis

    Identify Expensive Operations

    Path Analysis

    Dynamic Gas Estimation

    EIP-3860 Initcode Gas

    Calculate initcode gas (2 gas per 32-byte word):
    Post-Shanghai, initcode costs 2 gas per 32-byte word. Include this when deploying contracts.

    Gas Cost Categories

    Instructions grouped by gas cost category:

    Base Cost (3 gas)

    • Stack: PUSH, DUP, SWAP, POP
    • Arithmetic: ADD, SUB, MUL
    • Comparison: LT, GT, EQ
    • Bitwise: AND, OR, XOR, NOT

    Memory Expansion (3+ gas)

    • MLOAD, MSTORE, MSTORE8: 3 gas + expansion cost
    • Expansion: 3 * new_words + (new_words)² ÷ 512

    Storage (2100/20000 gas)

    • SLOAD: 100 gas (warm) / 2100 gas (cold)
    • SSTORE: 100/2900/20000 gas (depends on change)

    Calls (700+ gas)

    • CALL, DELEGATECALL, STATICCALL: 700 base + value transfer + memory expansion
    • CREATE, CREATE2: 32000 gas + deployment gas

    Hashing

    • KECCAK256: 30 gas + 6 gas per word
    • SHA256, RIPEMD160: 60 gas + 12 gas per word (precompiles)

    Expensive Operations

    • EXP: 10 gas + 50 gas per byte of exponent
    • SELFDESTRUCT: 5000 gas + refund

    Limitations

    Gas estimation is based on static analysis and may not reflect actual execution costs:
    • Dynamic jumps - Multiple possible paths
    • Loop gas - Cannot determine iteration count
    • External calls - Called contract gas unknown
    • Memory expansion - Depends on runtime values
    • Storage access - Warm/cold status runtime-dependent
    Use includeDynamic: true with context for better estimates, but always test on-chain.

    What’s Included

    ✅ Base opcode costs (ADD, MUL, PUSH, etc.) ✅ JUMPDEST costs (1 gas each) ✅ Block-level aggregation ✅ Sequential execution path ✅ Multiple path exploration (with analyzePaths)

    What’s Estimated

    ⚠️ Memory expansion (requires runtime sizes) ⚠️ Storage access (warm/cold requires context) ⚠️ Call stipend and value transfer ⚠️ CREATE deployment gas

    What’s Not Included

    ❌ Actual loop iteration counts ❌ External contract execution costs ❌ Precompile gas (except fixed-cost ones) ❌ Gas refunds (SELFDESTRUCT, SSTORE)

    Optimization Hints

    Identify gas optimization opportunities:

    Integration with Opcode Module

    Gas costs come from Opcode.getGasCost():

    See Also