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

Upgrade ripp to arkworks 0.4 #50

Merged
merged 8 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 7 additions & 7 deletions dh_commitments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ark-dh-commitments"
version = "0.3.0"
version = "0.4.0"
authors = [
"Benedikt Bünz",
"Mary Maller",
Expand All @@ -14,16 +14,16 @@ repository = "https://github.com/arkworks-rs/ripp"
documentation = "https://docs.rs/ark-dh-commitments/"

[dependencies]
ark-ff = "0.3"
ark-ec = "0.3"
ark-serialize = { version = "0.3", features = [ "derive" ] }
ark-std = "0.3"
ark-ff = "0.4"
ark-ec = "0.4"
ark-serialize = { version = "0.4", features = [ "derive" ] }
ark-std = "0.4"

ark-inner-products = { path = "../inner_products" }

[dev-dependencies]
ark-bls12-381 = { version = "0.3", features = [ "curve" ] }
ark-ed-on-bls12-381 = "0.3"
ark-bls12-381 = { version = "0.4", features = [ "curve" ] }
ark-ed-on-bls12-381 = "0.4"

[features]
default = [ "parallel" ]
Expand Down
42 changes: 21 additions & 21 deletions dh_commitments/src/afgho16/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use ark_ec::PairingEngine;
use ark_ec::pairing::{Pairing, PairingOutput};
use ark_std::rand::Rng;
use std::marker::PhantomData;

use crate::{random_generators, DoublyHomomorphicCommitment, Error};

use ark_inner_products::{ExtensionFieldElement, InnerProduct, PairingInnerProduct};
use ark_inner_products::{InnerProduct, PairingInnerProduct};

#[derive(Clone)]
pub struct AFGHOCommitment<P: PairingEngine> {
pub struct AFGHOCommitment<P: Pairing> {
_pair: PhantomData<P>,
}

#[derive(Clone)]
pub struct AFGHOCommitmentG1<P: PairingEngine>(AFGHOCommitment<P>);
pub struct AFGHOCommitmentG1<P: Pairing>(AFGHOCommitment<P>);

#[derive(Clone)]
pub struct AFGHOCommitmentG2<P: PairingEngine>(AFGHOCommitment<P>);
pub struct AFGHOCommitmentG2<P: Pairing>(AFGHOCommitment<P>);

impl<P: PairingEngine> DoublyHomomorphicCommitment for AFGHOCommitmentG1<P> {
type Scalar = P::Fr;
type Message = P::G1Projective;
type Key = P::G2Projective;
type Output = ExtensionFieldElement<P>;
impl<P: Pairing> DoublyHomomorphicCommitment for AFGHOCommitmentG1<P> {
type Scalar = P::ScalarField;
type Message = P::G1;
type Key = P::G2;
type Output = PairingOutput<P>;

fn setup<R: Rng>(rng: &mut R, size: usize) -> Result<Vec<Self::Key>, Error> {
Ok(random_generators(rng, size))
Expand All @@ -32,11 +32,11 @@ impl<P: PairingEngine> DoublyHomomorphicCommitment for AFGHOCommitmentG1<P> {
}
}

impl<P: PairingEngine> DoublyHomomorphicCommitment for AFGHOCommitmentG2<P> {
type Scalar = P::Fr;
type Message = P::G2Projective;
type Key = P::G1Projective;
type Output = ExtensionFieldElement<P>;
impl<P: Pairing> DoublyHomomorphicCommitment for AFGHOCommitmentG2<P> {
type Scalar = P::ScalarField;
type Message = P::G2;
type Key = P::G1;
type Output = PairingOutput<P>;

fn setup<R: Rng>(rng: &mut R, size: usize) -> Result<Vec<Self::Key>, Error> {
Ok(random_generators(rng, size))
Expand Down Expand Up @@ -65,13 +65,13 @@ mod tests {
let mut message = Vec::new();
let mut wrong_message = Vec::new();
for _ in 0..TEST_SIZE {
message.push(<Bls12_381 as PairingEngine>::G1Projective::rand(&mut rng));
wrong_message.push(<Bls12_381 as PairingEngine>::G1Projective::rand(&mut rng));
message.push(<Bls12_381 as Pairing>::G1::rand(&mut rng));
wrong_message.push(<Bls12_381 as Pairing>::G1::rand(&mut rng));
}
let com = C1::commit(&commit_keys, &message).unwrap();
assert!(C1::verify(&commit_keys, &message, &com).unwrap());
assert!(!C1::verify(&commit_keys, &wrong_message, &com).unwrap());
message.push(<Bls12_381 as PairingEngine>::G1Projective::rand(&mut rng));
message.push(<Bls12_381 as Pairing>::G1::rand(&mut rng));
assert!(C1::verify(&commit_keys, &message, &com).is_err());
}

Expand All @@ -82,13 +82,13 @@ mod tests {
let mut message = Vec::new();
let mut wrong_message = Vec::new();
for _ in 0..TEST_SIZE {
message.push(<Bls12_381 as PairingEngine>::G2Projective::rand(&mut rng));
wrong_message.push(<Bls12_381 as PairingEngine>::G2Projective::rand(&mut rng));
message.push(<Bls12_381 as Pairing>::G2::rand(&mut rng));
wrong_message.push(<Bls12_381 as Pairing>::G2::rand(&mut rng));
}
let com = C2::commit(&commit_keys, &message).unwrap();
assert!(C2::verify(&commit_keys, &message, &com).unwrap());
assert!(!C2::verify(&commit_keys, &wrong_message, &com).unwrap());
message.push(<Bls12_381 as PairingEngine>::G2Projective::rand(&mut rng));
message.push(<Bls12_381 as Pairing>::G2::rand(&mut rng));
assert!(C2::verify(&commit_keys, &message, &com).is_err());
}
}
23 changes: 3 additions & 20 deletions dh_commitments/src/identity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use ark_ff::{bytes::ToBytes, fields::PrimeField};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError};
use ark_ff::fields::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::Rng;
use std::{
io::{Read, Result as IoResult, Write},
marker::PhantomData,
ops::{Add, MulAssign},
};
Expand All @@ -18,12 +17,6 @@ pub struct IdentityCommitment<T, F: PrimeField> {
#[derive(CanonicalSerialize, CanonicalDeserialize, Clone, Default, Eq, PartialEq)]
pub struct HomomorphicPlaceholderValue;

impl ToBytes for HomomorphicPlaceholderValue {
fn write<W: Write>(&self, _writer: W) -> IoResult<()> {
Ok(())
}
}

impl Add for HomomorphicPlaceholderValue {
type Output = Self;

Expand All @@ -41,15 +34,6 @@ pub struct IdentityOutput<T>(pub Vec<T>)
where
T: CanonicalSerialize + CanonicalDeserialize + Clone + Default + Eq;

impl<T> ToBytes for IdentityOutput<T>
where
T: ToBytes + CanonicalSerialize + CanonicalDeserialize + Clone + Default + Eq,
{
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
self.0.write(&mut writer)
}
}

impl<T> Add for IdentityOutput<T>
where
T: Add<T, Output = T> + CanonicalSerialize + CanonicalDeserialize + Clone + Default + Eq,
Expand Down Expand Up @@ -79,8 +63,7 @@ where

impl<T, F> DoublyHomomorphicCommitment for IdentityCommitment<T, F>
where
T: ToBytes
+ CanonicalSerialize
T: CanonicalSerialize
+ CanonicalDeserialize
+ Clone
+ Default
Expand Down
13 changes: 5 additions & 8 deletions dh_commitments/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ark_ec::group::Group;
use ark_ff::{bytes::ToBytes, fields::PrimeField};
use ark_ec::Group;
use ark_ff::fields::PrimeField;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::rand::Rng;
use std::{
Expand All @@ -19,8 +19,7 @@ pub type Error = Box<dyn ErrorTrait>;

pub trait DoublyHomomorphicCommitment: Clone {
type Scalar: PrimeField;
type Message: ToBytes
+ CanonicalSerialize
type Message: CanonicalSerialize
+ CanonicalDeserialize
+ Clone
+ Default
Expand All @@ -29,8 +28,7 @@ pub trait DoublyHomomorphicCommitment: Clone {
+ Sync
+ Add<Self::Message, Output = Self::Message>
+ MulAssign<Self::Scalar>;
type Key: ToBytes
+ CanonicalSerialize
type Key: CanonicalSerialize
+ CanonicalDeserialize
+ Clone
+ Default
Expand All @@ -39,8 +37,7 @@ pub trait DoublyHomomorphicCommitment: Clone {
+ Sync
+ Add<Self::Key, Output = Self::Key>
+ MulAssign<Self::Scalar>;
type Output: ToBytes
+ CanonicalSerialize
type Output: CanonicalSerialize
+ CanonicalDeserialize
+ Clone
+ Default
Expand Down
14 changes: 7 additions & 7 deletions dh_commitments/src/pedersen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ark_ec::ProjectiveCurve;
use ark_ec::CurveGroup;
use ark_std::rand::Rng;
use std::marker::PhantomData;

Expand All @@ -7,11 +7,11 @@ use crate::{random_generators, DoublyHomomorphicCommitment, Error};
use ark_inner_products::{InnerProduct, MultiexponentiationInnerProduct};

#[derive(Clone)]
pub struct PedersenCommitment<G: ProjectiveCurve> {
pub struct PedersenCommitment<G: CurveGroup> {
_group: PhantomData<G>,
}

impl<G: ProjectiveCurve> DoublyHomomorphicCommitment for PedersenCommitment<G> {
impl<G: CurveGroup> DoublyHomomorphicCommitment for PedersenCommitment<G> {
type Scalar = G::ScalarField;
type Message = G::ScalarField;
type Key = G;
Expand All @@ -29,7 +29,7 @@ impl<G: ProjectiveCurve> DoublyHomomorphicCommitment for PedersenCommitment<G> {
#[cfg(test)]
mod tests {
use super::*;
use ark_ed_on_bls12_381::EdwardsProjective as JubJub;
use ark_ed_on_bls12_381::{EdwardsProjective as JubJub, Fr};
use ark_ff::UniformRand;
use ark_std::rand::{rngs::StdRng, SeedableRng};

Expand All @@ -43,13 +43,13 @@ mod tests {
let mut message = Vec::new();
let mut wrong_message = Vec::new();
for _ in 0..TEST_SIZE {
message.push(<JubJub as ProjectiveCurve>::ScalarField::rand(&mut rng));
wrong_message.push(<JubJub as ProjectiveCurve>::ScalarField::rand(&mut rng));
message.push(Fr::rand(&mut rng));
wrong_message.push(Fr::rand(&mut rng));
}
let com = C::commit(&commit_keys, &message).unwrap();
assert!(C::verify(&commit_keys, &message, &com).unwrap());
assert!(!C::verify(&commit_keys, &wrong_message, &com).unwrap());
message.push(<JubJub as ProjectiveCurve>::ScalarField::rand(&mut rng));
message.push(Fr::rand(&mut rng));
assert!(C::verify(&commit_keys, &message, &com).is_err());
}
}
10 changes: 5 additions & 5 deletions inner_products/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ark-inner-products"
version = "0.3.0"
version = "0.4.0"
authors = [
"Benedikt Bünz",
"Mary Maller",
Expand All @@ -16,10 +16,10 @@ documentation = "https://docs.rs/ark-inner-products/"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ark-ff = "0.3"
ark-ec = "0.3"
ark-std = "0.3"
ark-serialize = { version = "0.3", features = [ "derive" ] }
ark-ff = "0.4"
ark-ec = "0.4"
ark-std = "0.4"
ark-serialize = { version = "0.4", features = [ "derive" ] }
rayon = { version = "1", optional = true }

[features]
Expand Down
Loading
Loading