Skip to content

Commit 84880e9

Browse files
only 1 execution, at witness generation, instead of 2, using precomputed values (idea by Lambdaclass)
Co-authored-by: Mauro Toscano <[email protected]>
1 parent 26ee048 commit 84880e9

File tree

14 files changed

+187
-228
lines changed

14 files changed

+187
-228
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
- Lev's trick to skip some low-level modular reduction
2020
- Sumcheck, case z = 0, no need to fold, only keep first half of the values (done in PR 33 by Lambda) (and also in WHIR?)
2121
- Custom AVX2 / AVX512 / Neon implem in Plonky3 for all of the finite field operations (done for degree 4 extension, but not degree 5)
22-
- the 2 executions of the program, before generating the validity proof, can be merged, using some kind of placeholders
2322
- Many times, we evaluate different multilinear polynomials (diferent columns of the same table etc) at a common point. OPTI = compute the eq(.) once, and then dot_product with everything
2423
- To commit to multiple AIR table using 1 single pcs, the most general form our "packed pcs" api should accept is:
2524
a list of n (n not a power of 2) columns, each ending with m repeated values (in this manner we can reduce proof size when they are a lot of columns (poseidons ...))

benches/xmss.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::{hint::black_box, time::Duration};
22

33
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
4-
use rec_aggregation::bench_xmss;
4+
use rec_aggregation::run_xmss_benchmark;
55

66
fn bench_xmss_benchmark(c: &mut Criterion) {
77
const N: usize = 500;
8-
const LOG_LIFETIME: usize = 32;
98

109
let mut group = c.benchmark_group("xmss");
1110
group.sample_size(10);
@@ -15,7 +14,7 @@ fn bench_xmss_benchmark(c: &mut Criterion) {
1514

1615
group.bench_function("xmss", |b| {
1716
b.iter(|| {
18-
let duration = bench_xmss(N, LOG_LIFETIME);
17+
let duration = run_xmss_benchmark(N).proving_time;
1918
black_box(duration);
2019
});
2120
});

crates/lean_compiler/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@ pub fn compile_program(program: &str) -> (Bytecode, BTreeMap<usize, String>) {
3232
(compiled, function_locations)
3333
}
3434

35-
pub fn compile_and_run(program: &str, public_input: &[F], private_input: &[F], profiler: bool) {
35+
pub fn compile_and_run(
36+
program: &str,
37+
public_input: &[F],
38+
private_input: &[F],
39+
no_vec_runtime_memory: usize, // size of the "non-vectorized" runtime memory
40+
profiler: bool,
41+
) {
3642
let (bytecode, function_locations) = compile_program(program);
3743
execute_bytecode(
3844
&bytecode,
3945
public_input,
4046
private_input,
4147
program,
4248
&function_locations,
49+
no_vec_runtime_memory,
4350
profiler,
4451
);
4552
}

crates/lean_compiler/tests/test_compiler.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use lean_vm::*;
33
use p3_symmetric::Permutation;
44
use utils::{get_poseidon16, get_poseidon24};
55

6+
const DEFAULT_NO_VEC_RUNTIME_MEMORY: usize = 1 << 15;
7+
68
#[test]
79
#[should_panic]
810
fn test_duplicate_function_name() {
@@ -20,7 +22,7 @@ fn test_duplicate_function_name() {
2022
return;
2123
}
2224
"#;
23-
compile_and_run(program, &[], &[], false);
25+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
2426
}
2527

2628
#[test]
@@ -34,7 +36,7 @@ fn test_duplicate_constant_name() {
3436
return;
3537
}
3638
"#;
37-
compile_and_run(program, &[], &[], false);
39+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
3840
}
3941

4042
#[test]
@@ -55,7 +57,7 @@ fn test_fibonacci_program() {
5557
return;
5658
}
5759
"#;
58-
compile_and_run(program, &[], &[], false);
60+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
5961
}
6062

6163
#[test]
@@ -73,7 +75,7 @@ fn test_edge_case_0() {
7375
return;
7476
}
7577
"#;
76-
compile_and_run(program, &[], &[], false);
78+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
7779
}
7880

7981
#[test]
@@ -86,7 +88,7 @@ fn test_edge_case_1() {
8688
return;
8789
}
8890
"#;
89-
compile_and_run(program, &[], &[], false);
91+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
9092
}
9193

9294
#[test]
@@ -104,7 +106,7 @@ fn test_edge_case_2() {
104106
return;
105107
}
106108
"#;
107-
compile_and_run(program, &[], &[], false);
109+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
108110
}
109111

110112
#[test]
@@ -120,7 +122,7 @@ fn test_decompose_bits() {
120122
return;
121123
}
122124
"#;
123-
compile_and_run(program, &[], &[], false);
125+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
124126
}
125127

