From a34d146409c067a012ec3aef13f8a0c8454147f9 Mon Sep 17 00:00:00 2001 From: Constance Beguier Date: Fri, 2 Aug 2024 10:26:56 +0200 Subject: [PATCH] Some renamings --- halo2_gadgets/src/ecc.rs | 33 ++++---- halo2_gadgets/src/ecc/chip/mul_fixed/short.rs | 50 +++++------ halo2_gadgets/src/sinsemilla.rs | 58 ++++++------- halo2_gadgets/src/sinsemilla/merkle.rs | 77 +++++++++-------- ...chip_4_5_b.bin => proof_ecc_chip_4_5b.bin} | Bin ....bin => proof_lookup_range_check_4_5b.bin} | Bin ...of_merkle_with_private_init_chip_4_5b.bin} | Bin ...=> proof_short_range_check_4_5b_case0.bin} | Bin ...=> proof_short_range_check_4_5b_case1.bin} | Bin ...=> proof_short_range_check_4_5b_case2.bin} | Bin ...=> proof_short_range_check_4_5b_case3.bin} | Bin ...insemilla_with_private_init_chip_4_5b.bin} | Bin ...hip_4_5_b.rdata => vk_ecc_chip_4_5b.rdata} | 0 ...rdata => vk_lookup_range_check_4_5b.rdata} | 0 ..._merkle_with_private_init_chip_4_5b.rdata} | 0 ... => vk_short_range_check_4_5b_case0.rdata} | 0 ... => vk_short_range_check_4_5b_case1.rdata} | 0 ... => vk_short_range_check_4_5b_case2.rdata} | 0 ... => vk_short_range_check_4_5b_case3.rdata} | 0 ...semilla_with_private_init_chip_4_5b.rdata} | 0 halo2_gadgets/src/utilities/cond_swap.rs | 34 ++++---- .../src/utilities/lookup_range_check.rs | 80 +++++++++--------- 22 files changed, 169 insertions(+), 163 deletions(-) rename halo2_gadgets/src/tests/circuit_data/{proof_ecc_chip_4_5_b.bin => proof_ecc_chip_4_5b.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_lookup_range_check_4_5_b.bin => proof_lookup_range_check_4_5b.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_merkle_with_private_init_chip_4_5_b.bin => proof_merkle_with_private_init_chip_4_5b.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_short_range_check_4_5_b_case0.bin => proof_short_range_check_4_5b_case0.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_short_range_check_4_5_b_case1.bin => proof_short_range_check_4_5b_case1.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_short_range_check_4_5_b_case2.bin => proof_short_range_check_4_5b_case2.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_short_range_check_4_5_b_case3.bin => proof_short_range_check_4_5b_case3.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{proof_sinsemilla_with_private_init_chip_4_5_b.bin => proof_sinsemilla_with_private_init_chip_4_5b.bin} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_ecc_chip_4_5_b.rdata => vk_ecc_chip_4_5b.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_lookup_range_check_4_5_b.rdata => vk_lookup_range_check_4_5b.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_merkle_with_private_init_chip_4_5_b.rdata => vk_merkle_with_private_init_chip_4_5b.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_short_range_check_4_5_b_case0.rdata => vk_short_range_check_4_5b_case0.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_short_range_check_4_5_b_case1.rdata => vk_short_range_check_4_5b_case1.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_short_range_check_4_5_b_case2.rdata => vk_short_range_check_4_5b_case2.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_short_range_check_4_5_b_case3.rdata => vk_short_range_check_4_5b_case3.rdata} (100%) rename halo2_gadgets/src/tests/circuit_data/{vk_sinsemilla_with_private_init_chip_4_5_b.rdata => vk_sinsemilla_with_private_init_chip_4_5b.rdata} (100%) diff --git a/halo2_gadgets/src/ecc.rs b/halo2_gadgets/src/ecc.rs index e534ce10a..78e389395 100644 --- a/halo2_gadgets/src/ecc.rs +++ b/halo2_gadgets/src/ecc.rs @@ -635,7 +635,7 @@ pub(crate) mod tests { use crate::{ tests::test_utils::test_against_stored_circuit, utilities::lookup_range_check::{ - PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, PallasLookupRangeCheckConfig, + PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig, }, }; use halo2_proofs::{ @@ -772,12 +772,12 @@ pub(crate) mod tests { type Base = BaseField; } - struct MyCircuit { + struct EccCircuit { test_errors: bool, _lookup_marker: PhantomData, } - impl MyCircuit { + impl EccCircuit { fn new(test_errors: bool) -> Self { Self { test_errors, @@ -787,12 +787,12 @@ pub(crate) mod tests { } #[allow(non_snake_case)] - impl Circuit for MyCircuit { + impl Circuit for EccCircuit { type Config = EccConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuit::new(false) + EccCircuit::new(false) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -968,14 +968,14 @@ pub(crate) mod tests { #[test] fn ecc_chip() { let k = 13; - let circuit = MyCircuit::::new(true); + let circuit = EccCircuit::::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::::new(false); + let circuit = EccCircuit::::new(false); test_against_stored_circuit(circuit, "ecc_chip", 3872); } @@ -988,38 +988,37 @@ pub(crate) mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("Ecc Chip Layout", ("sans-serif", 60)).unwrap(); - let circuit = MyCircuit::::new(false); + let circuit = EccCircuit::::new(false); halo2_proofs::dev::CircuitLayout::default() .render(13, &circuit, &root) .unwrap(); } #[test] - fn ecc_chip_4_5_b() { + fn ecc_chip_4_5b() { let k = 13; - let circuit = MyCircuit::::new(true); + let circuit = EccCircuit::::new(true); let prover = MockProver::run(k, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) } #[test] - fn test_against_stored_ecc_chip_4_5_b() { - let circuit = MyCircuit::::new(false); - test_against_stored_circuit(circuit, "ecc_chip_4_5_b", 3968); + fn test_against_stored_ecc_chip_4_5b() { + let circuit = EccCircuit::::new(false); + test_against_stored_circuit(circuit, "ecc_chip_4_5b", 3968); } #[cfg(feature = "test-dev-graph")] #[test] - fn print_ecc_chip_4_5_b() { + fn print_ecc_chip_4_5b() { use plotters::prelude::*; - let root = - BitMapBackend::new("ecc-chip-4-5-b-layout.png", (1024, 7680)).into_drawing_area(); + let root = BitMapBackend::new("ecc-chip-4_5b-layout.png", (1024, 7680)).into_drawing_area(); root.fill(&WHITE).unwrap(); let root = root.titled("Ecc Chip Layout", ("sans-serif", 60)).unwrap(); - let circuit = MyCircuit::::new(false); + let circuit = EccCircuit::::new(false); halo2_proofs::dev::CircuitLayout::default() .render(13, &circuit, &root) .unwrap(); diff --git a/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs b/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs index 0d7216388..d06049d3f 100644 --- a/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs +++ b/halo2_gadgets/src/ecc/chip/mul_fixed/short.rs @@ -325,7 +325,7 @@ pub mod tests { }, utilities::{ lookup_range_check::{ - PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, + PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig, }, UtilitiesInstructions, @@ -471,7 +471,7 @@ pub mod tests { } #[derive(Default)] - struct MyMagnitudeSignCircuit { + struct MagnitudeSignCircuit { magnitude: Value, sign: Value, // For test checking @@ -480,17 +480,17 @@ pub mod tests { } impl UtilitiesInstructions - for MyMagnitudeSignCircuit + for MagnitudeSignCircuit { type Var = AssignedCell; } - impl Circuit for MyMagnitudeSignCircuit { + impl Circuit for MagnitudeSignCircuit { type Config = EccConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyMagnitudeSignCircuit { + MagnitudeSignCircuit { magnitude: Value::unknown(), sign: Value::unknown(), magnitude_error: Value::unknown(), @@ -584,41 +584,41 @@ pub mod tests { } } - impl MyMagnitudeSignCircuit { + impl MagnitudeSignCircuit { fn test_invalid_magnitude_sign() { // Magnitude larger than 64 bits should fail { let circuits = [ // 2^64 - MyMagnitudeSignCircuit:: { + MagnitudeSignCircuit:: { magnitude: Value::known(pallas::Base::from_u128(1 << 64)), sign: Value::known(pallas::Base::one()), magnitude_error: Value::known(pallas::Base::from(1 << 1)), _lookup_marker: PhantomData, }, // -2^64 - MyMagnitudeSignCircuit:: { + MagnitudeSignCircuit:: { magnitude: Value::known(pallas::Base::from_u128(1 << 64)), sign: Value::known(-pallas::Base::one()), magnitude_error: Value::known(pallas::Base::from(1 << 1)), _lookup_marker: PhantomData, }, // 2^66 - MyMagnitudeSignCircuit:: { + MagnitudeSignCircuit:: { magnitude: Value::known(pallas::Base::from_u128(1 << 66)), sign: Value::known(pallas::Base::one()), magnitude_error: Value::known(pallas::Base::from(1 << 3)), _lookup_marker: PhantomData, }, // -2^66 - MyMagnitudeSignCircuit:: { + MagnitudeSignCircuit:: { magnitude: Value::known(pallas::Base::from_u128(1 << 66)), sign: Value::known(-pallas::Base::one()), magnitude_error: Value::known(pallas::Base::from(1 << 3)), _lookup_marker: PhantomData, }, // 2^254 - MyMagnitudeSignCircuit:: { + MagnitudeSignCircuit:: { magnitude: Value::known(pallas::Base::from_u128(1 << 127).square()), sign: Value::known(pallas::Base::one()), magnitude_error: Value::known( @@ -627,7 +627,7 @@ pub mod tests { _lookup_marker: PhantomData, }, // -2^254 - MyMagnitudeSignCircuit:: { + MagnitudeSignCircuit:: { magnitude: Value::known(pallas::Base::from_u128(1 << 127).square()), sign: Value::known(-pallas::Base::one()), magnitude_error: Value::known( @@ -682,7 +682,7 @@ pub mod tests { // Sign that is not +/- 1 should fail { let magnitude_u64 = rand::random::(); - let circuit: MyMagnitudeSignCircuit = MyMagnitudeSignCircuit { + let circuit: MagnitudeSignCircuit = MagnitudeSignCircuit { magnitude: Value::known(pallas::Base::from(magnitude_u64)), sign: Value::known(pallas::Base::zero()), magnitude_error: Value::unknown(), @@ -744,12 +744,12 @@ pub mod tests { #[test] fn invalid_magnitude_sign() { - MyMagnitudeSignCircuit::::test_invalid_magnitude_sign(); + MagnitudeSignCircuit::::test_invalid_magnitude_sign(); } #[test] - fn invalid_magnitude_sign_4_5_b() { - MyMagnitudeSignCircuit::::test_invalid_magnitude_sign(); + fn invalid_magnitude_sign_4_5b() { + MagnitudeSignCircuit::::test_invalid_magnitude_sign(); } pub(crate) fn test_mul_sign( @@ -819,24 +819,24 @@ pub mod tests { } #[derive(Default)] - struct MyMulSignCircuit { + struct MulSignCircuit { base: Value, sign: Value, _lookup_marker: PhantomData, } impl UtilitiesInstructions - for MyMulSignCircuit + for MulSignCircuit { type Var = AssignedCell; } - impl Circuit for MyMulSignCircuit { + impl Circuit for MulSignCircuit { type Config = EccConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyMulSignCircuit { + MulSignCircuit { base: Value::unknown(), sign: Value::unknown(), _lookup_marker: PhantomData, @@ -900,12 +900,12 @@ pub mod tests { } } - impl MyMulSignCircuit { + impl MulSignCircuit { fn test_invalid_magnitude_sign() { // Sign that is not +/- 1 should fail // Generate a random non-identity point let point = pallas::Point::random(rand::rngs::OsRng); - let circuit: MyMulSignCircuit = MyMulSignCircuit { + let circuit: MulSignCircuit = MulSignCircuit { base: Value::known(point.to_affine()), sign: Value::known(pallas::Base::zero()), _lookup_marker: PhantomData, @@ -954,10 +954,10 @@ pub mod tests { #[test] fn invalid_sign_in_mul_sign() { - MyMulSignCircuit::::test_invalid_magnitude_sign(); + MulSignCircuit::::test_invalid_magnitude_sign(); } #[test] - fn invalid_sign_in_mul_sign_4_5_b() { - MyMulSignCircuit::::test_invalid_magnitude_sign(); + fn invalid_sign_in_mul_sign_4_5b() { + MulSignCircuit::::test_invalid_magnitude_sign(); } } diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index 35b27869d..ee70342e3 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -542,7 +542,7 @@ pub(crate) mod tests { sinsemilla::primitives::{self as sinsemilla, K}, tests::test_utils::test_against_stored_circuit, utilities::lookup_range_check::{ - PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, PallasLookupRangeCheckConfig, + PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig, }, }; @@ -585,11 +585,11 @@ pub(crate) mod tests { } } - struct MyCircuit { + struct SinsemillaCircuit { _lookup_marker: PhantomData, } - impl MyCircuit { + impl SinsemillaCircuit { fn new() -> Self { Self { _lookup_marker: PhantomData, @@ -597,7 +597,7 @@ pub(crate) mod tests { } } - type MyConfig = ( + type EccSinsemillaConfig = ( EccConfig, SinsemillaConfig, SinsemillaConfig, @@ -606,7 +606,7 @@ pub(crate) mod tests { fn configure( meta: &mut ConstraintSystem, enable_hash_from_private_point: bool, - ) -> MyConfig { + ) -> EccSinsemillaConfig { let advices = [ meta.advice_column(), meta.advice_column(), @@ -674,7 +674,7 @@ pub(crate) mod tests { } fn synthesize( - config: MyConfig, + config: EccSinsemillaConfig, mut layouter: impl Layouter, ) -> Result<(), Error> { let rng = OsRng; @@ -807,12 +807,12 @@ pub(crate) mod tests { } } - impl Circuit for MyCircuit { - type Config = MyConfig; + impl Circuit for SinsemillaCircuit { + type Config = EccSinsemillaConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuit::new() + SinsemillaCircuit::new() } #[allow(non_snake_case)] @@ -832,14 +832,14 @@ pub(crate) mod tests { #[test] fn sinsemilla_chip() { let k = 11; - let circuit = MyCircuit::::new(); + let circuit = SinsemillaCircuit::::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::::new(); + let circuit = SinsemillaCircuit::::new(); test_against_stored_circuit(circuit, "sinsemilla_chip", 4576); } @@ -853,17 +853,17 @@ pub(crate) mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("SinsemillaHash", ("sans-serif", 60)).unwrap(); - let circuit = MyCircuit::::new(); + let circuit = SinsemillaCircuit::::new(); halo2_proofs::dev::CircuitLayout::default() .render(11, &circuit, &root) .unwrap(); } - struct MyCircuitWithHashFromPrivatePoint { + struct SinsemillaCircuitWithHashFromPrivatePoint { _lookup_marker: PhantomData, } - impl MyCircuitWithHashFromPrivatePoint { + impl SinsemillaCircuitWithHashFromPrivatePoint { fn new() -> Self { Self { _lookup_marker: PhantomData, @@ -872,13 +872,13 @@ pub(crate) mod tests { } impl Circuit - for MyCircuitWithHashFromPrivatePoint + for SinsemillaCircuitWithHashFromPrivatePoint { - type Config = MyConfig; + type Config = EccSinsemillaConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuitWithHashFromPrivatePoint::new() + SinsemillaCircuitWithHashFromPrivatePoint::new() } #[allow(non_snake_case)] @@ -896,33 +896,33 @@ pub(crate) mod tests { } #[test] - fn sinsemilla_with_hash_from_private_point_chip_4_5_b() { + fn sinsemilla_with_hash_from_private_point_chip_4_5b() { let k = 11; - let circuit = MyCircuitWithHashFromPrivatePoint::::new(); + let circuit = + SinsemillaCircuitWithHashFromPrivatePoint::::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::::new(); - test_against_stored_circuit(circuit, "sinsemilla_with_private_init_chip_4_5_b", 4672); + fn test_against_stored_sinsemilla_with_hash_from_private_point_chip_4_5b() { + let circuit = + SinsemillaCircuitWithHashFromPrivatePoint::::new(); + test_against_stored_circuit(circuit, "sinsemilla_with_private_init_chip_4_5b", 4672); } #[cfg(feature = "test-dev-graph")] #[test] - fn print_sinsemilla_with_hash_from_private_point_chip_4_5_b() { + fn print_sinsemilla_with_hash_from_private_point_chip_4_5b() { use plotters::prelude::*; - let root = BitMapBackend::new( - "sinsemilla-with-private-init-4-5-b-layout.png", - (1024, 7680), - ) - .into_drawing_area(); + let root = BitMapBackend::new("sinsemilla-with-private-init-4_5b-layout.png", (1024, 7680)) + .into_drawing_area(); root.fill(&WHITE).unwrap(); let root = root.titled("SinsemillaHash", ("sans-serif", 60)).unwrap(); - let circuit = MyCircuitWithHashFromPrivatePoint::::new(); + let circuit = + SinsemillaCircuitWithHashFromPrivatePoint::::new(); halo2_proofs::dev::CircuitLayout::default() .render(11, &circuit, &root) .unwrap(); diff --git a/halo2_gadgets/src/sinsemilla/merkle.rs b/halo2_gadgets/src/sinsemilla/merkle.rs index bad9672e2..ae2f3883b 100644 --- a/halo2_gadgets/src/sinsemilla/merkle.rs +++ b/halo2_gadgets/src/sinsemilla/merkle.rs @@ -188,7 +188,7 @@ pub mod tests { utilities::{ i2lebsp, lookup_range_check::{ - PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, + PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig, }, UtilitiesInstructions, @@ -209,14 +209,14 @@ pub mod tests { const MERKLE_DEPTH: usize = 32; #[derive(Default)] - struct MyCircuit { + struct MerkleCircuit { leaf: Value, leaf_pos: Value, merkle_path: Value<[pallas::Base; MERKLE_DEPTH]>, _lookup_marker: PhantomData, } - impl MyCircuit { + impl MerkleCircuit { fn new( leaf: Value, leaf_pos: Value, @@ -231,15 +231,14 @@ pub mod tests { } } - type MyConfig = ( - MerkleConfig, - MerkleConfig, - ); - + #[allow(clippy::type_complexity)] fn configure( meta: &mut ConstraintSystem, enable_hash_from_private_point: bool, - ) -> MyConfig { + ) -> ( + MerkleConfig, + MerkleConfig, + ) { let advices = [ meta.advice_column(), meta.advice_column(), @@ -296,12 +295,15 @@ pub mod tests { (config1, config2) } - impl Circuit for MyCircuit { - type Config = MyConfig; + impl Circuit for MerkleCircuit { + type Config = ( + MerkleConfig, + MerkleConfig, + ); type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuit::new(Value::default(), Value::default(), Value::default()) + MerkleCircuit::new(Value::default(), Value::default(), Value::default()) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -390,7 +392,7 @@ pub mod tests { } } - fn generate_circuit() -> MyCircuit { + fn generate_circuit() -> MerkleCircuit { let mut rng = OsRng; // Choose a random leaf and position @@ -403,7 +405,7 @@ pub mod tests { .collect(); // The root is provided as a public input in the Orchard circuit. - MyCircuit::new( + MerkleCircuit::new( Value::known(leaf), Value::known(pos), Value::known(path.try_into().unwrap()), @@ -412,7 +414,7 @@ pub mod tests { #[test] fn merkle_chip() { - let circuit: MyCircuit = generate_circuit(); + let circuit: MerkleCircuit = generate_circuit(); let prover = MockProver::run(11, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) @@ -420,7 +422,7 @@ pub mod tests { #[test] fn test_merkle_chip_against_stored_circuit() { - let circuit: MyCircuit = generate_circuit(); + let circuit: MerkleCircuit = generate_circuit(); test_against_stored_circuit(circuit, "merkle_chip", 4160); } @@ -433,7 +435,7 @@ pub mod tests { root.fill(&WHITE).unwrap(); let root = root.titled("MerkleCRH Path", ("sans-serif", 60)).unwrap(); - let circuit: MyCircuit = MyCircuit { + let circuit: MerkleCircuit = MerkleCircuit { leaf: Value::default(), leaf_pos: Value::default(), merkle_path: Value::default(), @@ -446,14 +448,14 @@ pub mod tests { } #[derive(Default)] - struct MyCircuitWithHashFromPrivatePoint { + struct MerkleCircuitWithHashFromPrivatePoint { leaf: Value, leaf_pos: Value, merkle_path: Value<[pallas::Base; MERKLE_DEPTH]>, _lookup_marker: PhantomData, } - impl MyCircuitWithHashFromPrivatePoint { + impl MerkleCircuitWithHashFromPrivatePoint { fn new( leaf: Value, leaf_pos: Value, @@ -469,13 +471,16 @@ pub mod tests { } impl Circuit - for MyCircuitWithHashFromPrivatePoint + for MerkleCircuitWithHashFromPrivatePoint { - type Config = MyConfig; + type Config = ( + MerkleConfig, + MerkleConfig, + ); type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyCircuitWithHashFromPrivatePoint::new( + MerkleCircuitWithHashFromPrivatePoint::new( Value::default(), Value::default(), Value::default(), @@ -568,8 +573,8 @@ pub mod tests { } } - fn generate_circuit_4_5_b( - ) -> MyCircuitWithHashFromPrivatePoint { + fn generate_circuit_4_5b( + ) -> MerkleCircuitWithHashFromPrivatePoint { let mut rng = OsRng; // Choose a random leaf and position @@ -582,44 +587,44 @@ pub mod tests { .collect(); // The root is provided as a public input in the Orchard circuit. - MyCircuitWithHashFromPrivatePoint::new( + MerkleCircuitWithHashFromPrivatePoint::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() { - let circuit: MyCircuitWithHashFromPrivatePoint = - generate_circuit_4_5_b(); + fn merkle_with_hash_from_private_point_chip_4_5b() { + let circuit: MerkleCircuitWithHashFromPrivatePoint = + generate_circuit_4_5b(); let prover = MockProver::run(11, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), Ok(())) } #[test] - fn test_against_stored_merkle_with_hash_from_private_point_chip_4_5_b() { - let circuit: MyCircuitWithHashFromPrivatePoint = - generate_circuit_4_5_b(); + fn test_against_stored_merkle_with_hash_from_private_point_chip_4_5b() { + let circuit: MerkleCircuitWithHashFromPrivatePoint = + generate_circuit_4_5b(); - test_against_stored_circuit(circuit, "merkle_with_private_init_chip_4_5_b", 4160); + test_against_stored_circuit(circuit, "merkle_with_private_init_chip_4_5b", 4160); } #[cfg(feature = "test-dev-graph")] #[test] - fn print_merkle_with_hash_from_private_point_chip_4_5_b() { + fn print_merkle_with_hash_from_private_point_chip_4_5b() { use plotters::prelude::*; let root = BitMapBackend::new( - "merkle-path-with-private-init-4-5-b-layout.png", + "merkle-with-private-init-chip-4_5b-layout.png", (1024, 7680), ) .into_drawing_area(); root.fill(&WHITE).unwrap(); let root = root.titled("MerkleCRH Path", ("sans-serif", 60)).unwrap(); - let circuit: MyCircuitWithHashFromPrivatePoint = - MyCircuitWithHashFromPrivatePoint::new( + let circuit: MerkleCircuitWithHashFromPrivatePoint = + MerkleCircuitWithHashFromPrivatePoint::new( Value::default(), Value::default(), Value::default(), diff --git a/halo2_gadgets/src/tests/circuit_data/proof_ecc_chip_4_5_b.bin b/halo2_gadgets/src/tests/circuit_data/proof_ecc_chip_4_5b.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_ecc_chip_4_5_b.bin rename to halo2_gadgets/src/tests/circuit_data/proof_ecc_chip_4_5b.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_lookup_range_check_4_5_b.bin b/halo2_gadgets/src/tests/circuit_data/proof_lookup_range_check_4_5b.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_lookup_range_check_4_5_b.bin rename to halo2_gadgets/src/tests/circuit_data/proof_lookup_range_check_4_5b.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_merkle_with_private_init_chip_4_5_b.bin b/halo2_gadgets/src/tests/circuit_data/proof_merkle_with_private_init_chip_4_5b.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_merkle_with_private_init_chip_4_5_b.bin rename to halo2_gadgets/src/tests/circuit_data/proof_merkle_with_private_init_chip_4_5b.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case0.bin b/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case0.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case0.bin rename to halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case0.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case1.bin b/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case1.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case1.bin rename to halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case1.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case2.bin b/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case2.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case2.bin rename to halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case2.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case3.bin b/halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case3.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5_b_case3.bin rename to halo2_gadgets/src/tests/circuit_data/proof_short_range_check_4_5b_case3.bin diff --git a/halo2_gadgets/src/tests/circuit_data/proof_sinsemilla_with_private_init_chip_4_5_b.bin b/halo2_gadgets/src/tests/circuit_data/proof_sinsemilla_with_private_init_chip_4_5b.bin similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/proof_sinsemilla_with_private_init_chip_4_5_b.bin rename to halo2_gadgets/src/tests/circuit_data/proof_sinsemilla_with_private_init_chip_4_5b.bin diff --git a/halo2_gadgets/src/tests/circuit_data/vk_ecc_chip_4_5_b.rdata b/halo2_gadgets/src/tests/circuit_data/vk_ecc_chip_4_5b.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_ecc_chip_4_5_b.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_ecc_chip_4_5b.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_lookup_range_check_4_5_b.rdata b/halo2_gadgets/src/tests/circuit_data/vk_lookup_range_check_4_5b.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_lookup_range_check_4_5_b.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_lookup_range_check_4_5b.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_merkle_with_private_init_chip_4_5_b.rdata b/halo2_gadgets/src/tests/circuit_data/vk_merkle_with_private_init_chip_4_5b.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_merkle_with_private_init_chip_4_5_b.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_merkle_with_private_init_chip_4_5b.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case0.rdata b/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case0.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case0.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case0.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case1.rdata b/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case1.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case1.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case1.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case2.rdata b/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case2.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case2.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case2.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case3.rdata b/halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case3.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5_b_case3.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_short_range_check_4_5b_case3.rdata diff --git a/halo2_gadgets/src/tests/circuit_data/vk_sinsemilla_with_private_init_chip_4_5_b.rdata b/halo2_gadgets/src/tests/circuit_data/vk_sinsemilla_with_private_init_chip_4_5b.rdata similarity index 100% rename from halo2_gadgets/src/tests/circuit_data/vk_sinsemilla_with_private_init_chip_4_5_b.rdata rename to halo2_gadgets/src/tests/circuit_data/vk_sinsemilla_with_private_init_chip_4_5b.rdata diff --git a/halo2_gadgets/src/utilities/cond_swap.rs b/halo2_gadgets/src/utilities/cond_swap.rs index c2be61785..43a0f791c 100644 --- a/halo2_gadgets/src/utilities/cond_swap.rs +++ b/halo2_gadgets/src/utilities/cond_swap.rs @@ -300,7 +300,7 @@ mod tests { use crate::utilities::{ cond_swap::{CondSwapChip, CondSwapConfig, CondSwapInstructions}, lookup_range_check::{ - PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, PallasLookupRangeCheckConfig, + PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig, }, UtilitiesInstructions, }; @@ -317,13 +317,13 @@ mod tests { #[test] fn cond_swap() { #[derive(Default)] - struct MyCircuit { + struct CondSwapCircuit { a: Value, b: Value, swap: Value, } - impl Circuit for MyCircuit { + impl Circuit for CondSwapCircuit { type Config = CondSwapConfig; type FloorPlanner = SimpleFloorPlanner; @@ -380,7 +380,7 @@ mod tests { // Test swap case { - let circuit: MyCircuit = MyCircuit { + let circuit: CondSwapCircuit = CondSwapCircuit { a: Value::known(Base::random(rng)), b: Value::known(Base::random(rng)), swap: Value::known(true), @@ -391,7 +391,7 @@ mod tests { // Test non-swap case { - let circuit: MyCircuit = MyCircuit { + let circuit: CondSwapCircuit = CondSwapCircuit { a: Value::known(Base::random(rng)), b: Value::known(Base::random(rng)), swap: Value::known(false), @@ -420,7 +420,7 @@ mod tests { use rand::rngs::OsRng; #[derive(Clone, Debug)] - pub struct MyMuxConfig { + pub struct MuxConfig { primary: Column, advice: Column, cond_swap_config: CondSwapConfig, @@ -428,20 +428,20 @@ mod tests { } #[derive(Default)] - struct MyMuxCircuit { + struct MuxCircuit { left_point: Value, right_point: Value, choice: Value, _lookup_marker: PhantomData, } - impl MyMuxCircuit { + impl MuxCircuit { fn new( left_point: Value, right_point: Value, choice: Value, ) -> Self { - MyMuxCircuit { + MuxCircuit { left_point, right_point, choice, @@ -450,12 +450,12 @@ mod tests { } } - impl Circuit for MyMuxCircuit { - type Config = MyMuxConfig; + impl Circuit for MuxCircuit { + type Config = MuxConfig; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyMuxCircuit::::new(Value::default(), Value::default(), Value::default()) + MuxCircuit::::new(Value::default(), Value::default(), Value::default()) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -506,7 +506,7 @@ mod tests { range_check, ); - MyMuxConfig { + MuxConfig { primary, advice: advices[0], cond_swap_config, @@ -597,7 +597,7 @@ mod tests { } } - impl MyMuxCircuit { + impl MuxCircuit { fn test_mux_circuits() { // Test different circuits let mut circuits = vec![]; @@ -610,7 +610,7 @@ mod tests { }; let left_point = pallas::Point::random(OsRng).to_affine(); let right_point = pallas::Point::random(OsRng).to_affine(); - circuits.push(MyMuxCircuit:: { + circuits.push(MuxCircuit:: { left_point: Value::known(left_point), right_point: Value::known(right_point), choice: Value::known(choice_value), @@ -638,7 +638,7 @@ mod tests { } } - MyMuxCircuit::::test_mux_circuits(); - MyMuxCircuit::::test_mux_circuits(); + MuxCircuit::::test_mux_circuits(); + MuxCircuit::::test_mux_circuits(); } } diff --git a/halo2_gadgets/src/utilities/lookup_range_check.rs b/halo2_gadgets/src/utilities/lookup_range_check.rs index 784d80eb4..2a1715a33 100644 --- a/halo2_gadgets/src/utilities/lookup_range_check.rs +++ b/halo2_gadgets/src/utilities/lookup_range_check.rs @@ -465,14 +465,14 @@ impl PallasLookupRangeCheck for PallasLookupRangeCheckConfig {} /// Configuration that provides methods for an efficient 4, 5, and 10-bit lookup range check. #[derive(Eq, PartialEq, Debug, Clone, Copy)] -pub struct LookupRangeCheck45BConfig { +pub struct LookupRangeCheck4_5BConfig { base: LookupRangeCheckConfig, q_range_check_4: Selector, q_range_check_5: Selector, table_range_check_tag: TableColumn, } -impl LookupRangeCheck45BConfig { +impl LookupRangeCheck4_5BConfig { /// The `running_sum` advice column breaks the field element into `K`-bit /// words. It is used to construct the input expression to the lookup /// argument. @@ -498,7 +498,7 @@ impl LookupRangeCheck45BConfig { let q_range_check_4 = meta.complex_selector(); let q_range_check_5 = meta.complex_selector(); - let config = LookupRangeCheck45BConfig { + let config = LookupRangeCheck4_5BConfig { base: LookupRangeCheckConfig { q_lookup, q_running, @@ -595,7 +595,9 @@ impl LookupRangeCheck45BConfig { } } -impl LookupRangeCheck for LookupRangeCheck45BConfig { +impl LookupRangeCheck + for LookupRangeCheck4_5BConfig +{ fn config(&self) -> &LookupRangeCheckConfig { &self.base } @@ -685,13 +687,13 @@ impl LookupRangeCheck for LookupRangeCh } } -/// In this crate, `LookupRangeCheck45BConfig` is always used with `pallas::Base` as the prime field +/// In this crate, `LookupRangeCheck4_5BConfig` is always used with `pallas::Base` as the prime field /// and the constant `K` from the `sinsemilla` module. To reduce verbosity and improve readability, /// we introduce this alias and use it instead of that long construction. -pub type PallasLookupRangeCheck45BConfig = - LookupRangeCheck45BConfig; +pub type PallasLookupRangeCheck4_5BConfig = + LookupRangeCheck4_5BConfig; -impl PallasLookupRangeCheck for PallasLookupRangeCheck45BConfig {} +impl PallasLookupRangeCheck for PallasLookupRangeCheck4_5BConfig {} #[cfg(test)] mod tests { @@ -709,21 +711,21 @@ mod tests { sinsemilla::primitives::K, tests::test_utils::test_against_stored_circuit, utilities::lookup_range_check::{ - LookupRangeCheck, PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig, + LookupRangeCheck, PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig, PallasLookupRangeCheckConfig, }, }; use std::{convert::TryInto, marker::PhantomData}; #[derive(Clone, Copy)] - struct MyLookupCircuit> { + struct LookupCircuit> { num_words: usize, _marker: PhantomData<(F, Lookup)>, } - impl> MyLookupCircuit { + impl> LookupCircuit { fn new(num_words: usize) -> Self { - MyLookupCircuit { + LookupCircuit { num_words, _marker: PhantomData, } @@ -731,13 +733,13 @@ mod tests { } impl + std::clone::Clone> Circuit - for MyLookupCircuit + for LookupCircuit { type Config = Lookup; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyLookupCircuit::new(self.num_words) + LookupCircuit::new(self.num_words) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -812,40 +814,40 @@ mod tests { #[test] fn lookup_range_check() { - let circuit = MyLookupCircuit::::new(6); + let circuit = LookupCircuit::::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::::new(6); + let circuit = LookupCircuit::::new(6); test_against_stored_circuit(circuit, "lookup_range_check", 1888); } #[test] - fn lookup_range_check_4_5_b() { - let circuit = MyLookupCircuit::::new(6); + fn lookup_range_check_4_5b() { + let circuit = LookupCircuit::::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::::new(6); - test_against_stored_circuit(circuit, "lookup_range_check_4_5_b", 2048); + fn test_lookup_range_check_against_stored_circuit_4_5b() { + let circuit = LookupCircuit::::new(6); + test_against_stored_circuit(circuit, "lookup_range_check_4_5b", 2048); } #[derive(Clone, Copy)] - struct MyShortRangeCheckCircuit> { + struct ShortRangeCheckCircuit> { element: Value, num_bits: usize, _lookup_marker: PhantomData, } - impl> MyShortRangeCheckCircuit { + impl> ShortRangeCheckCircuit { fn new(element: Value, num_bits: usize) -> Self { - MyShortRangeCheckCircuit { + ShortRangeCheckCircuit { element, num_bits, _lookup_marker: PhantomData, @@ -854,13 +856,13 @@ mod tests { } impl + std::clone::Clone> Circuit - for MyShortRangeCheckCircuit + for ShortRangeCheckCircuit { type Config = Lookup; type FloorPlanner = SimpleFloorPlanner; fn without_witnesses(&self) -> Self { - MyShortRangeCheckCircuit::new(Value::unknown(), self.num_bits) + ShortRangeCheckCircuit::new(Value::unknown(), self.num_bits) } fn configure(meta: &mut ConstraintSystem) -> Self::Config { @@ -899,7 +901,7 @@ mod tests { expected_proof_size: usize, ) { let circuit = - MyShortRangeCheckCircuit::::new(Value::known(element), num_bits); + ShortRangeCheckCircuit::::new(Value::known(element), num_bits); let prover = MockProver::::run(11, &circuit, vec![]).unwrap(); assert_eq!(prover.verify(), *proof_result); @@ -923,11 +925,11 @@ mod tests { "short_range_check_case0", proof_size_10_bits, ); - test_short_range_check::( + test_short_range_check::( element, num_bits, &Ok(()), - "short_range_check_4_5_b_case0", + "short_range_check_4_5b_case0", proof_size_4_5_10_bits, ); @@ -941,11 +943,11 @@ mod tests { "short_range_check_case1", proof_size_10_bits, ); - test_short_range_check::( + test_short_range_check::( element, num_bits, &Ok(()), - "short_range_check_4_5_b_case1", + "short_range_check_4_5b_case1", proof_size_4_5_10_bits, ); @@ -959,11 +961,11 @@ mod tests { "short_range_check_case2", proof_size_10_bits, ); - test_short_range_check::( + test_short_range_check::( element, num_bits, &Ok(()), - "short_range_check_4_5_b_case2", + "short_range_check_4_5b_case2", proof_size_4_5_10_bits, ); @@ -984,7 +986,7 @@ mod tests { "not_saved", proof_size_10_bits, ); - test_short_range_check::( + test_short_range_check::( element, num_bits, &error, @@ -1018,7 +1020,7 @@ mod tests { "not_saved", proof_size_10_bits, ); - test_short_range_check::( + test_short_range_check::( element, num_bits, &error, @@ -1049,7 +1051,7 @@ mod tests { "not_saved", proof_size_10_bits, ); - test_short_range_check::( + test_short_range_check::( element, num_bits as usize, &error, @@ -1058,16 +1060,16 @@ mod tests { ); // Element within 4 bits - test_short_range_check::( + test_short_range_check::( pallas::Base::from((1 << 4) - 1), 4, &Ok(()), - "short_range_check_4_5_b_case3", + "short_range_check_4_5b_case3", proof_size_4_5_10_bits, ); // Element larger than 5 bits - test_short_range_check::( + test_short_range_check::( pallas::Base::from(1 << 5), 5, &Err(vec![VerifyFailure::Lookup {