Simplification

This commit is contained in:
wborgeaud 2022-02-15 17:35:12 +01:00
parent d0da2fe1ad
commit 2d4d2d21a0
25 changed files with 15 additions and 263 deletions

View File

@ -240,14 +240,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -269,20 +269,6 @@ 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())
}
fn num_ops(&self) -> usize {
self.num_ops
}
fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target> {
U32AddManyGenerator {
gate: *self,
gate_index,
i,
_phantom: PhantomData,
}
.dependencies()
}
}
#[derive(Clone, Debug)]

View File

@ -149,18 +149,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
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<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for ArithmeticGate {

View File

@ -156,19 +156,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
[
ExtensionTarget::<D>::from_range(gate_index, Self::wires_ith_multiplicand_0(i)).0,
ExtensionTarget::<D>::from_range(gate_index, Self::wires_ith_multiplicand_1(i)).0,
ExtensionTarget::<D>::from_range(gate_index, Self::wires_ith_addend(i)).0,
]
.concat()
}
}
#[derive(Clone, Debug)]

View File

@ -230,20 +230,6 @@ 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())
}
fn num_ops(&self) -> usize {
self.num_ops
}
fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target> {
U32ArithmeticGenerator {
gate: *self,
gate_index,
i,
_phantom: PhantomData,
}
.dependencies()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>

View File

@ -278,14 +278,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>

View File

@ -134,14 +134,6 @@ impl<F: RichField + Extendable<D>, const D: usize, const B: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
impl<F: RichField + Extendable<D>, const D: usize, const B: usize> PackedEvaluableBase<F, D>

View File

@ -311,14 +311,6 @@ 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()
}
fn num_ops(&self) -> usize {
1
}
fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec<Target> {
unreachable!()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>

View File

@ -111,14 +111,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
vec![]
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for ConstantGate {

View File

@ -188,14 +188,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>

View File

@ -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<F: RichField + Extendable<D>, 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<Target>;
/// Fill the dependencies of the
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);
}
}
}
fn num_ops(&self) -> usize {
self.generators(0, &[F::ZERO; 100]).len()
}
}

View File

@ -201,14 +201,6 @@ 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
}
fn num_ops(&self) -> usize {
1
}
fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -292,14 +292,6 @@ 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)
}
fn num_ops(&self) -> usize {
1
}
fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -143,18 +143,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
[
ExtensionTarget::<D>::from_range(gate_index, Self::wires_ith_multiplicand_0(i)).0,
ExtensionTarget::<D>::from_range(gate_index, Self::wires_ith_multiplicand_1(i)).0,
]
.concat()
}
}
#[derive(Clone, Debug)]

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
#[cfg(test)]

View File

@ -405,14 +405,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F
+ 1
+ 4
}
fn num_ops(&self) -> usize {
1
}
fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -195,14 +195,6 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
#[derive(Clone, Debug)]

View File

@ -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<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for PublicInputGate {

View File

@ -228,19 +228,6 @@ 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
}
fn num_ops(&self) -> usize {
self.num_copies
}
fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target> {
RandomAccessGenerator {
gate_index,
gate: *self,
copy: i,
}
.dependencies()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>

View File

@ -164,14 +164,6 @@ 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())
}
fn num_ops(&self) -> usize {
1
}
fn dependencies_ith_op(&self, _gate_index: usize, _i: usize) -> Vec<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -164,14 +164,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingGate<D
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<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -164,14 +164,6 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> 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<Target> {
unreachable!()
}
}
#[derive(Debug)]

View File

@ -219,20 +219,6 @@ 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())
}
fn num_ops(&self) -> usize {
self.num_ops
}
fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target> {
U32SubtractionGenerator {
gate: *self,
gate_index,
i,
_phantom: Default::default(),
}
.dependencies()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>

View File

@ -187,19 +187,6 @@ 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
}
fn num_ops(&self) -> usize {
self.num_copies
}
fn dependencies_ith_op(&self, gate_index: usize, i: usize) -> Vec<Target> {
SwitchGenerator::<F, D> {
gate_index,
gate: *self,
copy: i,
}
.watch_list()
}
}
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for SwitchGate<F, D> {

View File

@ -662,8 +662,6 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
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<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
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::<HashMap<_, _>>();
// 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<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
}
}
}
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
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);
}
}
}
}