This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BW6-767 curve and update BW6-761 to use the new bw6 model (#156)
* Rework bw6-761 to bw6-767 use bls12-381 instead of 377 for test imports fix the inline comments with correct name and params Set the right base field Equation for base curve is y2 = x3 + 1 fill in pairing params adapt sage scripts with correct moduli calculate the correct cubic non residue correct the parameter B in the curve equation remove the specialized method for mult by nonresidue nonresidue is two, so default will be doubling calculate more correct parameters for fq3 `TRACE_MINUS_ONE_DIV_TWO` and `QUADRATIC_NONRESIDUE_TO_T` compute the right fq3 & fp6 frobenious coefficients calculate the cofactor for g1 use the g1 generator from gnark's fork use the right g2 equation g2 cofactor is slightly smaller than g1 cofactor get the g2 generators from gnark's fork update g1 and g2 curve info in the comments fill in `COFACTOR_INV` value for g1 fill in `COFACTOR_INV` value for g2 * update module description author information 2-adicity of the scalar field * update changelog * remove trailing comma * remove todo * 2nd loop count is x^3 - x^2 - x * Revert "2nd loop count is x^3 - x^2 - x" This reverts commit 2b323db. * fix comment regarding non-residue * first loop count should be X * 1. Generic BW6 params added to BW6-761 2. Curve specific hard part of the final exp moved from algebra * 1. Generic BW6 params added to BW6-767 2. Miller loop params changed to the "unoptimized" version * cargo fmt * changelog updated * X_MINUS_1_DIV_3 added to BW6Config * imports fixed --------- Co-authored-by: mmagician <[email protected]>
- Loading branch information
Showing
20 changed files
with
619 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ members = [ | |
"bw6_761", | ||
"ed_on_bw6_761", | ||
|
||
"bw6_767", | ||
|
||
"cp6_782", | ||
"ed_on_cp6_782", | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "ark-bw6-767" | ||
version = "0.4.0" | ||
authors = [ "arkworks contributors" ] | ||
description = "The BW6-767 pairing-friendly elliptic curve" | ||
homepage = "https://arkworks.rs" | ||
repository = "https://github.com/arkworks-rs/curves" | ||
documentation = "https://docs.rs/ark-bw6-767/" | ||
keywords = ["cryptography", "finite-fields", "elliptic-curves" ] | ||
categories = ["cryptography"] | ||
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] | ||
license = "MIT/Apache-2.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
ark-ff = { version= "0.4.0", default-features = false } | ||
ark-ec = { version= "0.4.0", default-features = false } | ||
ark-std = { version = "0.4.0", default-features = false } | ||
ark-bls12-381 = { version = "0.4.0", path = "../bls12_381", default-features = false, features = [ "curve" ] } | ||
|
||
[dev-dependencies] | ||
ark-serialize = { version = "0.4.0", default-features = false } | ||
ark-algebra-test-templates = { version = "0.4.0", default-features = false } | ||
ark-algebra-bench-templates = { version = "0.4.0", default-features = false } | ||
|
||
[features] | ||
default = [] | ||
std = [ "ark-std/std", "ark-ff/std", "ark-ec/std", "ark-bls12-381/std" ] | ||
|
||
[[bench]] | ||
name = "bw6_767" | ||
path = "benches/bw6_767.rs" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-APACHE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE-MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use ark_algebra_bench_templates::*; | ||
|
||
use ark_bw6_767::{ | ||
fq::Fq, fq3::Fq3, fq6::Fq6, fr::Fr, g1::G1Projective as G1, g2::G2Projective as G2, BW6_767, | ||
}; | ||
|
||
bench!( | ||
Name = "BW6_767", | ||
Pairing = BW6_767, | ||
G1 = G1, | ||
G2 = G2, | ||
ScalarField = Fr, | ||
G1BaseField = Fq, | ||
G2BaseField = Fq3, | ||
TargetField = Fq6, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
modulus = 496597749679620867773432037469214230242402307330180853437434581099336634619713640485778675608223760166307530047354464605410050411581079376994803852937842168733702867087556948851016246640584660942486895230518034810309227309966899431 | ||
|
||
assert(modulus.is_prime()) | ||
|
||
Fp = GF(modulus) | ||
|
||
generator = Fp(0); | ||
for i in range(0, 20): | ||
i = Fp(i); | ||
neg_i = Fp(-i) | ||
if not(i.is_primitive_root() or neg_i.is_primitive_root()): | ||
continue | ||
elif i.is_primitive_root(): | ||
assert(i.is_primitive_root()); | ||
print("Generator: %d" % i) | ||
generator = i | ||
break | ||
else: | ||
assert(neg_i.is_primitive_root()); | ||
print("Generator: %d" % neg_i) | ||
generator = neg_i | ||
break | ||
|
||
|
||
two_adicity = valuation(modulus - 1, 2); | ||
trace = (modulus - 1) / 2**two_adicity; | ||
two_adic_root_of_unity = generator^trace | ||
print("2-adic Root of Unity: %d " % two_adic_root_of_unity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
modulus = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 | ||
|
||
assert(modulus.is_prime()) | ||
|
||
Fp = GF(modulus) | ||
|
||
generator = Fp(0); | ||
for i in range(0, 20): | ||
i = Fp(i); | ||
neg_i = Fp(-i) | ||
if not(i.is_primitive_root() or neg_i.is_primitive_root()): | ||
continue | ||
elif i.is_primitive_root(): | ||
assert(i.is_primitive_root()); | ||
print("Generator: %d" % i) | ||
generator = i | ||
break | ||
else: | ||
assert(neg_i.is_primitive_root()); | ||
print("Generator: %d" % neg_i) | ||
generator = neg_i | ||
break | ||
|
||
|
||
two_adicity = valuation(modulus - 1, 2); | ||
trace = (modulus - 1) / 2**two_adicity; | ||
two_adic_root_of_unity = generator^trace | ||
print("2-adic Root of Unity: %d " % two_adic_root_of_unity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use ark_ec::{ | ||
models::{short_weierstrass::SWCurveConfig, CurveConfig}, | ||
short_weierstrass::{Affine, Projective}, | ||
}; | ||
use ark_ff::{AdditiveGroup, MontFp}; | ||
|
||
use crate::{Fq, Fr}; | ||
|
||
pub type G1Affine = Affine<Config>; | ||
pub type G1Projective = Projective<Config>; | ||
|
||
#[derive(Clone, Default, PartialEq, Eq)] | ||
pub struct Config; | ||
|
||
impl CurveConfig for Config { | ||
type BaseField = Fq; | ||
type ScalarField = Fr; | ||
|
||
/// COFACTOR = | ||
/// 124074696211871689196744963988542244365937182994917792082847997279938522233341057826255097957635256182243502012934844 | ||
#[rustfmt::skip] | ||
const COFACTOR: &'static [u64] = &[ | ||
0x9fed0006fffaaabc, | ||
0xfae29bffb34d7c0d, | ||
0xc51e35fba8145036, | ||
0x58c9927410ca3a62, | ||
0x7772b64205a0bc67, | ||
0x26212b5cf67cecaf, | ||
0x3, | ||
]; | ||
|
||
/// COFACTOR^(-1) mod r = | ||
/// 1707860402533867312515920333330662452399178546610458136488910471176197226039103222144872611321997303708365553992812 | ||
const COFACTOR_INV: Fr = MontFp!("1707860402533867312515920333330662452399178546610458136488910471176197226039103222144872611321997303708365553992812"); | ||
} | ||
|
||
impl SWCurveConfig for Config { | ||
/// COEFF_A = 0 | ||
const COEFF_A: Fq = Fq::ZERO; | ||
|
||
/// COEFF_B = 1 | ||
const COEFF_B: Fq = MontFp!("1"); | ||
|
||
/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y) | ||
const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y); | ||
#[inline(always)] | ||
fn mul_by_a(_elem: Self::BaseField) -> Self::BaseField { | ||
use ark_ff::Zero; | ||
Self::BaseField::zero() | ||
} | ||
} | ||
|
||
/// G1_GENERATOR_X = | ||
/// 127687253511432941835499154999732953539969793860764514205013635996439242747457934431893570832266740963864950713809357287070846939000367049554519743864924323440810949629217677483481194663331926309250818003412838087592587472550707218 | ||
pub const G1_GENERATOR_X: Fq = MontFp!("127687253511432941835499154999732953539969793860764514205013635996439242747457934431893570832266740963864950713809357287070846939000367049554519743864924323440810949629217677483481194663331926309250818003412838087592587472550707218"); | ||
|
||
/// G1_GENERATOR_Y = | ||
/// 415570529523170147223250223671601071129165798689804006717876771297003017718159840368703823786319144396618898691682149260290217115399107531975419658973137909698922937988511368601419289861827304905241655385035120916874417442125721204 | ||
pub const G1_GENERATOR_Y: Fq = MontFp!("415570529523170147223250223671601071129165798689804006717876771297003017718159840368703823786319144396618898691682149260290217115399107531975419658973137909698922937988511368601419289861827304905241655385035120916874417442125721204"); |
Oops, something went wrong.