pub struct KZG10<E: Pairing, P: DenseUVPolynomial<E::ScalarField>> { /* private fields */ }Expand description
KZG10 is an implementation of the polynomial commitment scheme of
Kate, Zaverucha and Goldbgerg
Implementations§
Source§impl<E, P> KZG10<E, P>where
E: Pairing,
P: DenseUVPolynomial<E::ScalarField, Point = E::ScalarField>,
for<'a, 'b> &'a P: Div<&'b P, Output = P>,
impl<E, P> KZG10<E, P>where
E: Pairing,
P: DenseUVPolynomial<E::ScalarField, Point = E::ScalarField>,
for<'a, 'b> &'a P: Div<&'b P, Output = P>,
Sourcepub fn setup<R: RngCore>(
max_degree: usize,
produce_g2_powers: bool,
rng: &mut R,
) -> Result<UniversalParams<E>, Error>
pub fn setup<R: RngCore>( max_degree: usize, produce_g2_powers: bool, rng: &mut R, ) -> Result<UniversalParams<E>, Error>
Constructs public parameters when given as input the maximum degree degree
for the polynomial commitment scheme.
§Examples
use ark_poly_commit::kzg10::KZG10;
use ark_bls12_381::Bls12_381;
use ark_bls12_381::Fr;
use ark_poly::univariate::DensePolynomial;
use ark_ec::pairing::Pairing;
use ark_std::test_rng;
type UniPoly_381 = DensePolynomial<<Bls12_381 as Pairing>::ScalarField>;
let rng = &mut test_rng();
let params = KZG10::<Bls12_381, UniPoly_381>::setup(10, false, rng).expect("Setup failed");Sourcepub fn commit(
powers: &Powers<'_, E>,
polynomial: &P,
hiding_bound: Option<usize>,
rng: Option<&mut dyn RngCore>,
) -> Result<(Commitment<E>, Randomness<E::ScalarField, P>), Error>
pub fn commit( powers: &Powers<'_, E>, polynomial: &P, hiding_bound: Option<usize>, rng: Option<&mut dyn RngCore>, ) -> Result<(Commitment<E>, Randomness<E::ScalarField, P>), Error>
Outputs a commitment to polynomial.
§Examples
use ark_poly_commit::kzg10::{KZG10, Powers};
use ark_bls12_381::Bls12_381;
use ark_bls12_381::Fr;
use ark_poly::DenseUVPolynomial;
use ark_poly::univariate::DensePolynomial;
use ark_ec::pairing::Pairing;
use ark_ec::AffineRepr;
use ark_std::test_rng;
use ark_std::Zero;
type UniPoly_381 = DensePolynomial<<Bls12_381 as Pairing>::ScalarField>;
let rng = &mut test_rng();
let params = KZG10::<Bls12_381, UniPoly_381>::setup(10, false, rng).expect("Setup failed");
let powers_of_g = params.powers_of_g[..=10].to_vec();
let powers_of_gamma_g = (0..=10)
.map(|i| params.powers_of_gamma_g[&i])
.collect();
let powers = Powers {
powers_of_g: ark_std::borrow::Cow::Owned(powers_of_g),
powers_of_gamma_g: ark_std::borrow::Cow::Owned(powers_of_gamma_g),
};
let secret_poly = UniPoly_381::rand(10, rng);
let (comm, r) = KZG10::<Bls12_381, UniPoly_381>::commit(&powers, &secret_poly, None, None).expect("Commitment failed");
assert!(!comm.0.is_zero(), "Commitment should not be zero");
assert!(!r.is_hiding(), "Commitment should not be hiding");Sourcepub fn compute_witness_polynomial(
p: &P,
point: P::Point,
randomness: &Randomness<E::ScalarField, P>,
) -> Result<(P, Option<P>), Error>
pub fn compute_witness_polynomial( p: &P, point: P::Point, randomness: &Randomness<E::ScalarField, P>, ) -> Result<(P, Option<P>), Error>
Compute witness polynomial.
The witness polynomial $w(x)$ the quotient of the division (p(x) - p(z)) / (x - z) Observe that this quotient does not change with $z$ because $p(z)$ is the remainder term. We can therefore omit $p(z)$ when computing the quotient.
Sourcepub fn open_with_witness_polynomial<'a>(
powers: &Powers<'_, E>,
point: P::Point,
randomness: &Randomness<E::ScalarField, P>,
witness_polynomial: &P,
hiding_witness_polynomial: Option<&P>,
) -> Result<Proof<E>, Error>
pub fn open_with_witness_polynomial<'a>( powers: &Powers<'_, E>, point: P::Point, randomness: &Randomness<E::ScalarField, P>, witness_polynomial: &P, hiding_witness_polynomial: Option<&P>, ) -> Result<Proof<E>, Error>
Yields a Proof with a witness polynomial.
Sourcepub fn open<'a>(
powers: &Powers<'_, E>,
p: &P,
point: P::Point,
rand: &Randomness<E::ScalarField, P>,
) -> Result<Proof<E>, Error>
pub fn open<'a>( powers: &Powers<'_, E>, p: &P, point: P::Point, rand: &Randomness<E::ScalarField, P>, ) -> Result<Proof<E>, Error>
On input a polynomial p and a point, outputs a Proof for the same.
Sourcepub fn check(
vk: &VerifierKey<E>,
comm: &Commitment<E>,
point: E::ScalarField,
value: E::ScalarField,
proof: &Proof<E>,
) -> Result<bool, Error>
pub fn check( vk: &VerifierKey<E>, comm: &Commitment<E>, point: E::ScalarField, value: E::ScalarField, proof: &Proof<E>, ) -> Result<bool, Error>
Verifies that value is the evaluation at point of the polynomial
committed inside comm.
Sourcepub fn batch_check<R: RngCore>(
vk: &VerifierKey<E>,
commitments: &[Commitment<E>],
points: &[E::ScalarField],
values: &[E::ScalarField],
proofs: &[Proof<E>],
rng: &mut R,
) -> Result<bool, Error>
pub fn batch_check<R: RngCore>( vk: &VerifierKey<E>, commitments: &[Commitment<E>], points: &[E::ScalarField], values: &[E::ScalarField], proofs: &[Proof<E>], rng: &mut R, ) -> Result<bool, Error>
Check that each proof_i in proofs is a valid proof of evaluation for
commitment_i at point_i.
Auto Trait Implementations§
impl<E, P> Freeze for KZG10<E, P>
impl<E, P> RefUnwindSafe for KZG10<E, P>where
E: RefUnwindSafe,
P: RefUnwindSafe,
impl<E, P> Send for KZG10<E, P>where
P: Send,
impl<E, P> Sync for KZG10<E, P>
impl<E, P> Unpin for KZG10<E, P>
impl<E, P> UnwindSafe for KZG10<E, P>where
E: UnwindSafe,
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more