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

Remove ToBytes and FromBytes #417

Merged
merged 7 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [\#396](https://github.com/arkworks-rs/algebra/pull/396) (`ark-ec`) Remove `mul_bits` feature, and remove default implementations of `mul` and `mul_by_cofactor_to_projective`.
- [\#408](https://github.com/arkworks-rs/algebra/pull/408) (`ark-ff`) Change the output of `Display` formatting for BigInt & Fp from hex to decimal.
- [\#412](https://github.com/arkworks-rs/algebra/pull/412) (`ark-poly`) Rename UV/MVPolynomial to DenseUV/MVPolynomial.
- [\#417](https://github.com/arkworks-rs/algebra/pull/417) (`ark-ff`) Remove `ToBytes` and `FromBytes`.
- [\#425](https://github.com/arkworks-rs/algebra/pull/425) (`ark-ec`) Refactor `VariableBase` struct to `VariableBaseMSM` trait and implement it for `GroupProjective`.

### Features
Expand Down
10 changes: 2 additions & 8 deletions ec/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ use core::{
};
use num_traits::Zero;

use ark_ff::{
bytes::{FromBytes, ToBytes},
fields::PrimeField,
UniformRand,
};
use ark_ff::{fields::PrimeField, UniformRand};

pub trait Group:
ToBytes
+ 'static
+ FromBytes
'static
+ Copy
+ Clone
+ Debug
Expand Down
9 changes: 2 additions & 7 deletions ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ extern crate derivative;
extern crate ark_std;

use ark_ff::{
bytes::{FromBytes, ToBytes},
fields::{Field, PrimeField, SquareRootField},
UniformRand,
};
Expand Down Expand Up @@ -67,7 +66,7 @@ pub trait PairingEngine: Sized + 'static + Copy + Debug + Sync + Send + Eq + Par
+ Into<Self::G1Prepared>;

/// A G1 element that has been preprocessed for use in a pairing.
type G1Prepared: ToBytes + Default + Clone + Send + Sync + Debug + From<Self::G1Affine>;
type G1Prepared: Default + Clone + Send + Sync + Debug + From<Self::G1Affine>;

/// The projective representation of an element in G2.
type G2Projective: ProjectiveCurve<BaseField = Self::Fqe, ScalarField = Self::Fr, Affine = Self::G2Affine>
Expand All @@ -82,7 +81,7 @@ pub trait PairingEngine: Sized + 'static + Copy + Debug + Sync + Send + Eq + Par
+ Into<Self::G2Prepared>;

/// A G2 element that has been preprocessed for use in a pairing.
type G2Prepared: ToBytes + Default + Clone + Send + Sync + Debug + From<Self::G2Affine>;
type G2Prepared: Default + Clone + Send + Sync + Debug + From<Self::G2Affine>;

/// The base field that hosts G1.
type Fq: PrimeField + SquareRootField;
Expand Down Expand Up @@ -131,8 +130,6 @@ pub trait ProjectiveCurve:
Eq
+ 'static
+ Sized
+ ToBytes
+ FromBytes
+ CanonicalSerialize
+ CanonicalDeserialize
+ Copy
Expand Down Expand Up @@ -229,8 +226,6 @@ pub trait AffineCurve:
Eq
+ 'static
+ Sized
+ ToBytes
+ FromBytes
+ CanonicalSerialize
+ CanonicalDeserialize
+ Copy
Expand Down
8 changes: 0 additions & 8 deletions ec/src/models/bls12/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::bytes::ToBytes;
use ark_std::io::{Result as IoResult, Write};
use num_traits::Zero;

pub type G1Affine<P> = GroupAffine<<P as Bls12Parameters>::G1Parameters>;
Expand Down Expand Up @@ -36,9 +34,3 @@ impl<P: Bls12Parameters> Default for G1Prepared<P> {
G1Prepared(G1Affine::<P>::prime_subgroup_generator())
}
}

impl<P: Bls12Parameters> ToBytes for G1Prepared<P> {
fn write<W: Write>(&self, writer: W) -> IoResult<()> {
self.0.write(writer)
}
}
21 changes: 2 additions & 19 deletions ec/src/models/bls12/g2.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use ark_std::{
io::{Result as IoResult, Write},
vec::Vec,
};
use ark_std::vec::Vec;

use ark_ff::{
bytes::ToBytes,
fields::{BitIteratorBE, Field, Fp2},
};
use ark_ff::fields::{BitIteratorBE, Field, Fp2};

use num_traits::{One, Zero};

Expand Down Expand Up @@ -54,17 +48,6 @@ impl<P: Bls12Parameters> Default for G2Prepared<P> {
}
}

impl<P: Bls12Parameters> ToBytes for G2Prepared<P> {
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
for coeff in &self.ell_coeffs {
coeff.0.write(&mut writer)?;
coeff.1.write(&mut writer)?;
coeff.2.write(&mut writer)?;
}
self.infinity.write(writer)
}
}

impl<P: Bls12Parameters> From<G2Affine<P>> for G2Prepared<P> {
fn from(q: G2Affine<P>) -> Self {
let two_inv = P::Fp::one().double().inverse().unwrap();
Expand Down
8 changes: 0 additions & 8 deletions ec/src/models/bn/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::bytes::ToBytes;
use ark_std::io::{Result as IoResult, Write};
use num_traits::Zero;

pub type G1Affine<P> = GroupAffine<<P as BnParameters>::G1Parameters>;
Expand Down Expand Up @@ -36,9 +34,3 @@ impl<P: BnParameters> Default for G1Prepared<P> {
G1Prepared(G1Affine::<P>::prime_subgroup_generator())
}
}

impl<P: BnParameters> ToBytes for G1Prepared<P> {
fn write<W: Write>(&self, writer: W) -> IoResult<()> {
self.0.write(writer)
}
}
21 changes: 2 additions & 19 deletions ec/src/models/bn/g2.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use ark_std::{
io::{Result as IoResult, Write},
vec::Vec,
};
use ark_std::vec::Vec;

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

use num_traits::{One, Zero};

Expand Down Expand Up @@ -54,17 +48,6 @@ impl<P: BnParameters> Default for G2Prepared<P> {
}
}

impl<P: BnParameters> ToBytes for G2Prepared<P> {
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
for coeff in &self.ell_coeffs {
coeff.0.write(&mut writer)?;
coeff.1.write(&mut writer)?;
coeff.2.write(&mut writer)?;
}
self.infinity.write(writer)
}
}

impl<P: BnParameters> From<G2Affine<P>> for G2Prepared<P> {
fn from(q: G2Affine<P>) -> Self {
let two_inv = P::Fp::one().double().inverse().unwrap();
Expand Down
8 changes: 0 additions & 8 deletions ec/src/models/bw6/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::bytes::ToBytes;
use ark_std::io::{Result as IoResult, Write};
use num_traits::Zero;

pub type G1Affine<P> = GroupAffine<<P as BW6Parameters>::G1Parameters>;
Expand Down Expand Up @@ -36,9 +34,3 @@ impl<P: BW6Parameters> Default for G1Prepared<P> {
G1Prepared(G1Affine::<P>::prime_subgroup_generator())
}
}

impl<P: BW6Parameters> ToBytes for G1Prepared<P> {
fn write<W: Write>(&self, writer: W) -> IoResult<()> {
self.0.write(writer)
}
}
26 changes: 2 additions & 24 deletions ec/src/models/bw6/g2.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use ark_std::{
io::{Result as IoResult, Write},
vec::Vec,
};
use ark_std::vec::Vec;

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

use num_traits::{One, Zero};

Expand Down Expand Up @@ -53,22 +47,6 @@ impl<P: BW6Parameters> Default for G2Prepared<P> {
}
}

impl<P: BW6Parameters> ToBytes for G2Prepared<P> {
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
for coeff_1 in &self.ell_coeffs_1 {
coeff_1.0.write(&mut writer)?;
coeff_1.1.write(&mut writer)?;
coeff_1.2.write(&mut writer)?;
}
for coeff_2 in &self.ell_coeffs_2 {
coeff_2.0.write(&mut writer)?;
coeff_2.1.write(&mut writer)?;
coeff_2.2.write(&mut writer)?;
}
self.infinity.write(writer)
}
}

