mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 07:21:30 +01:00
Upgrade to work with latest ark-ff (#95)
Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
28
vesta/scripts/base_field.sage
Normal file
28
vesta/scripts/base_field.sage
Normal file
@@ -0,0 +1,28 @@
|
||||
modulus = 28948022309329048855892746252171976963363056481941647379679742748393362948097
|
||||
|
||||
assert(modulus.is_prime())
|
||||
|
||||
Fp = GF(modulus)
|
||||
|
||||
generator = Fp(0);
|
||||
for i in range(0, 20):
|
||||
i = Fp(i);
|
||||
neg_i = Fp(-i)
|
||||
if not(i.is_primitive_root() or neg_i.is_primitive_root()):
|
||||
continue
|
||||
elif i.is_primitive_root():
|
||||
assert(i.is_primitive_root());
|
||||
print("Generator: %d" % i)
|
||||
generator = i
|
||||
break
|
||||
else:
|
||||
assert(neg_i.is_primitive_root());
|
||||
print("Generator: %d" % neg_i)
|
||||
generator = neg_i
|
||||
break
|
||||
|
||||
|
||||
two_adicity = valuation(modulus - 1, 2);
|
||||
trace = (modulus - 1) / 2**two_adicity;
|
||||
two_adic_root_of_unity = generator^trace
|
||||
print("2-adic Root of Unity: %d " % two_adic_root_of_unity)
|
||||
28
vesta/scripts/scalar_field.sage
Normal file
28
vesta/scripts/scalar_field.sage
Normal file
@@ -0,0 +1,28 @@
|
||||
modulus = 28948022309329048855892746252171976963363056481941560715954676764349967630337
|
||||
|
||||
assert(modulus.is_prime())
|
||||
|
||||
Fp = GF(modulus)
|
||||
|
||||
generator = Fp(0);
|
||||
for i in range(0, 20):
|
||||
i = Fp(i);
|
||||
neg_i = Fp(-i)
|
||||
if not(i.is_primitive_root() or neg_i.is_primitive_root()):
|
||||
continue
|
||||
elif i.is_primitive_root():
|
||||
assert(i.is_primitive_root());
|
||||
print("Generator: %d" % i)
|
||||
generator = i
|
||||
break
|
||||
else:
|
||||
assert(neg_i.is_primitive_root());
|
||||
print("Generator: %d" % neg_i)
|
||||
generator = neg_i
|
||||
break
|
||||
|
||||
|
||||
two_adicity = valuation(modulus - 1, 2);
|
||||
trace = (modulus - 1) / 2**two_adicity;
|
||||
two_adic_root_of_unity = generator^trace
|
||||
print("2-adic Root of Unity: %d " % two_adic_root_of_unity)
|
||||
@@ -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 Vesta prime-order group.
|
||||
pub type GVar = ProjectiveVar<VestaParameters, 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>;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use ark_ec::{
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
|
||||
};
|
||||
use ark_ff::{field_new, Zero};
|
||||
use ark_ff::{MontFp, Zero};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -19,7 +19,7 @@ impl ModelParameters for VestaParameters {
|
||||
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<VestaParameters>;
|
||||
@@ -27,10 +27,10 @@ pub type Projective = GroupProjective<VestaParameters>;
|
||||
|
||||
impl SWModelParameters for VestaParameters {
|
||||
/// 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) =
|
||||
@@ -44,8 +44,8 @@ impl SWModelParameters for VestaParameters {
|
||||
|
||||
/// G_GENERATOR_X = -1
|
||||
/// Encoded in Montgomery form, so the value here is -R mod p.
|
||||
pub const G_GENERATOR_X: Fq = field_new!(Fq, "-1");
|
||||
pub const G_GENERATOR_X: Fq = MontFp!(Fq, "-1");
|
||||
|
||||
/// G_GENERATOR_Y = 2
|
||||
/// Encoded in Montgomery form, so the value here is 2R mod p.
|
||||
pub const G_GENERATOR_Y: Fq = field_new!(Fq, "2");
|
||||
pub const G_GENERATOR_Y: Fq = MontFp!(Fq, "2");
|
||||
|
||||
18
vesta/src/curves/tests.rs
Normal file → Executable file
18
vesta/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, Projective, VestaParameters};
|
||||
|
||||
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, Projective, VestaParameters};
|
||||
|
||||
#[test]
|
||||
fn test_projective_curve() {
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub use ark_pallas::{Fr as Fq, FrParameters as FqParameters};
|
||||
pub use ark_pallas::{Fr as Fq, FrConfig as FqConfig};
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub use ark_pallas::{Fq as Fr, FqParameters as FrParameters};
|
||||
pub use ark_pallas::{Fq as Fr, FqConfig as FrConfig};
|
||||
|
||||
@@ -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!(vesta; mont(4, 4); );
|
||||
generate_field_serialization_test!(vesta;);
|
||||
|
||||
Reference in New Issue
Block a user