# Hardforks and Specs

MegaETH versions its verifiable behavior through **hardforks** and **specs**. This page defines both concepts and summarizes what each spec introduces.

## Hardfork vs Spec

The protocol distinguishes between two related concepts:

* [**Hardfork**](https://docs.megaeth.com/spec/reference/glossary#hardfork-megahardfork) — A network upgrade event: *when* changes are activated on the chain. A hardfork may include protocol-level changes beyond MegaEVM (e.g., networking, state sync, RPC behavior). Represented as `MegaHardfork` in the reference implementation.
* [**Spec**](https://docs.megaeth.com/spec/reference/glossary#spec-megaspecid) — A set of MegaETH verifiable behaviors: *what* a correct node does. A spec captures the execution-layer semantics that determine node correctness. Represented as `MegaSpecId` in the reference implementation.

Multiple hardforks can map to the same spec. A hardfork can also map to an older spec. For example: `MiniRex` → `MINI_REX`, `MiniRex1` → `EQUIVALENCE` (rollback), `MiniRex2` → `MINI_REX` (restoration).

This documentation covers specs — the verifiable behavioral definitions that determine correctness of a MegaETH node. Protocol-level changes outside the verifiable execution layer (e.g., networking, peer discovery) that are part of a hardfork are not covered here.

## Spec Progression

```
EQUIVALENCE → MINI_REX → REX → REX1 → REX2 → REX3 → REX4 → REX5
```

Each newer spec includes all previous behaviors. All specs build on Optimism Isthmus (Ethereum Prague) as the base layer. REX5 is currently **unstable** — its semantics can still change before network activation. All other specs are stable (frozen).

### Backward Compatibility

EVM semantics for stable (activated) specs are frozen. A new spec may add behavior or change the unstable spec, but it never alters what an existing stable spec does. Every spec carries the invariant: "Stable pre-{Spec} semantics MUST remain unchanged."

This means:

* Contracts deployed under a given spec will continue to behave identically after future upgrades.
* Adding or modifying a system contract requires introducing a new spec.
* Changing gas costs, opcode behavior, or resource limits requires a new spec.
* Implementations MUST gate spec-specific behavior on the active spec.

## Spec Summary

### EQUIVALENCE

The baseline spec. Maintains full compatibility with Optimism Isthmus EVM. Adds block environment access tracking for parallel execution support.

### MINI\_REX

The first spec to introduce MegaETH-specific modifications:

* [**Dual gas model**](https://docs.megaeth.com/spec/megaevm/dual-gas-model) — [Compute gas](https://docs.megaeth.com/spec/reference/glossary#compute-gas) + [storage gas](https://docs.megaeth.com/spec/reference/glossary#storage-gas)
* [**Multidimensional resource limits**](https://docs.megaeth.com/spec/megaevm/resource-limits) — Compute gas (1B), data size (3.125 MB), KV updates (125K)
* [**Dynamic gas costs**](https://docs.megaeth.com/spec/megaevm/dual-gas-model#dynamic-salt-multiplier) — [SALT bucket](https://docs.megaeth.com/spec/reference/glossary#salt-bucket)-based scaling
* [**Gas detention**](https://docs.megaeth.com/spec/megaevm/gas-detention) — [Volatile data](https://docs.megaeth.com/spec/reference/glossary#volatile-data) access triggers gas limiting
* **SELFDESTRUCT disabled**
* **Large contract support** — 512 KB contracts (21x increase from 24 KB)

*See* [*MiniRex Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/minirex) *for full details.*

### REX

Refines the [storage gas](https://docs.megaeth.com/spec/reference/glossary#storage-gas) economics introduced in MINI\_REX:

* **Refined storage gas formulas** — Gradual scaling (20K–32K base costs vs MiniRex's 2M)
* **Transaction intrinsic storage gas** — 39,000 flat fee for all transactions
* **Zero cost fresh storage** — Minimum-sized [SALT buckets](https://docs.megaeth.com/spec/reference/glossary#salt-bucket) charge 0 storage gas
* **Security fixes** — DELEGATECALL, STATICCALL, CALLCODE properly enforce gas forwarding and oracle access detection
* [**State growth**](https://docs.megaeth.com/spec/megaevm/resource-accounting#state-growth) **tracking** — New [resource limit](https://docs.megaeth.com/spec/megaevm/resource-limits) dimension

*See* [*Rex Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/rex) *for full details.*

### REX1

* **Limit reset fix** — Resets compute gas limits at the start of each transaction
* Inherits Rex semantics fully

*See* [*Rex1 Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/rex1) *for full details.*

### REX2

* **SELFDESTRUCT restored** — Re-enabled with [EIP-6780](https://eips.ethereum.org/EIPS/eip-6780) semantics
* [**KeylessDeploy**](https://docs.megaeth.com/spec/system-contracts/keyless-deploy) **system contract** — Enables deterministic cross-chain deployment (Nick's Method)

*See* [*Rex2 Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/rex2) *for full details.*

### REX3

* **Increased oracle access gas limit** — Raised from 1M to 20M
* **SLOAD-based** [**oracle**](https://docs.megaeth.com/spec/system-contracts/oracle) **detention** — Triggers on SLOAD from oracle storage instead of CALL to oracle contract
* [**Keyless deploy**](https://docs.megaeth.com/spec/system-contracts/keyless-deploy) [**compute gas**](https://docs.megaeth.com/spec/reference/glossary#compute-gas) **tracking** — Records the 100K overhead as compute gas

*See* [*Rex3 Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/rex3) *for full details.*

### REX4

* **Per-**[**call-frame**](https://docs.megaeth.com/spec/reference/glossary#call-frame) **resource budgets** — All four [resource dimensions](https://docs.megaeth.com/spec/reference/glossary#resource-dimension) (compute gas, data size, KV updates, state growth) are bounded per call frame with 98/100 forwarding
* **Relative** [**gas detention**](https://docs.megaeth.com/spec/megaevm/gas-detention) **cap** — Effective [detained limit](https://docs.megaeth.com/spec/reference/glossary#detained-limit) is `current_usage + cap` instead of an absolute cap
* [**Storage gas stipend**](https://docs.megaeth.com/spec/reference/glossary#storage-gas-stipend) — Value-transferring CALL/CALLCODE receives an additional 23,000 gas for [storage gas](https://docs.megaeth.com/spec/reference/glossary#storage-gas) operations, fixing LOG events in `receive()` under the [dual gas model](https://docs.megaeth.com/spec/megaevm/dual-gas-model)
* **MegaAccessControl system contract** — Allows contracts to proactively disable [volatile data](https://docs.megaeth.com/spec/reference/glossary#volatile-data) access for a call subtree
* **MegaLimitControl system contract** — Allows querying effective remaining compute gas under detention and call frame limits
* [**Keyless deploy**](https://docs.megaeth.com/spec/system-contracts/keyless-deploy) **sandbox environment inheritance** — Sandbox inherits parent transaction's external environment for dynamic pricing and oracle behavior

*See* [*Rex4 Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/rex4) *for full details.*

### REX5

> **Unstable** — This spec is under active development. Its semantics may change before network activation.

No behavioral changes have been defined yet. This spec serves as the placeholder for the next upgrade cycle.

*See* [*Rex5 Network Upgrade*](https://docs.megaeth.com/spec/network-upgrades/rex5) *for the latest status.*
