diff --git a/core/sonic/src/helped/prover.rs b/core/sonic/src/helped/prover.rs index b26c3ca9..7a0a0209 100644 --- a/core/sonic/src/helped/prover.rs +++ b/core/sonic/src/helped/prover.rs @@ -6,7 +6,7 @@ use crate::cs::{SynthesisDriver, Circuit, Backend, Variable, Coeff}; use crate::srs::SRS; use crate::transcript::ProvingTranscript; use crate::polynomials::commitment::{polynomial_commitment}; -use crate::utils::{ChainExt, mul_powers}; +use crate::utils::{ChainExt, coeffs_consecutive_powers}; pub const NUM_BLINDINGS: usize = 4; @@ -106,7 +106,7 @@ impl Proof { let first_power = y_inv.pow(&[(2 * n + NUM_BLINDINGS) as u64]); // Evaluate the polynomial r(X, Y) at y - mul_powers( + coeffs_consecutive_powers( &mut rxy, first_power, y, diff --git a/core/sonic/src/polynomials/mod.rs b/core/sonic/src/polynomials/mod.rs index 309416ee..7c8c87d7 100644 --- a/core/sonic/src/polynomials/mod.rs +++ b/core/sonic/src/polynomials/mod.rs @@ -1,3 +1,6 @@ +use pairing::Engine; pub mod commitment; pub mod s_eval; pub mod operations; + +pub struct Polynomial(Vec); diff --git a/core/sonic/src/polynomials/operations.rs b/core/sonic/src/polynomials/operations.rs index e69de29b..f77b7d42 100644 --- a/core/sonic/src/polynomials/operations.rs +++ b/core/sonic/src/polynomials/operations.rs @@ -0,0 +1,18 @@ +use bellman::multicore::Worker; +use pairing::{Engine, Field}; + +pub fn add_polynomials(a: &mut [F], b: &[F]) { + assert_eq!(a.len(), b.len()); + + let worker = Worker::new(); + + worker.scope(a.len(), |scope, chunk| { + for (a, b) in a.chunks_mut(chunk).zip(b.chunks(chunk)) { + scope.spawn(move |_| { + for (a, b) in a.iter_mut().zip(b.iter()) { + a.add_assign(b); + } + }); + } + }); +} diff --git a/core/sonic/src/polynomials/s_eval.rs b/core/sonic/src/polynomials/s_eval.rs index df0493d1..060ee2eb 100644 --- a/core/sonic/src/polynomials/s_eval.rs +++ b/core/sonic/src/polynomials/s_eval.rs @@ -2,6 +2,7 @@ use pairing::{Engine, Field}; use bellman::SynthesisError; /// Defined in Section 5: SYSTEM OF CONSTRAINTS +/// Evaluation of s(X, Y) at x #[derive(Clone)] pub struct SxEval { y: E::Fr, @@ -20,7 +21,8 @@ pub struct SxEval { } impl SxEval { + /// Initialize s(X, y) where y is fixed. pub fn new(y: E::Fr, n: usize) -> Result { unimplemented!(); } -} \ No newline at end of file +} diff --git a/core/sonic/src/utils.rs b/core/sonic/src/utils.rs index 18de0e11..00c60908 100644 --- a/core/sonic/src/utils.rs +++ b/core/sonic/src/utils.rs @@ -69,7 +69,7 @@ impl DoubleEndedIterator for Chain /// Multiply each coefficient by some power of the base in a form /// `first_power * base^{i}` /// This would be sparse, consecutive multiplication based on non-zero coefficients. -pub fn mul_powers<'a, F: Field> ( +pub fn coeffs_consecutive_powers<'a, F: Field> ( coeffs: &mut [F], first_power: F, base: F