diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index e6b71b1..eab4517 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -1,6 +1,6 @@ use core::cmp::max; use core::ops::{Add, Mul}; -use std::collections::HashMap; +use std::collections::BTreeMap; use super::Error; use crate::arithmetic::Field; @@ -160,7 +160,7 @@ pub struct MetaCircuit { pub(crate) fixed_queries: Vec<(FixedWire, Rotation)>, // Mapping from a witness vector rotation to the index in the point vector. - pub(crate) rotations: HashMap, + pub(crate) rotations: BTreeMap, // Vector of permutation arguments, where each corresponds to a set of wires // that are involved in a permutation argument. As an example, we could have @@ -174,7 +174,7 @@ pub struct MetaCircuit { impl Default for MetaCircuit { fn default() -> MetaCircuit { - let mut rotations = HashMap::new(); + let mut rotations = BTreeMap::new(); rotations.insert(Rotation::default(), PointIndex(0)); MetaCircuit { @@ -195,9 +195,9 @@ impl MetaCircuit { pub fn permutation(&mut self, wires: &[AdviceWire]) -> usize { let index = self.permutations.len(); if index == 0 { - // no permutations - let point_idx = self.rotations.len(); - self.rotations.insert(Rotation(-1), PointIndex(point_idx)); + let at = Rotation(-1); + let len = self.rotations.len(); + self.rotations.entry(at).or_insert(PointIndex(len)); } self.permutations.push(wires.to_vec()); diff --git a/src/plonk/domain.rs b/src/plonk/domain.rs index 62ec88d..81b74b6 100644 --- a/src/plonk/domain.rs +++ b/src/plonk/domain.rs @@ -2,7 +2,7 @@ use crate::arithmetic::{best_fft, parallelize, Field, Group}; /// Describes a relative location in the evaluation domain; applying a rotation /// by i will rotate the vector in the evaluation domain by i. -#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd)] pub struct Rotation(pub i32); impl Default for Rotation { diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index 861fa8c..03939fd 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -562,13 +562,11 @@ impl Proof { let x_6: C::Scalar = get_challenge_scalar(Challenge(transcript.squeeze().get_lower_128())); - let mut q_evals = vec![]; + let mut q_evals = vec![C::Scalar::zero(); meta.rotations.len()]; for (_, &point_index) in meta.rotations.iter() { - q_evals.push(eval_polynomial( - &q_polys[point_index.0].as_ref().unwrap(), - x_6, - )); + q_evals[point_index.0] = + eval_polynomial(&q_polys[point_index.0].as_ref().unwrap(), x_6); } for eval in q_evals.iter() {