Skip to content

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

Merged
Troublor merged 43 commits intomainfrom
cz/book
Mar 26, 2026
Merged

docs: add MegaEVM book docs and refactor spec docs structure#202
Troublor merged 43 commits intomainfrom
cz/book

Conversation

@RealiCZ
Copy link
Copy Markdown
Collaborator

@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
Comment thread book/src/README.md Outdated
Comment thread book/src/README.md Outdated
Comment thread book/src/evm/spec-system.md Outdated
Comment thread book/src/evm/spec-system.md Outdated
@claude
Copy link
Copy Markdown
Contributor

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.

Comment thread book/src/README.md Outdated
Comment thread docs/upgrades/rex4.md
Comment thread specs/Rex.md Outdated
Comment thread specs/MiniRex.md Outdated
@claude
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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:

Comment thread book/src/system-contracts/keyless-deploy.md Outdated
Comment thread book/src/upgrades/README.md Outdated
Comment thread specs/Rex.md Outdated
@claude
Copy link
Copy Markdown
Contributor

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.

Comment thread docs/evm/gas-detention.md
Comment thread book/src/evm/gas-detention.md Outdated
Comment thread book/src/evm/resource-accounting.md Outdated
Comment thread specs/Rex1.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 20, 2026

Review

This is a solid documentation PR — the three-file spec structure (normative / behavior-details / impl-references), the GitBook setup, and the upgrade pages are all well-organized and accurate overall. A few issues worth addressing before merge:

1. CLAUDE.md spec progression is now inconsistent with the book (should be fixed here)

CLAUDE.md line 55 still lists MINI_REX1 and MINI_REX2 in the spec progression, but those are hardforks, not spec IDs — they map back to EQUIVALENCE and MINI_REX respectively and do not appear in the MegaSpecId enum. The new book/src/evm/spec-system.md correctly explains this distinction. CLAUDE.md progression should be updated to: EQUIVALENCE → MINI_REX → REX → REX1 → REX2 → REX3 → REX4 (with a note that MiniRex1/MiniRex2 are hardforks that reuse earlier spec IDs). Since this PR introduces the hardfork-vs-spec distinction into the docs, this is the right place to fix the agent guidance file too.

2. resource-limits.md — opening count is confusing

The opening sentence says MegaETH enforces seven types of resource limits but only four are listed inline. The other three (gas limit, tx size, DA size) only appear later under Two-Phase Checking. Either list all seven upfront or drop the count.

3. gas-detention.md — step 4 wording is imprecise

Step 4 says: Pre-Rex4 (absolute cap): if compute_gas_used already exceeds the cap, execution halts with VolatileDataAccessOutOfGas. The halt occurs at the moment of volatile access, not during post-access enforcement as the current phrasing implies. Suggested: At the moment of the volatile access, if compute_gas_used already exceeds the cap, execution halts immediately with VolatileDataAccessOutOfGas. Otherwise, remaining compute gas is capped to cap minus compute_gas_used.

4. Minor: evm/README.md concept-dives table headers are swapped

The table columns are labeled Topic and Page but the data has the link in Topic and the description in Page. Should be Topic and Description.

Comment thread docs/evm/resource-limits.md
Comment thread docs/evm/gas-detention.md
Comment thread book/src/evm/README.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 20, 2026

Review

Overall the structure is solid — the normative/informative separation, STYLE-GUIDE, and impl reference files are a clear improvement over the old format. A few issues worth addressing before merge.

Rex4 unstable warning missing from the main EVM reference page

book/src/evm/README.md is titled "Current EVM Standard" and says it reflects Rex4, but Rex4 is the current unstable spec (subject to change). A developer landing on this page as their primary reference won't know that. The individual upgrades/rex4.md page has the unstable note, but the central reference page does not. Suggest adding a visible notice at the top, similar to the one in upgrades/rex4.md.

(v83) version annotation is unexplained

book/src/README.md lines 20-21 annotate the revm/op-revm versions with (v83). Readers have no context for what this means. Either add a brief explanation or remove it.

Rex4 implementation references: test file links removed

The previous Rex4-Implementation-References.md mapped each invariant to specific test files. This PR removes all of them — which is consistent with the other newly-added impl reference files (none include test links). But auditors verifying Rex4 invariants must now search test directories manually. If the intent is to keep impl references test-free across all specs, that convention should be documented in specs/STYLE-GUIDE.md so future authors follow the same approach.

Minor: MiniRex1/MiniRex2 rows in upgrades/README.md

