Skip to content

docs: add MegaEVM book docs and refactor spec docs structure#202

Open
RealiCZ wants to merge 20 commits intomainfrom
cz/book
Open

docs: add MegaEVM book docs and refactor spec docs structure#202
RealiCZ wants to merge 20 commits intomainfrom
cz/book

Conversation

@RealiCZ
Copy link
Contributor

@RealiCZ RealiCZ commented Mar 20, 2026

Summary

  • Add GitBook-based documentation structure under book/, including EVM, system contracts, and network upgrade pages.
  • Add specs/STYLE-GUIDE.md to define normative/informative doc conventions and writing rules.
  • Add per-spec informative companion docs under specs/impl/ (Behavior Details + Implementation References).
  • Keep this PR documentation/spec-text focused, without runtime code changes.

Test plan

  • Verified changed files are documentation/spec files only (book/, specs/, .gitbook.yaml).
  • Manually reviewed cross-links and document structure consistency (book/src/SUMMARY.md, spec references).
  • No runtime behavior validation needed for this docs/spec-only PR.

@RealiCZ RealiCZ requested a review from Troublor as a code owner March 20, 2026 01:27
@RealiCZ RealiCZ added spec:unchanged No change to any `mega-evm`'s behavior comp:misc Changes to the miscellaneous part of this repo api:unchanged No change to the public interface or API labels Mar 20, 2026
@claude
Copy link

claude bot commented Mar 20, 2026

Good structure overall — the separation into normative specs, behavior details, implementation references, and public book pages is clean and maintainable.

Three issues to fix before merging:

1. Spec progression diagram mixes hardfork and spec names (blocking)

book/src/README.md and book/src/evm/spec-system.md both show:

EQUIVALENCE → MINI_REX → MINI_REX1 → MINI_REX2 → REX → …

MINI_REX1 and MINI_REX2 are MegaHardfork values, not MegaSpecId values. The actual spec progression is:

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

Showing them in a diagram labeled "Spec Progression" immediately followed by "each newer spec includes all previous behaviors" is wrong — MiniRex1 → EQUIVALENCE (a rollback) breaks that invariant. See inline comments.

2. alloy-evm GitHub link is wrong

book/src/README.md line 22 links alloy-evm to https://github.com/alloy-rs/core, which is the primitives/core library. alloy-evm is in alloy-rs/alloy.

3. Hardfork→spec example omits MiniRex1

spec-system.md says "both MiniRex and MiniRex2 hardforks use the MINI_REX spec" but omits MiniRex1 → EQUIVALENCE (the rollback). That's exactly what makes the many-to-one mapping interesting and worth documenting. See inline comment.

@claude
Copy link

claude bot commented Mar 20, 2026

Review

Overall this is a solid refactor: the new style guide is well-defined, the spec restructuring into Abstract / Changes / Invariants / Inheritance / References is a clear improvement over the old numbered-section format, and the companion specs/impl/ docs are a valuable addition. No runtime code changes.

Four issues worth fixing before merge:

Factual error

  • book/src/README.md line 22: alloy-evm is linked to github.com/alloy-rs/core, which is the alloy-core repo (primitives, sol-types). alloy-evm lives elsewhere. See inline comment.

Missing unstable caveat

  • book/src/upgrades/rex4.md presents Rex4 as a completed upgrade with no caveat, but CLAUDE.md explicitly marks Rex4 as the current unstable spec under active development. Public docs for an unstable spec should carry a clear notice that semantics may change. See inline comment.

Semantic ambiguity in specs

  • specs/Rex.md: the state growth definition omits the "net" qualifier that CLAUDE.md specifies ("Net new accounts + net new storage slots"). Whether reverted inner writes count is left undefined. See inline comment.
  • specs/MiniRex.md: the SELFBALANCE entry in the beneficiary access list is misleading — SELFBALANCE reads the current contract's own balance, so it only accesses the beneficiary's balance when the current contract is the beneficiary. See inline comment.

@claude
Copy link

claude bot commented Mar 20, 2026

