diff --git a/halo2_gadgets/src/ecc.rs b/halo2_gadgets/src/ecc.rs index 060ea32b6..e534ce10a 100644 --- a/halo2_gadgets/src/ecc.rs +++ b/halo2_gadgets/src/ecc.rs @@ -625,14 +625,6 @@ pub(crate) mod tests { use group::{prime::PrimeCurveAffine, Curve, Group}; use std::marker::PhantomData; - use halo2_proofs::{ - circuit::{Layouter, SimpleFloorPlanner, Value}, - dev::MockProver, - plonk::{Circuit, ConstraintSystem, Error}, - }; - use lazy_static::lazy_static; - use pasta_curves::pallas; - use super::{ chip::{ find_zs_and_us, BaseFieldElem, EccChip, EccConfig, FixedPoint, FullScalar, ShortScalar, @@ -646,6 +638,13 @@ pub(crate) mod tests { PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, PallasLookupRangeCheckConfig, }, }; + use halo2_proofs::{ + circuit::{Layouter, SimpleFloorPlanner, Value}, + dev::MockProver, + plonk::{Circuit, ConstraintSystem, Error}, + }; + use lazy_static::lazy_static; + use pasta_curves::pallas; #[derive(Debug, Eq, PartialEq, Clone)] pub(crate) struct TestFixedBases; @@ -778,16 +777,22 @@ pub(crate) mod tests { _lookup_marker: PhantomData, } + impl MyCircuit { + fn new(test_errors: bool) -> Self { + Self { + test_errors, + _lookup_marker: PhantomData, + } + } + } + #[allow(non_snake_case)] impl Circuit for MyCircuit { type Config = EccConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuit { - test_errors: false, - _lookup_marker: PhantomData, - } + MyCircuit::new(false) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -962,21 +967,15 @@ pub(crate) mod tests { #[test] fn ecc_chip() { - let k = 11; - let circuit: MyCircuit = MyCircuit { - test_errors: true, - _lookup_marker: PhantomData, - }; + let k = 13; + let circuit = MyCircuit::::new(true); let prover = MockProver::run(k, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) } #[test] fn test_ecc_chip_against_stored_circuit() { - let circuit: MyCircuit = MyCircuit { - test_errors: false, - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(false); test_against_stored_circuit(circuit, "ecc_chip", 3872); } @@ -989,10 +988,7 @@ pub(crate) mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("Ecc Chip Layout", ("sans-serif", 60)).unwrap(); - let circuit: MyCircuit = MyCircuit { - test_errors: false, - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(false); halo2_proofs::dev::CircuitLayout::default() .render(13, &circuit, &root) .unwrap(); @@ -1000,11 +996,8 @@ pub(crate) mod tests { #[test] fn ecc_chip_4_5_b() { - let k = 11; - let circuit: MyCircuit = MyCircuit { - test_errors: true, - _lookup_marker: PhantomData, - }; + let k = 13; + let circuit = MyCircuit::::new(true); let prover = MockProver::run(k, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) @@ -1012,10 +1005,7 @@ pub(crate) mod tests { #[test] fn test_against_stored_ecc_chip_4_5_b() { - let circuit: MyCircuit = MyCircuit { - test_errors: false, - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(false); test_against_stored_circuit(circuit, "ecc_chip_4_5_b", 3968); } @@ -1029,10 +1019,7 @@ pub(crate) mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("Ecc Chip Layout", ("sans-serif", 60)).unwrap(); - let circuit: MyCircuit = MyCircuit { - test_errors: false, - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(false); halo2_proofs::dev::CircuitLayout::default() .render(13, &circuit, &root) .unwrap(); diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index 6f56e35da..4d87fe757 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -589,6 +589,14 @@ pub(crate) mod tests { _lookup_marker: PhantomData, } + impl MyCircuit { + fn new() -> Self { + Self { + _lookup_marker: PhantomData, + } + } + } + type MyConfig = ( EccConfig, SinsemillaConfig, @@ -805,9 +813,7 @@ pub(crate) mod tests { type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuit { - _lookup_marker: PhantomData, - } + MyCircuit::new() } #[allow(non_snake_case)] @@ -827,18 +833,14 @@ pub(crate) mod tests { #[test] fn sinsemilla_chip() { let k = 11; - let circuit: MyCircuit = MyCircuit { - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(); let prover = MockProver::run(k, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) } #[test] fn test_sinsemilla_chip_against_stored_circuit() { - let circuit: MyCircuit = MyCircuit { - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(); test_against_stored_circuit(circuit, "sinsemilla_chip", 4576); } @@ -852,9 +854,7 @@ pub(crate) mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("SinsemillaHash", ("sans-serif", 60)).unwrap(); - let circuit: MyCircuit = MyCircuit { - _lookup_marker: PhantomData, - }; + let circuit = MyCircuit::::new(); halo2_proofs::dev::CircuitLayout::default() .render(11, &circuit, &root) .unwrap(); @@ -864,6 +864,14 @@ pub(crate) mod tests { _lookup_marker: PhantomData, } + impl MyCircuitWithHashFromPrivatePoint { + fn new() -> Self { + Self { + _lookup_marker: PhantomData, + } + } + } + impl Circuit for MyCircuitWithHashFromPrivatePoint { @@ -872,9 +880,7 @@ pub(crate) mod tests { type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuitWithHashFromPrivatePoint { - _lookup_marker: PhantomData, - } + MyCircuitWithHashFromPrivatePoint::new() } #[allow(non_snake_case)] @@ -894,20 +900,14 @@ pub(crate) mod tests { #[test] fn sinsemilla_with_hash_from_private_point_chip_4_5_b() { let k = 11; - let circuit: MyCircuitWithHashFromPrivatePoint = - MyCircuitWithHashFromPrivatePoint { - _lookup_marker: PhantomData, - }; + let circuit = MyCircuitWithHashFromPrivatePoint::::new(); let prover = MockProver::run(k, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) } #[test] fn test_against_stored_sinsemilla_with_hash_from_private_point_chip_4_5_b() { - let circuit: MyCircuitWithHashFromPrivatePoint = - MyCircuitWithHashFromPrivatePoint { - _lookup_marker: PhantomData, - }; + let circuit = MyCircuitWithHashFromPrivatePoint::::new(); test_against_stored_circuit(circuit, "sinsemilla_with_private_init_chip_4_5_b", 4672); } @@ -924,10 +924,7 @@ pub(crate) mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("SinsemillaHash", ("sans-serif", 60)).unwrap(); - let circuit: MyCircuitWithHashFromPrivatePoint = - MyCircuitWithHashFromPrivatePoint { - _lookup_marker: PhantomData, - }; + let circuit = MyCircuitWithHashFromPrivatePoint::::new(); halo2_proofs::dev::CircuitLayout::default() .render(11, &circuit, &root) .unwrap(); diff --git a/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs b/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs index ac81a5e48..c3d928ca6 100644 --- a/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs +++ b/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs @@ -471,7 +471,6 @@ where Ok((x_a, y_a, zs)) } - #[allow(unused_variables)] #[allow(non_snake_case)] #[allow(clippy::type_complexity)] diff --git a/halo2_gadgets/src/sinsemilla/merkle.rs b/halo2_gadgets/src/sinsemilla/merkle.rs index adf1f02b3..e0e14afc3 100644 --- a/halo2_gadgets/src/sinsemilla/merkle.rs +++ b/halo2_gadgets/src/sinsemilla/merkle.rs @@ -216,6 +216,21 @@ pub mod tests { _lookup_marker: PhantomData, } + impl MyCircuit { + fn new( + leaf: Value, + leaf_pos: Value, + merkle_path: Value<[pallas::Base; MERKLE_DEPTH]>, + ) -> Self { + Self { + leaf, + leaf_pos, + merkle_path, + _lookup_marker: PhantomData, + } + } + } + type MyConfig = ( MerkleConfig, MerkleConfig, @@ -286,12 +301,7 @@ pub mod tests { type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuit { - leaf: Value::default(), - leaf_pos: Value::default(), - merkle_path: Value::default(), - _lookup_marker: PhantomData, - } + MyCircuit::new(Value::default(), Value::default(), Value::default()) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -393,12 +403,11 @@ pub mod tests { .collect(); // The root is provided as a public input in the Orchard circuit. - MyCircuit { - leaf: Value::known(leaf), - leaf_pos: Value::known(pos), - merkle_path: Value::known(path.try_into().unwrap()), - _lookup_marker: PhantomData, - } + MyCircuit::new( + Value::known(leaf), + Value::known(pos), + Value::known(path.try_into().unwrap()), + ) } #[test] @@ -444,6 +453,21 @@ pub mod tests { _lookup_marker: PhantomData, } + impl MyCircuitWithHashFromPrivatePoint { + fn new( + leaf: Value, + leaf_pos: Value, + merkle_path: Value<[pallas::Base; MERKLE_DEPTH]>, + ) -> Self { + Self { + leaf, + leaf_pos, + merkle_path, + _lookup_marker: PhantomData, + } + } + } + impl Circuit for MyCircuitWithHashFromPrivatePoint { @@ -451,12 +475,11 @@ pub mod tests { type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuitWithHashFromPrivatePoint { - leaf: Value::default(), - leaf_pos: Value::default(), - merkle_path: Value::default(), - _lookup_marker: PhantomData, - } + MyCircuitWithHashFromPrivatePoint::new( + Value::default(), + Value::default(), + Value::default(), + ) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -559,12 +582,11 @@ pub mod tests { .collect(); // The root is provided as a public input in the Orchard circuit. - MyCircuitWithHashFromPrivatePoint { - leaf: Value::known(leaf), - leaf_pos: Value::known(pos), - merkle_path: Value::known(path.try_into().unwrap()), - _lookup_marker: PhantomData, - } + MyCircuitWithHashFromPrivatePoint::new( + Value::known(leaf), + Value::known(pos), + Value::known(path.try_into().unwrap()), + ) } #[test] fn merkle_with_hash_from_private_point_chip_4_5_b() { diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 83ed67ee3..784d80eb4 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -718,8 +718,16 @@ mod tests { #[derive(Clone, Copy)] struct MyLookupCircuit> { num_words: usize, - _field_marker: PhantomData, - _lookup_marker: PhantomData, + _marker: PhantomData<(F, Lookup)>, + } + + impl> MyLookupCircuit { + fn new(num_words: usize) -> Self { + MyLookupCircuit { + num_words, + _marker: PhantomData, + } + } } impl + std::clone::Clone> Circuit @@ -729,11 +737,7 @@ mod tests { type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyLookupCircuit { - num_words: self.num_words, - _field_marker: PhantomData, - _lookup_marker: PhantomData, - } + MyLookupCircuit::new(self.num_words) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -808,50 +812,27 @@ mod tests { #[test] fn lookup_range_check() { - let circuit: MyLookupCircuit = - MyLookupCircuit { - num_words: 6, - _field_marker: PhantomData, - _lookup_marker: PhantomData, - }; - + let circuit = MyLookupCircuit::::new(6); let prover = MockProver::::run(11, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())); } #[test] fn test_lookup_range_check_against_stored_circuit() { - let circuit: MyLookupCircuit = - MyLookupCircuit { - num_words: 6, - _field_marker: PhantomData, - _lookup_marker: PhantomData, - }; - + let circuit = MyLookupCircuit::::new(6); test_against_stored_circuit(circuit, "lookup_range_check", 1888); } #[test] fn lookup_range_check_4_5_b() { - let circuit: MyLookupCircuit = - MyLookupCircuit { - num_words: 6, - _field_marker: PhantomData, - _lookup_marker: PhantomData, - }; - + let circuit = MyLookupCircuit::::new(6); let prover = MockProver::::run(11, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())); } #[test] fn test_lookup_range_check_against_stored_circuit_4_5_b() { - let circuit: MyLookupCircuit = - MyLookupCircuit { - num_words: 6, - _field_marker: PhantomData, - _lookup_marker: PhantomData, - }; + let circuit = MyLookupCircuit::::new(6); test_against_stored_circuit(circuit, "lookup_range_check_4_5_b", 2048); } @@ -862,6 +843,16 @@ mod tests { _lookup_marker: PhantomData, } + impl> MyShortRangeCheckCircuit { + fn new(element: Value, num_bits: usize) -> Self { + MyShortRangeCheckCircuit { + element, + num_bits, + _lookup_marker: PhantomData, + } + } + } + impl + std::clone::Clone> Circuit for MyShortRangeCheckCircuit { @@ -869,11 +860,7 @@ mod tests { type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyShortRangeCheckCircuit { - element: Value::unknown(), - num_bits: self.num_bits, - _lookup_marker: PhantomData, - } + MyShortRangeCheckCircuit::new(Value::unknown(), self.num_bits) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -911,11 +898,8 @@ mod tests { circuit_name: &str, expected_proof_size: usize, ) { - let circuit: MyShortRangeCheckCircuit = MyShortRangeCheckCircuit { - element: Value::known(element), - num_bits, - _lookup_marker: PhantomData, - }; + let circuit = + MyShortRangeCheckCircuit::::new(Value::known(element), num_bits); let prover = MockProver::::run(11, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), *proof_result);