Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCS crate moved to jellyfish repository #74

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"arithmetic",
"hyperplonk",
"pcs",
"poly-iop",
"transcript",
]
6 changes: 3 additions & 3 deletions hyperplonk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
poly-iop = { path = "../poly-iop" }
pcs = { path = "../pcs" }

ark-std = { version = "^0.3.0", default-features = false }
ark-ec = { version = "^0.3.0", default-features = false }
Expand All @@ -19,6 +18,7 @@ displaydoc = { version = "0.2.3", default-features = false }
transcript = { path = "../transcript" }
arithmetic = { path = "../arithmetic" }

jf-primitives = { git = "https://github.com/EspressoSystems/jellyfish", rev = "ff43209" }

[dev-dependencies]
ark-bls12-381 = { version = "0.3.0", default-features = false, features = [ "curve" ] }
Expand All @@ -36,12 +36,12 @@ parallel = [
"ark-poly/parallel",
"ark-ec/parallel",
"poly-iop/parallel",
"pcs/parallel",
"arithmetic/parallel",
"jf-primitives/parallel",
]
print-trace = [
"ark-std/print-trace",
"poly-iop/print-trace",
"pcs/print-trace",
"arithmetic/print-trace",
"jf-primitives/print-trace",
]
10 changes: 5 additions & 5 deletions hyperplonk/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use arithmetic::ArithErrors;
use ark_serialize::SerializationError;
use ark_std::string::String;
use displaydoc::Display;
use pcs::prelude::PCSErrors;
use jf_primitives::pcs::prelude::PCSError;
use poly_iop::prelude::PolyIOPErrors;
use transcript::TranscriptErrors;

Expand All @@ -24,7 +24,7 @@ pub enum HyperPlonkErrors {
/// PolyIOP error {0}
PolyIOPErrors(PolyIOPErrors),
/// PCS error {0}
PCSErrors(PCSErrors),
PCSError(PCSError),
/// Transcript error {0}
TranscriptError(TranscriptErrors),
/// Arithmetic Error: {0}
Expand All @@ -43,9 +43,9 @@ impl From<PolyIOPErrors> for HyperPlonkErrors {
}
}

impl From<PCSErrors> for HyperPlonkErrors {
fn from(e: PCSErrors) -> Self {
Self::PCSErrors(e)
impl From<PCSError> for HyperPlonkErrors {
fn from(e: PCSError) -> Self {
Self::PCSError(e)
}
}

Expand Down
48 changes: 27 additions & 21 deletions hyperplonk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ use crate::utils::{eval_f, prove_sanity_check};
use arithmetic::VPAuxInfo;
use ark_ec::PairingEngine;
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::{end_timer, log2, start_timer, One, Zero};
use ark_std::{
borrow::Borrow, end_timer, log2, marker::PhantomData, rc::Rc, start_timer, One, Zero,
};
use errors::HyperPlonkErrors;
use pcs::prelude::{compute_qx_degree, merge_polynomials, PCSErrors, PolynomialCommitmentScheme};
use jf_primitives::pcs::prelude::{
compute_qx_degree, merge_polynomials, PCSError, PolynomialCommitmentScheme,
};
use poly_iop::{
prelude::{identity_permutation_mle, PermutationCheck, ZeroCheck},
PolyIOP,
};
use std::{marker::PhantomData, rc::Rc};
use structs::{HyperPlonkIndex, HyperPlonkProof, HyperPlonkProvingKey, HyperPlonkVerifyingKey};
use transcript::IOPTranscript;
use utils::{build_f, gen_eval_point};
Expand Down Expand Up @@ -47,7 +50,7 @@ where
/// polynomial commitments
fn preprocess(
index: &Self::Index,
pcs_srs: &PCS::SRS,
pcs_srs: impl Borrow<PCS::SRS>,
) -> Result<(Self::ProvingKey, Self::VerifyingKey), HyperPlonkErrors>;

/// Generate HyperPlonk SNARK proof.
Expand All @@ -59,7 +62,7 @@ where
/// Outputs:
/// - The HyperPlonk SNARK proof.
fn prove(
pk: &Self::ProvingKey,
pk: impl Borrow<Self::ProvingKey>,
pub_input: &[E::Fr],
witnesses: &[WitnessColumn<E::Fr>],
) -> Result<Self::Proof, HyperPlonkErrors>;
Expand All @@ -73,7 +76,7 @@ where
/// Outputs:
/// - Return a boolean on whether the verification is successful
fn verify(
vk: &Self::VerifyingKey,
vk: impl Borrow<Self::VerifyingKey>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action required: vk is usually small so & might be fine, but perhaps for consistency it's better to use impl Borrow.

pub_input: &[E::Fr],
proof: &Self::Proof,
) -> Result<bool, HyperPlonkErrors>;
Expand All @@ -99,7 +102,7 @@ where

fn preprocess(
index: &Self::Index,
pcs_srs: &PCS::SRS,
pcs_srs: impl Borrow<PCS::SRS>,
) -> Result<(Self::ProvingKey, Self::VerifyingKey), HyperPlonkErrors> {
let num_vars = index.params.nv;
let log_num_witness_polys = index.params.log_n_wires;
Expand Down Expand Up @@ -133,7 +136,7 @@ where
let selector_com = selector_oracles
.iter()
.map(|poly| PCS::commit(&pcs_prover_param, poly))
.collect::<Result<Vec<PCS::Commitment>, PCSErrors>>()?;
.collect::<Result<Vec<PCS::Commitment>, PCSError>>()?;

Ok((
Self::ProvingKey {
Expand Down Expand Up @@ -186,10 +189,11 @@ where
///
/// TODO: this function is gigantic -- refactor it to smaller ones
fn prove(
pk: &Self::ProvingKey,
pk: impl Borrow<Self::ProvingKey>,
pub_input: &[E::Fr],
witnesses: &[WitnessColumn<E::Fr>],
) -> Result<Self::Proof, HyperPlonkErrors> {
let pk = pk.borrow();
let start = start_timer!(|| "hyperplonk proving");
let mut transcript = IOPTranscript::<E::Fr>::new(b"hyperplonk");

Expand Down Expand Up @@ -219,7 +223,8 @@ where
// transcript
// =======================================================================
let step = start_timer!(|| "commit witnesses");
let w_merged = merge_polynomials(&witness_polys)?;
// TODO(Chengyu): update `merge_polynomials` method in jellyfish repo.
let w_merged = Rc::new(merge_polynomials(&witness_polys)?);
if w_merged.num_vars != merged_nv {
return Err(HyperPlonkErrors::InvalidParameters(format!(
"merged witness poly has a different num_vars ({}) from expected ({})",
Expand Down Expand Up @@ -590,10 +595,11 @@ where
/// - check zero check evaluations
/// - public input consistency checks
fn verify(
vk: &Self::VerifyingKey,
vk: impl Borrow<Self::VerifyingKey>,
pub_input: &[E::Fr],
proof: &Self::Proof,
) -> Result<bool, HyperPlonkErrors> {
let vk = vk.borrow();
let start = start_timer!(|| "hyperplonk verification");

let mut transcript = IOPTranscript::<E::Fr>::new(b"hyperplonk");
Expand Down Expand Up @@ -925,7 +931,7 @@ mod tests {
};
use ark_bls12_381::Bls12_381;
use ark_std::test_rng;
use pcs::prelude::KZGMultilinearPCS;
use jf_primitives::pcs::prelude::MultilinearKzgPCS;
use poly_iop::prelude::random_permutation_mle;

#[test]
Expand Down Expand Up @@ -957,7 +963,7 @@ mod tests {
gate_func: CustomizedGates,
) -> Result<(), HyperPlonkErrors> {
let mut rng = test_rng();
let pcs_srs = KZGMultilinearPCS::<E>::gen_srs_for_testing(&mut rng, 15)?;
let pcs_srs = MultilinearKzgPCS::<E>::gen_srs_for_testing(&mut rng, 15)?;
let merged_nv = nv + log_n_wires;

// generate index
Expand All @@ -977,7 +983,7 @@ mod tests {
};

// generate pk and vks
let (pk, vk) = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, KZGMultilinearPCS<E>>>::preprocess(
let (pk, vk) = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::preprocess(
&index, &pcs_srs,
)?;

Expand All @@ -999,38 +1005,38 @@ mod tests {
let pi = w1.clone();

// generate a proof and verify
let proof = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, KZGMultilinearPCS<E>>>::prove(
let proof = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::prove(
&pk,
&pi.0,
&[w1.clone(), w2.clone()],
)?;

let _verify = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, KZGMultilinearPCS<E>>>::verify(
let _verify = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::verify(
&vk, &pi.0, &proof,
)?;

// bad path 1: wrong permutation
let rand_perm: Vec<E::Fr> = random_permutation_mle(merged_nv, &mut rng)
.evaluations
.clone();
let mut bad_index = index.clone();
let mut bad_index = index;
bad_index.permutation = rand_perm;
// generate pk and vks
let (_, bad_vk) = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, KZGMultilinearPCS<E>>>::preprocess(
let (_, bad_vk) = <PolyIOP<E::Fr> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::preprocess(
&bad_index, &pcs_srs,
)?;
assert!(
<PolyIOP<E::Fr> as HyperPlonkSNARK<E, KZGMultilinearPCS<E>>>::verify(
<PolyIOP<E::Fr> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::verify(
&bad_vk, &pi.0, &proof,
)
.is_err()
);

// bad path 2: wrong witness
let mut w1_bad = w1.clone();
let mut w1_bad = w1;
w1_bad.0[0] = E::Fr::one();
assert!(
<PolyIOP<E::Fr> as HyperPlonkSNARK<E, KZGMultilinearPCS<E>>>::prove(
<PolyIOP<E::Fr> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::prove(
&pk,
&pi.0,
&[w1_bad, w2],
Expand Down
2 changes: 1 addition & 1 deletion hyperplonk/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ark_ec::PairingEngine;
use ark_ff::PrimeField;
use ark_poly::DenseMultilinearExtension;
use ark_std::cmp::max;
use pcs::PolynomialCommitmentScheme;
use jf_primitives::pcs::PolynomialCommitmentScheme;
use poly_iop::prelude::{PermutationCheck, ZeroCheck};
use std::rc::Rc;

Expand Down
40 changes: 0 additions & 40 deletions pcs/Cargo.toml

This file was deleted.

88 changes: 0 additions & 88 deletions pcs/benches/bench.rs

This file was deleted.

6 changes: 0 additions & 6 deletions pcs/readme.md

This file was deleted.

Loading