Skip to content

Commit dfd4c53

Browse files
committed
Return false instead of panicking on zero GKR root denominator
1 parent d04f642 commit dfd4c53

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

crypto/stark/src/gkr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,14 @@ pub fn gkr_verify_batch<E: IsField>(
20472047
// instance i's child layer has (n_layers[i] - n_remaining + 1) variables,
20482048
// so the parent has (n_layers[i] - n_remaining) variables.
20492049
let parent_num_vars_i = n_layers_by_instance[i] - n_remaining;
2050+
if num_rounds < parent_num_vars_i {
2051+
return Err(GkrError::InvalidTree {
2052+
reason: format!(
2053+
"layer {}: num_rounds ({}) < parent_num_vars for instance {} ({})",
2054+
layer_idx, num_rounds, i, parent_num_vars_i,
2055+
),
2056+
});
2057+
}
20502058
let sumcheck_n_unused = num_rounds - parent_num_vars_i;
20512059

20522060
// eq evaluation: the prover builds eq from the instance-specific eval point

crypto/stark/src/verifier.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,14 @@ pub trait IsStarkVerifier<
990990
let contrib = if *root_d == FieldElement::one() {
991991
root_n.clone()
992992
} else {
993-
root_n * &root_d.inv().expect("GKR root denominator must be non-zero")
993+
match root_d.inv() {
994+
Ok(inv) => root_n * &inv,
995+
Err(_) => {
996+
#[cfg(not(feature = "test_fiat_shamir"))]
997+
error!("GKR root denominator is zero — invalid proof");
998+
return false;
999+
}
1000+
}
9941001
};
9951002
total = total + &contrib;
9961003
}

0 commit comments

Comments
 (0)