Repository navigation
Conversation
Restores the 2026-08 proof-optimization work that lived as uncommitted
changes on main (kept alive in stash@{0}, "proof-bench work", 2026-08-25)
onto main 945d5bd. Content is unchanged apart from rustfmt on the bench.
- banderwagon: hand-rolled window-parallel Pippenger MSM (msm_windowed)
that avoids arkworks' thread-pool traffic at SALT's MSM sizes;
multi_scalar_mul skips the batch inversion when the bases are already
affine; Committer::num_bases.
- ipa-multipoint: create_with_precomp computes every IPA L/R point as a
fixed-base MSM over the original CRS generators (byte-identical
proofs); MultiPoint::open_with_committer and commit_dense route the
polynomial commitments through the precomputed tables; queries share
their polynomial via Arc; verification sums scalars per commitment run
so the final multiexp has one point per node instead of per query;
serial fast paths for small powers_of_par and per-query scalar work;
equivalence tests against the generic paths.
- salt: process-wide DEFAULT_CRS and shared_committer() so proof
creation reuses the trie's fixed-base tables instead of rebuilding the
CRS per call; shape.rs/subtrie.rs cut per-key allocations, read each
bucket's metadata once, and cache default-commitment scalar
conversions; new benches/proof.rs covering SaltProof::create/check and
Witness::create/verify.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGFBjWNK8YFania1Bstst9
…ding base - proof/subtrie: a process-wide node-polynomial cache keyed by physical node id and validated by commitment bytes (the commitment binds the children), so unchanged nodes skip the 256-child range read and the map-to-field pass. Query construction keeps node/point order either way: the transcript hashes it. Hit rate on mainnet ~44% internal / ~48% leaf (misses are the block's own write paths). - ipa: the shared committer carries Q as base n, so the IPA's per-round blinding terms z*(w*Q) are fixed-base multiplications instead of two variable-base ones per round. - banderwagon: ScalarWindows produces the wNAF digits on the fly, so mul_index no longer allocates a Vec per call. - rayon chunk floors in the multiproof aggregate, the shape pass, the parent reads and the fixed-base MSM (8 terms): below that the dispatch costs more than the work. Measured with mega-reth's replay-full pipeline (W32/K4/M6, 5000 mainnet blocks, 32-vCPU box): 150 -> 172 blocks/s; per witness at M=1 7.43 -> 6.00 ms (IPA 2.41 -> 1.70, internal nodes 1.88 -> 1.37). Proofs stay byte-identical (see the determinism test). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01722A9KuCsH6MnM83Mhax3Y
The node-polynomial cache only helps for nodes whose commitment did not change since they were cached; every node on a block's write paths is a miss (~55% of the internal nodes of a mainnet witness) that costs a 256-child range read and 256 map-to-field conversions. A witness proves the pre-state, so the polynomials it resolves are exactly the bases the block's transition transforms. `NodePolyRefresh` carries that transition — the (old, new) commitment of every changed node and the (old, new) value of every changed slot, the pair `StateRoot::update_fin` produced — and `Witness::create_with_refresh` (also `SaltWitness`/`SaltProof`) applies it after the witness's own lookups: each changed parent's polynomial is copied, its changed positions overwritten (hash-to-field of the new child commitment, or the slot's new value), and the result inserted under the parent's new commitment, so the next block's witness hits. Buckets whose capacity changes are frozen for the block; subtree tops are keyed the way the witness reads them; a parent read at any commitment other than the transition's old one is skipped. Debug builds check every refreshed entry: old + sum G_i*(s_i - base_i) == new, which commitment validation alone cannot see. The existing `create` signatures are unchanged. Measured on the replay-full pipeline: hit rate at one worker 44% -> 98%, per-witness internal-node phase 1.39 -> 0.42 ms; at six workers the witness build 19.6 -> 15.3 ms and the pipeline 265 -> 305 blocks/s. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01722A9KuCsH6MnM83Mhax3Y
…-state guard Six tests over `NodePolyRefresh` in subtrie.rs, each pinning a path that a mutation of the refresh left the suite blind to: - `refresh_uses_cached_bases_for_parents_the_witness_did_not_read`: a planned parent out of the witness's hand is skipped while the cache holds no entry for its old commitment, and refreshed from that entry once a pre-state witness has cached it. - `refresh_applies_every_planned_parent`: with every base in hand, `apply_refresh` inserts exactly one entry per planned parent, each equal to the post-block rebuild. - `witness_refresh_reports_every_planned_parent` (`perf`): a witness over every changed key reports `refreshed_nodes == plan.len()` on the calling thread, race-free against the shared cache. - `refresh_rejects_a_witness_over_the_post_state` (debug): the `read_at_old` guard fires with its own message on a witness over the post-state. - `refresh_skips_a_parent_read_at_a_foreign_commitment` (release): a witness over the pre-B view carrying block C's transition patches nothing, so the bucket root stays absent under C's commitment. - `refresh_patches_a_rehashed_bucket_with_unchanged_capacity`: a nonce-only rehash of a two-level, 512-slot bucket is not frozen; its leaves, top and metadata leaf are planned at the moved slots and refreshed. Each test fails under the mutation it targets (dropping the cache fallback, skipping level-1/2 parents, freezing on any metadata change, accepting any read commitment) and passes on the code as it is. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01722A9KuCsH6MnM83Mhax3Y
The refresh doc comments referred to numbered invariants of a design note outside the repository; the sentences now stand on their own. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01722A9KuCsH6MnM83Mhax3Y
…est fixtures Quality cleanup of the proof-opt changes; proof and witness bytes are unchanged (blake3 digests of three serializations match before/after). - subtrie: one resolve_polys helper replaces the duplicated internal/leaf cache blocks; in_hand carries the commitment each base was read at and is only filled with a refresh, so apply_refresh drops its parent_bytes parameter; multi_commitments_to_scalars takes node ids; empty_slot_scalar and slot_position are shared by refresh_plan and leaf_polynomial; the test-only query shims are gone; node_poly_cache::insert evicts only for a new node and frees evicted or replaced entries outside the shard lock. - ipa-multipoint: open_with_committer takes &CRS (no CRS clone per proof); create_with_precomp uses a plain flag for Q in the tables and reuses its per-round term buffers; commit_dense falls back to commit_lagrange_poly; check calls multi_scalar_mul directly and multi_scalar_mul_par is deprecated; LagrangeBasis::values is public. - DEFAULT_CRS lives in trie.rs next to the committer built from it, so the trie no longer depends on proof::prover. - tests/bench: apply_block and two_block_fixture move to proof::test_utils and back the witness.rs refresh test; shared value/meta/store_with_two_slots helpers; the check bench builds its data with SaltWitness::create. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…hold `make_digits` recenters every window's digit to [-2^(c-1), 2^(c-1) - 1], so a bucket index (|digit| - 1) never reaches the upper half of the 2^c array the windowed MSM allocated: half of every window's bucket array was untouched, and the reduction still walked it, paying one point addition per empty bucket (arkworks skips the zero operand, so the cost was the `res += running_sum` of each empty slot rather than both additions). Each window now takes 2^(c-1) buckets. The last window is the exception: it absorbs the outstanding carry instead of being recentered, so its digits run 0..=2^last_bits and it takes 2^last_bits buckets — the full 2^c when c divides the 253-bit modulus width, which is the width the size heuristic picks for 8,193 to 16,384 points. Results are unchanged (exact group arithmetic), so proofs stay byte-identical. Measured on an M4 Pro, release, medians of two runs: 274 points (the IPA's closing MSM, present in every proof check) 525 -> 418 us, 400 points 580 -> 484, 1,000 points 880 -> 798, 2,335 points 2,046 -> 1,718, 8,192 points 4,884 -> 4,564. The band that gains most is exactly the one a mainnet head witness lands in: its commitments coalesce to a few hundred to a couple of thousand points. None of this depends on AVX-512, so every platform gets it. `msm_windowed` now picks `c` and delegates to `msm_windowed_with_c`, which lets the new equivalence test cover every window width (and with it every bucket-count branch) at a size that keeps a debug run cheap; the existing size-driven test still covers the parallel path. A second test pins the digit bounds the bucket counts rest on, and an ignored timing test reports the sizes above. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`benches/proof.rs` creates every proof over one store and one key set, so from the second sample on, the process-wide node-polynomial cache serves every node and the benchmark reports a 100% hit rate — a number no caller sees, and one that hides the cost of the stages that feed the cache (store reads, map-to-field passes, their rayon chunking) from anything measured against it. `salt_proof/create-cold` and `witness/create-cold` clear the cache before every iteration, so each sample pays for the nodes on its own paths. The warm groups stay: production sits between the two, at 44% on mainnet without the refresh and 98% with it, so the pair brackets it. `clear_node_poly_cache` is the hook the benches call. It is `#[doc(hidden)]` — nothing in production wants to drop the cache — and clearing a shard frees its map after the lock is released, like the eviction path does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ffect for An ablation of every mechanism this branch adds (one arm per mechanism switched off, salt's own criterion benches, 32-thread EPYC) found three that are either inert at mainnet witness shapes or too small to carry their cost: - `ScalarWindows` (allocation-free wNAF digits in `mul_index`): nothing on proof creation, +1.3% / +2.4% on `update 10000 KVs` at 1 / 8 threads, the first of which sits on the benchmark's noise floor. It also removed `calculate_prefetch_index`, which the batched committer this branch is about to be merged with builds on. `salt_committer.rs` goes back to what `ad33ac8` left. - `MIN_PARENT_CHUNK = 8`: a floor binds only below `floor x threads` items, and a mainnet head witness reads ~560 parent commitments, so it never bound under 70 threads. The parent list is never empty, so no floor is needed at all. - The `max(8)` on the multiproof aggregate and the `max(64)` on `parents_and_points`: no measurable effect in isolation. Both become `max(1)`, which is what keeps an empty input away from `chunks(0)` (a panic) — the verifier reaches `parents_and_points` with whatever key set it was handed, and `MultiPoint::open` is a library entry point. `MIN_NODE_CHUNK` and `MSM_MIN_CHUNK` stay: the first also guards the all-hits case (an empty rebuild list, the norm once the refresh lifts the hit rate to 98%), the second binds on every proof once the pool has more than 16 threads, and what both are for — several proofs sharing one pool — is not something a one-proof-at-a-time benchmark can see. Outputs are unchanged; proofs stay byte-identical. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…hook An end-to-end replay-full run (5000 mainnet blocks, 5 alternating rounds per arm) put numbers on what the isolated ablation could not: - `MIN_NODE_CHUNK` and `MSM_MIN_CHUNK` are worth 1.3% of pipeline throughput with 8 concurrent witness builds and cost 1.4% with one. Both become `.max(1)`, which only keeps an empty input off `chunks(0)`. - The cold-cache bench groups and the public `clear_node_poly_cache` hook they needed (reverts 4e613ce): the pipeline run now answers the question they were added for, so the crate does not need the extra public symbol. - `msm_windowed_timing`, an ignored timing harness. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…anch `NodePolyRefresh` and the three `create_with_refresh` entry points leave this branch for `liquan/perf/proof-refresh`, which carries them on top of it unchanged. The refresh is 336 lines of product code and about 850 of tests, close to half of this PR, and the part that most deserves a review of its own; end to end it is worth 12.5% of replay-full throughput on top of the cache, which stays here and is worth 16% by itself. Without a refresh the cache is filled by rebuilds alone, so a node the previous block wrote is rebuilt once under its new commitment. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Mutation testing - PASSNothing to test: no viable mutants were generated. |
Performance Benchmark ComparisonCompared Detailed Comparison
|
Mutation testing - FAILMutation score: 88.2% (15/17 viable mutants killed)
Survivors needing attentionEach mutant changed code but no test failed. Add a killing test or record a justified suppression.
|
Reuse, simplification, efficiency and altitude passes over the diff
against main; outputs are unchanged and the proof byte-identity tests
pin that.
- `thread_chunk_size!` (salt-macros): the `div_ceil(num_threads).max(1)`
idiom and its zero-chunk guard live once, not at four sites with four
comments; every chunking site uses it.
- `CRS::committer` builds the `G ++ [Q]` tables the provers require, and
`create_with_precomp` asserts that shape: its `q` parameter, the
table-shape sniffing, the debug assert and the variable-base blinding
fallback no caller reached are gone. The trie's shared committer is
built through it.
- `Committer::msm` (banderwagon) replaces `ipa::fixed_base_msm`, which
multiproof reached across modules for a committer operation.
- `create_sub_trie`: one `ParentNode` (logical id, physical id, bytes,
decoded commitment) per parent, read in parallel in node order; this
drops the second `parent_bytes` map, the lookup closure with an
unreachable error arm, the repeated `connect_parent_id` calls and the
hash lookups per node, and `resolve_polys` takes the slice.
`internal_polynomials` returns one polynomial per node instead of a
flat buffer the caller copied out of. Key validation groups the sorted
keys with `chunk_by`.
- `open_inner` derives `a`/`b` once for both IPA paths;
`open_point_outside_of_domain` is inlined into its only (test) caller.
- Deleted or narrowed: `multi_scalar_mul_par` (deprecated, no callers),
`LagrangeBasis::values` and `DEFAULT_CRS` back to `pub(crate)`,
`shared_committer` returns `&'static`, `apply_block` returns nothing,
`msm_windowed` stops truncating to the shorter slice (its caller asserts
equal lengths), `slot_position` is shared with `shape.rs`, the arkworks
agreement tests share one input builder.
Bench (M4 Pro, warm cache) against the tree before this commit:
`salt_proof/create/{16,256,2048}` and `witness/create/{256,1024}` within
noise. An intermediate version read the parents with an unbounded
`par_iter`, which cost 2% on `witness/create/256`; the read is bounded to
one chunk per thread again via `with_min_len`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
flyq
force-pushed
the
liquan/perf/proof-refresh
branch
from
September 22, 2026 03:32
cdd5d8a to
86e58d5
Compare
…h the suppressions The mutation gate's three survivors sat in the cache's eviction condition (`len >= MAX_PER_SHARD && !contains_key`): nothing filled a shard. That cannot be tested deterministically against a process-wide cache that every proof test writes to, so the shards become `NodePolyCache`, with `CACHE` as the one global instance, and a test fills a private instance: a full shard keeps its entries when a node it holds is re-inserted (at a new commitment, which retires the old one) and is cleared only by a node it does not hold. The suppression hygiene check has failed on this branch since 9/7: three entries named `multi_commitments_to_scalars` and `process_leaf_node`, which this branch rewrote (the `<` guard is now in `leaf_polynomial`; the `*` sizing arithmetic no longer exists), and four `create_node_aligned_chunks` entries were pinned to lines that `DEFAULT_CRS` and `shared_committer` shifted by eleven. Re-pointed and re-pinned; the orphan check passes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…transition The node-polynomial cache is keyed by a node's commitment, so the nodes a block writes — the ones the next block is most likely to touch — miss on the next witness and are rebuilt from storage. `create_with_refresh` takes the block's `TrieUpdates` and `StateUpdates`, patches each changed node's polynomial at its changed positions once the witness's own lookups are done, and inserts it under the new commitment. Buckets whose capacity changes are skipped whole and rebuilt on the next block. replay-full over 5000 mainnet blocks, median of 5 alternating rounds: 248 -> 279 blocks/s with 6 witness workers, 258 -> 290 with 8, and 146 -> 153 with 1; witness build 19.6 -> 15.9 ms at 6 workers. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
flyq
force-pushed
the
liquan/perf/proof-refresh
branch
from
September 22, 2026 03:53
86e58d5 to
6384a5d
Compare
Contributor
Author
|
Closing without merging. The branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #152. The node-polynomial cache is keyed by a node's commitment, so the nodes a block writes — the ones the next block is most likely to touch — miss on the next witness and are rebuilt from storage: on mainnet the cache alone hits 44%.
create_with_refreshtakes the block's own transition and advances the cache to the post-state, which lifts the hit rate to 98% and replay-full throughput by 12.5% at production concurrency. Split out of #152 because it is the largest and most intricate part (336 lines of product code, about 850 of tests) and deserves its own review; the diff is what #152 carried before the split, rebased onto its review cleanup (1f97191: the hooks now sit oncreate_sub_trie'sParentNodelist, andLagrangeBasis::valuesispubfor the patch copy).Changes
NodePolyRefresh { trie_updates, state_updates }(salt/src/proof/subtrie.rs): the pairStateRoot::update_finproduced for the block.Witness::create_with_refresh,SaltWitness::create_with_refreshandSaltProof::create_with_refreshpass it down; the existingcreatesignatures are unchanged and forwardNone.refresh_planderives, from the block's outputs alone, which position of which cached polynomial takes which new scalar: a changed child's new commitment for an internal node, a changed slot's kv hash for a leaf. Physical vs logical subtree ids follow the trie's rules (a bucket whose subtree top changed is keyed by its main-trie bucket root); duplicates fold to the first old and last new commitment.apply_refreshruns after the witness's own lookups: it copies the base polynomial (the one this witness just resolved for the pre-state, else the cached one validated at the old commitment), patches it, and inserts it under the new commitment. A parent read at any other commitment is skipped, so a retried witness is idempotent.Testing
Same gates as #152 (
cargo test --workspace, release lib tests, no_std build, clippy, fmt). Eleven refresh tests insubtrie.rs— equality with a storage rebuild, expanded-bucket subtrees, frozen buckets, idempotent retries, cached-base fallback, every-planned-parent coverage, nonce-only rehash,should_panicpins on the two debug self-checks and on the pre-state guard, and the release-only foreign-commitment skip — pluswitness_over_refreshed_polynomials_verifies_and_is_stable. Debug builds checkold + Σ G_i·(s_i − base_i) == newfor every refreshed entry (assert_patch_commits), which catches a wrong position or scalar that commitment validation alone cannot see.Measurements
mega-reth
liquan/perf/pipeline-optreplay-full over 5000 mainnet blocks (25827013..25832012) on a 32-thread EPYC 9B45, one binary per salt arm, runs strictly sequential with the arm order alternating between rounds; median of 5 rounds, run-to-run spread ±0.3%, 75 runs, 0 errors. "Refresh ignored" is this branch with the argument dropped at the top ofcreate_sub_trie, so the cache is filled by rebuilds alone. M = concurrent witness builders (production runs 6–8); stage times are per-block means in ms. The rows were measured at784d695; this branch's head additionally drops two rayon chunk floors, measured in the same matrix at 154.8 / 278.2 / 286.4 blocks/s.The refresh adds +4.9% / +12.5% / +12.5% throughput on top of the cache and cuts the witness build by 5% / 19% / 26%, net of its own cost. It gains most at M6–M8 because the pool is saturated there, so the rebuild work it avoids turns into wall time one for one, and the sequential state-root stage gets that CPU back (3.26 → 2.86 ms at M8). Peak RSS is 19.0–19.3 GB on every arm: the cache's 256 MB cap is below what the process-level figure resolves. (143.4 is the first run of the matrix on a cold page cache; the other four rounds are 151.8–153.1.)
Earlier runs on the same range, with the
perfphase-timing feature that has since left the branch: node-cache hit rate at one worker 44% → 98%; the internal-node stage of a witness 1.39 → 0.42 ms; per witness at one worker 6.00 → 5.62 ms; pipeline at six workers 265 → 305 blocks/s. A criterion bracket agrees with the first two: a 256-key witness is 5.48 ms on a cold cache and 4.11 ms fully warm, which puts 44% → 98% at about 0.74 ms per witness.Record in mega-reth:
data/salt/salt-152-e2e-2026-09-21.zh-CN.md,data/salt/pr152-trim-2026-09-07.md.Notes
create.🤖 Generated with Claude Code