Skip to content

Commit 05e9096

Browse files
committed
don't harcode LOG_INV_RATE in recursion program
1 parent ce967ea commit 05e9096

File tree

10 files changed

+50
-32
lines changed

10 files changed

+50
-32
lines changed

crates/lean_prover/src/prove_execution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn prove_execution(
5151
let mut prover_state = build_prover_state();
5252
prover_state.add_base_scalars(
5353
&[
54-
vec![log2_strict_usize(memory.len())],
54+
vec![whir_config.starting_log_inv_rate, log2_strict_usize(memory.len())],
5555
traces.values().map(|t| t.log_n_rows).collect::<Vec<_>>(),
5656
]
5757
.concat()

crates/lean_prover/src/test_zkvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn test_zk_vm_helper(program_str: &str, (public_input, private_input): (&[F], &[
162162
&bytecode,
163163
public_input,
164164
proof.proof.clone(),
165-
&default_whir_config(starting_log_inv_rate, false),
165+
default_whir_config(starting_log_inv_rate, false),
166166
)
167167
.unwrap();
168168
println!("{}", proof.exec_summary);
@@ -183,7 +183,7 @@ fn test_zk_vm_helper(program_str: &str, (public_input, private_input): (&[F], &[
183183
&bytecode,
184184
public_input,
185185
fuzzed_proof,
186-
&default_whir_config(starting_log_inv_rate, false),
186+
default_whir_config(starting_log_inv_rate, false),
187187
);
188188
assert!(verify_result.is_err(), "Fuzzing failed at index {}", i);
189189
}

crates/lean_prover/src/verify_execution.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ pub fn verify_execution(
2020
bytecode: &Bytecode,
2121
public_input: &[F],
2222
proof: Vec<F>,
23-
whir_config: &WhirConfigBuilder,
23+
mut whir_config: WhirConfigBuilder,
2424
) -> Result<ProofVerificationDetails, ProofError> {
2525
let mut verifier_state = VerifierState::<EF, _>::new(proof, get_poseidon16().clone());
2626

2727
let dims = verifier_state
28-
.next_base_scalars_vec(1 + N_TABLES)?
28+
.next_base_scalars_vec(2 + N_TABLES)?
2929
.into_iter()
3030
.map(|x| x.to_usize())
3131
.collect::<Vec<_>>();
32-
let log_memory = dims[0];
33-
let table_n_vars: BTreeMap<Table, VarCount> = (0..N_TABLES).map(|i| (ALL_TABLES[i], dims[i + 1])).collect();
32+
let log_inv_rate = dims[0];
33+
let log_memory = dims[1];
34+
let table_n_vars: BTreeMap<Table, VarCount> = (0..N_TABLES).map(|i| (ALL_TABLES[i], dims[i + 2])).collect();
35+
if !(MIN_WHIR_LOG_INV_RATE..=MAX_WHIR_LOG_INV_RATE).contains(&log_inv_rate) {
36+
return Err(ProofError::InvalidProof);
37+
}
38+
whir_config.starting_log_inv_rate = log_inv_rate;
3439
for (table, &n_vars) in &table_n_vars {
3540
if n_vars < MIN_LOG_N_ROWS_PER_TABLE {
3641
return Err(ProofError::InvalidProof);
@@ -57,7 +62,7 @@ pub fn verify_execution(
5762
}
5863

5964
let parsed_commitment = stacked_pcs_parse_commitment(
60-
whir_config,
65+
&whir_config,
6166
&mut verifier_state,
6267
log_memory,
6368
bytecode.log_size(),
@@ -145,7 +150,7 @@ pub fn verify_execution(
145150
&committed_statements,
146151
);
147152
let total_whir_statements = global_statements_base.iter().map(|s| s.values.len()).sum();
148-
WhirConfig::new(whir_config, parsed_commitment.num_variables).verify(
153+
WhirConfig::new(&whir_config, parsed_commitment.num_variables).verify(
149154
&mut verifier_state,
150155
&parsed_commitment,
151156
global_statements_base,

crates/lean_vm/src/core/constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pub const DIMENSION: usize = 5;
55

66
pub const DIGEST_LEN: usize = 8;
77

8+
pub const MIN_WHIR_LOG_INV_RATE: usize = 1;
9+
pub const MAX_WHIR_LOG_INV_RATE: usize = 4;
10+
811
/// Minimum and maximum memory size (as powers of two)
912
pub const MIN_LOG_MEMORY_SIZE: usize = 16;
1013
pub const MAX_LOG_MEMORY_SIZE: usize = 26;

crates/lean_vm/src/execution/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Memory {
5050
if index >= 1 << MAX_LOG_MEMORY_SIZE {
5151
return Err(RunnerError::OutOfMemory);
5252
}
53-
self.0.resize((index + 1).next_power_of_two(), None);
53+
self.0.resize(index + 1, None);
5454
}
5555
if let Some(existing) = &mut self.0[index] {
5656
if *existing != value {

crates/rec_aggregation/recursion.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from whir import *
33

44
N_TABLES = N_TABLES_PLACEHOLDER
5+
6+
MIN_WHIR_LOG_INV_RATE = MIN_WHIR_LOG_INV_RATE_PLACEHOLDER
7+
MAX_WHIR_LOG_INV_RATE = MAX_WHIR_LOG_INV_RATE_PLACEHOLDER
58
MIN_LOG_N_ROWS_PER_TABLE = MIN_LOG_N_ROWS_PER_TABLE_PLACEHOLDER
69
MAX_LOG_N_ROWS_PER_TABLE = MAX_LOG_N_ROWS_PER_TABLE_PLACEHOLDER
710
MIN_LOG_MEMORY_SIZE = MIN_LOG_MEMORY_SIZE_PLACEHOLDER
@@ -61,12 +64,16 @@ def recursion(inner_public_memory_log_size, inner_public_memory, proof_transcrip
6164

6265
# table dims
6366
debug_assert(N_TABLES + 1 < DIGEST_LEN)
64-
fs, mem_and_table_dims = fs_receive_chunks(fs, 1)
65-
for i in unroll(N_TABLES + 1, 8):
66-
assert mem_and_table_dims[i] == 0
67-
log_memory = mem_and_table_dims[0]
67+
fs, dims = fs_receive_chunks(fs, 1)
68+
for i in unroll(N_TABLES + 2, 8):
69+
assert dims[i] == 0
70+
whir_log_inv_rate = dims[0]
71+
log_memory = dims[1]
72+
table_log_heights = dims + 2
73+
74+
assert MIN_WHIR_LOG_INV_RATE <= whir_log_inv_rate
75+
assert whir_log_inv_rate <= MAX_WHIR_LOG_INV_RATE
6876

69-
table_log_heights = mem_and_table_dims + 1
7077
log_n_cycles = table_log_heights[EXECUTION_TABLE_INDEX]
7178
assert log_n_cycles <= log_memory
7279

@@ -85,6 +92,7 @@ def recursion(inner_public_memory_log_size, inner_public_memory, proof_transcrip
8592
assert log_memory <= GUEST_BYTECODE_LEN
8693

8794
stacked_n_vars = compute_stacked_n_vars(log_memory, log_bytecode_padded, table_heights)
95+
assert stacked_n_vars <= TWO_ADICITY + WHIR_FOLDING_FACTORS[0] - whir_log_inv_rate
8896

8997
fs, whir_base_root, whir_base_ood_points, whir_base_ood_evals = parse_whir_commitment_const(fs, WHIR_NUM_OOD_COMMIT)
9098

@@ -486,6 +494,7 @@ def recursion(inner_public_memory_log_size, inner_public_memory, proof_transcrip
486494
fs, folding_randomness_global, s, final_value, end_sum = whir_open(
487495
fs,
488496
stacked_n_vars,
497+
whir_log_inv_rate,
489498
whir_base_root,
490499
whir_base_ood_points,
491500
combination_randomness_powers,

crates/rec_aggregation/src/recursion.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,12 @@ def main():
6565
&bytecode_to_prove,
6666
&inner_public_input,
6767
proof_to_prove.proof.clone(),
68-
&inner_whir_config,
68+
inner_whir_config.clone(),
6969
)
7070
.unwrap();
7171

7272
let outer_whir_config = WhirConfig::<EF>::new(&inner_whir_config, proof_to_prove.whir_n_vars);
7373

74-
// let guest_program_commitment = {
75-
// let mut prover_state = build_prover_state();
76-
// let polynomial = MleOwned::Base(bytecode_to_multilinear_polynomial(&bytecode_to_prove.instructions));
77-
// let witness = ext_whir.commit(&mut prover_state, &polynomial);
78-
// let commitment_transcript = prover_state.proof().to_vec();
79-
// assert_eq!(commitment_transcript.len(), ext_whir.committment_ood_samples * DIMENSION + VECTOR_LEN);
80-
// };
81-
8274
let mut replacements = whir_recursion_placeholder_replacements(&outer_whir_config);
8375

8476
assert!(
@@ -106,6 +98,14 @@ def main():
10698
max_log_n_rows_per_table.sort_by_key(|(table, _)| table.index());
10799
max_log_n_rows_per_table.dedup();
108100
assert_eq!(max_log_n_rows_per_table.len(), N_TABLES);
101+
replacements.insert(
102+
"MIN_WHIR_LOG_INV_RATE_PLACEHOLDER".to_string(),
103+
MIN_WHIR_LOG_INV_RATE.to_string(),
104+
);
105+
replacements.insert(
106+
"MAX_WHIR_LOG_INV_RATE_PLACEHOLDER".to_string(),
107+
MAX_WHIR_LOG_INV_RATE.to_string(),
108+
);
109109
replacements.insert(
110110
"MAX_LOG_N_ROWS_PER_TABLE_PLACEHOLDER".to_string(),
111111
format!(
@@ -335,7 +335,7 @@ def main():
335335
&recursion_bytecode,
336336
&outer_public_input,
337337
recursion_proof.proof,
338-
&default_whir_config(log_inv_rate, prox_gaps_conjecture),
338+
default_whir_config(log_inv_rate, prox_gaps_conjecture),
339339
)
340340
.unwrap();
341341
println!(
@@ -396,10 +396,6 @@ pub(crate) fn whir_recursion_placeholder_replacements(whir_config: &WhirConfig<E
396396
format!("WHIR_FOLDING_FACTORS{}", end),
397397
format!("[{}]", folding_factors.join(", ")),
398398
);
399-
replacements.insert(
400-
format!("WHIR_LOG_INV_RATE{}", end),
401-
whir_config.starting_log_inv_rate.to_string(),
402-
);
403399
replacements.insert(
404400
format!("WHIR_FINAL_VARS{}", end),
405401
whir_config.n_vars_of_final_polynomial().to_string(),

crates/rec_aggregation/src/xmss_aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn xmss_verify_aggregated_signatures(
223223
program,
224224
&public_input,
225225
proof,
226-
&default_whir_config(log_inv_rate, prox_gaps_conjecture),
226+
default_whir_config(log_inv_rate, prox_gaps_conjecture),
227227
)
228228
.map(|_| ())
229229
}

crates/rec_aggregation/whir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from snark_lib import *
22
from fiat_shamir import *
33

4-
WHIR_LOG_INV_RATE = WHIR_LOG_INV_RATE_PLACEHOLDER
54
WHIR_FOLDING_FACTORS = WHIR_FOLDING_FACTORS_PLACEHOLDER
65
WHIR_FINAL_VARS = WHIR_FINAL_VARS_PLACEHOLDER
76
WHIR_FIRST_RS_REDUCTION_FACTOR = WHIR_FIRST_RS_REDUCTION_FACTOR_PLACEHOLDER
@@ -13,6 +12,7 @@
1312
def whir_open(
1413
fs: Mut,
1514
n_vars,
15+
initial_log_inv_rate,
1616
root: Mut,
1717
ood_points_commit,
1818
combination_randomness_powers_0,
@@ -23,7 +23,7 @@ def whir_open(
2323
all_circle_values = Array(WHIR_N_ROUNDS + 1)
2424
all_combination_randomness_powers = Array(WHIR_N_ROUNDS)
2525

26-
domain_sz: Mut = n_vars + WHIR_LOG_INV_RATE
26+
domain_sz: Mut = n_vars + initial_log_inv_rate
2727
for r in unroll(0, WHIR_N_ROUNDS):
2828
is_first_round: Imu
2929
if r == 0:

crates/sub_protocols/src/stacked_pcs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ pub fn stacked_pcs_parse_commitment(
167167
}
168168

169169
let stacked_n_vars = compute_stacked_n_vars(log_memory, log_bytecode, tables_heights);
170+
if stacked_n_vars
171+
> F::TWO_ADICITY + whir_config_builder.folding_factor.at_round(0) - whir_config_builder.starting_log_inv_rate
172+
{
173+
return Err(ProofError::InvalidProof);
174+
}
170175
WhirConfig::new(whir_config_builder, stacked_n_vars).parse_commitment(verifier_state)
171176
}
172177

0 commit comments

Comments
 (0)