Skip to content
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e426c34
Add domain types for Algorithm 6 sumcheck optimization
wu-s-john Dec 18, 2025
d0f8eed
Add Lagrange domain extension for multilinear polynomials
wu-s-john Dec 18, 2025
e6d738f
Add accumulator data structures for Langrange Interpolation Based
wu-s-john Dec 18, 2025
8f7c456
Add const generic D to domain types for compile-time type safety
wu-s-john Dec 18, 2025
d23b654
Add index mapping for Algorithm 6 sumcheck optimization (Definition A.5)
wu-s-john Dec 18, 2025
e4444fd
Add suffix eq-polynomial pyramid for Algorithm 6 sumcheck optimization
wu-s-john Dec 18, 2025
b0908d7
Add gather_prefix_evals and UdTuple::from_binary for Algorithm 6
wu-s-john Dec 18, 2025
c7841ac
Implement Procedure 9 accumulator builder and add tests
wu-s-john Dec 18, 2025
7b32a0c
Add bit-ordering sanity tests for eq, gather, and binding
wu-s-john Dec 18, 2025
006fb04
Add Lagrange tensor evaluation helper and tests
wu-s-john Dec 19, 2025
6465006
Add eq round factor helper and tests
wu-s-john Dec 20, 2025
d9c75df
Fix clippy warnings in accumulator and Lagrange loops
wu-s-john Dec 20, 2025
cc373c1
Implement Lagrange sum-check round helpers
wu-s-john Dec 20, 2025
f8d5308
Add small-value sumcheck round harness and parity test
wu-s-john Dec 20, 2025
312bea3
Improve small-value accumulators: use quadratic t_i and speed up
wu-s-john Dec 21, 2025
93ee149
Add generic Csr<T> data structure and refactor accumulator cache
wu-s-john Dec 21, 2025
1a81943
Add SmallValueSumCheck::from_accumulators factory method
wu-s-john Dec 21, 2025
16ddb2b
Implement small-value sumcheck optimization (Algorithm 6)
wu-s-john Dec 21, 2025
950cca8
Add ping-pong buffer reuse to Lagrange extension: reduce allocations in
wu-s-john Dec 21, 2025
03b5293
Split build_accumulators: add Spartan-optimized and generic Procedure 9
wu-s-john Dec 21, 2025
1ed71a3
Add SHA256 circuit example to verify sumcheck method equivalence
wu-s-john Dec 21, 2025
67674c4
Add SmallValueField trait with Barrett-optimized sl multiplication
wu-s-john Dec 23, 2025
f6af2b4
Add type-safe UdEvaluations and UdHatEvaluations wrappers for domain
wu-s-john Dec 23, 2025
bccca73
Remove dead code and move test-only helpers to #[cfg(test)]
wu-s-john Dec 23, 2025
d050cf4
Eliminate per-iteration allocations in accumulator building
wu-s-john Dec 23, 2025
7e69518
Extract SpartanAccumulatorInputPolynomial trait to dedicated module
wu-s-john Dec 23, 2025
9611590
Remove dead code and simplify APIs
wu-s-john Dec 24, 2025
2bb44a0
Improve code readability: add clarifying comments and reduce duplication
wu-s-john Dec 24, 2025
44b442c
Fix formatting issues
wu-s-john Jan 6, 2026
c3f2268
Fix 33 clippy errors and typos checker warnings, all in test modules.
wu-s-john Jan 6, 2026
5bf9901
Implement delayed modular reduction for small-value sumcheck
wu-s-john Jan 8, 2026
af031c4
Optimize hot paths: fused MAC, single reduction, JIT eq tables
wu-s-john Jan 8, 2026
bd0d913
Refactor sumcheck_sweep to use clap CLI instead of env vars
wu-s-john Jan 8, 2026
074fcac
Optimize unreduced_mont_int_mul_add: use overflowing_add for carry
wu-s-john Jan 8, 2026
e434257
Fix formatting and clippy warnings
wu-s-john Jan 8, 2026
88ba34b
Added clap cli command
wu-s-john Jan 8, 2026
26cb450
Add small-value compatible SHA-256 circuit gadgets
wu-s-john Jan 7, 2026
bd8abf9
Add SHA-256 chain benchmark with CSV output
wu-s-john Jan 9, 2026
9325068
Refactor small-value traits and deduplicate reduction functions
wu-s-john Jan 9, 2026
4cd9b9b
Reorganize small_field module and relocate batching types to gadgets
wu-s-john Jan 9, 2026
406b59e
Improve accumulator helpers: dedupe eq-table prep and scatter beta
wu-s-john Jan 9, 2026
997556f
Refactor sub_mag to return SubMagResult enum instead of tuple
wu-s-john Jan 9, 2026
c90062d
Consolidate limb operations into small_field/limbs module
wu-s-john Jan 9, 2026
23ba9be
Reorganize Lagrange code into lagrange_accumulator/ module
wu-s-john Jan 9, 2026
eb33792
Reorganize small_field module and relocate batching types to gadgets
wu-s-john Jan 9, 2026
4b85d84
Fix clippy lints in lagrange_accumulator: add Default and is_empty impls
wu-s-john Jan 9, 2026
391fb50
Optimize accumulator builder: minimize Montgomery reductions in scatter
wu-s-john Jan 9, 2026
cc41fcb
Optimize eq table split: balance e_in and e_xout for ~33% precomputation
wu-s-john Jan 9, 2026
2a980b8
Optimize benchmark memory: scope polynomial lifetimes to free memory
wu-s-john Jan 17, 2026
6e73f98
Add BN254 curve support with small-value field optimizations
wu-s-john Jan 18, 2026
5bed106
Expand sumcheck_sweep benchmark: multi-field support and CLI options
wu-s-john Jan 18, 2026
6166bd8
Reuse beta_values buffer in accumulator builder to reduce allocations
wu-s-john Jan 18, 2026
c14e69d
Reduce allocations in small-value sumcheck: pre-allocate vectors and use
wu-s-john Jan 18, 2026
3685c61
Optimize small-value sumcheck binding: combine A/B/C in single pass
wu-s-john Jan 18, 2026
9e8d1dc
Add delayed reduction for eq sumcheck remaining rounds
wu-s-john Jan 18, 2026
2cc6af0
Add ILP batch-4 optimization to Lagrange extension
wu-s-john Jan 18, 2026
9adb677
Add split-eq-dmr benchmark: isolate delayed modular reduction impact
wu-s-john Jan 19, 2026
c4e5d8c
Add compile-time DMR mode selection for accumulator building
wu-s-john Jan 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions examples/compute_barrett_constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//! Compute Barrett reduction constants for Pallas Fp.
//! Run with: cargo run --example compute_barrett_constants

