Skip to content

Commit

Permalink
circuit: Add verifying key correctness checks in SP1CompressVerifier
Browse files Browse the repository at this point in the history
This PR adds verifying key (VK) correctness checks in the SP1CompressVerifier::verify method. The changes ensure that:

1. All VK commitments are non-zero, preventing invalid or uninitialized VKs from being used
2. Each VK's digest matches the expected root VK digest, maintaining consistency across the verification chain

These checks are crucial for maintaining the security and correctness of the recursive proof verification process. The validation happens before any proof verification begins, ensuring that we fail fast if any VK is invalid.

Technical changes:
- Added VK commitment non-zero checks using builder.assert_bool_felt_neq
- Added VK digest verification against the root VK using StarkVerifier::compute_vk_digest
- Implemented checks in a loop to validate all VKs in the batch

Testing:
- Existing tests should pass
- Additional tests for VK validation would be beneficial (can be added if requested)
  • Loading branch information
VolodymyrBg authored Jan 29, 2025
1 parent dbe622a commit e60b077
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/recursion/circuit/src/machine/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,20 @@ where
let compress_public_values: &mut RecursionPublicValues<_> =
reduce_public_values_stream.as_mut_slice().borrow_mut();

// TODO: add vk correctness check.
// Verify that all VKs are valid and consistent with the root VK
for (vk, _) in vks_and_proofs.iter() {
// Check that VK commitment is not zero
let zero = builder.eval(C::F::zero());
for commitment in vk.commitment.iter() {
builder.assert_bool_felt_neq(*commitment, zero);
}

// Verify VK root matches the expected root
let vk_digest = StarkVerifier::compute_vk_digest(builder, vk);
for (expected, actual) in vk_root.iter().zip(vk_digest.iter()) {
builder.assert_felt_eq(*expected, *actual);
}
}

// Make sure there is at least one proof.
assert!(!vks_and_proofs.is_empty());
Expand Down

0 comments on commit e60b077

Please sign in to comment.