The upgrade history table lists MiniRex1 and MiniRex2 as plain-text rows without links or explanation of why they have no dedicated pages. A note like "(no behavior change; see Spec System for hardfork-to-spec mapping)" would prevent readers from wondering if the pages are simply missing.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 20, 2026

Overall this is a solid docs restructuring — the new spec format is cleaner, the book pages are well-organized, and the AGENTS.md correction (removing MINI_REX1/MINI_REX2 from the spec progression) is accurate. Three issues to fix below.

Comment thread specs/impl/Rex4-Implementation-References.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

LGTM. Spot-checked the latest commits (cbbbc51, c5e9720): MIN_BUCKET_SIZE=256 is correct (verified against external/salt.rs), the Nick's Method background section is accurate, the Uniswap 20M gas cap reference is reasonable context, and the title rename is clean. All prior review issues remain resolved.

Session 2 — Dapp builder readability (issues 1-20):
- Clarify compute gas = standard Ethereum gas with opcode examples
- Explain gas_limit/compute gas/storage gas relationship
- Fix LOG revert behavior, EIP-7623 floor cost explanations
- Restructure Oracle interface into Public/Internal/Sequencer-Only
- Add SSTORE no-refund warning with transient storage recommendation
- Full system contract addresses, EIP-7883 ModExp note
- MiniRex1/2 expanded, timestamp lower bound, detained limit cleanup

Session 3 — Cross-reference docs/ and specs/ vs book/ (gaps G1-G12):
- Add all 7 resource limits in unified table with pre-execution limits
- Add block building workflow with skip/reject/fail/succeed semantics
- KeylessDeploy: Nick's Method background, execution flow, security
  considerations, tx format table, value transfer, nonce rationale
- Oracle: real-time data feeding lifecycle, source links
- System tx: explicit nonce handling
- Dual gas model rationale hint box

Session 4-5 — Final pre-deletion sweep (F1-F9):
- Gas detention: full beneficiary trigger list, DELEGATECALL exception
- 98/100 rule: note MiniRex limitation
- KeylessDeploy: error parameters, depth-0 rationale, gas price semantics
- Oracle forced-cold SLOAD rationale
- Contract creation storage gas charged regardless of initcode outcome
- Style rules: hint boxes for developer tips and design rationale
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

LGTM. The 085c91b commit ("comprehensive book improvements") was not covered by prior reviews — here's what's new.

What changed: Four new overview.md files created (evm/, oracle-services/, system-contracts/, upgrades/), SUMMARY.md updated to point to them. The new evm/overview.md correctly scopes to Rex3-stable with Rex4 in expandable <details> blocks — this is a solid improvement.

Three minor issues in this commit:

  1. Stale cross-linkbook/src/evm/overview.md, Oracle Forced-Cold SLOAD hint block: links to ../oracle-services/README.md but SUMMARY.md now points readers to ../oracle-services/overview.md. Should be ../oracle-services/overview.md.

  2. Orphaned README.md files — SUMMARY.md now references the overview.md variants but the old README.md files remain in all four directories and are not listed anywhere in SUMMARY.md. In GitBook v2 non-SUMMARY files are simply inaccessible via navigation. evm/README.md in particular has different content ("Current EVM Standard", Rex4-scoped) and will be silently unreachable. Consider deleting the orphaned README.md files or moving their unique content elsewhere.

  3. Rex4 warning removed from Overview.md — The {% hint style="warning" %} block was removed from book/src/Overview.md; only the inline *(unstable)* marker remains. Prior review rounds specifically added this notice. The inline marker is less visible to skimmers. Not blocking, but worth keeping consistent with the other pages that use hint blocks.

All factual content verified correct (no new numeric errors, SELFDESTRUCT correctly says "target address", initcode size is 548,864 in the new files).

Comment thread docs/CONTRIBUTING.md
**Format for each entry:**