impl<P: BW6Parameters> From<G2Affine<P>> for G2Prepared<P> {
fn from(q: G2Affine<P>) -> Self {
if q.is_zero() {
Expand Down
12 changes: 1 addition & 11 deletions ec/src/models/mnt4/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::{bytes::ToBytes, Fp2};
use ark_std::io::{Result as IoResult, Write};
use ark_ff::Fp2;

pub type G1Affine<P> = GroupAffine<<P as MNT4Parameters>::G1Parameters>;
pub type G1Projective<P> = GroupProjective<<P as MNT4Parameters>::G1Parameters>;
Expand Down Expand Up @@ -46,12 +45,3 @@ impl<P: MNT4Parameters> Default for G1Prepared<P> {
Self::from(G1Affine::<P>::prime_subgroup_generator())
}
}

impl<P: MNT4Parameters> ToBytes for G1Prepared<P> {
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
self.x.write(&mut writer)?;
self.y.write(&mut writer)?;
self.x_twist.write(&mut writer)?;
self.y_twist.write(&mut writer)
}
}
16 changes: 2 additions & 14 deletions ec/src/models/mnt4/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::{
bytes::ToBytes,
fields::{Field, Fp2},
};
use ark_std::{
io::{Result as IoResult, Write},
vec::Vec,
};
use ark_ff::fields::{Field, Fp2};
use ark_std::vec::Vec;
use num_traits::One;

pub type G2Affine<P> = GroupAffine<<P as MNT4Parameters>::G2Parameters>;
Expand Down Expand Up @@ -39,12 +33,6 @@ impl<P: MNT4Parameters> Default for G2Prepared<P> {
}
}

