mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-27 22:23:48 +01:00
Upgrade to work with latest ark-ff (#95)
Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
@@ -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