Skip to content

Commit ee7377f

Browse files
implement some suggestions from @this-vishalsingh
Co-authored-by: thisvishalsingh <93567955+this-vishalsingh@users.noreply.github.com>
1 parent 0a2c522 commit ee7377f

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ pub(crate) use merkle_pruning::*;
2020

2121
mod verifier;
2222
pub use verifier::*;
23+
24+
const _: () = assert!(usize::BITS >= 32); // PoW grinding / Whir merkle index never exceeds 24 bits < 32

crates/lean_prover/src/prove_execution.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ pub fn prove_execution(
4444
prover_state.observe_scalars(&poseidon16_compress_pair(&bytecode.hash, &SNARK_DOMAIN_SEP));
4545
prover_state.add_base_scalars(
4646
&[
47-
vec![whir_config.starting_log_inv_rate, log2_strict_usize(memory.len())],
47+
vec![
48+
whir_config.starting_log_inv_rate,
49+
log2_strict_usize(memory.len()),
50+
public_input.len(),
51+
],
4852
traces.values().map(|t| t.log_n_rows).collect::<Vec<_>>(),
4953
]
5054
.concat()

crates/lean_prover/src/verify_execution.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ pub fn verify_execution(
2121
verifier_state.observe_scalars(public_input);
2222
verifier_state.observe_scalars(&poseidon16_compress_pair(&bytecode.hash, &SNARK_DOMAIN_SEP));
2323
let dims = verifier_state
24-
.next_base_scalars_vec(2 + N_TABLES)?
24+
.next_base_scalars_vec(3 + N_TABLES)?
2525
.into_iter()
2626
.map(|x| x.to_usize())
2727
.collect::<Vec<_>>();
2828
let log_inv_rate = dims[0];
2929
let log_memory = dims[1];
30-
let table_n_vars: BTreeMap<Table, VarCount> = (0..N_TABLES).map(|i| (ALL_TABLES[i], dims[i + 2])).collect();
30+
let public_input_len = dims[2]; // enforce the exact length of the public input to pass through Fiat Shamir (otherwise we could have 2 public inputs, only differing by a few (<8) zeros in the end, leading to the same fiat shamir state: tipically giving the advseary 2 or 3 bits of advantage in the subsequent part where the public input is evaluated as a multilinear polynomial)
31+
if public_input_len != public_input.len() {
32+
return Err(ProofError::InvalidProof);
33+
}
34+
let table_n_vars: BTreeMap<Table, VarCount> = (0..N_TABLES).map(|i| (ALL_TABLES[i], dims[i + 3])).collect();
3135
if !(MIN_WHIR_LOG_INV_RATE..=MAX_WHIR_LOG_INV_RATE).contains(&log_inv_rate) {
3236
return Err(ProofError::InvalidProof);
3337
}

crates/rec_aggregation/recursion.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ def recursion(inner_public_memory, proof_transcript, bytecode_value_hint):
5252
# table dims
5353
debug_assert(N_TABLES + 1 < DIGEST_LEN)
5454
fs, dims = fs_receive_chunks(fs, 1)
55-
for i in unroll(N_TABLES + 2, 8):
55+
for i in unroll(N_TABLES + 3, 8):
5656
assert dims[i] == 0
5757
whir_log_inv_rate = dims[0]
5858
log_memory = dims[1]
59-
table_log_heights = dims + 2
59+
public_input_len = dims[2]
60+
table_log_heights = dims + 3
61+
62+
assert public_input_len == PUB_INPUT_SIZE
6063

6164
assert MIN_WHIR_LOG_INV_RATE <= whir_log_inv_rate
6265
assert whir_log_inv_rate <= MAX_WHIR_LOG_INV_RATE

0 commit comments

Comments
 (0)