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

fix: snark prove and verify check product to be 1 #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 19 additions & 2 deletions hyperplonk/src/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ where
));
}

// check product check subclaim
if prod_evals[3] != perm_check_sub_claim.product_check_sub_claim.final_query.1 {
return Err(HyperPlonkErrors::InvalidVerifier(
"product of product check is not one".to_string(),
));
}

end_timer!(step);
// =======================================================================
// 3. Verify the opening against the commitment
Expand Down Expand Up @@ -734,17 +741,27 @@ mod tests {
>>::verify(&bad_vk, &pi.0, &proof,)?);

// bad path 2: wrong witness
let mut w1_bad = w1;
let mut w1_bad = w1.clone();
w1_bad.0[0] = E::ScalarField::one();
assert!(
<PolyIOP<E::ScalarField> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::prove(
&pk,
&pi.0,
&[w1_bad, w2],
&[w1_bad, w2.clone()],
)
.is_err()
);

// bad path 3: permutation and witness mismatch
let permutation = random_permutation(nv, num_witnesses, &mut rng);
assert!(
<PolyIOP<E::ScalarField> as HyperPlonkSNARK<E, MultilinearKzgPCS<E>>>::prove(
&pk,
&permutation,
&[w1, w2],
).is_err()
);

Ok(())
}
}
7 changes: 7 additions & 0 deletions subroutines/src/poly_iop/perm_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
poly_iop::{errors::PolyIOPErrors, prelude::ProductCheck, PolyIOP},
};
use ark_ec::pairing::Pairing;
use ark_ff::One;
use ark_poly::DenseMultilinearExtension;
use ark_std::{end_timer, start_timer};
use std::sync::Arc;
Expand Down Expand Up @@ -161,6 +162,12 @@ where
transcript,
)?;

if prod_poly.evaluations[(1 << num_vars) - 2] != E::ScalarField::one() {
return Err(PolyIOPErrors::InvalidProof(
"Product should be one".to_string(),
));
}

end_timer!(start);
Ok((proof, prod_poly, frac_poly))
}
Expand Down