diff --git a/insertion/src/insertion_gate.rs b/insertion/src/insertion_gate.rs index 5b60f13b..442416d3 100644 --- a/insertion/src/insertion_gate.rs +++ b/insertion/src/insertion_gate.rs @@ -240,14 +240,6 @@ impl, const D: usize> Gate for InsertionGate< fn num_constraints(&self) -> usize { (self.vec_size + 1) * (2 + D) } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/add_many_u32.rs b/plonky2/src/gates/add_many_u32.rs index 3ea52988..4f9c4293 100644 --- a/plonky2/src/gates/add_many_u32.rs +++ b/plonky2/src/gates/add_many_u32.rs @@ -269,20 +269,6 @@ impl, const D: usize> Gate for U32AddManyGate fn num_constraints(&self) -> usize { self.num_ops * (3 + Self::num_limbs()) } - - fn num_ops(&self) -> usize { - self.num_ops - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - U32AddManyGenerator { - gate: *self, - gate_index, - i, - _phantom: PhantomData, - } - .dependencies() - } } #[derive(Clone, Debug)] diff --git a/plonky2/src/gates/arithmetic_base.rs b/plonky2/src/gates/arithmetic_base.rs index 7062ef84..5f73fef0 100644 --- a/plonky2/src/gates/arithmetic_base.rs +++ b/plonky2/src/gates/arithmetic_base.rs @@ -149,18 +149,6 @@ impl, const D: usize> Gate for ArithmeticGate fn num_constraints(&self) -> usize { self.num_ops } - - fn num_ops(&self) -> usize { - self.num_ops - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - vec![ - Target::wire(gate_index, Self::wire_ith_multiplicand_0(i)), - Target::wire(gate_index, Self::wire_ith_multiplicand_1(i)), - Target::wire(gate_index, Self::wire_ith_addend(i)), - ] - } } impl, const D: usize> PackedEvaluableBase for ArithmeticGate { diff --git a/plonky2/src/gates/arithmetic_extension.rs b/plonky2/src/gates/arithmetic_extension.rs index fcedb6de..6b5af067 100644 --- a/plonky2/src/gates/arithmetic_extension.rs +++ b/plonky2/src/gates/arithmetic_extension.rs @@ -156,19 +156,6 @@ impl, const D: usize> Gate for ArithmeticExte fn num_constraints(&self) -> usize { self.num_ops * D } - - fn num_ops(&self) -> usize { - self.num_ops - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - [ - ExtensionTarget::::from_range(gate_index, Self::wires_ith_multiplicand_0(i)).0, - ExtensionTarget::::from_range(gate_index, Self::wires_ith_multiplicand_1(i)).0, - ExtensionTarget::::from_range(gate_index, Self::wires_ith_addend(i)).0, - ] - .concat() - } } #[derive(Clone, Debug)] diff --git a/plonky2/src/gates/arithmetic_u32.rs b/plonky2/src/gates/arithmetic_u32.rs index 1432d20e..dc03e296 100644 --- a/plonky2/src/gates/arithmetic_u32.rs +++ b/plonky2/src/gates/arithmetic_u32.rs @@ -230,20 +230,6 @@ impl, const D: usize> Gate for U32ArithmeticG fn num_constraints(&self) -> usize { self.num_ops * (3 + Self::num_limbs()) } - - fn num_ops(&self) -> usize { - self.num_ops - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - U32ArithmeticGenerator { - gate: *self, - gate_index, - i, - _phantom: PhantomData, - } - .dependencies() - } } impl, const D: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/assert_le.rs b/plonky2/src/gates/assert_le.rs index 08c9c8e3..cec7274b 100644 --- a/plonky2/src/gates/assert_le.rs +++ b/plonky2/src/gates/assert_le.rs @@ -278,14 +278,6 @@ impl, const D: usize> Gate for AssertLessThan fn num_constraints(&self) -> usize { 4 + 5 * self.num_chunks } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } impl, const D: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index be81044a..e03a2c5b 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -134,14 +134,6 @@ impl, const D: usize, const B: usize> Gate fo fn num_constraints(&self) -> usize { 1 + self.num_limbs } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } impl, const D: usize, const B: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/comparison.rs b/plonky2/src/gates/comparison.rs index 4a68adb7..b1cf7b98 100644 --- a/plonky2/src/gates/comparison.rs +++ b/plonky2/src/gates/comparison.rs @@ -311,14 +311,6 @@ impl, const D: usize> Gate for ComparisonGate fn num_constraints(&self) -> usize { 6 + 5 * self.num_chunks + self.chunk_bits() } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } impl, const D: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/constant.rs b/plonky2/src/gates/constant.rs index d62befc4..990a4df8 100644 --- a/plonky2/src/gates/constant.rs +++ b/plonky2/src/gates/constant.rs @@ -111,14 +111,6 @@ impl, const D: usize> Gate for ConstantGate { fn num_constraints(&self) -> usize { self.num_consts } - - fn num_ops(&self) -> usize { - self.num_consts - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - vec![] - } } impl, const D: usize> PackedEvaluableBase for ConstantGate { diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index fd37249f..51558a21 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -188,14 +188,6 @@ impl, const D: usize> Gate for Exponentiation fn num_constraints(&self) -> usize { self.num_power_bits + 1 } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } impl, const D: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 1d487db7..1d6a0e3d 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -12,7 +12,6 @@ use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; use crate::iop::generator::WitnessGenerator; -use crate::iop::target::Target; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::vars::{ EvaluationTargets, EvaluationVars, EvaluationVarsBase, EvaluationVarsBaseBatch, @@ -143,26 +142,8 @@ pub trait Gate, const D: usize>: 'static + Send + S fn num_constraints(&self) -> usize; /// Number of operations performed by the gate. - fn num_ops(&self) -> usize; - - /// Dependencies (inputs) for the i-th operation. - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec; - - /// Fill the dependencies of the - fn fill_gate( - &self, - params: &[F], - current_slot: &CurrentSlot, - builder: &mut CircuitBuilder, - ) { - if let Some(&(gate_index, op)) = current_slot.current_slot.get(params) { - let zero = builder.zero(); - for i in op..self.num_ops() { - for dep in self.dependencies_ith_op(gate_index, i) { - builder.connect(dep, zero); - } - } - } + fn num_ops(&self) -> usize { + self.generators(0, &[F::ZERO; 100]).len() } } diff --git a/plonky2/src/gates/interpolation.rs b/plonky2/src/gates/interpolation.rs index 0edb7276..46c42113 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -201,14 +201,6 @@ impl, const D: usize> Gate // point-value pairs, plus D constraints for the evaluation value. self.num_points() * D + D } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 3821d5f1..845da5ab 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -292,14 +292,6 @@ impl, const D: usize> Gate for LowDegreeInter // to check power constraints for evaluation point and shift. self.num_points() * D + D + (D + 1) * (self.num_points() - 2) } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index d4dd8645..09701260 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -143,18 +143,6 @@ impl, const D: usize> Gate for MulExtensionGa fn num_constraints(&self) -> usize { self.num_ops * D } - - fn num_ops(&self) -> usize { - self.num_ops - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - [ - ExtensionTarget::::from_range(gate_index, Self::wires_ith_multiplicand_0(i)).0, - ExtensionTarget::::from_range(gate_index, Self::wires_ith_multiplicand_1(i)).0, - ] - .concat() - } } #[derive(Clone, Debug)] diff --git a/plonky2/src/gates/noop.rs b/plonky2/src/gates/noop.rs index 5ef7c318..4cd872d8 100644 --- a/plonky2/src/gates/noop.rs +++ b/plonky2/src/gates/noop.rs @@ -4,7 +4,6 @@ use crate::gates::gate::Gate; use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; use crate::iop::generator::WitnessGenerator; -use crate::iop::target::Target; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBaseBatch}; @@ -55,14 +54,6 @@ impl, const D: usize> Gate for NoopGate { fn num_constraints(&self) -> usize { 0 } - - fn num_ops(&self) -> usize { - 0 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[cfg(test)] diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index 4a5f119a..29971c23 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -405,14 +405,6 @@ impl, const D: usize> Gate for PoseidonGate usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index 772059ce..81583f88 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -195,14 +195,6 @@ impl + Poseidon, const D: usize> Gate for Pos fn num_constraints(&self) -> usize { SPONGE_WIDTH * D } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Clone, Debug)] diff --git a/plonky2/src/gates/public_input.rs b/plonky2/src/gates/public_input.rs index e7e37663..20fc59c8 100644 --- a/plonky2/src/gates/public_input.rs +++ b/plonky2/src/gates/public_input.rs @@ -9,7 +9,6 @@ use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; use crate::iop::generator::WitnessGenerator; -use crate::iop::target::Target; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::vars::{ EvaluationTargets, EvaluationVars, EvaluationVarsBase, EvaluationVarsBaseBatch, @@ -86,14 +85,6 @@ impl, const D: usize> Gate for PublicInputGat fn num_constraints(&self) -> usize { 4 } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } impl, const D: usize> PackedEvaluableBase for PublicInputGate { diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index 6579b590..6379f99f 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -228,19 +228,6 @@ impl, const D: usize> Gate for RandomAccessGa let constraints_per_copy = self.bits + 2; self.num_copies * constraints_per_copy } - - fn num_ops(&self) -> usize { - self.num_copies - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - RandomAccessGenerator { - gate_index, - gate: *self, - copy: i, - } - .dependencies() - } } impl, const D: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/range_check_u32.rs b/plonky2/src/gates/range_check_u32.rs index 73cc0d98..79e91de8 100644 --- a/plonky2/src/gates/range_check_u32.rs +++ b/plonky2/src/gates/range_check_u32.rs @@ -164,14 +164,6 @@ impl, const D: usize> Gate for U32RangeCheckG fn num_constraints(&self) -> usize { self.num_input_limbs * (1 + self.aux_limbs_per_input_limb()) } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index c53609de..2abf8425 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -164,14 +164,6 @@ impl, const D: usize> Gate for ReducingGate usize { D * self.num_coeffs } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index c455a5cd..6655f1d7 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -164,14 +164,6 @@ impl, const D: usize> Gate for ReducingExtens fn num_constraints(&self) -> usize { D * self.num_coeffs } - - fn num_ops(&self) -> usize { - 1 - } - - fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { - unreachable!() - } } #[derive(Debug)] diff --git a/plonky2/src/gates/subtraction_u32.rs b/plonky2/src/gates/subtraction_u32.rs index 03e8d652..b1e4d84f 100644 --- a/plonky2/src/gates/subtraction_u32.rs +++ b/plonky2/src/gates/subtraction_u32.rs @@ -219,20 +219,6 @@ impl, const D: usize> Gate for U32Subtraction fn num_constraints(&self) -> usize { self.num_ops * (3 + Self::num_limbs()) } - - fn num_ops(&self) -> usize { - self.num_ops - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - U32SubtractionGenerator { - gate: *self, - gate_index, - i, - _phantom: Default::default(), - } - .dependencies() - } } impl, const D: usize> PackedEvaluableBase diff --git a/plonky2/src/gates/switch.rs b/plonky2/src/gates/switch.rs index f5fb8828..bd298762 100644 --- a/plonky2/src/gates/switch.rs +++ b/plonky2/src/gates/switch.rs @@ -187,19 +187,6 @@ impl, const D: usize> Gate for SwitchGate usize { 4 * self.num_copies * self.chunk_size } - - fn num_ops(&self) -> usize { - self.num_copies - } - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { - SwitchGenerator:: { - gate_index, - gate: *self, - copy: i, - } - .watch_list() - } } impl, const D: usize> PackedEvaluableBase for SwitchGate { diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index a46ddb4e..aa4c67be 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -662,8 +662,6 @@ impl, const D: usize> CircuitBuilder { let start = Instant::now(); let rate_bits = self.config.fri_config.rate_bits; - self.fill_batched_gates(); - // Hash the public inputs, and route them to a `PublicInputGate` which will enforce that // those hash wires match the claimed public inputs. let num_public_inputs = self.public_inputs.len(); @@ -739,12 +737,24 @@ impl, const D: usize> CircuitBuilder { constants_sigmas_cap: constants_sigmas_cap.clone(), }; + let incomplete_gates = self + .current_slots + .values() + .flat_map(|current_slot| current_slot.current_slot.values().copied()) + .collect::>(); + // Add gate generators. self.add_generators( self.gate_instances .iter() .enumerate() - .flat_map(|(index, gate)| gate.gate_ref.0.generators(index, &gate.constants)) + .flat_map(|(index, gate)| { + let mut gens = gate.gate_ref.0.generators(index, &gate.constants); + if let Some(&op) = incomplete_gates.get(&index) { + gens.drain(op..); + } + gens + }) .collect(), ); @@ -856,15 +866,3 @@ impl, const D: usize> CircuitBuilder { } } } - -impl, const D: usize> CircuitBuilder { - fn fill_batched_gates(&mut self) { - let instances = self.gate_instances.clone(); - for gate in instances { - if let Some(slot) = self.current_slots.get(&gate.gate_ref) { - let cloned = slot.clone(); - gate.gate_ref.0.fill_gate(&gate.params, &cloned, self); - } - } - } -}