mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-11 16:31:36 +01:00
Upgrade to work with latest ark-ff (#95)
Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
@@ -1 +1 @@
|
||||
pub use ark_bls12_381::{Fr as Fq, FrParameters as FqParameters};
|
||||
pub use ark_bls12_381::{Fr as Fq, FrConfig as FqConfig};
|
||||
|
||||
@@ -1,81 +1,7 @@
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
||||
fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
|
||||
};
|
||||
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
||||
pub type Fr = Fp256<FrParameters>;
|
||||
|
||||
pub struct FrParameters;
|
||||
|
||||
impl Fp256Parameters for FrParameters {}
|
||||
impl FftParameters for FrParameters {
|
||||
type BigInt = BigInteger;
|
||||
|
||||
const TWO_ADICITY: u32 = 1;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
0xaa9f02ab1d6124de,
|
||||
0xb3524a6466112932,
|
||||
0x7342261215ac260b,
|
||||
0x4d6b87b1da259e2,
|
||||
]);
|
||||
}
|
||||
impl FpParameters for FrParameters {
|
||||
/// MODULUS = 6554484396890773809930967563523245729705921265872317281365359162392183254199.
|
||||
#[rustfmt::skip]
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
0xd0970e5ed6f72cb7,
|
||||
0xa6682093ccc81082,
|
||||
0x6673b0101343b00,
|
||||
0xe7db4ea6533afa9,
|
||||
]);
|
||||
|
||||
const MODULUS_BITS: u32 = 252;
|
||||
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
||||
|
||||
const REPR_SHAVE_BITS: u32 = 4;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R: BigInteger = BigInt::new([
|
||||
0x25f80bb3b99607d9,
|
||||
0xf315d62f66b6e750,
|
||||
0x932514eeeb8814f4,
|
||||
0x9a6fc6f479155c6,
|
||||
]);
|
||||
|
||||
#[rustfmt::skip]
|
||||
const R2: BigInteger = BigInt::new([
|
||||
0x67719aa495e57731,
|
||||
0x51b0cef09ce3fc26,
|
||||
0x69dab7fac026e9a5,
|
||||
0x4f6547b8d127688,
|
||||
]);
|
||||
|
||||
const INV: u64 = 0x1ba3a358ef788ef9;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
0x720b1b19d49ea8f1,
|
||||
0xbf4aa36101f13a58,
|
||||
0x5fa8cc968193ccbb,
|
||||
0xe70cbdc7dccf3ac,
|
||||
]);
|
||||
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
7515249040934278747,
|
||||
5995434913520945217,
|
||||
9454073218019761536,
|
||||
522094803716528084,
|
||||
]);
|
||||
|
||||
const T: BigInteger = Self::MODULUS_MINUS_ONE_DIV_TWO;
|
||||
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
12980996557321915181,
|
||||
2997717456760472608,
|
||||
4727036609009880768,
|
||||
261047401858264042,
|
||||
]);
|
||||
}
|
||||
#[derive(MontConfig)]
|
||||
#[modulus = "6554484396890773809930967563523245729705921265872317281365359162392183254199"]
|
||||
#[generator = "6"]
|
||||
pub struct FrConfig;
|
||||
pub type Fr = Fp256<MontBackend<FrConfig, 4>>;
|
||||
|
||||
@@ -4,5 +4,5 @@ pub mod fr;
|
||||
pub use fq::*;
|
||||
pub use fr::*;
|
||||
|
||||
#[cfg(all(feature = "ed_on_bls12_381", test))]
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -1,33 +1,20 @@
|
||||
use crate::{Fq, Fr};
|
||||
use ark_algebra_test_templates::{
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
};
|
||||
use ark_ff::{
|
||||
biginteger::BigInteger256 as BigInteger,
|
||||
bytes::{FromBytes, ToBytes},
|
||||
fields::{Field, LegendreSymbol::*, SquareRootField},
|
||||
One, Zero,
|
||||
fields::{Field, LegendreSymbol::*, PrimeField, SquareRootField},
|
||||
One, UniformRand, Zero,
|
||||
};
|
||||
use ark_std::test_rng;
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, str::FromStr, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
use ark_algebra_test_templates::fields::*;
|
||||
use crate::{Fq, FqConfig, Fr, FrConfig};
|
||||
|
||||
use ark_std::{rand::Rng, str::FromStr};
|
||||
|
||||
#[test]
|
||||
fn test_fr() {
|
||||
let mut rng = test_rng();
|
||||
let a: Fr = rng.gen();
|
||||
let b: Fr = rng.gen();
|
||||
field_test(a, b);
|
||||
primefield_test::<Fr>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fq() {
|
||||
let mut rng = test_rng();
|
||||
let a: Fq = rng.gen();
|
||||
let b: Fq = rng.gen();
|
||||
field_test(a, b);
|
||||
primefield_test::<Fq>();
|
||||
}
|
||||
generate_field_test!(ed_on_bls12_381; mont(4, 4); );
|
||||
generate_field_serialization_test!(ed_on_bls12_381;);
|
||||
|
||||
#[test]
|
||||
fn test_fq_add() {
|
||||
@@ -148,22 +135,6 @@ fn test_fq_sub() {
|
||||
assert_eq!(f1 - &f2, f3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fq_double_in_place() {
|
||||
let mut f1 = Fq::from_str(
|
||||
"29729289787452206300641229002276778748586801323231253291984198106063944136114",
|
||||
)
|
||||
.unwrap();
|
||||
let f3 = Fq::from_str(
|
||||
"7022704399778222121834717496367591659483050145934868761364737512189307087715",
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!f1.is_zero());
|
||||
assert!(!f3.is_zero());
|
||||
f1.double_in_place();
|
||||
assert_eq!(f1, f3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fq_double_in_place_thrice() {
|
||||
let mut f1 = Fq::from_str(
|
||||
@@ -280,22 +251,9 @@ fn test_fq_square_in_place() {
|
||||
assert_eq!(f1, f3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fq_sqrt() {
|
||||
let f1 = Fq::from_str(
|
||||
"10875927553327821418567659853801220899541454800710193788767706167237535308235",
|
||||
)
|
||||
.unwrap();
|
||||
let f3 = Fq::from_str(
|
||||
"10816221372957505053219354782681292880545918527618367765651802809826238616708",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(f1.sqrt().unwrap(), f3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fq_from_str() {
|
||||
let f1_from_repr = Fq::from(BigInteger([
|
||||
let f1_from_repr = Fq::from(BigInteger::new([
|
||||
0xab8a2535947d1a77,
|
||||
0x9ba74cbfda0bbcda,
|
||||
0xe928b59724d60baf,
|
||||
@@ -305,7 +263,7 @@ fn test_fq_from_str() {
|
||||
"13026376210409056429264774981357153555336288129100724591327877625017068755575",
|
||||
)
|
||||
.unwrap();
|
||||
let f2_from_repr = Fq::from(BigInteger([
|
||||
let f2_from_repr = Fq::from(BigInteger::new([
|
||||
0x97e9103775d2f35c,
|
||||
0xbe6756b6c587544b,
|
||||
0x6ee38c3afd88ef4b,
|
||||
@@ -324,14 +282,14 @@ fn test_fq_legendre() {
|
||||
assert_eq!(QuadraticResidue, Fq::one().legendre());
|
||||
assert_eq!(Zero, Fq::zero().legendre());
|
||||
|
||||
let e = BigInteger([
|
||||
let e = BigInteger::new([
|
||||
0x0dbc5349cd5664da,
|
||||
0x8ac5b6296e3ae29d,
|
||||
0x127cb819feceaa3b,
|
||||
0x3a6b21fb03867191,
|
||||
]);
|
||||
assert_eq!(QuadraticResidue, Fq::from(e).legendre());
|
||||
let e = BigInteger([
|
||||
let e = BigInteger::new([
|
||||
0x96341aefd047c045,
|
||||
0x9b5f4254500a4d65,
|
||||
0x1ee08223b68ac240,
|
||||
@@ -342,7 +300,7 @@ fn test_fq_legendre() {
|
||||
|
||||
#[test]
|
||||
fn test_fq_bytes() {
|
||||
let f1_from_repr = Fq::from(BigInteger([
|
||||
let f1_from_repr = Fq::from(BigInteger::new([
|
||||
0xab8a2535947d1a77,
|
||||
0x9ba74cbfda0bbcda,
|
||||
0xe928b59724d60baf,
|
||||
@@ -358,19 +316,19 @@ fn test_fq_bytes() {
|
||||
|
||||
#[test]
|
||||
fn test_fr_add() {
|
||||
let f1 = Fr::from(BigInteger([
|
||||
let f1 = Fr::from(BigInteger::new([
|
||||
0xc81265fb4130fe0c,
|
||||
0xb308836c14e22279,
|
||||
0x699e887f96bff372,
|
||||
0x84ecc7e76c11ad,
|
||||
]));
|
||||
let f2 = Fr::from(BigInteger([
|
||||
let f2 = Fr::from(BigInteger::new([
|
||||
0x71875719b422efb8,
|
||||
0x43658e68a93612,
|
||||
0x9fa756be2011e833,
|
||||
0xaa2b2cb08dac497,
|
||||
]));
|
||||
let f3 = Fr::from(BigInteger([
|
||||
let f3 = Fr::from(BigInteger::new([
|
||||
0x3999bd14f553edc4,
|
||||
0xb34be8fa7d8b588c,
|
||||
0x945df3db6d1dba5,
|
||||
@@ -381,19 +339,19 @@ fn test_fr_add() {
|
||||
|
||||
#[test]
|
||||
fn test_fr_mul() {
|
||||
let f1 = Fr::from(BigInteger([
|
||||
let f1 = Fr::from(BigInteger::new([
|
||||
0xc81265fb4130fe0c,
|
||||
0xb308836c14e22279,
|
||||
0x699e887f96bff372,
|
||||
0x84ecc7e76c11ad,
|
||||
]));
|
||||
let f2 = Fr::from(BigInteger([
|
||||
let f2 = Fr::from(BigInteger::new([
|
||||
0x71875719b422efb8,
|
||||
0x43658e68a93612,
|
||||
0x9fa756be2011e833,
|
||||
0xaa2b2cb08dac497,
|
||||
]));
|
||||
let f3 = Fr::from(BigInteger([
|
||||
let f3 = Fr::from(BigInteger::new([
|
||||
0x6d6618ac6b4a8381,
|
||||
0x5b9eb35d711ee1da,
|
||||
0xce83310e6ac4105d,
|
||||
@@ -404,7 +362,7 @@ fn test_fr_mul() {
|
||||
|
||||
#[test]
|
||||
fn test_fr_bytes() {
|
||||
let f1_from_repr = Fr::from(BigInteger([
|
||||
let f1_from_repr = Fr::from(BigInteger::new([
|
||||
0xc81265fb4130fe0c,
|
||||
0xb308836c14e22279,
|
||||
0x699e887f96bff372,
|
||||
@@ -420,7 +378,7 @@ fn test_fr_bytes() {
|
||||
|
||||
#[test]
|
||||
fn test_fr_from_str() {
|
||||
let f100_from_repr = Fr::from(BigInteger([0x64, 0, 0, 0]));
|
||||
let f100_from_repr = Fr::from(BigInteger::new([0x64, 0, 0, 0]));
|
||||
let f100 = Fr::from_str("100").unwrap();
|
||||
assert_eq!(f100_from_repr, f100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user