Overall this PR is well-structured and a significant improvement to the documentation. The three-tier hierarchy (normative spec → behavior details → implementation references) is clear, the STYLE-GUIDE.md is useful, and the book pages are accurate and developer-friendly. A few issues to address:

@claude
Copy link

claude bot commented Mar 20, 2026

This is a well-structured docs PR. The spec refactoring (normative/behavior-details/implementation-references split) is clean and the style guide are a valuable addition. A few issues worth addressing.

1. Per-frame limits section scoped only to State Growth (book/src/evm/resource-accounting.md)

The "Per-Frame Limits (Rex4+)" subsection appears only under State Growth. But Rex4 adds per-frame budgets for all four dimensions (compute gas, data size, KV updates, state growth). A developer reading only the Data Size or KV Updates sections will miss this entirely. The subsection should be elevated to a top-level section or at minimum cross-referenced from each dimension.

2. "How It Works" steps 4-5 are alternatives, not sequential steps (book/src/evm/gas-detention.md)

The numbered list presents a process flow, but steps 4 and 5 are mutually exclusive spec variants (pre-Rex4 absolute cap vs Rex4 relative cap). Numbering them as consecutive steps implies both execute for the same transaction, which is wrong.

3. Error name mismatch (book/src/evm/gas-detention.md)

Step 4 says "execution halts with OutOfGas" but specs/MiniRex.md uses VolatileDataAccessOutOfGas. These should match so readers can correlate the two documents.

4. specs/Rex1.md References lists Rex2 before Rex

The successor (Rex2) is listed before the predecessor (Rex), which is inconsistent with other spec files.

Minor: book/src/README.md hardcodes library versions (revm v27.1.0, op-revm v8.1.0, alloy-evm v0.15.0) that will silently go stale.

@claude
Copy link

claude bot commented Mar 22, 2026

Review: Good structure overall. The spec style guide is a real improvement. The AGENTS.md correction (removing MINI_REX1/MINI_REX2 from the spec progression) is correct. One factual error repeated in four places: MAX_INITCODE_SIZE should be 548,864 bytes (512 KB + 24 KB), not 536,576. Inline suggestions posted on each location. Also the 21x larger note in book/src/evm/README.md only applies to contract size, not initcode.

@claude
Copy link

claude bot commented Mar 22, 2026

Review

Overall the structure is clean and the spec rewrites improve clarity significantly. Three issues to address:

1. Removed test links in specs/impl/Rex4-Implementation-References.md (actionable)
All test file references were removed from the implementation references document, but the tests themselves still exist in crates/mega-evm/tests/rex4/ (frame_limits.rs, frame_state_growth.rs, access_control.rs, limit_control.rs, gas_detention.rs, keyless_deploy.rs). The scope description was also narrowed from "implementation and tests" to "implementation". This leaves the document inaccurate as a code-navigation aid. Restore the test links or add a brief note explaining the intentional omission.

2. Forward references in Rex1.md and Rex3.md (minor)
Rex1 now links to Rex2, and Rex3 links to Rex4 in their normative References sections. This is unusual for spec documents — readers expect references to point to ancestors, not successors. Rex4 is also the current unstable spec, so linking it from a stable spec creates maintenance risk if Rex4 is restructured. Consider a separate "Next" or "See also" section for these forward links.

3. AGENTS.md wording for MiniRex1/MiniRex2 (nit)
"reuse EQUIVALENCE and MINI_REX respectively" doesn't convey the rollback semantics. The hardfork.rs comment says "intentionally reverted to previously released specs". The book's upgrade table uses "Rollback" and "Restoration" which is more accurate. Suggest aligning AGENTS.md with that language.

@RealiCZ
Copy link
Contributor Author

RealiCZ commented Mar 22, 2026

@claude All three points were discussed in prior review rounds:

  1. Test links removal — Intentional. All impl reference files consistently exclude test
    links. Convention documented in specs/STYLE-GUIDE.md.
  2. Forward references — Intentional for bidirectional navigation. Not a dependency claim.
  3. AGENTS.md wording — Sufficient for its audience.

No changes needed for this round.

@claude
Copy link

