Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Implement WB hash2curve for BLS12-377 and BLS12-381 #138

Merged
merged 64 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
533d160
include the coefficients of bls12-377 G1 and G2 isogenies for wb hash…
drskalman Oct 14, 2021
3d1a539
replacing the ark-ec dependency to w3f/arkworks-algebra
drskalman Oct 19, 2021
da53a6b
added parameters for isogenous curve to bls12-377 g1 curve for swu map
drskalman Oct 20, 2021
302975e
fix dependency inconsistency problem
drskalman Oct 20, 2021
711f426
implement WBParams and its isogenous curve for BLS12-377 G1
drskalman Oct 20, 2021
d8a5e79
implement the SWUParameters for isogenous curve to BLS12-377 g2 curve.
drskalman Oct 20, 2021
95c4cb2
implement WBParams for BLS12-377 G2 curve
drskalman Oct 20, 2021
f2804a8
replacing const generic arrays with const slice in g1 and g2 iso coef…
drskalman Oct 25, 2021
9c1d38d
- Implement WB hash to curve for BLS12-381 G1
drskalman Oct 26, 2021
2b52206
Implement WB hash to curve for BLS12-381 G2
drskalman Oct 26, 2021
2e57d74
- fix the bug with base order for field_new for Fq2
drskalman Oct 28, 2021
a22aa14
fix bls12-377 wb hash to curve isogeny coeffcients
drskalman Oct 28, 2021
88016a9
fixed sage code for generating the isogeny coefficients
drskalman Nov 29, 2021
911cdb8
Merge branch 'master' into skalman-bls12-377-wb-hash2curve
drskalman Nov 29, 2021
c51717e
Merge remote-tracking branch 'origin/master' into skalman-bls12-377-w…
drskalman Dec 8, 2021
26c3d50
use patch.crates-io hack to resolve dependancy issues on w3f fork
drskalman Dec 8, 2021
c40d426
Rename `Parameters` to `Config` for all fields
Pratyush Feb 6, 2022
62e98b7
Rename `field_new` to `MontFp`
Pratyush Feb 6, 2022
e8d3b36
Rename `field_new` to `QuadExt` and `CubicExt`
Pratyush Feb 6, 2022
2cc194e
- Merge remote-tracking branch 'upstream/upgrade-ff' into skalman-bls…
drskalman Mar 3, 2022
181f974
Refactor bls12_381 crate based on update-ff branch. Close #9
drskalman Mar 8, 2022
4ec6ca4
Merge branch 'master' into skalman-bls12-377-wb-hash2curve
drskalman Oct 5, 2022
5c0780d
adapt bls12 wb hashing to new changes in algebra
drskalman Oct 5, 2022
157e3ec
update bls12-381 dependancies and g1, g2 definition to pass tests
drskalman Oct 5, 2022
7884e6e
adapt bls12-377 hash to curve to algebar updates
drskalman Oct 5, 2022
de51dab
depend on upstream for pull request
drskalman Oct 5, 2022
fc0b092
cargo fmt
drskalman Oct 6, 2022
4555710
- move the isogeny finder script from sage to script folder
drskalman Oct 6, 2022
f7176b2
add unit tests for wb hashing to bls12-377 g1 and g2
drskalman Oct 6, 2022
86ec5aa
- Use IsogenyMap struct to specify WB Isogeny for bls12-381 and bls12…
drskalman Dec 7, 2022
543807c
Merge branch 'master' into skalman-bls12-377-wb-hash2curve
drskalman Dec 7, 2022
72106f7
Bump the Algebra dependencies of bls12_381 and bls12_377 to 0.4.0-alp…
drskalman Dec 7, 2022
624719b
Add h2c tests for BLS12-381 curve
mmagician Dec 12, 2022
fa9a945
Drop alpha sub-version in dependancies because it takes the lastest s…
drskalman Dec 16, 2022
ec2d3dd
Merge pull request #11 from w3f/skalman-bls12-377-wb-hash2curve
drskalman Dec 19, 2022
f5a2135
Merge branch 'master' of https://github.com/arkworks-rs/curves
drskalman Dec 19, 2022
9c315fc
Parameters → Config for bls12-377/381 curves
drskalman Dec 20, 2022
d76be8a
do cargo fmt
drskalman Dec 20, 2022
7d2ef2a
do SwuIsoParameters → SwuIsoConfig for bls12-377/381
drskalman Dec 20, 2022
e5bddd3
Merge branch 'master' into h2c-test-templates
mmagician Dec 22, 2022
fc1c00f
Adapt to new macro
mmagician Dec 22, 2022
87d9db0
Merge branch 'master' into skalman-bls12-377-wb-hash2curve
drskalman Dec 23, 2022
8e3f8b8
Merge branch 'master' into h2c-test-templates
mmagician Dec 30, 2022
1889fff
Merge branch 'h2c-test-templates' into skalman-bls12-377-wb-hash2curve
mmagician Dec 30, 2022
4a9280c
Fix macro invocation
mmagician Dec 30, 2022
7dcf144
curves master should use algebra/r1cs default branch
mmagician Dec 30, 2022
9ecc17f
Merge branch 'h2c-test-templates' into skalman-bls12-377-wb-hash2curve
mmagician Dec 30, 2022
b546710
Add h2c test invocation for bls12-377 curve
mmagician Dec 30, 2022
83c8963
add faster cofactor clearing and tests for g1
mmagician Dec 30, 2022
a00563d
add faster cofactor clearing and tests for g2
mmagician Dec 30, 2022
2dedb93
add test vectors for bls12-377
mmagician Dec 30, 2022
8b9ec01
add h_eff to g2 tests for correctness
mmagician Jan 1, 2023
802b519
improve cofactor tests g2
mmagician Jan 1, 2023
d4586c0
add a test for psi(psi(P)) == psi2(P)
mmagician Jan 1, 2023
652d3ab
fix bls12-377 psi & psi2 computation parameters
mmagician Jan 1, 2023
6fd8c0c
rename const to DOUBLE_P_POWER_ENDOMORPHISM_COEFF_0 and make private
mmagician Jan 1, 2023
082c708
fix clippy warnings in changed code
mmagician Jan 1, 2023
54ba898
Merge branch 'cofactor-clearing-bls12-377' into bls12-h2c
mmagician Jan 1, 2023
ecd61b7
use the same zeta as test suites
mmagician Jan 1, 2023
e414515
update code comments, make methods private
mmagician Jan 1, 2023
c53ff1f
update changelog
mmagician Jan 1, 2023
c363967
- Merge branch 'upstream/master' into skalman-bls12-377-wb-hash2curve
drskalman Jan 9, 2023
07414d7
Merge branch 'skalman-bls12-377-wb-hash2curve' into cofactor-clearing…
drskalman Jan 9, 2023
d7169c9
Merge pull request #13 from mmagician/cofactor-clearing-bls12-377
drskalman Jan 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- [\#103](https://github.com/arkworks-rs/curves/pull/103) Faster cofactor clearing for BLS12-381.
- [\#107](https://github.com/arkworks-rs/curves/pull/107/) Use 2-NAF of `ATE_LOOP_COUNT` to speed up the Miller loop in MNT curves.
- [\#141](https://github.com/arkworks-rs/curves/pull/103) Faster cofactor clearing for BLS12-377.
- [\#138](https://github.com/arkworks-rs/curves/pull/138) Implement WB Hash-to-Curve for bls12-381 and bls12-377

### Bug fixes

Expand Down
1 change: 1 addition & 0 deletions bls12_377/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ark-serialize = { version = "0.4.0-alpha", default-features = false }
ark-algebra-test-templates = { version = "0.4.0-alpha", default-features = false }
ark-algebra-bench-templates = { version = "0.4.0-alpha", default-features = false }
ark-curve-constraint-tests = { path = "../curve-constraint-tests", default-features = false }
sha2 = { version = "0.10", default-features = false }

[features]
default = [ "curve" ]
Expand Down
327 changes: 327 additions & 0 deletions bls12_377/scripts/bls12_isogeny_computer.sage

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions bls12_377/src/curves/g1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use ark_ec::{
bls12,
bls12::Bls12Config,
hashing::curve_maps::wb::{IsogenyMap, WBConfig},
models::{
short_weierstrass::{Affine as SWAffine, SWCurveConfig},
twisted_edwards::{
Expand All @@ -11,8 +13,12 @@ use ark_ec::{
use ark_ff::{Field, MontFp, PrimeField, Zero};
use ark_std::{ops::Neg, One};

use super::g1_swu_iso::{SwuIsoConfig, ISOGENY_MAP_TO_G1};
use crate::{Fq, Fr};

pub type G1Affine = bls12::G1Affine<crate::Config>;
pub type G1Projective = bls12::G1Projective<crate::Config>;

#[derive(Clone, Default, PartialEq, Eq)]
pub struct Config;

Expand Down Expand Up @@ -175,6 +181,12 @@ pub const G1_GENERATOR_X: Fq = MontFp!("8193799937315096423993825557346594823998
/// 241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030
pub const G1_GENERATOR_Y: Fq = MontFp!("241266749859715473739788878240585681733927191168601896383759122102112907357779751001206799952863815012735208165030");

impl WBConfig for Config {
type IsogenousCurve = SwuIsoConfig;

const ISOGENY_MAP: IsogenyMap<'static, Self::IsogenousCurve, Self> = ISOGENY_MAP_TO_G1;
}

// The generator for twisted Edward form is the same SW generator converted into
// the normalized TE form (TE2).
//``` sage
Expand Down
107 changes: 107 additions & 0 deletions bls12_377/src/curves/g1_swu_iso.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use ark_ec::{
hashing::curve_maps::{swu::SWUConfig, wb::IsogenyMap},
models::{
short_weierstrass::{Affine, SWCurveConfig},
CurveConfig,
},
};

use ark_ff::MontFp;

use crate::{g1, Fq, Fr};

type G1Affine = Affine<SwuIsoConfig>;

#[derive(Clone, Default, PartialEq, Eq)]
pub struct SwuIsoConfig;

impl CurveConfig for SwuIsoConfig {
type BaseField = Fq;
type ScalarField = Fr;

/// COFACTOR = (x - 1)^2 / 3 = iso_G1.domain().order() /
/// 8444461749428370424248824938781546531375899335154063827935233455917409239041
// 30631250834960419227450344600217059328
const COFACTOR: &'static [u64] = &[0x0, 0x170b5d4430000000];

/// COFACTOR_INV = COFACTOR^{-1} mod r
/// = 5285428838741532253824584287042945485047145357130994810877
const COFACTOR_INV: Fr = MontFp!("5285428838741532253824584287042945485047145357130994810877");
}

// sage: iso_G1
// Isogeny of degree 2 from Elliptic Curve defined by y^2 = x^3 +
// 258664426012969092796408009721202742408018065645352501567204841856062976176281513834280849065051431927238430294002*
// x + 22 over Finite Field of size
// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
// to Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field of size
// 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177

impl SWCurveConfig for SwuIsoConfig {
/// COEFF_A
const COEFF_A: Fq = MontFp!("258664426012969092796408009721202742408018065645352501567204841856062976176281513834280849065051431927238430294002");

/// COEFF_B
const COEFF_B: Fq = MontFp!("22");

/// AFFINE_GENERATOR_COEFFS = (G1_GENERATOR_X, G1_GENERATOR_Y)
const GENERATOR: G1Affine = G1Affine::new_unchecked(G1_GENERATOR_X, G1_GENERATOR_Y);
}

// sage: G1_gen = iso_G1.domain().random_point()
// sage: G1_gen = 30631250834960419227450344600217059328* G1_gen
// sage: G1_gen.order() ==
// 8444461749428370424248824938781546531375899335154063827935233455917409239041
// True
// sage: G1_gen
// (183898640136580512316530045470998831691790391453237259434516336279447756609241220664846162561503820562316877867830 : 69018534046895515891776145953191511526693172354818719412306559690461416836925400134233128432719372819569406562974 : 1)
/// G1_GENERATOR_X =
/// 183898640136580512316530045470998831691790391453237259434516336279447756609241220664846162561503820562316877867830
pub const G1_GENERATOR_X: Fq = MontFp!("183898640136580512316530045470998831691790391453237259434516336279447756609241220664846162561503820562316877867830");

/// G1_GENERATOR_Y =
/// 69018534046895515891776145953191511526693172354818719412306559690461416836925400134233128432719372819569406562974
pub const G1_GENERATOR_Y: Fq = MontFp!("69018534046895515891776145953191511526693172354818719412306559690461416836925400134233128432719372819569406562974");

impl SWUConfig for SwuIsoConfig {
const ZETA: Fq = MontFp!("-11"); // arbitatry primitive root of unity (element)
}

pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoConfig, g1::Config, > = IsogenyMap {
x_map_numerator : &[
MontFp!("193998319509726820447277314072485610595876362210707887456279225959507476652652651634192264150953923683470146535424"),
MontFp!("40474824132456359704279181570318738632422647360355249739068643631356267969150730939906729705473"),
MontFp!("193998319509726820507989550271170150152295134566185995404913197000040351261255617081226666104680020093330241093633"),
],

x_map_denominator : &[
MontFp!("161899296529825438817116726281274954529690589441420998956274574525425071876602923759626918821892"),
MontFp!("1"),
],

y_map_numerator : &[
MontFp!("193998319509726820507989550271170150152295134566185995404913197000040351261255617081226666104680020093330241093631"),
MontFp!("32333053251621136903112182208573040583096119983059602439070460434672245065050016464457115901761911040205276577794"),
MontFp!("129332213006484547066038603046131306324615528732935438218576102373893108782773376834518846023512776472080255287298"),
MontFp!("226331372761347957259321141983031841844344323660550327972398729833380409804798219928097777122126690108885281275905"),
],

y_map_denominator : &[
MontFp!("258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458169"),
MontFp!("971395779178952632902700357687649727178143536648525993737647447152550431259617542557761512931340"),
MontFp!("485697889589476316451350178843824863589071768324262996868823723576275215629808771278880756465676"),
MontFp!("1"),
],
};

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_gen() {
let gen: G1Affine = SwuIsoConfig::GENERATOR;
assert!(gen.is_on_curve());
assert!(gen.is_in_correct_subgroup_assuming_on_curve());
}
}
19 changes: 16 additions & 3 deletions bls12_377/src/curves/g2.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
use ark_ec::{
bls12,
bls12::Bls12Config,
models::{short_weierstrass::SWCurveConfig, CurveConfig},
short_weierstrass::{Affine, Projective},
hashing::curve_maps::wb::{IsogenyMap, WBConfig},
models::CurveConfig,
short_weierstrass::{Affine, Projective, SWCurveConfig},
AffineRepr, CurveGroup, Group,
};

use ark_ff::{Field, MontFp, Zero};
use ark_std::ops::Neg;

use crate::*;

pub type G2Affine = Affine<Config>;
use super::g2_swu_iso::{SwuIsoConfig, ISOGENY_MAP_TO_G2};

pub type G2Affine = bls12::G2Affine<crate::Config>;
pub type G2Projective = bls12::G2Projective<crate::Config>;

#[derive(Clone, Default, PartialEq, Eq)]
pub struct Config;

Expand Down Expand Up @@ -169,6 +176,12 @@ fn double_p_power_endomorphism(p: &Projective<Config>) -> Projective<Config> {
res
}

impl WBConfig for Config {
type IsogenousCurve = SwuIsoConfig;

const ISOGENY_MAP: IsogenyMap<'static, Self::IsogenousCurve, Self> = ISOGENY_MAP_TO_G2;
}

#[cfg(test)]
mod test {

Expand Down
Loading