> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Hardfork.hasEIP3855

> Check if PUSH0 opcode is available

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/hardfork.ts">
  Run Hardfork examples in the interactive playground
</Card>

<Tabs />

## 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:

```typescript theme={null}
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:

```typescript theme={null}
import { Hardfork } from 'tevm'

function getCompilerTarget(fork: BrandedHardfork) {
  return {
    hardfork: Hardfork.toString(fork),
    usePUSH0: fork.hasEIP3855()
  }
}
```

### Bytecode Generation

Generate optimal bytecode:

```typescript theme={null}
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:

```typescript theme={null}
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:

```typescript theme={null}
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:

```typescript theme={null}
import { Hardfork } from 'tevm'

function getSoliditySettings(fork: BrandedHardfork) {
  return {
    evmVersion: fork.hasEIP3855() ? "shanghai" : "paris",
    optimizer: {
      enabled: true,
      runs: 200
    }
  }
}
```

## EIP References

**Primary:**

* [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855) - PUSH0 instruction

## 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 0x00` → `PUSH0` 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](/primitives/hardfork/has-eip1559) - Check EIP-1559 base fee availability (London)
* [hasEIP4844](/primitives/hardfork/has-eip4844) - Check blob transactions availability (Cancun)
* [isAtLeast](/primitives/hardfork/is-at-least) - General version comparison
