diff --git a/src/verifier.rs b/src/verifier.rs index 4eecb3c..5b62614 100644 --- a/src/verifier.rs +++ b/src/verifier.rs @@ -5,7 +5,7 @@ use crate::{r1cs_to_qap::R1CSToQAP, Groth16}; use super::{PreparedVerifyingKey, Proof, VerifyingKey}; -use ark_relations::gr1cs::Result as R1CSResult; +use ark_relations::gr1cs::{Result as R1CSResult, SynthesisError}; use core::ops::{AddAssign, Neg}; @@ -26,6 +26,12 @@ impl Groth16 { pvk: &PreparedVerifyingKey, public_inputs: &[E::ScalarField], ) -> R1CSResult { + // Ensure the number of provided public inputs matches the verification key query length. + // Expected: gamma_abc_g1 has 1 extra element accounting for the constant term. + if public_inputs.len() + 1 != pvk.vk.gamma_abc_g1.len() { + return Err(SynthesisError::AssignmentMissing); + } + let mut g_ic = pvk.vk.gamma_abc_g1[0].into_group(); for (i, b) in public_inputs.iter().zip(pvk.vk.gamma_abc_g1.iter().skip(1)) { g_ic.add_assign(&b.mul_bigint(i.into_bigint()));