Skip to content
Snippets Groups Projects
Commit b128d752 authored by Pratyush Mishra's avatar Pratyush Mishra
Browse files

Update for Zexe changes, and add support

parent 2d7563cf
No related branches found
No related tags found
No related merge requests found
language: rust language: rust
rust: cache: cargo
- stable
- nightly
matrix: matrix:
fast_finish: true fast_finish: true
include:
- rust: stable
script:
- cargo test --release
- cargo check --examples --all
- cargo check --all-features --examples --all
cache: cargo - rust: nightly
install:
- rustup component add rustfmt
script:
- cargo fmt -- --check
- cargo test --release
- cargo check --examples --all --benches
- cargo check --all-features --examples --all --benches
script: - rust: stable
- cargo test --release install:
- cargo check --all-features --examples --all - rustup target add thumbv6m-none-eabi
env: RUSTFLAGS='-C target-cpu=cortex-a7'
script:
# test algebra
- cargo check --examples --no-default-features --target thumbv6m-none-eabi
- cargo build --no-default-features --target thumbv6m-none-eabi
...@@ -19,15 +19,16 @@ license = "MIT/Apache-2.0" ...@@ -19,15 +19,16 @@ license = "MIT/Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
algebra = { git = "https://github.com/scipr-lab/zexe/", features = [ "parallel" ] } algebra-core = { git = "https://github.com/scipr-lab/zexe/", default-features = false }
ff-fft = { git = "https://github.com/scipr-lab/zexe/" } ff-fft = { git = "https://github.com/scipr-lab/zexe/", default-features = false }
bench-utils = { git = "https://github.com/scipr-lab/zexe/" } bench-utils = { git = "https://github.com/scipr-lab/zexe/", default-features = false }
rand_core = { version = "0.5" } rand_core = { version = "0.5", default-features = false }
rayon = { version = "1" } rayon = { version = "1", optional = true }
derivative = { version = "1" } derivative = { version = "1", features = [ "use_core" ] }
[dev-dependencies] [dev-dependencies]
rand = { version = "0.7" } rand = { version = "0.7", default-features = false }
algebra = { git = "https://github.com/scipr-lab/zexe/", default-features = false, features = ["full"] }
[profile.release] [profile.release]
opt-level = 3 opt-level = 3
...@@ -42,4 +43,7 @@ incremental = true ...@@ -42,4 +43,7 @@ incremental = true
debug = true debug = true
[features] [features]
default = ["std"]
std = [ "algebra-core/std", "ff-fft/std", ]
print-trace = [ "bench-utils/print-trace" ] print-trace = [ "bench-utils/print-trace" ]
parallel = [ "std", "algebra-core/parallel", "ff-fft/parallel", "rayon" ]
use algebra::Field; use crate::{Cow, String, Vec};
use algebra_core::Field;
pub use ff_fft::DensePolynomial as Polynomial; pub use ff_fft::DensePolynomial as Polynomial;
use rand_core::RngCore; use rand_core::RngCore;
use std::borrow::Cow;
/// Labels a `LabeledPolynomial` or a `LabeledCommitment`. /// Labels a `LabeledPolynomial` or a `LabeledCommitment`.
pub type PolynomialLabel = String; pub type PolynomialLabel = String;
/// Defines the minimal interface for public params for any polynomial /// Defines the minimal interface for public params for any polynomial
/// commitment scheme. /// commitment scheme.
pub trait PCUniversalParams: Clone + std::fmt::Debug { pub trait PCUniversalParams: Clone + core::fmt::Debug {
/// Outputs the maximum degree supported by the committer key. /// Outputs the maximum degree supported by the committer key.
fn max_degree(&self) -> usize; fn max_degree(&self) -> usize;
} }
/// Defines the minimal interface of committer keys for any polynomial /// Defines the minimal interface of committer keys for any polynomial
/// commitment scheme. /// commitment scheme.
pub trait PCCommitterKey: Clone + std::fmt::Debug { pub trait PCCommitterKey: Clone + core::fmt::Debug {
/// Outputs the maximum degree supported by the universal parameters /// Outputs the maximum degree supported by the universal parameters
/// `Self` was derived from. /// `Self` was derived from.
fn max_degree(&self) -> usize; fn max_degree(&self) -> usize;
...@@ -26,7 +26,7 @@ pub trait PCCommitterKey: Clone + std::fmt::Debug { ...@@ -26,7 +26,7 @@ pub trait PCCommitterKey: Clone + std::fmt::Debug {
/// Defines the minimal interface of verifier keys for any polynomial /// Defines the minimal interface of verifier keys for any polynomial
/// commitment scheme. /// commitment scheme.
pub trait PCVerifierKey: Clone + std::fmt::Debug { pub trait PCVerifierKey: Clone + core::fmt::Debug {
/// Outputs the maximum degree supported by the universal parameters /// Outputs the maximum degree supported by the universal parameters
/// `Self` was derived from. /// `Self` was derived from.
fn max_degree(&self) -> usize; fn max_degree(&self) -> usize;
...@@ -37,7 +37,7 @@ pub trait PCVerifierKey: Clone + std::fmt::Debug { ...@@ -37,7 +37,7 @@ pub trait PCVerifierKey: Clone + std::fmt::Debug {
/// Defines the minimal interface of commitments for any polynomial /// Defines the minimal interface of commitments for any polynomial
/// commitment scheme. /// commitment scheme.
pub trait PCCommitment: Clone + algebra::ToBytes { pub trait PCCommitment: Clone + algebra_core::ToBytes {
/// Outputs a non-hiding commitment to the zero polynomial. /// Outputs a non-hiding commitment to the zero polynomial.
fn empty() -> Self; fn empty() -> Self;
...@@ -63,7 +63,7 @@ pub trait PCRandomness: Clone { ...@@ -63,7 +63,7 @@ pub trait PCRandomness: Clone {
/// Defines the minimal interface of evaluation proofs for any polynomial /// Defines the minimal interface of evaluation proofs for any polynomial
/// commitment scheme. /// commitment scheme.
pub trait PCProof: Clone + algebra::ToBytes { pub trait PCProof: Clone + algebra_core::ToBytes {
/// Size in bytes /// Size in bytes
fn size_in_bytes(&self) -> usize; fn size_in_bytes(&self) -> usize;
} }
...@@ -79,7 +79,7 @@ pub struct LabeledPolynomial<'a, F: Field> { ...@@ -79,7 +79,7 @@ pub struct LabeledPolynomial<'a, F: Field> {
hiding_bound: Option<usize>, hiding_bound: Option<usize>,
} }
impl<'a, F: Field> std::ops::Deref for LabeledPolynomial<'a, F> { impl<'a, F: Field> core::ops::Deref for LabeledPolynomial<'a, F> {
type Target = Polynomial<F>; type Target = Polynomial<F>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
...@@ -183,9 +183,9 @@ impl<C: PCCommitment> LabeledCommitment<C> { ...@@ -183,9 +183,9 @@ impl<C: PCCommitment> LabeledCommitment<C> {
} }
} }
impl<C: PCCommitment> algebra::ToBytes for LabeledCommitment<C> { impl<C: PCCommitment> algebra_core::ToBytes for LabeledCommitment<C> {
#[inline] #[inline]
fn write<W: std::io::Write>(&self, writer: W) -> std::io::Result<()> { fn write<W: algebra_core::io::Write>(&self, writer: W) -> algebra_core::io::Result<()> {
self.commitment.write(writer) self.commitment.write(writer)
} }
} }
......
use crate::String;
/// Errors that arise when dealing with query sets. /// Errors that arise when dealing with query sets.
#[derive(Debug)] #[derive(Debug)]
pub enum QuerySetError { pub enum QuerySetError {
...@@ -15,8 +16,8 @@ pub enum QuerySetError { ...@@ -15,8 +16,8 @@ pub enum QuerySetError {
}, },
} }
impl std::fmt::Display for QuerySetError { impl core::fmt::Display for QuerySetError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self { match self {
QuerySetError::MissingPolynomial { label } => write!( QuerySetError::MissingPolynomial { label } => write!(
f, f,
...@@ -32,11 +33,7 @@ impl std::fmt::Display for QuerySetError { ...@@ -32,11 +33,7 @@ impl std::fmt::Display for QuerySetError {
} }
} }
impl std::error::Error for QuerySetError { impl algebra_core::Error for QuerySetError {}
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
/// Equation errors that arise when dealing with query sets. /// Equation errors that arise when dealing with query sets.
#[derive(Debug)] #[derive(Debug)]
...@@ -48,8 +45,8 @@ pub enum EquationError { ...@@ -48,8 +45,8 @@ pub enum EquationError {
}, },
} }
impl std::fmt::Display for EquationError { impl core::fmt::Display for EquationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self { match self {
EquationError::MissingLHS { label } => write!( EquationError::MissingLHS { label } => write!(
f, f,
...@@ -60,8 +57,4 @@ impl std::fmt::Display for EquationError { ...@@ -60,8 +57,4 @@ impl std::fmt::Display for EquationError {
} }
} }
impl std::error::Error for EquationError { impl algebra_core::Error for EquationError {}
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
use algebra::{AffineCurve, ProjectiveCurve, ToBytes, PairingCurve, PairingEngine, PrimeField, Zero}; use algebra_core::{AffineCurve, ProjectiveCurve, ToBytes, PairingEngine, PrimeField, Zero};
use crate::*; use crate::*;
use std::ops::{Add, AddAssign}; use core::ops::{Add, AddAssign};
use std::borrow::Cow;
/// `UniversalParams` are the universal parameters for the KZG10 scheme. /// `UniversalParams` are the universal parameters for the KZG10 scheme.
#[derive(Derivative)] #[derive(Derivative)]
...@@ -21,10 +20,10 @@ pub struct UniversalParams<E: PairingEngine> { ...@@ -21,10 +20,10 @@ pub struct UniversalParams<E: PairingEngine> {
pub beta_h: E::G2Affine, pub beta_h: E::G2Affine,
/// The generator of G2, prepared for use in pairings. /// The generator of G2, prepared for use in pairings.
#[derivative(Debug="ignore")] #[derivative(Debug="ignore")]
pub prepared_h: <E::G2Affine as PairingCurve>::Prepared, pub prepared_h: E::G2Prepared,
/// \beta times the above generator of G2, prepared for use in pairings. /// \beta times the above generator of G2, prepared for use in pairings.
#[derivative(Debug="ignore")] #[derivative(Debug="ignore")]
pub prepared_beta_h: <E::G2Affine as PairingCurve>::Prepared, pub prepared_beta_h: E::G2Prepared,
} }
impl<E: PairingEngine> PCUniversalParams for UniversalParams<E> { impl<E: PairingEngine> PCUniversalParams for UniversalParams<E> {
...@@ -70,10 +69,10 @@ pub struct VerifierKey<E: PairingEngine> { ...@@ -70,10 +69,10 @@ pub struct VerifierKey<E: PairingEngine> {
pub beta_h: E::G2Affine, pub beta_h: E::G2Affine,
/// The generator of G2, prepared for use in pairings. /// The generator of G2, prepared for use in pairings.
#[derivative(Debug="ignore")] #[derivative(Debug="ignore")]
pub prepared_h: <E::G2Affine as PairingCurve>::Prepared, pub prepared_h: E::G2Prepared,
/// \beta times the above generator of G2, prepared for use in pairings. /// \beta times the above generator of G2, prepared for use in pairings.
#[derivative(Debug="ignore")] #[derivative(Debug="ignore")]
pub prepared_beta_h: <E::G2Affine as PairingCurve>::Prepared, pub prepared_beta_h: E::G2Prepared,
} }
/// `Commitment` commits to a polynomial. It is output by `KZG10::commit`. /// `Commitment` commits to a polynomial. It is output by `KZG10::commit`.
...@@ -94,7 +93,7 @@ pub struct Commitment<E: PairingEngine>( ...@@ -94,7 +93,7 @@ pub struct Commitment<E: PairingEngine>(
impl<E: PairingEngine> ToBytes for Commitment<E> { impl<E: PairingEngine> ToBytes for Commitment<E> {
#[inline] #[inline]
fn write<W: std::io::Write>(&self, writer: W) -> std::io::Result<()> { fn write<W: algebra_core::io::Write>(&self, writer: W) -> algebra_core::io::Result<()> {
self.0.write(writer) self.0.write(writer)
} }
} }
...@@ -110,7 +109,7 @@ impl<E: PairingEngine> PCCommitment for Commitment<E> { ...@@ -110,7 +109,7 @@ impl<E: PairingEngine> PCCommitment for Commitment<E> {
} }
fn size_in_bytes(&self) -> usize { fn size_in_bytes(&self) -> usize {
to_bytes![E::G1Affine::zero()].unwrap().len() / 2 algebra_core::to_bytes![E::G1Affine::zero()].unwrap().len() / 2
} }
} }
...@@ -223,14 +222,14 @@ pub struct Proof<E: PairingEngine> { ...@@ -223,14 +222,14 @@ pub struct Proof<E: PairingEngine> {
impl<E: PairingEngine> PCProof for Proof<E> { impl<E: PairingEngine> PCProof for Proof<E> {
fn size_in_bytes(&self) -> usize { fn size_in_bytes(&self) -> usize {
to_bytes![E::G1Affine::zero()].unwrap().len() / 2 + to_bytes![E::Fr::zero()].unwrap().len() algebra_core::to_bytes![E::G1Affine::zero()].unwrap().len() / 2 + algebra_core::to_bytes![E::Fr::zero()].unwrap().len()
} }
} }
impl<E: PairingEngine> ToBytes for Proof<E> { impl<E: PairingEngine> ToBytes for Proof<E> {
#[inline] #[inline]
fn write<W: std::io::Write>(&self, mut writer: W) -> std::io::Result<()> { fn write<W: algebra_core::io::Write>(&self, mut writer: W) -> algebra_core::io::Result<()> {
self.w.write(&mut writer)?; self.w.write(&mut writer)?;
self.random_v.write(&mut writer) self.random_v.write(&mut writer)
} }
......
...@@ -25,8 +25,8 @@ pub enum Error { ...@@ -25,8 +25,8 @@ pub enum Error {
}, },
} }
impl std::fmt::Display for Error { impl core::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self { match self {
Error::MissingRng => write!(f, "hiding commitments require `Some(rng)`"), Error::MissingRng => write!(f, "hiding commitments require `Some(rng)`"),
Error::DegreeIsZero => write!( Error::DegreeIsZero => write!(
...@@ -58,11 +58,7 @@ impl std::fmt::Display for Error { ...@@ -58,11 +58,7 @@ impl std::fmt::Display for Error {
} }
} }
impl std::error::Error for Error { impl algebra_core::Error for Error {}
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
impl Error { impl Error {
pub(crate) fn check_degree_is_within_bounds(num_coefficients: usize, num_powers: usize) -> Result<(), Self> { pub(crate) fn check_degree_is_within_bounds(num_coefficients: usize, num_powers: usize) -> Result<(), Self> {
......
...@@ -5,15 +5,17 @@ ...@@ -5,15 +5,17 @@
//! proposed by Kate, Zaverucha, and Goldberg ([KZG10](http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf)). //! proposed by Kate, Zaverucha, and Goldberg ([KZG10](http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf)).
//! This construction achieves extractability in the algebraic group model (AGM). //! This construction achieves extractability in the algebraic group model (AGM).
use crate::{PCRandomness, Polynomial}; use crate::{PCRandomness, Polynomial, Vec};
use algebra::msm::{FixedBaseMSM, VariableBaseMSM}; use algebra_core::msm::{FixedBaseMSM, VariableBaseMSM};
use algebra::{ use algebra_core::{
AffineCurve, Group, PairingCurve, PairingEngine, PrimeField, ProjectiveCurve, AffineCurve, Group, PairingEngine, PrimeField, ProjectiveCurve,
UniformRand, One, Zero UniformRand, One, Zero
}; };
use rand_core::RngCore; use rand_core::RngCore;
#[cfg(feature = "parallel")]
use rayon::prelude::*; use rayon::prelude::*;
use std::marker::PhantomData;
use core::marker::PhantomData;
mod data_structures; mod data_structures;
pub use data_structures::*; pub use data_structures::*;
...@@ -82,10 +84,10 @@ impl<E: PairingEngine> KZG10<E> { ...@@ -82,10 +84,10 @@ impl<E: PairingEngine> KZG10<E> {
E::G1Projective::batch_normalization(powers_of_g.as_mut_slice()); E::G1Projective::batch_normalization(powers_of_g.as_mut_slice());
E::G1Projective::batch_normalization(powers_of_gamma_g.as_mut_slice()); E::G1Projective::batch_normalization(powers_of_gamma_g.as_mut_slice());
let beta_h = h.mul(&beta).into_affine(); let beta_h = h.mul(beta).into_affine();
let h = h.into_affine(); let h = h.into_affine();
let prepared_h = h.prepare(); let prepared_h = h.into();
let prepared_beta_h = beta_h.prepare(); let prepared_beta_h = beta_h.into();
let pp = UniversalParams { let pp = UniversalParams {
powers_of_g: powers_of_g.into_iter().map(|e| e.into_affine()).collect(), powers_of_g: powers_of_g.into_iter().map(|e| e.into_affine()).collect(),
...@@ -249,11 +251,11 @@ impl<E: PairingEngine> KZG10<E> { ...@@ -249,11 +251,11 @@ impl<E: PairingEngine> KZG10<E> {
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let check_time = start_timer!(|| "Checking evaluation"); let check_time = start_timer!(|| "Checking evaluation");
let inner = comm.0.into_projective() let inner = comm.0.into_projective()
- &vk.g.into_projective().mul(&value) - &vk.g.into_projective().mul(value)
- &vk.gamma_g.into_projective().mul(&proof.random_v); - &vk.gamma_g.into_projective().mul(proof.random_v);
let lhs = E::pairing(inner, vk.h); let lhs = E::pairing(inner, vk.h);
let inner = vk.beta_h.into_projective() - &vk.h.into_projective().mul(&point); let inner = vk.beta_h.into_projective() - &vk.h.into_projective().mul(point);
let rhs = E::pairing(proof.w, inner); let rhs = E::pairing(proof.w, inner);
end_timer!(check_time, || format!("Result: {}", lhs == rhs)); end_timer!(check_time, || format!("Result: {}", lhs == rhs));
...@@ -287,17 +289,17 @@ impl<E: PairingEngine> KZG10<E> { ...@@ -287,17 +289,17 @@ impl<E: PairingEngine> KZG10<E> {
for (((c, z), v), proof) in commitments.iter().zip(points).zip(values).zip(proofs) { for (((c, z), v), proof) in commitments.iter().zip(points).zip(values).zip(proofs) {
let mut c = c.0.into_projective(); let mut c = c.0.into_projective();
let w = proof.w.into_projective(); let w = proof.w.into_projective();
c += &w.mul(z); c += &w.mul(*z);
g_multiplier += &(randomizer * &v); g_multiplier += &(randomizer * &v);
gamma_g_multiplier += &(randomizer * &proof.random_v); gamma_g_multiplier += &(randomizer * &proof.random_v);
total_c += &c.mul(&randomizer); total_c += &c.mul(randomizer);
total_w += &w.mul(&randomizer); total_w += &w.mul(randomizer);
// We don't need to sample randomizers from the full field, // We don't need to sample randomizers from the full field,
// only from 128-bit strings. // only from 128-bit strings.
randomizer = u128::rand(rng).into(); randomizer = u128::rand(rng).into();
} }
total_c -= &g.mul(&g_multiplier); total_c -= &g.mul(g_multiplier);
total_c -= &gamma_g.mul(&gamma_g_multiplier); total_c -= &gamma_g.mul(gamma_g_multiplier);
end_timer!(combination_time); end_timer!(combination_time);
let to_affine_time = start_timer!(|| "Converting results to affine for pairing"); let to_affine_time = start_timer!(|| "Converting results to affine for pairing");
...@@ -310,8 +312,8 @@ impl<E: PairingEngine> KZG10<E> { ...@@ -310,8 +312,8 @@ impl<E: PairingEngine> KZG10<E> {
let pairing_time = start_timer!(|| "Performing product of pairings"); let pairing_time = start_timer!(|| "Performing product of pairings");
let result = E::product_of_pairings(&[ let result = E::product_of_pairings(&[
(&total_w.prepare(), &vk.prepared_beta_h), (total_w.into(), vk.prepared_beta_h.clone()),
(&total_c.prepare(), &vk.prepared_h), (total_c.into(), vk.prepared_h.clone()),
]) == E::Fqk::one(); ]) == E::Fqk::one();
end_timer!(pairing_time); end_timer!(pairing_time);
end_timer!(check_time, || format!("Result: {}", result)); end_timer!(check_time, || format!("Result: {}", result));
...@@ -330,7 +332,7 @@ fn skip_leading_zeros_and_convert_to_bigints<F: PrimeField>(p: &Polynomial<F>) - ...@@ -330,7 +332,7 @@ fn skip_leading_zeros_and_convert_to_bigints<F: PrimeField>(p: &Polynomial<F>) -
fn convert_to_bigints<F: PrimeField>(p: &[F]) -> Vec<F::BigInt> { fn convert_to_bigints<F: PrimeField>(p: &[F]) -> Vec<F::BigInt> {
let to_bigint_time = start_timer!(|| "Converting polynomial coeffs to bigints"); let to_bigint_time = start_timer!(|| "Converting polynomial coeffs to bigints");
let coeffs = p.par_iter().map(|s| s.into_repr()).collect::<Vec<_>>(); let coeffs = ff_fft::cfg_iter!(p).map(|s| s.into_repr()).collect::<Vec<_>>();
end_timer!(to_bigint_time); end_timer!(to_bigint_time);
coeffs coeffs
} }
...@@ -340,14 +342,15 @@ mod tests { ...@@ -340,14 +342,15 @@ mod tests {
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
use crate::kzg10::*; use crate::kzg10::*;
use crate::*; use crate::*;
use algebra::fields::bls12_381::Fr;
use algebra::curves::bls12_377::Bls12_377; use algebra::bls12_381::Fr;
use algebra::curves::bls12_381::Bls12_381; use algebra::Bls12_377;
use algebra::curves::mnt6::MNT6; use algebra::Bls12_381;
use algebra::curves::sw6::SW6; use algebra::MNT6;
use algebra::SW6;
use algebra::test_rng;
use rand::thread_rng; type KZG_Bls12_381 = KZG10<Bls12_381>;
impl<E: PairingEngine> KZG10<E> { impl<E: PairingEngine> KZG10<E> {
/// Specializes the public parameters for a given maximum degree `d` for polynomials /// Specializes the public parameters for a given maximum degree `d` for polynomials
...@@ -363,8 +366,8 @@ mod tests { ...@@ -363,8 +366,8 @@ mod tests {
let powers_of_gamma_g = pp.powers_of_gamma_g[..=supported_degree].to_vec(); let powers_of_gamma_g = pp.powers_of_gamma_g[..=supported_degree].to_vec();
let powers = Powers { let powers = Powers {
powers_of_g: std::borrow::Cow::Owned(powers_of_g), powers_of_g: Cow::Owned(powers_of_g),
powers_of_gamma_g: std::borrow::Cow::Owned(powers_of_gamma_g), powers_of_gamma_g: Cow::Owned(powers_of_gamma_g),
}; };
let vk = VerifierKey { let vk = VerifierKey {
g: pp.powers_of_g[0], g: pp.powers_of_g[0],
...@@ -380,7 +383,7 @@ mod tests { ...@@ -380,7 +383,7 @@ mod tests {
#[test] #[test]
fn add_commitments_test() { fn add_commitments_test() {
let rng = &mut thread_rng(); let rng = &mut test_rng();
let p = Polynomial::from_coefficients_slice(&[ let p = Polynomial::from_coefficients_slice(&[
Fr::rand(rng), Fr::rand(rng),
Fr::rand(rng), Fr::rand(rng),
...@@ -405,10 +408,8 @@ mod tests { ...@@ -405,10 +408,8 @@ mod tests {
assert_eq!(f_comm, f_comm_2); assert_eq!(f_comm, f_comm_2);
} }
type KZG_Bls12_381 = KZG10<Bls12_381>;
fn end_to_end_test_template<E: PairingEngine>() -> Result<(), Error> { fn end_to_end_test_template<E: PairingEngine>() -> Result<(), Error> {
let rng = &mut thread_rng(); let rng = &mut test_rng();
for _ in 0..100 { for _ in 0..100 {
let mut degree = 0; let mut degree = 0;
while degree <= 1 { while degree <= 1 {
...@@ -434,7 +435,7 @@ mod tests { ...@@ -434,7 +435,7 @@ mod tests {
} }
fn linear_polynomial_test_template<E: PairingEngine>() -> Result<(), Error> { fn linear_polynomial_test_template<E: PairingEngine>() -> Result<(), Error> {
let rng = &mut thread_rng(); let rng = &mut test_rng();
for _ in 0..100 { for _ in 0..100 {
let degree = 50; let degree = 50;
let pp = KZG10::<E>::setup(degree, false, rng)?; let pp = KZG10::<E>::setup(degree, false, rng)?;
...@@ -457,7 +458,7 @@ mod tests { ...@@ -457,7 +458,7 @@ mod tests {
} }
fn batch_check_test_template<E: PairingEngine>() -> Result<(), Error> { fn batch_check_test_template<E: PairingEngine>() -> Result<(), Error> {
let rng = &mut thread_rng(); let rng = &mut test_rng();
for _ in 0..10 { for _ in 0..10 {
let mut degree = 0; let mut degree = 0;
while degree <= 1 { while degree <= 1 {
......
...@@ -7,24 +7,31 @@ ...@@ -7,24 +7,31 @@
#![deny(unused_comparisons, bare_trait_objects, unused_must_use, const_err)] #![deny(unused_comparisons, bare_trait_objects, unused_must_use, const_err)]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#[macro_use]
extern crate algebra;
#[macro_use] #[macro_use]
extern crate derivative; extern crate derivative;
#[macro_use] #[macro_use]
extern crate bench_utils; extern crate bench_utils;
use algebra::Field; use algebra_core::Field;
pub use ff_fft::DensePolynomial as Polynomial; pub use ff_fft::DensePolynomial as Polynomial;
use rand_core::RngCore; use rand_core::RngCore;
use std::collections::{BTreeMap, BTreeSet};
#[cfg(not(feature = "std"))]
#[macro_use]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::{borrow::Cow, string::String, vec::Vec, collections::{BTreeSet, BTreeMap}};
#[cfg(feature = "std")]
use std::{borrow::Cow, string::String, vec::Vec, collections::{BTreeMap, BTreeSet}};
/// Data structures used by a polynomial commitment scheme. /// Data structures used by a polynomial commitment scheme.
pub mod data_structures; pub mod data_structures;
pub use data_structures::*; pub use data_structures::*;
/// Errors pertaining to query sets. /// Errors pertaining to query sets.
pub mod error; pub mod error;
pub use error::*; pub use error::*;
...@@ -72,7 +79,7 @@ pub trait PolynomialCommitment<F: Field> { ...@@ -72,7 +79,7 @@ pub trait PolynomialCommitment<F: Field> {
/// The evaluation proof for a query set. /// The evaluation proof for a query set.
type BatchProof: Clone + From<Vec<Self::Proof>> + Into<Vec<Self::Proof>>; type BatchProof: Clone + From<Vec<Self::Proof>> + Into<Vec<Self::Proof>>;
/// The error type for the scheme. /// The error type for the scheme.
type Error: std::error::Error + From<QuerySetError> + From<EquationError>; type Error: algebra_core::Error + From<QuerySetError> + From<EquationError>;
/// Constructs public parameters when given as input the maximum degree `degree` /// Constructs public parameters when given as input the maximum degree `degree`
/// for the polynomial commitment scheme. /// for the polynomial commitment scheme.
...@@ -302,8 +309,8 @@ pub trait PolynomialCommitment<F: Field> { ...@@ -302,8 +309,8 @@ pub trait PolynomialCommitment<F: Field> {
#[cfg(test)] #[cfg(test)]
pub mod tests { pub mod tests {
use crate::*; use crate::*;
use algebra::Field; use algebra::{Field, test_rng};
use rand::{distributions::Distribution, thread_rng, Rng}; use rand::{distributions::Distribution, Rng};
#[derive(Default)] #[derive(Default)]
struct TestInfo { struct TestInfo {
...@@ -333,7 +340,7 @@ pub mod tests { ...@@ -333,7 +340,7 @@ pub mod tests {
.. ..
} = info; } = info;
let rng = &mut thread_rng(); let rng = &mut test_rng();
let max_degree = max_degree.unwrap_or(rand::distributions::Uniform::from(2..=64).sample(rng)); let max_degree = max_degree.unwrap_or(rand::distributions::Uniform::from(2..=64).sample(rng));
let pp = PC::setup(max_degree, rng)?; let pp = PC::setup(max_degree, rng)?;
...@@ -449,7 +456,7 @@ pub mod tests { ...@@ -449,7 +456,7 @@ pub mod tests {
num_equations, num_equations,
} = info; } = info;
let rng = &mut thread_rng(); let rng = &mut test_rng();
let max_degree = max_degree.unwrap_or(rand::distributions::Uniform::from(2..=64).sample(rng)); let max_degree = max_degree.unwrap_or(rand::distributions::Uniform::from(2..=64).sample(rng));
let pp = PC::setup(max_degree, rng)?; let pp = PC::setup(max_degree, rng)?;
......
use rand_core::RngCore; use rand_core::RngCore;
use algebra::{ToBytes, PairingEngine}; use algebra_core::{ToBytes, PairingEngine};
use crate::{PCCommitment, PCCommitterKey, PCRandomness, PCVerifierKey}; use crate::{PCCommitment, PCCommitterKey, PCRandomness, PCVerifierKey, Vec};
use std::ops::{Add, AddAssign}; use core::ops::{Add, AddAssign};
use crate::kzg10; use crate::kzg10;
/// `UniversalParams` are the universal parameters for the KZG10 scheme. /// `UniversalParams` are the universal parameters for the KZG10 scheme.
...@@ -133,7 +133,7 @@ pub struct Commitment<E: PairingEngine> { ...@@ -133,7 +133,7 @@ pub struct Commitment<E: PairingEngine> {
impl<E: PairingEngine> ToBytes for Commitment<E> { impl<E: PairingEngine> ToBytes for Commitment<E> {
#[inline] #[inline]
fn write<W: std::io::Write>(&self, mut writer: W) -> std::io::Result<()> { fn write<W: algebra_core::io::Write>(&self, mut writer: W) -> algebra_core::io::Result<()> {
self.comm.write(&mut writer)?; self.comm.write(&mut writer)?;
let shifted_exists = self.shifted_comm.is_some(); let shifted_exists = self.shifted_comm.is_some();
shifted_exists.write(&mut writer)?; shifted_exists.write(&mut writer)?;
......
use crate::String;
use crate::kzg10; use crate::kzg10;
use crate::{PCCommitterKey, LabeledPolynomial, QuerySetError as QSError, EquationError as EqError}; use crate::{PCCommitterKey, LabeledPolynomial, QuerySetError as QSError, EquationError as EqError};
...@@ -58,7 +59,7 @@ impl From<EqError> for Error { ...@@ -58,7 +59,7 @@ impl From<EqError> for Error {
} }
impl Error { impl Error {
pub(crate) fn check_degrees_and_bounds<'a, E: algebra::PairingEngine>( pub(crate) fn check_degrees_and_bounds<'a, E: algebra_core::PairingEngine>(
ck: &super::CommitterKey<E>, ck: &super::CommitterKey<E>,
p: &'a LabeledPolynomial<'a, E::Fr>, p: &'a LabeledPolynomial<'a, E::Fr>,
) -> Result<(), Self> { ) -> Result<(), Self> {
...@@ -85,8 +86,8 @@ impl Error { ...@@ -85,8 +86,8 @@ impl Error {
} }
} }
impl std::fmt::Display for Error { impl core::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self { match self {
Error::TrimmingDegreeTooLarge => write!(f, "the degree provided to `trim` was too large"), Error::TrimmingDegreeTooLarge => write!(f, "the degree provided to `trim` was too large"),
Error::EmptyDegreeBounds => write!(f, "provided `enforced_degree_bounds` was `Some<&[]>`"), Error::EmptyDegreeBounds => write!(f, "provided `enforced_degree_bounds` was `Some<&[]>`"),
...@@ -117,8 +118,4 @@ impl std::fmt::Display for Error { ...@@ -117,8 +118,4 @@ impl std::fmt::Display for Error {
} }
} }
impl std::error::Error for Error { impl algebra_core::Error for Error {}
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
use crate::{PCUniversalParams, PCRandomness, Polynomial, PolynomialCommitment}; use crate::{PCUniversalParams, PCRandomness, Polynomial, PolynomialCommitment};
use crate::{BTreeMap, BTreeSet, Vec};
use crate::{QuerySetError, EquationError, QuerySet, Evaluations}; use crate::{QuerySetError, EquationError, QuerySet, Evaluations};
use crate::{LabeledPolynomial, LabeledCommitment, Equation}; use crate::{LabeledPolynomial, LabeledCommitment, Equation};
use crate::kzg10; use crate::kzg10;
use algebra::{AffineCurve, Field, PairingEngine, ProjectiveCurve, One, Zero}; use algebra_core::{AffineCurve, Field, PairingEngine, ProjectiveCurve, One, Zero};
use rand_core::RngCore; use rand_core::RngCore;
use std::marker::PhantomData; use core::marker::PhantomData;
use std::collections::{BTreeMap, BTreeSet};
mod data_structures; mod data_structures;
pub use data_structures::*; pub use data_structures::*;
...@@ -473,7 +473,7 @@ impl<E: PairingEngine> PolynomialCommitment<E::Fr> for MarlinKZG10<E> { ...@@ -473,7 +473,7 @@ impl<E: PairingEngine> PolynomialCommitment<E::Fr> for MarlinKZG10<E> {
} }
// Some(_) > None, always. // Some(_) > None, always.
hiding_bound = std::cmp::max(hiding_bound, cur_poly.hiding_bound()); hiding_bound = core::cmp::max(hiding_bound, cur_poly.hiding_bound());
poly += (*coeff, cur_poly.polynomial()); poly += (*coeff, cur_poly.polynomial());
randomness += (*coeff, cur_rand); randomness += (*coeff, cur_rand);
...@@ -573,10 +573,10 @@ mod tests { ...@@ -573,10 +573,10 @@ mod tests {
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
use crate::marlin_kzg10::MarlinKZG10; use crate::marlin_kzg10::MarlinKZG10;
use algebra::curves::bls12_377::Bls12_377; use algebra::Bls12_377;
use algebra::curves::bls12_381::Bls12_381; use algebra::Bls12_381;
use algebra::curves::mnt6::MNT6; use algebra::MNT6;
use algebra::curves::sw6::SW6; use algebra::SW6;
type PC<E> = MarlinKZG10<E>; type PC<E> = MarlinKZG10<E>;
type PC_Bls12_381 = PC<Bls12_381>; type PC_Bls12_381 = PC<Bls12_381>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment