Skip to content

Commit

Permalink
fix cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoGalteland committed Jun 3, 2024
1 parent 9337142 commit 8a8aca2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
68 changes: 45 additions & 23 deletions halo2_gadgets/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,6 @@ pub(crate) mod tests {
use ff::PrimeField;
use group::{prime::PrimeCurveAffine, Curve, Group};

use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
dev::MockProver,
plonk::{Circuit, ConstraintSystem, Error},
};
use lazy_static::lazy_static;
use pasta_curves::pallas;
use pasta_curves::vesta::Affine;

use super::{
chip::{
find_zs_and_us, BaseFieldElem, EccChip, EccConfig, FixedPoint, FullScalar, ShortScalar,
Expand All @@ -649,6 +640,13 @@ pub(crate) mod tests {
tests::test_utils::{test_against_stored_proof, test_against_stored_vk},
utilities::lookup_range_check::{LookupRangeCheck, PallasLookupRCConfig},
};
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 @@ -953,7 +951,7 @@ pub(crate) mod tests {

#[test]
fn ecc_chip() {
let k = 13;
let k = 11;
let circuit = MyCircuit { test_errors: true };
let prover = MockProver::run(k, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), Ok(()))
Expand Down Expand Up @@ -986,20 +984,20 @@ pub(crate) mod tests {
.unwrap();
}

struct MyCircuit_4_5_b {
struct MyCircuit45B {
test_errors: bool,
}

#[allow(non_snake_case)]
impl Circuit<pallas::Base> for MyCircuit_4_5_b {
impl Circuit<pallas::Base> for MyCircuit45B {
type Config = EccConfig<
crate::ecc::tests::TestFixedBases,
LookupRangeCheckConfigOptimized<pallas::Base, { crate::sinsemilla::primitives::K }>,
>;
type FloorPlanner = SimpleFloorPlanner;

fn without_witnesses(&self) -> Self {
MyCircuit_4_5_b { test_errors: false }
MyCircuit45B { test_errors: false }
}

fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
Expand Down Expand Up @@ -1083,7 +1081,7 @@ pub(crate) mod tests {
Value::known(pallas::Affine::identity()),
)?;

crate::ecc::NonIdentityPoint::new(
super::NonIdentityPoint::new(
chip.clone(),
layouter.namespace(|| "identity"),
Value::known(pallas::Affine::identity()),
Expand All @@ -1093,15 +1091,15 @@ pub(crate) mod tests {

// Test witness non-identity point
{
crate::ecc::chip::witness_point::tests::test_witness_non_id(
super::chip::witness_point::tests::test_witness_non_id(
chip.clone(),
layouter.namespace(|| "witness non-identity point"),
)
}

// Test complete addition
{
crate::ecc::chip::add::tests::test_add(
super::chip::add::tests::test_add(
chip.clone(),
layouter.namespace(|| "complete addition"),
p_val,
Expand All @@ -1114,7 +1112,7 @@ pub(crate) mod tests {

// Test incomplete addition
{
crate::ecc::chip::add_incomplete::tests::test_add_incomplete(
super::chip::add_incomplete::tests::test_add_incomplete(
chip.clone(),
layouter.namespace(|| "incomplete addition"),
p_val,
Expand All @@ -1128,7 +1126,7 @@ pub(crate) mod tests {

// Test variable-base scalar multiplication
{
crate::ecc::chip::mul::tests::test_mul(
super::chip::mul::tests::test_mul(
chip.clone(),
layouter.namespace(|| "variable-base scalar mul"),
&p,
Expand All @@ -1138,34 +1136,58 @@ pub(crate) mod tests {

// Test variable-base sign-scalar multiplication
{
crate::ecc::chip::mul_fixed::short::tests::test_mul_sign(
super::chip::mul_fixed::short::tests::test_mul_sign(
chip.clone(),
layouter.namespace(|| "variable-base sign-scalar mul"),
)?;
}

// Test full-width fixed-base scalar multiplication
{
super::chip::mul_fixed::full_width::tests::test_mul_fixed(
chip.clone(),
layouter.namespace(|| "full-width fixed-base scalar mul"),
)?;
}

// Test signed short fixed-base scalar multiplication
{
super::chip::mul_fixed::short::tests::test_mul_fixed_short(
chip.clone(),
layouter.namespace(|| "signed short fixed-base scalar mul"),
)?;
}

// Test fixed-base scalar multiplication with a base field element
{
super::chip::mul_fixed::base_field_elem::tests::test_mul_fixed_base_field(
chip,
layouter.namespace(|| "fixed-base scalar mul with base field element"),
)?;
}

Ok(())
}
}

#[test]
fn ecc_chip() {
fn ecc_chip_4_5_b() {
let k = 11;
let circuit = MyCircuit_4_5_b { test_errors: true };
let circuit = MyCircuit45B { test_errors: true };
let prover = MockProver::run(k, &circuit, vec![]).unwrap();

assert_eq!(prover.verify(), Ok(()))
}
#[cfg(feature = "test-dev-graph")]
#[test]
fn print_ecc_chip() {
fn print_ecc_chip_4_5_b() {
use plotters::prelude::*;

let root = BitMapBackend::new("ecc-chip-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_4_5_b { test_errors: false };
let circuit = MyCircuit45B { test_errors: false };
halo2_proofs::dev::CircuitLayout::default()
.render(13, &circuit, &root)
.unwrap();
Expand Down
14 changes: 6 additions & 8 deletions halo2_gadgets/src/ecc/chip/mul_fixed/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,10 @@ pub mod tests {
}

pub(crate) fn test_mul_sign(
chip: EccChip<TestFixedBases>,
chip: EccChip<
TestFixedBases,
LookupRangeCheckConfigOptimized<pallas::Base, { crate::sinsemilla::primitives::K }>,
>,
mut layouter: impl Layouter<pallas::Base>,
) -> Result<(), Error> {
// Generate a random non-identity point P
Expand Down Expand Up @@ -1107,7 +1110,6 @@ pub mod tests {
meta.advice_column(),
];
let lookup_table = meta.lookup_table_column();
let table_range_check_tag = meta.lookup_table_column();
let lagrange_coeffs = [
meta.fixed_column(),
meta.fixed_column(),
Expand All @@ -1123,12 +1125,8 @@ pub mod tests {
let constants = meta.fixed_column();
meta.enable_constant(constants);

let range_check = LookupRangeCheckConfigOptimized::configure_with_tag(
meta,
advices[9],
lookup_table,
table_range_check_tag,
);
let range_check =
LookupRangeCheckConfigOptimized::configure(meta, advices[9], lookup_table);
EccChip::<
TestFixedBases,
LookupRangeCheckConfigOptimized<
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/ecc/chip/witness_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Config {
}

/// Assigns a constant point that can be the identity.
pub(crate) fn constant_point(
pub(super) fn constant_point(
&self,
value: pallas::Affine,
offset: usize,
Expand Down
2 changes: 1 addition & 1 deletion halo2_gadgets/src/sinsemilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub trait SinsemillaInstructions<C: CurveAffine, const K: usize, const MAX_WORDS
/// This returns both the resulting point, as well as the message
/// decomposition in the form of intermediate values in a cumulative
/// sum.
///
/// The initial point `Q` is a public point.
#[allow(non_snake_case)]
#[allow(clippy::type_complexity)]
fn hash_to_point(
Expand Down

0 comments on commit 8a8aca2

Please sign in to comment.