diff --git a/plonky2/src/gadgets/arithmetic_u32.rs b/plonky2/src/gadgets/arithmetic_u32.rs index 649c0624..8a6d7296 100644 --- a/plonky2/src/gadgets/arithmetic_u32.rs +++ b/plonky2/src/gadgets/arithmetic_u32.rs @@ -120,7 +120,8 @@ impl, const D: usize> CircuitBuilder { _ => { let num_addends = to_add.len(); let gate = U32AddManyGate::::new_from_config(&self.config, num_addends); - let (gate_index, copy) = self.find_u32_add_many_gate(num_addends); + let (gate_index, copy) = + self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]); for j in 0..num_addends { self.connect( @@ -153,7 +154,7 @@ impl, const D: usize> CircuitBuilder { let num_addends = to_add.len(); let gate = U32AddManyGate::::new_from_config(&self.config, num_addends); - let (gate_index, copy) = self.find_u32_add_many_gate(num_addends); + let (gate_index, copy) = self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]); for j in 0..num_addends { self.connect( diff --git a/plonky2/src/gadgets/range_check.rs b/plonky2/src/gadgets/range_check.rs index 0776fc68..1aec39ce 100644 --- a/plonky2/src/gadgets/range_check.rs +++ b/plonky2/src/gadgets/range_check.rs @@ -47,7 +47,7 @@ impl, const D: usize> CircuitBuilder { pub fn range_check_u32(&mut self, vals: Vec) { let num_input_limbs = vals.len(); let gate = U32RangeCheckGate::::new(num_input_limbs); - let gate_index = self.add_gate(gate, vec![]); + let gate_index = self.add_gate(gate, vec![], vec![]); for i in 0..num_input_limbs { self.connect( diff --git a/plonky2/src/gates/add_many_u32.rs b/plonky2/src/gates/add_many_u32.rs index 4f9c4293..532dd97a 100644 --- a/plonky2/src/gates/add_many_u32.rs +++ b/plonky2/src/gates/add_many_u32.rs @@ -5,6 +5,7 @@ use plonky2_util::ceil_div_usize; use crate::field::extension_field::Extendable; use crate::field::field_types::Field; +use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -271,6 +272,22 @@ impl, const D: usize> Gate for U32AddManyGate } } +impl, const D: usize> MultiOpsGate for U32AddManyGate { + 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)] struct U32AddManyGenerator, const D: usize> { gate: U32AddManyGate, diff --git a/plonky2/src/gates/arithmetic_u32.rs b/plonky2/src/gates/arithmetic_u32.rs index 6f61b7b4..b4b714f0 100644 --- a/plonky2/src/gates/arithmetic_u32.rs +++ b/plonky2/src/gates/arithmetic_u32.rs @@ -239,11 +239,13 @@ impl, const D: usize> MultiOpsGate for U32Ari } 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)), - ] + U32ArithmeticGenerator { + gate: *self, + gate_index, + i, + _phantom: PhantomData, + } + .dependencies() } } diff --git a/plonky2/src/gates/range_check_u32.rs b/plonky2/src/gates/range_check_u32.rs index 79e91de8..38731189 100644 --- a/plonky2/src/gates/range_check_u32.rs +++ b/plonky2/src/gates/range_check_u32.rs @@ -4,6 +4,7 @@ use plonky2_util::ceil_div_usize; use crate::field::extension_field::Extendable; use crate::field::field_types::Field; +use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -166,6 +167,16 @@ impl, const D: usize> Gate for U32RangeCheckG } } +impl, const D: usize> MultiOpsGate for U32RangeCheckGate { + fn num_ops(&self) -> usize { + 1 + } + + fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec { + unreachable!() + } +} + #[derive(Debug)] pub struct U32RangeCheckGenerator, const D: usize> { gate: U32RangeCheckGate, diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index b5db44a7..e0a4aba2 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -16,7 +16,6 @@ use crate::gadgets::arithmetic::BaseArithmeticOperation; use crate::gadgets::arithmetic_extension::ExtensionArithmeticOperation; use crate::gadgets::arithmetic_u32::U32Target; use crate::gadgets::polynomial::PolynomialCoeffsExtTarget; -use crate::gates::add_many_u32::U32AddManyGate; use crate::gates::arithmetic_base::ArithmeticGate; use crate::gates::arithmetic_extension::ArithmeticExtensionGate; use crate::gates::batchable::{BatchableGate, CurrentSlot, GateRef};