126128
#[test]
@@ -136,7 +138,7 @@ fn test_unroll() {
136138
return;
137139
}
138140
"#;
139-
compile_and_run(program, &[], &[], false);
141+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
140142
}
141143

142144
#[test]
@@ -148,7 +150,7 @@ fn test_rev_unroll() {
148150
return;
149151
}
150152
"#;
151-
compile_and_run(program, &[], &[], false);
153+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
152154
}
153155

154156
#[test]
@@ -168,7 +170,7 @@ fn test_mini_program_0() {
168170
return;
169171
}
170172
"#;
171-
compile_and_run(program, &[], &[], false);
173+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
172174
}
173175

174176
#[test]
@@ -211,7 +213,7 @@ fn test_mini_program_1() {
211213
return;
212214
}
213215
"#;
214-
compile_and_run(program, &[], &[], false);
216+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
215217
}
216218

217219
#[test]
@@ -239,7 +241,7 @@ fn test_mini_program_2() {
239241
return sum, product;
240242
}
241243
"#;
242-
compile_and_run(program, &[], &[], false);
244+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
243245
}
244246

245247
#[test]
@@ -266,7 +268,13 @@ fn test_mini_program_3() {
266268
}
267269
"#;
268270
let mut public_input: [F; 16] = (0..16).map(F::new).collect::<Vec<F>>().try_into().unwrap();
269-
compile_and_run(program, &public_input, &[], false);
271+
compile_and_run(
272+
program,
273+
&public_input,
274+
&[],
275+
DEFAULT_NO_VEC_RUNTIME_MEMORY,
276+
false,
277+
);
270278

271279
get_poseidon16().permute_mut(&mut public_input);
272280
let _ = public_input;
@@ -289,7 +297,13 @@ fn test_mini_program_4() {
289297
}
290298
"#;
291299
let mut public_input: [F; 24] = (0..24).map(F::new).collect::<Vec<F>>().try_into().unwrap();
292-
compile_and_run(program, &public_input, &[], false);
300+
compile_and_run(
301+
program,
302+
&public_input,
303+
&[],
304+
DEFAULT_NO_VEC_RUNTIME_MEMORY,
305+
false,
306+
);
293307

294308
get_poseidon24().permute_mut(&mut public_input);
295309
dbg!(&public_input[16..]);
@@ -369,7 +383,7 @@ fn test_inlined() {
369383
return;
370384
}
371385
"#;
372-
compile_and_run(program, &[], &[], false);
386+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
373387
}
374388

375389
#[test]
@@ -421,7 +435,7 @@ fn test_match() {
421435
return x * x * x * x * x * x;
422436
}
423437
"#;
424-
compile_and_run(program, &[], &[], false);
438+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
425439
}
426440

427441
// #[test]
@@ -462,7 +476,7 @@ fn test_const_functions_calling_const_functions() {
462476
}
463477
"#;
464478

465-
compile_and_run(program, &[], &[], false);
479+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
466480
}
467481

468482
#[test]
@@ -485,7 +499,7 @@ fn test_inline_functions_calling_inline_functions() {
485499
}
486500
"#;
487501

488-
compile_and_run(program, &[], &[], false);
502+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
489503
}
490504

491505
#[test]
@@ -512,5 +526,5 @@ fn test_nested_inline_functions() {
512526
}
513527
"#;
514528

515-
compile_and_run(program, &[], &[], false);
529+
compile_and_run(program, &[], &[], DEFAULT_NO_VEC_RUNTIME_MEMORY, false);
516530
}

crates/lean_prover/src/prove_execution.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub fn prove_execution(
2929
bytecode: &Bytecode,
3030
source_code: &str, // debug purpose
3131
function_locations: &BTreeMap<usize, String>, // debug purpose
32-
public_input: &[F],
33-
private_input: &[F],
32+
(public_input, private_input): (&[F], &[F]),
3433
whir_config_builder: WhirConfigBuilder,
34+
no_vec_runtime_memory: usize, // size of the "non-vectorized" runtime memory
3535
vm_profiler: bool,
3636
) -> (Vec<PF<EF>>, usize) {
3737
let ExecutionTrace {
@@ -52,6 +52,7 @@ pub fn prove_execution(
5252
private_input,
5353
source_code,
5454
function_locations,
55+
no_vec_runtime_memory,
5556
vm_profiler,
5657
);
5758
get_execution_trace(bytecode, execution_result)

crates/lean_prover/tests/test_zkvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ fn test_zk_vm() {
8383
&bytecode,
8484
&program_str,
8585
&function_locations,
86-
&public_input,
87-
&private_input,
86+
(&public_input, &private_input),
8887
whir_config_builder(),
88+
1 << 20,
8989
false,
9090
)
9191
.0;

0 commit comments

Comments
 (0)