Skip to content

Commit

Permalink
Take into account Pablo's review
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Jul 17, 2024
1 parent a8832c9 commit 8a2cbee
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 134 deletions.
63 changes: 25 additions & 38 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -778,16 +777,22 @@ pub(crate) mod tests {
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyCircuit<Lookup> {
fn new(test_errors: bool) -> Self {
Self {
test_errors,
_lookup_marker: PhantomData,
}
}
}

#[allow(non_snake_case)]
impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MyCircuit<Lookup> {
type Config = EccConfig<TestFixedBases, Lookup>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
MyCircuit {
test_errors: false,
_lookup_marker: PhantomData,
}
MyCircuit::new(false)
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
Expand Down Expand Up @@ -962,21 +967,15 @@ pub(crate) mod tests {

#[test]
fn ecc_chip() {
let k = 11;
let circuit: MyCircuit<PallasLookupRangeCheckConfig> = MyCircuit {
test_errors: true,
_lookup_marker: PhantomData,
};
let k = 13;
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::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<PallasLookupRangeCheckConfig> = MyCircuit {
test_errors: false,
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::new(false);
test_against_stored_circuit(circuit, "ecc_chip", 3872);
}

Expand All @@ -989,33 +988,24 @@ pub(crate) mod tests {
root.fill(&WHITE).unwrap();
let root = root.titled("Ecc Chip Layout", ("sans-serif", 60)).unwrap();

let circuit: MyCircuit<PallasLookupRangeCheckConfig> = MyCircuit {
test_errors: false,
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::new(false);
halo2_proofs::dev::CircuitLayout::default()
.render(13, &circuit, &root)
.unwrap();
}

#[test]
fn ecc_chip_4_5_b() {
let k = 11;
let circuit: MyCircuit<PallasLookupRangeCheck45BConfig> = MyCircuit {
test_errors: true,
_lookup_marker: PhantomData,
};
let k = 13;
let circuit = MyCircuit::<PallasLookupRangeCheck45BConfig>::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<PallasLookupRangeCheck45BConfig> = MyCircuit {
test_errors: false,
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheck45BConfig>::new(false);
test_against_stored_circuit(circuit, "ecc_chip_4_5_b", 3968);
}

Expand All @@ -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<PallasLookupRangeCheck45BConfig> = MyCircuit {
test_errors: false,
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheck45BConfig>::new(false);
halo2_proofs::dev::CircuitLayout::default()
.render(13, &circuit, &root)
.unwrap();
Expand Down
51 changes: 24 additions & 27 deletions halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,14 @@ pub(crate) mod tests {
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyCircuit<Lookup> {
fn new() -> Self {
Self {
_lookup_marker: PhantomData,
}
}
}

type MyConfig<Lookup> = (
EccConfig<TestFixedBases, Lookup>,
SinsemillaConfig<TestHashDomain, TestCommitDomain, TestFixedBases, Lookup>,
Expand Down Expand Up @@ -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)]
Expand All @@ -827,18 +833,14 @@ pub(crate) mod tests {
#[test]
fn sinsemilla_chip() {
let k = 11;
let circuit: MyCircuit<PallasLookupRangeCheckConfig> = MyCircuit {
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::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<PallasLookupRangeCheckConfig> = MyCircuit {
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::new();
test_against_stored_circuit(circuit, "sinsemilla_chip", 4576);
}

Expand All @@ -852,9 +854,7 @@ pub(crate) mod tests {
root.fill(&WHITE).unwrap();
let root = root.titled("SinsemillaHash", ("sans-serif", 60)).unwrap();

let circuit: MyCircuit<PallasLookupRangeCheckConfig> = MyCircuit {
_lookup_marker: PhantomData,
};
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::new();
halo2_proofs::dev::CircuitLayout::default()
.render(11, &circuit, &root)
.unwrap();
Expand All @@ -864,6 +864,14 @@ pub(crate) mod tests {
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyCircuitWithHashFromPrivatePoint<Lookup> {
fn new() -> Self {
Self {
_lookup_marker: PhantomData,
}
}
}

impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base>
for MyCircuitWithHashFromPrivatePoint<Lookup>
{
Expand All @@ -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)]
Expand All @@ -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<PallasLookupRangeCheck45BConfig> =
MyCircuitWithHashFromPrivatePoint {
_lookup_marker: PhantomData,
};
let circuit = MyCircuitWithHashFromPrivatePoint::<PallasLookupRangeCheck45BConfig>::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<PallasLookupRangeCheck45BConfig> =
MyCircuitWithHashFromPrivatePoint {
_lookup_marker: PhantomData,
};
let circuit = MyCircuitWithHashFromPrivatePoint::<PallasLookupRangeCheck45BConfig>::new();
test_against_stored_circuit(circuit, "sinsemilla_with_private_init_chip_4_5_b", 4672);
}

Expand All @@ -924,10 +924,7 @@ pub(crate) mod tests {
root.fill(&WHITE).unwrap();
let root = root.titled("SinsemillaHash", ("sans-serif", 60)).unwrap();

let circuit: MyCircuitWithHashFromPrivatePoint<PallasLookupRangeCheck45BConfig> =
MyCircuitWithHashFromPrivatePoint {
_lookup_marker: PhantomData,
};
let circuit = MyCircuitWithHashFromPrivatePoint::<PallasLookupRangeCheck45BConfig>::new();
halo2_proofs::dev::CircuitLayout::default()
.render(11, &circuit, &root)
.unwrap();
Expand Down
1 change: 0 additions & 1 deletion halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ where

Ok((x_a, y_a, zs))
}

#[allow(unused_variables)]
#[allow(non_snake_case)]
#[allow(clippy::type_complexity)]
Expand Down
70 changes: 46 additions & 24 deletions halo2_gadgets/src/sinsemilla/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ pub mod tests {
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyCircuit<Lookup> {
fn new(
leaf: Value<pallas::Base>,
leaf_pos: Value<u32>,
merkle_path: Value<[pallas::Base; MERKLE_DEPTH]>,
) -> Self {
Self {
leaf,
leaf_pos,
merkle_path,
_lookup_marker: PhantomData,
}
}
}

type MyConfig<Lookup> = (
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases, Lookup>,
MerkleConfig<TestHashDomain, TestCommitDomain, TestFixedBases, Lookup>,
Expand Down Expand Up @@ -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<pallas::Base>) -> Self::Config {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -444,19 +453,33 @@ pub mod tests {
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyCircuitWithHashFromPrivatePoint<Lookup> {
fn new(
leaf: Value<pallas::Base>,
leaf_pos: Value<u32>,
merkle_path: Value<[pallas::Base; MERKLE_DEPTH]>,
) -> Self {
Self {
leaf,
leaf_pos,
merkle_path,
_lookup_marker: PhantomData,
}
}
}

impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base>
for MyCircuitWithHashFromPrivatePoint<Lookup>
{
type Config = MyConfig<Lookup>;
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<pallas::Base>) -> Self::Config {
Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 8a2cbee

Please sign in to comment.