mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 15:31:34 +01:00
Catch up with algebra (#106)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! This module implements the R1CS equivalent of `ark_ed_on_mnt4_298`.
|
||||
//!
|
||||
//! It implements field variables for `crate::Fq`,
|
||||
//! and group variables for `crate::GroupProjective`.
|
||||
//! and group variables for `crate::Projective`.
|
||||
//!
|
||||
//! The field underlying these constraints is `crate::Fq`.
|
||||
//!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use ark_ec::{
|
||||
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
|
||||
twisted_edwards_extended::{GroupAffine, GroupProjective},
|
||||
models::CurveConfig,
|
||||
twisted_edwards::{Affine, MontCurveConfig, Projective, TECurveConfig},
|
||||
};
|
||||
use ark_ff::MontFp;
|
||||
|
||||
@@ -9,13 +9,13 @@ use crate::{fq::Fq, fr::Fr};
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub type EdwardsAffine = GroupAffine<EdwardsParameters>;
|
||||
pub type EdwardsProjective = GroupProjective<EdwardsParameters>;
|
||||
pub type EdwardsAffine = Affine<EdwardsParameters>;
|
||||
pub type EdwardsProjective = Projective<EdwardsParameters>;
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct EdwardsParameters;
|
||||
|
||||
impl ModelParameters for EdwardsParameters {
|
||||
impl CurveConfig for EdwardsParameters {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -25,7 +25,6 @@ impl ModelParameters for EdwardsParameters {
|
||||
/// COFACTOR_INV (mod r) =
|
||||
/// 29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158
|
||||
const COFACTOR_INV: Fr = MontFp!(
|
||||
Fr,
|
||||
"29745142885578832859584328103315528221570304936126890280067991221921526670592508030983158"
|
||||
);
|
||||
}
|
||||
@@ -35,23 +34,23 @@ impl ModelParameters for EdwardsParameters {
|
||||
// R for Fq: 223364648326281414938801705359223029554923725549792420683051274872200260503540791531766876
|
||||
// R for Fr: 104384076783966083500464392945960916666734135485183910065100558776489954102951241798239545
|
||||
|
||||
impl TEModelParameters for EdwardsParameters {
|
||||
impl TECurveConfig for EdwardsParameters {
|
||||
/// COEFF_A = -1
|
||||
/// Needs to be in the Montgomery residue form in Fq
|
||||
/// I.e., -1 * R for Fq
|
||||
/// = 252557637842979910814547544293825421990201153003031094870216460866964386803867699028196261
|
||||
const COEFF_A: Fq = MontFp!(Fq, "-1");
|
||||
const COEFF_A: Fq = MontFp!("-1");
|
||||
|
||||
/// COEFF_D = 4212
|
||||
/// Needs to be in the Montgomery residue form in Fq
|
||||
/// I.e., 4212 * R for Fq
|
||||
/// = 389461279836940033614665658623660232171971995346409183754923941118154161474636585314923000
|
||||
const COEFF_D: Fq = MontFp!(Fq, "4212");
|
||||
const COEFF_D: Fq = MontFp!("4212");
|
||||
|
||||
/// Generated randomly
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) = (GENERATOR_X, GENERATOR_Y);
|
||||
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
|
||||
|
||||
type MontgomeryModelParameters = EdwardsParameters;
|
||||
type MontCurveConfig = EdwardsParameters;
|
||||
|
||||
/// Multiplication by `a` is just negation.
|
||||
#[inline(always)]
|
||||
@@ -60,26 +59,24 @@ impl TEModelParameters for EdwardsParameters {
|
||||
}
|
||||
}
|
||||
|
||||
impl MontgomeryModelParameters for EdwardsParameters {
|
||||
impl MontCurveConfig for EdwardsParameters {
|
||||
/// COEFF_A = 203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204
|
||||
const COEFF_A: Fq = MontFp!(Fq, "203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
|
||||
const COEFF_A: Fq = MontFp!("203563247015667910991582090642011229452721346107806307863040223071914240315202967004285204");
|
||||
|
||||
/// COEFF_B = 272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931
|
||||
const COEFF_B: Fq = MontFp!(Fq, "272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
|
||||
const COEFF_B: Fq = MontFp!("272359039153593414761767159011037222092403532445017207690227512667250406992205523555677931");
|
||||
|
||||
type TEModelParameters = EdwardsParameters;
|
||||
type TECurveConfig = EdwardsParameters;
|
||||
}
|
||||
|
||||
/// GENERATOR_X =
|
||||
/// 282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227
|
||||
const GENERATOR_X: Fq = MontFp!(
|
||||
Fq,
|
||||
"282406820114868156776872298252698015906762052916420164316497572033519876761239463633892227"
|
||||
);
|
||||
|
||||
/// GENERATOR_Y =
|
||||
/// 452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703
|
||||
const GENERATOR_Y: Fq = MontFp!(
|
||||
Fq,
|
||||
"452667754940241021433619311795265643711152068500301853535337412655162600774122192283142703"
|
||||
);
|
||||
|
||||
@@ -1,37 +1,8 @@
|
||||
use ark_algebra_test_templates::{curves::*, groups::*};
|
||||
use ark_ec::{AffineCurve, ProjectiveCurve};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use ark_algebra_test_templates::curves::*;
|
||||
use ark_ec::AffineCurve;
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn test_projective_curve() {
|
||||
curve_tests::<EdwardsProjective>();
|
||||
|
||||
edwards_tests::<EdwardsParameters>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_projective_group() {
|
||||
let mut rng = test_rng();
|
||||
let a = rng.gen();
|
||||
let b = rng.gen();
|
||||
|
||||
for _i in 0..100 {
|
||||
group_test::<EdwardsProjective>(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_affine_group() {
|
||||
let mut rng = test_rng();
|
||||
let a: EdwardsAffine = rng.gen();
|
||||
let b: EdwardsAffine = rng.gen();
|
||||
for _i in 0..100 {
|
||||
group_test::<EdwardsAffine>(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generator() {
|
||||
let generator = EdwardsAffine::prime_subgroup_generator();
|
||||
@@ -39,22 +10,6 @@ fn test_generator() {
|
||||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion() {
|
||||
let mut rng = test_rng();
|
||||
let a: EdwardsAffine = rng.gen();
|
||||
let b: EdwardsAffine = rng.gen();
|
||||
let a_b = {
|
||||
use ark_ec::group::Group;
|
||||
(a + &b).double().double()
|
||||
};
|
||||
let a_b2 = (a.into_projective() + &b.into_projective())
|
||||
.double()
|
||||
.double();
|
||||
assert_eq!(a_b, a_b2.into_affine());
|
||||
assert_eq!(a_b.into_projective(), a_b2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_montgomery_conversion() {
|
||||
montgomery_conversion_test::<EdwardsParameters>();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ark_algebra_test_templates::{
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
};
|
||||
use ark_ff::{Field, One, PrimeField, SquareRootField, UniformRand, Zero};
|
||||
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
use core::ops::{AddAssign, MulAssign, SubAssign};
|
||||
|
||||
Reference in New Issue
Block a user