claude bot commented Mar 22, 2026

Claude finished @RealiCZ's task in 26s —— View job


Acknowledged — all three points are intentional design decisions:

  1. Test links removal: Confirmed. specs/STYLE-GUIDE.md line 208–209 explicitly states: "Implementation references map to production source files only. Test file links are not included — tests can be discovered via the corresponding test directory." The convention is documented.

  2. Forward references: Confirmed. Bidirectional navigation intent is reasonable; the reference list is not a dependency claim.

  3. AGENTS.md wording: Confirmed. Sufficient for its audience.

No changes needed. The remaining open issues from earlier rounds (factual fixes like the MAX_INITCODE_SIZE byte count, oracle trigger STATICCALL in Rex3 "Previous behavior", gas-detention terminology, etc.) are still outstanding unless separately addressed or dismissed.

@RealiCZ
Copy link
Contributor Author

RealiCZ commented Mar 22, 2026

@claude Please post a final review summary confirming the current state of the PR.

@claude
Copy link

claude bot commented Mar 22, 2026

Claude finished @RealiCZ's task in 3m 49s —— View job


Final Review Summary

This is a well-structured docs PR. The three-tier hierarchy (normative spec / behavior details / implementation references), the STYLE-GUIDE, and the GitBook setup are all solid additions.

Issues Resolved ✅

All major factual and structural issues raised across review rounds are fixed:

Issue Status
alloy-evm linked to wrong repo (alloy-rs/corealloy-rs/alloy) ✅ Fixed
Spec progression showing hardfork names (MINI_REX1, MINI_REX2) instead of spec IDs ✅ Fixed
Hardfork→spec mapping example missing MiniRex1 → EQUIVALENCE rollback ✅ Fixed
Rex4 unstable notice missing from upgrades/rex4.md ✅ Fixed
State growth missing "net" qualifier in specs/Rex.md ✅ Fixed
I-5 invariant not in MUST/MUST NOT format ✅ Fixed
SELFBALANCE applies only when current contract is the beneficiary ✅ Fixed in specs/MiniRex.md
Gas detention cap not described as absolute in specs/MiniRex.md ✅ Fixed
Gas detention steps 4/5 presented as sequential instead of alternatives ✅ Fixed
Error name OutOfGas vs VolatileDataAccessOutOfGas mismatch ✅ Fixed
Rex–Rex2 oracle trigger missing STATICCALL in evolution table ✅ Fixed
Concept table headers swapped ("Topic"/"Page") in evm/README.md ✅ Fixed
Unexplained (v83) annotation in book/src/README.md ✅ Fixed
MiniRex1/MiniRex2 absent from upgrade history table ✅ Fixed
MAX_INITCODE_SIZE incorrect (536,576 → 548,864 bytes) across 4 files ✅ Fixed
"21×" note incorrectly applied to initcode (only applies to contract size) ✅ Fixed
Rex3 "Previous behavior" missing STATICCALL as oracle trigger ✅ Fixed (specs/Rex3.md + book/src/upgrades/rex3.md)
"Seven types" count in resource-limits.md inconsistent with inline list ✅ Fixed
Rex1 References listed Rex2 before Rex ✅ Fixed
Missing blank line before Rex4 blockquote (rendering issue) ✅ Fixed
"beneficiary" overloaded in SELFDESTRUCT context (rex2.md) ✅ Fixed
Per-frame limits only under State Growth section ✅ Fixed
"Cap (Rex3+)" column header misleading ✅ Fixed
NonZeroTxNonce() missing from keyless-deploy validation table ✅ Fixed

Intentionally Dismissed (acknowledged) ✅

  • Test links in specs/impl/Rex4-Implementation-References.md — Intentional; convention documented in specs/STYLE-GUIDE.md lines 208–209.
  • Forward references in Rex1/Rex3 — Intentional for bidirectional navigation; not a dependency claim.
  • AGENTS.md wording for MiniRex1/MiniRex2 — Deemed sufficient for its audience.

One Remaining Issue ⚠️

book/src/evm/README.md (the "Current EVM Standard" page) is missing the Rex4 unstable notice.

