Skip to content

Commit

Permalink
Replace derivative with educe (#832)
Browse files Browse the repository at this point in the history
* replace derivative with educe

* fmt ff/src/fields/models/fp/mod.rs

---------

Co-authored-by: Marcin <[email protected]>
Co-authored-by: Pratyush Mishra <[email protected]>
  • Loading branch information
3 people authored Jun 19, 2024
1 parent ed7a187 commit 85d17f5
Show file tree
Hide file tree
Showing 30 changed files with 94 additions and 244 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ num-bigint = { version = "0.4", default-features = false }
num-integer = { version = "0.1", default-features = false }

criterion = "0.5.0"
derivative = "2"
educe = "0.5.0"
digest = { version = "0.10", default-features = false }
hashbrown = { version = "0.14", default-features = false, features = ["inline-more", "allocator-api2"] }
hex = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion ec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ark-std.workspace = true
ark-serialize.workspace = true
ark-ff.workspace = true
ark-poly.workspace = true
derivative = { workspace = true, features = ["use_core"] }
educe.workspace = true
num-bigint.workspace = true
num-traits.workspace = true
num-integer.workspace = true
Expand Down
11 changes: 3 additions & 8 deletions ec/src/models/bls12/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ use crate::{
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;

pub type G1Affine<P> = Affine<<P as Bls12Config>::G1Config>;
pub type G1Projective<P> = Projective<<P as Bls12Config>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: Bls12Config"),
Debug(bound = "P: Bls12Config"),
PartialEq(bound = "P: Bls12Config"),
Eq(bound = "P: Bls12Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct G1Prepared<P: Bls12Config>(pub G1Affine<P>);

impl<P: Bls12Config> From<G1Affine<P>> for G1Prepared<P> {
Expand Down
19 changes: 5 additions & 14 deletions ec/src/models/bls12/g2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_ff::{AdditiveGroup, BitIteratorBE, Field, Fp2};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{vec::*, One};
use derivative::Derivative;
use educe::Educe;

use crate::{
bls12::{Bls12Config, TwistType},
Expand All @@ -13,13 +13,8 @@ use crate::{
pub type G2Affine<P> = Affine<<P as Bls12Config>::G2Config>;
pub type G2Projective<P> = Projective<<P as Bls12Config>::G2Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: Bls12Config"),
Debug(bound = "P: Bls12Config"),
PartialEq(bound = "P: Bls12Config"),
Eq(bound = "P: Bls12Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct G2Prepared<P: Bls12Config> {
/// Stores the coefficients of the line evaluations as calculated in
/// <https://eprint.iacr.org/2013/722.pdf>
Expand All @@ -33,12 +28,8 @@ pub type EllCoeff<P> = (
Fp2<<P as Bls12Config>::Fp2Config>,
);

#[derive(Derivative)]
#[derivative(
Clone(bound = "P: Bls12Config"),
Copy(bound = "P: Bls12Config"),
Debug(bound = "P: Bls12Config")
)]
#[derive(Educe)]
#[educe(Clone, Copy, Debug)]
pub struct G2HomProjective<P: Bls12Config> {
x: Fp2<P::Fp2Config>,
y: Fp2<P::Fp2Config>,
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/bls12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ark_ff::{
BitIteratorBE, CyclotomicMultSubgroup, Field, PrimeField,
};
use ark_std::{cfg_chunks_mut, marker::PhantomData, vec::*};
use derivative::Derivative;
use educe::Educe;
use num_traits::{One, Zero};

#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -165,8 +165,8 @@ pub use self::{
g2::{G2Affine, G2Prepared, G2Projective},
};

#[derive(Derivative)]
#[derivative(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[derive(Educe)]
#[educe(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct Bls12<P: Bls12Config>(PhantomData<fn() -> P>);

impl<P: Bls12Config> Bls12<P> {
Expand Down
11 changes: 3 additions & 8 deletions ec/src/models/bn/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ use crate::{
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;

pub type G1Affine<P> = Affine<<P as BnConfig>::G1Config>;
pub type G1Projective<P> = Projective<<P as BnConfig>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BnConfig"),
Debug(bound = "P: BnConfig"),
PartialEq(bound = "P: BnConfig"),
Eq(bound = "P: BnConfig")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct G1Prepared<P: BnConfig>(pub G1Affine<P>);

impl<P: BnConfig> From<G1Affine<P>> for G1Prepared<P> {
Expand Down
19 changes: 5 additions & 14 deletions ec/src/models/bn/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ark_ff::{
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;
use num_traits::One;

use crate::{
Expand All @@ -17,13 +17,8 @@ use crate::{
pub type G2Affine<P> = Affine<<P as BnConfig>::G2Config>;
pub type G2Projective<P> = Projective<<P as BnConfig>::G2Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BnConfig"),
Debug(bound = "P: BnConfig"),
PartialEq(bound = "P: BnConfig"),
Eq(bound = "P: BnConfig")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct G2Prepared<P: BnConfig> {
/// Stores the coefficients of the line evaluations as calculated in
/// <https://eprint.iacr.org/2013/722.pdf>
Expand All @@ -37,12 +32,8 @@ pub type EllCoeff<P> = (
Fp2<<P as BnConfig>::Fp2Config>,
);

#[derive(Derivative)]
#[derivative(
Clone(bound = "P: BnConfig"),
Copy(bound = "P: BnConfig"),
Debug(bound = "P: BnConfig")
)]
#[derive(Educe)]
#[educe(Clone, Copy, Debug)]
pub struct G2HomProjective<P: BnConfig> {
x: Fp2<P::Fp2Config>,
y: Fp2<P::Fp2Config>,
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/bn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ark_ff::{
CyclotomicMultSubgroup,
};
use ark_std::{cfg_chunks_mut, marker::PhantomData, vec::*};
use derivative::Derivative;
use educe::Educe;
use itertools::Itertools;
use num_traits::One;

Expand Down Expand Up @@ -175,8 +175,8 @@ pub use self::{
g2::{G2Affine, G2Prepared, G2Projective},
};

#[derive(Derivative)]
#[derivative(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[derive(Educe)]
#[educe(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct Bn<P: BnConfig>(PhantomData<fn() -> P>);

impl<P: BnConfig> Bn<P> {
Expand Down
12 changes: 3 additions & 9 deletions ec/src/models/bw6/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ use crate::{
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;

pub type G1Affine<P> = Affine<<P as BW6Config>::G1Config>;
pub type G1Projective<P> = Projective<<P as BW6Config>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Copy(bound = "P: BW6Config"),
Clone(bound = "P: BW6Config"),
Debug(bound = "P: BW6Config"),
PartialEq(bound = "P: BW6Config"),
Eq(bound = "P: BW6Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Copy, Clone, Debug, PartialEq, Eq)]
pub struct G1Prepared<P: BW6Config>(pub G1Affine<P>);

impl<P: BW6Config> From<G1Affine<P>> for G1Prepared<P> {
Expand Down
19 changes: 5 additions & 14 deletions ec/src/models/bw6/g2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_ff::{AdditiveGroup, BitIteratorBE, Field};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;
use num_traits::One;

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

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BW6Config"),
Debug(bound = "P: BW6Config"),
PartialEq(bound = "P: BW6Config"),
Eq(bound = "P: BW6Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct G2Prepared<P: BW6Config> {
/// Stores the coefficients of the line evaluations as calculated in
/// <https://eprint.iacr.org/2013/722.pdf>
Expand All @@ -29,12 +24,8 @@ pub struct G2Prepared<P: BW6Config> {
pub infinity: bool,
}

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: BW6Config"),
Copy(bound = "P: BW6Config"),
Debug(bound = "P: BW6Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Copy, Debug)]
pub struct G2HomProjective<P: BW6Config> {
x: P::Fp,
y: P::Fp,
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/bw6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ark_ff::{
BitIteratorBE, CyclotomicMultSubgroup,
};
use ark_std::cfg_chunks_mut;
use derivative::Derivative;
use educe::Educe;
use itertools::Itertools;
use num_traits::One;

Expand Down Expand Up @@ -185,8 +185,8 @@ pub use self::{
g2::{G2Affine, G2Prepared, G2Projective},
};

#[derive(Derivative)]
#[derivative(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[derive(Educe)]
#[educe(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct BW6<P: BW6Config>(PhantomData<fn() -> P>);

impl<P: BW6Config> BW6<P> {
Expand Down
12 changes: 3 additions & 9 deletions ec/src/models/mnt4/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ use crate::{
use ark_ff::Fp2;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;

pub type G1Affine<P> = Affine<<P as MNT4Config>::G1Config>;
pub type G1Projective<P> = Projective<<P as MNT4Config>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Copy(bound = "P: MNT4Config"),
Clone(bound = "P: MNT4Config"),
Debug(bound = "P: MNT4Config"),
PartialEq(bound = "P: MNT4Config"),
Eq(bound = "P: MNT4Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Copy, Clone, Debug, PartialEq, Eq)]
pub struct G1Prepared<P: MNT4Config> {
pub x: P::Fp,
pub y: P::Fp,
Expand Down
29 changes: 7 additions & 22 deletions ec/src/models/mnt4/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ use crate::{
use ark_ff::fields::{Field, Fp2};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{vec, vec::*};
use derivative::Derivative;
use educe::Educe;
use num_traits::One;

pub type G2Affine<P> = Affine<<P as MNT4Config>::G2Config>;
pub type G2Projective<P> = Projective<<P as MNT4Config>::G2Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT4Config"),
Debug(bound = "P: MNT4Config"),
PartialEq(bound = "P: MNT4Config"),
Eq(bound = "P: MNT4Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct G2Prepared<P: MNT4Config> {
pub x: Fp2<P::Fp2Config>,
pub y: Fp2<P::Fp2Config>,
Expand Down Expand Up @@ -117,27 +112,17 @@ pub struct G2ProjectiveExtended<P: MNT4Config> {
pub t: Fp2<P::Fp2Config>,
}

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT4Config"),
Debug(bound = "P: MNT4Config"),
PartialEq(bound = "P: MNT4Config"),
Eq(bound = "P: MNT4Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct AteDoubleCoefficients<P: MNT4Config> {
pub c_h: Fp2<P::Fp2Config>,
pub c_4c: Fp2<P::Fp2Config>,
pub c_j: Fp2<P::Fp2Config>,
pub c_l: Fp2<P::Fp2Config>,
}

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Clone(bound = "P: MNT4Config"),
Debug(bound = "P: MNT4Config"),
PartialEq(bound = "P: MNT4Config"),
Eq(bound = "P: MNT4Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Clone, Debug, PartialEq, Eq)]
pub struct AteAdditionCoefficients<P: MNT4Config> {
pub c_l1: Fp2<P::Fp2Config>,
pub c_rz: Fp2<P::Fp2Config>,
Expand Down
6 changes: 3 additions & 3 deletions ec/src/models/mnt4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ark_ff::{
fp4::{Fp4, Fp4Config},
AdditiveGroup, CyclotomicMultSubgroup, Field, PrimeField,
};
use derivative::Derivative;
use educe::Educe;
use itertools::Itertools;
use num_traits::{One, Zero};

Expand Down Expand Up @@ -74,8 +74,8 @@ pub trait MNT4Config: 'static + Sized {
}
}

#[derive(Derivative)]
#[derivative(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[derive(Educe)]
#[educe(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct MNT4<P: MNT4Config>(PhantomData<fn() -> P>);

impl<P: MNT4Config> MNT4<P> {
Expand Down
12 changes: 3 additions & 9 deletions ec/src/models/mnt6/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ use crate::{
use ark_ff::Fp3;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::*;
use derivative::Derivative;
use educe::Educe;

pub type G1Affine<P> = Affine<<P as MNT6Config>::G1Config>;
pub type G1Projective<P> = Projective<<P as MNT6Config>::G1Config>;

#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(
Copy(bound = "P: MNT6Config"),
Clone(bound = "P: MNT6Config"),
Debug(bound = "P: MNT6Config"),
PartialEq(bound = "P: MNT6Config"),
Eq(bound = "P: MNT6Config")
)]
#[derive(Educe, CanonicalSerialize, CanonicalDeserialize)]
#[educe(Copy, Clone, Debug, PartialEq, Eq)]
pub struct G1Prepared<P: MNT6Config> {
pub x: P::Fp,
pub y: P::Fp,
Expand Down
Loading

0 comments on commit 85d17f5

Please sign in to comment.