Fix benchmarks and fix accidental renaming of Pallas/Vesta (#108)

This commit is contained in:
Pratyush Mishra
2022-08-01 13:46:52 -07:00
committed by GitHub
parent 67d5a8582e
commit e75546313a
5 changed files with 17 additions and 24 deletions

View File

@@ -2,15 +2,15 @@
extern crate ark_relations; extern crate ark_relations;
pub mod fields { pub mod fields {
use ark_ff::{BigInteger, BitIteratorLE, Field, PrimeField, UniformRand}; use ark_ff::{BitIteratorLE, Field, PrimeField, UniformRand};
use ark_r1cs_std::prelude::*; use ark_r1cs_std::prelude::*;
use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_relations::r1cs::{ConstraintSystem, SynthesisError};
use ark_std::{test_rng, vec::Vec}; use ark_std::{test_rng, vec::Vec};
pub fn field_test<F, ConstraintF, AF>() -> Result<(), SynthesisError> pub fn field_test<F, ConstraintF, AF>() -> Result<(), SynthesisError>
where where
F: PrimeField, F: Field,
ConstraintF: Field, ConstraintF: PrimeField,
AF: FieldVar<F, ConstraintF>, AF: FieldVar<F, ConstraintF>,
AF: TwoBitLookupGadget<ConstraintF, TableConstant = F>, AF: TwoBitLookupGadget<ConstraintF, TableConstant = F>,
for<'a> &'a AF: FieldOpsBounds<'a, F, AF>, for<'a> &'a AF: FieldOpsBounds<'a, F, AF>,
@@ -175,13 +175,6 @@ pub mod fields {
let _ = r.to_bits_le()?; let _ = r.to_bits_le()?;
assert!(cs.is_satisfied().unwrap()); assert!(cs.is_satisfied().unwrap());
let bytes = r.to_non_unique_bytes()?;
assert_eq!(r_native.into_bigint().to_bytes_le(), bytes.value().unwrap());
assert!(cs.is_satisfied().unwrap());
let bytes = r.to_bytes()?;
assert_eq!(r_native.into_bigint().to_bytes_le(), bytes.value().unwrap());
assert!(cs.is_satisfied().unwrap());
let ab_false = &a + (AF::from(Boolean::Constant(false)) * b_native); let ab_false = &a + (AF::from(Boolean::Constant(false)) * b_native);
let ab_true = &a + (AF::from(Boolean::Constant(true)) * b_native); let ab_true = &a + (AF::from(Boolean::Constant(true)) * b_native);
assert_eq!(ab_false.value()?, a_native); assert_eq!(ab_false.value()?, a_native);

View File

@@ -1,6 +1,6 @@
use ark_ec::{ use ark_ec::{
models::CurveConfig, models::CurveConfig,
short_weierstrass::{Affine, Projective, SWCurveConfig}, short_weierstrass::{self as sw, SWCurveConfig},
}; };
use ark_ff::{Field, MontFp, Zero}; use ark_ff::{Field, MontFp, Zero};
@@ -23,8 +23,8 @@ impl CurveConfig for PallasParameters {
const COFACTOR_INV: Fr = Fr::ONE; const COFACTOR_INV: Fr = Fr::ONE;
} }
pub type G1Affine = Affine<PallasParameters>; pub type Affine = sw::Affine<PallasParameters>;
pub type G1Projective = Projective<PallasParameters>; pub type Projective = sw::Projective<PallasParameters>;
impl SWCurveConfig for PallasParameters { impl SWCurveConfig for PallasParameters {
/// COEFF_A = 0 /// COEFF_A = 0
@@ -34,7 +34,7 @@ impl SWCurveConfig for PallasParameters {
const COEFF_B: Fq = MontFp!("5"); const COEFF_B: Fq = MontFp!("5");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
const GENERATOR: G1Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y); const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
#[inline(always)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {

View File

@@ -1,17 +1,17 @@
use ark_algebra_test_templates::curves::{curve_tests, sw_tests}; use ark_algebra_test_templates::curves::{curve_tests, sw_tests};
use ark_ec::AffineCurve; use ark_ec::AffineCurve;
use crate::{G1Affine, G1Projective, PallasParameters}; use crate::{Affine, PallasParameters, Projective};
#[test] #[test]
fn test_projective_curve() { fn test_projective_curve() {
curve_tests::<G1Projective>(); curve_tests::<Projective>();
sw_tests::<PallasParameters>(); sw_tests::<PallasParameters>();
} }
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = G1Affine::prime_subgroup_generator(); let generator = Affine::prime_subgroup_generator();
assert!(generator.is_on_curve()); assert!(generator.is_on_curve());
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }

View File

@@ -1,7 +1,7 @@
use crate::{fq::Fq, fr::Fr}; use crate::{fq::Fq, fr::Fr};
use ark_ec::{ use ark_ec::{
models::CurveConfig, models::CurveConfig,
short_weierstrass::{Affine, Projective, SWCurveConfig}, short_weierstrass::{self as sw, SWCurveConfig},
}; };
use ark_ff::{Field, MontFp, Zero}; use ark_ff::{Field, MontFp, Zero};
@@ -22,8 +22,8 @@ impl CurveConfig for VestaParameters {
const COFACTOR_INV: Fr = Fr::ONE; const COFACTOR_INV: Fr = Fr::ONE;
} }
pub type G1Affine = Affine<VestaParameters>; pub type Affine = sw::Affine<VestaParameters>;
pub type G1Projective = Projective<VestaParameters>; pub type Projective = sw::Projective<VestaParameters>;
impl SWCurveConfig for VestaParameters { impl SWCurveConfig for VestaParameters {
/// COEFF_A = 0 /// COEFF_A = 0
@@ -33,7 +33,7 @@ impl SWCurveConfig for VestaParameters {
const COEFF_B: Fq = MontFp!("5"); const COEFF_B: Fq = MontFp!("5");
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) /// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
const GENERATOR: G1Affine = G1Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y); const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
#[inline(always)] #[inline(always)]
fn mul_by_a(_: &Self::BaseField) -> Self::BaseField { fn mul_by_a(_: &Self::BaseField) -> Self::BaseField {

View File

@@ -1,17 +1,17 @@
use ark_algebra_test_templates::curves::{curve_tests, sw_tests}; use ark_algebra_test_templates::curves::{curve_tests, sw_tests};
use ark_ec::AffineCurve; use ark_ec::AffineCurve;
use crate::{G1Affine, G1Projective, VestaParameters}; use crate::{Affine, Projective, VestaParameters};
#[test] #[test]
fn test_projective_curve() { fn test_projective_curve() {
curve_tests::<G1Projective>(); curve_tests::<Projective>();
sw_tests::<VestaParameters>(); sw_tests::<VestaParameters>();
} }
#[test] #[test]
fn test_generator() { fn test_generator() {
let generator = G1Affine::prime_subgroup_generator(); let generator = Affine::prime_subgroup_generator();
assert!(generator.is_on_curve()); assert!(generator.is_on_curve());
assert!(generator.is_in_correct_subgroup_assuming_on_curve()); assert!(generator.is_in_correct_subgroup_assuming_on_curve());
} }