diff --git a/src/kzg10.rs b/src/kzg10.rs index c62f285..13d7a83 100644 --- a/src/kzg10.rs +++ b/src/kzg10.rs @@ -1,15 +1,15 @@ use ark_poly::univariate::DensePolynomial; -use ark_poly::{DenseUVPolynomial, EvaluationDomain, GeneralEvaluationDomain}; +use ark_poly::DenseUVPolynomial; use ark_poly_commit::{ LabeledPolynomial, }; use ark_std::test_rng; -use anyhow::{anyhow, Result}; +use anyhow::Result; use ark_bls12_381::Bls12_381; use ark_ec::pairing::Pairing; use ark_ec::{AffineRepr, CurveGroup}; 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}; pub type E = Bls12_381; @@ -17,31 +17,7 @@ pub type F = ::ScalarField; pub type UniPoly381 = DensePolynomial; pub type PCS = KZG10; -pub struct KZG10SRS { - pub poly_domain: GeneralEvaluationDomain, - pub pp: UniversalParams -} - -impl SRSTrait for KZG10SRS{ - type PP = UniversalParams; - type Domain = GeneralEvaluationDomain; - - 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 type KZG10SRS = UniversalParams; pub struct KZG10PolyComm {} @@ -86,7 +62,7 @@ impl CommitOutputTrait for KZG10CommitOutput { impl KZG10PolyComm{ fn commit_single(srs: &KZG10SRS, input: F, index: usize) -> Result> { - let power = &srs.pp.powers_of_g[index]; + let power = &srs.powers_of_g[index]; let c = power.mul_bigint(input.into_bigint()); @@ -106,17 +82,13 @@ impl PolyCommScheme for KZG10PolyComm { fn setup(degree: usize) -> Result { let rng = &mut test_rng(); let pp = PCS::setup(degree,false, rng)?; - let poly_domain = EvaluationDomain::::new(degree).ok_or(anyhow!("polycommit domain error"))?; - Ok(KZG10SRS { - poly_domain, - pp, - }) + Ok(pp) } fn commit(srs: &Self::SRS, input: Vec) -> Result { let rng = &mut test_rng(); - let degree = srs.poly_domain.size(); - let powers = get_powers(&srs.pp, degree)?; + let degree = input.len(); + let powers = get_powers(&srs, degree)?; // input are poly coeffs let input_poly = DensePolynomial::::from_coefficients_vec(input); @@ -165,8 +137,8 @@ impl PolyCommScheme for KZG10PolyComm { ) -> Result { // powers from the srs - let m = srs.poly_domain.size(); - let powers= get_powers(&srs.pp, m)?; + let m = srs.powers_of_g.len(); + let powers= get_powers(&srs, m)?; // get row poly and rand let poly = &comm.poly; diff --git a/src/matrix_commit.rs b/src/matrix_commit.rs index d2c418f..83af65e 100644 --- a/src/matrix_commit.rs +++ b/src/matrix_commit.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use anyhow::Result; use ark_ff::Field; use crate::field_matrix::Matrix; -use crate::traits::{MatrixPolyCommScheme, DataMatrix, PolyCommScheme, SRSTrait, MatrixCommitOutput}; +use crate::traits::{MatrixPolyCommScheme, DataMatrix, PolyCommScheme, MatrixCommitOutput}; pub struct MatrixPolyComm> { @@ -44,7 +44,6 @@ impl> MatrixPolyCommScheme for Matr ) -> Result<()> { // check input is consistent 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 // if there is, then update the commitment @@ -57,9 +56,7 @@ impl> MatrixPolyCommScheme for Matr Ok(()) } - fn open(comm: &MatrixCommitOutput, srs: &P::SRS, row: usize, col: usize) -> Result { - // the point we want to open - let point = srs.get_domain_element(col); + fn open(comm: &MatrixCommitOutput, srs: &P::SRS, row: usize, point: F) -> Result { let proof = P::open(&comm.comm_output[row], srs, point)?; diff --git a/src/traits.rs b/src/traits.rs index bb9e3ce..ba82cce 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -39,21 +39,21 @@ pub trait CommitOutputTrait { fn get_rand(&self) -> &Self::Rand; } -pub trait SRSTrait{ - // public/universal params - type PP; - // domain type - type Domain; - - fn get_pp(&self) -> &Self::PP; - fn get_domain(&self) -> &Self::Domain; - fn get_domain_element(&self, idx: usize) -> F; - fn get_domain_size(&self) -> usize; -} +// pub trait SRSTrait{ +// // public/universal params +// type PP; +// // domain type +// type Domain; +// +// fn get_pp(&self) -> &Self::PP; +// fn get_domain(&self) -> &Self::Domain; +// fn get_domain_element(&self, idx: usize) -> F; +// fn get_domain_size(&self) -> usize; +// } /// Polynomial Commitment scheme (e.g. KZG) trait pub trait PolyCommScheme{ - type SRS: SRSTrait; + type SRS; type VK; type CommitOutput: CommitOutputTrait; type Comm; @@ -95,7 +95,7 @@ pub trait MatrixPolyCommScheme>{ comm: &MatrixCommitOutput, srs: &P::SRS, row: usize, - col: usize, + point: F, ) -> Result; fn verify( vk: &P::VK,