impl<P: MNT4Parameters> ToBytes for G2Prepared<P> {
fn write<W: Write>(&self, _writer: W) -> IoResult<()> {
unimplemented!()
}
}

impl<P: MNT4Parameters> From<G2Affine<P>> for G2Prepared<P> {
fn from(g2: G2Affine<P>) -> Self {
let twist_inv = P::TWIST.inverse().unwrap();
Expand Down
12 changes: 1 addition & 11 deletions ec/src/models/mnt6/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::{bytes::ToBytes, Fp3};
use ark_std::io::{Result as IoResult, Write};
use ark_ff::Fp3;

pub type G1Affine<P> = GroupAffine<<P as MNT6Parameters>::G1Parameters>;
pub type G1Projective<P> = GroupProjective<<P as MNT6Parameters>::G1Parameters>;
Expand Down Expand Up @@ -46,12 +45,3 @@ impl<P: MNT6Parameters> Default for G1Prepared<P> {
Self::from(G1Affine::<P>::prime_subgroup_generator())
}
}

impl<P: MNT6Parameters> ToBytes for G1Prepared<P> {
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
self.x.write(&mut writer)?;
self.y.write(&mut writer)?;
self.x_twist.write(&mut writer)?;
self.y_twist.write(&mut writer)
}
}
16 changes: 2 additions & 14 deletions ec/src/models/mnt6/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ use crate::{
short_weierstrass_jacobian::{GroupAffine, GroupProjective},
AffineCurve,
};
use ark_ff::{
bytes::ToBytes,
fields::{Field, Fp3},
};
use ark_std::{
io::{Result as IoResult, Write},
vec::Vec,
};
use ark_ff::fields::{Field, Fp3};
use ark_std::vec::Vec;
use num_traits::One;

pub type G2Affine<P> = GroupAffine<<P as MNT6Parameters>::G2Parameters>;
Expand Down Expand Up @@ -39,12 +33,6 @@ impl<P: MNT6Parameters> Default for G2Prepared<P> {
}
}

impl<P: MNT6Parameters> ToBytes for G2Prepared<P> {
fn write<W: Write>(&self, _writer: W) -> IoResult<()> {
unimplemented!()
}
}

impl<P: MNT6Parameters> From<G2Affine<P>> for G2Prepared<P> {
fn from(g2: G2Affine<P>) -> Self {
let twist_inv = P::TWIST.inverse().unwrap();
Expand Down
Loading