diff --git a/halo2_gadgets/src/ecc.rs b/halo2_gadgets/src/ecc.rs index 45bf63acf..b6e68b40e 100644 --- a/halo2_gadgets/src/ecc.rs +++ b/halo2_gadgets/src/ecc.rs @@ -597,7 +597,7 @@ pub(crate) mod tests { }; use crate::{ tests::test_utils::{test_against_stored_proof, test_against_stored_vk}, - utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRC10b}, + utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig}, }; #[derive(Debug, Eq, PartialEq, Clone)] @@ -732,7 +732,7 @@ pub(crate) mod tests { #[allow(non_snake_case)] impl Circuit for MyCircuit { - type Config = EccConfig; + type Config = EccConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { @@ -767,8 +767,8 @@ pub(crate) mod tests { let constants = meta.fixed_column(); meta.enable_constant(constants); - let range_check = PallasLookupRC10b::configure(meta, advices[9], lookup_table); - EccChip::::configure( + let range_check = PallasLookupRCConfig::configure(meta, advices[9], lookup_table); + EccChip::::configure( meta, advices, lagrange_coeffs, diff --git a/halo2_gadgets/src/ecc/chip.rs b/halo2_gadgets/src/ecc/chip.rs index c168e0f45..926da7906 100644 --- a/halo2_gadgets/src/ecc/chip.rs +++ b/halo2_gadgets/src/ecc/chip.rs @@ -2,7 +2,7 @@ use super::{BaseFitsInScalarInstructions, EccInstructions, FixedPoints}; use crate::utilities::{ - lookup_range_check::{PallasLookupRC, PallasLookupRC10b}, + lookup_range_check::{PallasLookupRC, PallasLookupRCConfig}, UtilitiesInstructions, }; use arrayvec::ArrayVec; @@ -139,7 +139,7 @@ impl From for EccPoint { #[allow(non_snake_case)] pub struct EccConfig< FixedPoints: super::FixedPoints, - Lookup: PallasLookupRC = PallasLookupRC10b, + Lookup: PallasLookupRC = PallasLookupRCConfig, > { /// Advice columns needed by instructions in the ECC chip. pub advices: [Column; 10], @@ -232,7 +232,7 @@ pub trait FixedPoint: std::fmt::Debug + Eq + Clone { #[derive(Clone, Debug, Eq, PartialEq)] pub struct EccChip< FixedPoints: super::FixedPoints, - Lookup: PallasLookupRC = PallasLookupRC10b, + Lookup: PallasLookupRC = PallasLookupRCConfig, > { config: EccConfig, } diff --git a/halo2_gadgets/src/ecc/chip/mul.rs b/halo2_gadgets/src/ecc/chip/mul.rs index bc2c00e7c..e4e200488 100644 --- a/halo2_gadgets/src/ecc/chip/mul.rs +++ b/halo2_gadgets/src/ecc/chip/mul.rs @@ -1,6 +1,6 @@ use super::{add, EccPoint, NonIdentityEccPoint, ScalarVar, T_Q}; use crate::utilities::{ - lookup_range_check::{PallasLookupRC, PallasLookupRC10b}, + lookup_range_check::{PallasLookupRC, PallasLookupRCConfig}, {bool_check, ternary}, }; use std::{ @@ -46,7 +46,7 @@ const INCOMPLETE_LO_LEN: usize = INCOMPLETE_LEN - INCOMPLETE_HI_LEN; const COMPLETE_RANGE: Range = INCOMPLETE_LEN..(INCOMPLETE_LEN + NUM_COMPLETE_BITS); #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct Config { +pub struct Config { // Selector used to check switching logic on LSB q_mul_lsb: Selector, // Configuration used in complete addition diff --git a/halo2_gadgets/src/ecc/chip/mul/overflow.rs b/halo2_gadgets/src/ecc/chip/mul/overflow.rs index 8853439bd..482594e62 100644 --- a/halo2_gadgets/src/ecc/chip/mul/overflow.rs +++ b/halo2_gadgets/src/ecc/chip/mul/overflow.rs @@ -1,7 +1,7 @@ use super::{T_Q, Z}; use crate::{ sinsemilla::primitives as sinsemilla, - utilities::lookup_range_check::{PallasLookupRC, PallasLookupRC10b}, + utilities::lookup_range_check::{PallasLookupRC, PallasLookupRCConfig}, }; use group::ff::PrimeField; @@ -16,7 +16,7 @@ use pasta_curves::pallas; use std::iter; #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct Config { +pub struct Config { // Selector to check z_0 = alpha + t_q (mod p) q_mul_overflow: Selector, // 10-bit lookup table diff --git a/halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs b/halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs index 1116497ab..e6060ec42 100644 --- a/halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs +++ b/halo2_gadgets/src/ecc/chip/mul_fixed/base_field_elem.rs @@ -3,7 +3,7 @@ use super::H_BASE; use crate::utilities::{ bitrange_subset, bool_check, - lookup_range_check::{PallasLookupRC, PallasLookupRC10b}, + lookup_range_check::{PallasLookupRC, PallasLookupRCConfig}, range_check, }; @@ -18,7 +18,8 @@ use pasta_curves::pallas; use std::convert::TryInto; #[derive(Clone, Debug, Eq, PartialEq)] -pub struct Config, Lookup: PallasLookupRC = PallasLookupRC10b> { +pub struct Config, Lookup: PallasLookupRC = PallasLookupRCConfig> +{ q_mul_fixed_base_field: Selector, canon_advices: [Column; 3], lookup_config: Lookup, diff --git a/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs b/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs index d7e78c309..eb402d0f2 100644 --- a/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs +++ b/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs @@ -260,7 +260,7 @@ pub mod tests { FixedPointShort, NonIdentityPoint, Point, ScalarFixedShort, }, utilities::{ - lookup_range_check::{LookupRangeCheck, PallasLookupRC, PallasLookupRC10b}, + lookup_range_check::{LookupRangeCheck, PallasLookupRC, PallasLookupRCConfig}, UtilitiesInstructions, }, }; @@ -428,7 +428,7 @@ pub mod tests { } impl Circuit for MyCircuit { - type Config = EccConfig; + type Config = EccConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { @@ -464,8 +464,8 @@ pub mod tests { let constants = meta.fixed_column(); meta.enable_constant(constants); - let range_check = PallasLookupRC10b::configure(meta, advices[9], lookup_table); - EccChip::::configure( + let range_check = PallasLookupRCConfig::configure(meta, advices[9], lookup_table); + EccChip::::configure( meta, advices, lagrange_coeffs, diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index 46cd2ad65..e79797b61 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -473,7 +473,7 @@ pub(crate) mod tests { }, sinsemilla::primitives::{self as sinsemilla, K}, tests::test_utils::{test_against_stored_proof, test_against_stored_vk}, - utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRC10b}, + utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig}, }; use group::{ff::Field, Curve}; @@ -519,9 +519,19 @@ pub(crate) mod tests { impl Circuit for MyCircuit { #[allow(clippy::type_complexity)] type Config = ( - EccConfig, - SinsemillaConfig, - SinsemillaConfig, + EccConfig, + SinsemillaConfig< + TestHashDomain, + TestCommitDomain, + TestFixedBases, + PallasLookupRCConfig, + >, + SinsemillaConfig< + TestHashDomain, + TestCommitDomain, + TestFixedBases, + PallasLookupRCConfig, + >, ); type FloorPlanner = SimpleFloorPlanner; @@ -567,9 +577,9 @@ pub(crate) mod tests { meta.lookup_table_column(), ); - let range_check = PallasLookupRC10b::configure(meta, advices[9], table_idx); + let range_check = PallasLookupRCConfig::configure(meta, advices[9], table_idx); - let ecc_config = EccChip::::configure( + let ecc_config = EccChip::::configure( meta, advices, lagrange_coeffs, @@ -609,7 +619,7 @@ pub(crate) mod tests { TestHashDomain, TestCommitDomain, TestFixedBases, - PallasLookupRC10b, + PallasLookupRCConfig, >::load(config.1.clone(), &mut layouter)?; // This MerkleCRH example is purely for illustrative purposes. diff --git a/halo2_gadgets/src/sinsemilla/chip.rs b/halo2_gadgets/src/sinsemilla/chip.rs index 454b6c915..069c115b2 100644 --- a/halo2_gadgets/src/sinsemilla/chip.rs +++ b/halo2_gadgets/src/sinsemilla/chip.rs @@ -9,7 +9,7 @@ use crate::{ chip::{DoubleAndAdd, NonIdentityEccPoint}, FixedPoints, }, - utilities::lookup_range_check::{PallasLookupRC, PallasLookupRC10b}, + utilities::lookup_range_check::{PallasLookupRC, PallasLookupRCConfig}, }; use std::marker::PhantomData; @@ -30,7 +30,7 @@ mod hash_to_point; /// Configuration for the Sinsemilla hash chip #[derive(Eq, PartialEq, Clone, Debug)] -pub struct SinsemillaConfig +pub struct SinsemillaConfig where Hash: HashDomains, F: FixedPoints, @@ -98,7 +98,7 @@ where /// /// [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, diff --git a/halo2_gadgets/src/sinsemilla/merkle.rs b/halo2_gadgets/src/sinsemilla/merkle.rs index 5c453a81a..95e9e401b 100644 --- a/halo2_gadgets/src/sinsemilla/merkle.rs +++ b/halo2_gadgets/src/sinsemilla/merkle.rs @@ -187,7 +187,7 @@ pub mod tests { tests::test_utils::{test_against_stored_proof, test_against_stored_vk}, utilities::{ i2lebsp, - lookup_range_check::{LookupRangeCheck, PallasLookupRC10b}, + lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig}, UtilitiesInstructions, }, }; @@ -213,8 +213,8 @@ pub mod tests { impl Circuit for MyCircuit { type Config = ( - MerkleConfig, - MerkleConfig, + MerkleConfig, + MerkleConfig, ); type FloorPlanner = SimpleFloorPlanner; @@ -252,7 +252,7 @@ pub mod tests { meta.lookup_table_column(), ); - let range_check = PallasLookupRC10b::configure(meta, advices[9], lookup.0); + let range_check = PallasLookupRCConfig::configure(meta, advices[9], lookup.0); let sinsemilla_config_1 = SinsemillaChip::configure( meta, @@ -287,7 +287,7 @@ pub mod tests { TestHashDomain, TestCommitDomain, TestFixedBases, - PallasLookupRC10b, + PallasLookupRCConfig, >::load(config.0.sinsemilla_config.clone(), &mut layouter)?; // Construct Merkle chips which will be placed side-by-side in the circuit. diff --git a/halo2_gadgets/src/sinsemilla/merkle/chip.rs b/halo2_gadgets/src/sinsemilla/merkle/chip.rs index 2410f8f72..b8ea59ead 100644 --- a/halo2_gadgets/src/sinsemilla/merkle/chip.rs +++ b/halo2_gadgets/src/sinsemilla/merkle/chip.rs @@ -12,7 +12,7 @@ use super::MerkleInstructions; use crate::{ sinsemilla::{primitives as sinsemilla, MessagePiece}, utilities::{ - lookup_range_check::{PallasLookupRC, PallasLookupRC10b}, + lookup_range_check::{PallasLookupRC, PallasLookupRCConfig}, RangeConstrained, }, { @@ -31,7 +31,7 @@ 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, @@ -55,7 +55,7 @@ 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, diff --git a/halo2_gadgets/src/tests/test_utils.rs b/halo2_gadgets/src/tests/test_utils.rs index d9a2ead12..ed73cc3c1 100644 --- a/halo2_gadgets/src/tests/test_utils.rs +++ b/halo2_gadgets/src/tests/test_utils.rs @@ -23,9 +23,9 @@ use halo2_proofs::{ const TEST_DATA_DIR: &str = "src/tests/circuit_data"; const GEN_ENV_VAR: &str = "CIRCUIT_TEST_GENERATE_NEW_DATA"; -/// A proof structure #[derive(Clone, Debug)] pub struct Proof(Vec); + impl AsRef<[u8]> for Proof { fn as_ref(&self) -> &[u8] { &self.0 @@ -61,6 +61,7 @@ impl Proof { let mut transcript = Blake2bRead::init(&self.0[..]); plonk::verify_proof(params, vk, strategy, &[&[]], &mut transcript) } + /// Constructs a new Proof value. pub fn new(bytes: Vec) -> Self { Proof(bytes) @@ -91,8 +92,7 @@ pub(crate) fn test_against_stored_vk>(circuit: &C, circ ); } -/// If the environment variable GEN_ENV_VAR_PROOF is set, -/// write the old proof in a file +/// If the env variable GEN_ENV_VAR is set, write the `Proof` to a file fn conditionally_save_proof_to_disk>( vk: &VerifyingKey, params: &Params, @@ -121,12 +121,11 @@ pub(crate) fn test_against_stored_proof>( let params: Params = Params::new(11); let vk = plonk::keygen_vk(¶ms, &circuit).unwrap(); - // Conditionally save proof to disk conditionally_save_proof_to_disk(&vk, ¶ms, circuit, &full_file_name); - // Read proof from disk + // Read the proof from storage let proof = Proof::new(fs::read(full_file_name).expect("Unable to read proof test file")); - // Verify the old proof with the new vk + // Verify the stored proof with the generated vk assert!(proof.verify(&vk, ¶ms).is_ok()); } diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 7ed6386d9..10a302e82 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -450,11 +450,11 @@ pub trait PallasLookupRC: { } -/// `PallasLookupRC10b` is a shorthand for `LookupRangeCheckConfig` specialized with +/// `PallasLookupRCConfig` is a shorthand for `LookupRangeCheckConfig` specialized with /// `pallas::Base` and `sinsemilla::K` and used to improve readability``` -pub type PallasLookupRC10b = LookupRangeCheckConfig; +pub type PallasLookupRCConfig = LookupRangeCheckConfig; -impl PallasLookupRC for PallasLookupRC10b {} +impl PallasLookupRC for PallasLookupRCConfig {} #[cfg(test)] mod tests {