Skip to content

Commit

Permalink
Some renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstanceBeguier committed Aug 2, 2024
1 parent 03dbe70 commit a34d146
Show file tree
Hide file tree
Showing 22 changed files with 169 additions and 163 deletions.
33 changes: 16 additions & 17 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -772,12 +772,12 @@ pub(crate) mod tests {
type Base = BaseField;
}

struct MyCircuit<Lookup: PallasLookupRangeCheck> {
struct EccCircuit<Lookup: PallasLookupRangeCheck> {
test_errors: bool,
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> MyCircuit<Lookup> {
impl<Lookup: PallasLookupRangeCheck> EccCircuit<Lookup> {
fn new(test_errors: bool) -> Self {
Self {
test_errors,
Expand All @@ -787,12 +787,12 @@ pub(crate) mod tests {
}

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

fn without_witnesses(&self) -> Self {
MyCircuit::new(false)
EccCircuit::new(false)
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
Expand Down Expand Up @@ -968,14 +968,14 @@ pub(crate) mod tests {
#[test]
fn ecc_chip() {
let k = 13;
let circuit = MyCircuit::<PallasLookupRangeCheckConfig>::new(true);
let circuit = EccCircuit::<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>::new(false);
let circuit = EccCircuit::<PallasLookupRangeCheckConfig>::new(false);
test_against_stored_circuit(circuit, "ecc_chip", 3872);
}

Expand All @@ -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::<PallasLookupRangeCheckConfig>::new(false);
let circuit = EccCircuit::<PallasLookupRangeCheckConfig>::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::<PallasLookupRangeCheck45BConfig>::new(true);
let circuit = EccCircuit::<PallasLookupRangeCheck4_5BConfig>::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>::new(false);
test_against_stored_circuit(circuit, "ecc_chip_4_5_b", 3968);
fn test_against_stored_ecc_chip_4_5b() {
let circuit = EccCircuit::<PallasLookupRangeCheck4_5BConfig>::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::<PallasLookupRangeCheck45BConfig>::new(false);
let circuit = EccCircuit::<PallasLookupRangeCheck4_5BConfig>::new(false);
halo2_proofs::dev::CircuitLayout::default()
.render(13, &circuit, &root)
.unwrap();
Expand Down
50 changes: 25 additions & 25 deletions halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub mod tests {
},
utilities::{
lookup_range_check::{
PallasLookupRangeCheck, PallasLookupRangeCheck45BConfig,
PallasLookupRangeCheck, PallasLookupRangeCheck4_5BConfig,
PallasLookupRangeCheckConfig,
},
UtilitiesInstructions,
Expand Down Expand Up @@ -471,7 +471,7 @@ pub mod tests {
}

#[derive(Default)]
struct MyMagnitudeSignCircuit<Lookup: PallasLookupRangeCheck> {
struct MagnitudeSignCircuit<Lookup: PallasLookupRangeCheck> {
magnitude: Value<pallas::Base>,
sign: Value<pallas::Base>,
// For test checking
Expand All @@ -480,17 +480,17 @@ pub mod tests {
}

impl<Lookup: PallasLookupRangeCheck> UtilitiesInstructions<pallas::Base>
for MyMagnitudeSignCircuit<Lookup>
for MagnitudeSignCircuit<Lookup>
{
type Var = AssignedCell<pallas::Base, pallas::Base>;
}

impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MyMagnitudeSignCircuit<Lookup> {
impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MagnitudeSignCircuit<Lookup> {
type Config = EccConfig<TestFixedBases, Lookup>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
MyMagnitudeSignCircuit {
MagnitudeSignCircuit {
magnitude: Value::unknown(),
sign: Value::unknown(),
magnitude_error: Value::unknown(),
Expand Down Expand Up @@ -584,41 +584,41 @@ pub mod tests {
}
}

impl<Lookup: PallasLookupRangeCheck> MyMagnitudeSignCircuit<Lookup> {
impl<Lookup: PallasLookupRangeCheck> MagnitudeSignCircuit<Lookup> {
fn test_invalid_magnitude_sign() {
// Magnitude larger than 64 bits should fail
{
let circuits = [
// 2^64
MyMagnitudeSignCircuit::<Lookup> {
MagnitudeSignCircuit::<Lookup> {
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::<Lookup> {
MagnitudeSignCircuit::<Lookup> {
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::<Lookup> {
MagnitudeSignCircuit::<Lookup> {
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::<Lookup> {
MagnitudeSignCircuit::<Lookup> {
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::<Lookup> {
MagnitudeSignCircuit::<Lookup> {
magnitude: Value::known(pallas::Base::from_u128(1 << 127).square()),
sign: Value::known(pallas::Base::one()),
magnitude_error: Value::known(
Expand All @@ -627,7 +627,7 @@ pub mod tests {
_lookup_marker: PhantomData,
},
// -2^254
MyMagnitudeSignCircuit::<Lookup> {
MagnitudeSignCircuit::<Lookup> {
magnitude: Value::known(pallas::Base::from_u128(1 << 127).square()),
sign: Value::known(-pallas::Base::one()),
magnitude_error: Value::known(
Expand Down Expand Up @@ -682,7 +682,7 @@ pub mod tests {
// Sign that is not +/- 1 should fail
{
let magnitude_u64 = rand::random::<u64>();
let circuit: MyMagnitudeSignCircuit<Lookup> = MyMagnitudeSignCircuit {
let circuit: MagnitudeSignCircuit<Lookup> = MagnitudeSignCircuit {
magnitude: Value::known(pallas::Base::from(magnitude_u64)),
sign: Value::known(pallas::Base::zero()),
magnitude_error: Value::unknown(),
Expand Down Expand Up @@ -744,12 +744,12 @@ pub mod tests {

#[test]
fn invalid_magnitude_sign() {
MyMagnitudeSignCircuit::<PallasLookupRangeCheckConfig>::test_invalid_magnitude_sign();
MagnitudeSignCircuit::<PallasLookupRangeCheckConfig>::test_invalid_magnitude_sign();
}

#[test]
fn invalid_magnitude_sign_4_5_b() {
MyMagnitudeSignCircuit::<PallasLookupRangeCheck45BConfig>::test_invalid_magnitude_sign();
fn invalid_magnitude_sign_4_5b() {
MagnitudeSignCircuit::<PallasLookupRangeCheck4_5BConfig>::test_invalid_magnitude_sign();
}

pub(crate) fn test_mul_sign<Lookup: PallasLookupRangeCheck>(
Expand Down Expand Up @@ -819,24 +819,24 @@ pub mod tests {
}

#[derive(Default)]
struct MyMulSignCircuit<Lookup: PallasLookupRangeCheck> {
struct MulSignCircuit<Lookup: PallasLookupRangeCheck> {
base: Value<pallas::Affine>,
sign: Value<pallas::Base>,
_lookup_marker: PhantomData<Lookup>,
}

impl<Lookup: PallasLookupRangeCheck> UtilitiesInstructions<pallas::Base>
for MyMulSignCircuit<Lookup>
for MulSignCircuit<Lookup>
{
type Var = AssignedCell<pallas::Base, pallas::Base>;
}

impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MyMulSignCircuit<Lookup> {
impl<Lookup: PallasLookupRangeCheck> Circuit<pallas::Base> for MulSignCircuit<Lookup> {
type Config = EccConfig<TestFixedBases, Lookup>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
MyMulSignCircuit {
MulSignCircuit {
base: Value::unknown(),
sign: Value::unknown(),
_lookup_marker: PhantomData,
Expand Down Expand Up @@ -900,12 +900,12 @@ pub mod tests {
}
}

impl<Lookup: PallasLookupRangeCheck> MyMulSignCircuit<Lookup> {
impl<Lookup: PallasLookupRangeCheck> MulSignCircuit<Lookup> {
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<Lookup> = MyMulSignCircuit {
let circuit: MulSignCircuit<Lookup> = MulSignCircuit {
base: Value::known(point.to_affine()),
sign: Value::known(pallas::Base::zero()),
_lookup_marker: PhantomData,
Expand Down Expand Up @@ -954,10 +954,10 @@ pub mod tests {

#[test]
fn invalid_sign_in_mul_sign() {
MyMulSignCircuit::<PallasLookupRangeCheckConfig>::test_invalid_magnitude_sign();
MulSignCircuit::<PallasLookupRangeCheckConfig>::test_invalid_magnitude_sign();
}
#[test]
fn invalid_sign_in_mul_sign_4_5_b() {
MyMulSignCircuit::<PallasLookupRangeCheck45BConfig>::test_invalid_magnitude_sign();
fn invalid_sign_in_mul_sign_4_5b() {
MulSignCircuit::<PallasLookupRangeCheck4_5BConfig>::test_invalid_magnitude_sign();
}
}
Loading

0 comments on commit a34d146

Please sign in to comment.