@@ -29,6 +29,11 @@ impl Verifier {
2929 FieldElement < F > : ByteConversion ,
3030 <F as IsField >:: BaseType : Send + Sync + Copy ,
3131 {
32+ // The proof should haver one layer-proof for each circuit layer.
33+ if proof. layer_proofs . len ( ) != circuit. layers ( ) . len ( ) {
34+ println ! ( "The proof has an invalid number of proof layers" ) ;
35+ return Ok ( false ) ;
36+ }
3237 // Fiat-Shamir heuristic:
3338 // Both parties need to to append to the transcript the circuit, the inputs and the outputs.
3439 // See https://eprint.iacr.org/2025/118.pdf, Sections 2.1 and 2.2
@@ -57,6 +62,16 @@ impl Verifier {
5762
5863 // For each layer, verify the sumcheck proof and calculate the next layer's challenges and claimed sum.
5964 for ( layer_idx, layer_proof) in proof. layer_proofs . iter ( ) . enumerate ( ) {
65+ // The number of sumcheck round polynomials `g_j` should be `2 * k_{i+1}`,
66+ // where `k_{i+1} = next_num_vars` is the number of variables in the next layer.
67+ let next_num_vars = circuit
68+ . num_vars_at ( layer_idx + 1 )
69+ . ok_or ( VerifierError :: InvalidProof ) ?;
70+ if layer_proof. sumcheck_proof . round_polynomials . len ( ) != 2 * next_num_vars {
71+ println ! ( "The proof has an invalid number of sumcheck round polynomials at layer {layer_idx}" ) ;
72+ return Ok ( false ) ;
73+ }
74+
6075 // Sumcheck verification.
6176 let ( sumcheck_verified, sumcheck_challenges) = gkr_sumcheck_verify (
6277 claimed_sum. clone ( ) ,
0 commit comments