refactor(stark): compute OOD pruning layout once and thread it through verify#837
Merged
MauroToscano merged 1 commit intoJul 16, 2026
Conversation
…h verify PR #823 added g·z OOD trace-opening pruning. The layout metadata and the full-grid reconstruction were then derived redundantly at several sites that had to be kept in lockstep by hand: - `num_eval_points`/`next_row_cols` + `num_surviving_trace_openings` + `build_pruned_trace_term_coeffs` recomputed in the verifier round-4 transcript replay and prover round-4. - `reconstruct_ood_full` built TWICE per verify — once in `step_2` (after the `ood_blocks_well_formed` shape guard) and again, unguarded, in `step_3`, which silently relied on `step_2`/Phase A having validated the shapes first. - `split_ood_blocks` args recomputed in prover round-3. Introduce `ood::OodLayout`, a small struct bundling the AIR-derived layout (`num_total_cols`, `num_eval_points`, `step_size`, `next_row_cols`) with methods that forward to the existing free functions (`num_surviving`, `flags`, `build_trace_term_coeffs`, `split_full`, `reconstruct_full`, plus `expected_next_{width,height}` and a `next_row_cols`/`step_size` accessor). The free functions and their pub API are unchanged; the struct only wraps them and adds no new arithmetic. It stays decoupled from the AIR trait — a one-line `ood_layout` helper per crate reads the four raw values and hands them to `OodLayout::new`. `verify_rounds_2_to_4` now builds the layout, runs the `ood_blocks_well_formed` guard, reconstructs the full grid ONCE, and passes borrows into `step_2` and `step_3` (which now take `ood_full`/`step_size`, and `ood_full`/`next_row_cols`/ `step_size` respectively — extending the precedent #826 set when it threaded these through the fused `reconstruct_deep_composition_poly_evaluations_for_all_queries` and `compute_query_invariant_deep_terms`). The guard runs before both steps (same check, same `return false` semantics, same "Composition Polynomial verification failed" log on failure, same order relative to grinding), removing the hidden step_2-before-step_3 ordering dependency and doing one reconstruction instead of two — a small guest-cycle saving on the recursion verifier. The transcript-replay and prover metadata sites derive from the same struct. `ood_blocks_well_formed` is left as-is: its width check uses `trace_layout().0 + num_auxiliary_rap_columns()` (an overridable metadata source I cannot prove equals `trace_columns`), so folding it fully onto OodLayout is not provably behavior-preserving, and a partial fold would force a layout construction in the Phase A hot loop for no net simplification. Zero behavior change: Fiat-Shamir absorption/sampling order is untouched; the metadata sites keep using `trace_columns`; the DEEP reconstruction keeps reading `next_row_cols` on the reconstructed grid exactly as before. The verifier gains no new panics/asserts/unwraps and every `return false` path is preserved; net work strictly decreases (one reconstruction instead of two, no added allocations). Validated with the full `cargo test --release -p stark` suite (196 passed, incl. a new `OodLayout`-delegates-to-free-functions test) and `make lint` (fmt + all four clippy passes incl. cuda) at exit 0.
MauroToscano
force-pushed
the
refactor/ood-layout-compute-once
branch
from
July 16, 2026 17:29
6b0f233 to
8bf6532
Compare
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.
What
PR #823 added g·z OOD trace-opening pruning. The layout metadata and the full-grid reconstruction were then derived redundantly across several sites that had to be kept in lockstep by hand. This PR bundles that layout into one
ood::OodLayoutstruct, builds it once per proof, and threads borrows through verify — no behavior change, strictly less work.Rebased onto the current
feat/logup-acc-current-row, which now composes #835 (the standaloneood_blocks_well_formedshape guard, also run in the Phase A loop) and #826 (the fused per-FRI-point deep-composition reconstruction:reconstruct_deep_composition_poly_evaluation_pair+ the hoistedcompute_query_invariant_deep_terms, which takenext_row_colsindices rather than bool flags).The duplicated sites (before)
num_eval_points+next_row_cols, thennum_surviving_trace_openings/build_pruned_trace_term_coeffs, recomputed in:verifier::replay_rounds_after_round_1(round-4 transcript replay)proverround-4 (round_4_compute_and_run_fri_on_the_deep_composition_polynomial)reconstruct_ood_fullbuilt twice per verify — once instep_2(after theood_blocks_well_formedguard) and again, unguarded, instep_3, which silently relied onstep_2/Phase A having validated the block shapes first.split_ood_blocksargs recomputed inproverround-3.Why compute-once
transition_offsets.len() * step_size,trace_columns, the next-row column set) must stay bit-identical for Fiat-Shamir to line up between prover and verifier. One source removes that footgun.step_3's reconstruction had no shape guard of its own; it was only safe becausestep_2/Phase A ran first. Hoisting the guard + reconstruction into the caller makes that ordering explicit.How
ood::OodLayoutholds the AIR-derived layout (num_total_cols,num_eval_points,step_size,next_row_cols) and forwards to the existing free functions vianum_surviving(),flags(grid_width),build_trace_term_coeffs(),split_full(),reconstruct_full(), plusexpected_next_width()/expected_next_height()andnext_row_cols()/step_size()accessors. The free functions and their pub API are untouched; the struct only wraps them and adds no new arithmetic. It stays decoupled from theAIRtrait — a one-lineood_layouthelper per crate reads the four raw values and callsOodLayout::new.verify_rounds_2_to_4builds the layout, runsood_blocks_well_formed, and reconstructs the grid once, then passes&ood_full/layout.step_size()intostep_2and&ood_full/layout.next_row_cols()/layout.step_size()intostep_3. The guard keeps the same check, the samereturn falsesemantics, the same"Composition Polynomial verification failed"log on failure, and the same order relative to grinding.Signature changes (all internal trait methods, single caller each)
step_2_verify_claimed_composition_polynomial(..)gainsood_full: &Table<FieldExtension>, step_size: usize.step_3_verify_fri(..)gainsood_full: &Table<FieldExtension>, next_row_cols: &[usize], step_size: usize(extends the precedent perf(stark): fuse and hoist deep-composition reconstruction for both FRI points #826 set, which threaded these into the fused reconstruction).replay_rounds_after_round_1(..)gainslayout: &ood::OodLayout.IsStarkVerifier::ood_layoutandIsStarkProver::ood_layouthelpers.ood_blocks_well_formedleft as-is (deliberate)#835's guard also computes expected next-block dims from AIR metadata. Its width check uses
trace_layout().0 + num_auxiliary_rap_columns()— andnum_auxiliary_rap_columns()is an overridable trait method I cannot prove always equalstrace_columns(OodLayout::num_total_cols). So a full fold ontoOodLayoutis not provably behavior-preserving, and a partial fold (layout dims + air width) would force a layout construction in the Phase A hot loop for no net simplification. Theexpected_next_width/expected_next_heightmethods exist onOodLayoutfor the verify path; the guard keeps its own inline computation.Zero behavior change + validation
trace_columns.next_row_colson the reconstructed grid exactly as before.return falsepath is preserved; net work strictly decreases (one reconstruction instead of two, no added allocations).cargo test --release -p stark: 196 passed, 0 failed (includes a newOodLayout-delegates-to-free-functions test locking the wrappers to the free functions).make lint(fmt --check + all four clippy passes incl. cuda features): exit 0.Stacking
Stacked on
feat/logup-acc-current-row(the open #823 branch, into which #833 and #835 have merged); base will auto-retarget tomainwhen #823 merges.