diff --git a/halo2_gadgets/benches/endoscale.rs b/halo2_gadgets/benches/endoscale.rs index 3a05e0b57..8b9d3766c 100644 --- a/halo2_gadgets/benches/endoscale.rs +++ b/halo2_gadgets/benches/endoscale.rs @@ -43,7 +43,7 @@ impl< where C::Base: PrimeFieldBits, { - type Config = (EndoscaleConfig, Column); + type Config = (EndoscaleConfig, Column); type FloorPlanner = SimpleFloorPlanner; #[cfg(feature = "circuit-params")] @@ -142,7 +142,7 @@ impl< where C::Base: PrimeFieldBits, { - type Config = EndoscaleConfig; + type Config = EndoscaleConfig; type FloorPlanner = SimpleFloorPlanner; #[cfg(feature = "circuit-params")] diff --git a/halo2_gadgets/examples/endoscaling_demo.rs b/halo2_gadgets/examples/endoscaling_demo.rs index bf56ed795..8486419aa 100644 --- a/halo2_gadgets/examples/endoscaling_demo.rs +++ b/halo2_gadgets/examples/endoscaling_demo.rs @@ -252,10 +252,9 @@ struct ChallengeMultiplicationConfig { /// - First parameter is the curve that the base point used in Alg 1 is on. /// - Second parameter is the window size used to decompose the challenge into a bitstring in /// Alg 2. - /// - Third parameter is the maximum length allowed for a bitstring used in Alg 2. /// - /// In this example, we don't use Alg 2, so we can set the second and third parameters to 0. - endoscale_config: EndoscaleConfig, + /// In this example, we don't use Alg 2, so we can set the second parameter to 0. + endoscale_config: EndoscaleConfig, } impl Circuit for ChallengeMultiplicationCircuit { diff --git a/halo2_gadgets/src/endoscale.rs b/halo2_gadgets/src/endoscale.rs index c2d2de77b..b4e5fec8b 100644 --- a/halo2_gadgets/src/endoscale.rs +++ b/halo2_gadgets/src/endoscale.rs @@ -24,8 +24,6 @@ where /// When endoscaling with a base, each unique base can only support up to /// `MAX_BITSTRING_LENGTH` bits. const MAX_BITSTRING_LENGTH: usize; - /// The number of fixed bases available. - const NUM_FIXED_BASES: usize; /// Witnesses a slice of bools as a vector of [`Self::Bitstring`]s. fn witness_bitstring( @@ -45,9 +43,6 @@ where /// Computes commitment (Alg 1) to a variable-length bitstring using the endoscaling /// algorithm. Uses the fixed bases defined in [`Self::FixedBases`]. - /// - /// # Panics - /// Panics if bitstring.len() exceeds NUM_FIXED_BASES. #[allow(clippy::type_complexity)] fn endoscale_fixed_base( &self, diff --git a/halo2_gadgets/src/endoscale/chip.rs b/halo2_gadgets/src/endoscale/chip.rs index 8883f128f..03dbec897 100644 --- a/halo2_gadgets/src/endoscale/chip.rs +++ b/halo2_gadgets/src/endoscale/chip.rs @@ -39,7 +39,7 @@ pub enum Bitstring { /// Config used in processing endoscalars. #[derive(Clone, Debug)] -pub struct EndoscaleConfig +pub struct EndoscaleConfig where C::Base: PrimeFieldBits, { @@ -51,24 +51,24 @@ where /// /// That is, given a bitstring, this computes the scalar value that, when scalar-multiplied /// by a curve point, provides the same result as endoscaling with the bitstring. - alg_2: Alg2Config, + alg_2: Alg2Config, } /// Chip implementing [`EndoscaleInstructions`] #[derive(Debug)] -pub struct EndoscaleChip +pub struct EndoscaleChip where C::Base: PrimeFieldBits, { - config: EndoscaleConfig, + config: EndoscaleConfig, } -impl EndoscaleChip +impl EndoscaleChip where C::Base: PrimeFieldBits, { /// Construct chip from inner config - pub fn construct(config: EndoscaleConfig) -> Self { + pub fn construct(config: EndoscaleConfig) -> Self { Self { config } } @@ -82,7 +82,7 @@ where // Running sum column shared across alg_1 and alg_2 running_sum: Column, endoscalars: Column, - ) -> EndoscaleConfig { + ) -> EndoscaleConfig { let running_sum_pairs = { let q_pairs = meta.selector(); RunningSumConfig::configure(meta, q_pairs, running_sum) @@ -126,13 +126,12 @@ where self.config.alg_1() } - fn alg_2(&self) -> &Alg2Config { + fn alg_2(&self) -> &Alg2Config { self.config.alg_2() } } -impl - EndoscaleConfig +impl EndoscaleConfig where C::Base: PrimeFieldBits, { @@ -142,7 +141,7 @@ where } /// Get the config for algorithm 2 . - pub fn alg_2(&self) -> &Alg2Config { + pub fn alg_2(&self) -> &Alg2Config { &self.alg_2 } } @@ -173,12 +172,11 @@ impl CurveEndoscale for pluto_eris::ErisAffine { const MAX_BITSTRING_LENGTH: usize = 442; } -impl Chip - for EndoscaleChip +impl Chip for EndoscaleChip where C::Base: PrimeFieldBits, { - type Config = EndoscaleConfig; + type Config = EndoscaleConfig; type Loaded = (); fn config(&self) -> &Self::Config { @@ -190,8 +188,8 @@ where } } -impl EndoscaleInstructions - for EndoscaleChip +impl EndoscaleInstructions + for EndoscaleChip where C::Base: PrimeFieldBits, { @@ -199,7 +197,6 @@ where type Bitstring = Bitstring; type FixedBases = C; const MAX_BITSTRING_LENGTH: usize = C::MAX_BITSTRING_LENGTH; - const NUM_FIXED_BASES: usize = N; fn witness_bitstring( &self, @@ -364,7 +361,7 @@ mod tests { where C::Base: PrimeFieldBits, { - type Config = (EndoscaleConfig, Column); + type Config = (EndoscaleConfig, Column); type FloorPlanner = SimpleFloorPlanner; #[cfg(feature = "circuit-params")] @@ -464,7 +461,7 @@ mod tests { where C::Base: PrimeFieldBits, { - type Config = EndoscaleConfig; + type Config = EndoscaleConfig; type FloorPlanner = SimpleFloorPlanner; #[cfg(feature = "circuit-params")] diff --git a/halo2_gadgets/src/endoscale/chip/alg_2.rs b/halo2_gadgets/src/endoscale/chip/alg_2.rs index bada8153f..c1fcc0d54 100644 --- a/halo2_gadgets/src/endoscale/chip/alg_2.rs +++ b/halo2_gadgets/src/endoscale/chip/alg_2.rs @@ -18,6 +18,8 @@ use crate::utilities::{ }; use std::marker::PhantomData; +use super::CurveEndoscale; + #[derive(Clone, Debug)] pub struct Bitstring { running_sum: RunningSum, @@ -86,7 +88,7 @@ impl, const K: usize> TableConfig { /// Config used in Algorithm 2 (endoscaling in the field). #[derive(Clone, Debug)] -pub struct Alg2Config +pub struct Alg2Config where C::Base: PrimeFieldBits, { @@ -114,8 +116,7 @@ where pow2_config: pow2_range_check::Config, } -impl - Alg2Config +impl Alg2Config where C::Base: PrimeFieldBits, { @@ -271,7 +272,7 @@ where let pad_len = bitstring.pad_len; let num_bits = bitstring.running_sum.num_bits() - pad_len; // num_bits must be an even number not greater than MAX_BITSTRING_LENGTH. - assert!(num_bits <= MAX_BITSTRING_LENGTH); + assert!(num_bits <= C::MAX_BITSTRING_LENGTH); // The bitstring will be broken into K-bit chunks with the first chunk // being a padded k_prime-bit partial chunk diff --git a/halo2_gadgets/src/recursive_chip.rs b/halo2_gadgets/src/recursive_chip.rs index 151103094..624f16d9a 100644 --- a/halo2_gadgets/src/recursive_chip.rs +++ b/halo2_gadgets/src/recursive_chip.rs @@ -89,7 +89,7 @@ type C = pasta::pallas::Affine; // Limitation of `EccChip` (will be generalized const K: usize = 0; // We won't be using Algorithm 2 yet, so no reason to have this table const MAX_BITSTRING_LENGTH: usize = ::MAX_BITSTRING_LENGTH; -type Endo = EndoscaleChip; +type Endo = EndoscaleChip; type P = Pow5Chip<::Base, { P128Pow5T3::WIDTH }, { P128Pow5T3::RATE }>; type TR = TranscriptReaderChip, TranscriptChipP128Pow5T3, R>; @@ -266,7 +266,6 @@ impl< type Bitstring = Endo::Bitstring; type FixedBases = Endo::FixedBases; const MAX_BITSTRING_LENGTH: usize = Endo::MAX_BITSTRING_LENGTH; - const NUM_FIXED_BASES: usize = Endo::NUM_FIXED_BASES; fn witness_bitstring( &self,