This page opens with "It reflects the latest spec (Rex4)" but carries no caveat that Rex4 is unstable and subject to change before activation. The upgrades/rex4.md page has the notice, but a developer landing on the primary EVM reference page won't see it.

Suggested addition after line 6:

> **Note**: This page reflects Rex4, which is the current unstable specification and is subject to change before activation.

Fix this →

Overall Assessment

The PR is high quality and nearly ready to merge. The one remaining issue is minor — the unstable warning is a one-line addition to book/src/evm/README.md. All other review concerns have been addressed.

Copy link
Collaborator

@Troublor Troublor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

High-quality documentation restructuring. The three-tier hierarchy (normative spec → behavior details → implementation references) with the separate public-facing book is well-designed.

Key issues raised:

  1. Current EVM Standard describes Rex4 (unstable) — should reflect Rex3 (latest stable) or clearly warn about unstable content.
  2. SALT buckets never explained — the multiplier formula is used everywhere but the concept is a black box for developers.
  3. Gas estimation guidance missing — developers need to know to call eth_estimateGas on a MegaETH endpoint.
  4. SSTORE condition underspecified in normative spec — "zero-to-non-zero" should state the exact triple condition (original==0 AND present==0 AND new!=0).
  5. LOG revert behavior needs clarification — gas cost is permanent regardless of revert, but data size limit accounting rolls back.
  6. 98/100 rule migration impact not surfaced for developers porting existing Ethereum contracts.
  7. "Remaining gas is preserved and refunded" is imprecise — should specify halt (not revert), gas_used < gas_limit in receipt.
  8. No glossary — MegaETH-specific terms used throughout without formal definitions.

Comment on lines +33 to +41
Storage gas costs scale dynamically based on **SALT bucket capacity**.
Each account and storage slot maps to a SALT bucket in MegaETH's blockchain state.

**Formula**: `multiplier = bucket_capacity / MIN_BUCKET_SIZE`

- When `multiplier = 1` (minimum bucket size): **zero storage gas** — no penalty for fresh storage
- When `multiplier > 1`: linear scaling based on bucket capacity expansion

This mechanism prevents state bloat by making storage more expensive in crowded state regions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SALT buckets are used throughout the docs but never explained to developers.

The formula multiplier = bucket_capacity / MIN_BUCKET_SIZE is clear mathematically, but a dapp developer reading this has no idea:

  • What IS a SALT bucket? (The concept is never introduced.)
  • What determines bucket_capacity? (State density? Account age? Something configurable?)
  • Can a developer query their contract's bucket capacity? Is there an RPC or system contract for this?
  • What is the practical range of multiplier values they should expect? (1–10? 1–1000?)

Without this context, a developer cannot estimate storage gas costs for their contracts. They see 20,000 × (multiplier − 1) and have no idea what multiplier will be.

Suggestion: Add a brief "SALT Buckets" subsection here explaining:

  1. What determines bucket capacity (conceptually — not implementation details)
  2. Whether developers can query or predict it
  3. The practical multiplier range
  4. Or simply: "Use MegaETH's gas estimation API; do not attempt to compute storage gas manually."

Comment on lines +41 to +42
| **LOG topic** | 3,750/topic | Per topic, regardless of revert |
| **LOG data** | 80/byte | Per byte, regardless of revert |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Regardless of revert" is true for the gas cost but not for the data size limit accounting.

Verified against code:

  • Storage gas: permanently consumed even if the frame reverts (charged via gas!() before LOG executes). ✓ "regardless of revert" is correct here.
  • Data size limit: LOG data is tracked as discardable in DataSizeTracker and rolled back when the frame reverts via pop_frame(success=false).

For a dapp developer, the practical question is: "If my subcall reverts, do I still pay for its LOGs?"

  • Gas cost: Yes, you still pay.
  • Data size budget: No, it does not count against your data size limit.

Suggestion: Clarify the dual behavior, e.g.:

| LOG topic | 3,750/topic | Gas cost is permanent regardless of revert; data size usage is rolled back on revert |
| LOG data | 80/byte | Gas cost is permanent regardless of revert; data size usage is rolled back on revert |

