From e73a98eda4cfa4326097a0e287d59824516148e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= <4142+huitseeker@users.noreply.github.com> Date: Sun, 25 Feb 2024 02:13:15 -0800 Subject: [PATCH] No more assert on result (#346) * refactor: a few zip_with applications * refactor: Replace assertion checks with direct unwraps for error handling - Replaced assertions throughout multiple functions and tests with directly unwrapping results for better error handling and clarity on failures. - Applied this change to methods like `prove_step`, `verify`, `test_inner`, and in areas like RecursiveSNARK, CompressedSNARK, and test functions across different scripts. - Enhanced the error feedback mechanism during benchmarks for RecursiveSNARK, and CompressedSNARK. - Simplified code further by removing unnecessary checks and variable assignments, and performing inline verification with cleanercode. - Updated `.cargo/config.toml` with a new project-wide Clippy lint rule for assertion on result states. --- .cargo/config.toml | 1 + benches/common/supernova/bench.rs | 25 +++--- benches/compressed-snark.rs | 34 ++++---- benches/recursive-snark.rs | 28 ++++--- benches/sha256.rs | 4 +- examples/and.rs | 9 ++- examples/hashchain.rs | 9 ++- examples/minroot.rs | 5 +- src/bellpepper/mod.rs | 2 +- src/circuit.rs | 4 +- src/gadgets/ecc.rs | 6 +- src/lib.rs | 127 +++++++++++++++--------------- src/nifs.rs | 8 +- src/provider/hyperkzg.rs | 23 ++---- src/provider/shplonk.rs | 20 ++--- src/r1cs/mod.rs | 9 +-- src/spartan/ppsnark.rs | 2 +- src/supernova/circuit.rs | 4 +- src/supernova/snark.rs | 48 +++++------ src/supernova/test.rs | 10 +-- 20 files changed, 178 insertions(+), 200 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 1051f0fd5..2143de06d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,6 +7,7 @@ xclippy = [ "clippy", "--all-targets", "--", "-Wclippy::all", + "-Wclippy::assertions_on_result_states", "-Wclippy::cast_lossless", "-Wclippy::checked_conversions", "-Wclippy::dbg_macro", diff --git a/benches/common/supernova/bench.rs b/benches/common/supernova/bench.rs index dc6b0f027..51b893a86 100644 --- a/benches/common/supernova/bench.rs +++ b/benches/common/supernova/bench.rs @@ -99,29 +99,28 @@ pub fn bench_snark_internal_with_arity< // Benchmark the prove time group.bench_function(bench_params.bench_id("Prove"), |b| { b.iter(|| { - assert!(CompressedSNARK::<_, S1, S2>::prove( + CompressedSNARK::<_, S1, S2>::prove( black_box(&pp), black_box(&prover_key), - black_box(&recursive_snark) + black_box(&recursive_snark), ) - .is_ok()); + .unwrap(); }) }); - let res = CompressedSNARK::<_, S1, S2>::prove(&pp, &prover_key, &recursive_snark); - assert!(res.is_ok()); - let compressed_snark = res.unwrap(); + let compressed_snark = + CompressedSNARK::<_, S1, S2>::prove(&pp, &prover_key, &recursive_snark).unwrap(); // Benchmark the verification time group.bench_function(bench_params.bench_id("Verify"), |b| { b.iter(|| { - assert!(black_box(&compressed_snark) + black_box(&compressed_snark) .verify( black_box(&pp), black_box(&verifier_key), black_box(&z0_primary), black_box(&z0_secondary), ) - .is_ok()); + .unwrap(); }) }); } @@ -129,26 +128,26 @@ pub fn bench_snark_internal_with_arity< // Benchmark the prove time group.bench_function(bench_params.bench_id("Prove"), |b| { b.iter(|| { - assert!(black_box(&mut recursive_snark.clone()) + black_box(&mut recursive_snark.clone()) .prove_step( black_box(&pp), &bench.primary_circuit(0), - &bench.secondary_circuit() + &bench.secondary_circuit(), ) - .is_ok()); + .unwrap(); }) }); // Benchmark the verification time group.bench_function(bench_params.bench_id("Verify"), |b| { b.iter(|| { - assert!(black_box(&mut recursive_snark.clone()) + black_box(&mut recursive_snark.clone()) .verify( black_box(&pp), black_box(&[::Scalar::from(2u64)]), black_box(&[::Scalar::from(2u64)]), ) - .is_ok()); + .unwrap(); }) }); } diff --git a/benches/compressed-snark.rs b/benches/compressed-snark.rs index 5a900df3b..3efabcdb4 100644 --- a/benches/compressed-snark.rs +++ b/benches/compressed-snark.rs @@ -86,17 +86,19 @@ fn bench_compressed_snark_internal, S2: RelaxedR1C .unwrap(); for i in 0..num_steps { - let res = recursive_snark.prove_step(&pp, &c_primary, &c_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, &c_primary, &c_secondary) + .unwrap(); // verify the recursive snark at each step of recursion - let res = recursive_snark.verify( - &pp, - i + 1, - &[::Scalar::from(2u64)], - &[::Scalar::from(2u64)], - ); - assert!(res.is_ok()); + recursive_snark + .verify( + &pp, + i + 1, + &[::Scalar::from(2u64)], + &[::Scalar::from(2u64)], + ) + .unwrap(); } let bench_params = BenchParams { @@ -108,29 +110,27 @@ fn bench_compressed_snark_internal, S2: RelaxedR1C // Bench time to produce a compressed SNARK group.bench_function(bench_params.bench_id("Prove"), |b| { b.iter(|| { - assert!(CompressedSNARK::<_, S1, S2>::prove( + CompressedSNARK::<_, S1, S2>::prove( black_box(&pp), black_box(&pk), - black_box(&recursive_snark) + black_box(&recursive_snark), ) - .is_ok()); + .unwrap(); }) }); - let res = CompressedSNARK::<_, S1, S2>::prove(&pp, &pk, &recursive_snark); - assert!(res.is_ok()); - let compressed_snark = res.unwrap(); + let compressed_snark = CompressedSNARK::<_, S1, S2>::prove(&pp, &pk, &recursive_snark).unwrap(); // Benchmark the verification time group.bench_function(bench_params.bench_id("Verify"), |b| { b.iter(|| { - assert!(black_box(&compressed_snark) + black_box(&compressed_snark) .verify( black_box(&vk), black_box(num_steps), black_box(&[::Scalar::from(2u64)]), black_box(&[::Scalar::from(2u64)]), ) - .is_ok()); + .unwrap(); }) }); } diff --git a/benches/recursive-snark.rs b/benches/recursive-snark.rs index d4437b549..ed0179c02 100644 --- a/benches/recursive-snark.rs +++ b/benches/recursive-snark.rs @@ -94,17 +94,19 @@ fn bench_recursive_snark(c: &mut Criterion) { .unwrap(); for i in 0..num_warmup_steps { - let res = recursive_snark.prove_step(&pp, &c_primary, &c_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, &c_primary, &c_secondary) + .unwrap(); // verify the recursive snark at each step of recursion - let res = recursive_snark.verify( - &pp, - i + 1, - &[::Scalar::from(2u64)], - &[::Scalar::from(2u64)], - ); - assert!(res.is_ok()); + recursive_snark + .verify( + &pp, + i + 1, + &[::Scalar::from(2u64)], + &[::Scalar::from(2u64)], + ) + .unwrap(); } let bench_params = BenchParams { @@ -116,27 +118,27 @@ fn bench_recursive_snark(c: &mut Criterion) { group.bench_function(bench_params.bench_id("Prove"), |b| { b.iter(|| { // produce a recursive SNARK for a step of the recursion - assert!(black_box(&mut recursive_snark.clone()) + black_box(&mut recursive_snark.clone()) .prove_step( black_box(&pp), black_box(&c_primary), black_box(&c_secondary), ) - .is_ok()); + .unwrap(); }) }); // Benchmark the verification time group.bench_function(bench_params.bench_id("Verify"), |b| { b.iter(|| { - assert!(black_box(&recursive_snark) + black_box(&recursive_snark) .verify( black_box(&pp), black_box(num_warmup_steps), black_box(&[::Scalar::from(2u64)]), black_box(&[::Scalar::from(2u64)]), ) - .is_ok()); + .unwrap(); }); }); group.finish(); diff --git a/benches/sha256.rs b/benches/sha256.rs index 9315ef40a..d41537ee6 100644 --- a/benches/sha256.rs +++ b/benches/sha256.rs @@ -179,13 +179,13 @@ fn bench_recursive_snark(c: &mut Criterion) { .unwrap(); // produce a recursive SNARK for a step of the recursion - assert!(recursive_snark + recursive_snark .prove_step( black_box(&pp), black_box(&circuit_primary), black_box(&circuit_secondary), ) - .is_ok()); + .unwrap(); }) }); group.finish(); diff --git a/examples/and.rs b/examples/and.rs index 85b3b5577..c5d207e5b 100644 --- a/examples/and.rs +++ b/examples/and.rs @@ -270,8 +270,9 @@ fn main() { let start = Instant::now(); for circuit_primary in circuits.iter() { - let res = recursive_snark.prove_step(&pp, circuit_primary, &circuit_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, circuit_primary, &circuit_secondary) + .unwrap(); } println!( "RecursiveSNARK::prove {} AND ops: took {:?} ", @@ -288,7 +289,7 @@ fn main() { &[::Scalar::ZERO], ); println!("RecursiveSNARK::verify: {:?}", res.is_ok(),); - assert!(res.is_ok()); + res.unwrap(); // produce a compressed SNARK println!("Generating a CompressedSNARK using Spartan with HyperKZG..."); @@ -327,7 +328,7 @@ fn main() { res.is_ok(), start.elapsed() ); - assert!(res.is_ok()); + res.unwrap(); println!("========================================================="); } } diff --git a/examples/hashchain.rs b/examples/hashchain.rs index 746168bb5..3f6ffdb42 100644 --- a/examples/hashchain.rs +++ b/examples/hashchain.rs @@ -167,8 +167,9 @@ fn main() { for (i, circuit_primary) in circuits.iter().enumerate() { let start = Instant::now(); - let res = recursive_snark.prove_step(&pp, circuit_primary, &circuit_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, circuit_primary, &circuit_secondary) + .unwrap(); println!("RecursiveSNARK::prove {} : took {:?} ", i, start.elapsed()); } @@ -182,7 +183,7 @@ fn main() { &[::Scalar::ZERO], ); println!("RecursiveSNARK::verify: {:?}", res.is_ok(),); - assert!(res.is_ok()); + res.unwrap(); // produce a compressed SNARK println!("Generating a CompressedSNARK using Spartan with HyperKZG..."); @@ -221,7 +222,7 @@ fn main() { res.is_ok(), start.elapsed() ); - assert!(res.is_ok()); + res.unwrap(); println!("========================================================="); } } diff --git a/examples/minroot.rs b/examples/minroot.rs index d2e3d3668..a34321f45 100644 --- a/examples/minroot.rs +++ b/examples/minroot.rs @@ -314,7 +314,6 @@ fn main() { for (i, circuit_primary) in minroot_circuits.iter().enumerate() { let start = Instant::now(); let res = recursive_snark.prove_step(&pp, circuit_primary, &circuit_secondary); - assert!(res.is_ok()); println!( "RecursiveSNARK::prove_step {}: {:?}, took {:?} ", i, @@ -332,7 +331,7 @@ fn main() { res.is_ok(), start.elapsed() ); - assert!(res.is_ok()); + res.unwrap(); // produce a compressed SNARK println!("Generating a CompressedSNARK using Spartan with HyperKZG..."); @@ -372,7 +371,7 @@ fn main() { res.is_ok(), start.elapsed() ); - assert!(res.is_ok()); + res.unwrap(); println!("========================================================="); } } diff --git a/src/bellpepper/mod.rs b/src/bellpepper/mod.rs index a8a657e01..db7e04e0f 100644 --- a/src/bellpepper/mod.rs +++ b/src/bellpepper/mod.rs @@ -53,7 +53,7 @@ mod tests { let (inst, witness) = cs.r1cs_instance_and_witness(&shape, &ck).unwrap(); // Make sure that this is satisfiable - assert!(shape.is_sat(&ck, &inst, &witness).is_ok()); + shape.is_sat(&ck, &inst, &witness).unwrap(); } #[test] diff --git a/src/circuit.rs b/src/circuit.rs index 18be84383..ef7d2bbbe 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -427,7 +427,7 @@ mod tests { let _ = circuit1.synthesize(&mut cs1); let (inst1, witness1) = cs1.r1cs_instance_and_witness(&shape1, &ck1).unwrap(); // Make sure that this is satisfiable - assert!(shape1.is_sat(&ck1, &inst1, &witness1).is_ok()); + shape1.is_sat(&ck1, &inst1, &witness1).unwrap(); // Execute the base case for the secondary let zero2 = <::Base as Field>::ZERO; @@ -446,7 +446,7 @@ mod tests { let _ = circuit2.synthesize(&mut cs2); let (inst2, witness2) = cs2.r1cs_instance_and_witness(&shape2, &ck2).unwrap(); // Make sure that it is satisfiable - assert!(shape2.is_sat(&ck2, &inst2, &witness2).is_ok()); + shape2.is_sat(&ck2, &inst2, &witness2).unwrap(); } #[test] diff --git a/src/gadgets/ecc.rs b/src/gadgets/ecc.rs index ec30572f2..cc282b6e1 100644 --- a/src/gadgets/ecc.rs +++ b/src/gadgets/ecc.rs @@ -1056,7 +1056,7 @@ mod tests { let e_new = a_p.scalar_mul(&s); assert!(e_p.x == e_new.x && e_p.y == e_new.y); // Make sure that this is satisfiable - assert!(shape.is_sat(&ck, &inst, &witness).is_ok()); + shape.is_sat(&ck, &inst, &witness).unwrap(); } fn synthesize_add_equal(mut cs: CS) -> (AllocatedPoint, AllocatedPoint) @@ -1111,7 +1111,7 @@ mod tests { let e_new = a_p.add(&a_p); assert!(e_p.x == e_new.x && e_p.y == e_new.y); // Make sure that it is satisfiable - assert!(shape.is_sat(&ck, &inst, &witness).is_ok()); + shape.is_sat(&ck, &inst, &witness).unwrap(); } fn synthesize_add_negation(mut cs: CS) -> AllocatedPoint @@ -1180,6 +1180,6 @@ mod tests { ); assert!(e_p.is_infinity); // Make sure that it is satisfiable - assert!(shape.is_sat(&ck, &inst, &witness).is_ok()); + shape.is_sat(&ck, &inst, &witness).unwrap(); } } diff --git a/src/lib.rs b/src/lib.rs index 3e6d02274..9c3a877f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1180,18 +1180,19 @@ mod tests { ) .unwrap(); - let res = recursive_snark.prove_step(&pp, &test_circuit1, &test_circuit2); - - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, &test_circuit1, &test_circuit2) + .unwrap(); // verify the recursive SNARK - let res = recursive_snark.verify( - &pp, - num_steps, - &[::Scalar::ZERO], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); + recursive_snark + .verify( + &pp, + num_steps, + &[::Scalar::ZERO], + &[ as Engine>::Scalar::ZERO], + ) + .unwrap(); } #[test] @@ -1230,29 +1231,30 @@ mod tests { .unwrap(); for i in 0..num_steps { - let res = recursive_snark.prove_step(&pp, &circuit_primary, &circuit_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, &circuit_primary, &circuit_secondary) + .unwrap(); // verify the recursive snark at each step of recursion - let res = recursive_snark.verify( - &pp, - i + 1, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); + recursive_snark + .verify( + &pp, + i + 1, + &[::Scalar::ONE], + &[ as Engine>::Scalar::ZERO], + ) + .unwrap(); } // verify the recursive SNARK - let res = recursive_snark.verify( - &pp, - num_steps, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); - - let (zn_primary, zn_secondary) = res.unwrap(); + let (zn_primary, zn_secondary) = recursive_snark + .verify( + &pp, + num_steps, + &[::Scalar::ONE], + &[ as Engine>::Scalar::ZERO], + ) + .unwrap(); // sanity: check the claimed output with a direct computation of the same assert_eq!(zn_primary, vec![::Scalar::ONE]); @@ -1308,20 +1310,20 @@ mod tests { .unwrap(); for _i in 0..num_steps { - let res = recursive_snark.prove_step(&pp, &circuit_primary, &circuit_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, &circuit_primary, &circuit_secondary) + .unwrap(); } // verify the recursive SNARK - let res = recursive_snark.verify( - &pp, - num_steps, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); - - let (zn_primary, zn_secondary) = res.unwrap(); + let (zn_primary, zn_secondary) = recursive_snark + .verify( + &pp, + num_steps, + &[::Scalar::ONE], + &[ as Engine>::Scalar::ZERO], + ) + .unwrap(); // sanity: check the claimed output with a direct computation of the same assert_eq!(zn_primary, vec![::Scalar::ONE]); @@ -1340,9 +1342,7 @@ mod tests { let (pk, vk) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); // produce a compressed SNARK - let res = CompressedSNARK::<_, S1, S2>::prove(&pp, &pk, &recursive_snark); - assert!(res.is_ok()); - let compressed_snark = res.unwrap(); + let compressed_snark = CompressedSNARK::<_, S1, S2>::prove(&pp, &pk, &recursive_snark).unwrap(); // verify the compressed SNARK compressed_snark @@ -1560,25 +1560,27 @@ mod tests { .unwrap(); for circuit_primary in roots.iter().take(num_steps) { - let res = recursive_snark.prove_step(&pp, circuit_primary, &circuit_secondary); - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, circuit_primary, &circuit_secondary) + .unwrap(); } // verify the recursive SNARK - let res = recursive_snark.verify(&pp, num_steps, &z0_primary, &z0_secondary); - assert!(res.is_ok()); + recursive_snark + .verify(&pp, num_steps, &z0_primary, &z0_secondary) + .unwrap(); // produce the prover and verifier keys for compressed snark let (pk, vk) = CompressedSNARK::<_, S, S<_, EE2>>::setup(&pp).unwrap(); // produce a compressed SNARK - let res = CompressedSNARK::<_, S, S<_, EE2>>::prove(&pp, &pk, &recursive_snark); - assert!(res.is_ok()); - let compressed_snark = res.unwrap(); + let compressed_snark = + CompressedSNARK::<_, S, S<_, EE2>>::prove(&pp, &pk, &recursive_snark).unwrap(); // verify the compressed SNARK - let res = compressed_snark.verify(&vk, num_steps, &z0_primary, &z0_secondary); - assert!(res.is_ok()); + compressed_snark + .verify(&vk, num_steps, &z0_primary, &z0_secondary) + .unwrap(); } #[test] @@ -1618,20 +1620,19 @@ mod tests { .unwrap(); // produce a recursive SNARK - let res = recursive_snark.prove_step(&pp, &test_circuit1, &test_circuit2); - - assert!(res.is_ok()); + recursive_snark + .prove_step(&pp, &test_circuit1, &test_circuit2) + .unwrap(); // verify the recursive SNARK - let res = recursive_snark.verify( - &pp, - num_steps, - &[::Scalar::ONE], - &[ as Engine>::Scalar::ZERO], - ); - assert!(res.is_ok()); - - let (zn_primary, zn_secondary) = res.unwrap(); + let (zn_primary, zn_secondary) = recursive_snark + .verify( + &pp, + num_steps, + &[::Scalar::ONE], + &[ as Engine>::Scalar::ZERO], + ) + .unwrap(); assert_eq!(zn_primary, vec![::Scalar::ONE]); assert_eq!(zn_secondary, vec![ as Engine>::Scalar::from(5u64)]); diff --git a/src/nifs.rs b/src/nifs.rs index f4a4cf68e..566397587 100644 --- a/src/nifs.rs +++ b/src/nifs.rs @@ -232,7 +232,7 @@ mod tests { let (U1, W1) = cs.r1cs_instance_and_witness(&shape, &ck).unwrap(); // Make sure that the first instance is satisfiable - assert!(shape.is_sat(&ck, &U1, &W1).is_ok()); + shape.is_sat(&ck, &U1, &W1).unwrap(); // Now get the instance and assignment for second instance let mut cs = SatisfyingAssignment::::new(); @@ -240,7 +240,7 @@ mod tests { let (U2, W2) = cs.r1cs_instance_and_witness(&shape, &ck).unwrap(); // Make sure that the second instance is satisfiable - assert!(shape.is_sat(&ck, &U2, &W2).is_ok()); + shape.is_sat(&ck, &U2, &W2).unwrap(); // execute a sequence of folds execute_sequence( @@ -309,7 +309,7 @@ mod tests { r_U = U; // check if the running instance is satisfiable - assert!(shape.is_sat_relaxed(ck, &r_U, &r_W).is_ok()); + shape.is_sat_relaxed(ck, &r_U, &r_W).unwrap(); } fn test_tiny_r1cs_with() { @@ -352,7 +352,7 @@ mod tests { }; // check that generated instance is satisfiable - assert!(S.is_sat(ck, &U, &W).is_ok()); + S.is_sat(ck, &U, &W).unwrap(); (O, U, W) }; diff --git a/src/provider/hyperkzg.rs b/src/provider/hyperkzg.rs index 02a6e4457..c3b68fc7e 100644 --- a/src/provider/hyperkzg.rs +++ b/src/provider/hyperkzg.rs @@ -454,23 +454,23 @@ mod tests { // The prover does not recompute so it may produce a proof, but it should not verify let point = vec![Fr::from(0), Fr::from(0)]; let eval = Fr::ONE; - assert!(test_inner(point, eval).is_ok()); + test_inner(point, eval).unwrap(); let point = vec![Fr::from(0), Fr::from(1)]; let eval = Fr::from(2); - assert!(test_inner(point, eval).is_ok()); + test_inner(point, eval).unwrap(); let point = vec![Fr::from(1), Fr::from(1)]; let eval = Fr::from(4); - assert!(test_inner(point, eval).is_ok()); + test_inner(point, eval).unwrap(); let point = vec![Fr::from(0), Fr::from(2)]; let eval = Fr::from(3); - assert!(test_inner(point, eval).is_ok()); + test_inner(point, eval).unwrap(); let point = vec![Fr::from(2), Fr::from(2)]; let eval = Fr::from(9); - assert!(test_inner(point, eval).is_ok()); + test_inner(point, eval).unwrap(); // Try a couple incorrect evaluations and expect failure let point = vec![Fr::from(2), Fr::from(2)]; @@ -525,7 +525,7 @@ mod tests { // eval = 57 let eval = Fr::from(57); - assert!(test_inner(n, &poly, &point, eval).is_ok()); + test_inner(n, &poly, &point, eval).unwrap(); // wrong eval let eval = Fr::from(56); @@ -563,15 +563,8 @@ mod tests { // verify the evaluation let mut verifier_transcript = Keccak256Transcript::::new(b"TestEval"); - assert!(EvaluationEngine::::verify( - &vk, - &mut verifier_transcript, - &C, - &point, - &eval, - &proof - ) - .is_ok()); + EvaluationEngine::::verify(&vk, &mut verifier_transcript, &C, &point, &eval, &proof) + .unwrap(); let post_c_v = verifier_transcript.squeeze(b"c").unwrap(); // check if the prover transcript and verifier transcript are kept in the diff --git a/src/provider/shplonk.rs b/src/provider/shplonk.rs index 44d59ea1a..ee67aa1be 100644 --- a/src/provider/shplonk.rs +++ b/src/provider/shplonk.rs @@ -330,8 +330,8 @@ mod tests { use super::*; use crate::provider::util::iterators::DoubleEndedIteratorExt as _; use crate::traits::TranscriptEngineTrait; - use crate::zip_with; use crate::{provider::keccak::Keccak256Transcript, CommitmentEngineTrait, CommitmentKey}; + use crate::{zip_with, zip_with_for_each}; use halo2curves::bn256::G1; use itertools::Itertools; @@ -371,7 +371,7 @@ mod tests { let K_x = EvaluationEngine::::compute_k_polynomial(&batched_Pi, &Q_x, &D, &R_x, a); let mut C_P = G1::identity(); - q_powers.iter().zip_eq(comms.iter()).for_each(|(q_i, C_i)| { + zip_with_for_each!(iter, (q_powers, comms), |q_i, C_i| { C_P += *C_i * q_i; }); @@ -480,10 +480,7 @@ mod tests { .map(|poly| UniPoly::new(poly).evaluate(evaluation_scalar)) .collect::>(); - let expected = zip_with!((evals.iter(), q_powers.iter()), |eval, q| eval * q) - .collect::>() - .into_iter() - .sum::(); + let expected = zip_with!(iter, (evals, q_powers), |eval, q| eval * q).sum::(); let actual = batched_Pi.evaluate(evaluation_scalar); assert_eq!(expected, actual); @@ -559,15 +556,8 @@ mod tests { .unwrap(); let mut verifier_transcript = Keccak256Transcript::::new(b"TestEval"); - assert!(EvaluationEngine::::verify( - &vk, - &mut verifier_transcript, - &C, - &point, - &eval, - &proof - ) - .is_ok()); + EvaluationEngine::::verify(&vk, &mut verifier_transcript, &C, &point, &eval, &proof) + .unwrap(); } #[test] diff --git a/src/r1cs/mod.rs b/src/r1cs/mod.rs index 5f1508841..aab1022ea 100644 --- a/src/r1cs/mod.rs +++ b/src/r1cs/mod.rs @@ -874,16 +874,15 @@ pub(crate) mod tests { let rows = num_cons; let cols = num_vars + num_io + 1; - let res = R1CSShape::new( + R1CSShape::new( num_cons, num_vars, num_io, SparseMatrix::new(&A, rows, cols), SparseMatrix::new(&B, rows, cols), SparseMatrix::new(&C, rows, cols), - ); - assert!(res.is_ok()); - res.unwrap() + ) + .unwrap() } fn test_pad_tiny_r1cs_with() { @@ -913,7 +912,7 @@ pub(crate) mod tests { for (num_cons, num_vars, num_io, num_entries) in cases { let S = R1CSShape::::random(num_cons, num_vars, num_io, num_entries, &mut rng); let (W, U) = S.random_witness_instance(&ck, &mut rng); - assert!(S.is_sat_relaxed(&ck, &U, &W).is_ok()); + S.is_sat_relaxed(&ck, &U, &W).unwrap(); } } diff --git a/src/spartan/ppsnark.rs b/src/spartan/ppsnark.rs index b5038c4ab..711f80039 100644 --- a/src/spartan/ppsnark.rs +++ b/src/spartan/ppsnark.rs @@ -370,7 +370,7 @@ impl> RelaxedR1CSSNARK { let coeffs = powers(&s, claims.len()); // compute the joint claim - let claim = zip_with!((claims.iter(), coeffs.iter()), |c_1, c_2| *c_1 * c_2).sum(); + let claim = zip_with!(iter, (claims, coeffs), |c_1, c_2| *c_1 * c_2).sum(); let mut e = claim; let mut r: Vec = Vec::new(); diff --git a/src/supernova/circuit.rs b/src/supernova/circuit.rs index 2a1d3209b..b9a33cda6 100644 --- a/src/supernova/circuit.rs +++ b/src/supernova/circuit.rs @@ -798,7 +798,7 @@ mod tests { let _ = circuit1.synthesize(&mut cs1); let (inst1, witness1) = cs1.r1cs_instance_and_witness(&shape1, &ck1).unwrap(); // Make sure that this is satisfiable - assert!(shape1.is_sat(&ck1, &inst1, &witness1).is_ok()); + shape1.is_sat(&ck1, &inst1, &witness1).unwrap(); // Execute the base case for the secondary let zero2 = <::Base as Field>::ZERO; @@ -826,7 +826,7 @@ mod tests { let _ = circuit2.synthesize(&mut cs2); let (inst2, witness2) = cs2.r1cs_instance_and_witness(&shape2, &ck2).unwrap(); // Make sure that it is satisfiable - assert!(shape2.is_sat(&ck2, &inst2, &witness2).is_ok()); + shape2.is_sat(&ck2, &inst2, &witness2).unwrap(); } #[test] diff --git a/src/supernova/snark.rs b/src/supernova/snark.rs index f6bdcbb14..cba4ad6eb 100644 --- a/src/supernova/snark.rs +++ b/src/supernova/snark.rs @@ -487,26 +487,22 @@ mod test { .unwrap(); for circuit in test_circuits.iter().take(NUM_STEPS) { - let prove_res = recursive_snark.prove_step(&pp, circuit, &secondary_circuit); + recursive_snark + .prove_step(&pp, circuit, &secondary_circuit) + .unwrap(); - let verify_res = recursive_snark.verify(&pp, &z0_primary, &z0_secondary); - - assert!(prove_res.is_ok()); - assert!(verify_res.is_ok()); + recursive_snark + .verify(&pp, &z0_primary, &z0_secondary) + .unwrap(); } let (prover_key, verifier_key) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); - let compressed_prove_res = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark); - - assert!(compressed_prove_res.is_ok()); - - let compressed_snark = compressed_prove_res.unwrap(); - - let compressed_verify_res = - compressed_snark.verify(&pp, &verifier_key, &z0_primary, &z0_secondary); + let compressed_snark = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark).unwrap(); - assert!(compressed_verify_res.is_ok()); + compressed_snark + .verify(&pp, &verifier_key, &z0_primary, &z0_secondary) + .unwrap(); } #[test] @@ -670,26 +666,22 @@ mod test { .unwrap(); for circuit in test_circuits.iter().take(NUM_STEPS) { - let prove_res = recursive_snark.prove_step(&pp, circuit, &secondary_circuit); + recursive_snark + .prove_step(&pp, circuit, &secondary_circuit) + .unwrap(); - let verify_res = recursive_snark.verify(&pp, &z0_primary, &z0_secondary); - - assert!(prove_res.is_ok()); - assert!(verify_res.is_ok()); + recursive_snark + .verify(&pp, &z0_primary, &z0_secondary) + .unwrap(); } let (prover_key, verifier_key) = CompressedSNARK::<_, S1, S2>::setup(&pp).unwrap(); - let compressed_prove_res = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark); - - assert!(compressed_prove_res.is_ok()); - - let compressed_snark = compressed_prove_res.unwrap(); - - let compressed_verify_res = - compressed_snark.verify(&pp, &verifier_key, &z0_primary, &z0_secondary); + let compressed_snark = CompressedSNARK::prove(&pp, &prover_key, &recursive_snark).unwrap(); - assert!(compressed_verify_res.is_ok()); + compressed_snark + .verify(&pp, &verifier_key, &z0_primary, &z0_secondary) + .unwrap(); } #[test] diff --git a/src/supernova/test.rs b/src/supernova/test.rs index 3adb7ce35..d499b1dc8 100644 --- a/src/supernova/test.rs +++ b/src/supernova/test.rs @@ -518,7 +518,7 @@ fn test_recursive_circuit_with( } let (inst1, witness1) = cs1.r1cs_instance_and_witness(&shape1, &ck1).unwrap(); // Make sure that this is satisfiable - assert!(shape1.is_sat(&ck1, &inst1, &witness1).is_ok()); + shape1.is_sat(&ck1, &inst1, &witness1).unwrap(); // Execute the base case for the secondary let zero2 = <::Base as Field>::ZERO; @@ -549,7 +549,7 @@ fn test_recursive_circuit_with( } let (inst2, witness2) = cs2.r1cs_instance_and_witness(&shape2, &ck2).unwrap(); // Make sure that it is satisfiable - assert!(shape2.is_sat(&ck2, &inst2, &witness2).is_ok()); + shape2.is_sat(&ck2, &inst2, &witness2).unwrap(); } #[test] @@ -863,12 +863,12 @@ where .is_ok()); // verify the recursive SNARK - let res = recursive_snark + recursive_snark .verify(&pp, &z0_primary, &z0_secondary) .map_err(|err| { print_constraints_name_on_error_index(&err, &pp, circuit_primary, &circuit_secondary, 2) - }); - assert!(res.is_ok()); + }) + .unwrap(); } }