Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Jul 21, 2022
1 parent 34ca74b commit 43b66b8
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 933 deletions.
22 changes: 10 additions & 12 deletions hyperplonk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//! Main module for the HyperPlonk PolyIOP.
use ark_ec::PairingEngine;
use ark_ff::PrimeField;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::{end_timer, start_timer, One, Zero};
use errors::HyperPlonkErrors;
use pcs::prelude::{
merge_polynomials, MultilinearCommitmentScheme, PCSErrors, StructuredReferenceString,
merge_polynomials, PolynomialCommitmentScheme, PCSErrors, StructuredReferenceString,
};
use poly_iop::{
prelude::{IOPTranscript, PermutationCheck, SumCheck, VPAuxInfo, ZeroCheck},
prelude::{ PermutationCheck, SumCheck, VPAuxInfo, ZeroCheck},
PolyIOP,
};
use selectors::SelectorRow;
Expand All @@ -33,7 +32,7 @@ pub trait HyperPlonkPIOP<E, PCS>:
SumCheck<E::Fr> + ZeroCheck<E::Fr> + PermutationCheck<E::Fr>
where
E: PairingEngine,
PCS: MultilinearCommitmentScheme<E, Transcript = Self::Transcript>,
PCS: PolynomialCommitmentScheme<E>,
{
type Parameters;
type ProvingKey;
Expand Down Expand Up @@ -97,7 +96,7 @@ where
impl<E, PCS> HyperPlonkPIOP<E, PCS> for PolyIOP<E::Fr>
where
E: PairingEngine,
PCS: MultilinearCommitmentScheme<E, Transcript = Self::Transcript>,
PCS: PolynomialCommitmentScheme<E>,
{
type Parameters = HyperPlonkParams;
type ProvingKey = HyperPlonkProvingKey<E, PCS>;
Expand Down Expand Up @@ -634,9 +633,9 @@ where
mod tests {
use super::*;
use crate::structs::CustomizedGates;
use ark_bls12_381::{Bls12_381};
use ark_std::test_rng;use ark_std::UniformRand;
use pcs::KZGMultilinearPC;
use ark_bls12_381::Bls12_381;
use ark_std::{test_rng, UniformRand};
use pcs::prelude::KZGMultilinearPCS;

#[test]
fn test_hyperplonk_e2e() -> Result<(), HyperPlonkErrors> {
Expand Down Expand Up @@ -675,12 +674,11 @@ mod tests {
log_n_wires,
gate_func,
};
let pcs_srs = KZGMultilinearPC::<E>::setup(&mut rng, 10)?;
let permutation:Vec<E::Fr> = (0..1<<nv).map(|_|E::Fr::rand(&mut rng)).collect();

let pcs_srs = KZGMultilinearPCS::<E>::setup(&mut rng, 10)?;
let permutation: Vec<E::Fr> = (0..1 << nv).map(|_| E::Fr::rand(&mut rng)).collect();

// generate pk and vks
let (pk, vk) = <PolyIOP<E::Fr> as HyperPlonkPIOP<E, KZGMultilinearPC<E>>>::preprocess(
let (pk, vk) = <PolyIOP<E::Fr> as HyperPlonkPIOP<E, KZGMultilinearPCS<E>>>::preprocess(
&params,
&pcs_srs,
&permutation,
Expand Down
8 changes: 2 additions & 6 deletions hyperplonk/src/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ impl<F: PrimeField> SelectorRow<'_, F> {

#[cfg(test)]
impl<'a, F: PrimeField> SelectorRow<'a, F> {


pub(crate) fn rand<R: RngCore>(rng: &mut R, num_vars: usize)->Self {
let slices:Vec<F> = (0..1<<num_vars).map(|_| F::rand(&mut rng)).collect();

pub(crate) fn rand<R: RngCore>(rng: &mut R, num_vars: usize) -> Self {
let slices: Vec<F> = (0..1 << num_vars).map(|_| F::rand(&mut rng)).collect();
}
}

8 changes: 4 additions & 4 deletions hyperplonk/src/structs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_ec::PairingEngine;
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use pcs::MultilinearCommitmentScheme;
use pcs::PolynomialCommitmentScheme;
use poly_iop::prelude::{PermutationCheck, ZeroCheck};
use std::rc::Rc;

Expand All @@ -27,7 +27,7 @@ pub struct HyperPlonkSubClaim<F: PrimeField, ZC: ZeroCheck<F>, PC: PermutationCh
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HyperPlonkProof<
E: PairingEngine,
PCS: MultilinearCommitmentScheme<E>,
PCS: PolynomialCommitmentScheme<E>,
ZC: ZeroCheck<E::Fr>,
PC: PermutationCheck<E::Fr>,
> {
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct HyperPlonkParams {
/// - the hyperplonk instance parameters
/// - the preprocessed polynomials output by the indexer
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: MultilinearCommitmentScheme<E>> {
pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
/// hyperplonk instance parameters
pub params: HyperPlonkParams,
/// the preprocessed permutation polynomials
Expand All @@ -110,7 +110,7 @@ pub struct HyperPlonkProvingKey<E: PairingEngine, PCS: MultilinearCommitmentSche
/// - the hyperplonk instance parameters
/// - the preprocessed polynomials output by the indexer
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HyperPlonkVerifyingKey<E: PairingEngine, PCS: MultilinearCommitmentScheme<E>> {
pub struct HyperPlonkVerifyingKey<E: PairingEngine, PCS: PolynomialCommitmentScheme<E>> {
/// hyperplonk instance parameters
pub params: HyperPlonkParams,
/// the parameters for PCS commitment
Expand Down
4 changes: 2 additions & 2 deletions pcs/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_bls12_381::{Bls12_381, Fr};
use ark_ff::UniformRand;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::test_rng;
use ark_std::{rc::Rc, test_rng};
use pcs::{
prelude::{KZGMultilinearPCS, PCSErrors, PolynomialCommitmentScheme},
StructuredReferenceString,
Expand All @@ -27,7 +27,7 @@ fn bench_pcs() -> Result<(), PCSErrors> {
10
};

let poly = DenseMultilinearExtension::rand(nv, &mut rng);
let poly = Rc::new(DenseMultilinearExtension::rand(nv, &mut rng));
let (ml_ck, ml_vk) = uni_params.0.trim(nv)?;
let (uni_ck, uni_vk) = uni_params.1.trim(nv)?;
let ck = (ml_ck, uni_ck);
Expand Down
Loading

0 comments on commit 43b66b8

Please sign in to comment.