From 663545d8829395f5f0e77ceff3dd2673c58a4eb7 Mon Sep 17 00:00:00 2001 From: Jonathan Wang Date: Mon, 22 May 2023 19:54:11 -0700 Subject: [PATCH] fix: add better error messages/docs for catching empty inputs --- snark-verifier-sdk/src/halo2/aggregation.rs | 4 ++++ snark-verifier/src/loader/evm/loader.rs | 2 +- snark-verifier/src/loader/halo2/loader.rs | 1 + snark-verifier/src/loader/native.rs | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/snark-verifier-sdk/src/halo2/aggregation.rs b/snark-verifier-sdk/src/halo2/aggregation.rs index f361b876..b5dc148d 100644 --- a/snark-verifier-sdk/src/halo2/aggregation.rs +++ b/snark-verifier-sdk/src/halo2/aggregation.rs @@ -57,6 +57,9 @@ pub type Halo2Loader<'chip> = loader::halo2::Halo2Loader( svk: &Svk, loader: &Rc>, @@ -76,6 +79,7 @@ where VerifyingKey = KzgAsVerifyingKey, >, { + assert!(!snarks.is_empty(), "trying to aggregate 0 snarks"); let assign_instances = |instances: &[Vec]| { instances .iter() diff --git a/snark-verifier/src/loader/evm/loader.rs b/snark-verifier/src/loader/evm/loader.rs index f6bf17b2..98ca5ca4 100644 --- a/snark-verifier/src/loader/evm/loader.rs +++ b/snark-verifier/src/loader/evm/loader.rs @@ -663,7 +663,7 @@ where _ => ec_point.loader.ec_point_scalar_mul(ec_point, scalar), }) .reduce(|acc, ec_point| acc.loader.ec_point_add(&acc, &ec_point)) - .unwrap() + .expect("pairs should not be empty") } } diff --git a/snark-verifier/src/loader/halo2/loader.rs b/snark-verifier/src/loader/halo2/loader.rs index 9a8410d6..31be9841 100644 --- a/snark-verifier/src/loader/halo2/loader.rs +++ b/snark-verifier/src/loader/halo2/loader.rs @@ -536,6 +536,7 @@ impl> EcPointLoader for Rc>::LoadedScalar, &EcPoint)], ) -> EcPoint { + assert!(!pairs.is_empty(), "multi_scalar_multiplication: pairs is empty"); let loader = &pairs[0].0.loader; let (constant, fixed_base, variable_base_non_scaled, variable_base_scaled) = diff --git a/snark-verifier/src/loader/native.rs b/snark-verifier/src/loader/native.rs index 96e7239a..783aaa89 100644 --- a/snark-verifier/src/loader/native.rs +++ b/snark-verifier/src/loader/native.rs @@ -66,7 +66,7 @@ impl EcPointLoader for NativeLoader { .cloned() .map(|(scalar, base)| *base * scalar) .reduce(|acc, value| acc + value) - .unwrap() + .expect("pairs should not be empty") .to_affine() } }