Merge MultiOpsGate into Gate

This commit is contained in:
wborgeaud 2022-02-15 15:30:34 +01:00
parent 5e3177520b
commit 0aefe92b8c
28 changed files with 146 additions and 215 deletions

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for InsertionGate<
fn num_constraints(&self) -> usize {
(self.vec_size + 1) * (2 + D)
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for InsertionGate<F, D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize>:
BatchableGate<F, D> + Copy
Gate<F, D> + Copy
{
fn new(subgroup_bits: usize) -> Self;

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32AddManyGate
fn num_constraints(&self) -> usize {
self.num_ops * (3 + Self::num_limbs())
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for U32AddManyGate<F, D> {
fn num_ops(&self) -> usize {
self.num_ops
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticGate
fn num_constraints(&self) -> usize {
self.num_ops
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for ArithmeticGate {
fn num_ops(&self) -> usize {
self.num_ops
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
fn num_constraints(&self) -> usize {
self.num_ops * D
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D>
for ArithmeticExtensionGate<D>
{
fn num_ops(&self) -> usize {
self.num_ops
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32ArithmeticG
fn num_constraints(&self) -> usize {
self.num_ops * (3 + Self::num_limbs())
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for U32ArithmeticGate<F, D> {
fn num_ops(&self) -> usize {
self.num_ops
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for AssertLessThan
fn num_constraints(&self) -> usize {
4 + 5 * self.num_chunks
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for AssertLessThanGate<F, D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize, const B: usize> Gate<F, D> fo
fn num_constraints(&self) -> usize {
1 + self.num_limbs
}
}
impl<F: RichField + Extendable<D>, const D: usize, const B: usize> MultiOpsGate<F, D>
for BaseSumGate<B>
{
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize>: Gate<F, D> {
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<F, D>,
builder: &mut CircuitBuilder<F, D>,
);
}
#[derive(Clone, Debug)]
pub struct CurrentSlot<F: RichField + Extendable<D>, const D: usize> {
pub current_slot: HashMap<Vec<F>, (usize, usize)>,
}
#[derive(Clone)]
pub struct GateRef<F: RichField + Extendable<D>, const D: usize>(
pub(crate) Arc<dyn BatchableGate<F, D>>,
);
impl<F: RichField + Extendable<D>, const D: usize> GateRef<F, D> {
pub fn new<G: BatchableGate<F, D>>(gate: G) -> GateRef<F, D> {
GateRef(Arc::new(gate))
}
}
impl<F: RichField + Extendable<D>, const D: usize> PartialEq for GateRef<F, D> {
fn eq(&self, other: &Self) -> bool {
self.0.id() == other.0.id()
}
}
impl<F: RichField + Extendable<D>, const D: usize> Hash for GateRef<F, D> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.id().hash(state)
}
}
impl<F: RichField + Extendable<D>, const D: usize> Eq for GateRef<F, D> {}
impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
write!(f, "{}", self.0.id())
}
}
// pub trait SingleOpGate<F: RichField + Extendable<D>, const D: usize>: Gate<F, D> {}
// impl<F: RichField + Extendable<D>, G: SingleOpGate<F, D>, const D: usize> MultiOpsGate<F, D> 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<Target> {
// 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<F: RichField + Extendable<D>, const D: usize>: Gate<F, D> {
// 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<F, D>,
// builder: &mut CircuitBuilder<F, D>,
// );
// }
//
// #[derive(Clone, Debug)]
// pub struct CurrentSlot<F: RichField + Extendable<D>, const D: usize> {
// pub current_slot: HashMap<Vec<F>, (usize, usize)>,
// }
//
// #[derive(Clone)]
// pub struct GateRef<F: RichField + Extendable<D>, const D: usize>(
// pub(crate) Arc<dyn BatchableGate<F, D>>,
// );
//
// impl<F: RichField + Extendable<D>, const D: usize> GateRef<F, D> {
// pub fn new<G: BatchableGate<F, D>>(gate: G) -> GateRef<F, D> {
// GateRef(Arc::new(gate))
// }
// }
//
// impl<F: RichField + Extendable<D>, const D: usize> PartialEq for GateRef<F, D> {
// fn eq(&self, other: &Self) -> bool {
// self.0.id() == other.0.id()
// }
// }
//
// impl<F: RichField + Extendable<D>, const D: usize> Hash for GateRef<F, D> {
// fn hash<H: Hasher>(&self, state: &mut H) {
// self.0.id().hash(state)
// }
// }
//
// impl<F: RichField + Extendable<D>, const D: usize> Eq for GateRef<F, D> {}
//
// impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
// fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
// write!(f, "{}", self.0.id())
// }
// }
//
// // pub trait SingleOpGate<F: RichField + Extendable<D>, const D: usize>: Gate<F, D> {}
// // impl<F: RichField + Extendable<D>, G: SingleOpGate<F, D>, const D: usize> MultiOpsGate<F, D> for G {
// // fn num_ops(&self) -> usize {
// // 1
// // }
// //
// // fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target> {
// // unreachable!()
// // }
// // }
//
// pub trait MultiOpsGate<F: RichField + Extendable<D>, const D: usize>: Gate<F, D> {}
//
// impl<F: RichField + Extendable<D>, G: MultiOpsGate<F, D>, const D: usize> BatchableGate<F, D>
// for G
// {
// fn num_ops(&self) -> usize {
// self.num_ops()
// }
// }
pub trait MultiOpsGate<F: RichField + Extendable<D>, const D: usize>: Gate<F, D> {
fn num_ops(&self) -> usize;
fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target>;
}
impl<F: RichField + Extendable<D>, G: MultiOpsGate<F, D>, const D: usize> BatchableGate<F, D>
for G
{
fn num_ops(&self) -> usize {
self.num_ops()
}
fn fill_gate(
&self,
params: &[F],
current_slot: &CurrentSlot<F, D>,
builder: &mut CircuitBuilder<F, D>,
) {
dbg!(self.id(), &current_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);
}
}
}
}
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate
fn num_constraints(&self) -> usize {
6 + 5 * self.num_chunks + self.chunk_bits()
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for ComparisonGate<F, D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
fn num_constraints(&self) -> usize {
self.num_consts
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for ConstantGate {
fn num_ops(&self) -> usize {
self.num_consts
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for Exponentiation
fn num_constraints(&self) -> usize {
self.num_power_bits + 1
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for ExponentiationGate<F, D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, 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<Target>;
fn fill_gate(
&self,
params: &[F],
current_slot: &CurrentSlot<F, D>,
builder: &mut CircuitBuilder<F, D>,
) {
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<Gate>` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs.
// #[derive(Clone)]
// pub struct GateRef<F: RichField + Extendable<D>, const D: usize>(pub(crate) Arc<dyn Gate<F, D>>);
//
// impl<F: RichField + Extendable<D>, const D: usize> GateRef<F, D> {
// pub fn new<G: Gate<F, D>>(gate: G) -> GateRef<F, D> {
// GateRef(Arc::new(gate))
// }
// }
//
// impl<F: RichField + Extendable<D>, const D: usize> PartialEq for GateRef<F, D> {
// fn eq(&self, other: &Self) -> bool {
// self.0.id() == other.0.id()
// }
// }
//
// impl<F: RichField + Extendable<D>, const D: usize> Hash for GateRef<F, D> {
// fn hash<H: Hasher>(&self, state: &mut H) {
// self.0.id().hash(state)
// }
// }
//
// impl<F: RichField + Extendable<D>, const D: usize> Eq for GateRef<F, D> {}
//
// impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
// fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
// write!(f, "{}", self.0.id())
// }
// }
/// A wrapper around an `Rc<Gate>` which implements `PartialEq`, `Eq` and `Hash` based on gate IDs.
#[derive(Clone)]
pub struct GateRef<F: RichField + Extendable<D>, const D: usize>(pub(crate) Arc<dyn Gate<F, D>>);
impl<F: RichField + Extendable<D>, const D: usize> GateRef<F, D> {
pub fn new<G: Gate<F, D>>(gate: G) -> GateRef<F, D> {
GateRef(Arc::new(gate))
}
}
impl<F: RichField + Extendable<D>, const D: usize> PartialEq for GateRef<F, D> {
fn eq(&self, other: &Self) -> bool {
self.0.id() == other.0.id()
}
}
impl<F: RichField + Extendable<D>, const D: usize> Hash for GateRef<F, D> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.id().hash(state)
}
}
impl<F: RichField + Extendable<D>, const D: usize> Eq for GateRef<F, D> {}
impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
write!(f, "{}", self.0.id())
}
}
#[derive(Clone, Debug)]
pub struct CurrentSlot<F: RichField + Extendable<D>, const D: usize> {
pub current_slot: HashMap<Vec<F>, (usize, usize)>,
}
/// A gate along with any constants used to configure it.
#[derive(Clone)]

View File

@ -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.

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D>
// point-value pairs, plus D constraints for the evaluation value.
self.num_points() * D + D
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D>
for HighDegreeInterpolationGate<F, D>
{
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for LowDegreeInter
// to check power constraints for evaluation point and shift.
self.num_points() * D + D + (D + 1) * (self.num_points() - 2)
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D>
for LowDegreeInterpolationGate<F, D>
{
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for MulExtensionGa
fn num_constraints(&self) -> usize {
self.num_ops * D
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for MulExtensionGate<D> {
fn num_ops(&self) -> usize {
self.num_ops
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for NoopGate {
fn num_constraints(&self) -> usize {
0
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for NoopGate {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F
+ 1
+ 4
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for PoseidonGate<F, D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D> + Poseidon, const D: usize> Gate<F, D> for Pos
fn num_constraints(&self) -> usize {
SPONGE_WIDTH * D
}
}
impl<F: RichField + Extendable<D> + Poseidon, const D: usize> MultiOpsGate<F, D>
for PoseidonMdsGate<F, D>
{
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PublicInputGat
fn num_constraints(&self) -> usize {
4
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for PublicInputGate {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for RandomAccessGa
let constraints_per_copy = self.bits + 2;
self.num_copies * constraints_per_copy
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for RandomAccessGate<F, D> {
fn num_ops(&self) -> usize {
self.num_copies
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32RangeCheckG
fn num_constraints(&self) -> usize {
self.num_input_limbs * (1 + self.aux_limbs_per_input_limb())
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for U32RangeCheckGate<F, D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingGate<D
fn num_constraints(&self) -> usize {
D * self.num_coeffs
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for ReducingGate<D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingExtens
fn num_constraints(&self) -> usize {
D * self.num_coeffs
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for ReducingExtensionGate<D> {
fn num_ops(&self) -> usize {
1
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32Subtraction
fn num_constraints(&self) -> usize {
self.num_ops * (3 + Self::num_limbs())
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for U32SubtractionGate<F, D> {
fn num_ops(&self) -> usize {
self.num_ops
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for SwitchGate<F,
fn num_constraints(&self) -> usize {
4 * self.num_copies * self.chunk_size
}
}
impl<F: RichField + Extendable<D>, const D: usize> MultiOpsGate<F, D> for SwitchGate<F, D> {
fn num_ops(&self) -> usize {
self.num_copies
}

View File

@ -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<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
/// Adds a gate to the circuit, and returns its index.
pub fn add_gate<G: BatchableGate<F, D>>(
pub fn add_gate<G: Gate<F, D>>(
&mut self,
gate_type: G,
constants: Vec<F>,
@ -398,7 +397,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
})
}
pub fn find_slot<G: BatchableGate<F, D> + Clone>(
pub fn find_slot<G: Gate<F, D> + Clone>(
&mut self,
gate: G,
params: &[F],