mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 07:21:30 +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_753`.
|
||||
//!
|
||||
//! 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;
|
||||
|
||||
@@ -24,20 +24,20 @@ impl ModelParameters for EdwardsParameters {
|
||||
|
||||
/// COFACTOR_INV (mod r) =
|
||||
/// 4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505
|
||||
const COFACTOR_INV: Fr = MontFp!(Fr, "4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505");
|
||||
const COFACTOR_INV: Fr = MontFp!("4582647449616135528381398492791944685893671397494963179726320631987147963874964803303316505414568319530101512550297775574042810022553679071007001162683923594233560231270043634777390699589793776691858866199511300853468155295505");
|
||||
}
|
||||
|
||||
impl TEModelParameters for EdwardsParameters {
|
||||
impl TECurveConfig for EdwardsParameters {
|
||||
/// COEFF_A = -1
|
||||
const COEFF_A: Fq = MontFp!(Fq, "-1");
|
||||
const COEFF_A: Fq = MontFp!("-1");
|
||||
|
||||
/// COEFF_D = 317690
|
||||
const COEFF_D: Fq = MontFp!(Fq, "317690");
|
||||
const COEFF_D: Fq = MontFp!("317690");
|
||||
|
||||
/// 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)]
|
||||
@@ -46,20 +46,20 @@ impl TEModelParameters for EdwardsParameters {
|
||||
}
|
||||
}
|
||||
|
||||
impl MontgomeryModelParameters for EdwardsParameters {
|
||||
impl MontCurveConfig for EdwardsParameters {
|
||||
/// COEFF_A = 40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419
|
||||
const COEFF_A: Fq = MontFp!(Fq, "40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419");
|
||||
const COEFF_A: Fq = MontFp!("40212480635445336270302172549278415015971955924352275480357619589919378421241453024646804979794897776496091377551124233752850182852486874251193367187677349266115879541798515219680194853352256809837126277708211496794264654247419");
|
||||
|
||||
/// COEFF_B = 1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580
|
||||
const COEFF_B: Fq = MontFp!(Fq, "1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580");
|
||||
const COEFF_B: Fq = MontFp!("1686010332473617132042042241962222112198753995601673591425883331105974391329653748412088783995441144921979594337334243570322874639106980818502874667119046899605536783551549221790223284494141659774809441351696667426519821912580");
|
||||
|
||||
type TEModelParameters = EdwardsParameters;
|
||||
type TECurveConfig = EdwardsParameters;
|
||||
}
|
||||
|
||||
/// GENERATOR_X =
|
||||
/// 41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826
|
||||
const GENERATOR_X: Fq = MontFp!(Fq, "41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826");
|
||||
const GENERATOR_X: Fq = MontFp!("41126137307536311801428235632419266329480236393691483739251051053325519918069469184425962602019877935619960143044210127218431046103600632347238890180171944971817510488009355627861577881883236134824745174469522277738875418206826");
|
||||
|
||||
/// GENERATOR_Y =
|
||||
/// 18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681
|
||||
const GENERATOR_Y: Fq = MontFp!(Fq, "18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681");
|
||||
const GENERATOR_Y: Fq = MontFp!("18249602579663240810999977712212098844157230095713722119136881953011435881503578209163288529034825612841855863913294174196656077002578342108932925693640046298989762289691399012056048139253937882385653600831389370198228562812681");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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::*;
|
||||
|
||||
@@ -11,27 +10,6 @@ fn test_projective_curve() {
|
||||
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 +17,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