Comment on lines +92 to +95
## Gas Forwarding (98/100 Rule)

All CALL-like opcodes (CALL, STATICCALL, DELEGATECALL, CALLCODE) and CREATE/CREATE2 forward at most **98/100** of remaining gas to subcalls, replacing the standard EVM's 63/64 rule.
This prevents call-depth attacks under MegaETH's high gas limits.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section describes what the 98/100 rule IS, but not what it BREAKS for developers porting existing Ethereum contracts.

Contracts that depend on gas forwarding precision may behave differently on MegaETH:

  • Gas-limited subcalls — patterns like addr.call{gas: X}(...) where X is calculated assuming 63/64 retained by the parent. With 98/100, the parent retains 2/100 instead of 1/64, changing the effective gas available to the caller after the subcall.
  • Proxy patterns checking gasleft() — contracts that estimate remaining gas after a subcall (e.g., to decide whether to attempt a fallback) will see different numbers.
  • Gas stipend assumptions — the 2300 gas stipend for ETH transfers is unchanged, but any contract that computes "how much gas will my subcall actually receive" using the 63/64 formula will be wrong.

The MiniRex Behavior Details companion doc touches this under "Migration Impact", but a dapp developer reading the book would never find it there.

Suggestion: Add a brief developer note here, e.g.:

Migration note: Contracts that compute gas forwarding amounts assuming the standard 63/64 rule (EIP-150) will see different behavior. The parent frame retains 2% instead of ~1.6%, so subcalls receive slightly less gas. Review any patterns that rely on precise gas forwarding calculations.

Comment on lines +50 to +57
Storage gas costs for SSTORE, account creation, and contract creation scale dynamically based on SALT bucket capacity.

**Formula**: `multiplier = bucket_capacity / MIN_BUCKET_SIZE`

- At `multiplier = 1` (minimum bucket size): **zero storage gas** — fresh storage is free.
- At `multiplier > 1`: linear scaling makes crowded state regions more expensive.

See [Dual Gas Model](dual-gas-model.md) for details.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the SALT multiplier section, a developer's immediate question is: "How do I estimate gas for my transactions?"

With dynamic SALT multipliers, storage gas, gas detention, and multidimensional resource limits all affecting the final cost, a developer cannot manually compute gas costs from the formulas alone — the multiplier depends on on-chain state they may not have access to.

Suggestion: Add a brief practical note here, e.g.:

Gas estimation: Call eth_estimateGas on a MegaETH RPC endpoint to get precise gas estimates. The endpoint accounts for SALT multipliers, storage gas, and all resource dimensions. Do not attempt to compute gas costs manually from the formulas above — the dynamic multiplier depends on on-chain SALT bucket state.

specs/MiniRex.md Outdated
- In comparison, Standard EVM (EIP-3860): 49,152 bytes (48 KB)
| Operation | Storage Gas | Condition |
| --- | --- | --- |
| **SSTORE (0→non-0)** | 2,000,000 × multiplier | Only zero-to-non-zero transitions |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Only zero-to-non-zero transitions" is ambiguous for a reimplementer.

Verified against code (instructions.rs), the exact condition is:

original_value == 0 AND present_value == 0 AND new_value != 0

This is the "clean zero → nonzero" case only. Critically, if original == 0 but present != 0 (the slot was already written to non-zero earlier in the same tx), no storage gas is charged on re-write — even though the transition from the caller's perspective looks like a zero-to-non-zero write.

A reimplementer reading "zero-to-non-zero" could reasonably implement present == 0 && new != 0 (missing the original == 0 guard), which would overcharge in the original != 0, present == 0, new != 0 case (slot cleared then re-set within the same tx).

Suggestion: State the exact triple condition:

Only when original_value == 0 AND present_value == 0 AND new_value != 0 (using EIP-2200 terminology: original is the value at transaction start, present is the current value in the journal).

