Skip to content

Commit 4becd65

Browse files
committed
Merge branch 'main' into feature/range_check
2 parents a2b25a2 + be06151 commit 4becd65

File tree

11 files changed

+189
-61
lines changed

11 files changed

+189
-61
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ RUSTFLAGS='-C target-cpu=native' cargo run --release -- xmss --n-signatures 990
5656

5757
![Alt text](docs/benchmark_graphs/graphs/xmss_aggregated_overhead.svg)
5858

59+
### Fibonacci:
60+
61+
n = 2,000,000
62+
63+
```
64+
RUSTFLAGS='-C target-cpu=native' cargo test --release --package lean_prover --test test_zkvm -- --nocapture -- test_prove_fibonacci --exact --nocapture
65+
```
66+
67+
Proving time:
68+
69+
- i9-12900H: 2.0 s (1.0 MHz)
70+
- mac m4 max: 1.2 s (1.7 MHz)
71+
5972
### Proof size
6073

6174
With conjecture "up to capacity", current proofs with rate = 1/2 are about ≈ 400 - 500 KiB, of which ≈ 300 KiB comes from WHIR.

TODO.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@
2727
- Opti WHIR https://github.com/tcoratger/whir-p3/issues/303 and https://github.com/tcoratger/whir-p3/issues/306
2828
- Avoid committing to the 3 index columns, and replace it by a sumcheck? Using this idea, we would only commit to PC and FP for the execution table. Idea by Georg (Powdr). Do we even need to commit to FP then?
2929

30+
- About the ordering of the variables in sumchecks, currently we do as follows:
31+
32+
[a, b, c, d, e, f, g, h] (1st round of sumcheck)
33+
[(a-r).a + r.e, (1-r).b + r.f, (1-r).c + r.g, (1-r).d + r.h] (2nd round of sumcheck)
34+
... etc
35+
36+
This is otpimal for packing (SIMD) but not optimal when to comes to padding.
37+
When there are a lot of "ending" zeros, the optimal way of folding is:
38+
39+
[a, b, c, d, e, 0, 0, 0] (1st round of sumcheck)
40+
[(a-r).a + r.b, (1-r).c + r.d, (1-r).e, 0] (2nd round of sumcheck)
41+
... etc
42+
43+
But we can get the bost of both worlds (suggested by Lev, TODO implement):
44+
45+
[a, b, c, d, e, f, g, h, i, 0, 0, 0, 0, 0, 0, 0] (1st round of sumcheck)
46+
[(1-r).a + r.c, (1-r).b + r.d, (1-r).e + r.g, (1-r).f + r.h, (1-r).i, 0, 0, 0] (2nd round of sumcheck)
47+
... etc
48+
3049
About "the packed pcs" (similar to SP1 Jagged PCS, slightly less efficient, but simpler (no sumchecks)):
3150
- The best strategy is probably to pack as much as possible (the cost increasing the density = additional inner evaluations), if we can fit below a power of 2 - epsilon (epsilon = 20% for instance, tbd), if the sum of the non zero data is just above a power of 2, no packed technique, even the best, can help us, so we should spread aniway (to reduce the pressure of inner evaluations)
3251
- About those inner evaluations, there is a trick: we need to compute M1(a, b, c, d, ...) then M2(b, c, d, ...), then M3(c, d, ...) -> The trick = compute the "eq(.) for (b, c, d), then dot product with M3. Then expand to eq(b, c, d, ...), dot product with M2. Then expand to eq(a, b, c, d, ...), dot product with M1. The idea is that in this order, computing each "eq" is easier is we start from the previous one.
@@ -68,6 +87,10 @@ But we reduce proof size a lot using instead (TODO):
6887
└────────────────────────┘└──────────┘└─┘
6988
```
7089

90+
## Security:
91+
92+
Fiat Shamir: add a claim tracing feature, to ensure all the claims are indeed checked (Lev)
93+
7194
## Not Perf
7295

7396
- Whir batching: handle the case where the second polynomial is too small compared to the first one

crates/lean_compiler/src/a_simplify_lang.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub enum SimpleLine {
9696
condition: SimpleExpr,
9797
then_branch: Vec<Self>,
9898
else_branch: Vec<Self>,
99+
line_number: SourceLineNumber,
99100
},
100101
TestZero {
101102
// Test that the result of the given operation is zero
@@ -107,6 +108,7 @@ pub enum SimpleLine {
107108
function_name: String,
108109
args: Vec<SimpleExpr>,
109110
return_data: Vec<Var>,
111+
line_number: SourceLineNumber,
110112
},
111113
FunctionRet {
112114
return_data: Vec<SimpleExpr>,
@@ -320,7 +322,7 @@ fn simplify_lines(
320322
const_malloc,
321323
);
322324
}
323-
Line::Assert(boolean) => match boolean {
325+
Line::Assert(boolean, line_number) => match boolean {
324326
Boolean::Different { left, right } => {
325327
let left = simplify_expr(left, &mut res, counters, array_manager, const_malloc);
326328
let right =
@@ -337,6 +339,7 @@ fn simplify_lines(
337339
condition: diff_var.into(),
338340
then_branch: vec![],
339341
else_branch: vec![SimpleLine::Panic],
342+
line_number: *line_number,
340343
});
341344
}
342345
Boolean::Equal { left, right } => {
@@ -362,6 +365,7 @@ fn simplify_lines(
362365
condition,
363366
then_branch,
364367
else_branch,
368+
line_number,
365369
} => {
366370
let (condition_simplified, then_branch, else_branch) = match condition {
367371
Condition::Comparison(condition) => {
@@ -472,6 +476,7 @@ fn simplify_lines(
472476
condition: condition_simplified,
473477
then_branch: then_branch_simplified,
474478
else_branch: else_branch_simplified,
479+
line_number: *line_number,
475480
});
476481
}
477482
Line::ForLoop {
@@ -481,6 +486,7 @@ fn simplify_lines(
481486
body,
482487
rev,
483488
unroll,
489+
line_number,
484490
} => {
485491
if *unroll {
486492
let (internal_variables, _) = find_variable_usage(body);
@@ -538,7 +544,7 @@ fn simplify_lines(
538544
const_malloc.counter = loop_const_malloc.counter;
539545
array_manager.valid = valid_aux_vars_in_array_manager_before; // restore the valid aux vars
540546

541-
let func_name = format!("@loop_{}", counters.loops);
547+
let func_name = format!("@loop_{}_line_{}", counters.loops, line_number);
542548
counters.loops += 1;
543549

544550
// Find variables used inside loop but defined outside
@@ -578,6 +584,7 @@ fn simplify_lines(
578584
// Create recursive function body
579585
let recursive_func = create_recursive_function(
580586
func_name.clone(),
587+
*line_number,
581588
func_args,
582589
iterator.clone(),
583590
end_simplified,
@@ -594,12 +601,14 @@ fn simplify_lines(
594601
function_name: func_name,
595602
args: call_args,
596603
return_data: vec![],
604+
line_number: *line_number,
597605
});
598606
}
599607
Line::FunctionCall {
600608
function_name,
601609
args,
602610
return_data,
611+
line_number,
603612
} => {
604613
let simplified_args = args
605614
.iter()
@@ -609,6 +618,7 @@ fn simplify_lines(
609618
function_name: function_name.clone(),
610619
args: simplified_args,
611620
return_data: return_data.clone(),
621+
line_number: *line_number,
612622
});
613623
}
614624
Line::FunctionRet { return_data } => {
@@ -884,6 +894,7 @@ pub fn find_variable_usage(lines: &[Line]) -> (BTreeSet<Var>, BTreeSet<Var>) {
884894
condition,
885895
then_branch,
886896
else_branch,
897+
line_number: _,
887898
} => {
888899
on_new_condition(condition, &internal_vars, &mut external_vars);
889900

@@ -906,7 +917,7 @@ pub fn find_variable_usage(lines: &[Line]) -> (BTreeSet<Var>, BTreeSet<Var>) {
906917
}
907918
internal_vars.extend(return_data.iter().cloned());
908919
}
909-
Line::Assert(condition) => {
920+
Line::Assert(condition, _line_number) => {
910921
on_new_condition(
911922
&Condition::Comparison(condition.clone()),
912923
&internal_vars,
@@ -953,6 +964,7 @@ pub fn find_variable_usage(lines: &[Line]) -> (BTreeSet<Var>, BTreeSet<Var>) {
953964
body,
954965
rev: _,
955966
unroll: _,
967+
line_number: _,
956968
} => {
957969
let (body_internal, body_external) = find_variable_usage(body);
958970
internal_vars.extend(body_internal);
@@ -1052,6 +1064,7 @@ pub fn inline_lines(
10521064
condition,
10531065
then_branch,
10541066
else_branch,
1067+
line_number: _,
10551068
} => {
10561069
inline_condition(condition);
10571070

@@ -1070,7 +1083,7 @@ pub fn inline_lines(
10701083
inline_internal_var(return_var);
10711084
}
10721085
}
1073-
Line::Assert(condition) => {
1086+
Line::Assert(condition, _line_number) => {
10741087
inline_comparison(condition);
10751088
}
10761089
Line::FunctionRet { return_data } => {
@@ -1124,6 +1137,7 @@ pub fn inline_lines(
11241137
body,
11251138
rev: _,
11261139
unroll: _,
1140+
line_number: _,
11271141
} => {
11281142
inline_lines(body, args, res, inlining_count);
11291143
inline_internal_var(iterator);
@@ -1246,6 +1260,7 @@ fn handle_array_assignment(
12461260

12471261
fn create_recursive_function(
12481262
name: String,
1263+
line_number: SourceLineNumber,
12491264
args: Vec<Var>,
12501265
iterator: Var,
12511266
end: SimpleExpr,
@@ -1269,6 +1284,7 @@ fn create_recursive_function(
12691284
function_name: name.clone(),
12701285
args: recursive_args,
12711286
return_data: vec![],
1287+
line_number,
12721288
});
12731289
body.push(SimpleLine::FunctionRet {
12741290
return_data: vec![],
@@ -1289,6 +1305,7 @@ fn create_recursive_function(
12891305
else_branch: vec![SimpleLine::FunctionRet {
12901306
return_data: vec![],
12911307
}],
1308+
line_number,
12921309
},
12931310
];
12941311

@@ -1428,7 +1445,10 @@ fn replace_vars_for_unroll(
14281445
internal_vars,
14291446
);
14301447
}
1431-
Line::Assert(Boolean::Equal { left, right } | Boolean::Different { left, right }) => {
1448+
Line::Assert(
1449+
Boolean::Equal { left, right } | Boolean::Different { left, right },
1450+
_line_number,
1451+
) => {
14321452
replace_vars_for_unroll_in_expr(
14331453
left,
14341454
iterator,
@@ -1448,6 +1468,7 @@ fn replace_vars_for_unroll(
14481468
condition,
14491469
then_branch,
14501470
else_branch,
1471+
line_number: _,
14511472
} => {
14521473
match condition {
14531474
Condition::Comparison(
@@ -1501,6 +1522,7 @@ fn replace_vars_for_unroll(
15011522
body,
15021523
rev: _,
15031524
unroll: _,
1525+
line_number: _,
15041526
} => {
15051527
assert!(other_iterator != iterator);
15061528
*other_iterator =
@@ -1531,6 +1553,7 @@ fn replace_vars_for_unroll(
15311553
function_name: _,
15321554
args,
15331555
return_data,
1556+
line_number: _,
15341557
} => {
15351558
// Function calls are not unrolled, so we don't need to change them
15361559
for arg in args {
@@ -1721,6 +1744,7 @@ fn handle_inlined_functions_helper(
17211744
function_name,
17221745
args,
17231746
return_data,
1747+
line_number: _,
17241748
} => {
17251749
if let Some(func) = inlined_functions.get(&*function_name) {
17261750
let mut inlined_lines = vec![];
@@ -1872,6 +1896,7 @@ fn handle_const_arguments_helper(
18721896
function_name,
18731897
args,
18741898
return_data: _,
1899+
line_number: _,
18751900
} => {
18761901
if let Some(func) = constant_functions.get(function_name) {
18771902
// If the function has constant arguments, we need to handle them
@@ -2064,6 +2089,7 @@ fn replace_vars_by_const_in_lines(lines: &mut [Line], map: &BTreeMap<Var, F>) {
20642089
condition,
20652090
then_branch,
20662091
else_branch,
2092+
line_number: _,
20672093
} => {
20682094
match condition {
20692095
Condition::Comparison(Boolean::Equal { left, right })
@@ -2085,7 +2111,7 @@ fn replace_vars_by_const_in_lines(lines: &mut [Line], map: &BTreeMap<Var, F>) {
20852111
replace_vars_by_const_in_expr(end, map);
20862112
replace_vars_by_const_in_lines(body, map);
20872113
}
2088-
Line::Assert(condition) => match condition {
2114+
Line::Assert(condition, _line_number) => match condition {
20892115
Boolean::Equal { left, right } | Boolean::Different { left, right } => {
20902116
replace_vars_by_const_in_expr(left, map);
20912117
replace_vars_by_const_in_expr(right, map);
@@ -2225,6 +2251,7 @@ impl SimpleLine {
22252251
condition,
22262252
then_branch,
22272253
else_branch,
2254+
line_number: _,
22282255
} => {
22292256
let then_str = then_branch
22302257
.iter()
@@ -2250,6 +2277,7 @@ impl SimpleLine {
22502277
function_name,
22512278
args,
22522279
return_data,
2280+
line_number: _,
22532281
} => {
22542282
let args_str = args
22552283
.iter()

crates/lean_compiler/src/b_compile_intermediate.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,17 @@ fn compile_lines(
288288
condition,
289289
then_branch,
290290
else_branch,
291+
line_number,
291292
} => {
292293
validate_vars_declared(&[condition], declared_vars)?;
293294

294295
let if_id = compiler.if_counter;
295296
compiler.if_counter += 1;
296297

297298
let (if_label, else_label, end_label) = (
298-
Label::if_label(if_id),
299-
Label::else_label(if_id),
300-
Label::if_else_end(if_id),
299+
Label::if_label(if_id, *line_number),
300+
Label::else_label(if_id, *line_number),
301+
Label::if_else_end(if_id, *line_number),
301302
);
302303

303304
// c: condition
@@ -426,10 +427,11 @@ fn compile_lines(
426427
function_name: callee_function_name,
427428
args,
428429
return_data,
430+
line_number,
429431
} => {
430432
let call_id = compiler.call_counter;
431433
compiler.call_counter += 1;
432-
let return_label = Label::return_from_call(call_id);
434+
let return_label = Label::return_from_call(call_id, *line_number);
433435

434436
let new_fp_pos = compiler.stack_size;
435437
compiler.stack_size += 1;

0 commit comments

Comments
 (0)