mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-08 23:11:29 +01:00
Catch up with algebra (#106)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//! This module implements the R1CS equivalent of `ark_ed_on_cp6_782`.
|
||||
//!
|
||||
//! 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, 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^(-1) mod r =
|
||||
/// 12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560
|
||||
const COFACTOR_INV: Fr = MontFp!(Fr, "12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560");
|
||||
const COFACTOR_INV: Fr = MontFp!("12124894969357926281749346891948134384518445910386624712788431705725441736421489799867521238554906438478484045560");
|
||||
}
|
||||
|
||||
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 = 79743
|
||||
const COEFF_D: Fq = MontFp!(Fq, "79743");
|
||||
const COEFF_D: Fq = MontFp!("79743");
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
|
||||
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 = 0x95D53EB3F6AC3F7A53C26020144439DC6073BCAE513E03FD06B6B3BAA390F25E51534B26719E33F4CD906D4DA9B535
|
||||
const COEFF_A: Fq = MontFp!(Fq, "90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765");
|
||||
const COEFF_A: Fq = MontFp!("90083623084271891037116870487743067984710080209539149685414147055329063590616489392386084989619674926965747987765");
|
||||
|
||||
/// COEFF_B = 0x118650763CE64AB4BE743604C8D05013DC2663652A3D58B21ECAB7BFF65B70DB8BA09F9098E61CC903B2F92B2564ACA
|
||||
const COEFF_B: Fq = MontFp!(Fq, "168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410");
|
||||
const COEFF_B: Fq = MontFp!("168580802928697202973535863207150465551683432545375510854470115611391404757724333382582803149953685197474573470410");
|
||||
|
||||
type TEModelParameters = EdwardsParameters;
|
||||
type TECurveConfig = EdwardsParameters;
|
||||
}
|
||||
|
||||
/// GENERATOR_X =
|
||||
/// 174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127
|
||||
const GENERATOR_X: Fq = MontFp!(Fq, "174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127");
|
||||
const GENERATOR_X: Fq = MontFp!("174701772324485506941690903512423551998294352968833659960042362742684869862495746426366187462669992073196420267127");
|
||||
|
||||
/// GENERATOR_Y =
|
||||
/// 208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833
|
||||
const GENERATOR_Y: Fq = MontFp!(Fq, "208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833");
|
||||
const GENERATOR_Y: Fq = MontFp!("208487200052258845495340374451540775445408439654930191324011635560142523886549663106522691296420655144190624954833");
|
||||
|
||||
@@ -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,26 +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();
|
||||
@@ -38,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