From 3fd52581912991e16c53c7f035fe3874269bdff8 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Tue, 15 Feb 2022 18:00:53 +0100 Subject: [PATCH] Comments --- plonky2/src/gates/gate.rs | 4 +++- plonky2/src/iop/generator.rs | 5 ----- plonky2/src/plonk/circuit_builder.rs | 7 ++++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 1d6a0e3d..c84c6595 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -143,7 +143,8 @@ pub trait Gate, const D: usize>: 'static + Send + S /// Number of operations performed by the gate. fn num_ops(&self) -> usize { - self.generators(0, &[F::ZERO; 100]).len() + self.generators(0, &vec![F::ZERO; self.num_constants()]) + .len() } } @@ -177,6 +178,7 @@ impl, const D: usize> Debug for GateRef { } } +/// Map between gate parameters and available slots. #[derive(Clone, Debug)] pub struct CurrentSlot, const D: usize> { pub current_slot: HashMap, (usize, usize)>, diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 0105e031..1569e889 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -91,11 +91,6 @@ pub(crate) fn generate_partial_witness< pending_generator_indices = next_pending_generator_indices; } - for i in 0..generator_is_expired.len() { - if !generator_is_expired[i] { - dbg!(i); - } - } assert_eq!( remaining_generators, 0, "{} generators weren't run", diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index aa4c67be..5c5f66f0 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -81,6 +81,7 @@ pub struct CircuitBuilder, const D: usize> { /// Memoized results of `arithmetic_extension` calls. pub(crate) arithmetic_results: HashMap, ExtensionTarget>, + /// Map between gate type and the current gate of this type with available slots. current_slots: HashMap, CurrentSlot>, } @@ -211,7 +212,6 @@ impl, const D: usize> CircuitBuilder { constants: Vec, params: Vec, ) -> usize { - // println!("{} {}", self.num_gates(), gate_type.id()); self.check_gate_compatibility(&gate_type); assert_eq!( gate_type.num_constants(), @@ -397,6 +397,7 @@ impl, const D: usize> CircuitBuilder { }) } + /// Find an available slot, of the form `(gate_index, op)` for gate `G`. pub fn find_slot + Clone>( &mut self, gate: G, @@ -420,12 +421,14 @@ impl, const D: usize> CircuitBuilder { (num_gates, 0) }; if res.1 == num_ops - 1 { + // We've filled up the slots at this index. self.current_slots .get_mut(&gate_ref) .unwrap() .current_slot .remove(params); } else { + // Increment the slot operation index. self.current_slots .get_mut(&gate_ref) .unwrap() @@ -737,6 +740,7 @@ impl, const D: usize> CircuitBuilder { constants_sigmas_cap: constants_sigmas_cap.clone(), }; + // Map between gates where not all generators are used and the gate's number of used generators. let incomplete_gates = self .current_slots .values() @@ -750,6 +754,7 @@ impl, const D: usize> CircuitBuilder { .enumerate() .flat_map(|(index, gate)| { let mut gens = gate.gate_ref.0.generators(index, &gate.constants); + // Remove unused generators, if any. if let Some(&op) = incomplete_gates.get(&index) { gens.drain(op..); }