Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pasta dependency #180

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ subtle = "2.5"
ff = { version = "0.13.0", default-features = false, features = ["std"] }
group = "0.13.0"
pairing = "0.23.0"
pasta_curves = "0.5.0"
static_assertions = "1.1.0"
rand = "0.8"
rand_core = { version = "0.6", default-features = false }
Expand All @@ -53,7 +52,7 @@ default = ["bits"]
asm = ["halo2derive/asm"]
bits = ["ff/bits"]
bn256-table = []
derive_serde = ["serde/derive", "serde_arrays", "hex", "pasta_curves/serde"]
derive_serde = ["serde/derive", "serde_arrays", "hex"]
print-trace = ["ark-std/print-trace"]

[profile.bench]
Expand Down
3 changes: 2 additions & 1 deletion benches/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughpu
use ff::Field;
use group::prime::PrimeCurveAffine;
use halo2curves::bn256::G1;
use pasta_curves::arithmetic::CurveExt;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;

use halo2curves::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
5 changes: 3 additions & 2 deletions 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 halo2curves::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: 0 additions & 1 deletion derive/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {
#[cfg(feature = "asm")]
let impl_arith = {
if num_limbs == 4 && num_bits < 256 {
println!("implementing asm, {}", identifier);
asm::limb4::impl_arith(&field, inv64)
} else {
arith::impl_arith(&field, num_limbs, inv64)
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
10 changes: 10 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# It's the default. But here for visibility.
comment_width = 80
# Makes code docs & examples easier to write.
format_code_in_doc_comments = true
# Group imports by crate.
imports_granularity = "Crate"
# This is a standard almost
wrap_comments = true
# Rustlang core team is migrating to this
group_imports = "StdExternalCrate"
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: 20 additions & 16 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 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 pasta_curves::arithmetic::{Coordinates, CurveAffine, CurveExt};
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,11 +176,11 @@ pub(crate) fn hash_to_curve<'a>(

#[cfg(test)]
mod test {
use crate::arithmetic::CurveEndo;
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
Loading
Loading