- [Rex1](upgrades/rex1.md)
- [Rex2](upgrades/rex2.md)
- [Rex3](upgrades/rex3.md)
- [Rex4](upgrades/rex4.md)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a Glossary page to the book.

Terms like "compute gas", "storage gas", "SALT bucket", "volatile data", "gas detention", "multiplier", "frame-local", "resource dimension", "detained limit" are used throughout the docs but never formally defined in one place.

For a dapp developer new to MegaETH, these terms appear without introduction — especially "SALT bucket" and "gas detention" which have no equivalent in vanilla Ethereum. A glossary gives them a single place to look up unfamiliar terms without hunting through multiple pages.

For a chain developer reimplementing mega-evm, a glossary establishes canonical terminology — avoiding ambiguity when the same concept is described slightly differently across pages (e.g., "remaining gas is preserved" vs "excess gas is refunded" vs "detained gas is returned").

Suggestion:

## Reference

- [Glossary](glossary.md)

# Current EVM Standard

This page describes the current MegaETH EVM behavior as a single reference.
It reflects the latest spec (Rex4) and serves as the starting point for developers building on MegaETH.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page describes Rex4 behavior, but Rex4 is the unstable spec (as noted in AGENTS.md and the Rex4 upgrade page itself). Unstable specs are under active development and their semantics may change.

A public-facing developer doc should describe the latest stable spec (Rex3) as the canonical reference. Documenting unstable behavior as "the starting point for developers building on MegaETH" risks developers building against semantics that may change before the spec is finalized.

Rex4-specific features described here that are NOT in Rex3:

  • Per-frame resource budgets (§ Per-Frame Resource Budgets)
  • Relative gas detention caps (§ Relative Cap)
  • MegaAccessControl system contract
  • MegaLimitControl system contract

Suggestion: Either

  1. Rewrite this page to reflect Rex3 (latest stable) and note Rex4 features as "upcoming", or
  2. Keep Rex4 content but add a clear warning at the top, e.g.: "This page includes features from Rex4, which is currently unstable and subject to change. The latest stable spec is Rex3."

@claude
Copy link

claude bot commented Mar 23, 2026

Final Review

All issues from prior rounds have been resolved. One item remains from the previous claude summary:

book/src/evm/README.md is missing the Rex4 unstable notice.

The page opens with 'It reflects the latest spec (Rex4)' with no caveat that Rex4 is the current unstable spec. upgrades/rex4.md correctly has the notice; this primary reference page does not. Suggest adding before the ## Base Layer heading:

> **Note**: Rex4 is the current unstable specification and is subject to change before activation.

Everything else is in good shape — the three-tier hierarchy, STYLE-GUIDE, spec rewrites, glossary, gas estimation guidance, SSTORE condition precision, and LOG revert behavior are all correct and well-documented.

This page describes the current MegaETH EVM behavior as a single reference.
It reflects the latest spec (Rex4) and serves as the starting point for developers building on MegaETH.
For incremental changes introduced by each upgrade, see the [Network Upgrades](../upgrades/README.md) section.
For deep dives on individual topics, see the linked concept pages below.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rex4 is the current unstable spec (per CLAUDE.md), but this page carries no warning. A developer landing here as their primary EVM reference won't know the semantics may change before activation.

Suggested change
For deep dives on individual topics, see the linked concept pages below.
For deep dives on individual topics, see the linked concept pages below.
> **Note**: This page reflects Rex4, which is the current unstable specification and is subject to change before activation.

- Transaction halts with `OutOfGas` error
- Remaining gas is **preserved** (not consumed), refunded to sender
- Transaction **fails** (status=0) but is **still included** in the block
- Failed transactions still count toward block limits
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rex4 introduced a third enforcement tier that's missing here: frame-local violations. When a frame-local budget is exceeded in Rex4+, the frame reverts with MegaLimitExceeded(uint8 kind, uint64 limit) rather than halting the transaction with OutOfGas. The parent frame can catch and continue.

Without this subsection, readers consulting this page in Rex4+ context will have an incomplete and misleading picture of enforcement (the current text implies all violations halt the transaction). resource-accounting.md covers this fully, but readers of resource-limits.md won't know to look there.

