Skip to content

Commit

Permalink
chore: Rename UV(KZG{ProverKey, VerifierKey}|UniversalKZGParam) -> \1
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Dec 12, 2023
1 parent b8d2ba9 commit 9f29b52
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/provider/kzg_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::traits::{
};

use crate::provider::{
non_hiding_kzg::{UVKZGCommitment, UVUniversalKZGParam},
non_hiding_kzg::{UVKZGCommitment, UniversalKZGParam},
pedersen::Commitment,
traits::DlogGroup,
};
Expand All @@ -35,7 +35,7 @@ where
E::G2Affine: Serialize + for<'de> Deserialize<'de>,
E::Fr: PrimeFieldBits, // TODO due to use of gen_srs_for_testing, make optional
{
type CommitmentKey = UVUniversalKZGParam<E>;
type CommitmentKey = UniversalKZGParam<E>;
type Commitment = Commitment<NE>;

fn setup(label: &'static [u8], n: usize) -> Self::CommitmentKey {
Expand All @@ -44,7 +44,7 @@ where
let len = label.len().min(32);
bytes[..len].copy_from_slice(&label[..len]);
let rng = &mut StdRng::from_seed(bytes);
UVUniversalKZGParam::gen_srs_for_testing(rng, n.next_power_of_two())
UniversalKZGParam::gen_srs_for_testing(rng, n.next_power_of_two())
}

fn commit(ck: &Self::CommitmentKey, v: &[<E::G1 as Group>::Scalar]) -> Self::Commitment {
Expand Down
19 changes: 9 additions & 10 deletions src/provider/mlkzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
errors::NovaError,
provider::{
kzg_commitment::KZGCommitmentEngine,
non_hiding_kzg::{UVKZGProverKey, UVKZGVerifierKey, UVUniversalKZGParam},
non_hiding_kzg::{KZGProverKey, KZGVerifierKey, UniversalKZGParam},
pedersen::Commitment,
traits::DlogGroup,
},
Expand Down Expand Up @@ -120,15 +120,15 @@ where
E::G1Affine: TranscriptReprTrait<E::G1>,
{
type EvaluationArgument = EvaluationArgument<E>;
type ProverKey = UVKZGProverKey<E>;
type VerifierKey = UVKZGVerifierKey<E>;
type ProverKey = KZGProverKey<E>;
type VerifierKey = KZGVerifierKey<E>;

fn setup(ck: &UVUniversalKZGParam<E>) -> (Self::ProverKey, Self::VerifierKey) {
fn setup(ck: &UniversalKZGParam<E>) -> (Self::ProverKey, Self::VerifierKey) {
ck.trim(ck.length() - 1)
}

fn prove(
ck: &UVUniversalKZGParam<E>,
ck: &UniversalKZGParam<E>,
_pk: &Self::ProverKey,
transcript: &mut <NE as NovaEngine>::TE,
C: &Commitment<NE>,
Expand Down Expand Up @@ -314,7 +314,7 @@ where

// vk is hashed in transcript already, so we do not add it here

let kzg_verify_batch = |vk: &UVKZGVerifierKey<E>,
let kzg_verify_batch = |vk: &KZGVerifierKey<E>,
C: &Vec<E::G1Affine>,
W: &Vec<E::G1Affine>,
u: &Vec<E::Fr>,
Expand Down Expand Up @@ -456,7 +456,7 @@ mod tests {
let n = 4;
let ck: CommitmentKey<NE> =
<KZGCommitmentEngine<E> as CommitmentEngineTrait<NE>>::setup(b"test", n);
let (pk, _vk): (UVKZGProverKey<E>, UVKZGVerifierKey<E>) = EvaluationEngine::<E, NE>::setup(&ck);
let (pk, _vk): (KZGProverKey<E>, KZGVerifierKey<E>) = EvaluationEngine::<E, NE>::setup(&ck);

// poly is in eval. representation; evaluated at [(0,0), (0,1), (1,0), (1,1)]
let poly = vec![Fr::from(1), Fr::from(2), Fr::from(2), Fr::from(4)];
Expand Down Expand Up @@ -511,7 +511,7 @@ mod tests {

let ck: CommitmentKey<NE> =
<KZGCommitmentEngine<E> as CommitmentEngineTrait<NE>>::setup(b"test", n);
let (pk, vk): (UVKZGProverKey<E>, UVKZGVerifierKey<E>) = EvaluationEngine::<E, NE>::setup(&ck);
let (pk, vk): (KZGProverKey<E>, KZGVerifierKey<E>) = EvaluationEngine::<E, NE>::setup(&ck);

// make a commitment
let C = KZGCommitmentEngine::commit(&ck, &poly);
Expand Down Expand Up @@ -579,8 +579,7 @@ mod tests {

let ck: CommitmentKey<NE> =
<KZGCommitmentEngine<E> as CommitmentEngineTrait<NE>>::setup(b"test", n);
let (pk, vk): (UVKZGProverKey<E>, UVKZGVerifierKey<E>) =
EvaluationEngine::<E, NE>::setup(&ck);
let (pk, vk): (KZGProverKey<E>, KZGVerifierKey<E>) = EvaluationEngine::<E, NE>::setup(&ck);

// make a commitment
let C = <KZGCommitmentEngine<E> as CommitmentEngineTrait<NE>>::commit(&ck, &poly);
Expand Down
38 changes: 19 additions & 19 deletions src/provider/non_hiding_kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
deserialize = "E::G1Affine: Deserialize<'de>, E::G2Affine: Deserialize<'de>"
))]
#[abomonation_omit_bounds]
pub struct UVUniversalKZGParam<E: Engine> {
pub struct UniversalKZGParam<E: Engine> {
/// Group elements of the form `{ β^i G }`, where `i` ranges from 0 to
/// `degree`.
#[abomonate_with(Vec<[u64; 8]>)] // // this is a hack; we just assume the size of the element.
Expand All @@ -32,14 +32,14 @@ pub struct UVUniversalKZGParam<E: Engine> {
pub powers_of_h: Vec<E::G2Affine>,
}

impl<E: Engine> PartialEq for UVUniversalKZGParam<E> {
fn eq(&self, other: &UVUniversalKZGParam<E>) -> bool {
impl<E: Engine> PartialEq for UniversalKZGParam<E> {
fn eq(&self, other: &UniversalKZGParam<E>) -> bool {
self.powers_of_g == other.powers_of_g && self.powers_of_h == other.powers_of_h
}
}

// for the purpose of the Len trait, we count commitment bases, i.e. G1 elements
impl<E: Engine> Len for UVUniversalKZGParam<E> {
impl<E: Engine> Len for UniversalKZGParam<E> {
fn length(&self) -> usize {
self.powers_of_g.len()
}
Expand All @@ -52,7 +52,7 @@ impl<E: Engine> Len for UVUniversalKZGParam<E> {
serialize = "E::G1Affine: Serialize",
deserialize = "E::G1Affine: Deserialize<'de>"
))]
pub struct UVKZGProverKey<E: Engine> {
pub struct KZGProverKey<E: Engine> {
/// generators
#[abomonate_with(Vec<[u64; 8]>)] // this is a hack; we just assume the size of the element.
pub powers_of_g: Vec<E::G1Affine>,
Expand All @@ -66,7 +66,7 @@ pub struct UVKZGProverKey<E: Engine> {
serialize = "E::G1Affine: Serialize, E::G2Affine: Serialize",
deserialize = "E::G1Affine: Deserialize<'de>, E::G2Affine: Deserialize<'de>"
))]
pub struct UVKZGVerifierKey<E: Engine> {
pub struct KZGVerifierKey<E: Engine> {
/// The generator of G1.
#[abomonate_with([u64; 8])] // this is a hack; we just assume the size of the element.
pub g: E::G1Affine,
Expand All @@ -78,7 +78,7 @@ pub struct UVKZGVerifierKey<E: Engine> {
pub beta_h: E::G2Affine,
}

impl<E: Engine> UVUniversalKZGParam<E> {
impl<E: Engine> UniversalKZGParam<E> {
/// Returns the maximum supported degree
pub fn max_degree(&self) -> usize {
self.powers_of_g.len()
Expand All @@ -88,21 +88,21 @@ impl<E: Engine> UVUniversalKZGParam<E> {
///
/// # Panics
/// if `supported_size` is greater than `self.max_degree()`
pub fn extract_prover_key(&self, supported_size: usize) -> UVKZGProverKey<E> {
pub fn extract_prover_key(&self, supported_size: usize) -> KZGProverKey<E> {
let powers_of_g = self.powers_of_g[..=supported_size].to_vec();
UVKZGProverKey { powers_of_g }
KZGProverKey { powers_of_g }
}

/// Returns the verifier parameters
///
/// # Panics
/// If self.prover_params is empty.
pub fn extract_verifier_key(&self, supported_size: usize) -> UVKZGVerifierKey<E> {
pub fn extract_verifier_key(&self, supported_size: usize) -> KZGVerifierKey<E> {
assert!(
self.powers_of_g.len() >= supported_size,
"supported_size is greater than self.max_degree()"
);
UVKZGVerifierKey {
KZGVerifierKey {
g: self.powers_of_g[0],
h: self.powers_of_h[0],
beta_h: self.powers_of_h[1],
Expand All @@ -116,11 +116,11 @@ impl<E: Engine> UVUniversalKZGParam<E> {
///
/// # Panics
/// If `supported_size` is greater than `self.max_degree()`, or `self.max_degree()` is zero.
pub fn trim(&self, supported_size: usize) -> (UVKZGProverKey<E>, UVKZGVerifierKey<E>) {
pub fn trim(&self, supported_size: usize) -> (KZGProverKey<E>, KZGVerifierKey<E>) {
let powers_of_g = self.powers_of_g[..=supported_size].to_vec();

let pk = UVKZGProverKey { powers_of_g };
let vk = UVKZGVerifierKey {
let pk = KZGProverKey { powers_of_g };
let vk = KZGVerifierKey {
g: self.powers_of_g[0],
h: self.powers_of_h[0],
beta_h: self.powers_of_h[1],
Expand All @@ -129,7 +129,7 @@ impl<E: Engine> UVUniversalKZGParam<E> {
}
}

impl<E: Engine> UVUniversalKZGParam<E>
impl<E: Engine> UniversalKZGParam<E>
where
E::Fr: PrimeFieldBits,
{
Expand Down Expand Up @@ -239,7 +239,7 @@ where
/// Generate a commitment for a polynomial
/// Note that the scheme is not hidding
pub fn commit(
prover_param: impl Borrow<UVKZGProverKey<E>>,
prover_param: impl Borrow<KZGProverKey<E>>,
poly: &UVKZGPoly<E::Fr>,
) -> Result<UVKZGCommitment<E>, NovaError> {
let prover_param = prover_param.borrow();
Expand All @@ -257,7 +257,7 @@ where
/// On input a polynomial `p` and a point `point`, outputs a proof for the
/// same.
pub fn open(
prover_param: impl Borrow<UVKZGProverKey<E>>,
prover_param: impl Borrow<KZGProverKey<E>>,
polynomial: &UVKZGPoly<E::Fr>,
point: &E::Fr,
) -> Result<(UVKZGProof<E>, UVKZGEvaluation<E>), NovaError> {
Expand Down Expand Up @@ -287,7 +287,7 @@ where
/// committed inside `comm`.
#[allow(dead_code)]
pub fn verify(
verifier_param: impl Borrow<UVKZGVerifierKey<E>>,
verifier_param: impl Borrow<KZGVerifierKey<E>>,
commitment: &UVKZGCommitment<E>,
point: &E::Fr,
proof: &UVKZGProof<E>,
Expand Down Expand Up @@ -334,7 +334,7 @@ mod tests {
let mut rng = &mut thread_rng();
let degree = rng.gen_range(2..20);

let pp = UVUniversalKZGParam::<E>::gen_srs_for_testing(&mut rng, degree);
let pp = UniversalKZGParam::<E>::gen_srs_for_testing(&mut rng, degree);
let (ck, vk) = pp.trim(degree);
let p = random(degree, rng);
let comm = UVKZGPCS::<E>::commit(&ck, &p)?;
Expand Down
22 changes: 11 additions & 11 deletions src/provider/non_hiding_zeromorph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
errors::{NovaError, PCSError},
provider::{
non_hiding_kzg::{
UVKZGCommitment, UVKZGEvaluation, UVKZGPoly, UVKZGProof, UVKZGProverKey, UVKZGVerifierKey,
UVUniversalKZGParam, UVKZGPCS,
KZGProverKey, KZGVerifierKey, UVKZGCommitment, UVKZGEvaluation, UVKZGPoly, UVKZGProof,
UniversalKZGParam, UVKZGPCS,
},
traits::DlogGroup,
},
Expand Down Expand Up @@ -41,8 +41,8 @@ use crate::provider::kzg_commitment::KZGCommitmentEngine;
deserialize = "E::G1Affine: Deserialize<'de>"
))]
pub struct ZMProverKey<E: Engine> {
commit_pp: UVKZGProverKey<E>,
open_pp: UVKZGProverKey<E>,
commit_pp: KZGProverKey<E>,
open_pp: KZGProverKey<E>,
}

/// `ZMVerifierKey` is used to check evaluation proofs for a given
Expand All @@ -54,7 +54,7 @@ pub struct ZMProverKey<E: Engine> {
deserialize = "E::G1Affine: Deserialize<'de>, E::G2Affine: Deserialize<'de>"
))]
pub struct ZMVerifierKey<E: Engine> {
vp: UVKZGVerifierKey<E>,
vp: KZGVerifierKey<E>,
#[abomonate_with([u64; 16])] // this is a hack; we just assume the size of the element.
s_offset_h: E::G2Affine,
}
Expand All @@ -70,14 +70,14 @@ pub struct ZMVerifierKey<E: Engine> {
// TODO: important, we need a better way to handle that the commitment key should be 2^max_degree sized,
// see the runtime error in commit() below
pub fn trim<E: Engine>(
params: &UVUniversalKZGParam<E>,
params: &UniversalKZGParam<E>,
max_degree: usize,
) -> (ZMProverKey<E>, ZMVerifierKey<E>) {
let (commit_pp, vp) = params.trim(max_degree);
let offset = params.powers_of_g.len() - max_degree;
let open_pp = {
let offset_powers_of_g1 = params.powers_of_g[offset..].to_vec();
UVKZGProverKey {
KZGProverKey {
powers_of_g: offset_powers_of_g1,
}
};
Expand Down Expand Up @@ -474,12 +474,12 @@ where

type EvaluationArgument = ZMProof<E>;

fn setup(ck: &UVUniversalKZGParam<E>) -> (Self::ProverKey, Self::VerifierKey) {
fn setup(ck: &UniversalKZGParam<E>) -> (Self::ProverKey, Self::VerifierKey) {
trim(ck, ck.length() - 1)
}

fn prove(
_ck: &UVUniversalKZGParam<E>,
_ck: &UniversalKZGParam<E>,
pk: &Self::ProverKey,
transcript: &mut NE::TE,
comm: &Commitment<NE>,
Expand Down Expand Up @@ -529,7 +529,7 @@ mod test {
use crate::{
provider::{
keccak::Keccak256Transcript,
non_hiding_kzg::{UVKZGPoly, UVUniversalKZGParam},
non_hiding_kzg::{UVKZGPoly, UniversalKZGParam},
non_hiding_zeromorph::{
batched_lifted_degree_quotient, eval_and_quotient_scalars, trim, ZMEvaluation, ZMPCS,
},
Expand All @@ -549,7 +549,7 @@ mod test {
let max_vars = 16;
let mut rng = thread_rng();
let max_poly_size = 1 << (max_vars + 1);
let universal_setup = UVUniversalKZGParam::<E>::gen_srs_for_testing(&mut rng, max_poly_size);
let universal_setup = UniversalKZGParam::<E>::gen_srs_for_testing(&mut rng, max_poly_size);

for num_vars in 3..max_vars {
// Setup
Expand Down

0 comments on commit 9f29b52

Please sign in to comment.