From d684ee2d8de04f047818c6b8064819d2c50cc815 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 28 Jun 2023 07:59:07 -0400 Subject: [PATCH] Switch Field type of generators to be F: RichField + Extendable --- plonky2/examples/square_root.rs | 2 +- plonky2/src/gadgets/arithmetic.rs | 2 +- plonky2/src/gadgets/arithmetic_extension.rs | 2 +- plonky2/src/gadgets/range_check.rs | 2 +- plonky2/src/gadgets/split_base.rs | 5 ++- plonky2/src/gadgets/split_join.rs | 4 +- plonky2/src/gates/arithmetic_base.rs | 4 +- plonky2/src/gates/arithmetic_extension.rs | 4 +- plonky2/src/gates/base_sum.rs | 6 ++- plonky2/src/gates/constant.rs | 2 +- plonky2/src/gates/coset_interpolation.rs | 4 +- plonky2/src/gates/exponentiation.rs | 4 +- plonky2/src/gates/gate.rs | 2 +- plonky2/src/gates/lookup.rs | 4 +- plonky2/src/gates/lookup_table.rs | 4 +- plonky2/src/gates/multiplication_extension.rs | 4 +- plonky2/src/gates/noop.rs | 2 +- plonky2/src/gates/poseidon.rs | 4 +- plonky2/src/gates/poseidon_mds.rs | 4 +- plonky2/src/gates/public_input.rs | 2 +- plonky2/src/gates/random_access.rs | 4 +- plonky2/src/gates/reducing.rs | 4 +- plonky2/src/gates/reducing_extension.rs | 4 +- plonky2/src/iop/generator.rs | 42 ++++++++++++------- plonky2/src/plonk/circuit_builder.rs | 6 +-- plonky2/src/plonk/circuit_data.rs | 2 +- plonky2/src/recursion/dummy_circuit.rs | 2 +- .../serialization/generator_serialization.rs | 23 +++++----- plonky2/src/util/serialization/mod.rs | 8 ++-- 29 files changed, 89 insertions(+), 73 deletions(-) diff --git a/plonky2/examples/square_root.rs b/plonky2/examples/square_root.rs index 019d2c14..f27c46d1 100644 --- a/plonky2/examples/square_root.rs +++ b/plonky2/examples/square_root.rs @@ -32,7 +32,7 @@ struct SquareRootGenerator, const D: usize> { _phantom: PhantomData, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for SquareRootGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gadgets/arithmetic.rs b/plonky2/src/gadgets/arithmetic.rs index ed9e7c4a..aaf12a40 100644 --- a/plonky2/src/gadgets/arithmetic.rs +++ b/plonky2/src/gadgets/arithmetic.rs @@ -379,7 +379,7 @@ pub struct EqualityGenerator { inv: Target, } -impl SimpleGenerator for EqualityGenerator { +impl, const D: usize> SimpleGenerator for EqualityGenerator { fn id(&self) -> String { "EqualityGenerator".to_string() } diff --git a/plonky2/src/gadgets/arithmetic_extension.rs b/plonky2/src/gadgets/arithmetic_extension.rs index ccb84a40..d201b523 100644 --- a/plonky2/src/gadgets/arithmetic_extension.rs +++ b/plonky2/src/gadgets/arithmetic_extension.rs @@ -501,7 +501,7 @@ pub struct QuotientGeneratorExtension { quotient: ExtensionTarget, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for QuotientGeneratorExtension { fn id(&self) -> String { diff --git a/plonky2/src/gadgets/range_check.rs b/plonky2/src/gadgets/range_check.rs index bdd1942c..4a4617b6 100644 --- a/plonky2/src/gadgets/range_check.rs +++ b/plonky2/src/gadgets/range_check.rs @@ -60,7 +60,7 @@ pub struct LowHighGenerator { high: Target, } -impl SimpleGenerator for LowHighGenerator { +impl, const D: usize> SimpleGenerator for LowHighGenerator { fn id(&self) -> String { "LowHighGenerator".to_string() } diff --git a/plonky2/src/gadgets/split_base.rs b/plonky2/src/gadgets/split_base.rs index c2919315..1b375138 100644 --- a/plonky2/src/gadgets/split_base.rs +++ b/plonky2/src/gadgets/split_base.rs @@ -5,7 +5,6 @@ use core::borrow::Borrow; use itertools::Itertools; use crate::field::extension::Extendable; -use crate::field::types::Field; use crate::gates::base_sum::BaseSumGate; use crate::hash::hash_types::RichField; use crate::iop::generator::{GeneratedValues, SimpleGenerator}; @@ -86,7 +85,9 @@ pub struct BaseSumGenerator { limbs: Vec, } -impl SimpleGenerator for BaseSumGenerator { +impl, const B: usize, const D: usize> SimpleGenerator + for BaseSumGenerator +{ fn id(&self) -> String { "BaseSumGenerator".to_string() } diff --git a/plonky2/src/gadgets/split_join.rs b/plonky2/src/gadgets/split_join.rs index e3eda241..919cba95 100644 --- a/plonky2/src/gadgets/split_join.rs +++ b/plonky2/src/gadgets/split_join.rs @@ -62,7 +62,7 @@ pub struct SplitGenerator { bits: Vec, } -impl SimpleGenerator for SplitGenerator { +impl, const D: usize> SimpleGenerator for SplitGenerator { fn id(&self) -> String { "SplitGenerator".to_string() } @@ -105,7 +105,7 @@ pub struct WireSplitGenerator { num_limbs: usize, } -impl SimpleGenerator for WireSplitGenerator { +impl, const D: usize> SimpleGenerator for WireSplitGenerator { fn id(&self) -> String { "WireSplitGenerator".to_string() } diff --git a/plonky2/src/gates/arithmetic_base.rs b/plonky2/src/gates/arithmetic_base.rs index 7ed25328..62d5ebac 100644 --- a/plonky2/src/gates/arithmetic_base.rs +++ b/plonky2/src/gates/arithmetic_base.rs @@ -126,7 +126,7 @@ impl, const D: usize> Gate for ArithmeticGate constraints } - fn generators(&self, row: usize, local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, local_constants: &[F]) -> Vec> { (0..self.num_ops) .map(|i| { WitnessGeneratorRef::new( @@ -188,7 +188,7 @@ pub struct ArithmeticBaseGenerator, const D: usize> i: usize, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for ArithmeticBaseGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/arithmetic_extension.rs b/plonky2/src/gates/arithmetic_extension.rs index ebe7a650..d1f789ac 100644 --- a/plonky2/src/gates/arithmetic_extension.rs +++ b/plonky2/src/gates/arithmetic_extension.rs @@ -131,7 +131,7 @@ impl, const D: usize> Gate for ArithmeticExte constraints } - fn generators(&self, row: usize, local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, local_constants: &[F]) -> Vec> { (0..self.num_ops) .map(|i| { WitnessGeneratorRef::new( @@ -172,7 +172,7 @@ pub struct ArithmeticExtensionGenerator, const D: u i: usize, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for ArithmeticExtensionGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index fee50c66..66cff0d5 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -118,7 +118,7 @@ impl, const D: usize, const B: usize> Gate fo constraints } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { let gen = BaseSplitGenerator:: { row, num_limbs: self.num_limbs, @@ -175,7 +175,9 @@ pub struct BaseSplitGenerator { num_limbs: usize, } -impl SimpleGenerator for BaseSplitGenerator { +impl, const B: usize, const D: usize> SimpleGenerator + for BaseSplitGenerator +{ fn id(&self) -> String { "BaseSplitGenerator".to_string() } diff --git a/plonky2/src/gates/constant.rs b/plonky2/src/gates/constant.rs index 5fac1f00..d6be45a9 100644 --- a/plonky2/src/gates/constant.rs +++ b/plonky2/src/gates/constant.rs @@ -86,7 +86,7 @@ impl, const D: usize> Gate for ConstantGate { .collect() } - fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec> { vec![] } diff --git a/plonky2/src/gates/coset_interpolation.rs b/plonky2/src/gates/coset_interpolation.rs index ff6d9918..a1409626 100644 --- a/plonky2/src/gates/coset_interpolation.rs +++ b/plonky2/src/gates/coset_interpolation.rs @@ -362,7 +362,7 @@ impl, const D: usize> Gate for CosetInterpola constraints } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { let gen = InterpolationGenerator::::new(row, self.clone()); vec![WitnessGeneratorRef::new(gen.adapter())] } @@ -406,7 +406,7 @@ impl, const D: usize> InterpolationGenerator } } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for InterpolationGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index eefc7ba7..d7ba936b 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -173,7 +173,7 @@ impl, const D: usize> Gate for Exponentiation constraints } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { let gen = ExponentiationGenerator:: { row, gate: self.clone(), @@ -243,7 +243,7 @@ pub struct ExponentiationGenerator, const D: usize> gate: ExponentiationGate, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for ExponentiationGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index dd0779de..78552588 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -175,7 +175,7 @@ pub trait Gate, const D: usize>: 'static + Send + S /// The generators used to populate the witness. /// Note: This should return exactly 1 generator per operation in the gate. - fn generators(&self, row: usize, local_constants: &[F]) -> Vec>; + fn generators(&self, row: usize, local_constants: &[F]) -> Vec>; /// The number of wires used by this gate. fn num_wires(&self) -> usize; diff --git a/plonky2/src/gates/lookup.rs b/plonky2/src/gates/lookup.rs index 0ecac501..61db77fc 100644 --- a/plonky2/src/gates/lookup.rs +++ b/plonky2/src/gates/lookup.rs @@ -101,7 +101,7 @@ impl, const D: usize> Gate for LookupGate { vec![] } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { (0..self.num_slots) .map(|i| { WitnessGeneratorRef::new( @@ -149,7 +149,7 @@ pub struct LookupGenerator { slot_nb: usize, } -impl SimpleGenerator for LookupGenerator { +impl, const D: usize> SimpleGenerator for LookupGenerator { fn id(&self) -> String { "LookupGenerator".to_string() } diff --git a/plonky2/src/gates/lookup_table.rs b/plonky2/src/gates/lookup_table.rs index b4ad902a..6796dc0a 100644 --- a/plonky2/src/gates/lookup_table.rs +++ b/plonky2/src/gates/lookup_table.rs @@ -116,7 +116,7 @@ impl, const D: usize> Gate for LookupTableGat vec![] } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { (0..self.num_slots) .map(|i| { WitnessGeneratorRef::new( @@ -168,7 +168,7 @@ pub struct LookupTableGenerator { last_lut_row: usize, } -impl SimpleGenerator for LookupTableGenerator { +impl, const D: usize> SimpleGenerator for LookupTableGenerator { fn id(&self) -> String { "LookupTableGenerator".to_string() } diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index 7e1c1924..3aa69a5f 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -119,7 +119,7 @@ impl, const D: usize> Gate for MulExtensionGa constraints } - fn generators(&self, row: usize, local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, local_constants: &[F]) -> Vec> { (0..self.num_ops) .map(|i| { WitnessGeneratorRef::new( @@ -158,7 +158,7 @@ pub struct MulExtensionGenerator, const D: usize> { i: usize, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for MulExtensionGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/noop.rs b/plonky2/src/gates/noop.rs index cfcfb912..332dd3a8 100644 --- a/plonky2/src/gates/noop.rs +++ b/plonky2/src/gates/noop.rs @@ -42,7 +42,7 @@ impl, const D: usize> Gate for NoopGate { Vec::new() } - fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec> { Vec::new() } diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index caab7faf..ff2ecf2e 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -380,7 +380,7 @@ impl, const D: usize> Gate for PoseidonGate Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { let gen = PoseidonGenerator:: { row, _phantom: PhantomData, @@ -415,7 +415,7 @@ pub struct PoseidonGenerator + Poseidon, const D: u _phantom: PhantomData, } -impl + Poseidon, const D: usize> SimpleGenerator +impl + Poseidon, const D: usize> SimpleGenerator for PoseidonGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index a3b4c927..ee5665de 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -187,7 +187,7 @@ impl + Poseidon, const D: usize> Gate for Pos .collect() } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { let gen = PoseidonMdsGenerator:: { row }; vec![WitnessGeneratorRef::new(gen.adapter())] } @@ -214,7 +214,7 @@ pub struct PoseidonMdsGenerator { row: usize, } -impl + Poseidon, const D: usize> SimpleGenerator +impl + Poseidon, const D: usize> SimpleGenerator for PoseidonMdsGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/public_input.rs b/plonky2/src/gates/public_input.rs index 2c3e2428..4d3f6982 100644 --- a/plonky2/src/gates/public_input.rs +++ b/plonky2/src/gates/public_input.rs @@ -72,7 +72,7 @@ impl, const D: usize> Gate for PublicInputGat .collect() } - fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec> { Vec::new() } diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index 7f651bab..d5ae5b9d 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -252,7 +252,7 @@ impl, const D: usize> Gate for RandomAccessGa constraints } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { (0..self.num_copies) .map(|copy| { WitnessGeneratorRef::new( @@ -345,7 +345,7 @@ pub struct RandomAccessGenerator, const D: usize> { copy: usize, } -impl, const D: usize> SimpleGenerator +impl, const D: usize> SimpleGenerator for RandomAccessGenerator { fn id(&self) -> String { diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index b9bd025a..2f02a747 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -150,7 +150,7 @@ impl, const D: usize> Gate for ReducingGate Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { vec![WitnessGeneratorRef::new( ReducingGenerator { row, @@ -183,7 +183,7 @@ pub struct ReducingGenerator { gate: ReducingGate, } -impl, const D: usize> SimpleGenerator for ReducingGenerator { +impl, const D: usize> SimpleGenerator for ReducingGenerator { fn id(&self) -> String { "ReducingGenerator".to_string() } diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index 11541ec2..5b36aad0 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -150,7 +150,7 @@ impl, const D: usize> Gate for ReducingExtens .collect() } - fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { + fn generators(&self, row: usize, _local_constants: &[F]) -> Vec> { vec![WitnessGeneratorRef::new( ReducingGenerator { row, @@ -183,7 +183,7 @@ pub struct ReducingGenerator { gate: ReducingExtensionGate, } -impl, const D: usize> SimpleGenerator for ReducingGenerator { +impl, const D: usize> SimpleGenerator for ReducingGenerator { fn id(&self) -> String { "ReducingExtensionGenerator".to_string() } diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 16a23e26..c5f6074e 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -98,7 +98,9 @@ pub(crate) fn generate_partial_witness< } /// A generator participates in the generation of the witness. -pub trait WitnessGenerator: 'static + Send + Sync + Debug { +pub trait WitnessGenerator, const D: usize>: + 'static + Send + Sync + Debug +{ fn id(&self) -> String; /// Targets to be "watched" by this generator. Whenever a target in the watch list is populated, @@ -119,23 +121,25 @@ pub trait WitnessGenerator: 'static + Send + Sync + Debug { /// A wrapper around an `Box` which implements `PartialEq` /// and `Eq` based on generator IDs. -pub struct WitnessGeneratorRef(pub Box>); +pub struct WitnessGeneratorRef, const D: usize>( + pub Box>, +); -impl WitnessGeneratorRef { - pub fn new>(generator: G) -> WitnessGeneratorRef { +impl, const D: usize> WitnessGeneratorRef { + pub fn new>(generator: G) -> WitnessGeneratorRef { WitnessGeneratorRef(Box::new(generator)) } } -impl PartialEq for WitnessGeneratorRef { +impl, const D: usize> PartialEq for WitnessGeneratorRef { fn eq(&self, other: &Self) -> bool { self.0.id() == other.0.id() } } -impl Eq for WitnessGeneratorRef {} +impl, const D: usize> Eq for WitnessGeneratorRef {} -impl Debug for WitnessGeneratorRef { +impl, const D: usize> Debug for WitnessGeneratorRef { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.0.id()) } @@ -190,14 +194,16 @@ impl GeneratedValues { } /// A generator which runs once after a list of dependencies is present in the witness. -pub trait SimpleGenerator: 'static + Send + Sync + Debug { +pub trait SimpleGenerator, const D: usize>: + 'static + Send + Sync + Debug +{ fn id(&self) -> String; fn dependencies(&self) -> Vec; fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues); - fn adapter(self) -> SimpleGeneratorAdapter + fn adapter(self) -> SimpleGeneratorAdapter where Self: Sized, { @@ -215,12 +221,18 @@ pub trait SimpleGenerator: 'static + Send + Sync + Debug { } #[derive(Debug)] -pub struct SimpleGeneratorAdapter + ?Sized> { +pub struct SimpleGeneratorAdapter< + F: RichField + Extendable, + SG: SimpleGenerator + ?Sized, + const D: usize, +> { _phantom: PhantomData, inner: SG, } -impl> WitnessGenerator for SimpleGeneratorAdapter { +impl, SG: SimpleGenerator, const D: usize> WitnessGenerator + for SimpleGeneratorAdapter +{ fn id(&self) -> String { self.inner.id() } @@ -257,7 +269,7 @@ pub struct CopyGenerator { pub(crate) dst: Target, } -impl SimpleGenerator for CopyGenerator { +impl, const D: usize> SimpleGenerator for CopyGenerator { fn id(&self) -> String { "CopyGenerator".to_string() } @@ -289,7 +301,7 @@ pub struct RandomValueGenerator { pub(crate) target: Target, } -impl SimpleGenerator for RandomValueGenerator { +impl, const D: usize> SimpleGenerator for RandomValueGenerator { fn id(&self) -> String { "RandomValueGenerator".to_string() } @@ -320,7 +332,7 @@ pub struct NonzeroTestGenerator { pub(crate) dummy: Target, } -impl SimpleGenerator for NonzeroTestGenerator { +impl, const D: usize> SimpleGenerator for NonzeroTestGenerator { fn id(&self) -> String { "NonzeroTestGenerator".to_string() } @@ -368,7 +380,7 @@ impl ConstantGenerator { } } -impl SimpleGenerator for ConstantGenerator { +impl, const D: usize> SimpleGenerator for ConstantGenerator { fn id(&self) -> String { "ConstantGenerator".to_string() } diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 8955a2bd..d8f9e32c 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -109,7 +109,7 @@ pub struct CircuitBuilder, const D: usize> { context_log: ContextTree, /// Generators used to generate the witness. - generators: Vec>, + generators: Vec>, constants_to_targets: HashMap, targets_to_constants: HashMap, @@ -444,11 +444,11 @@ impl, const D: usize> CircuitBuilder { self.connect(x, one); } - pub fn add_generators(&mut self, generators: Vec>) { + pub fn add_generators(&mut self, generators: Vec>) { self.generators.extend(generators); } - pub fn add_simple_generator>(&mut self, generator: G) { + pub fn add_simple_generator>(&mut self, generator: G) { self.generators .push(WitnessGeneratorRef::new(generator.adapter())); } diff --git a/plonky2/src/plonk/circuit_data.rs b/plonky2/src/plonk/circuit_data.rs index a2fd48df..edf28ba5 100644 --- a/plonky2/src/plonk/circuit_data.rs +++ b/plonky2/src/plonk/circuit_data.rs @@ -295,7 +295,7 @@ pub struct ProverOnlyCircuitData< C: GenericConfig, const D: usize, > { - pub generators: Vec>, + pub generators: Vec>, /// Generator indices (within the `Vec` above), indexed by the representative of each target /// they watch. pub generator_indices_by_watches: BTreeMap>, diff --git a/plonky2/src/recursion/dummy_circuit.rs b/plonky2/src/recursion/dummy_circuit.rs index daf9319a..2d9c48e4 100644 --- a/plonky2/src/recursion/dummy_circuit.rs +++ b/plonky2/src/recursion/dummy_circuit.rs @@ -238,7 +238,7 @@ where } } -impl SimpleGenerator for DummyProofGenerator +impl SimpleGenerator for DummyProofGenerator where F: RichField + Extendable, C: GenericConfig + 'static, diff --git a/plonky2/src/util/serialization/generator_serialization.rs b/plonky2/src/util/serialization/generator_serialization.rs index cbc6d6ba..4f35510e 100644 --- a/plonky2/src/util/serialization/generator_serialization.rs +++ b/plonky2/src/util/serialization/generator_serialization.rs @@ -11,12 +11,13 @@ pub trait WitnessGeneratorSerializer, const D: usiz fn read_generator( &self, buf: &mut Buffer, - common: &CommonCircuitData, - ) -> IoResult>; + cd: &CommonCircuitData, + ) -> IoResult>; + fn write_generator( &self, buf: &mut Vec, - generator: &WitnessGeneratorRef, + generator: &WitnessGeneratorRef, ) -> IoResult<()>; } @@ -30,16 +31,16 @@ macro_rules! read_generator_impl { if tag == 0 { let generator: $crate::recursion::dummy_circuit::DummyProofGenerator = $crate::recursion::dummy_circuit::DummyProofGenerator::deserialize_with_circuit_data(buf, $common)?; - return Ok($crate::iop::generator::WitnessGeneratorRef::::new( - $crate::iop::generator::SimpleGenerator::::adapter(generator), + return Ok($crate::iop::generator::WitnessGeneratorRef::::new( + $crate::iop::generator::SimpleGenerator::::adapter(generator), )); } $(if tag == i.next().unwrap() { let generator = - <$generator_types as $crate::iop::generator::SimpleGenerator>::deserialize(buf)?; - Ok($crate::iop::generator::WitnessGeneratorRef::::new( - $crate::iop::generator::SimpleGenerator::::adapter(generator), + <$generator_types as $crate::iop::generator::SimpleGenerator>::deserialize(buf)?; + Ok($crate::iop::generator::WitnessGeneratorRef::::new( + $crate::iop::generator::SimpleGenerator::::adapter(generator), )) } else)* { @@ -52,7 +53,7 @@ macro_rules! read_generator_impl { macro_rules! get_generator_tag_impl { ($generator:expr, $($generator_types:ty),+) => {{ let mut i = 0..; - $(if let (tag, true) = (i.next().unwrap(), $generator.0.id() == $crate::iop::generator::SimpleGenerator::::id(&<$generator_types>::default())) { + $(if let (tag, true) = (i.next().unwrap(), $generator.0.id() == $crate::iop::generator::SimpleGenerator::::id(&<$generator_types>::default())) { Ok(tag) } else)* { @@ -77,7 +78,7 @@ macro_rules! impl_generator_serializer { &self, buf: &mut $crate::util::serialization::Buffer, common: &$crate::plonk::circuit_data::CommonCircuitData, - ) -> $crate::util::serialization::IoResult<$crate::iop::generator::WitnessGeneratorRef> { + ) -> $crate::util::serialization::IoResult<$crate::iop::generator::WitnessGeneratorRef> { let tag = $crate::util::serialization::Read::read_u32(buf)?; read_generator_impl!(buf, tag, common, $($generator_types),+) } @@ -85,7 +86,7 @@ macro_rules! impl_generator_serializer { fn write_generator( &self, buf: &mut Vec, - generator: &$crate::iop::generator::WitnessGeneratorRef, + generator: &$crate::iop::generator::WitnessGeneratorRef, ) -> $crate::util::serialization::IoResult<()> { let tag = get_generator_tag_impl!(generator, $($generator_types),+)?; diff --git a/plonky2/src/util/serialization/mod.rs b/plonky2/src/util/serialization/mod.rs index 4324d715..88038da8 100644 --- a/plonky2/src/util/serialization/mod.rs +++ b/plonky2/src/util/serialization/mod.rs @@ -690,7 +690,7 @@ pub trait Read { &mut self, generator_serializer: &dyn WitnessGeneratorSerializer, common_data: &CommonCircuitData, - ) -> IoResult>; + ) -> IoResult>; fn read_selectors_info(&mut self) -> IoResult { let selector_indices = self.read_usize_vec()?; @@ -1693,7 +1693,7 @@ pub trait Write { fn write_generator, const D: usize>( &mut self, - generator: &WitnessGeneratorRef, + generator: &WitnessGeneratorRef, generator_serializer: &dyn WitnessGeneratorSerializer, ) -> IoResult<()>; @@ -2116,7 +2116,7 @@ impl Write for Vec { fn write_generator, const D: usize>( &mut self, - generator: &WitnessGeneratorRef, + generator: &WitnessGeneratorRef, generator_serializer: &dyn WitnessGeneratorSerializer, ) -> IoResult<()> { generator_serializer.write_generator(self, generator) @@ -2186,7 +2186,7 @@ impl<'a> Read for Buffer<'a> { &mut self, generator_serializer: &dyn WitnessGeneratorSerializer, common_data: &CommonCircuitData, - ) -> IoResult> { + ) -> IoResult> { generator_serializer.read_generator(self, common_data) } }