Suggest adding a "Frame-Level Violations (Rex4+)" subsection here, or at minimum a forward reference:

Suggested change
- Failed transactions still count toward block limits
- Failed transactions still count toward block limits
### Frame-Level Violations (Rex4+)
When a call frame exceeds its frame-local budget:
- That frame **reverts** with `MegaLimitExceeded(uint8 kind, uint64 limit)` — the transaction does **not** halt
- The parent frame can continue executing after the child reverts
- Compute gas consumed by the reverted frame still counts toward the transaction total
Transaction-level limits still apply independently; exceeding them halts the transaction with `OutOfGas`.
See [Resource Accounting](resource-accounting.md) for per-frame budget forwarding details.

| Max contract | 524,288 bytes (512 KB) |
| Max initcode | 548,864 bytes (512 KB + 24 KB) |

The contract size limit is 21× larger than standard Ethereum (24 KB); the initcode limit is ~11× larger (48 KB).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "(48 KB)" parenthetical is ambiguous — it reads as though it's MegaETH's initcode limit, but the table above already shows 548,864 bytes. The intended meaning is that the comparison baseline (standard Ethereum's initcode limit) is 48 KB. Suggest making that explicit:

Suggested change
The contract size limit is 21× larger than standard Ethereum (24 KB); the initcode limit is ~11× larger (48 KB).
The contract size limit is 21× larger than the standard Ethereum limit (24 KB); the initcode limit is ~11× larger than the standard Ethereum limit (48 KB).

@claude
Copy link

claude bot commented Mar 23, 2026

Good docs PR overall. Numbers and constants are accurate against the implementation (verified resource limits, gas detention caps, storage gas formulas, and the AGENTS.md spec progression fix). Two issues worth addressing before merge:

resource-limits.md enforcement section is incomplete for Rex4+
The "Transaction-Level Violations" section implies all limit violations halt the transaction with OutOfGas. Rex4 introduced frame-local violations that revert the frame (not halt the transaction), and the parent can continue. resource-accounting.md covers this correctly, but resource-limits.md doesn't reference it or describe this behavior at all. Left a suggestion inline.

README.md initcode limit comparison is ambiguous
"the initcode limit is ~11× larger (48 KB)" — the "(48 KB)" looks like it could be MegaETH's initcode limit, but it's actually the Ethereum standard baseline. Left a suggestion inline.

AGENTS.md change — correct. MINI_REX1/MINI_REX2 are hardforks, not specs, so removing them from the spec progression is accurate. The added clarifying sentence is helpful.

@@ -0,0 +1,195 @@
# Overview

This page describes the current MegaETH EVM behavior as a single reference.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line presents Rex4 as the current reference spec without any stability caveat. CLAUDE.md explicitly marks Rex4 as the current unstable spec under active development.

book/src/upgrades/rex4.md already has the right note — it should also appear here:

Suggested change
This page describes the current MegaETH EVM behavior as a single reference.
This page describes the current MegaETH EVM behavior as a single reference.
It reflects the latest spec (Rex4), which is currently **unstable** and subject to change before activation.
For incremental changes introduced by each upgrade, see the [Network Upgrades](../upgrades/README.md) section.

@claude
Copy link

claude bot commented Mar 23, 2026

Review

Good shape overall — the three-tier doc structure (normative spec / behavior details / impl references), STYLE-GUIDE, and GitBook scaffolding are all clean. Most prior feedback has been addressed.

One remaining issue:

book/src/evm/README.md is missing the Rex4 unstable notice (inline comment added). The upgrades/rex4.md page already has the right note; it should appear in the main EVM reference page too, since that page opens by saying it "reflects the latest spec (Rex4)" — a reader landing there will take Rex4 semantics as production-ready.

Everything else looks good to merge once that's addressed.

@claude
Copy link

claude bot commented Mar 23, 2026

Final Review

All issues from prior rounds have been resolved, including the previously-flagged remaining item:

  • book/src/evm/README.md Rex4 unstable notice is now present as a GitBook hint block after the intro paragraphs.

All key numbers verified accurate against the implementation (constants.rs): resource limits, storage gas formulas, gas detention caps, frame forwarding ratio (98/100), and the 548,864-byte initcode size fix.

The AGENTS.md spec progression correction (removing MINI_REX1/MINI_REX2 from the spec ID list, adding hardfork clarification) is correct.

Ready to merge.

@claude
Copy link

claude bot commented Mar 23, 2026

Review

Documentation-only PR. Verified numeric constants against implementation — all values match. Internal consistency between spec files, book pages, and impl is good. Spec reformatting follows the new style guide. AGENTS.md fix (removing MINI_REX1/MINI_REX2 from spec progression) is correct.

One gap to address:

In book/src/evm/README.md, the MegaAccessControl summary documents disableVolatileDataAccess() but omits enableVolatileDataAccess() and the DisabledByParent() revert. The Rex4 spec requires the interface to provide disable, enable, and status-query operations; a descendant calling enable when an ancestor has disabled it will get DisabledByParent() — that's developer-relevant behavior that belongs in this section.

Everything else looks good to merge after that fix.


### MegaLimitControl

You can query your effective remaining compute gas by calling `remainingComputeGas()`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enableVolatileDataAccess() call and its DisabledByParent() revert are omitted here. Per the Rex4 spec, the interface MUST provide disable, enable, and status-query operations, and calling enable from a descendant when an ancestor owns the restriction MUST revert with DisabledByParent(). That revert is developer-observable and should be documented alongside the disable behaviour.

Suggested change
You can query your effective remaining compute gas by calling `remainingComputeGas()`.
You can disable volatile data access for your frame and all descendant calls by calling `disableVolatileDataAccess()`.
While disabled, any volatile access reverts immediately with `VolatileDataAccessDisabled(uint8 accessType)` — no gas detention is triggered.
A descendant frame can call `enableVolatileDataAccess()`, but if the restriction was set by an ancestor the call reverts with `DisabledByParent()`.
The restriction ends automatically when the disabling frame returns.

@claude
Copy link

claude bot commented Mar 23, 2026

Review

Documentation-only PR. Numbers are accurate against the implementation (verified resource limits, storage gas formulas, gas detention caps, frame forwarding ratio, and the 548,864-byte initcode size fix). Spec doc reformatting follows the new STYLE-GUIDE. AGENTS.md spec-progression fix is correct.

One remaining gap before merge:

book/src/evm/README.md — MegaAccessControl section describes only disableVolatileDataAccess(), leaving the API appearing one-directional. enableVolatileDataAccess() and the DisabledByParent() revert when a descendant tries to override an ancestor's disable are both developer-relevant: contracts often disable-then-re-enable around a specific code path, and callers need to handle DisabledByParent() when interacting with untrusted subtrees. The full interface is documented in upgrades/rex4.md, but since evm/README.md is the primary current-behavior reference, the omission can mislead. Suggest adding two bullet points to the section:

- Call `enableVolatileDataAccess()` to lift the restriction for your frame and descendants.
- A descendant that calls `enableVolatileDataAccess()` while an ancestor's disable is active reverts with `DisabledByParent()`.


MegaETH pre-deploys system contracts at well-known addresses:

| Contract | Address | Purpose |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section only documents disableVolatileDataAccess() — the enable direction is missing. Without it the API reads as one-way, and developers need to know about DisabledByParent() when building contracts that call untrusted subtrees.

Suggested change
| Contract | Address | Purpose |
You can disable volatile data access for your frame and all descendant calls by calling `disableVolatileDataAccess()`.
While disabled, any volatile access reverts immediately with `VolatileDataAccessDisabled(uint8 accessType)` — no gas detention is triggered.
Call `enableVolatileDataAccess()` to lift the restriction for your frame and its descendants.
A descendant frame cannot re-enable access disabled by an ancestor — attempting to do so reverts with `DisabledByParent()`.
The restriction ends when the disabling frame returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api:unchanged No change to the public interface or API comp:misc Changes to the miscellaneous part of this repo spec:unchanged No change to any `mega-evm`'s behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants