remove domain from kzg commit

This commit is contained in:
M Alghazwi 2025-07-03 11:59:30 +02:00
parent 2610b41834
commit be89b3be77
3 changed files with 25 additions and 56 deletions

View File

@ -1,15 +1,15 @@
use ark_poly::univariate::DensePolynomial; use ark_poly::univariate::DensePolynomial;
use ark_poly::{DenseUVPolynomial, EvaluationDomain, GeneralEvaluationDomain}; use ark_poly::DenseUVPolynomial;
use ark_poly_commit::{ use ark_poly_commit::{
LabeledPolynomial, LabeledPolynomial,
}; };
use ark_std::test_rng; use ark_std::test_rng;
use anyhow::{anyhow, Result}; use anyhow::Result;
use ark_bls12_381::Bls12_381; use ark_bls12_381::Bls12_381;
use ark_ec::pairing::Pairing; use ark_ec::pairing::Pairing;
use ark_ec::{AffineRepr, CurveGroup}; use ark_ec::{AffineRepr, CurveGroup};
use ark_ff::{PrimeField, Zero}; use ark_ff::{PrimeField, Zero};
use crate::traits::{CommitOutputTrait, PolyCommScheme, SRSTrait}; use crate::traits::{CommitOutputTrait, PolyCommScheme};
use ark_poly_commit::kzg10::{KZG10, Proof, UniversalParams, Powers, VerifierKey, Commitment, Randomness}; use ark_poly_commit::kzg10::{KZG10, Proof, UniversalParams, Powers, VerifierKey, Commitment, Randomness};
pub type E = Bls12_381; pub type E = Bls12_381;
@ -17,31 +17,7 @@ pub type F = <E as Pairing>::ScalarField;
pub type UniPoly381 = DensePolynomial<F>; pub type UniPoly381 = DensePolynomial<F>;
pub type PCS = KZG10<E, UniPoly381>; pub type PCS = KZG10<E, UniPoly381>;
pub struct KZG10SRS { pub type KZG10SRS = UniversalParams<E>;
pub poly_domain: GeneralEvaluationDomain<F>,
pub pp: UniversalParams<E>
}
impl SRSTrait<F> for KZG10SRS{
type PP = UniversalParams<E>;
type Domain = GeneralEvaluationDomain<F>;
fn get_pp(&self) -> &Self::PP {
&self.pp
}
fn get_domain(&self) -> &Self::Domain {
&self.poly_domain
}
fn get_domain_element(&self, idx:usize) -> F {
self.poly_domain.element(idx)
}
fn get_domain_size(&self) -> usize{
self.poly_domain.size()
}
}
pub struct KZG10PolyComm {} pub struct KZG10PolyComm {}
@ -86,7 +62,7 @@ impl CommitOutputTrait for KZG10CommitOutput {
impl KZG10PolyComm{ impl KZG10PolyComm{
fn commit_single(srs: &KZG10SRS, input: F, index: usize) -> Result<Commitment<E>> { fn commit_single(srs: &KZG10SRS, input: F, index: usize) -> Result<Commitment<E>> {
let power = &srs.pp.powers_of_g[index]; let power = &srs.powers_of_g[index];
let c = power.mul_bigint(input.into_bigint()); let c = power.mul_bigint(input.into_bigint());
@ -106,17 +82,13 @@ impl PolyCommScheme<F> for KZG10PolyComm {
fn setup(degree: usize) -> Result<Self::SRS> { fn setup(degree: usize) -> Result<Self::SRS> {
let rng = &mut test_rng(); let rng = &mut test_rng();
let pp = PCS::setup(degree,false, rng)?; let pp = PCS::setup(degree,false, rng)?;
let poly_domain = EvaluationDomain::<F>::new(degree).ok_or(anyhow!("polycommit domain error"))?; Ok(pp)
Ok(KZG10SRS {
poly_domain,
pp,
})
} }
fn commit(srs: &Self::SRS, input: Vec<F>) -> Result<Self::CommitOutput> { fn commit(srs: &Self::SRS, input: Vec<F>) -> Result<Self::CommitOutput> {
let rng = &mut test_rng(); let rng = &mut test_rng();
let degree = srs.poly_domain.size(); let degree = input.len();
let powers = get_powers(&srs.pp, degree)?; let powers = get_powers(&srs, degree)?;
// input are poly coeffs // input are poly coeffs
let input_poly = DensePolynomial::<F>::from_coefficients_vec(input); let input_poly = DensePolynomial::<F>::from_coefficients_vec(input);
@ -165,8 +137,8 @@ impl PolyCommScheme<F> for KZG10PolyComm {
) -> Result<Self::Proof> { ) -> Result<Self::Proof> {
// powers from the srs // powers from the srs
let m = srs.poly_domain.size(); let m = srs.powers_of_g.len();
let powers= get_powers(&srs.pp, m)?; let powers= get_powers(&srs, m)?;
// get row poly and rand // get row poly and rand
let poly = &comm.poly; let poly = &comm.poly;

View File

@ -2,7 +2,7 @@ use std::marker::PhantomData;
use anyhow::Result; use anyhow::Result;
use ark_ff::Field; use ark_ff::Field;
use crate::field_matrix::Matrix; use crate::field_matrix::Matrix;
use crate::traits::{MatrixPolyCommScheme, DataMatrix, PolyCommScheme, SRSTrait, MatrixCommitOutput}; use crate::traits::{MatrixPolyCommScheme, DataMatrix, PolyCommScheme, MatrixCommitOutput};
pub struct MatrixPolyComm<F, P: PolyCommScheme<F>> { pub struct MatrixPolyComm<F, P: PolyCommScheme<F>> {
@ -44,7 +44,6 @@ impl<F: Field + Clone, P: PolyCommScheme<F>> MatrixPolyCommScheme<F, P> for Matr
) -> Result<()> { ) -> Result<()> {
// check input is consistent // check input is consistent
assert_eq!(old_col.len(), new_col.len(), "col sizes don't match"); assert_eq!(old_col.len(), new_col.len(), "col sizes don't match");
assert_eq!(srs.get_domain_size(), new_col.len(), "domain size is incorrect");
// loop through all new_col elements to see if there is an update at each cell // loop through all new_col elements to see if there is an update at each cell
// if there is, then update the commitment // if there is, then update the commitment
@ -57,9 +56,7 @@ impl<F: Field + Clone, P: PolyCommScheme<F>> MatrixPolyCommScheme<F, P> for Matr
Ok(()) Ok(())
} }
fn open(comm: &MatrixCommitOutput<F, P>, srs: &P::SRS, row: usize, col: usize) -> Result<P::Proof> { fn open(comm: &MatrixCommitOutput<F, P>, srs: &P::SRS, row: usize, point: F) -> Result<P::Proof> {
// the point we want to open
let point = srs.get_domain_element(col);
let proof = P::open(&comm.comm_output[row], srs, point)?; let proof = P::open(&comm.comm_output[row], srs, point)?;

View File

@ -39,21 +39,21 @@ pub trait CommitOutputTrait {
fn get_rand(&self) -> &Self::Rand; fn get_rand(&self) -> &Self::Rand;
} }
pub trait SRSTrait<F>{ // pub trait SRSTrait<F>{
// public/universal params // // public/universal params
type PP; // type PP;
// domain type // // domain type
type Domain; // type Domain;
//
fn get_pp(&self) -> &Self::PP; // fn get_pp(&self) -> &Self::PP;
fn get_domain(&self) -> &Self::Domain; // fn get_domain(&self) -> &Self::Domain;
fn get_domain_element(&self, idx: usize) -> F; // fn get_domain_element(&self, idx: usize) -> F;
fn get_domain_size(&self) -> usize; // fn get_domain_size(&self) -> usize;
} // }
/// Polynomial Commitment scheme (e.g. KZG) trait /// Polynomial Commitment scheme (e.g. KZG) trait
pub trait PolyCommScheme<F>{ pub trait PolyCommScheme<F>{
type SRS: SRSTrait<F>; type SRS;
type VK; type VK;
type CommitOutput: CommitOutputTrait; type CommitOutput: CommitOutputTrait;
type Comm; type Comm;
@ -95,7 +95,7 @@ pub trait MatrixPolyCommScheme<F, P:PolyCommScheme<F>>{
comm: &MatrixCommitOutput<F, P>, comm: &MatrixCommitOutput<F, P>,
srs: &P::SRS, srs: &P::SRS,
row: usize, row: usize,
col: usize, point: F,
) -> Result<P::Proof>; ) -> Result<P::Proof>;
fn verify( fn verify(
vk: &P::VK, vk: &P::VK,