Skip to content

Commit

Permalink
Add canonical serialization for G2Prepared (#462)
Browse files Browse the repository at this point in the history
Co-authored-by: onewayfunc <onewayfunc@gmail.com>
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
  • Loading branch information
3 people authored Sep 6, 2022
1 parent 7a4ccd6 commit 602664b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 21 deletions.
4 changes: 3 additions & 1 deletion ec/src/models/bls12/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use crate::{
short_weierstrass::{Affine, Projective},
AffineRepr, CurveGroup,
};
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as Bls12Parameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as Bls12Parameters>::G1Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: Bls12Parameters"),
Debug(bound = "P: Bls12Parameters"),
Expand Down
3 changes: 2 additions & 1 deletion ec/src/models/bls12/g2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ark_ff::fields::{BitIteratorBE, Field, Fp2};
use ark_serialize::*;
use ark_std::{vec::Vec, One};

use crate::{
Expand All @@ -11,7 +12,7 @@ use crate::{
pub type G2Affine<P> = Affine<<P as Bls12Parameters>::G2Parameters>;
pub type G2Projective<P> = Projective<<P as Bls12Parameters>::G2Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: Bls12Parameters"),
Debug(bound = "P: Bls12Parameters"),
Expand Down
4 changes: 3 additions & 1 deletion ec/src/models/bn/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use crate::{
short_weierstrass::{Affine, Projective},
AffineRepr, CurveGroup,
};
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as BnParameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as BnParameters>::G1Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BnParameters"),
Debug(bound = "P: BnParameters"),
Expand Down
7 changes: 3 additions & 4 deletions ec/src/models/bn/g2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ark_std::vec::Vec;

use ark_ff::fields::{Field, Fp2};

use ark_serialize::*;
use ark_std::vec::Vec;
use num_traits::One;

use crate::{
Expand All @@ -14,7 +13,7 @@ use crate::{
pub type G2Affine<P> = Affine<<P as BnParameters>::G2Parameters>;
pub type G2Projective<P> = Projective<<P as BnParameters>::G2Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BnParameters"),
Debug(bound = "P: BnParameters"),
Expand Down
4 changes: 3 additions & 1 deletion ec/src/models/bw6/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use crate::{
short_weierstrass::{Affine, Projective},
AffineRepr, CurveGroup,
};
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as BW6Parameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as BW6Parameters>::G1Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Copy(bound = "P: BW6Parameters"),
Clone(bound = "P: BW6Parameters"),
Expand Down
9 changes: 4 additions & 5 deletions ec/src/models/bw6/g2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ark_std::vec::Vec;

use ark_ff::fields::{BitIteratorBE, Field};

use ark_serialize::*;
use ark_std::vec::Vec;
use num_traits::One;

use crate::{
Expand All @@ -14,7 +13,7 @@ use crate::{
pub type G2Affine<P> = Affine<<P as BW6Parameters>::G2Parameters>;
pub type G2Projective<P> = Projective<<P as BW6Parameters>::G2Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BW6Parameters"),
Debug(bound = "P: BW6Parameters"),
Expand All @@ -29,7 +28,7 @@ pub struct G2Prepared<P: BW6Parameters> {
pub infinity: bool,
}

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BW6Parameters"),
Copy(bound = "P: BW6Parameters"),
Expand Down
4 changes: 3 additions & 1 deletion ec/src/models/mnt4/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use crate::{
AffineRepr, CurveGroup,
};
use ark_ff::Fp2;
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as MNT4Parameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as MNT4Parameters>::G1Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Copy(bound = "P: MNT4Parameters"),
Clone(bound = "P: MNT4Parameters"),
Expand Down
7 changes: 4 additions & 3 deletions ec/src/models/mnt4/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use crate::{
AffineRepr, CurveGroup,
};
use ark_ff::fields::{Field, Fp2};
use ark_serialize::*;
use ark_std::vec::Vec;
use num_traits::One;

pub type G2Affine<P> = Affine<<P as MNT4Parameters>::G2Parameters>;
pub type G2Projective<P> = Projective<<P as MNT4Parameters>::G2Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT4Parameters"),
Debug(bound = "P: MNT4Parameters"),
Expand Down Expand Up @@ -115,7 +116,7 @@ pub(super) struct G2ProjectiveExtended<P: MNT4Parameters> {
pub(crate) t: Fp2<P::Fp2Config>,
}

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT4Parameters"),
Debug(bound = "P: MNT4Parameters"),
Expand All @@ -129,7 +130,7 @@ pub struct AteDoubleCoefficients<P: MNT4Parameters> {
pub c_l: Fp2<P::Fp2Config>,
}

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT4Parameters"),
Debug(bound = "P: MNT4Parameters"),
Expand Down
4 changes: 3 additions & 1 deletion ec/src/models/mnt6/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use crate::{
AffineRepr, CurveGroup,
};
use ark_ff::Fp3;
use ark_serialize::*;
use ark_std::vec::Vec;

pub type G1Affine<P> = Affine<<P as MNT6Parameters>::G1Parameters>;
pub type G1Projective<P> = Projective<<P as MNT6Parameters>::G1Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Copy(bound = "P: MNT6Parameters"),
Clone(bound = "P: MNT6Parameters"),
Expand Down
7 changes: 4 additions & 3 deletions ec/src/models/mnt6/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ use crate::{
AffineRepr, CurveGroup,
};
use ark_ff::fields::{Field, Fp3};
use ark_serialize::*;
use ark_std::vec::Vec;
use num_traits::One;

pub type G2Affine<P> = Affine<<P as MNT6Parameters>::G2Parameters>;
pub type G2Projective<P> = Projective<<P as MNT6Parameters>::G2Parameters>;

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT6Parameters"),
Debug(bound = "P: MNT6Parameters"),
Expand Down Expand Up @@ -112,7 +113,7 @@ pub(super) struct G2ProjectiveExtended<P: MNT6Parameters> {
pub(crate) t: Fp3<P::Fp3Config>,
}

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT6Parameters"),
Debug(bound = "P: MNT6Parameters"),
Expand All @@ -126,7 +127,7 @@ pub struct AteDoubleCoefficients<P: MNT6Parameters> {
pub c_l: Fp3<P::Fp3Config>,
}

#[derive(Derivative)]
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT6Parameters"),
Debug(bound = "P: MNT6Parameters"),
Expand Down
4 changes: 4 additions & 0 deletions ec/src/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub trait Pairing: Sized + 'static + Copy + Debug + Sync + Send + Eq {
+ Send
+ Sync
+ Debug
+ CanonicalSerialize
+ CanonicalDeserialize
+ for<'a> From<&'a Self::G1>
+ for<'a> From<&'a Self::G1Affine>
+ From<Self::G1>
Expand All @@ -66,6 +68,8 @@ pub trait Pairing: Sized + 'static + Copy + Debug + Sync + Send + Eq {
+ Send
+ Sync
+ Debug
+ CanonicalSerialize
+ CanonicalDeserialize
+ for<'a> From<&'a Self::G2>
+ for<'a> From<&'a Self::G2Affine>
+ From<Self::G2>
Expand Down

0 comments on commit 602664b

Please sign in to comment.