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< ::ScalarField>; l
(
powers: &Powers<E>,
polynomial: &P,
hiding_bound: Option<usize>,
rng: Option<&mut dyn RngCore>,
)
| 155 | /// assert!(!r.is_hiding(), "Commitment should not be hiding"); |
| 156 | /// ``` |
| 157 | pub fn commit( |
| 158 | powers: &Powers<E>, |
| 159 | polynomial: &P, |
| 160 | hiding_bound: Option<usize>, |
| 161 | rng: Option<&mut dyn RngCore>, |
| 162 | ) -> Result<(Commitment<E>, Randomness<E::ScalarField, P>), Error> { |
| 163 | Self::check_degree_is_too_large(polynomial.degree(), powers.size())?; |
| 164 | |
| 165 | let commit_time = start_timer!(|| format!( |
| 166 | "Committing to polynomial of degree {} with hiding_bound: {:?}", |
| 167 | polynomial.degree(), |
| 168 | hiding_bound, |
| 169 | )); |
| 170 | |
| 171 | let (num_leading_zeros, plain_coeffs) = |
| 172 | skip_leading_zeros_and_convert_to_bigints(polynomial); |
| 173 | |
| 174 | let msm_time = start_timer!(|| "MSM to compute commitment to plaintext poly"); |
| 175 | let mut commitment = <E::G1 as VariableBaseMSM>::msm_bigint( |
| 176 | &powers.powers_of_g[num_leading_zeros..], |
| 177 | &plain_coeffs, |
| 178 | ); |
| 179 | end_timer!(msm_time); |
| 180 | |
| 181 | let mut randomness = Randomness::<E::ScalarField, P>::empty(); |
| 182 | if let Some(hiding_degree) = hiding_bound { |
| 183 | let mut rng = rng.ok_or(Error::MissingRng)?; |
| 184 | let sample_random_poly_time = start_timer!(|| format!( |
| 185 | "Sampling a random polynomial of degree {}", |
| 186 | hiding_degree |
| 187 | )); |
| 188 | |
| 189 | randomness = Randomness::rand(hiding_degree, false, None, &mut rng); |
| 190 | Self::check_hiding_bound( |
| 191 | randomness.blinding_polynomial.degree(), |
| 192 | powers.powers_of_gamma_g.len(), |
| 193 | )?; |
| 194 | end_timer!(sample_random_poly_time); |
| 195 | } |
| 196 | |
| 197 | let random_ints = convert_to_bigints(&randomness.blinding_polynomial.coeffs()); |
| 198 | let msm_time = start_timer!(|| "MSM to compute commitment to random poly"); |
| 199 | let random_commitment = <E::G1 as VariableBaseMSM>::msm_bigint( |
| 200 | &powers.powers_of_gamma_g, |
| 201 | random_ints.as_slice(), |
| 202 | ) |
| 203 | .into_affine(); |
| 204 | end_timer!(msm_time); |
| 205 | |
| 206 | commitment += &random_commitment; |
| 207 | |
| 208 | end_timer!(commit_time); |
| 209 | Ok((Commitment(commitment.into()), randomness)) |
| 210 | } |
| 211 | |
| 212 | /// Compute witness polynomial. |
| 213 | /// |
nothing calls this directly
no test coverage detected