mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-11 00:11:37 +01:00
Upgrade to work with latest ark-ff (#95)
Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use crate::*;
|
||||
use ark_r1cs_std::groups::curves::short_weierstrass::ProjectiveVar;
|
||||
|
||||
use crate::constraints::FBaseVar;
|
||||
use crate::{constraints::FBaseVar, *};
|
||||
|
||||
/// A group element in the Pallas prime-order group.
|
||||
pub type GVar = ProjectiveVar<PallasParameters, FBaseVar>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::fq::Fq;
|
||||
use ark_r1cs_std::fields::fp::FpVar;
|
||||
|
||||
use crate::fq::Fq;
|
||||
|
||||
/// A variable that is the R1CS equivalent of `crate::Fq`.
|
||||
pub type FBaseVar = FpVar<Fq>;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::{fq::Fq, fr::Fr};
|
||||
use ark_ec::{
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
|
||||
};
|
||||
use ark_ff::{field_new, Zero};
|
||||
use ark_ff::{MontFp, Zero};
|
||||
|
||||
use crate::{fq::Fq, fr::Fr};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -19,7 +20,7 @@ impl ModelParameters for PallasParameters {
|
||||
const COFACTOR: &'static [u64] = &[0x1];
|
||||
|
||||
/// COFACTOR_INV = 1
|
||||
const COFACTOR_INV: Fr = field_new!(Fr, "1");
|
||||
const COFACTOR_INV: Fr = MontFp!(Fr, "1");
|
||||
}
|
||||
|
||||
pub type Affine = GroupAffine<PallasParameters>;
|
||||
@@ -27,10 +28,10 @@ pub type Projective = GroupProjective<PallasParameters>;
|
||||
|
||||
impl SWModelParameters for PallasParameters {
|
||||
/// COEFF_A = 0
|
||||
const COEFF_A: Fq = field_new!(Fq, "0");
|
||||
const COEFF_A: Fq = MontFp!(Fq, "0");
|
||||
|
||||
/// COEFF_B = 5
|
||||
const COEFF_B: Fq = field_new!(Fq, "5");
|
||||
const COEFF_B: Fq = MontFp!(Fq, "5");
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
|
||||
@@ -43,7 +44,7 @@ impl SWModelParameters for PallasParameters {
|
||||
}
|
||||
|
||||
/// G_GENERATOR_X = -1
|
||||
pub const G_GENERATOR_X: Fq = field_new!(Fq, "-1");
|
||||
pub const G_GENERATOR_X: Fq = MontFp!(Fq, "-1");
|
||||
|
||||
/// G_GENERATOR_Y = 2
|
||||
pub const G_GENERATOR_Y: Fq = field_new!(Fq, "2");
|
||||
pub const G_GENERATOR_Y: Fq = MontFp!(Fq, "2");
|
||||
|
||||
18
pallas/src/curves/tests.rs
Normal file → Executable file
18
pallas/src/curves/tests.rs
Normal file → Executable file
@@ -1,21 +1,11 @@
|
||||
#![allow(unused_imports)]
|
||||
use ark_ff::{
|
||||
fields::{Field, FpParameters, PrimeField, SquareRootField},
|
||||
One, Zero,
|
||||
};
|
||||
use ark_serialize::CanonicalSerialize;
|
||||
use ark_std::test_rng;
|
||||
|
||||
use ark_ec::{models::SWModelParameters, AffineCurve, PairingEngine, ProjectiveCurve};
|
||||
use ark_std::ops::{AddAssign, MulAssign};
|
||||
use ark_std::rand::Rng;
|
||||
|
||||
use crate::{Affine, PallasParameters, Projective};
|
||||
|
||||
use ark_algebra_test_templates::{
|
||||
curves::{curve_tests, sw_tests},
|
||||
groups::group_test,
|
||||
};
|
||||
use ark_ec::AffineCurve;
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
|
||||
use crate::{Affine, PallasParameters, Projective};
|
||||
|
||||
#[test]
|
||||
fn test_projective_curve() {
|
||||
|
||||
@@ -1,89 +1,7 @@
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
||||
fields::{FftParameters, Fp256, Fp256Parameters},
|
||||
};
|
||||
pub type Fq = Fp256<FqParameters>;
|
||||
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
||||
pub struct FqParameters;
|
||||
|
||||
impl Fp256Parameters for FqParameters {}
|
||||
impl FftParameters for FqParameters {
|
||||
type BigInt = BigInteger;
|
||||
|
||||
const TWO_ADICITY: u32 = 32;
|
||||
|
||||
// TWO_ADIC_ROOT_OF_UNITY = GENERATOR^T
|
||||
// Encoded in Montgomery form, so the value here is (5^T)R mod p.
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
0xa28db849bad6dbf0,
|
||||
0x9083cd03d3b539df,
|
||||
0xfba6b9ca9dc8448e,
|
||||
0x3ec928747b89c6da,
|
||||
]);
|
||||
}
|
||||
|
||||
impl ark_ff::fields::FpParameters for FqParameters {
|
||||
// 28948022309329048855892746252171976963363056481941560715954676764349967630337
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
0x992d30ed00000001,
|
||||
0x224698fc094cf91b,
|
||||
0x0000000000000000,
|
||||
0x4000000000000000,
|
||||
]);
|
||||
|
||||
// R = 2^256 mod p
|
||||
const R: BigInteger = BigInt::new([
|
||||
0x34786d38fffffffd,
|
||||
0x992c350be41914ad,
|
||||
0xffffffffffffffff,
|
||||
0x3fffffffffffffff,
|
||||
]);
|
||||
|
||||
// R2 = (2^256)^2 mod p
|
||||
const R2: BigInteger = BigInt::new([
|
||||
0x8c78ecb30000000f,
|
||||
0xd7d30dbd8b0de0e7,
|
||||
0x7797a99bc3c95d18,
|
||||
0x096d41af7b9cb714,
|
||||
]);
|
||||
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0xcc96987680000000,
|
||||
0x11234c7e04a67c8d,
|
||||
0x0000000000000000,
|
||||
0x2000000000000000,
|
||||
]);
|
||||
|
||||
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
||||
const T: BigInteger = BigInt::new([
|
||||
0x094cf91b992d30ed,
|
||||
0x00000000224698fc,
|
||||
0x0000000000000000,
|
||||
0x0000000040000000,
|
||||
]);
|
||||
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x04a67c8dcc969876,
|
||||
0x0000000011234c7e,
|
||||
0x0000000000000000,
|
||||
0x0000000020000000,
|
||||
]);
|
||||
|
||||
// GENERATOR = 5
|
||||
// Encoded in Montgomery form, so the value here is 5R mod p.
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
0xa1a55e68ffffffed,
|
||||
0x74c2a54b4f4982f3,
|
||||
0xfffffffffffffffd,
|
||||
0x3fffffffffffffff,
|
||||
]);
|
||||
|
||||
const MODULUS_BITS: u32 = 255;
|
||||
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
||||
|
||||
const REPR_SHAVE_BITS: u32 = 1;
|
||||
|
||||
// INV = -p^{-1} (mod 2^64)
|
||||
const INV: u64 = 11037532056220336127;
|
||||
}
|
||||
#[derive(MontConfig)]
|
||||
#[modulus = "28948022309329048855892746252171976963363056481941560715954676764349967630337"]
|
||||
#[generator = "5"]
|
||||
pub struct FqConfig;
|
||||
pub type Fq = Fp256<MontBackend<FqConfig, 4>>;
|
||||
|
||||
@@ -1,91 +1,7 @@
|
||||
use ark_ff::{
|
||||
biginteger::{BigInt, BigInteger256 as BigInteger},
|
||||
fields::{FftParameters, Fp256, Fp256Parameters, FpParameters},
|
||||
};
|
||||
use ark_ff::fields::{Fp256, MontBackend, MontConfig};
|
||||
|
||||
pub struct FrParameters;
|
||||
|
||||
pub type Fr = Fp256<FrParameters>;
|
||||
|
||||
impl Fp256Parameters for FrParameters {}
|
||||
impl FftParameters for FrParameters {
|
||||
type BigInt = BigInteger;
|
||||
|
||||
const TWO_ADICITY: u32 = 32;
|
||||
|
||||
// TWO_ADIC_ROOT_OF_UNITY = GENERATOR^T
|
||||
// Encoded in Montgomery form, so the value here is (5^T)R mod q.
|
||||
const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
|
||||
0x218077428c9942de,
|
||||
0xcc49578921b60494,
|
||||
0xac2e5d27b2efbee2,
|
||||
0x0b79fa897f2db056,
|
||||
]);
|
||||
}
|
||||
|
||||
impl FpParameters for FrParameters {
|
||||
// 28948022309329048855892746252171976963363056481941647379679742748393362948097
|
||||
const MODULUS: BigInteger = BigInt::new([
|
||||
0x8c46eb2100000001,
|
||||
0x224698fc0994a8dd,
|
||||
0x0000000000000000,
|
||||
0x4000000000000000,
|
||||
]);
|
||||
|
||||
// R = 2^256 mod q
|
||||
const R: BigInteger = BigInt::new([
|
||||
0x5b2b3e9cfffffffd,
|
||||
0x992c350be3420567,
|
||||
0xffffffffffffffff,
|
||||
0x3fffffffffffffff,
|
||||
]);
|
||||
|
||||
// R2 = (2^256)^2 mod q
|
||||
const R2: BigInteger = BigInt::new([
|
||||
0xfc9678ff0000000f,
|
||||
0x67bb433d891a16e3,
|
||||
0x7fae231004ccf590,
|
||||
0x096d41af7ccfdaa9,
|
||||
]);
|
||||
|
||||
const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0xc623759080000000,
|
||||
0x11234c7e04ca546e,
|
||||
0x0000000000000000,
|
||||
0x2000000000000000,
|
||||
]);
|
||||
|
||||
// T and T_MINUS_ONE_DIV_TWO, where MODULUS - 1 = 2^S * T
|
||||
|
||||
const T: BigInteger = BigInt::new([
|
||||
0x0994a8dd8c46eb21,
|
||||
0x00000000224698fc,
|
||||
0x0000000000000000,
|
||||
0x0000000040000000,
|
||||
]);
|
||||
|
||||
const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
|
||||
0x04ca546ec6237590,
|
||||
0x0000000011234c7e,
|
||||
0x0000000000000000,
|
||||
0x0000000020000000,
|
||||
]);
|
||||
|
||||
// GENERATOR = 5
|
||||
// Encoded in Montgomery form, so the value here is 5R mod q.
|
||||
const GENERATOR: BigInteger = BigInt::new([
|
||||
0x96bc8c8cffffffed,
|
||||
0x74c2a54b49f7778e,
|
||||
0xfffffffffffffffd,
|
||||
0x3fffffffffffffff,
|
||||
]);
|
||||
|
||||
const MODULUS_BITS: u32 = 255;
|
||||
|
||||
const CAPACITY: u32 = Self::MODULUS_BITS - 1;
|
||||
|
||||
const REPR_SHAVE_BITS: u32 = 1;
|
||||
|
||||
// INV = -q^{-1} (mod 2^64)
|
||||
const INV: u64 = 10108024940646105087;
|
||||
}
|
||||
#[derive(MontConfig)]
|
||||
#[modulus = "28948022309329048855892746252171976963363056481941647379679742748393362948097"]
|
||||
#[generator = "5"]
|
||||
pub struct FrConfig;
|
||||
pub type Fr = Fp256<MontBackend<FrConfig, 4>>;
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
use ark_std::rand::Rng;
|
||||
use ark_std::test_rng;
|
||||
use ark_algebra_test_templates::{
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
};
|
||||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
use crate::*;
|
||||
use crate::{Fq, FqConfig, Fr, FrConfig};
|
||||
|
||||
use ark_algebra_test_templates::fields::*;
|
||||
|
||||
#[test]
|
||||
fn test_fr() {
|
||||
let mut rng = test_rng();
|
||||
let a: Fr = rng.gen();
|
||||
let b: Fr = rng.gen();
|
||||
field_test(a, b);
|
||||
sqrt_field_test(a);
|
||||
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);
|
||||
sqrt_field_test(a);
|
||||
primefield_test::<Fq>();
|
||||
}
|
||||
generate_field_test!(pallas; mont(4, 4); );
|
||||
generate_field_serialization_test!(pallas;);
|
||||
|
||||
Reference in New Issue
Block a user