Struct ark_poly_commit::kzg10::KZG10
source · 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 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> 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>where E: Unpin, P: Unpin,
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
Mutably borrows from an owned value. Read more