diff --git a/src/gates/gate.rs b/src/gates/gate.rs index e4f81a02..075e2aab 100644 --- a/src/gates/gate.rs +++ b/src/gates/gate.rs @@ -1,5 +1,5 @@ use std::hash::{Hash, Hasher}; -use std::rc::Rc; +use std::sync::Arc; use crate::circuit_builder::CircuitBuilder; use crate::constraint_polynomial::{EvaluationTargets, EvaluationVars}; @@ -8,7 +8,7 @@ use crate::generator::WitnessGenerator; use crate::target::Target; /// A custom gate. -pub trait Gate: 'static { +pub trait Gate: 'static + Send + Sync { fn id(&self) -> String; fn eval_unfiltered(&self, vars: EvaluationVars) -> Vec; @@ -45,11 +45,11 @@ pub trait Gate: 'static { /// A wrapper around an `Rc` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs. #[derive(Clone)] -pub struct GateRef(pub(crate) Rc>); +pub struct GateRef(pub(crate) Arc>); impl GateRef { pub fn new>(gate: G) -> GateRef { - GateRef(Rc::new(gate)) + GateRef(Arc::new(gate)) } } diff --git a/src/generator.rs b/src/generator.rs index b2c4ca31..87a9cddd 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -66,7 +66,7 @@ pub(crate) fn generate_partial_witness( } /// A generator participates in the generation of the witness. -pub trait WitnessGenerator: 'static + Debug { +pub trait WitnessGenerator: 'static + Debug + Send + Sync { /// Targets to be "watched" by this generator. Whenever a target in the watch list is populated, /// the generator will be queued to run. fn watch_list(&self) -> Vec; @@ -80,7 +80,7 @@ pub trait WitnessGenerator: 'static + Debug { /// A generator which runs once after a list of dependencies is present in the witness. // TODO: Remove Debug. Here temporarily to debug generator issues. -pub trait SimpleGenerator: 'static + Debug { +pub trait SimpleGenerator: 'static + Debug + Send + Sync { fn dependencies(&self) -> Vec; fn run_once(&self, witness: &PartialWitness) -> PartialWitness; diff --git a/src/prover.rs b/src/prover.rs index 33933a04..96959f28 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -14,7 +14,7 @@ use crate::plonk_common::{eval_l_1, reduce_with_powers_multi}; use crate::polynomial::division::divide_by_z_h; use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues}; use crate::proof::Proof; -use crate::util::transpose_poly_values; +use crate::util::{transpose_poly_values, transpose}; use crate::wire::Wire; use crate::witness::PartialWitness; @@ -146,11 +146,9 @@ fn compute_vanishing_polys( let lde_gen = common_data.lde_generator(); let num_checks = common_data.config.num_checks; - let mut values = vec![Vec::with_capacity(lde_size); num_checks]; - let mut point = F::ONE; - for i in 0..lde_size { - debug_assert!(point != F::ONE); - + // let mut values = vec![Vec::with_capacity(lde_size); num_checks]; + let points = F::cyclic_subgroup_known_order(lde_gen, lde_size); + let values: Vec> = points.into_par_iter().enumerate().map(|(i, x)| { let i_next = (i + 1) % lde_size; let local_wires = &wire_ldes_t[i]; let next_wires = &wire_ldes_t[i_next]; @@ -169,18 +167,12 @@ fn compute_vanishing_polys( local_wires, next_wires, }; - let values_i = compute_vanishing_poly_entry( - common_data, point, vars, local_plonk_zs, next_plonk_zs, s_sigmas, beta, gamma, alphas); - for check in 0..num_checks { - values[check].push(values_i[check]) - } + compute_vanishing_poly_entry( + common_data, x, vars, local_plonk_zs, next_plonk_zs, s_sigmas, beta, gamma, alphas) + }).collect(); - point *= lde_gen; - } - - debug_assert_eq!(point, F::ONE); - - values.into_iter() + transpose(&values) + .into_iter() .map(PolynomialValues::new) .collect() }