```md
**Term** — Definition in 1–4 sentences.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The glossary template here uses bold-text format, but the actual glossary.md and the "Anchor targets must be headings" rule (added in the same file, line ~100) both require ## headings for glossary entries so that #fragment links resolve.

Suggested change
**Term** — Definition in 1–4 sentences.
## Term

Update the template to match the actual convention and the anchor rule.

Comment thread docs/evm/overview.md
Your transaction's `gas_limit` field works the same way as on Ethereum — it sets the maximum total gas you are willing to spend.
Both compute gas and storage gas are deducted from this single `gas_limit` budget.
If total gas consumed (compute + storage) exceeds `gas_limit`, the transaction runs out of gas just like on Ethereum.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Broken link — oracle-services/README.md does not exist in this PR; the file is oracle-services/overview.md.

Suggested change
**Why forced cold?** During live execution, oracle data may come from the [oracle service's external environment](../oracle-services/overview.md) rather than on-chain storage.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

Two items still unresolved from prior review rounds:

1. Broken link (blocking)book/src/evm/overview.md, Oracle Forced-Cold SLOAD hint block links to ../oracle-services/README.md, which does not exist in this PR. Should be ../oracle-services/overview.md. Inline suggestion posted.

2. Forward reference in specs/Rex3.md (minor) — The normative References section adds [Rex4 Specification](Rex4.md) pointing from a stable spec to the current unstable spec. This creates maintenance risk if Rex4 is restructured. This has been flagged in multiple prior rounds — consider moving it to a "See Also" section or removing it. (Same pattern exists in specs/Rex1.md → Rex2.)

Everything else from prior review rounds has been thoroughly addressed. The three-tier doc hierarchy, STYLE-GUIDE, book pages, glossary, hardfork-vs-spec distinction, Rex4 unstable markers, and all Troublor feedback items look good.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

Review

The PR is in good shape after many iterations. The three-tier doc hierarchy (normative spec / behavior details / impl references), GitBook setup, and book pages are consistent and accurate. All major issues from the previous human review (Rex4 unstable warning, SALT bucket explanation, glossary, gas estimation guidance, LOG revert behavior) are addressed in the current state.

One minor issue remaining (inline comment posted):

book/SITE_DOC_FORMAT.md — the Glossary template shows bold-text format for terms, but the actual glossary.md uses heading format, which is also required by the 'Anchor targets must be headings' rule defined in the same file. The template and the rule contradict each other. Update the template to match both the rule and the implementation.

Non-doc change (bin/mega-evme/src/replay/hardforks.rs): Rex3 timestamps for testnet (1771380000) and mainnet (1771639200) match the dates documented in upgrades/overview.md. Ordering constraints are respected. Looks correct.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

LGTM. All issues from prior review rounds have been addressed.

One minor note: bin/mega-evme/src/replay/hardforks.rs sets Rex3 activation timestamps (replacing ForkCondition::Never). The PR description says "documentation/spec-text focused, without runtime code changes", so this sneaked in without mention. The change itself looks correct — the timestamps match the upgrade history documented in book/src/upgrades/overview.md — but worth acknowledging explicitly.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

LGTM. All previously raised issues have been resolved:

  • Spec progression diagram corrected (hardfork vs spec distinction, MiniRex1→EQUIVALENCE rollback documented)
  • alloy-evm link fixed to alloy-rs/evm
  • Rex4 unstable caveat present throughout
  • State growth "net" qualifier explicit in specs/Rex.md
  • SELFBALANCE trigger correctly qualified ("only when the current contract is the beneficiary")
  • Per-call-frame limits elevated to top-level section in resource-accounting.md covering all four dimensions
  • Gas detention "How It Works" steps are now sequential; Rex4 delta in a separate details box
  • VolatileDataAccessOutOfGas used consistently
  • specs/Rex1.md references list Rex before Rex2

The hardforks.rs timestamps match upgrades/overview.md. No issues found.

Comment thread docs/evm/overview.md

{% hint style="info" %}
**Why forced cold?** During live execution, oracle data may come from the [oracle service's external environment](../oracle-services/README.md) rather than on-chain storage.
Replayers cannot determine which source was used, and external environment reads are inherently cold.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Broken link: ../oracle-services/README.md does not exist in this PR — the file added is oracle-services/overview.md.

Suggested change
Replayers cannot determine which source was used, and external environment reads are inherently cold.
**Why forced cold?** During live execution, oracle data may come from the [oracle service's external environment](../oracle-services/overview.md) rather than on-chain storage.

Comment thread docs/CONTRIBUTING.md

```md
**Term** — Definition in 1–4 sentences.
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The template uses bold-text format (**Term** — ...) but the actual glossary.md and the "Anchor targets must be headings" rule (line 236) both require heading format. These are inconsistent. The template should be:

Suggested change
```
### Term
Definition in 1–4 sentences.

Or, if the template is intentionally showing a different format, clarify that glossary terms specifically use ##/### headings.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

Nearly ready to merge — two remaining issues.

Blocking: broken link in book/src/evm/overview.md

The Oracle Forced-Cold SLOAD hint block links to ../oracle-services/README.md, which is not a file added by this PR. The file that was added is oracle-services/overview.md. Inline suggestion posted.

Minor: book/SITE_DOC_FORMAT.md glossary template contradicts anchor rule

The "Format for each entry" template on line 265 shows bold-text format (**Term** — ...), but the "Anchor targets must be headings" rule on line 236 requires heading format, and the actual glossary.md correctly uses ## Term headings. The template should match the rule and implementation. Inline suggestion posted.

Everything else from prior review rounds has been thoroughly addressed — Rex4 correctly placed in its own "Upcoming (Unstable)" section, stable upgrade history in the {% updates %} block, all numeric constants verified, glossary complete, hardfork-vs-spec distinction clear throughout.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

All previously raised issues have been addressed — spec progression diagram, alloy-evm link, Rex4 unstable caveat, SELFBALANCE qualification, net state growth, per-frame limits scope, gas detention steps, and error name consistency all look correct now.

Two new items:

1. Runtime code change not mentioned in PR description (bin/mega-evme/src/replay/hardforks.rs)

The PR description says "Keep this PR documentation/spec-text focused, without runtime code changes" but this PR changes Rex3 from ForkCondition::Never to actual timestamps on both testnet (1771380000) and mainnet (1771639200). This is a correct and expected change (Rex3 is documented as activated), but it should be acknowledged — nodes pulling this update will activate Rex3.

2. calldata changed to memory in docs/ORACLE_SERVICE.md

The PR changes getSlots and setSlots parameter locations from calldata to memory, and adds sendHint with bytes memory data. The actual Oracle.sol uses calldata throughout, and the new book/src/system-contracts/oracle.md (also in this PR) correctly uses calldata. The legacy docs file should match.

Comment thread docs/ORACLE_SERVICE.md Outdated
/// @param slots Array of storage slots to read from
/// @return values Array of bytes32 values at corresponding slots
function getSlots(uint256[] calldata slots)
function getSlots(uint256[] memory slots)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These parameter locations were changed from calldata to memory, but Oracle.sol uses calldata and so does the new book/src/system-contracts/oracle.md (also in this PR). Should stay consistent:

Suggested change
function getSlots(uint256[] memory slots)
function getSlots(uint256[] calldata slots)

- Rename book/ to docs/, remove src/ nesting for idiomatic GitBook structure
- Delete old docs/ (internal docs) and specs/ directories
- Rename Overview.md -> overview.md, SUMMARY.md -> toc.md, SITE_DOC_FORMAT.md -> CONTRIBUTING.md
- Add GitBook skill.md reference to CONTRIBUTING.md
- Update all cross-references in AGENTS.md, README.md, ARCH.md, upgrade pages, and source comments
Comment on lines 490 to +491
- [Project Architecture](../../../../ARCH.md)
- [Development Guide](../../../../DEV.md)
- [Main README](../../../../README.md)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicate entry: the replacement for [Development Guide] landed on top of the existing [Main README] line, leaving two identical entries. Remove one.

Suggested change
- [Project Architecture](../../../../ARCH.md)
- [Development Guide](../../../../DEV.md)
- [Main README](../../../../README.md)
- [Main README](../../../../README.md)

Comment thread docs/CONTRIBUTING.md

This file defines conventions and rules for writing and editing the public-facing book (`docs/`), hosted via GitBook.

For GitBook markdown syntax, custom blocks, configuration files, and best practices, refer to the [GitBook skill.md](https://gitbook.com/docs/skill.md).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

https://gitbook.com/docs/skill.md is not a real URL — the actual GitBook documentation is at https://docs.gitbook.com. Either fix the link or just omit the reference; the sentence adds little value since CONTRIBUTING.md already is the conventions document.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 26, 2026

Two small issues in the latest commits; everything else from prior reviews looks addressed.

  1. Duplicate link in bin/mega-evme/src/run/README.md — replacing [Development Guide] with [Main README] introduced a duplicate since the original [Main README] entry was already present. See inline comment.

  2. Fabricated URL in docs/CONTRIBUTING.mdhttps://gitbook.com/docs/skill.md is not a real page. The real GitBook docs are at https://docs.gitbook.com. See inline comment.

@Troublor Troublor merged commit 3204281 into main Mar 26, 2026
37 checks passed
@Troublor Troublor deleted the cz/book branch March 26, 2026 06:39
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