Skip to content
Closed
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
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rand_core = { version = "0.5", default-features = false }
digest = "0.8"
rayon = { version = "1", optional = true }
derivative = { version = "2", features = [ "use_core" ] }
combinations = { git = "https://github.com/ryanleh/uniquecombinations", version = "0.1.0"}

[dev-dependencies]
rand = { version = "0.7", default-features = false }
Expand All @@ -39,6 +40,12 @@ ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves", default-feature
ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves", default-features = false, features = [ "curve" ] }
blake2 = { version = "0.8", default-features = false }

[patch.'https://github.com/arkworks-rs/algebra']
ark-serialize = { git = "https://github.com/ryanleh/algebra", branch = "multivariate-support", default-features = false }
ark-ff = { git = "https://github.com/ryanleh/algebra", branch = "multivariate-support", default-features = false }
ark-ec = { git = "https://github.com/ryanleh/algebra", branch = "multivariate-support", default-features = false }
ark-poly = { git = "https://github.com/ryanleh/algebra", branch = "multivariate-support", default-features = false }

[profile.release]
opt-level = 3
lto = "thin"
Expand Down
47 changes: 31 additions & 16 deletions src/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{Cow, String, Vec};
use crate::{Cow, Polynomial, String, Vec};
use ark_ff::Field;
pub use ark_poly::DensePolynomial as Polynomial;
use core::borrow::Borrow;
use core::ops::{AddAssign, MulAssign, SubAssign};
use ark_std::{
borrow::Borrow,
marker::PhantomData,
ops::{AddAssign, MulAssign, SubAssign},
};
use rand_core::RngCore;

/// Labels a `LabeledPolynomial` or a `LabeledCommitment`.
Expand Down Expand Up @@ -59,8 +61,14 @@ pub trait PCRandomness: Clone {
/// Samples randomness for commitments;
/// `num_queries` specifies the number of queries that the commitment will be opened at.
/// `has_degree_bound` indicates that the corresponding commitment has an enforced
/// `num_vars` specifies the number of variables for multivariate commitment.
/// strict degree bound.
fn rand<R: RngCore>(num_queries: usize, has_degree_bound: bool, rng: &mut R) -> Self;
fn rand<R: RngCore>(
num_queries: usize,
has_degree_bound: bool,
num_vars: Option<usize>,
rng: &mut R,
) -> Self;
}

/// Defines the minimal interface of evaluation proofs for any polynomial
Expand All @@ -74,42 +82,43 @@ pub trait PCProof: Clone + ark_ff::ToBytes {
/// maximum number of queries that will be made to it. This latter number determines
/// the amount of protection that will be provided to a commitment for this polynomial.
#[derive(Debug, Clone)]
pub struct LabeledPolynomial<'a, F: Field> {
pub struct LabeledPolynomial<'a, F: Field, P: Polynomial<F>> {
label: PolynomialLabel,
polynomial: Cow<'a, Polynomial<F>>,
polynomial: Cow<'a, P>,
degree_bound: Option<usize>,
hiding_bound: Option<usize>,
_field: PhantomData<F>,
}

impl<'a, F: Field> core::ops::Deref for LabeledPolynomial<'a, F> {
type Target = Polynomial<F>;
impl<'a, F: Field, P: Polynomial<F>> core::ops::Deref for LabeledPolynomial<'a, F, P> {
type Target = P;

fn deref(&self) -> &Self::Target {
&self.polynomial
}
}

impl<'a, F: Field> LabeledPolynomial<'a, F> {
impl<'a, F: Field, P: Polynomial<F>> LabeledPolynomial<'a, F, P> {
/// Construct a new labeled polynomial by consuming `polynomial`.
pub fn new_owned(
label: PolynomialLabel,
polynomial: Polynomial<F>,
polynomial: P,
degree_bound: Option<usize>,
hiding_bound: Option<usize>,
) -> Self {
Self {
label,
polynomial: Cow::Owned(polynomial),
degree_bound,

hiding_bound,
_field: PhantomData,
}
}

/// Construct a new labeled polynomial.
pub fn new(
label: PolynomialLabel,
polynomial: &'a Polynomial<F>,
polynomial: &'a P,
degree_bound: Option<usize>,
hiding_bound: Option<usize>,
) -> Self {
Expand All @@ -118,6 +127,7 @@ impl<'a, F: Field> LabeledPolynomial<'a, F> {
polynomial: Cow::Borrowed(polynomial),
degree_bound,
hiding_bound,
_field: PhantomData,
}
}

Expand All @@ -126,16 +136,21 @@ impl<'a, F: Field> LabeledPolynomial<'a, F> {
&self.label
}

/// Retrieve the polynomial from `self`.
pub fn polynomial(&self) -> &Polynomial<F> {
/// Retrieve the polynomial from `self`
pub fn polynomial(&self) -> &P {
&self.polynomial
}

/// Evaluate the polynomial in `self`.
pub fn evaluate(&self, point: F) -> F {
pub fn evaluate(&self, point: &P::Point) -> F {
self.polynomial.evaluate(point)
}

/// Retrieve the degree of the polynomial in `self`.
pub fn degree(&self) -> usize {
self.polynomial.degree()
}

/// Retrieve the degree bound in `self`.
pub fn degree_bound(&self) -> Option<usize> {
self.degree_bound
Expand Down
36 changes: 35 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ pub enum Error {

/// The commitment was generated incorrectly, tampered with, or doesn't support the polynomial.
MalformedCommitment(String),

/// Attempted to cast `Polynomial` to wrong underlying polynomial type
InvalidPolynomialType,

/// An invalid number of variables was provided to `setup`
InvalidNumberOfVariables,

/// The degree of the `index`-th polynomial passed to `commit`, `open`
/// or `check` was incorrect, that is, `supported_degree <= poly_degree`
PolynomialDegreeTooLarge {
/// Degree of the polynomial.
poly_degree: usize,
/// Maximum supported degree.
supported_degree: usize,
/// Index of the offending polynomial.
label: String,
},
}

impl core::fmt::Display for Error {
Expand Down Expand Up @@ -154,8 +171,25 @@ impl core::fmt::Display for Error {
supported degree ({:?})",
degree_bound, label, poly_degree, supported_degree
),
Error::InvalidPolynomialType => write!(
f,
"Attempted to cast `Polynomial` to wrong underlying polynomial type"
),
Error::InvalidNumberOfVariables => write!(
f,
"An invalid number of variables was provided to `setup`"
),
Error::PolynomialDegreeTooLarge {
poly_degree,
supported_degree,
label,
} => write!(
f,
"the polynomial {} has degree {:?}, but parameters only
support up to degree ({:?})", label, poly_degree, supported_degree
),
Error::IncorrectInputLength(err) => write!(f, "{}", err),
Error::MalformedCommitment(err) => write!(f, "{}", err)
Error::MalformedCommitment(err) => write!(f, "{}", err),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ipa_pc/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<G: AffineCurve> PCRandomness for Randomness<G> {
}
}

fn rand<R: RngCore>(_num_queries: usize, has_degree_bound: bool, rng: &mut R) -> Self {
fn rand<R: RngCore>(_: usize, has_degree_bound: bool, _: Option<usize>, rng: &mut R) -> Self {
let rand = G::ScalarField::rand(rng);
let shifted_rand = if has_degree_bound {
Some(G::ScalarField::rand(rng))
Expand Down
Loading