Skip to content

Commit f8a8069

Browse files
committed
fix edge case: make proofs work even for very small programs
1 parent 1fb6678 commit f8a8069

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

crates/lean_prover/tests/test_zkvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ fn test_zk_vm_no_precompiles() {
6969
let program_str = r#"
7070
7171
fn main() {
72-
for i in 0..1000 {
73-
assert i != 1000;
72+
for i in 0..10 {
73+
assert i != 10;
7474
}
7575
return;
7676
}

crates/lean_prover/witness_generation/src/execution_trace.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::instruction_encoder::field_representation;
44
use crate::{
55
COL_INDEX_FP, COL_INDEX_MEM_ADDRESS_A, COL_INDEX_MEM_ADDRESS_B, COL_INDEX_MEM_ADDRESS_C,
66
COL_INDEX_MEM_VALUE_A, COL_INDEX_MEM_VALUE_B, COL_INDEX_MEM_VALUE_C, COL_INDEX_PC,
7-
LOG_MIN_POSEIDONS_16, LOG_MIN_POSEIDONS_24, N_TOTAL_COLUMNS,
7+
LOG_MIN_DOT_PRODUCT_ROWS, LOG_MIN_POSEIDONS_16, LOG_MIN_POSEIDONS_24, N_TOTAL_COLUMNS,
88
};
99
use lean_vm::*;
1010
use p3_field::Field;
@@ -29,9 +29,21 @@ pub struct ExecutionTrace {
2929

3030
pub fn get_execution_trace(
3131
bytecode: &Bytecode,
32-
execution_result: ExecutionResult,
32+
mut execution_result: ExecutionResult,
3333
) -> ExecutionTrace {
3434
assert_eq!(execution_result.pcs.len(), execution_result.fps.len());
35+
36+
// padding to make proof work even on small programs (TODO make this more elegant)
37+
let min_cycles = 32 << LOG_MIN_DOT_PRODUCT_ROWS;
38+
if execution_result.pcs.len() < min_cycles {
39+
execution_result
40+
.pcs
41+
.resize(min_cycles, *execution_result.pcs.last().unwrap());
42+
execution_result
43+
.fps
44+
.resize(min_cycles, *execution_result.fps.last().unwrap());
45+
}
46+
3547
let n_cycles = execution_result.pcs.len();
3648
let memory = &execution_result.memory;
3749
let log_n_cycles_rounded_up = n_cycles.next_power_of_two().ilog2() as usize;

0 commit comments

Comments
 (0)