From 0aefe92b8c2704b0613994afd9aa9b4acb10a97c Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Tue, 15 Feb 2022 15:30:34 +0100 Subject: [PATCH] Merge MultiOpsGate into Gate --- insertion/src/insertion_gate.rs | 3 - plonky2/src/gadgets/interpolation.rs | 4 +- plonky2/src/gates/add_many_u32.rs | 3 - plonky2/src/gates/arithmetic_base.rs | 3 - plonky2/src/gates/arithmetic_extension.rs | 5 - plonky2/src/gates/arithmetic_u32.rs | 3 - plonky2/src/gates/assert_le.rs | 3 - plonky2/src/gates/base_sum.rs | 6 +- plonky2/src/gates/batchable.rs | 175 ++++++++---------- plonky2/src/gates/comparison.rs | 3 - plonky2/src/gates/constant.rs | 3 - plonky2/src/gates/exponentiation.rs | 3 - plonky2/src/gates/gate.rs | 90 +++++---- plonky2/src/gates/gate_tree.rs | 2 +- plonky2/src/gates/interpolation.rs | 6 +- plonky2/src/gates/low_degree_interpolation.rs | 5 - plonky2/src/gates/multiplication_extension.rs | 3 - plonky2/src/gates/noop.rs | 3 - plonky2/src/gates/poseidon.rs | 4 +- plonky2/src/gates/poseidon_mds.rs | 6 +- plonky2/src/gates/public_input.rs | 3 - plonky2/src/gates/random_access.rs | 3 - plonky2/src/gates/range_check_u32.rs | 3 - plonky2/src/gates/reducing.rs | 3 - plonky2/src/gates/reducing_extension.rs | 3 - plonky2/src/gates/subtraction_u32.rs | 3 - plonky2/src/gates/switch.rs | 3 - plonky2/src/plonk/circuit_builder.rs | 7 +- 28 files changed, 146 insertions(+), 215 deletions(-) diff --git a/insertion/src/insertion_gate.rs b/insertion/src/insertion_gate.rs index 6fd98307..5b60f13b 100644 --- a/insertion/src/insertion_gate.rs +++ b/insertion/src/insertion_gate.rs @@ -3,7 +3,6 @@ use std::ops::Range; use plonky2::field::extension_field::{Extendable, FieldExtension}; use plonky2::field::field_types::Field; -use plonky2::gates::batchable::MultiOpsGate; use plonky2::gates::gate::Gate; use plonky2::gates::util::StridedConstraintConsumer; use plonky2::hash::hash_types::RichField; @@ -241,9 +240,7 @@ impl, const D: usize> Gate for InsertionGate< fn num_constraints(&self) -> usize { (self.vec_size + 1) * (2 + D) } -} -impl, const D: usize> MultiOpsGate for InsertionGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gadgets/interpolation.rs b/plonky2/src/gadgets/interpolation.rs index 473361aa..9dccd666 100644 --- a/plonky2/src/gadgets/interpolation.rs +++ b/plonky2/src/gadgets/interpolation.rs @@ -2,7 +2,7 @@ use std::ops::Range; use plonky2_field::extension_field::Extendable; -use crate::gates::batchable::BatchableGate; +use crate::gates::gate::Gate; use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; use crate::iop::target::Target; @@ -12,7 +12,7 @@ use crate::plonk::circuit_builder::CircuitBuilder; /// with the given size, and whose values are extension field elements, given by input wires. /// Outputs the evaluation of the interpolant at a given (extension field) evaluation point. pub(crate) trait InterpolationGate, const D: usize>: - BatchableGate + Copy + Gate + Copy { fn new(subgroup_bits: usize) -> Self; diff --git a/plonky2/src/gates/add_many_u32.rs b/plonky2/src/gates/add_many_u32.rs index 532dd97a..3ea52988 100644 --- a/plonky2/src/gates/add_many_u32.rs +++ b/plonky2/src/gates/add_many_u32.rs @@ -5,7 +5,6 @@ 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; @@ -270,9 +269,7 @@ impl, const D: usize> Gate for U32AddManyGate fn num_constraints(&self) -> usize { self.num_ops * (3 + Self::num_limbs()) } -} -impl, const D: usize> MultiOpsGate for U32AddManyGate { fn num_ops(&self) -> usize { self.num_ops } diff --git a/plonky2/src/gates/arithmetic_base.rs b/plonky2/src/gates/arithmetic_base.rs index 006f32ef..7062ef84 100644 --- a/plonky2/src/gates/arithmetic_base.rs +++ b/plonky2/src/gates/arithmetic_base.rs @@ -1,7 +1,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -150,9 +149,7 @@ impl, const D: usize> Gate for ArithmeticGate fn num_constraints(&self) -> usize { self.num_ops } -} -impl, const D: usize> MultiOpsGate for ArithmeticGate { fn num_ops(&self) -> usize { self.num_ops } diff --git a/plonky2/src/gates/arithmetic_extension.rs b/plonky2/src/gates/arithmetic_extension.rs index acb480d5..fcedb6de 100644 --- a/plonky2/src/gates/arithmetic_extension.rs +++ b/plonky2/src/gates/arithmetic_extension.rs @@ -3,7 +3,6 @@ use std::ops::Range; use plonky2_field::extension_field::Extendable; use plonky2_field::extension_field::FieldExtension; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -157,11 +156,7 @@ impl, const D: usize> Gate for ArithmeticExte fn num_constraints(&self) -> usize { self.num_ops * D } -} -impl, const D: usize> MultiOpsGate - for ArithmeticExtensionGate -{ fn num_ops(&self) -> usize { self.num_ops } diff --git a/plonky2/src/gates/arithmetic_u32.rs b/plonky2/src/gates/arithmetic_u32.rs index b4b714f0..1432d20e 100644 --- a/plonky2/src/gates/arithmetic_u32.rs +++ b/plonky2/src/gates/arithmetic_u32.rs @@ -5,7 +5,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::Field; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -231,9 +230,7 @@ impl, const D: usize> Gate for U32ArithmeticG fn num_constraints(&self) -> usize { self.num_ops * (3 + Self::num_limbs()) } -} -impl, const D: usize> MultiOpsGate for U32ArithmeticGate { fn num_ops(&self) -> usize { self.num_ops } diff --git a/plonky2/src/gates/assert_le.rs b/plonky2/src/gates/assert_le.rs index b240df85..08c9c8e3 100644 --- a/plonky2/src/gates/assert_le.rs +++ b/plonky2/src/gates/assert_le.rs @@ -5,7 +5,6 @@ use plonky2_field::field_types::{Field, Field64}; use plonky2_field::packed_field::PackedField; use plonky2_util::{bits_u64, ceil_div_usize}; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -279,9 +278,7 @@ impl, const D: usize> Gate for AssertLessThan fn num_constraints(&self) -> usize { 4 + 5 * self.num_chunks } -} -impl, const D: usize> MultiOpsGate for AssertLessThanGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index c9b0b0f6..be81044a 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -4,7 +4,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::{Field, Field64}; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -135,10 +134,7 @@ impl, const D: usize, const B: usize> Gate fo fn num_constraints(&self) -> usize { 1 + self.num_limbs } -} -impl, const D: usize, const B: usize> MultiOpsGate - for BaseSumGate -{ + fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/batchable.rs b/plonky2/src/gates/batchable.rs index c37cd2c8..20ab39f3 100644 --- a/plonky2/src/gates/batchable.rs +++ b/plonky2/src/gates/batchable.rs @@ -1,101 +1,80 @@ -use std::collections::HashMap; -use std::fmt::{Debug, Error, Formatter}; -use std::hash::{Hash, Hasher}; -use std::sync::Arc; - -use plonky2_field::extension_field::Extendable; - -use crate::gates::gate::Gate; -use crate::hash::hash_types::RichField; -use crate::iop::target::Target; -use crate::plonk::circuit_builder::CircuitBuilder; - -pub trait BatchableGate, const D: usize>: Gate { - fn num_ops(&self) -> usize; - - // TODO: It would be nice to have a `Parameters` associated type. - fn fill_gate( - &self, - params: &[F], - current_slot: &CurrentSlot, - builder: &mut CircuitBuilder, - ); -} - -#[derive(Clone, Debug)] -pub struct CurrentSlot, const D: usize> { - pub current_slot: HashMap, (usize, usize)>, -} - -#[derive(Clone)] -pub struct GateRef, const D: usize>( - pub(crate) Arc>, -); - -impl, const D: usize> GateRef { - pub fn new>(gate: G) -> GateRef { - GateRef(Arc::new(gate)) - } -} - -impl, const D: usize> PartialEq for GateRef { - fn eq(&self, other: &Self) -> bool { - self.0.id() == other.0.id() - } -} - -impl, const D: usize> Hash for GateRef { - fn hash(&self, state: &mut H) { - self.0.id().hash(state) - } -} - -impl, const D: usize> Eq for GateRef {} - -impl, const D: usize> Debug for GateRef { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { - write!(f, "{}", self.0.id()) - } -} - -// pub trait SingleOpGate, const D: usize>: Gate {} -// impl, G: SingleOpGate, const D: usize> MultiOpsGate for G { -// fn num_ops(&self) -> usize { -// 1 -// } +// use std::collections::HashMap; +// use std::fmt::{Debug, Error, Formatter}; +// use std::hash::{Hash, Hasher}; +// use std::sync::Arc; // -// fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { -// unreachable!() +// use plonky2_field::extension_field::Extendable; +// +// use crate::gates::gate::Gate; +// use crate::hash::hash_types::RichField; +// use crate::iop::target::Target; +// use crate::plonk::circuit_builder::CircuitBuilder; +// +// pub trait BatchableGate, const D: usize>: Gate { +// fn num_ops(&self) -> usize; +// +// // TODO: It would be nice to have a `Parameters` associated type. +// fn fill_gate( +// &self, +// params: &[F], +// current_slot: &CurrentSlot, +// builder: &mut CircuitBuilder, +// ); +// } +// +// #[derive(Clone, Debug)] +// pub struct CurrentSlot, const D: usize> { +// pub current_slot: HashMap, (usize, usize)>, +// } +// +// #[derive(Clone)] +// pub struct GateRef, const D: usize>( +// pub(crate) Arc>, +// ); +// +// impl, const D: usize> GateRef { +// pub fn new>(gate: G) -> GateRef { +// GateRef(Arc::new(gate)) +// } +// } +// +// impl, const D: usize> PartialEq for GateRef { +// fn eq(&self, other: &Self) -> bool { +// self.0.id() == other.0.id() +// } +// } +// +// impl, const D: usize> Hash for GateRef { +// fn hash(&self, state: &mut H) { +// self.0.id().hash(state) +// } +// } +// +// impl, const D: usize> Eq for GateRef {} +// +// impl, const D: usize> Debug for GateRef { +// fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { +// write!(f, "{}", self.0.id()) +// } +// } +// +// // pub trait SingleOpGate, const D: usize>: Gate {} +// // impl, G: SingleOpGate, const D: usize> MultiOpsGate for G { +// // fn num_ops(&self) -> usize { +// // 1 +// // } +// // +// // fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec { +// // unreachable!() +// // } +// // } +// +// pub trait MultiOpsGate, const D: usize>: Gate {} +// +// impl, G: MultiOpsGate, const D: usize> BatchableGate +// for G +// { +// fn num_ops(&self) -> usize { +// self.num_ops() // } // } - -pub trait MultiOpsGate, const D: usize>: Gate { - fn num_ops(&self) -> usize; - - fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec; -} - -impl, G: MultiOpsGate, const D: usize> BatchableGate - for G -{ - fn num_ops(&self) -> usize { - self.num_ops() - } - - fn fill_gate( - &self, - params: &[F], - current_slot: &CurrentSlot, - builder: &mut CircuitBuilder, - ) { - dbg!(self.id(), ¤t_slot, params); - 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); - } - } - } - } -} diff --git a/plonky2/src/gates/comparison.rs b/plonky2/src/gates/comparison.rs index b64a5394..00e7f4d3 100644 --- a/plonky2/src/gates/comparison.rs +++ b/plonky2/src/gates/comparison.rs @@ -5,7 +5,6 @@ use plonky2_field::field_types::{Field, Field64}; use plonky2_field::packed_field::PackedField; use plonky2_util::{bits_u64, ceil_div_usize}; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -312,9 +311,7 @@ impl, const D: usize> Gate for ComparisonGate fn num_constraints(&self) -> usize { 6 + 5 * self.num_chunks + self.chunk_bits() } -} -impl, const D: usize> MultiOpsGate for ComparisonGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/constant.rs b/plonky2/src/gates/constant.rs index e813d573..455e5349 100644 --- a/plonky2/src/gates/constant.rs +++ b/plonky2/src/gates/constant.rs @@ -4,7 +4,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::Field; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -101,9 +100,7 @@ impl, const D: usize> Gate for ConstantGate { fn num_constraints(&self) -> usize { self.num_consts } -} -impl, const D: usize> MultiOpsGate for ConstantGate { fn num_ops(&self) -> usize { self.num_consts } diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index 9803181a..fd37249f 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -5,7 +5,6 @@ use plonky2_field::field_types::Field; use plonky2_field::ops::Square; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -189,9 +188,7 @@ impl, const D: usize> Gate for Exponentiation fn num_constraints(&self) -> usize { self.num_power_bits + 1 } -} -impl, const D: usize> MultiOpsGate for ExponentiationGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 5e9f28a8..391533a7 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -1,15 +1,18 @@ -use std::fmt::Debug; +use std::collections::HashMap; +use std::fmt::{Debug, Error, Formatter}; +use std::hash::{Hash, Hasher}; +use std::sync::Arc; use plonky2_field::batch_util::batch_multiply_inplace; use plonky2_field::extension_field::{Extendable, FieldExtension}; use plonky2_field::field_types::Field; -use crate::gates::batchable::GateRef; use crate::gates::gate_tree::Tree; 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, @@ -138,37 +141,62 @@ pub trait Gate, const D: usize>: 'static + Send + S fn degree(&self) -> usize; fn num_constraints(&self) -> usize; + + fn num_ops(&self) -> usize; + + fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec; + + 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); + } + } + } + } } -// /// A wrapper around an `Rc` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs. -// #[derive(Clone)] -// pub struct GateRef, const D: usize>(pub(crate) Arc>); -// -// impl, const D: usize> GateRef { -// pub fn new>(gate: G) -> GateRef { -// GateRef(Arc::new(gate)) -// } -// } -// -// impl, const D: usize> PartialEq for GateRef { -// fn eq(&self, other: &Self) -> bool { -// self.0.id() == other.0.id() -// } -// } -// -// impl, const D: usize> Hash for GateRef { -// fn hash(&self, state: &mut H) { -// self.0.id().hash(state) -// } -// } -// -// impl, const D: usize> Eq for GateRef {} -// -// impl, const D: usize> Debug for GateRef { -// fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { -// write!(f, "{}", self.0.id()) -// } -// } +/// A wrapper around an `Rc` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs. +#[derive(Clone)] +pub struct GateRef, const D: usize>(pub(crate) Arc>); + +impl, const D: usize> GateRef { + pub fn new>(gate: G) -> GateRef { + GateRef(Arc::new(gate)) + } +} + +impl, const D: usize> PartialEq for GateRef { + fn eq(&self, other: &Self) -> bool { + self.0.id() == other.0.id() + } +} + +impl, const D: usize> Hash for GateRef { + fn hash(&self, state: &mut H) { + self.0.id().hash(state) + } +} + +impl, const D: usize> Eq for GateRef {} + +impl, const D: usize> Debug for GateRef { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { + write!(f, "{}", self.0.id()) + } +} + +#[derive(Clone, Debug)] +pub struct CurrentSlot, const D: usize> { + pub current_slot: HashMap, (usize, usize)>, +} /// A gate along with any constants used to configure it. #[derive(Clone)] diff --git a/plonky2/src/gates/gate_tree.rs b/plonky2/src/gates/gate_tree.rs index 66161333..2f670337 100644 --- a/plonky2/src/gates/gate_tree.rs +++ b/plonky2/src/gates/gate_tree.rs @@ -1,7 +1,7 @@ use log::debug; use plonky2_field::extension_field::Extendable; -use crate::gates::batchable::GateRef; +use crate::gates::gate::GateRef; use crate::hash::hash_types::RichField; /// A binary tree where leaves hold some type `T` and other nodes are empty. diff --git a/plonky2/src/gates/interpolation.rs b/plonky2/src/gates/interpolation.rs index c8743050..0edb7276 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -8,7 +8,6 @@ use plonky2_field::polynomial::PolynomialCoeffs; use crate::gadgets::interpolation::InterpolationGate; use crate::gadgets::polynomial::PolynomialCoeffsExtAlgebraTarget; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -202,10 +201,7 @@ impl, const D: usize> Gate // point-value pairs, plus D constraints for the evaluation value. self.num_points() * D + D } -} -impl, const D: usize> MultiOpsGate - for HighDegreeInterpolationGate -{ + fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 8e7d91c8..3821d5f1 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -9,7 +9,6 @@ use plonky2_field::polynomial::PolynomialCoeffs; use crate::gadgets::interpolation::InterpolationGate; use crate::gadgets::polynomial::PolynomialCoeffsExtAlgebraTarget; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -293,11 +292,7 @@ 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) } -} -impl, const D: usize> MultiOpsGate - for LowDegreeInterpolationGate -{ fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index 02e93eb1..d4dd8645 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -3,7 +3,6 @@ use std::ops::Range; use plonky2_field::extension_field::Extendable; use plonky2_field::extension_field::FieldExtension; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -144,9 +143,7 @@ impl, const D: usize> Gate for MulExtensionGa fn num_constraints(&self) -> usize { self.num_ops * D } -} -impl, const D: usize> MultiOpsGate for MulExtensionGate { fn num_ops(&self) -> usize { self.num_ops } diff --git a/plonky2/src/gates/noop.rs b/plonky2/src/gates/noop.rs index 5de05991..e9507a31 100644 --- a/plonky2/src/gates/noop.rs +++ b/plonky2/src/gates/noop.rs @@ -1,6 +1,5 @@ use plonky2_field::extension_field::Extendable; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; @@ -56,9 +55,7 @@ impl, const D: usize> Gate for NoopGate { fn num_constraints(&self) -> usize { 0 } -} -impl, const D: usize> MultiOpsGate for NoopGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index 82fedcbb..4a5f119a 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -3,7 +3,6 @@ use std::marker::PhantomData; use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::Field; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::poseidon_mds::PoseidonMdsGate; use crate::gates::util::StridedConstraintConsumer; @@ -406,8 +405,7 @@ impl, const D: usize> Gate for PoseidonGate, const D: usize> MultiOpsGate for PoseidonGate { + fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index ad899599..772059ce 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -6,7 +6,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::extension_field::FieldExtension; use plonky2_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; @@ -196,10 +195,7 @@ impl + Poseidon, const D: usize> Gate for Pos fn num_constraints(&self) -> usize { SPONGE_WIDTH * D } -} -impl + Poseidon, const D: usize> MultiOpsGate - for PoseidonMdsGate -{ + fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/public_input.rs b/plonky2/src/gates/public_input.rs index 85145e31..e7e37663 100644 --- a/plonky2/src/gates/public_input.rs +++ b/plonky2/src/gates/public_input.rs @@ -3,7 +3,6 @@ use std::ops::Range; use plonky2_field::extension_field::Extendable; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -87,9 +86,7 @@ impl, const D: usize> Gate for PublicInputGat fn num_constraints(&self) -> usize { 4 } -} -impl, const D: usize> MultiOpsGate for PublicInputGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index 4a17aae8..6579b590 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -5,7 +5,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::Field; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -229,9 +228,7 @@ impl, const D: usize> Gate for RandomAccessGa let constraints_per_copy = self.bits + 2; self.num_copies * constraints_per_copy } -} -impl, const D: usize> MultiOpsGate for RandomAccessGate { fn num_ops(&self) -> usize { self.num_copies } diff --git a/plonky2/src/gates/range_check_u32.rs b/plonky2/src/gates/range_check_u32.rs index 38731189..73cc0d98 100644 --- a/plonky2/src/gates/range_check_u32.rs +++ b/plonky2/src/gates/range_check_u32.rs @@ -4,7 +4,6 @@ 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; @@ -165,9 +164,7 @@ impl, const D: usize> Gate for U32RangeCheckG fn num_constraints(&self) -> usize { self.num_input_limbs * (1 + self.aux_limbs_per_input_limb()) } -} -impl, const D: usize> MultiOpsGate for U32RangeCheckGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index cf07d3a7..c53609de 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -3,7 +3,6 @@ use std::ops::Range; use plonky2_field::extension_field::Extendable; use plonky2_field::extension_field::FieldExtension; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -165,9 +164,7 @@ impl, const D: usize> Gate for ReducingGate usize { D * self.num_coeffs } -} -impl, const D: usize> MultiOpsGate for ReducingGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index 65eec526..c455a5cd 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -3,7 +3,6 @@ use std::ops::Range; use plonky2_field::extension_field::Extendable; use plonky2_field::extension_field::FieldExtension; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::util::StridedConstraintConsumer; use crate::hash::hash_types::RichField; @@ -165,9 +164,7 @@ impl, const D: usize> Gate for ReducingExtens fn num_constraints(&self) -> usize { D * self.num_coeffs } -} -impl, const D: usize> MultiOpsGate for ReducingExtensionGate { fn num_ops(&self) -> usize { 1 } diff --git a/plonky2/src/gates/subtraction_u32.rs b/plonky2/src/gates/subtraction_u32.rs index a37648c4..03e8d652 100644 --- a/plonky2/src/gates/subtraction_u32.rs +++ b/plonky2/src/gates/subtraction_u32.rs @@ -4,7 +4,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::Field; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -220,9 +219,7 @@ impl, const D: usize> Gate for U32Subtraction fn num_constraints(&self) -> usize { self.num_ops * (3 + Self::num_limbs()) } -} -impl, const D: usize> MultiOpsGate for U32SubtractionGate { fn num_ops(&self) -> usize { self.num_ops } diff --git a/plonky2/src/gates/switch.rs b/plonky2/src/gates/switch.rs index ae4419df..f5fb8828 100644 --- a/plonky2/src/gates/switch.rs +++ b/plonky2/src/gates/switch.rs @@ -5,7 +5,6 @@ use plonky2_field::extension_field::Extendable; use plonky2_field::field_types::Field; use plonky2_field::packed_field::PackedField; -use crate::gates::batchable::MultiOpsGate; use crate::gates::gate::Gate; use crate::gates::packed_util::PackedEvaluableBase; use crate::gates::util::StridedConstraintConsumer; @@ -188,9 +187,7 @@ impl, const D: usize> Gate for SwitchGate usize { 4 * self.num_copies * self.chunk_size } -} -impl, const D: usize> MultiOpsGate for SwitchGate { fn num_ops(&self) -> usize { self.num_copies } diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index e0a4aba2..c749ba4e 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -18,9 +18,8 @@ use crate::gadgets::arithmetic_u32::U32Target; use crate::gadgets::polynomial::PolynomialCoeffsExtTarget; use crate::gates::arithmetic_base::ArithmeticGate; use crate::gates::arithmetic_extension::ArithmeticExtensionGate; -use crate::gates::batchable::{BatchableGate, CurrentSlot, GateRef}; use crate::gates::constant::ConstantGate; -use crate::gates::gate::{Gate, GateInstance, PrefixedGate}; +use crate::gates::gate::{CurrentSlot, Gate, GateInstance, GateRef, PrefixedGate}; use crate::gates::gate_tree::Tree; use crate::gates::noop::NoopGate; use crate::gates::public_input::PublicInputGate; @@ -206,7 +205,7 @@ impl, const D: usize> CircuitBuilder { } /// Adds a gate to the circuit, and returns its index. - pub fn add_gate>( + pub fn add_gate>( &mut self, gate_type: G, constants: Vec, @@ -398,7 +397,7 @@ impl, const D: usize> CircuitBuilder { }) } - pub fn find_slot + Clone>( + pub fn find_slot + Clone>( &mut self, gate: G, params: &[F],