From bb44a3ad956abbbed3406b05d1cb292cd347da1f Mon Sep 17 00:00:00 2001 From: arnaucube Date: Thu, 11 Jul 2024 12:27:01 +0200 Subject: [PATCH] fix sumcheck verifier for when poly=0 (#126) Co-authored-by: NiDimi --- .../src/utils/espresso/sum_check/mod.rs | 32 ++++++++++++------- .../src/utils/espresso/sum_check/verifier.rs | 6 +++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/folding-schemes/src/utils/espresso/sum_check/mod.rs b/folding-schemes/src/utils/espresso/sum_check/mod.rs index 638719d..efb8b50 100644 --- a/folding-schemes/src/utils/espresso/sum_check/mod.rs +++ b/folding-schemes/src/utils/espresso/sum_check/mod.rs @@ -219,29 +219,39 @@ pub mod tests { #[test] pub fn sumcheck_poseidon() { + let n_vars = 5; + let mut rng = test_rng(); - let poly_mle = DenseMultilinearExtension::rand(5, &mut rng); + let poly_mle = DenseMultilinearExtension::rand(n_vars, &mut rng); let virtual_poly = VirtualPolynomial::new_from_mle(&Arc::new(poly_mle), Fr::ONE); + + sumcheck_poseidon_opt(virtual_poly); + + // test with zero poly + let poly_mle = DenseMultilinearExtension::from_evaluations_vec( + n_vars, + vec![Fr::ZERO; 2u32.pow(n_vars as u32) as usize], + ); + let virtual_poly = VirtualPolynomial::new_from_mle(&Arc::new(poly_mle), Fr::ONE); + sumcheck_poseidon_opt(virtual_poly); + } + + fn sumcheck_poseidon_opt(virtual_poly: VirtualPolynomial) { let poseidon_config = poseidon_canonical_config::(); // sum-check prove - let mut poseidon_transcript_prove: PoseidonSponge = - PoseidonSponge::::new(&poseidon_config); - let sum_check = IOPSumCheck::>::prove( - &virtual_poly, - &mut poseidon_transcript_prove, - ) - .unwrap(); + let mut transcript_p: PoseidonSponge = PoseidonSponge::::new(&poseidon_config); + let sum_check = + IOPSumCheck::>::prove(&virtual_poly, &mut transcript_p).unwrap(); // sum-check verify let claimed_sum = IOPSumCheck::>::extract_sum(&sum_check); - let mut poseidon_transcript_verify: PoseidonSponge = - PoseidonSponge::::new(&poseidon_config); + let mut transcript_v: PoseidonSponge = PoseidonSponge::::new(&poseidon_config); let res_verify = IOPSumCheck::>::verify( claimed_sum, &sum_check, &virtual_poly.aux_info, - &mut poseidon_transcript_verify, + &mut transcript_v, ); assert!(res_verify.is_ok()); diff --git a/folding-schemes/src/utils/espresso/sum_check/verifier.rs b/folding-schemes/src/utils/espresso/sum_check/verifier.rs index 8ff83b3..074eec1 100644 --- a/folding-schemes/src/utils/espresso/sum_check/verifier.rs +++ b/folding-schemes/src/utils/espresso/sum_check/verifier.rs @@ -137,7 +137,11 @@ impl SumCheckVerifier for IOPVerifierState { { let poly = DensePolynomial::from_coefficients_slice(coeffs); let eval_at_one: F = poly.iter().sum(); - let eval_at_zero: F = poly.coeffs[0]; + let eval_at_zero: F = if poly.coeffs.is_empty() { + F::zero() + } else { + poly.coeffs[0] + }; let eval = eval_at_one + eval_at_zero; // the deferred check during the interactive phase: