Skip to content

refactor(ciphernode): optimize v2 storage, p2p, proving, and runtime - #2547

Closed
hmzakhalid wants to merge 6 commits into
refactor/ciphernode-v2from
perf/ciphernode-v2-architecture
Closed

hmzakhalid wants to merge 6 commits into
refactor/ciphernode-v2from
perf/ciphernode-v2-architecture

Conversation

@hmzakhalid

Copy link
Copy Markdown
Collaborator

What and why

Architectural and performance optimizations for Ciphernode V2 across proving, storage, protocol state transitions, P2P transport, chain I/O, runtime event handling, and HTTP hardening, without changing ENCODING_VERSION = 1 durable layouts or protocol/circuit semantics:

  • Prover & witness pipeline (e3-zk-prover): File-stamp cached ParsedCircuit and VkArtifacts / vk_tree_hash, exponential 1ms → 50ms bb exit polling, and exported per-step recursive fold helpers (generate_c3_fold_step, generate_c6_fold_step, prove_c2ab_fold, prove_c3ab_fold, prove_c4ab_fold, prove_node_fold_final, prove_decryption_aggregator_with_c6_fold).
  • Blob store & journal (e3-blobs, e3-engine, e3-journal): Bounded 64 MiB zero-copy PublicCache (Arc<[u8]>), put_verified_batch (single sync_dir per batch), bounded Closing::closed, atomic group-commit Engine::apply_batch / Journal::commit_batch (up to 128 ops per redb transaction), and non-durable Effect::Note skipping journal writes.
  • Protocol (e3-protocol): Zero-allocation [u8; 116] ticket scoring, u128 bitmask + (H-1)-core clique selection for N ≤ 128, extracted O(1)-indexed Hold / Ended preserving exact bincode layout, admits_state fast path avoiding redundant ECDSA re-verification after blob fetch, Registry::prune_before, admission_epoch, and Node::might_fold.
  • Jobs & proving scheduler (e3-jobs): Priority ProveGate (Foreground vs Background) with dynamic HARDWARE_CONCURRENCY thread budgeting, single-flight per-step fold checkpointing, cached BFV profiles/CRPs, separated check_pool preventing proving jobs from starving checks/BFV math, parallel verification & decryption, and multi-slot (max_concurrent >= 2) speculative DKG pre-folding cancelled immediately on Phase::Observing.
  • P2P (e3-p2p): Compact binary length-prefixed blobs/2 batching (up to 16 blobs, zero-copy Arc<[u8]>, no CBOR), pairwise direct/1 delivery for Shares with gossipsub fallback, connection-cached (PeerId ↔ Address) PeerProof verification, merged deduplicated sources, and NetworkStats.
  • Chain, runtime, & daemon HTTP (e3-chain, e3-node, e3-daemon-server): Single-scan Account::key_chunks, bounded concurrent key-chunk publishing (8), 1-RPC Wallet::estimate when confirmations == 0, concurrent Reader::read & bounded block-timestamp cache, offloaded spawn_blocking journal group-commit/cleanup/checkpointing, Prometheus GET /metrics, and bounded HTTP body/headers/timeout on daemon server.

Moonstone Benchmarks (Baseline 31cd408ea vs. Optimized)

5-node multi-process E2E on Moonstone (Ryzen 5 7535U, 6C/12T, 28 GiB RAM, Minimum committee N=3, H=2):

Benchmark Baseline Optimized Delta / Speedup
Mock E2E post-finalization DKG (CommitteeFinalized → KeyPublished) 3.03 s 2.02 s -33.3% (1.50×)
Mock E2E decryption (CiphertextReady → PlaintextMade) 0.63 s 0.43 s -31.7% (1.46×)
Real-proof E2E non-fold DKG phases (C0 + C1–C3 + Roster/C4 + Publish) 12.89 s 9.15 s -29.0% (1.41×)
Real-proof E2E full post-finalization DKG (96.7% C++ bb, proofs=1) 282.03 s 275.06 s -6.97 s (-2.5%)
Real-proof E2E decryption (CiphertextReady → PlaintextMade) 25.32 s 24.94 s -0.38 s
--release FileBlobs serve (20× 4 MiB, zero-copy PublicCache) 176.32 ms <0.01 ms >10,000×
--release BFV CheckEncryptionKey (20×) 33.76 ms 2.88 ms 11.72×
--release 19-node Turán T(19,13) roster clique (50×) 5.85 ms 2.16 ms 2.71×
--release P2P Shares (20× 16×16 KiB proof blobs, loopback QUIC) 196.80 ms 98.90 ms 1.99×
--release Journal catch-up (500 chain events, 128-op group-commit) 37.32 ms 22.68 ms 1.65×
--release ACIR circuit load (20× pk.json) 2.06 ms 1.26 ms 1.63×
--release Selection ticket scoring (100k scores) 44.56 ms 34.74 ms 1.28×
--release Hold queue burst (512 held messages) 6.32 ms 5.62 ms 1.12×
--release P2P bulk 4 MiB batch loopback (5× 16×256 KiB) 207.97 ms 230.11 ms 0.90× (trade-off on 0.05 ms loopback)
--release FileBlobs batch write + PublicCache fill (16×256 KiB) 10.02 ms 11.96 ms 0.84× (cache population cost on NVMe)

Verification

  • Local unit & simulator tests (cargo test -p ...):
    • e3-blobs (10/10), e3-engine (7/7), e3-journal (4/4), e3-protocol (192/192, incl. the_persisted_encoding_is_the_one_its_version_names and might_fold observer regression), e3-jobs (12/12), e3-sim (10/10), e3-chain (69/69), e3-node (44/44), e3-p2p (70/70, incl. direct routing + batch fetch test), e3-daemon-server (compiled/0 tests).
  • Linux prover suite & checks (Moonstone):
    • cargo test -p e3-zk-prover --lib: 72 passed, 0 failed, 1 ignored.
    • cargo clippy --no-deps --all-targets -- -D warnings across all modified crates + e3-zk-prover --lib: 0 warnings.
    • cargo fmt --all -- --check and bash scripts/checks/repository.sh: passed.
  • End-to-end suites on Moonstone (tests/integration/v2.sh):
    • proofs: PASSED (0 errors, Decrypted: 4,0).
    • proofs-restart: PASSED (0 errors, Decrypted: 4,0, aggregator killed and recovered from journal + blobs).
    • mock: PASSED (0 errors, Decrypted: 4,0).
    • cli-restart: PASSED (run prior to the final 5-line might_fold pre-fold guard).
  • Verification limits:
    • Moonstone has 28 GiB RAM, so memory.rs (PROVER_BYTES = 13 GiB) caps capacity.proofs = 1. Multi-slot prover concurrency (c2ab || c3a || c3b || c4ab, C7 || C6Fold, dynamic bb_threads scaling, and background pre-folding) is covered by unit tests in e3-jobs (proofs.rs, tests.rs) rather than end-to-end on a ≥32 GiB host.
    • P2P tests ran on loopback QUIC (~0.05 ms RTT); WAN round-trip and gossipsub fanout savings were verified structurally via NetworkStats (direct_sent=25, gossip_sent=1, batches_fetched=26).

Compatibility

  • Domain references: docs/architecture/persistence-and-replay.md, docs/architecture/network-delivery.md, docs/architecture/dkg.md, docs/architecture/threshold-decryption.md, docs/architecture/proof-statements.md.
  • Durable state & old-data replay: ENCODING_VERSION = 1 snapshot/journal encoding is preserved (Hold and Ended serialize with the exact prior wire representation; admission_epoch is #[serde(skip)]; the_persisted_encoding_is_the_one_its_version_names passes). Effect::Note is non-durable by design; existing journal/outbox recovery passes proofs-restart.
  • Deployed contracts / verifiers: Unchanged. No circuit, VK, witness shape, proof statement, or contract ABI changes; verified end-to-end with real Barretenberg proofs against deployed verifiers.
  • Mixed-version peers (important): e3-p2p upgrades the blob request/response stream protocol from /interfold/blobs/1 to binary batched /interfold/blobs/2 and adds /interfold/direct/1 (which falls back to gossipsub if unavailable). Because blobs/1 was replaced rather than dual-registered, peers on this branch require matching blobs/2 support (targeted at the unreleased refactor/ciphernode-v2 branch; if mixed-version rolling upgrades against blobs/1 are needed later, blobs/1 compatibility can be dual-registered).
  • Release counters: Unchanged (refactor/ciphernode-v2 target branch; no release cut).

@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
interfold-dashboard Ready Ready Preview Nov 23, 2026 8:38am UTC
interfold-docs Ready Ready Preview Nov 23, 2026 8:38am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@neogiacomo

Copy link
Copy Markdown
Contributor

thanks @hmzakhalid <3

This branch was successfully deployed

2 active deployments
Preview – interfold-dashboard — caae224b Deployed Nov 23, 2026 by vercel[bot]
Preview – interfold-docs — caae224b Deployed Nov 23, 2026 by vercel[bot]
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.

2 participants