Upgrade to work with latest ark-ff (#95)

Co-authored-by: Sun <huachuang20@gmail.com>
This commit is contained in:
Pratyush Mishra
2022-03-07 13:12:03 -08:00
committed by GitHub
parent d0dc200f22
commit 1551d6d76c
231 changed files with 2830 additions and 4343 deletions

View File

@@ -1,4 +1,3 @@
use crate::{Fq, Fr};
use ark_ec::{
models::{ModelParameters, MontgomeryModelParameters, TEModelParameters},
short_weierstrass_jacobian::{
@@ -7,7 +6,9 @@ use ark_ec::{
twisted_edwards_extended::{GroupAffine, GroupProjective},
SWModelParameters,
};
use ark_ff::{field_new, Field};
use ark_ff::{Field, MontFp};
use crate::{Fq, Fr};
#[cfg(test)]
mod tests;
@@ -18,8 +19,8 @@ pub type EdwardsProjective = GroupProjective<BandersnatchParameters>;
pub type SWAffine = SWGroupAffine<BandersnatchParameters>;
pub type SWProjective = SWGroupProjective<BandersnatchParameters>;
/// `bandersnatch` is a twisted Edwards curve. These curves have equations of the
/// form: ax² + y² = 1 - dx²y².
/// `bandersnatch` is a twisted Edwards curve. These curves have equations of
/// the form: ax² + y² = 1 - dx²y².
/// over some base finite field Fq.
///
/// bandersnatch's curve equation: -5x² + y² = 1 - dx²y²
@@ -50,7 +51,6 @@ pub type SWProjective = SWGroupProjective<BandersnatchParameters>;
///
/// Script to transfer between different curves are available
/// <https://github.com/zhenfeizhang/bandersnatch/blob/main/bandersnatch/script/bandersnatch.sage>
///
#[derive(Clone, Default, PartialEq, Eq)]
pub struct BandersnatchParameters;
@@ -66,18 +66,22 @@ impl ModelParameters for BandersnatchParameters {
/// COFACTOR^(-1) mod r =
/// 9831726595336160714896451345284868594481866920080427688839802480047265754601
#[rustfmt::skip]
const COFACTOR_INV: Fr = field_new!(Fr, "9831726595336160714896451345284868594481866920080427688839802480047265754601");
const COFACTOR_INV: Fr = MontFp!(
Fr,
"9831726595336160714896451345284868594481866920080427688839802480047265754601"
);
}
impl TEModelParameters for BandersnatchParameters {
/// COEFF_A = -5
const COEFF_A: Fq = field_new!(Fq, "-5");
const COEFF_A: Fq = MontFp!(Fq, "-5");
/// COEFF_D = (138827208126141220649022263972958607803/
/// 171449701953573178309673572579671231137) mod q
#[rustfmt::skip]
const COEFF_D: Fq = field_new!(Fq, "45022363124591815672509500913686876175488063829319466900776701791074614335719");
const COEFF_D: Fq = MontFp!(
Fq,
"45022363124591815672509500913686876175488063829319466900776701791074614335719"
);
/// AFFINE_GENERATOR_COEFFS = (GENERATOR_X, GENERATOR_Y)
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =
@@ -95,44 +99,65 @@ impl TEModelParameters for BandersnatchParameters {
impl MontgomeryModelParameters for BandersnatchParameters {
/// COEFF_A = 29978822694968839326280996386011761570173833766074948509196803838190355340952
#[rustfmt::skip]
const COEFF_A: Fq = field_new!(Fq, "29978822694968839326280996386011761570173833766074948509196803838190355340952");
const COEFF_A: Fq = MontFp!(
Fq,
"29978822694968839326280996386011761570173833766074948509196803838190355340952"
);
/// COEFF_B = 25465760566081946422412445027709227188579564747101592991722834452325077642517
#[rustfmt::skip]
const COEFF_B: Fq = field_new!(Fq, "25465760566081946422412445027709227188579564747101592991722834452325077642517");
const COEFF_B: Fq = MontFp!(
Fq,
"25465760566081946422412445027709227188579564747101592991722834452325077642517"
);
type TEModelParameters = BandersnatchParameters;
}
// The TE form generator is generated following Zcash's fashion:
// "The generators of G1 and G2 are computed by finding the lexicographically smallest
// valid x-coordinate, and its lexicographically smallest y-coordinate and scaling it
// by the cofactor such that the result is not the point at infinity."
// The SW form generator is the same TE generator converted into SW form, obtained from the scripts:
// "The generators of G1 and G2 are computed by finding the lexicographically
// smallest valid x-coordinate, and its lexicographically smallest
// y-coordinate and scaling it by the cofactor such that the result is not
// the point at infinity."
// The SW form generator is the same TE generator converted into SW form,
// obtained from the scripts:
// <https://github.com/zhenfeizhang/bandersnatch/blob/main/bandersnatch/script/bandersnatch.sage>
/// x coordinate for TE curve generator
#[rustfmt::skip]
const TE_GENERATOR_X: Fq = field_new!(Fq, "18886178867200960497001835917649091219057080094937609519140440539760939937304");
const TE_GENERATOR_X: Fq = MontFp!(
Fq,
"18886178867200960497001835917649091219057080094937609519140440539760939937304"
);
/// y coordinate for TE curve generator
#[rustfmt::skip]
const TE_GENERATOR_Y: Fq = field_new!(Fq, "19188667384257783945677642223292697773471335439753913231509108946878080696678");
const TE_GENERATOR_Y: Fq = MontFp!(
Fq,
"19188667384257783945677642223292697773471335439753913231509108946878080696678"
);
/// x coordinate for SW curve generator
#[rustfmt::skip]
const SW_GENERATOR_X: Fq = field_new!(Fq, "30900340493481298850216505686589334086208278925799850409469406976849338430199");
const SW_GENERATOR_X: Fq = MontFp!(
Fq,
"30900340493481298850216505686589334086208278925799850409469406976849338430199"
);
/// y coordinate for SW curve generator
#[rustfmt::skip]
const SW_GENERATOR_Y: Fq = field_new!(Fq, "12663882780877899054958035777720958383845500985908634476792678820121468453298");
const SW_GENERATOR_Y: Fq = MontFp!(
Fq,
"12663882780877899054958035777720958383845500985908634476792678820121468453298"
);
impl SWModelParameters for BandersnatchParameters {
/// COEFF_A = 10773120815616481058602537765553212789256758185246796157495669123169359657269
#[rustfmt::skip]
const COEFF_A: Self::BaseField = field_new!(Fq, "10773120815616481058602537765553212789256758185246796157495669123169359657269");
const COEFF_A: Self::BaseField = MontFp!(
Fq,
"10773120815616481058602537765553212789256758185246796157495669123169359657269"
);
/// COEFF_B = 29569587568322301171008055308580903175558631321415017492731745847794083609535
#[rustfmt::skip]
const COEFF_B: Self::BaseField = field_new!(Fq, "29569587568322301171008055308580903175558631321415017492731745847794083609535");
const COEFF_B: Self::BaseField = MontFp!(
Fq,
"29569587568322301171008055308580903175558631321415017492731745847794083609535"
);
/// generators
const AFFINE_GENERATOR_COEFFS: (Self::BaseField, Self::BaseField) =

View File

@@ -1,9 +1,10 @@
use crate::*;
use ark_algebra_test_templates::{curves::*, groups::*};
use ark_ec::{AffineCurve, ProjectiveCurve};
use ark_ff::{bytes::FromBytes, Zero};
use ark_std::{rand::Rng, str::FromStr, test_rng};
use crate::*;
#[test]
fn test_projective_curve() {
curve_tests::<EdwardsProjective>();