Small value neutronnova#124
Open
wu-s-john wants to merge 38 commits into
Open
Conversation
Add support for accumulating field × small_int products (i32, i64, i128) with delayed modular reduction using generic Barrett reduction: - SmallValueField<V> trait for small integer ↔ field conversion - WideMul trait for widening multiplication - BarrettReductionConstants with compile-time computed μ = ⌊2^512/p⌋ - SignedWideLimbs<N> accumulator for signed product sums - DelayedReduction<i32/i64/i128> implementations for all fields
This replaces expensive field multiplications with native integer
arithmetic during the first ℓ₀ rounds when polynomial values are
guaranteed small.
Key components:
Lagrange accumulator infrastructure (src/lagrange_accumulator/):
- LagrangeAccumulators: precomputed A_i(v, u) values for all rounds
- LagrangeIndex/LagrangePoint/LagrangeHatPoint: type-safe domain indices
- LagrangeBasisFactory: barycentric Lagrange basis with O(D) evaluation
- extend_to_lagrange_domain: batch extension from {0,1}^ℓ₀ to U_D^ℓ₀
- EqRoundFactor: tracks α = eq(τ_{<i}, r_{<i}) across rounds
- Csr: compressed sparse row storage (2 allocations vs N+1 for Vec<Vec>)
Performance optimizations:
- Thread-local SpartanThreadState eliminates per-iteration allocations
- Delayed modular reduction via SignedWideLimbs accumulators
- Skip binary betas (Az·Bz = Cz on {0,1}^n for satisfying witnesses)
- Batched eq-weighted binding in transition phase
API:
- SmallValue trait: WideMul + Copy + Zero + Add + Sub + Send + Sync
- SmallValueEngine<SV>: blanket impl consolidates field requirements
- prove_cubic_small_value<E, SV, const LB>: main entry point
The prove_cubic_small_value function produces identical proofs to the
standard prove_cubic_with_three_inputs, verified via equivalence tests.
Collaborator
|
@wu-s-john, thanks for the PR! Any idea if we can make thread-1 performance better than baseline? |
Splits the small-value accumulator prep/prove path out of neutronnova_zk
into a new small_neutronnova_zk module. Along with the move:
- Consolidates build_accumulators_neutronnova: the full-small (l0 == ell_b)
and partial-small (l0 < ell_b) variants now live in one function;
_partial is removed from the lagrange_accumulator surface.
- Factors the bit-reversed prefix gather + Lagrange-extend pattern into
bit_rev_prefix_table and gather_and_extend_prefix helpers in
lagrange_accumulator::extension, shared by the merged builder,
build_extended_prefix_mle_evals, and the test that compares them.
- Simplifies the small-value casting API: removes
vec_to_small_for_extension_with_context; the call sites in
build_small_abc wrap with .map_err to prepend "accumulator prep
{matrix} layer={idx}" to the context.
- Drops the unused SmallSparseMatrix path from r1cs::sparse.
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.
Run the small value NeutronNova code using
RUSTFLAGS="-C target-cpu=native" cargo bench --bench sha256_neutronnovaThis implementation of small value NeutronNova seems to be more performant than the current existing