Skip to content

Commit 04c475f

Browse files
committed
make the range of the supported rate values (in WHIR) = 1/2, 1/4, 1/8, 1/16 more explicit
1 parent 9fbf13f commit 04c475f

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

crates/backend/fiat-shamir/src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ use std::{error::Error, fmt::Display};
2323
/// An error happened when creating or verifying a proof.
2424
#[derive(Debug, Clone)]
2525
pub enum ProofError {
26-
/// Signals the verification equation has failed.
2726
InvalidProof,
28-
/// Verifier is asking more data than what was provided in the transcript.
2927
ExceededTranscript,
30-
/// Invalid Pow Grinding
3128
InvalidGrindingWitness,
32-
/// Invalid Padding in the transcript
3329
InvalidPadding,
30+
InvalidRate,
3431
}
3532

3633
/// The result type when trying to prove or verify a proof using Fiat-Shamir.
@@ -43,6 +40,10 @@ impl Display for ProofError {
4340
Self::ExceededTranscript => write!(f, "Verifier exceeded transcript length"),
4441
Self::InvalidGrindingWitness => write!(f, "Invalid grinding witness"),
4542
Self::InvalidPadding => write!(f, "Invalid padding in the transcript"),
43+
Self::InvalidRate => write!(
44+
f,
45+
"LeanVM supports rate 1/2, 1/4, 1/8 and 1/16 (log_inv_rate in {{1, 2, 3, 4}})"
46+
),
4647
}
4748
}
4849
}

crates/lean_prover/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(not(test), allow(unused_crate_dependencies))]
22

33
use backend::*;
4-
use lean_vm::{EF, F};
4+
use lean_vm::{EF, F, MAX_WHIR_LOG_INV_RATE, MIN_WHIR_LOG_INV_RATE};
55
use utils::*;
66

77
mod trace_gen;
@@ -44,6 +44,14 @@ pub fn default_whir_config(starting_log_inv_rate: usize) -> WhirConfigBuilder {
4444
}
4545
}
4646

47+
pub(crate) fn check_rate(log_inv_rate: usize) -> Result<(), ProofError> {
48+
if (MIN_WHIR_LOG_INV_RATE..=MAX_WHIR_LOG_INV_RATE).contains(&log_inv_rate) {
49+
Ok(())
50+
} else {
51+
Err(ProofError::InvalidRate)
52+
}
53+
}
54+
4755
#[cfg(test)]
4856
mod tests {
4957
use backend::default_koalabear_poseidon2_16;

crates/lean_prover/src/prove_execution.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn prove_execution(
2222
whir_config: &WhirConfigBuilder,
2323
vm_profiler: bool,
2424
) -> ExecutionProof {
25+
check_rate(whir_config.starting_log_inv_rate).unwrap();
2526
let ExecutionTrace {
2627
traces,
2728
public_memory_size,

crates/lean_prover/src/verify_execution.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ pub fn verify_execution(
3232
return Err(ProofError::InvalidProof);
3333
}
3434
let table_n_vars: BTreeMap<Table, VarCount> = (0..N_TABLES).map(|i| (ALL_TABLES[i], dims[i + 3])).collect();
35-
if !(MIN_WHIR_LOG_INV_RATE..=MAX_WHIR_LOG_INV_RATE).contains(&log_inv_rate) {
36-
return Err(ProofError::InvalidProof);
37-
}
35+
check_rate(log_inv_rate)?;
3836
let whir_config = default_whir_config(log_inv_rate);
3937
for (table, &n_vars) in &table_n_vars {
4038
if n_vars < MIN_LOG_N_ROWS_PER_TABLE {

0 commit comments

Comments
 (0)