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_pallas`.
|
||||
//!
|
||||
//! 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,8 +1,8 @@
|
||||
use ark_ec::{
|
||||
models::{ModelParameters, SWModelParameters},
|
||||
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
|
||||
models::CurveConfig,
|
||||
short_weierstrass::{Affine, Projective, SWCurveConfig},
|
||||
};
|
||||
use ark_ff::{MontFp, Zero};
|
||||
use ark_ff::{Field, MontFp, Zero};
|
||||
|
||||
use crate::{fq::Fq, fr::Fr};
|
||||
|
||||
@@ -12,7 +12,7 @@ mod tests;
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq)]
|
||||
pub struct PallasParameters;
|
||||
|
||||
impl ModelParameters for PallasParameters {
|
||||
impl CurveConfig for PallasParameters {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
|
||||
@@ -20,22 +20,21 @@ impl ModelParameters for PallasParameters {
|
||||
const COFACTOR: &'static [u64] = &[0x1];
|
||||
|
||||
/// COFACTOR_INV = 1
|
||||
const COFACTOR_INV: Fr = MontFp!(Fr, "1");
|
||||
const COFACTOR_INV: Fr = Fr::ONE;
|
||||
}
|
||||
|
||||
pub type Affine = GroupAffine<PallasParameters>;
|
||||
pub type Projective = GroupProjective<PallasParameters>;
|
||||
pub type G1Affine = Affine<PallasParameters>;
|
||||
pub type G1Projective = Projective<PallasParameters>;
|
||||
|
||||
impl SWModelParameters for PallasParameters {
|
||||
impl SWCurveConfig for PallasParameters {
|
||||
/// COEFF_A = 0
|
||||
const COEFF_A: Fq = MontFp!(Fq, "0");
|
||||
const COEFF_A: Fq = Fq::ZERO;
|
||||
|
||||
/// COEFF_B = 5
|
||||
const COEFF_B: Fq = MontFp!(Fq, "5");
|
||||
const COEFF_B: Fq = MontFp!("5");
|
||||
|
||||
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
|
||||
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
|
||||
(G_GENERATOR_X, G_GENERATOR_Y);
|
||||
const GENERATOR: G1Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {
|
||||
@@ -44,7 +43,7 @@ impl SWModelParameters for PallasParameters {
|
||||
}
|
||||
|
||||
/// G_GENERATOR_X = -1
|
||||
pub const G_GENERATOR_X: Fq = MontFp!(Fq, "-1");
|
||||
pub const G_GENERATOR_X: Fq = MontFp!("-1");
|
||||
|
||||
/// G_GENERATOR_Y = 2
|
||||
pub const G_GENERATOR_Y: Fq = MontFp!(Fq, "2");
|
||||
pub const G_GENERATOR_Y: Fq = MontFp!("2");
|
||||
|
||||
@@ -1,29 +1,17 @@
|
||||
use ark_algebra_test_templates::{
|
||||
curves::{curve_tests, sw_tests},
|
||||
groups::group_test,
|
||||
};
|
||||
use ark_algebra_test_templates::curves::{curve_tests, sw_tests};
|
||||
use ark_ec::AffineCurve;
|
||||
use ark_std::{rand::Rng, test_rng};
|
||||
|
||||
use crate::{Affine, PallasParameters, Projective};
|
||||
use crate::{G1Affine, G1Projective, PallasParameters};
|
||||
|
||||
#[test]
|
||||
fn test_projective_curve() {
|
||||
curve_tests::<Projective>();
|
||||
curve_tests::<G1Projective>();
|
||||
sw_tests::<PallasParameters>();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_projective_group() {
|
||||
let mut rng = test_rng();
|
||||
let a: Projective = rng.gen();
|
||||
let b: Projective = rng.gen();
|
||||
group_test(a, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generator() {
|
||||
let generator = Affine::prime_subgroup_generator();
|
||||
let generator = G1Affine::prime_subgroup_generator();
|
||||
assert!(generator.is_on_curve());
|
||||
assert!(generator.is_in_correct_subgroup_assuming_on_curve());
|
||||
}
|
||||
|
||||
@@ -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