Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed Dec 3, 2024
1 parent 801d6f7 commit f5dd7df
Show file tree
Hide file tree
Showing 59 changed files with 561 additions and 457 deletions.
3 changes: 2 additions & 1 deletion benches/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
//!
//! cargo bench --bench curve
use crate::CurveExt;
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use ff::Field;
use group::prime::PrimeCurveAffine;
use halo2curves::bn256::G1;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;

use crate::CurveExt;

fn bench_curve_ops<G: CurveExt>(c: &mut Criterion, name: &'static str) {
{
let mut rng = XorShiftRng::seed_from_u64(3141519u64);
Expand Down
7 changes: 3 additions & 4 deletions benches/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#[macro_use]
extern crate criterion;

use std::{ops::Range, time::SystemTime};

use criterion::{BenchmarkId, Criterion};
use group::ff::Field;
use halo2curves::bn256::Fr as Scalar;
use halo2curves::fft::best_fft;
use halo2curves::{bn256::Fr as Scalar, fft::best_fft};
use rand::{RngCore, SeedableRng};
use rand_xorshift::XorShiftRng;
use std::ops::Range;
use std::time::SystemTime;

const RANGE: Range<u32> = 3..19;
const SEED: [u8; 16] = [
Expand Down
3 changes: 2 additions & 1 deletion benches/hash_to_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
//!
//! cargo bench --bench hash_to_curve
use std::iter;

use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use halo2curves::bn256::G1;
use pasta_curves::arithmetic::CurveExt;
use rand::SeedableRng;
use rand_core::RngCore;
use rand_xorshift::XorShiftRng;
use std::iter;

const SEED: [u8; 16] = [
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5,
Expand Down
15 changes: 10 additions & 5 deletions benches/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
#[macro_use]
extern crate criterion;

use std::time::SystemTime;

use criterion::{BenchmarkId, Criterion};
use ff::{Field, PrimeField};
use group::prime::PrimeCurveAffine;
use halo2curves::bn256::{Fr as Scalar, G1Affine as Point};
use halo2curves::msm::{msm_best, msm_serial};
use halo2curves::{
bn256::{Fr as Scalar, G1Affine as Point},
msm::{msm_best, msm_serial},
};
use rand_core::{RngCore, SeedableRng};
use rand_xorshift::XorShiftRng;
use rayon::current_thread_index;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use std::time::SystemTime;
use rayon::{
current_thread_index,
prelude::{IntoParallelIterator, ParallelIterator},
};

const SAMPLE_SIZE: usize = 10;
const SINGLECORE_RANGE: [u8; 6] = [3, 8, 10, 12, 14, 16];
Expand Down
3 changes: 1 addition & 2 deletions derive/src/field/arith.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use proc_macro2::TokenStream;
use quote::format_ident as fmtid;
use quote::quote;
use quote::{format_ident as fmtid, quote};

fn select(cond: bool, this: TokenStream, other: TokenStream) -> TokenStream {
if cond {
Expand Down
1 change: 1 addition & 0 deletions derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::ops::Shl;

use num_bigint::BigUint;
use num_traits::{One, ToPrimitive};

Expand Down
4 changes: 2 additions & 2 deletions src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This module provides common utilities, traits and structures for group and
//! field arithmetic.
//!
//! This module is temporary, and the extension traits defined here are expected to be
//! upstreamed into the `ff` and `group` crates after some refactoring.
//! This module is temporary, and the extension traits defined here are expected
//! to be upstreamed into the `ff` and `group` crates after some refactoring.
use crate::CurveExt;

Expand Down
32 changes: 17 additions & 15 deletions src/bls12381/engine.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use super::fq12::Fq12;
use super::fq2::Fq2;
use super::{Fr, G1Affine, G2Affine, BLS_X, G1, G2};
use crate::ff_ext::quadratic::QuadSparseMul;
use crate::ff_ext::ExtField;
use core::borrow::Borrow;
use core::iter::Sum;
use core::ops::{Add, Mul, Neg, Sub};
use ff::Field;
use ff::PrimeField;
use group::prime::PrimeCurveAffine;
use group::Group;
use core::{
borrow::Borrow,
iter::Sum,
ops::{Add, Mul, Neg, Sub},
};
use std::ops::MulAssign;

use ff::{Field, PrimeField};
use group::{prime::PrimeCurveAffine, Group};
use pairing::{Engine, MillerLoopResult, MultiMillerLoop, PairingCurveAffine};
use rand::RngCore;
use std::ops::MulAssign;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};

use super::{fq12::Fq12, fq2::Fq2, Fr, G1Affine, G2Affine, BLS_X, G1, G2};
use crate::ff_ext::{quadratic::QuadSparseMul, ExtField};

crate::impl_gt!(Gt, Fq12, Fr);
crate::impl_miller_loop_components!(Bls12381, G1, G1Affine, G2, G2Affine, Fq12, Gt, Fr);

Expand Down Expand Up @@ -116,11 +115,14 @@ fn ell(f: &mut Fq12, coeffs: &(Fq2, Fq2, Fq2), p: &G1Affine) {

#[cfg(test)]
mod test {
use super::super::{Bls12381, Fr, G1, G2};
use super::{multi_miller_loop, Fq12, G1Affine, G2Affine, Gt};
use ff::Field;
use group::{prime::PrimeCurveAffine, Curve, Group};
use pairing::{Engine as _, MillerLoopResult, PairingCurveAffine};
use rand_core::OsRng;

use super::{
super::{Bls12381, Fr, G1, G2},
multi_miller_loop, Fq12, G1Affine, G2Affine, Gt,
};
crate::test_pairing!(Bls12381, G1, G1Affine, G2, G2Affine, Fq12, Gt, Fr);
}
1 change: 1 addition & 0 deletions src/bls12381/fq.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::convert::TryInto;

use halo2derive::impl_field;
use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
Expand Down
9 changes: 4 additions & 5 deletions src/bls12381/fq12.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::fq::Fq;
use super::fq2::Fq2;
use super::fq6::Fq6;
use super::{fq::Fq, fq2::Fq2, fq6::Fq6};
use crate::ff_ext::{
quadratic::{QuadExtField, QuadExtFieldArith, QuadSparseMul},
ExtField,
Expand Down Expand Up @@ -281,11 +279,12 @@ mod test {
}
};
}
use super::*;
use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test};
use ff::Field;
use rand::RngCore;

use super::*;
use crate::{arith_test, frobenius_test, setup_f12_test_funcs, test};

arith_test!(Fq12);
// TODO Compile problems with derive_serde feature
// serde_test!(fq12);
Expand Down
17 changes: 12 additions & 5 deletions src/bls12381/fq2.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use super::fq::Fq;
use crate::ff::{Field, FromUniformBytes, PrimeField, WithSmallOrderMulGroup};
use crate::ff_ext::quadratic::{QuadExtField, QuadExtFieldArith, SQRT};
use crate::ff_ext::{ExtField, Legendre};
use core::convert::TryInto;
use std::cmp::Ordering;

use subtle::{Choice, CtOption};

use super::fq::Fq;
use crate::{
ff::{Field, FromUniformBytes, PrimeField, WithSmallOrderMulGroup},
ff_ext::{
quadratic::{QuadExtField, QuadExtFieldArith, SQRT},
ExtField, Legendre,
},
};

crate::impl_binops_additive!(Fq2, Fq2);
crate::impl_binops_multiplicative!(Fq2, Fq2);
crate::impl_binops_calls!(Fq2);
Expand Down Expand Up @@ -64,11 +70,12 @@ impl ExtField for Fq2 {
#[cfg(test)]
mod test {

use rand_core::RngCore;

use super::*;
use crate::{
arith_test, constants_test, f2_test, frobenius_test, legendre_test, serde_test, test,
};
use rand_core::RngCore;

constants_test!(Fq2);

Expand Down
9 changes: 5 additions & 4 deletions src/bls12381/fq6.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::fq::Fq;
use super::fq2::Fq2;
use ff::Field;

use super::{fq::Fq, fq2::Fq2};
use crate::ff_ext::{
cubic::{CubicExtField, CubicExtFieldArith, CubicSparseMul},
ExtField,
};
use ff::Field;

crate::impl_binops_additive!(Fq6, Fq6);
crate::impl_binops_multiplicative!(Fq6, Fq6);
Expand Down Expand Up @@ -276,9 +276,10 @@ pub const FROBENIUS_COEFF_FQ6_C2: [Fq2; 6] = [

#[cfg(test)]
mod test {
use rand_core::RngCore;

use super::*;
use crate::{arith_test, frobenius_test, setup_f6_test_funcs, test};
use rand_core::RngCore;

macro_rules! test_fq6 {
($test:ident, $size: expr) => {
Expand Down
1 change: 1 addition & 0 deletions src/bls12381/fr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::convert::TryInto;

use halo2derive::impl_field;
use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
Expand Down
36 changes: 19 additions & 17 deletions src/bls12381/g1.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use super::fq::Fq;
use super::Fr;
use crate::serde::{Compressed, CompressedFlagConfig};
use core::{
cmp,
iter::Sum,
ops::{Add, Mul, Neg, Sub},
};

use ff::{PrimeField, WithSmallOrderMulGroup};
use group::{
cofactor::CofactorGroup, ff::Field, prime::PrimeCurveAffine, Curve, Group, GroupEncoding,
};
use rand_core::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

use super::{fq::Fq, Fr};
use crate::{
impl_binops_additive, impl_binops_additive_specify_output, impl_binops_multiplicative,
impl_binops_multiplicative_mixed, new_curve_impl,
serde::{Compressed, CompressedFlagConfig},
Coordinates, CurveAffine, CurveExt,
};
use crate::{Coordinates, CurveAffine, CurveExt};
use core::cmp;
use core::iter::Sum;
use core::ops::{Add, Mul, Neg, Sub};
use ff::PrimeField;
use ff::WithSmallOrderMulGroup;
use group::cofactor::CofactorGroup;
use group::{ff::Field, prime::PrimeCurveAffine, Curve, Group, GroupEncoding};
use rand_core::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

new_curve_impl!(
(pub),
Expand Down Expand Up @@ -148,7 +151,8 @@ fn iso_map(x: Fq, y: Fq, z: Fq) -> G1 {
}
}

// x denominator is order 1 less than x numerator, so we need an extra factor of z
// x denominator is order 1 less than x numerator, so we need an extra factor of
// z
mapvals[1] *= z;

// multiply result of Y map by the y-coord, y / z
Expand All @@ -172,13 +176,11 @@ pub(crate) fn hash_to_curve<'a>(

#[cfg(test)]
mod test {
use crate::arithmetic::CurveEndo;
use crate::serde::SerdeObject;
use crate::tests::curve::TestH2C;
use group::UncompressedEncoding;
use rand_core::OsRng;

use super::*;
use crate::{arithmetic::CurveEndo, serde::SerdeObject, tests::curve::TestH2C};
crate::curve_testing_suite!(G1);
crate::curve_testing_suite!(G1, "endo_consistency");
crate::curve_testing_suite!(G1, "endo");
Expand Down
47 changes: 24 additions & 23 deletions src/bls12381/g2.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::bls12381::fq::Fq;
use crate::bls12381::fq2::Fq2;
use crate::bls12381::fr::Fr;
use crate::ff::WithSmallOrderMulGroup;
use crate::ff::{Field, PrimeField};
use crate::ff_ext::ExtField;
use crate::group::Curve;
use crate::group::{cofactor::CofactorGroup, prime::PrimeCurveAffine, Group, GroupEncoding};
use crate::serde::{Compressed, CompressedFlagConfig};
use core::{
cmp,
fmt::Debug,
iter::Sum,
ops::{Add, Mul, Neg, Sub},
};

use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

use crate::{
bls12381::{fq::Fq, fq2::Fq2, fr::Fr},
ff::{Field, PrimeField, WithSmallOrderMulGroup},
ff_ext::ExtField,
group::{cofactor::CofactorGroup, prime::PrimeCurveAffine, Curve, Group, GroupEncoding},
impl_binops_additive, impl_binops_additive_specify_output, impl_binops_multiplicative,
impl_binops_multiplicative_mixed, new_curve_impl,
serde::{Compressed, CompressedFlagConfig},
Coordinates, CurveAffine, CurveExt,
};
use crate::{Coordinates, CurveAffine, CurveExt};
use core::cmp;
use core::fmt::Debug;
use core::iter::Sum;
use core::ops::{Add, Mul, Neg, Sub};
use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};

const G2_GENERATOR_X: Fq2 = Fq2 {
c0: Fq([
Expand Down Expand Up @@ -126,9 +126,9 @@ impl group::cofactor::CofactorGroup for G2 {
CtOption::new(self, 1.into())
}

/// Returns true if this point is free of an $h$-torsion component, and so it
/// exists within the $q$-order subgroup $\mathbb{G}_2$. This should always return true
/// unless an "unchecked" API was used.
/// Returns true if this point is free of an $h$-torsion component, and so
/// it exists within the $q$-order subgroup $\mathbb{G}_2$. This should
/// always return true unless an "unchecked" API was used.
fn is_torsion_free(&self) -> Choice {
// Algorithm from Section 4 of https://eprint.iacr.org/2021/1130
// Updated proof of correctness in https://eprint.iacr.org/2022/352
Expand Down Expand Up @@ -305,7 +305,8 @@ fn iso_map(x: Fq2, y: Fq2, z: Fq2) -> G2 {
}
}

// x denominator is order 1 less than x numerator, so we need an extra factor of z
// x denominator is order 1 less than x numerator, so we need an extra factor of
// z
mapvals[1] *= z;

// multiply result of Y map by the y-coord, y / z
Expand All @@ -329,12 +330,12 @@ pub(crate) fn hash_to_curve<'a>(

#[cfg(test)]
mod test {
use super::*;
use crate::arithmetic::CurveEndo;
use crate::serde::SerdeObject;
use group::UncompressedEncoding;
use rand_core::OsRng;

use super::*;
use crate::{arithmetic::CurveEndo, serde::SerdeObject};

crate::curve_testing_suite!(G2);
crate::curve_testing_suite!(G2, "endo_consistency");
crate::curve_testing_suite!(G2, "endo");
Expand Down
Loading

0 comments on commit f5dd7df

Please sign in to comment.