use num_bigint::BigUint;
use num_traits::{One, ToPrimitive};
use tracing::info;
use tracing_subscriber::EnvFilter;

fn main() {
tracing_subscriber::fmt()
.with_target(false)
.with_ansi(true)
.with_env_filter(EnvFilter::from_default_env())
.init();

// Pallas Fp modulus (base field)
let p = BigUint::parse_bytes(
b"40000000000000000000000000000000224698fc094cf91b992d30ed00000001",
16,
)
.unwrap();

// Barrett parameters
let np = 255u32; // bit-length of p
let r_prime = BigUint::one() << np; // R' = 2^255
let r = BigUint::one() << 64u32; // r = 2^64

// Compute constants
let two_p = &p * 2u32;
let mu = (&r * &r_prime) / &two_p;
let two_pow_64_mod_p = (BigUint::one() << 64u32) % &p;

// Log as structured data
info!(field = "Pallas Fp (Base field)", modulus = %format!("0x{:x}", p), "Barrett constants");
log_const("PALLAS_FP", &p, 4);
log_const("PALLAS_FP_2P", &two_p, 5);
log_const("PALLAS_FP_MU", &mu, 5);
log_const("TWO_POW_64_MOD_FP", &two_pow_64_mod_p, 4);

// Also compute Fq constants
compute_pallas_fq();

// Print final summary
println!("\nBarrett constants computed successfully. Run with RUST_LOG=info to see values.");
}

fn log_const(name: &str, value: &BigUint, num_limbs: usize) {
let limbs: Vec<u64> = (0..num_limbs)
.map(|i| {
let shifted = value >> (64 * i);
let masked = &shifted & BigUint::from(u64::MAX);
masked.to_u64().unwrap_or(0)
})
.collect();

info!(name = name, num_limbs = num_limbs, limbs = ?limbs, "computed constant");
}

// Also compute for Pallas Fq (scalar field) = Vesta Fp
fn compute_pallas_fq() {
// Pallas Fq modulus (scalar field)
let q = BigUint::parse_bytes(
b"40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001",
16,
)
.unwrap();

let nq = 255u32;
let r_prime = BigUint::one() << nq;
let r = BigUint::one() << 64u32;

let two_q = &q * 2u32;
let mu = (&r * &r_prime) / &two_q;
let two_pow_64_mod_q = (BigUint::one() << 64u32) % &q;

info!(field = "Pallas Fq (Scalar field)", modulus = %format!("0x{:x}", q), "Barrett constants");
log_const("PALLAS_FQ", &q, 4);
log_const("PALLAS_FQ_2Q", &two_q, 5);
log_const("PALLAS_FQ_MU", &mu, 5);
log_const("TWO_POW_64_MOD_FQ", &two_pow_64_mod_q, 4);
}
Loading
Loading