Skip to content

Commit ebdf8cd

Browse files
nicole-grausjotabulacios
authored andcommitted
add verifier checks: proof structure match circuit structure
1 parent feb370e commit ebdf8cd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/provers/gkr/src/sumcheck.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ where
148148
}
149149
}
150150

151-
// Check that the degree of g_j does not exceed the theoretical bound
151+
// Check that the degree of `g_j` does not exceed the theoretical bound.
152+
// The polynomial `g_j` should be cuadratic since the polynomial `f(b,c)` to which the sumcheck is applied
153+
// is the sum of of two products, where each one is the product of two multilinear polynomials.
152154
if g_j.degree() > 2 {
153155
return Err(crate::verifier::VerifierError::InvalidDegree);
154156
}

crates/provers/gkr/src/verifier.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)