Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
45586da
feat: add coverage-replayer bin (M1: backfill, set-cover, report)
flyq Jul 8, 2026
7491e8d
fix: unique tmp names in write_atomic, scope llvm-cov report to mega-…
flyq Jul 8, 2026
935befc
feat(stateless-core): zero-validation light decode of witness bytes
flyq Jul 8, 2026
e77b148
refactor(witness): drop raw witness storage; re-fetch full witnesses …
flyq Jul 8, 2026
f38c2d4
upload server run M1 result
Jul 8, 2026
93945a2
feat(coverage-replayer): read-only inspect subcommand for store analysis
flyq Jul 8, 2026
58fa9dc
refactor(coverage-replayer): archive only sparse profdata, drop entri…
flyq Jul 8, 2026
9710c61
run 100k
Jul 9, 2026
b3b7ebc
feat(coverage-replayer): inspect gains growth buckets, antichain esti…
flyq Jul 9, 2026
902912d
update
Jul 9, 2026
d63d7ff
feat(coverage-replayer): dominated-pattern archive rejection + antich…
flyq Jul 9, 2026
15dc086
Merge branch 'liquan/coverage-replayer-design' of https://github.com/…
flyq Jul 9, 2026
db58a11
add R2
flyq Jul 9, 2026
5b6d815
add log
flyq Jul 9, 2026
e4902e8
300k blocks
Jul 9, 2026
af8ac96
feat(coverage-replayer): stable binary_id, lightest-block representat…
flyq Jul 9, 2026
628e88f
feat(coverage-replayer): merge subcommand for 4-machine sharded scans
flyq Jul 9, 2026
2fc2040
simplify
flyq Jul 10, 2026
74516fe
chore: untrack validator-data design doc (maintained locally, dir is …
flyq Jul 10, 2026
264ae8d
refactor: rehome megaeth-witness-r2 as crates/stateless-r2
flyq Jul 10, 2026
f9145a4
review & fix
flyq Jul 10, 2026
a1691d0
simplify
flyq Jul 10, 2026
7301100
feat(coverage-replayer): never skip a block — retry-forever fetch, no…
flyq Jul 11, 2026
4e91a79
feat: add R2 witness fetch metrics, happy-path decode test, review fixes
flyq Jul 11, 2026
22e11de
perf(debug-trace-server): light-decode witnesses on both RPC paths
flyq Jul 11, 2026
42cdce2
Merge remote-tracking branch 'origin/r2-witness-validation' into liqu…
flyq Jul 11, 2026
91e998a
chore: drop coverage run data from git; ignore /data/
flyq Jul 11, 2026
a8f58cf
chore: untrack stray profraw, ignore *.profraw
flyq Jul 11, 2026
9067271
feat(coverage-replayer): R2 witness source on the light-decode path
flyq Jul 11, 2026
d60e1f4
fix: address PR #153 review findings
flyq Jul 11, 2026
9de1ae9
fix(stateless-core): import vec! in light_witness tests for no_std bu…
flyq Jul 11, 2026
6b833c0
refactor: /simplify pass — dedup algorithm cores, shared helpers, hot…
flyq Jul 11, 2026
48ac2f3
fix: honor witness concurrency cap in R2 mode and report final tip be…
flyq Jul 11, 2026
b66c2c7
fix: retry the final validation report, fix rustdoc warnings
flyq Jul 11, 2026
96074e7
docs: tighten overlong comments across the R2 witness changes
flyq Jul 11, 2026
f8359a6
fix: harden coverage-replayer for unattended full-history scans
flyq Jul 11, 2026
6bf71fb
merge: pull latest r2-witness-validation (PR #152) updates
flyq Jul 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
.mcp.json

# database
validator-data
validator-data

# coverage-replayer run data & artifacts (transferred out-of-band, never via git)
/data/
*.profraw
*.pid
*.log
52 changes: 27 additions & 25 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This file provides guidance to AI agents (e.g., Claude Code, Codex, Cursor, etc.
## Project Overview

Stateless validator for MegaETH — validates blocks using SALT witness data without requiring full chain state.
The workspace contains two binaries: `stateless-validator` (chain-following validator) and `debug-trace-server` (RPC server for debug/trace methods).
The workspace contains three binaries: `stateless-validator` (chain-following validator), `debug-trace-server` (RPC server for debug/trace methods), and `coverage-replayer` (offline tool that derives the minimal mainnet block set maximizing mega-evm branch coverage).
See `README.md` for detailed documentation and quickstart.

## Build & Development Commands
Expand Down Expand Up @@ -34,14 +34,16 @@ The project uses nightly `2026-02-03` toolchain (edition 2024, rust-version 1.95

## Workspace Structure

| Crate | Path | Purpose |
| ---------------------- | ----------------------------- | ------------------------------------------------------------------------------------------ |
| `stateless-core` | `crates/stateless-core` | Storage traits, pipeline, EVM execution, SALT witness handling, chain spec, error types |
| `stateless-db` | `crates/stateless-db` | redb-backed persistence: table definitions, read/write helpers, `ContractCache` |
| `stateless-common` | `crates/stateless-common` | RPC client, metrics/logging utilities, witness size estimation |
| `stateless-test-utils` | `crates/stateless-test-utils` | Test fixtures (blocks, witnesses, contracts) and env-var lock for integration tests |
| `stateless-validator` | `bin/stateless-validator` | Main binary: chain sync, parallel validation workers (`app.rs` / `workers.rs` / `main.rs`) |
| `debug-trace-server` | `bin/debug-trace-server` | Standalone RPC server for debug/trace methods |
| Crate | Path | Purpose |
| ---------------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `stateless-core` | `crates/stateless-core` | Storage traits, pipeline, EVM execution, SALT witness handling, chain spec, error types |
| `stateless-db` | `crates/stateless-db` | redb-backed persistence: table definitions, read/write helpers, `ContractCache` |
| `stateless-common` | `crates/stateless-common` | RPC client, metrics/logging utilities, witness size estimation |
| `stateless-test-utils` | `crates/stateless-test-utils` | Test fixtures (blocks, witnesses, contracts) and env-var lock for integration tests |
| `stateless-r2` | `crates/stateless-r2` | Shared R2 (S3) witness primitives: SigV4 signer, object-key layout, endpoint parsing, signed PUT; consumed by mega-reth's uploaders (write) and the validator's R2 witness source (read) |
| `stateless-validator` | `bin/stateless-validator` | Main binary: chain sync, parallel validation workers (`app.rs` / `workers.rs` / `main.rs`) |
| `debug-trace-server` | `bin/debug-trace-server` | Standalone RPC server for debug/trace methods |
| `coverage-replayer` | `bin/coverage-replayer` | Offline coverage tool: replays blocks under LLVM branch instrumentation (`backfill`), dedups per-block coverage bitmaps into patterns, and computes the minimal covering block set (`set-cover` / `report` / `inspect` / `merge`). Requires the instrumented `[profile.coverage]` build |

Additional directories: `test_data/` (integration test fixtures including genesis config), `audits/` (security audit reports).

Expand Down Expand Up @@ -109,26 +111,26 @@ The server includes an HTTP response cache (`quick_cache`) for pre-serialized JS

### Key Source Files

| File | Purpose |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `crates/stateless-core/src/pipeline/{mod,config,traits,fetcher,divergence,advancer,worker}.rs` | Generic three-stage pipeline split by responsibility |
| `crates/stateless-core/src/executor.rs` | Block validation and EVM replay (generic over the `BlockInput` projection) |
| `crates/stateless-core/src/evm_database.rs` | WitnessDatabase implementing `revm::DatabaseRef` |
| `crates/stateless-core/src/db.rs` | Shared storage traits (`ContractStore`, `ChainStore`) + `StoreError` / `StoreResult` |
| `crates/stateless-core/src/withdrawals.rs` | Withdrawal validation and MPT witness handling |
| `crates/stateless-db/src/{lib,tables,helpers,serialize,cache}.rs` | Shared redb tables, helpers, serialization, and `ContractCache` |
| `crates/stateless-common/src/rpc_client.rs` | RPC client for blocks, witnesses, and bytecode |
| `crates/stateless-common/src/metrics.rs` | RpcMethod, RpcMetrics, RpcClientConfig |
| `bin/stateless-validator/src/{main,app,workers,chain_sync,validator_db,metrics}.rs` | Thin entry, CLI/startup wiring, pipeline+reporter, fetcher/processor, DB |
| `bin/debug-trace-server/src/chain_sync.rs` | TraceFetcher, TraceProcessor, TraceHooks |
| `bin/debug-trace-server/src/rpc_service.rs` | RPC method definitions and handlers |
| `bin/debug-trace-server/src/data_provider.rs` | Block data fetching with single-flight coalescing |
| `bin/debug-trace-server/src/server_db.rs` | Defines + implements the bin-local `BlockStore` trait (backed by `stateless-db`) |
| File | Purpose |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `crates/stateless-core/src/pipeline/{mod,config,traits,fetcher,divergence,advancer,worker}.rs` | Generic three-stage pipeline split by responsibility |
| `crates/stateless-core/src/executor.rs` | Block validation and EVM replay (generic over the `BlockInput` projection) |
| `crates/stateless-core/src/evm_database.rs` | WitnessDatabase implementing `revm::DatabaseRef` |
| `crates/stateless-core/src/db.rs` | Shared storage traits (`ContractStore`, `ChainStore`) + `StoreError` / `StoreResult` |
| `crates/stateless-core/src/withdrawals.rs` | Withdrawal validation and MPT witness handling |
| `crates/stateless-db/src/{lib,tables,helpers,serialize,cache}.rs` | Shared redb tables, helpers, serialization, and `ContractCache` |
| `crates/stateless-common/src/rpc_client.rs` | RPC client for blocks, witnesses, and bytecode |
| `crates/stateless-common/src/metrics.rs` | RpcMethod, RpcMetrics, RpcClientConfig |
| `bin/stateless-validator/src/{main,app,workers,chain_sync,validator_db,metrics}.rs` | Thin entry, CLI/startup wiring, pipeline+reporter, fetcher/processor, DB |
| `bin/debug-trace-server/src/chain_sync.rs` | TraceFetcher, TraceProcessor, TraceHooks |
| `bin/debug-trace-server/src/rpc_service.rs` | RPC method definitions and handlers |
| `bin/debug-trace-server/src/data_provider.rs` | Block data fetching with single-flight coalescing |
| `bin/debug-trace-server/src/server_db.rs` | Defines + implements the bin-local `BlockStore` trait (backed by `stateless-db`) |

## Test Organization

Unit tests are embedded in source files alongside the code they test.
Integration tests live in `bin/debug-trace-server/tests/` (6 modules: cache_metrics, block_tag, consistency, performance, timing_header, prune) and in `bin/stateless-validator/tests/integration.rs` (CLI parsing, mock-RPC pipeline, mainnet single-block validation).
Integration tests live in `bin/debug-trace-server/tests/` (5 modules: cache_metrics, block_tag, consistency, performance, timing_header), in `bin/stateless-validator/tests/integration.rs` (CLI parsing, mock-RPC pipeline, mainnet single-block validation), and in `bin/coverage-replayer/tests/replay_fixtures.rs` (worker replay glue over the `test_data/mainnet` fixtures).
Test data (block JSON files, contract bytecode, witness data) is stored in `test_data/`.

## Version Control
Expand Down
93 changes: 54 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[workspace]
members = [
"bin/coverage-replayer",
"bin/debug-trace-server",
"bin/stateless-validator",
"crates/stateless-common",
"crates/stateless-core",
"crates/stateless-db",
"crates/stateless-r2",
"crates/stateless-test-utils",
]
resolver = "2"
Expand Down Expand Up @@ -62,6 +64,7 @@ revm-inspectors = { version = "0.27.3", features = ["std", "js-tracer"], default
base64 = { version = "0.22", default-features = false }
bincode = { version = "2.0", features = ["serde", "alloc"], default-features = false }
bytes = "1.11"
chrono = { version = "0.4", default-features = false }
clap = { version = "4.6", features = ["derive", "env", "std"], default-features = false }
dashmap = { version = "6.1", default-features = false }
dotenvy = "0.15"
Expand All @@ -70,6 +73,8 @@ eyre = { version = "0.6", features = ["auto-install"], default-features = false
fastrand = { version = "2.4", default-features = false }
futures = { version = "0.3", default-features = false }
hashbrown = { version = "0.16", default-features = false }
hex = { version = "0.4", default-features = false }
hmac = { version = "0.12", default-features = false }
http = "1.4"
http-body = "1.0"
http-body-util = "0.1"
Expand All @@ -82,15 +87,17 @@ metrics = "0.24"
metrics-derive = "0.1"
metrics-exporter-prometheus = { version = "0.18", features = ["http-listener"], default-features = false }
num_cpus = "1.17"
percent-encoding = { version = "2.3", default-features = false }
pin-project-lite = "0.2"
quick_cache = { version = "0.6", default-features = false }
rayon = "1.11"
redb = "4.0"
reqwest = { version = "0.13", features = ["json", "blocking"], default-features = false }
reqwest = { version = "0.12", default-features = false }
rolling-file = "0.2"
rustc-hash = { version = "2.1", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
sha2 = { version = "0.10", default-features = false }
tempfile = { version = "3.27", default-features = false }
thiserror = { version = "2.0", default-features = false }
tokio = { version = "1.51", features = ["rt-multi-thread", "signal"], default-features = false }
Expand All @@ -113,3 +120,18 @@ opt-level = 3
debug-assertions = true
incremental = true
debug = true

# Instrumented builds for coverage-replayer: coverage only cares about "was it
# executed", so trade peak runtime speed for much faster builds (no LTO, many
# codegen units). Do NOT add `-C link-dead-code` (it monomorphizes dead generic
# code and fails const-eval asserts in revm). Pass an explicit --target so
# RUSTFLAGS skips host artifacts (otherwise instrumented proc-macros make every
# rustc invocation drop default_*.profraw files into the cwd). Build with:
# RUSTFLAGS="-C instrument-coverage -Z coverage-options=branch" \
# cargo build --profile coverage -p coverage-replayer --features coverage \
# --target "$(rustc -vV | sed -n 's/host: //p')"
[profile.coverage]
inherits = "release"
opt-level = 2
lto = "off"
codegen-units = 16
Loading
Loading