Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Jun 18, 2024
1 parent aa89085 commit 2d4c6c9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
38 changes: 17 additions & 21 deletions bi-kzg/src/bi_fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use ark_std::log2;
use halo2curves::{
ff::{Field, PrimeField},
fft::{best_fft, FftGroup},
fft::best_fft,
};

fn bitreverse(mut n: usize, l: usize) -> usize {
Expand All @@ -21,10 +21,6 @@ fn deep_swap_chunks<F: Clone + Copy>(a: &mut [&mut [F]], rk: usize, k: usize) {
let buf2 = (a[rk]).to_vec();
a[rk].copy_from_slice(&buf1);
a[k].copy_from_slice(&buf2);
// a[rk].iter_mut().zip(a[k].iter_mut()).for_each(|(a, b)| {
// let t = *a;
// *a = *b;
// *b = t});
}

// #[inline]
Expand Down Expand Up @@ -110,22 +106,22 @@ pub fn best_fft_vec<F: PrimeField>(a: &mut [F], omega: F, log_n: u32, log_m: u32
let rk = bitreverse(k, log_m as usize);

if k < rk {
println!("k: {}, rk: {}", k, rk);
for a in a_vec_ptrs.iter().enumerate() {
println!("{}: {:?}", a.0, a.1);
}
// println!("k: {}, rk: {}", k, rk);
// for a in a_vec_ptrs.iter().enumerate() {
// println!("{}: {:?}", a.0, a.1);
// }

deep_swap_chunks(&mut a_vec_ptrs, rk, k );
deep_swap_chunks(&mut a_vec_ptrs, rk, k);

// a_vec_ptrs.swap(rk, k);
// swap_chunks(a_vec_ptrs[k], log_n);
// swap_chunks(a_vec_ptrs[rk], log_n);

for a in a_vec_ptrs.iter().enumerate() {
println!("{}: {:?}", a.0, a.1);
}
// for a in a_vec_ptrs.iter().enumerate() {
// println!("{}: {:?}", a.0, a.1);
// }

println!();
// println!();
}
}

Expand Down Expand Up @@ -268,9 +264,9 @@ pub(crate) fn bi_fft_in_place<F: PrimeField>(coeffs: &mut [F], degree_n: usize,
.chunks_exact_mut(degree_n)
.for_each(|chunk| best_fft(chunk, omega_0, log2(degree_n)));

println!("before: {:?}", coeffs);
// println!("before: {:?}", coeffs);
best_fft_vec(coeffs, omega_1, log2(degree_n), log2(degree_m));
println!("after: {:?}", coeffs);
// println!("after: {:?}", coeffs);
}

#[cfg(test)]
Expand Down Expand Up @@ -313,11 +309,11 @@ mod tests {
let poly_lag = poly.lagrange_coeffs();
bi_fft_in_place(&mut poly_lag2, n, m);

for (i, (a, b)) in poly_lag.iter().zip(poly_lag2.iter()).enumerate() {
println!("{}: {:?} == {:?}", i, a, b);
}
// for (i, (a, b)) in poly_lag.iter().zip(poly_lag2.iter()).enumerate() {
// println!("{}: {:?} == {:?}", i, a, b);
// }

println!("correct one {:?}", poly_lag);
// println!("correct one {:?}", poly_lag);
// println!();
// println!("{:?}", poly_lag2);
// println!();
Expand All @@ -332,7 +328,7 @@ mod tests {
let mut poly_lag2 = poly.coefficients.clone();
let poly_lag = poly.lagrange_coeffs();
bi_fft_in_place(&mut poly_lag2, *n, *m);
println!("m = {}, n = {}: {}", m, n, poly_lag == poly_lag2);
// println!("m = {}, n = {}: {}", m, n, poly_lag == poly_lag2);
assert_eq!(poly_lag, poly_lag2);
}
}
Expand Down
14 changes: 10 additions & 4 deletions bi-kzg/src/coeff_form_bi_kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ where
"Committing to polynomial of degree {} {}",
poly.degree_0, poly.degree_1
));

let timer2 =
start_timer!(|| format!("Computing the msm for size {}", poly.coefficients.len()));
let com = best_multiexp(
&poly.coefficients,
prover_param.borrow().powers_of_g.as_slice(),
);

end_timer!(timer2);
end_timer!(timer);

Self::Commitment { com: com.into() }
Expand All @@ -192,11 +193,13 @@ where
q_0_x_b[0] -= u;
let q_0_x_b = univariate_quotient(&q_0_x_b, &point.0);

let timer2 = start_timer!(|| format!("Computing the msm for size {}", q_0_x_b.len()));
let pi_0 = best_multiexp(
&q_0_x_b,
prover_param.borrow().powers_of_g[..polynomial.degree_0].as_ref(),
)
.to_affine();
end_timer!(timer2);
(pi_0, f_x_b)
};
end_timer!(timer2);
Expand Down Expand Up @@ -237,14 +240,17 @@ where
.map(|(c, y)| (*c) * *y)
.collect::<Vec<_>>();

best_multiexp(
let timer2 = start_timer!(|| format!("Computing the msm for size {}", q_1_x_y.len()));
let res = best_multiexp(
&q_1_x_y,
prover_param
.borrow()
.powers_of_g_lagrange_over_both_roots
.as_ref(),
)
.to_affine()
.to_affine();
end_timer!(timer2);
res
};
end_timer!(timer2);
let proof = BiKZGProof::<E> {
Expand Down
5 changes: 5 additions & 0 deletions bi-kzg/src/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use itertools::Itertools;
use rand::RngCore;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};

use crate::bi_fft::bi_fft_in_place;
use crate::structs::{BivariateLagrangePolynomial, BivariatePolynomial};
use crate::util::powers_of_field_elements;

Expand Down Expand Up @@ -66,6 +67,9 @@ impl<F: PrimeField> BivariatePolynomial<F> {
self.degree_0, self.degree_1
));

// let mut coeff = self.coefficients.clone();
// bi_fft_in_place(&mut coeff, self.degree_0, self.degree_1);

// roots of unity for supported_n and supported_m
let (omega_0, omega_1) = {
let omega = F::ROOT_OF_UNITY;
Expand Down Expand Up @@ -93,6 +97,7 @@ impl<F: PrimeField> BivariatePolynomial<F> {
}
}
end_timer!(timer);
// coeff
res
}
}
Expand Down

0 comments on commit 2d4c6c9

Please sign in to comment.