From 32aeaf8043fcf5e476744db8e199613afd9e41ef Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Tue, 2 Apr 2024 13:03:30 +0200 Subject: [PATCH] implement proof verification --- nomos-da/kzgrs/src/kzg.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nomos-da/kzgrs/src/kzg.rs b/nomos-da/kzgrs/src/kzg.rs index 07c96041..8221a0ba 100644 --- a/nomos-da/kzgrs/src/kzg.rs +++ b/nomos-da/kzgrs/src/kzg.rs @@ -1,9 +1,11 @@ use crate::common::KzgRsError; use ark_bls12_381::{Bls12_381, Fr}; +use ark_ec::pairing::Pairing; use ark_poly::univariate::DensePolynomial; use ark_poly::{DenseUVPolynomial, EvaluationDomain, GeneralEvaluationDomain, Polynomial}; -use ark_poly_commit::kzg10::{Commitment, Powers, Proof, KZG10}; +use ark_poly_commit::kzg10::{Commitment, Powers, Proof, UniversalParams, KZG10}; use num_traits::One; +use std::ops::{Mul, Neg}; /// 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). @@ -37,13 +39,20 @@ pub fn generate_element_proof( } pub fn verify_element_proof( + element_index: usize, element: &Fr, commitment: &Commitment, proof: &Proof, - element_index: usize, - roots_of_unity: &Powers, + domain: &GeneralEvaluationDomain, + global_parameters: &UniversalParams, ) -> bool { - todo!() + let u = domain.element(element_index); + let v = element; + let commitment_check_g1 = commitment.0 + global_parameters.powers_of_g[0].mul(v).neg(); + let proof_check_g2 = global_parameters.beta_h + global_parameters.h.mul(u).neg(); + let lhs = Bls12_381::pairing(commitment_check_g1, global_parameters.h); + let rhs = Bls12_381::pairing(proof.w, proof_check_g2); + lhs == rhs } #[cfg(test)]