@@ -5,8 +5,6 @@ use lean_prover::{
55use lean_vm:: * ;
66use p3_field:: PrimeCharacteristicRing ;
77
8- const NO_VEC_RUNTIME_MEMORY : usize = 1 << 20 ;
9-
108#[ test]
119fn test_zk_vm_all_precompiles ( ) {
1210 let program_str = r#"
@@ -61,25 +59,6 @@ fn test_zk_vm_all_precompiles() {
6159 }
6260 "# ;
6361
64- test_zk_vm_helper ( program_str) ;
65- }
66-
67- #[ test]
68- fn test_zk_vm_no_precompiles ( ) {
69- let program_str = r#"
70-
71- fn main() {
72- for i in 0..10 {
73- assert i != 10;
74- }
75- return;
76- }
77- "# ;
78-
79- test_zk_vm_helper ( program_str) ;
80- }
81-
82- fn test_zk_vm_helper ( program_str : & str ) {
8362 const SECOND_POINT : usize = 2 ;
8463 const SECOND_N_VARS : usize = 7 ;
8564
@@ -99,16 +78,63 @@ fn test_zk_vm_helper(program_str: &str) {
9978 . map ( |i| F :: from_usize ( i) . square ( ) )
10079 . collect :: < Vec < _ > > ( ) ;
10180
102- // utils::init_tracing();
81+ test_zk_vm_helper ( program_str, ( & public_input, & private_input) , 1 << 20 ) ;
82+ }
83+
84+ #[ test]
85+ fn test_prove_fibonacci ( ) {
86+ let program_str = r#"
87+ const N = 2000000;
88+ const STEPS = 10000; // N should be a multiple of STEPS
89+ const N_STEPS = N / STEPS;
90+
91+ fn main() {
92+ x, y = fibonacci_step(0, 1, N_STEPS);
93+ print(x);
94+ return;
95+ }
96+
97+ fn fibonacci_step(a, b, steps_remaining) -> 2 {
98+ if steps_remaining == 0 {
99+ return a, b;
100+ }
101+ new_a, new_b = fibonacci_const(a, b, STEPS);
102+ res_a, res_b = fibonacci_step(new_a, new_b, steps_remaining - 1);
103+ return res_a, res_b;
104+ }
105+
106+ fn fibonacci_const(a, b, const n) -> 2 {
107+ buff = malloc(n + 2);
108+ buff[0] = a;
109+ buff[1] = b;
110+ for j in 2..n + 2 unroll {
111+ buff[j] = buff[j - 1] + buff[j - 2];
112+ }
113+ return buff[n], buff[n + 1];
114+ }
115+ "# ;
116+
117+ test_zk_vm_helper ( program_str, ( & [ F :: ZERO ; 1 << 14 ] , & [ ] ) , 0 ) ;
118+ }
119+
120+ fn test_zk_vm_helper (
121+ program_str : & str ,
122+ ( public_input, private_input) : ( & [ F ] , & [ F ] ) ,
123+ no_vec_runtime_memory : usize ,
124+ ) {
125+ utils:: init_tracing ( ) ;
103126 let bytecode = compile_program ( program_str. to_string ( ) ) ;
104- let proof_data = prove_execution (
127+ let time = std:: time:: Instant :: now ( ) ;
128+ let ( proof_data, _, summary) = prove_execution (
105129 & bytecode,
106130 ( & public_input, & private_input) ,
107131 whir_config_builder ( ) ,
108- NO_VEC_RUNTIME_MEMORY ,
132+ no_vec_runtime_memory ,
109133 false ,
110134 ( & vec ! [ ] , & vec ! [ ] ) ,
111- )
112- . 0 ;
135+ ) ;
136+ let proof_time = time . elapsed ( ) ;
113137 verify_execution ( & bytecode, & public_input, proof_data, whir_config_builder ( ) ) . unwrap ( ) ;
138+ println ! ( "{}" , summary) ;
139+ println ! ( "Proof time: {:.3} s" , proof_time. as_secs_f32( ) ) ;
114140}
0 commit comments