diff --git a/plonky2/src/gates/selectors.rs b/plonky2/src/gates/selectors.rs index 559dcf48..dffeb987 100644 --- a/plonky2/src/gates/selectors.rs +++ b/plonky2/src/gates/selectors.rs @@ -13,7 +13,12 @@ pub(crate) const UNUSED_SELECTOR: usize = u32::MAX as usize; pub(crate) struct SelectorsInfo { pub(crate) selector_indices: Vec, pub(crate) groups: Vec>, - pub(crate) num_selectors: usize, +} + +impl SelectorsInfo { + pub fn num_selectors(&self) -> usize { + self.groups.len() + } } /// Returns the selector polynomials and related information. @@ -51,7 +56,6 @@ pub(crate) fn selector_polynomials, const D: usize> SelectorsInfo { selector_indices: vec![0; num_gates], groups: vec![0..num_gates], - num_selectors: 1, }, ); } @@ -101,7 +105,6 @@ pub(crate) fn selector_polynomials, const D: usize> polynomials, SelectorsInfo { selector_indices, - num_selectors: groups.len(), groups, }, ) diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 022e2b12..924ca553 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -666,7 +666,7 @@ impl, const D: usize> CircuitBuilder { let quotient_degree_factor = self.config.max_quotient_degree_factor; let mut gates = self.gates.iter().cloned().collect::>(); - // Gates need to be sorted by their degrees to compute the selector polynomials. + // Gates need to be sorted by their degrees (and ID to make the ordering deterministic) to compute the selector polynomials. gates.sort_unstable_by_key(|g| (g.0.degree(), g.0.id())); let (mut constant_vecs, selectors_info) = selector_polynomials(&gates, &self.gate_instances, quotient_degree_factor + 1); diff --git a/plonky2/src/plonk/vanishing_poly.rs b/plonky2/src/plonk/vanishing_poly.rs index 54a5fe98..ab23aa45 100644 --- a/plonky2/src/plonk/vanishing_poly.rs +++ b/plonky2/src/plonk/vanishing_poly.rs @@ -221,7 +221,7 @@ pub fn evaluate_gate_constraints< i, selector_index, common_data.selectors_info.groups[selector_index].clone(), - common_data.selectors_info.num_selectors, + common_data.selectors_info.num_selectors(), ); for (i, c) in gate_constraints.into_iter().enumerate() { debug_assert!( @@ -255,7 +255,7 @@ pub fn evaluate_gate_constraints_base_batch< i, selector_index, common_data.selectors_info.groups[selector_index].clone(), - common_data.selectors_info.num_selectors, + common_data.selectors_info.num_selectors(), ); debug_assert!( gate_constraints_batch.len() <= constraints_batch.len(), @@ -291,7 +291,7 @@ pub fn evaluate_gate_constraints_recursively< i, selector_index, common_data.selectors_info.groups[selector_index].clone(), - common_data.selectors_info.num_selectors, + common_data.selectors_info.num_selectors(), &mut all_gate_constraints, ) );