Skip to content

Small value neutronnova#124

Open
wu-s-john wants to merge 38 commits into
microsoft:mainfrom
wu-s-john:small-value-neutronnova
Open

Small value neutronnova#124
wu-s-john wants to merge 38 commits into
microsoft:mainfrom
wu-s-john:small-value-neutronnova

Conversation

@wu-s-john
Copy link
Copy Markdown
Contributor

@wu-s-john wu-s-john commented Apr 29, 2026

Run the small value NeutronNova code using

RUSTFLAGS="-C target-cpu=native" cargo bench --bench sha256_neutronnova

This implementation of small value NeutronNova seems to be more performant than the current existing

neutronnova_prove_threads_2048 neutronnova_prove_threads_1024

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.
@srinathsetty
Copy link
Copy Markdown
Collaborator

@wu-s-john, thanks for the PR! Any idea if we can make thread-1 performance better than baseline?

wu-s-john added 9 commits May 7, 2026 11:17
  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.
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