Skip to content

Commit

Permalink
Merge pull request #2756 from o1-labs/chunking/zkrows_error-develop
Browse files Browse the repository at this point in the history
[easy] `develop` counterpart of PR#2590
  • Loading branch information
dannywillems authored Nov 14, 2024
2 parents f2134c8 + 0f1718b commit 872c8f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions kimchi/src/circuits/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,22 @@ impl<F: PrimeField> ConstraintSystem<F> {
}
}

/// The default number of chunks in a circuit is one (< 2^16 rows)
pub const NUM_CHUNKS_BY_DEFAULT: usize = 1;

/// The number of rows required for zero knowledge in circuits with one single chunk
pub const ZK_ROWS_BY_DEFAULT: u64 = 3;

/// This function computes a strict lower bound in the number of rows required
/// for zero knowledge in circuits with `num_chunks` chunks. This means that at
/// least one needs 1 more row than the result of this function to achieve zero
/// knowledge.
/// Example:
/// for 1 chunk, this function returns 2, but at least 3 rows are needed
/// Note:
/// the number of zero knowledge rows is usually computed across the codebase
/// as the formula `(16 * num_chunks + 5) / 7`, which is precisely the formula
/// in this function plus one.
pub fn zk_rows_strict_lower_bound(num_chunks: usize) -> usize {
(2 * (PERMUTS + 1) * num_chunks - 2) / PERMUTS
}
Expand Down
12 changes: 10 additions & 2 deletions kimchi/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,17 @@ where
.ok_or(ProverError::NoRoomForZkInWitness)?;

let zero_knowledge_limit = zk_rows_strict_lower_bound(num_chunks);
if (index.cs.zk_rows as usize) < zero_knowledge_limit {
// Because the lower bound is strict, the result of the function above
// is not a sufficient number of zero knowledge rows, so the error must
// be raised anytime the number of zero knowledge rows is not greater
// than the strict lower bound.
// Example:
// for 1 chunk, `zero_knowledge_limit` is 2, and we need at least 3,
// thus the error should be raised and the message should say that the
// expected number of zero knowledge rows is 3 (hence the + 1).
if (index.cs.zk_rows as usize) <= zero_knowledge_limit {
return Err(ProverError::NotZeroKnowledge(
zero_knowledge_limit,
zero_knowledge_limit + 1,
index.cs.zk_rows as usize,
));
}
Expand Down

0 comments on commit 872c8f2

Please sign in to comment.