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:
@@ -1,7 +1,7 @@
|
||||
//! This module implements the R1CS equivalent of `ark_ed_on_bls12_377`.
|
||||
//!
|
||||
//! 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,23 +24,21 @@ impl ModelParameters for EdwardsParameters {
|
||||
|
||||
/// COFACTOR_INV =
|
||||
/// 527778859339273151515551558673846658209717731602102048798421311598680340096
|
||||
const COFACTOR_INV: Fr = MontFp!(
|
||||
Fr,
|
||||
"527778859339273151515551558673846658209717731602102048798421311598680340096"
|
||||
);
|
||||
const COFACTOR_INV: Fr =
|
||||
MontFp!("527778859339273151515551558673846658209717731602102048798421311598680340096");
|
||||
}
|
||||
|
||||
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 = 3021
|
||||
const COEFF_D: Fq = MontFp!(Fq, "3021");
|
||||
const COEFF_D: Fq = MontFp!("3021");
|
||||
|
||||
/// 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.
|
||||
/// Is `a` 1 or -1?
|
||||
@@ -50,34 +48,26 @@ impl TEModelParameters for EdwardsParameters {
|
||||
}
|
||||
}
|
||||
|
||||
impl MontgomeryModelParameters for EdwardsParameters {
|
||||
impl MontCurveConfig for EdwardsParameters {
|
||||
/// COEFF_A = 0x8D26E3FADA9010A26949031ECE3971B93952AD84D4753DDEDB748DA37E8F552
|
||||
/// = 3990301581132929505568273333084066329187552697088022219156688740916631500114
|
||||
const COEFF_A: Fq = MontFp!(
|
||||
Fq,
|
||||
"3990301581132929505568273333084066329187552697088022219156688740916631500114"
|
||||
);
|
||||
const COEFF_A: Fq =
|
||||
MontFp!("3990301581132929505568273333084066329187552697088022219156688740916631500114");
|
||||
|
||||
/// COEFF_B = 0x9D8F71EEC83A44C3A1FBCEC6F5418E5C6154C2682B8AC231C5A3725C8170AAD
|
||||
/// = 4454160168295440918680551605697480202188346638066041608778544715000777738925
|
||||
const COEFF_B: Fq = MontFp!(
|
||||
Fq,
|
||||
"4454160168295440918680551605697480202188346638066041608778544715000777738925"
|
||||
);
|
||||
const COEFF_B: Fq =
|
||||
MontFp!("4454160168295440918680551605697480202188346638066041608778544715000777738925");
|
||||
|
||||
type TEModelParameters = EdwardsParameters;
|
||||
type TECurveConfig = EdwardsParameters;
|
||||
}
|
||||
|
||||
/// GENERATOR_X =
|
||||
/// 4497879464030519973909970603271755437257548612157028181994697785683032656389,
|
||||
const GENERATOR_X: Fq = MontFp!(
|
||||
Fq,
|
||||
"4497879464030519973909970603271755437257548612157028181994697785683032656389"
|
||||
);
|
||||
const GENERATOR_X: Fq =
|
||||
MontFp!("4497879464030519973909970603271755437257548612157028181994697785683032656389");
|
||||
|
||||
/// GENERATOR_Y =
|
||||
/// 4357141146396347889246900916607623952598927460421559113092863576544024487809
|
||||
const GENERATOR_Y: Fq = MontFp!(
|
||||
Fq,
|
||||
"4357141146396347889246900916607623952598927460421559113092863576544024487809"
|
||||
);
|
||||
const GENERATOR_Y: Fq =
|
||||
MontFp!("4357141146396347889246900916607623952598927460421559113092863576544024487809");
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -2,7 +2,7 @@ use ark_algebra_test_templates::{
|
||||
fields::*, generate_field_serialization_test, generate_field_test,
|
||||
};
|
||||
use ark_ff::{
|
||||
fields::{Field, PrimeField, SquareRootField},
|
||||
fields::{Field, PrimeField},
|
||||
One, UniformRand, Zero,
|
||||
};
|
||||
use ark_serialize::{buffer_bit_byte_size, CanonicalSerialize};
|
||||
|
||||
Reference in New Issue
Block a user