Skip to main content

Try it Live

Run Hardfork examples in the interactive playground

    EIP-3855 Features

    Active Since: Shanghai (April 12, 2023)

    PUSH0 Opcode

    Opcode: 0x5F Function: Pushes constant 0 onto the stack Gas Cost: 2 gas

    Benefits

    Gas Savings:
    • PUSH0: 2 gas
    • PUSH1 0x00: 3 gas
    • Saves 1 gas per zero push (33% reduction)
    Bytecode Size:
    • PUSH0: 1 byte
    • PUSH1 0x00: 2 bytes
    • Reduces contract size by 1 byte per occurrence
    Common Use Cases:
    • Function return values initialization
    • Array/mapping default values
    • Stack manipulation
    • Placeholder values

    Usage Patterns

    Opcode Selection

    Select optimal zero-push implementation:
    import { Hardfork } from 'tevm'
    
    function getPushZeroOpcode(fork: BrandedHardfork) {
      if (fork.hasEIP3855()) {
        return {
          opcode: 0x5F,        // PUSH0
          gas: 2,
          bytes: [0x5F]
        }
      }
    
      return {
        opcode: 0x60,          // PUSH1
        gas: 3,
        bytes: [0x60, 0x00]
      }
    }
    

    Compiler Optimization

    Enable PUSH0 in compiler:
    import { Hardfork } from 'tevm'
    
    function getCompilerTarget(fork: BrandedHardfork) {
      return {
        hardfork: Hardfork.toString(fork),
        usePUSH0: fork.hasEIP3855()
      }
    }
    

    Bytecode Generation

    Generate optimal bytecode:
    import { Hardfork } from 'tevm'
    
    function emitPushZero(fork: BrandedHardfork): Uint8Array {
      if (fork.hasEIP3855()) {
        return new Uint8Array([0x5F])  // PUSH0
      }
    
      return new Uint8Array([0x60, 0x00])  // PUSH1 0x00
    }
    

    Gas Estimation

    Calculate gas costs:
    import { Hardfork } from 'tevm'
    
    function estimatePushZeroGas(
      fork: BrandedHardfork,
      occurrences: number
    ): number {
      if (fork.hasEIP3855()) {
        return 2 * occurrences  // PUSH0: 2 gas each
      }
    
      return 3 * occurrences  // PUSH1 0x00: 3 gas each
    }
    
    // Typical contract might save 100-500 gas
    const savings = estimatePushZeroGas(MERGE, 100) - estimatePushZeroGas(SHANGHAI, 100)
    console.log(`Gas savings: ${savings}`)  // 100 gas
    

    Network Configuration

    Validate PUSH0 support:
    import { Hardfork, SHANGHAI } from 'tevm'
    
    function validatePUSH0Support(config: NetworkConfig) {
      const fork = Hardfork(config.hardfork)
    
      if (fork.hasEIP3855()) {
        console.log("PUSH0 optimization available")
      } else {
        console.log("PUSH0 not available, using PUSH1 0x00")
      }
    }
    

    Compiler Integration

    Solidity compiler support:
    import { Hardfork } from 'tevm'
    
    function getSoliditySettings(fork: BrandedHardfork) {
      return {
        evmVersion: fork.hasEIP3855() ? "shanghai" : "paris",
        optimizer: {
          enabled: true,
          runs: 200
        }
      }
    }
    

    EIP References

    Primary:

    Impact

    For Developers:
    • Smaller contract sizes (reduces deployment costs)
    • Lower execution costs (1 gas saved per zero push)
    • Must target Shanghai or later for PUSH0 optimization
    For Compilers:
    • Can optimize PUSH1 0x00PUSH0 when targeting Shanghai+
    • Reduces bytecode size without semantic changes
    For Contracts:
    • Typical savings: 50-500 gas per transaction
    • Reduced deployment costs: 100-1000 gas per contract
    • Zero runtime overhead

    See Also

    • hasEIP1559 - Check EIP-1559 base fee availability (London)
    • hasEIP4844 - Check blob transactions availability (Cancun)
    • isAtLeast - General version comparison