Skip to content

docs(node): add stateless validator architecture guide#46

Merged
flyq merged 15 commits intomainfrom
liquan/doc/stateless-validator-architecture
May 9, 2026
Merged

docs(node): add stateless validator architecture guide#46
flyq merged 15 commits intomainfrom
liquan/doc/stateless-validator-architecture

Conversation

@flyq
Copy link
Copy Markdown
Member

@flyq flyq commented May 6, 2026

Summary

Adds an implementer-facing architecture and walkthrough for building a MegaETH-compatible stateless validator from scratch — aimed at external teams porting the validator to a different language or EVM stack.

The new page lives at docs/node/validator-architecture.md and slots under Stateless Validation (peer to Get Block Witness).
It links to the operator guide and witness wire-format reference rather than duplicating their content.

Covers:

  • Three-stage pipeline (fetch → workers → advancer) and component responsibilities, with upstream path:line references
  • Eleven-step per-block validation pipeline: fetch → decode → IPA verify → witness-backed read backend → bytecode resolution → replay → pre/post system writes → withdrawals MPT → SALT root recompute → header comparisons → advance/reorg
  • Three-state witness security model (Some(value) / Some(None) / absent) and the anti-omission rule
  • Re-execution requirements with absolute spec links (dual gas model, resource limits, system contracts, precompiles, volatile data)
  • Trust model recap and a reference-implementation crate map

