Skip to content

Commit

Permalink
derive pk and vk from srs
Browse files Browse the repository at this point in the history
  • Loading branch information
PatStiles committed Nov 27, 2023
1 parent ac6d2ad commit 0306142
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/subprotocols/zeromorph/data_structures.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use ark_bn254::Bn254;
use ark_ec::{pairing::Pairing, CurveGroup};
use ark_ec::{pairing::Pairing, CurveGroup, Group};
use ark_std::rand::rngs::StdRng;
use ark_ff::UniformRand;
use lazy_static::lazy_static;
use rand_chacha::rand_core::SeedableRng;
use std::sync::{Arc, Mutex};

use crate::utils::math::Math;

//TODO: The SRS is set with a default value of ____ if this is to be changed (extended) use the cli arg and change it manually.
//TODO: add input specifiying monomial or lagrange basis
lazy_static! {
Expand All @@ -17,6 +19,8 @@ lazy_static! {
pub struct ZeromorphSRS<P: Pairing> {
g1: P::G1Affine,
g2: P::G2Affine,
tau_g1: P::G1Affine,
tau_g2: P::G2Affine,
g1_powers: Vec<P::G1Affine>,
g2_powers: Vec<P::G2Affine>,
}
Expand All @@ -26,29 +30,13 @@ impl<P: Pairing> ZeromorphSRS<P> {
fn compute_g_powers<G: CurveGroup>(tau: G::ScalarField, n: usize) -> Vec<G::Affine> {
let mut g_srs = vec![G::zero(); n - 1];

#[cfg(not(feature = "parallel"))]
let g_srs: Vec<G> = std::iter::once(G::generator())
.chain(g_srs.iter().scan(G::generator(), |state, _| {
*state *= &tau;
Some(*state)
}))
.collect();

#[cfg(feature = "parallel")]
{
use ark_ff::Field;
use ark_ff::Zero;
g_srs.push(G::zero());
parallelize(&mut g_srs, |g, start| {
let mut current_g: G = G::generator();
current_g = current_g.mul(tau.pow(&[start as u64]));
for g in g.iter_mut() {
*g = current_g;
current_g *= tau;
}
});
}

G::normalize_batch(&g_srs)
}

Expand All @@ -71,24 +59,25 @@ impl<P: Pairing> ZeromorphSRS<P> {
let tau = P::ScalarField::rand(rng);
let g1_powers = Self::compute_g_powers::<P::G1>(tau, N_MAX);
let g2_powers = Self::compute_g_powers::<P::G2>(tau, N_MAX);
ZeromorphSRS { g1: g1_powers[0], g2: g2_powers[0], g1_powers, g2_powers }
ZeromorphSRS { g1: P::G1::generator().into_affine(), g2: P::G2::generator().into_affine(), tau_g1: g1_powers[0], tau_g2: g2_powers[0], g1_powers, g2_powers }
}

pub fn get_verifier_key() -> ProverKey<P> {
todo!()
pub fn get_prover_key(&self) -> ProverKey<P> {
ProverKey { g1: self.g1, tau_1: self.tau_g1, g1_powers: self.g1_powers }
}

pub fn get_prover_key() -> VerifierKey<P> {
todo!()
pub fn get_verifier_key(&self, n_max: usize) -> VerifierKey<P> {
let idx = n_max - (2_usize.pow(n_max.log_2() as u32) - 1);
VerifierKey { g1: self.g1, g2: self.g2, tau_2: self.tau_g2, tau_N_max_sub_2_N: self.g2_powers[idx] }
}

}

pub struct ProverKey<P: Pairing> {
// generator
pub g1: P::G1Affine,
pub tau_1: P::G1Affine,
// random power of tau + g1 used for commitments
pub g1_tau_powers: Vec<P::G1Affine>,
pub g1_powers: Vec<P::G1Affine>,
}

pub struct VerifierKey<P: Pairing> {
Expand Down

0 comments on commit 0306142

Please sign in to comment.