Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct isogeny map using new function #529

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
116 changes: 113 additions & 3 deletions ec/src/hashing/curve_maps/wb/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::marker::PhantomData;
use core::{default, marker::PhantomData};

use crate::{models::short_weierstrass::SWCurveConfig, CurveConfig};
use ark_ff::batch_inversion;
Expand Down Expand Up @@ -32,18 +32,48 @@ pub struct IsogenyMap<
DOMAIN: SWCurveConfig,
CODOMAIN: SWCurveConfig<BaseField = BaseField<DOMAIN>>,
> {
pub x_map_numerator: &'a [BaseField<DOMAIN>],
pub x_map_numerator: &'a [BaseField<CODOMAIN>],
pub x_map_denominator: &'a [BaseField<CODOMAIN>],

pub y_map_numerator: &'a [BaseField<DOMAIN>],
pub y_map_numerator: &'a [BaseField<CODOMAIN>],
pub y_map_denominator: &'a [BaseField<CODOMAIN>],
_phantom_domain: PhantomData<DOMAIN>,
}

// Pratyush suggestion
// impl</* bounds */> IsogenyMap<'a, DOMAIN, CODOMAIN> {
// const fn new(
// x_numerator: &'a [BaseField<CODOMAIN>],
// x_denominator: &'a [BaseField<CODOMAIN>],
// ...
// ) → Self {
// Self {
// x_numerator,
// x_denominator,
// ...
// }
// }
// }
impl<'a, DOMAIN, CODOMAIN> IsogenyMap<'a, DOMAIN, CODOMAIN>
where
DOMAIN: SWCurveConfig,
CODOMAIN: SWCurveConfig<BaseField = BaseField<DOMAIN>>,
{
pub const fn new(
x_map_numerator: &'a [BaseField<CODOMAIN>],
x_map_denominator: &'a [BaseField<CODOMAIN>],
y_map_numerator: &'a [BaseField<CODOMAIN>],
y_map_denominator: &'a [BaseField<CODOMAIN>],
) -> Self {
Self {
x_map_numerator,
x_map_denominator,
y_map_numerator,
y_map_denominator,
_phantom_domain: PhantomData::<DOMAIN>,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also limit this to 'static lifetimes. That might help with the "temporary dropped while borrowed" issue.

Copy link
Contributor Author

@drskalman drskalman Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean to hard code static life time? I think I did that and the error still persists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it too, couldn't find a way around it...


fn apply(&self, domain_point: Affine<DOMAIN>) -> Result<Affine<CODOMAIN>, HashToCurveError> {
match domain_point.xy() {
Some((x, y)) => {
Expand Down Expand Up @@ -221,6 +251,86 @@ mod test {
/// - 43*x^5*y - 60*x^4*y - 18*x^3*y + 30*x^2*y - 57*x*y - 34*y)/(x^18 + 44*x^17
/// - 63*x^16 + 52*x^15 + 3*x^14 + 38*x^13 - 30*x^12 + 11*x^11 - 42*x^10 - 13*x^9
/// - 46*x^8 - 61*x^7 - 16*x^6 - 55*x^5 + 18*x^4 + 23*x^3 - 24*x^2 - 18*x + 32)
const ISOGENY_MAP_TESTWBF127_NEW: IsogenyMap<
'static,
TestSWU127MapToIsogenousCurveParams,
TestWBF127MapToCurveParams,
> = IsogenyMap::<'static, TestSWU127MapToIsogenousCurveParams, TestWBF127MapToCurveParams>::new(
&[
MontFp!("4"),
MontFp!("63"),
MontFp!("23"),
MontFp!("39"),
MontFp!("-14"),
MontFp!("23"),
MontFp!("-32"),
MontFp!("32"),
MontFp!("-13"),
MontFp!("40"),
MontFp!("34"),
MontFp!("10"),
MontFp!("-21"),
MontFp!("-57"),
],
&[
MontFp!("2"),
MontFp!("31"),
MontFp!("-10"),
MontFp!("-20"),
MontFp!("63"),
MontFp!("-44"),
MontFp!("34"),
MontFp!("30"),
MontFp!("-30"),
MontFp!("-33"),
MontFp!("11"),
MontFp!("-13"),
MontFp!("1"),
],
&[
MontFp!("-34"),
MontFp!("-57"),
MontFp!("30"),
MontFp!("-18"),
MontFp!("-60"),
MontFp!("-43"),
MontFp!("-63"),
MontFp!("-18"),
MontFp!("-49"),
MontFp!("36"),
MontFp!("12"),
MontFp!("62"),
MontFp!("5"),
MontFp!("6"),
MontFp!("-7"),
MontFp!("48"),
MontFp!("41"),
MontFp!("59"),
MontFp!("10"),
],
&[
MontFp!("32"),
MontFp!("-18"),
MontFp!("-24"),
MontFp!("23"),
MontFp!("18"),
MontFp!("-55"),
MontFp!("-16"),
MontFp!("-61"),
MontFp!("-46"),
MontFp!("-13"),
MontFp!("-42"),
MontFp!("11"),
MontFp!("-30"),
MontFp!("38"),
MontFp!("3"),
MontFp!("52"),
MontFp!("-63"),
MontFp!("44"),
MontFp!("1"),
],
);

const ISOGENY_MAP_TESTWBF127: IsogenyMap<
'_,
TestSWU127MapToIsogenousCurveParams,
Expand Down
12 changes: 6 additions & 6 deletions test-curves/src/bls12_381/g1_swu_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl SWUParams for SwuIsoParameters {
const ZETA: Fq = MontFp!("11");
}

pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoParameters, g1::Parameters, > = IsogenyMap {
x_map_numerator : &[
pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoParameters, g1::Parameters, > = IsogenyMap::new(
&[
MontFp!("2712959285290305970661081772124144179193819192423276218370281158706191519995889425075952244140278856085036081760695"),
MontFp!("3564859427549639835253027846704205725951033235539816243131874237388832081954622352624080767121604606753339903542203"),
MontFp!("2051387046688339481714726479723076305756384619135044672831882917686431912682625619320120082313093891743187631791280"),
Expand All @@ -74,7 +74,7 @@ pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoParameters, g1::Parameters, >
MontFp!("1058488477413994682556770863004536636444795456512795473806825292198091015005841418695586811009326456605062948114985"),
],

x_map_denominator : &[
&[
MontFp!("1353092447850172218905095041059784486169131709710991428415161466575141675351394082965234118340787683181925558786844"),
MontFp!("2822220997908397120956501031591772354860004534930174057793539372552395729721474912921980407622851861692773516917759"),
MontFp!("1717937747208385987946072944131378949849282930538642983149296304709633281382731764122371874602115081850953846504985"),
Expand All @@ -88,7 +88,7 @@ pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoParameters, g1::Parameters, >
MontFp!("1"),
],

y_map_numerator : &[
&[
MontFp!("1393399195776646641963150658816615410692049723305861307490980409834842911816308830479576739332720113414154429643571"),
MontFp!("2968610969752762946134106091152102846225411740689724909058016729455736597929366401532929068084731548131227395540630"),
MontFp!("122933100683284845219599644396874530871261396084070222155796123161881094323788483360414289333111221370374027338230"),
Expand All @@ -107,7 +107,7 @@ pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoParameters, g1::Parameters, >
MontFp!("3370924952219000111210625390420697640496067348723987858345031683392215988129398381698161406651860675722373763741188"),
],

y_map_denominator : &[
&[
MontFp!("3396434800020507717552209507749485772788165484415495716688989613875369612529138640646200921379825018840894888371137"),
MontFp!("3907278185868397906991868466757978732688957419873771881240086730384895060595583602347317992689443299391009456758845"),
MontFp!("854914566454823955479427412036002165304466268547334760894270240966182605542146252771872707010378658178126128834546"),
Expand All @@ -125,7 +125,7 @@ pub const ISOGENY_MAP_TO_G1 : IsogenyMap<'_, SwuIsoParameters, g1::Parameters, >
MontFp!("2164195715141237148945939585099633032390257748382945597506236650132835917087090097395995817229686247227784224263055"),
MontFp!("1"),
],
};
);

#[cfg(test)]
mod test {
Expand Down
12 changes: 6 additions & 6 deletions test-curves/src/bls12_381/g2_swu_iso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl SWUParams for SwuIsoParameters {
const ZETA: Fq2 = Fq2::new(MontFp!("-2"), MontFp!("-1"));
}

pub const ISOGENY_MAP_TO_G2 : IsogenyMap<'_, SwuIsoParameters, g2::Parameters> = IsogenyMap {
x_map_numerator: &[
pub const ISOGENY_MAP_TO_G2 : IsogenyMap<'_, SwuIsoParameters, g2::Parameters> = IsogenyMap::new (
&[
Fq2::new(
MontFp!("889424345604814976315064405719089812568196182208668418962679585805340366775741747653930584250892369786198727235542"),
MontFp!("889424345604814976315064405719089812568196182208668418962679585805340366775741747653930584250892369786198727235542")),
Expand All @@ -92,7 +92,7 @@ pub const ISOGENY_MAP_TO_G2 : IsogenyMap<'_, SwuIsoParameters, g2::Parameters>
MontFp!("0")),
],

x_map_denominator: &[
&[
Fq2::new(
MontFp!("0"),
MontFp!("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559715")),
Expand All @@ -104,7 +104,7 @@ pub const ISOGENY_MAP_TO_G2 : IsogenyMap<'_, SwuIsoParameters, g2::Parameters>
MontFp!("0")),
],

y_map_numerator: &[
&[
Fq2::new(
MontFp!("3261222600550988246488569487636662646083386001431784202863158481286248011511053074731078808919938689216061999863558"),
MontFp!("3261222600550988246488569487636662646083386001431784202863158481286248011511053074731078808919938689216061999863558")),
Expand All @@ -119,7 +119,7 @@ pub const ISOGENY_MAP_TO_G2 : IsogenyMap<'_, SwuIsoParameters, g2::Parameters>
MontFp!("0")),
],

y_map_denominator: &[
&[
Fq2::new(
MontFp!("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559355"),
MontFp!("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559355")),
Expand All @@ -133,7 +133,7 @@ pub const ISOGENY_MAP_TO_G2 : IsogenyMap<'_, SwuIsoParameters, g2::Parameters>
MontFp!("1"),
MontFp!("0")),
],
};
);

#[cfg(test)]
mod test {
Expand Down