Test plan

  • GitBook preview renders the {% stepper %}, {% hint %}, and table blocks correctly
  • Relative .md links resolve: witness.md, stateless-validation.md, ../architecture.md, ../dev/execution/volatile-data.md
  • Absolute https://docs.megaeth.com/spec/... links resolve on the published site
  • GitHub permalinks (...#L<N>) point to the cited symbols on main

@flyq flyq requested review from Troublor and nnsgmsone as code owners May 6, 2026 15:17
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

Review

Layer boundary — the page's stated audience conflicts with where it lives.

The opening line is: "It is written for engineers building a compatible validator from scratch — in another language, against a different EVM stack."
But docs/node/ targets node operators running the upstream Rust client (see docs/node/AGENTS.md), and its What Does NOT Belong Here list explicitly calls this out:

Internal architecture of the validator crate (module layout, trait design) → the upstream repo README.

This page covers exactly that: the three-stage pipeline diagram, per-component crate references, 11-step validate_block internals, WitnessDatabase trait surface, and the full Cargo workspace crate map.

The suggested home from the AGENTS.md is the upstream stateless-validator repo README (or a docs/ page there). If the intent is to keep this content in the docs site, the right layer would be a new docs/dev/ page (implementers, not operators), and docs/node/AGENTS.md would need to be updated to allow it.

One minor issue noted inline below.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

docs/node/validator-architecture.md, line 251 — inline commenting is failing due to a GitHub API error, so noting here:

trust-minimized is explicitly on the banned-terms list in docs/node/AGENTS.md (alongside "honest" and "fastest"). Suggested replacement:

To independently verify the canonical chain from L1, pair it with op-node and a MegaETH replica that derive canonicality from L1 — see Stateless Validation > Trust model.

Copy link
Copy Markdown
Contributor

@nnsgmsone nnsgmsone left a comment

Choose a reason for hiding this comment

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

lgtm

Add a Genesis configuration section to the validator architecture
guide. Spell out that the validator extracts only chain_id and the
hardfork schedule (Ethereum, OP-Stack, MegaETH) from the genesis
JSON, with file:line references into chain_spec.rs. Note the fields
that are loaded but not consumed (alloc, gasLimit, baseFeePerGas, ...)
and warn that any divergence in hardfork timestamps surfaces only as
a state_root mismatch.

Tighten the Trust model section to list the two startup trust
inputs (genesis JSON, anchor block hash) explicitly.
Comment thread docs/node/validator-architecture.md
Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 8, 2026

Good addition overall — the content is accurate, well-sourced with upstream line references, and the stepper structure maps cleanly to the pipeline. All relative and anchor links resolve correctly (witness.md#decoding-pipeline, #saltvalue, stateless-validation.md#useful-metrics, #trust-model). Four issues to address before merge:

  1. Steps 6 and 7 ordering (correctness) — Step 7 says to apply pre-block hooks "before the first transaction," but it comes after the replay step in the numbered sequence. An implementer following the steps in order will apply hooks after replay. See inline comment.

  2. Rex1-5 / MiniRex1-2 fork names — Range shorthands that may imply forks not in the approved terminology list (Rex1-4 per docs/AGENTS.md). See inline comment on the genesis table.

  3. eth_getCodeByHash undocumented — Not a standard method; no reference to its spec or RPC docs. See inline comment on step 5.

  4. "trust-minimized" language — Prohibited by node/AGENTS.md. See inline comment on line 280.

- Reorder validation steps so pre-execution system updates come
  before transaction replay and post-execution updates come after,
  matching the actual execution order an implementer must follow.
- Drop the Rex1-5 / MiniRex1-2 range shorthands and list each fork
  individually (MiniRex, MiniRex1, MiniRex2, Rex, Rex1-Rex4) per the
  canonical terminology table in docs/AGENTS.md.
- Note that eth_getCodeByHash is a MegaETH RPC extension and call
  out the eth_getCode fallback path for endpoints that do not
  implement it.
- Replace 'fully trust-minimized' (banned in docs/node/AGENTS.md)
  with neutral wording about deriving canonicality from L1.
Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md
Comment thread docs/node/validator-architecture.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 8, 2026

Review

The page is well-structured and technically thorough for its target audience (re-implementers). Previous rounds of feedback on step ordering, fork names, eth_getCodeByHash documentation, and marketing language are all resolved.

Two threads from the previous round remain open — fix before merging:

  1. Wrong step reference (thread on line 237): The "Compare every header commitment" table says withdrawals_root comes from "step 8", but the withdrawals MPT step is step 9. Should read "step 9".

  2. Unapproved fork names (thread on line 39): MiniRex1 and MiniRex2 are not in the approved terminology table in docs/AGENTS.md (which lists MiniRex, Rex, Rex1, Rex2, Rex3, Rex4). Either confirm these are real fork names and add them to the terminology table, or remove them.

New comment: Precompiles row (line 269) — "if any" leaves re-implementers without a definitive answer about what to build. Needs a concrete statement.

- Fix step reference in the header-commitment table:
  withdrawals_root is recomputed in step 9 (Update the withdrawals
  MPT), not step 8. The numbering shifted when pre/post-execution
  system updates were split into separate steps.
- Add MiniRex1 and MiniRex2 to the canonical spec-name list in
  docs/AGENTS.md. Both are real hardforks defined in
  crates/stateless-core/src/chain_spec.rs (mini_rex_1_time,
  mini_rex_2_time) with activation timestamps in the mainnet
  genesis.
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 8, 2026

Review update — round 2

Good progress on the previous round. Most threads are now addressed.

Resolved this round:

  • withdrawals_root step reference now correctly says "step 9" ✓
  • MiniRex1/MiniRex2 added to the docs/AGENTS.md terminology table ✓

Still open:

  • Thread on the precompiles row: the "if any" qualifier (thread PRRT_kwDOODfgX86Aix43) is still unresolved. Either confirm no MegaETH-specific precompiles exist beyond the standard set and say so explicitly, or list them. Leaving "if any" makes the row unhelpful to implementers.

Everything else looks good — the 12-step pipeline is correctly ordered, the architecture.md link is valid, and the SALT encoding table and trust model section are clear.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 8, 2026

All six previous threads have been addressed. The precompiles row no longer says "if any" — it now specifies the OP-Stack Isthmus set with MegaETH gas-cost overrides and links to the spec — so I've resolved that last thread.

The content is solid: step ordering is correct, MiniRex1/MiniRex2 are added to the terminology table, eth_getCodeByHash is labelled as a MegaETH RPC extension, and the trust-model section avoids marketing language. One thing worth a follow-up (not a blocker): docs/node/AGENTS.md says the node layer targets operators of the upstream client, but this page targets re-implementers building a compatible validator from scratch. The AGENTS.md "What Does NOT Belong Here" note about internal architecture doesn't apply here (this is a protocol-compliance guide, not a crate-layout doc), but it would be worth adding a sentence to docs/node/AGENTS.md clarifying that re-implementer guides are also in scope for this layer.

Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 8, 2026

Good shape overall — previous round of feedback is all addressed. Two threads remain open before this is ready:

1. Rex5 not in the terminology table (thread): Rex5 is used in step 6 (and the genesis hardfork list on the same page omits it), but docs/AGENTS.md stops at Rex4. Either add Rex5 to the Correct column alongside the MiniRex1/MiniRex2 additions made in this PR, or replace the fork name if the canonical name differs.

2. Two sentences on one line (thread): The Block canonicity bullet (line 341) puts two sentences on one line, violating the one-sentence-per-line rule in docs/AGENTS.md. The suggested split in the thread is correct.

Everything else looks good — links resolve (../architecture.md, ../dev/execution/volatile-data.md, relative node pages), the stepper/hint/table blocks render cleanly in the diff, and the content is accurate to the reference implementation.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 8, 2026

All previously open threads are now resolved — Rex5 was dropped and the two-sentence line was split per the suggestions.

The content is technically thorough and well-structured. A few minor things worth a pass before merge:

  • Step 6, pre-execution hooks list: MiniRex1, MiniRex2, Rex, Rex1, Rex3 are absent from the per-hardfork system-contract bullet list. Either those forks deploy nothing (worth a brief "no new system contracts" note) or they were omitted by accident.
  • Line 117: "The current implementation of stateless validator is..." — missing article, should be "the stateless validator".
  • Genesis section: The file path reference in the store_genesis hint block uses a line anchor (#L88). If that line moves in the upstream repo, the link silently goes stale. Consider whether a function-anchor or prose description is more durable here (same applies to the other #L links throughout).

Nothing blocking. The core pipeline doc is accurate and the spec links are correct.

- Fix grammar: 'implementation of stateless validator' →
  'implementation of the stateless validator' (missing article).
- List the MegaETH forks that deploy no system contracts (MiniRex1,
  MiniRex2, Rex, Rex1, Rex3) so the per-hardfork hook list is
  exhaustive. Verified against
  mega-evm/crates/mega-evm/src/block/executor.rs (only MiniRex,
  Rex2, Rex4 install contracts in pre_execution_changes).
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 9, 2026

All nine previous threads are resolved. The document is technically solid — previous fixes confirmed:

  • eth_getCodeByHash now identified as a MegaETH RPC extension (inline description added)
  • MiniRex1, MiniRex2 added to the spec-name terminology table in docs/AGENTS.md
  • withdrawals_root header row correctly cites step 9
  • Pre-execution hook step (6) comes before replay (7); post-execution (8) after — ordering is correct
  • trust-minimized language removed; block-canonicity note is clean
  • Rex5 removed from the document
  • One sentence per line throughout

One minor note, not a blocker: the Related pages footer labels the dual-gas-model spec page as [Specification](...). That label implies a spec root; something like [Specification — Dual Gas Model](...) would be more precise. Fine to leave as-is if the intent is just a spec entry point.

The link goes to the Dual Gas Model spec page, not the spec root,
so 'Specification' alone misled readers. Use 'MegaEVM specification
— Dual Gas Model' on both the inline reference (re-execution
section) and in Related pages, and note that the linked page is the
entry point into the spec space.
Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md Outdated
The '— MegaETH is iterating quickly, ...' clause is removed; the
bolded imperative carries the message on its own.
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 9, 2026

All previous review threads are now resolved. The three remaining formatting issues (two sentences on one line in the MiniRex bullet, anchor block hash bullet, and salt crate entry) have been addressed in the latest revision. No new issues found. LGTM.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 9, 2026

All 12 prior threads are resolved. The document reads cleanly — pipeline ordering, step references, fork-name terminology, one-sentence-per-line, and the precompiles/eth_getCodeByHash clarifications all look correct.

LGTM.

Comment thread docs/node/validator-architecture.md Outdated
Comment thread docs/node/validator-architecture.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 9, 2026

All 12 threads from the previous review round are resolved. Two minor issues remain.

Line 88 — missing link in architecture table. The Contract cache row in the Reference Architecture table is the only component without a hyperlink. The three other rows all link to specific files/lines in the reference implementation.

Line 313 — baseline understated. The Re-execution requirements section opens with "standard Cancun/Shanghai semantics", but MegaETH's floor is OP-Stack Isthmus. Isthmus adds deposit transactions, EIP-7002, and EIP-7251 — none of which are in vanilla Cancun. An implementer who stops at Cancun will silently miss those behaviors. Suggested fix: "OP-Stack Isthmus semantics (the floor for MegaETH)".

Content, structure, and formatting otherwise look solid: step ordering is correct, step references in the intro match the stepper, SALT encoding table arithmetic checks out, terminology aligns with the updated AGENTS.md, and one-sentence-per-line is consistently applied.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 9, 2026

All previous threads are resolved. LGTM.

Checklist against REVIEW.md:

  • ✅ YAML frontmatter with description field present
  • ✅ New page listed in docs/SUMMARY.md under Stateless Validation (peer to Get Block Witness)
  • ✅ Internal links use relative .md paths; external spec links use absolute https://docs.megaeth.com/spec/... URLs
  • ✅ One sentence per line throughout
  • {% stepper %}, {% step %}, {% hint %} blocks correctly opened and closed
  • docs/AGENTS.md terminology table updated to include MiniRex1, MiniRex2
  • ✅ Precompiles row now points to the spec page with a clear description rather than the vague "if any"
  • ✅ Re-execution baseline correctly states OP-Stack Isthmus (not Cancun/Shanghai)
  • ✅ Step ordering: pre-execution (step 6) → replay (step 7) → post-execution (step 8) is correct
  • withdrawals_root header table references step 9, not step 8

@flyq flyq merged commit b0b06ab into main May 9, 2026
5 checks passed
@flyq flyq deleted the liquan/doc/stateless-validator-architecture branch May 9, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants