diff --git a/halo2_gadgets/src/sinsemilla/chip.rs b/halo2_gadgets/src/sinsemilla/chip.rs index ce78a241f7..281b07d77a 100644 --- a/halo2_gadgets/src/sinsemilla/chip.rs +++ b/halo2_gadgets/src/sinsemilla/chip.rs @@ -95,18 +95,27 @@ where } } +/* +trait SinsemillaArgs { + type Hash: HashDomains, + type Fixed: FixedPoints, + type Commit: CommitDomains, + type Lookup: DefaultLookupRangeCheck, +} +*/ + /// A chip that implements 10-bit Sinsemilla using a lookup table and 5 advice columns. /// /// [Chip description](https://zcash.github.io/halo2/design/gadgets/sinsemilla.html#plonk--halo-2-constraints). #[derive(Eq, PartialEq, Clone, Debug)] -pub struct SinsemillaChip +pub struct SinsemillaChip where Hash: HashDomains, Fixed: FixedPoints, Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + Lookup: DefaultLookupRangeCheck, { - config: SinsemillaConfig, + config: SinsemillaConfig, } impl Chip diff --git a/halo2_gadgets/src/sinsemilla/merkle/chip.rs b/halo2_gadgets/src/sinsemilla/merkle/chip.rs index dc7fb3f6f8..bafd64fd10 100644 --- a/halo2_gadgets/src/sinsemilla/merkle/chip.rs +++ b/halo2_gadgets/src/sinsemilla/merkle/chip.rs @@ -11,13 +11,9 @@ use super::MerkleInstructions; use crate::{ sinsemilla::{primitives as sinsemilla, MessagePiece}, - utilities::{lookup_range_check::DefaultLookupRangeCheck, RangeConstrained}, + utilities::RangeConstrained, { - ecc::FixedPoints, - sinsemilla::{ - chip::{SinsemillaChip, SinsemillaConfig}, - CommitDomains, HashDomains, SinsemillaInstructions, - }, + sinsemilla::SinsemillaInstructions, utilities::{ cond_swap::{CondSwapChip, CondSwapConfig, CondSwapInstructions}, UtilitiesInstructions, @@ -28,17 +24,15 @@ use group::ff::PrimeField; /// Configuration for the `MerkleChip` implementation. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct MerkleConfig +pub struct MerkleConfig where - Hash: HashDomains, - Fixed: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { advices: [Column; 5], q_decompose: Selector, pub(crate) cond_swap_config: CondSwapConfig, - pub(crate) sinsemilla_config: SinsemillaConfig, + sinsemilla_chip: SinsemillaChip, } /// Chip implementing `MerkleInstructions`. @@ -52,25 +46,20 @@ where /// This chip does **NOT** constrain `left⋆` and `right⋆` to be canonical encodings of /// `left` and `right`. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct MerkleChip +pub struct MerkleChip where - Hash: HashDomains, - Fixed: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { - config: MerkleConfig, + config: MerkleConfig, } -impl Chip - for MerkleChip +impl Chip for MerkleChip where - Hash: HashDomains, - Fixed: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { - type Config = MerkleConfig; + type Config = MerkleConfig; type Loaded = (); fn config(&self) -> &Self::Config { @@ -82,20 +71,18 @@ where } } -impl MerkleChip +impl MerkleChip where - Hash: HashDomains, - F: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { /// Configures the [`MerkleChip`]. pub fn configure( meta: &mut ConstraintSystem, - sinsemilla_config: SinsemillaConfig, - ) -> MerkleConfig { + sinsemilla_chip: SinsemillaChip, + ) -> MerkleConfig { // All five advice columns are equality-enabled by SinsemillaConfig. - let advices = sinsemilla_config.advices(); + let advices = sinsemilla_chip.config().advices(); let cond_swap_config = CondSwapChip::configure(meta, advices); // This selector enables the decomposition gate. @@ -191,24 +178,22 @@ where advices, q_decompose, cond_swap_config, - sinsemilla_config, + sinsemilla_chip, } } /// Constructs a [`MerkleChip`] given a [`MerkleConfig`]. - pub fn construct(config: MerkleConfig) -> Self { + pub fn construct(config: MerkleConfig) -> Self { MerkleChip { config } } } -impl +impl MerkleInstructions - for MerkleChip + for MerkleChip where - Hash: HashDomains + Eq, - F: FixedPoints, - Commit: CommitDomains + Eq, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { #[allow(non_snake_case)] fn hash_layer( @@ -421,24 +406,18 @@ where } } -impl UtilitiesInstructions - for MerkleChip +impl UtilitiesInstructions for MerkleChip where - Hash: HashDomains, - F: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { type Var = AssignedCell; } -impl CondSwapInstructions - for MerkleChip +impl CondSwapInstructions for MerkleChip where - Hash: HashDomains, - F: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { #[allow(clippy::type_complexity)] fn swap( @@ -453,71 +432,61 @@ where } } -impl - SinsemillaInstructions - for MerkleChip +// FIXME: do we need to constraint SinsemillaChipt with Chip? +impl SinsemillaInstructions + for MerkleChip where - Hash: HashDomains, - F: FixedPoints, - Commit: CommitDomains, - LookupRangeCheckConfig: DefaultLookupRangeCheck, + SinsemillaChip: Chip + + SinsemillaInstructions, { - type CellValue = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::CellValue; - - type Message = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::Message; - type MessagePiece = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::MessagePiece; - type RunningSum = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::RunningSum; - - type X = as SinsemillaInstructions< + type CellValue = >::CellValue; + + type Message = >::Message; + type MessagePiece = >::MessagePiece; + type RunningSum = >::RunningSum; + + type X = >::X; - type NonIdentityPoint = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::NonIdentityPoint; - type FixedPoints = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::FixedPoints; - - type HashDomains = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::HashDomains; - type CommitDomains = - as SinsemillaInstructions< - pallas::Affine, - { sinsemilla::K }, - { sinsemilla::C }, - >>::CommitDomains; + type NonIdentityPoint = >::NonIdentityPoint; + type FixedPoints = >::FixedPoints; + + type HashDomains = >::HashDomains; + type CommitDomains = >::CommitDomains; fn witness_message_piece( &self, @@ -526,8 +495,8 @@ where num_words: usize, ) -> Result { let config = self.config().sinsemilla_config.clone(); - let chip = SinsemillaChip::::construct(config); - chip.witness_message_piece(layouter, value, num_words) + self.sinsemilla_chip + .witness_message_piece(layouter, value, num_words) } #[allow(non_snake_case)] @@ -539,11 +508,10 @@ where message: Self::Message, ) -> Result<(Self::NonIdentityPoint, Vec>), Error> { let config = self.config().sinsemilla_config.clone(); - let chip = SinsemillaChip::::construct(config); - chip.hash_to_point(layouter, Q, message) + self.sinsemilla_chip.hash_to_point(layouter, Q, message) } fn extract(point: &Self::NonIdentityPoint) -> Self::X { - SinsemillaChip::::extract(point) + SinsemillaChip::extract(point) } } diff --git a/halo2_gadgets/src/sinsemilla_opt/merkle/chip.rs b/halo2_gadgets/src/sinsemilla_opt/merkle/chip.rs index 14b6a41579..6f50cc999b 100644 --- a/halo2_gadgets/src/sinsemilla_opt/merkle/chip.rs +++ b/halo2_gadgets/src/sinsemilla_opt/merkle/chip.rs @@ -8,23 +8,16 @@ use pasta_curves::pallas; use crate::{ sinsemilla::{merkle::chip::MerkleChip, primitives as sinsemilla}, - sinsemilla_opt::SinsemillaInstructionsOptimized, - utilities_opt::lookup_range_check::DefaultLookupRangeCheckConfigOptimized, { - ecc::FixedPoints, - sinsemilla::{CommitDomains, HashDomains}, - sinsemilla_opt::chip::SinsemillaChipOptimized, - utilities::cond_swap::CondSwapChip, + sinsemilla::SinsemillaInstructions, utilities::cond_swap::CondSwapChip, utilities_opt::cond_swap::CondSwapInstructionsOptimized, }, }; -impl CondSwapInstructionsOptimized - for MerkleChip +impl CondSwapInstructionsOptimized for MerkleChip where - Hash: HashDomains, - F: FixedPoints, - Commit: CommitDomains, + SinsemillaChip: Chip + + SinsemillaInstructions, { fn mux( &self, @@ -39,13 +32,14 @@ where } } -impl +// FIXME: uncomment and implement this properly +/* +impl SinsemillaInstructionsOptimized - for MerkleChip + for MerkleChip where - Hash: HashDomains, - F: FixedPoints, - Commit: CommitDomains, + SinsemillaChip: Chip + + SinsemillaInstructions, { #[allow(non_snake_case)] #[allow(clippy::type_complexity)] @@ -60,3 +54,4 @@ where chip.hash_to_point_with_private_init(layouter, Q, message) } } +*/ diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 09369c04f1..e938d1cf3a 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -426,3 +426,6 @@ pub trait DefaultLookupRangeCheck: } impl DefaultLookupRangeCheck for LookupRangeCheckConfig {} + +pub(crate) type DefaultLookupRangeCheckConfig = + LookupRangeCheckConfig; diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 948d27daa4..0000000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.60.0"