Skip to content
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
26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poly-commit"
version = "0.1.1-alpha.0"
name = "ark-poly-commit"
version = "0.1.0"
authors = [
"Alessandro Chiesa <alexch@berkeley.edu>",
"Mary Maller <mary.maller.15@ucl.ac.uk>",
Expand All @@ -9,28 +9,34 @@ authors = [
"Pratyush Mishra <pratyush@berkeley.edu>",
"Noah Vesely <noah.vesely.18@ucl.ac.uk>",
"Nicholas Ward <npward@berkeley.edu>",
"arkworks contributors"
]
description = "A library for constructing polynomial commitment schemes for use in zkSNARKs"
repository = "https://github.com/scipr-lab/poly-commit"
documentation = "https://docs.rs/poly-commit/"
repository = "https://github.com/arkworks-rs/poly-commit"
documentation = "https://docs.rs/ark-poly-commit/"
keywords = ["cryptography", "polynomial commitments", "elliptic curves", "pairing"]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"

[dependencies]
algebra-core = { git = "https://github.com/scipr-lab/zexe", version = "0.1.1-alpha.0", default-features = false }
ff-fft = { git = "https://github.com/scipr-lab/zexe", version = "0.1.1-alpha.0", default-features = false }
bench-utils = { git = "https://github.com/scipr-lab/zexe", version = "0.1.1-alpha.0" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra", default-features = false, features = [ "derive" ] }
ark-ff = { git = "https://github.com/arkworks-rs/algebra", default-features = false }
ark-ec = { git = "https://github.com/arkworks-rs/algebra", default-features = false }
ark-std = { git = "https://github.com/arkworks-rs/utils", default-features = false }
ark-poly = { git = "https://github.com/arkworks-rs/algebra", default-features = false }
bench-utils = { git = "https://github.com/arkworks-rs/utils" }
rand_core = { version = "0.5", default-features = false }
digest = "0.8"
rayon = { version = "1", optional = true }
derivative = { version = "2", features = [ "use_core" ] }

[dev-dependencies]
rand = { version = "0.7", default-features = false }
algebra = { git = "https://github.com/scipr-lab/zexe", version = "0.1.1-alpha.0", default-features = false, features = ["ed_on_bls12_381", "bls12_381", "bls12_377"] }
ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/curves", default-features = false }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves", default-features = false, features = [ "curve" ] }
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves", default-features = false, features = [ "curve" ] }
blake2 = { version = "0.8", default-features = false }

[profile.release]
Expand All @@ -47,6 +53,6 @@ debug = true

[features]
default = ["std", "parallel"]
std = [ "algebra-core/std", "ff-fft/std", ]
std = [ "ark-ff/std", "ark-ec/std", "ark-poly/std", "ark-std/std", "ark-serialize/std" ]
print-trace = [ "bench-utils/print-trace" ]
parallel = [ "std", "algebra-core/parallel", "ff-fft/parallel", "rayon" ]
parallel = [ "std", "ark-ff/parallel", "ark-ec/parallel", "ark-poly/parallel", "ark-std/parallel", "rayon" ]
9 changes: 9 additions & 0 deletions scripts/install-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/env bash
# This script will install the provided directory ../.hooks as the hook
# directory for the present repo. See there for hooks, including a pre-commit
# hook that runs rustfmt on files before a commit.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HOOKS_DIR="${DIR}/../.hooks"

git config core.hooksPath "$HOOKS_DIR"
12 changes: 6 additions & 6 deletions src/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{Cow, String, Vec};
use algebra_core::Field;
use ark_ff::Field;
pub use ark_poly::DensePolynomial as Polynomial;
use core::borrow::Borrow;
use core::ops::{AddAssign, MulAssign, SubAssign};
pub use ff_fft::DensePolynomial as Polynomial;
use rand_core::RngCore;

/// Labels a `LabeledPolynomial` or a `LabeledCommitment`.
Expand Down Expand Up @@ -39,7 +39,7 @@ pub trait PCVerifierKey: Clone + core::fmt::Debug {

/// Defines the minimal interface of commitments for any polynomial
/// commitment scheme.
pub trait PCCommitment: Clone + algebra_core::ToBytes {
pub trait PCCommitment: Clone + ark_ff::ToBytes {
/// Outputs a non-hiding commitment to the zero polynomial.
fn empty() -> Self;

Expand All @@ -65,7 +65,7 @@ pub trait PCRandomness: Clone {

/// Defines the minimal interface of evaluation proofs for any polynomial
/// commitment scheme.
pub trait PCProof: Clone + algebra_core::ToBytes {
pub trait PCProof: Clone + ark_ff::ToBytes {
/// Size in bytes
fn size_in_bytes(&self) -> usize;
}
Expand Down Expand Up @@ -186,9 +186,9 @@ impl<C: PCCommitment> LabeledCommitment<C> {
}
}

impl<C: PCCommitment> algebra_core::ToBytes for LabeledCommitment<C> {
impl<C: PCCommitment> ark_ff::ToBytes for LabeledCommitment<C> {
#[inline]
fn write<W: algebra_core::io::Write>(&self, writer: W) -> algebra_core::io::Result<()> {
fn write<W: ark_std::io::Write>(&self, writer: W) -> ark_std::io::Result<()> {
self.commitment.write(writer)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ impl core::fmt::Display for Error {
}
}

impl algebra_core::Error for Error {}
impl ark_std::error::Error for Error {}
12 changes: 7 additions & 5 deletions src/ipa_pc/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::*;
use crate::{PCCommitterKey, PCVerifierKey, Vec};
use algebra_core::{AffineCurve, Field, ToBytes, UniformRand, Zero};
use ark_ec::AffineCurve;
use ark_ff::{Field, ToBytes, UniformRand, Zero};
use ark_std::vec;
use rand_core::RngCore;

/// `UniversalParams` are the universal parameters for the inner product arg scheme.
Expand Down Expand Up @@ -105,13 +107,13 @@ impl<G: AffineCurve> PCCommitment for Commitment<G> {
}

fn size_in_bytes(&self) -> usize {
algebra_core::to_bytes![G::zero()].unwrap().len() / 2
ark_ff::to_bytes![G::zero()].unwrap().len() / 2
}
}

impl<G: AffineCurve> ToBytes for Commitment<G> {
#[inline]
fn write<W: algebra_core::io::Write>(&self, mut writer: W) -> algebra_core::io::Result<()> {
fn write<W: ark_std::io::Write>(&self, mut writer: W) -> ark_std::io::Result<()> {
self.comm.write(&mut writer)?;
let shifted_exists = self.shifted_comm.is_some();
shifted_exists.write(&mut writer)?;
Expand Down Expand Up @@ -192,13 +194,13 @@ pub struct Proof<G: AffineCurve> {

impl<G: AffineCurve> PCProof for Proof<G> {
fn size_in_bytes(&self) -> usize {
algebra_core::to_bytes![self].unwrap().len()
ark_ff::to_bytes![self].unwrap().len()
}
}

impl<G: AffineCurve> ToBytes for Proof<G> {
#[inline]
fn write<W: algebra_core::io::Write>(&self, mut writer: W) -> algebra_core::io::Result<()> {
fn write<W: ark_std::io::Write>(&self, mut writer: W) -> ark_std::io::Result<()> {
self.l_vec.write(&mut writer)?;
self.r_vec.write(&mut writer)?;
self.final_comm_key.write(&mut writer)?;
Expand Down
46 changes: 22 additions & 24 deletions src/ipa_pc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use crate::{BatchLCProof, Error, Evaluations, QuerySet};
use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination};
use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, Polynomial, PolynomialCommitment};

use algebra_core::{
to_bytes, AffineCurve, Field, One, PrimeField, ProjectiveCurve, UniformRand, VariableBaseMSM,
Zero,
};
use ark_ec::{msm::VariableBaseMSM, AffineCurve, ProjectiveCurve};
use ark_ff::{to_bytes, Field, One, PrimeField, UniformRand, Zero};
use ark_std::{format, vec};
use core::{convert::TryInto, marker::PhantomData};
use rand_core::RngCore;

Expand Down Expand Up @@ -48,7 +47,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
hiding_generator: Option<G>,
randomizer: Option<G::ScalarField>,
) -> G::Projective {
let scalars_bigint = ff_fft::cfg_iter!(scalars)
let scalars_bigint = ark_std::cfg_iter!(scalars)
.map(|s| s.into_repr())
.collect::<Vec<_>>();

Expand All @@ -66,7 +65,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
let mut i = 0u64;
let mut challenge = None;
while challenge.is_none() {
let hash_input = algebra_core::to_bytes![bytes, i].unwrap();
let hash_input = ark_ff::to_bytes![bytes, i].unwrap();
let hash = D::digest(&hash_input);
challenge = <G::ScalarField as Field>::from_random_bytes(&hash);

Expand All @@ -78,7 +77,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {

#[inline]
fn inner_product(l: &[G::ScalarField], r: &[G::ScalarField]) -> G::ScalarField {
ff_fft::cfg_iter!(l).zip(r).map(|(li, ri)| *li * ri).sum()
ark_std::cfg_iter!(l).zip(r).map(|(li, ri)| *li * ri).sum()
}

/// The succinct portion of `PC::check`. This algorithm runs in time
Expand All @@ -96,7 +95,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
let d = vk.supported_degree();

// `log_d` is ceil(log2 (d + 1)), which is the number of steps to compute all of the challenges
let log_d = algebra_core::log2(d + 1) as usize;
let log_d = ark_std::log2(d + 1) as usize;

let mut combined_commitment_proj = G::Projective::zero();
let mut combined_v = G::ScalarField::zero();
Expand Down Expand Up @@ -131,8 +130,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
let rand = proof.rand.unwrap();

let hiding_challenge = Self::compute_random_oracle_challenge(
&algebra_core::to_bytes![combined_commitment, point, combined_v, hiding_comm]
.unwrap(),
&ark_ff::to_bytes![combined_commitment, point, combined_v, hiding_comm].unwrap(),
);
combined_commitment_proj += &(hiding_comm.mul(hiding_challenge) - &vk.s.mul(rand));
combined_commitment = combined_commitment_proj.into_affine();
Expand All @@ -141,7 +139,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
// Challenge for each round
let mut round_challenges = Vec::with_capacity(log_d);
let mut round_challenge = Self::compute_random_oracle_challenge(
&algebra_core::to_bytes![combined_commitment, point, combined_v].unwrap(),
&ark_ff::to_bytes![combined_commitment, point, combined_v].unwrap(),
);

let h_prime = vk.h.mul(round_challenge);
Expand All @@ -153,7 +151,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {

for (l, r) in l_iter.zip(r_iter) {
round_challenge = Self::compute_random_oracle_challenge(
&algebra_core::to_bytes![round_challenge, l, r].unwrap(),
&ark_ff::to_bytes![round_challenge, l, r].unwrap(),
);
round_challenges.push(round_challenge);
round_commitment_proj +=
Expand Down Expand Up @@ -284,7 +282,7 @@ impl<G: AffineCurve, D: Digest> InnerProductArgPC<G, D> {
}

fn sample_generators(num_generators: usize) -> Vec<G> {
let generators: Vec<_> = ff_fft::cfg_into_iter!(0..num_generators)
let generators: Vec<_> = ark_std::cfg_into_iter!(0..num_generators)
.map(|i| {
let i = i as u64;
let mut hash = D::digest(&to_bytes![&Self::PROTOCOL_NAME, i].unwrap());
Expand Down Expand Up @@ -530,7 +528,7 @@ impl<G: AffineCurve, D: Digest> PolynomialCommitment<G::ScalarField> for InnerPr
let d = ck.supported_degree();

// `log_d` is ceil(log2 (d + 1)), which is the number of steps to compute all of the challenges
let log_d = algebra_core::log2(d + 1) as usize;
let log_d = ark_std::log2(d + 1) as usize;

let mut combined_commitment;
let mut hiding_commitment = None;
Expand Down Expand Up @@ -558,7 +556,7 @@ impl<G: AffineCurve, D: Digest> PolynomialCommitment<G::ScalarField> for InnerPr
combined_commitment = batch.pop().unwrap();

let hiding_challenge = Self::compute_random_oracle_challenge(
&algebra_core::to_bytes![
&ark_ff::to_bytes![
combined_commitment,
point,
combined_v,
Expand Down Expand Up @@ -587,7 +585,7 @@ impl<G: AffineCurve, D: Digest> PolynomialCommitment<G::ScalarField> for InnerPr

// ith challenge
let mut round_challenge = Self::compute_random_oracle_challenge(
&algebra_core::to_bytes![combined_commitment, point, combined_v].unwrap(),
&ark_ff::to_bytes![combined_commitment, point, combined_v].unwrap(),
);

let h_prime = ck.h.mul(round_challenge).into_affine();
Expand Down Expand Up @@ -641,19 +639,19 @@ impl<G: AffineCurve, D: Digest> PolynomialCommitment<G::ScalarField> for InnerPr
r_vec.push(lr[1]);

round_challenge = Self::compute_random_oracle_challenge(
&algebra_core::to_bytes![round_challenge, lr[0], lr[1]].unwrap(),
&ark_ff::to_bytes![round_challenge, lr[0], lr[1]].unwrap(),
);
let round_challenge_inv = round_challenge.inverse().unwrap();

ff_fft::cfg_iter_mut!(coeffs_l)
ark_std::cfg_iter_mut!(coeffs_l)
.zip(coeffs_r)
.for_each(|(c_l, c_r)| *c_l += &(round_challenge_inv * &c_r));
.for_each(|(c_l, c_r)| *c_l += &(round_challenge_inv * &*c_r));

ff_fft::cfg_iter_mut!(z_l)
ark_std::cfg_iter_mut!(z_l)
.zip(z_r)
.for_each(|(z_l, z_r)| *z_l += &(round_challenge * &z_r));
.for_each(|(z_l, z_r)| *z_l += &(round_challenge * &*z_r));

ff_fft::cfg_iter_mut!(key_proj_l)
ark_std::cfg_iter_mut!(key_proj_l)
.zip(key_r)
.for_each(|(k_l, k_r)| *k_l += &(k_r.mul(round_challenge)));

Expand Down Expand Up @@ -695,7 +693,7 @@ impl<G: AffineCurve, D: Digest> PolynomialCommitment<G::ScalarField> for InnerPr
let d = vk.supported_degree();

// `log_d` is ceil(log2 (d + 1)), which is the number of steps to compute all of the challenges
let log_d = algebra_core::log2(d + 1) as usize;
let log_d = ark_std::log2(d + 1) as usize;

if proof.l_vec.len() != proof.r_vec.len() || proof.l_vec.len() != log_d {
return Err(Error::IncorrectInputLength(
Expand Down Expand Up @@ -1016,7 +1014,7 @@ mod tests {

use super::InnerProductArgPC;

use algebra::ed_on_bls12_381::EdwardsAffine;
use ark_ed_on_bls12_381::EdwardsAffine;
use blake2::Blake2s;

type PC<E, D> = InnerProductArgPC<E, D>;
Expand Down
15 changes: 8 additions & 7 deletions src/kzg10/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::*;
use algebra_core::{AffineCurve, PairingEngine, PrimeField, ProjectiveCurve, ToBytes, Zero};
use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve};
use ark_ff::{PrimeField, ToBytes, Zero};
use core::ops::{Add, AddAssign};

/// `UniversalParams` are the universal parameters for the KZG10 scheme.
Expand Down Expand Up @@ -75,7 +76,7 @@ pub struct VerifierKey<E: PairingEngine> {

impl<E: PairingEngine> ToBytes for VerifierKey<E> {
#[inline]
fn write<W: algebra_core::io::Write>(&self, mut writer: W) -> algebra_core::io::Result<()> {
fn write<W: ark_std::io::Write>(&self, mut writer: W) -> ark_std::io::Result<()> {
self.g.write(&mut writer)?;
self.gamma_g.write(&mut writer)?;
self.h.write(&mut writer)?;
Expand Down Expand Up @@ -103,7 +104,7 @@ pub struct Commitment<E: PairingEngine>(

impl<E: PairingEngine> ToBytes for Commitment<E> {
#[inline]
fn write<W: algebra_core::io::Write>(&self, writer: W) -> algebra_core::io::Result<()> {
fn write<W: ark_std::io::Write>(&self, writer: W) -> ark_std::io::Result<()> {
self.0.write(writer)
}
}
Expand All @@ -119,7 +120,7 @@ impl<E: PairingEngine> PCCommitment for Commitment<E> {
}

fn size_in_bytes(&self) -> usize {
algebra_core::to_bytes![E::G1Affine::zero()].unwrap().len() / 2
ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len() / 2
}
}

Expand Down Expand Up @@ -233,17 +234,17 @@ pub struct Proof<E: PairingEngine> {
impl<E: PairingEngine> PCProof for Proof<E> {
fn size_in_bytes(&self) -> usize {
let hiding_size = if self.random_v.is_some() {
algebra_core::to_bytes![E::Fr::zero()].unwrap().len()
ark_ff::to_bytes![E::Fr::zero()].unwrap().len()
} else {
0
};
algebra_core::to_bytes![E::G1Affine::zero()].unwrap().len() / 2 + hiding_size
ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len() / 2 + hiding_size
}
}

impl<E: PairingEngine> ToBytes for Proof<E> {
#[inline]
fn write<W: algebra_core::io::Write>(&self, mut writer: W) -> algebra_core::io::Result<()> {
fn write<W: ark_std::io::Write>(&self, mut writer: W) -> ark_std::io::Result<()> {
self.w.write(&mut writer)?;
self.random_v
.as_ref()
Expand Down
Loading