Implement proof generation

This commit is contained in:
Daniel Sanchez Quiros 2024-04-01 19:57:23 +02:00
parent da4420a46e
commit b5898aa958
1 changed files with 25 additions and 1 deletions

View File

@ -1,8 +1,12 @@
use crate::common::KzgRsError;
use ark_bls12_381::{Bls12_381, Fr};
use ark_poly::univariate::DensePolynomial;
use ark_poly_commit::kzg10::{Commitment, Powers, KZG10};
use ark_poly::{DenseUVPolynomial, EvaluationDomain, GeneralEvaluationDomain, Polynomial};
use ark_poly_commit::kzg10::{Commitment, Powers, Proof, KZG10};
use num_traits::One;
/// Commit to a polynomial where each of the evaluations are over `w(i)` for the degree
/// of the polynomial being omega (`w`) the root of unity (2^x).
pub fn commit_polynomial(
polynomial: &DensePolynomial<Fr>,
roots_of_unity: &Powers<Bls12_381>,
@ -12,6 +16,26 @@ pub fn commit_polynomial(
.map(|(commitment, _)| commitment)
}
/// Compute a witness polynomial in that satisfies `witness(x) = (f(x)-v)/(x-u)`
fn generate_element_proof(
element_index: usize,
polynomial: &DensePolynomial<Fr>,
roots_of_unity: &Powers<Bls12_381>,
domain: &GeneralEvaluationDomain<Fr>,
) -> Result<Proof<Bls12_381>, KzgRsError> {
let u = domain.element(element_index);
let v = polynomial.evaluate(&u);
let f_x_v = polynomial + &DensePolynomial::<Fr>::from_coefficients_vec(vec![-v]);
let x_u = DensePolynomial::<Fr>::from_coefficients_vec(vec![-u, Fr::one()]);
let witness_polynomial: DensePolynomial<_> = &f_x_v / &x_u;
let proof = commit_polynomial(&witness_polynomial, roots_of_unity)?;
let proof = Proof {
w: proof.0,
random_v: None,
};
Ok(proof)
}
#[cfg(test)]
mod test {
use crate::kzg::commit_polynomial;