Skip to content

Commit f8d87cb

Browse files
committed
working but needs a redo to respect changes made in the main branch
1 parent b82b090 commit f8d87cb

File tree

32 files changed

+325
-1420
lines changed

32 files changed

+325
-1420
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lean_compiler/src/d_compile_range_checks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn is_undef(mem: &Memory, pos: usize) -> bool {
5757
}
5858

5959
pub fn compile_range_checks(
60-
first_exec: &lean_runner::ExecutionResult,
60+
first_exec: &ExecutionResult,
6161
bytecode: &Bytecode,
6262
) -> Result<Bytecode, RunnerError> {
6363
// Early return if no range checks exist

crates/lean_compiler/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::BTreeMap;
22

3-
use lean_runner::{ExecutionHistory, execute_bytecode, execute_bytecode_helper};
3+
use lean_runner::{execute_bytecode, execute_bytecode_helper};
4+
use lean_vm::ExecutionHistory;
45
use lean_vm::*;
56

67
pub use crate::{
@@ -23,15 +24,14 @@ mod parser;
2324
mod precompiles;
2425
pub use precompiles::PRECOMPILES;
2526

26-
pub fn compile_program(program: &str) -> (Bytecode, BTreeMap<usize, String>) {
27+
/// Compile a program and return the bytecode. The public and private inputs are necessary as their
28+
/// contents may affect the memory layout required for the range-check compilation to work
29+
/// correctly.
30+
pub fn compile_program(program: &str, public_input: &[F], private_input: &[F]) -> (Bytecode, BTreeMap<usize, String>) {
2731
let (parsed_program, function_locations) = parse_program(program).unwrap();
28-
// println!("Parsed program: {}", parsed_program.to_string());
2932
let simple_program = simplify_program(parsed_program);
30-
// println!("Simplified program: {}", simple_program.to_string());
3133
let intermediate_bytecode = compile_to_intermediate_bytecode(simple_program).unwrap();
32-
// println!("Intermediate Bytecode:\n\n{}", intermediate_bytecode.to_string());
3334
let mut compiled = compile_to_low_level_bytecode(intermediate_bytecode).unwrap();
34-
//println!("Compiled Program:\n\n{}", compiled.to_string());
3535

3636
// Check if range checks exist - if so, compile them
3737
if compiled
@@ -44,10 +44,9 @@ pub fn compile_program(program: &str) -> (Bytecode, BTreeMap<usize, String>) {
4444
let mut instruction_history = ExecutionHistory::default();
4545
let first_exec = execute_bytecode_helper(
4646
&compiled,
47-
&[], // No public input for range check compilation
48-
&[], // No private input for range check compilation
47+
public_input,
48+
private_input,
4949
MAX_RUNNER_MEMORY_SIZE / 2,
50-
false,
5150
&mut std_out,
5251
&mut instruction_history,
5352
false,
@@ -63,13 +62,14 @@ pub fn compile_program(program: &str) -> (Bytecode, BTreeMap<usize, String>) {
6362
}
6463

6564
pub fn compile_and_run(program: &str, public_input: &[F], private_input: &[F], profiler: bool) {
66-
let (mut bytecode, function_locations) = compile_program(program);
65+
let (bytecode, function_locations) = compile_program(program, public_input, private_input);
6766
let _r = execute_bytecode(
68-
&mut bytecode,
67+
&bytecode,
6968
public_input,
7069
private_input,
7170
program,
7271
&function_locations,
72+
10000, // no_vec_runtime_memory
7373
profiler,
7474
);
7575
}

crates/lean_compiler/tests/test_range_check.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use lean_compiler::{
33
compile_to_low_level_bytecode, simplify_program,
44
};
55
use lean_compiler::{compile_program, parse_program};
6-
use lean_runner::{ExecutionHistory, execute_bytecode, execute_bytecode_helper};
6+
use lean_runner::{execute_bytecode, execute_bytecode_helper};
7+
use lean_vm::{ExecutionHistory, ExecutionResult};
78
use lean_vm::core::Label;
89
use lean_vm::*;
910
use p3_field::PrimeCharacteristicRing;
@@ -99,7 +100,7 @@ fn do_test_range_check(v: usize, t: usize, verbose: bool) {
99100
let max_runner_memory_size: usize = 1 << 24;
100101

101102
let program = range_check_program(v, t);
102-
let (bytecode, function_locations) = compile_program(&program); // Range checks are automatically compiled now
103+
let (bytecode, function_locations) = compile_program(&program, &[], &[]);
103104

104105
if verbose {
105106
println!("Range Check Test: v: {}, t: {} ==============", v, t);
@@ -115,7 +116,6 @@ fn do_test_range_check(v: usize, t: usize, verbose: bool) {
115116
&[],
116117
&[],
117118
max_runner_memory_size / 2,
118-
false,
119119
&mut std_out,
120120
&mut instruction_history,
121121
false,
@@ -144,6 +144,12 @@ fn do_test_range_check(v: usize, t: usize, verbose: bool) {
144144
}
145145
}
146146

147+
#[test]
148+
fn test_range_check_execution() {
149+
do_test_range_check(0, 1, false);
150+
}
151+
152+
147153
/// Test that the range check keyword is parsed and compiled (steps a to c only).
148154
#[test]
149155
fn test_range_check_parsing_and_compilation() {
@@ -268,7 +274,6 @@ fn do_test_invalid_range_check(v: usize, t: usize) {
268274
println!("Execution complete but the range check failed to OOM");
269275
assert!(false, "range check failed to catch OOM");
270276
}
271-
println!("result: {}", result.as_ref().unwrap_err());
272277
assert!(matches!(&result, Err(RunnerError::OutOfMemory)));
273278
}
274279

@@ -445,20 +450,21 @@ fn test_deref() {
445450
};
446451
println!("bytecode:\n{}", bytecode.to_string());
447452
let execution_result = execute_bytecode(
448-
&mut bytecode,
453+
&bytecode,
449454
&[], // public input
450455
&[], // private input
451456
"", // no source code for debug
452457
&std::collections::BTreeMap::new(), // no function locations
458+
1 << 23, // no_vec_runtime_memory
453459
false, // no profiler
454460
);
455461

456-
assert!(execution_result.is_ok());
462+
// execution_result is now ExecutionResult struct, not a Result
463+
assert!(execution_result.pcs.len() > 0); // Basic check that execution completed
457464
}
458465

459-
fn range_check(v: usize, t: usize) -> Result<lean_runner::ExecutionResult, RunnerError> {
466+
fn range_check(v: usize, t: usize) -> Result<ExecutionResult, RunnerError> {
460467
let starting_frame_memory = 5;
461-
println!("v: {}; t: {}", v, t);
462468
let val = F::from_usize(v);
463469

464470
// In the final version, these values will have to be set after a first execution pass
@@ -571,13 +577,16 @@ fn range_check(v: usize, t: usize) -> Result<lean_runner::ExecutionResult, Runne
571577
};
572578

573579
// Execute the bytecode
574-
let execution_result = execute_bytecode(
575-
&mut bytecode,
576-
&[], // public input
577-
&[], // private input
578-
"", // no source code for debug
579-
&std::collections::BTreeMap::new(), // no function locations
580-
false, // no profiler
581-
);
582-
execution_result
580+
let execution_result = execute_bytecode_helper(
581+
&bytecode,
582+
&[],
583+
&[],
584+
1 << 23,
585+
&mut String::new(),
586+
&mut ExecutionHistory::new(),
587+
false,
588+
&BTreeMap::new(),
589+
)?;
590+
591+
Ok(execution_result)
583592
}

crates/lean_prover/src/prove_execution.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ pub fn prove_execution(
4848
memory, // padded with zeros to next power of two
4949
} = info_span!("Witness generation").in_scope(|| {
5050
let execution_result = execute_bytecode(
51-
&mut bytecode.clone(),
51+
bytecode,
5252
public_input,
5353
private_input,
5454
source_code,
5555
function_locations,
56+
_no_vec_runtime_memory,
5657
vm_profiler,
57-
)
58-
.unwrap();
58+
);
5959
get_execution_trace(bytecode, execution_result)
6060
});
6161

crates/lean_prover/src/verify_execution.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::common::*;
22
use crate::*;
3+
use lean_runner::build_public_memory;
34
use ::air::table::AirTable;
45
use lean_vm::*;
56
use lookup::verify_gkr_product;

crates/lean_prover/tests/test_zkvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn test_zk_vm() {
8080
.collect::<Vec<_>>();
8181

8282
// utils::init_tracing();
83-
let (bytecode, function_locations) = compile_program(&program_str);
83+
let (bytecode, function_locations) = compile_program(&program_str, &public_input, &private_input);
8484
let proof_data = prove_execution(
8585
&bytecode,
8686
&program_str,

crates/lean_prover/witness_generation/src/execution_trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
COL_INDEX_MEM_VALUE_A, COL_INDEX_MEM_VALUE_B, COL_INDEX_MEM_VALUE_C, COL_INDEX_PC,
55
N_EXEC_COLUMNS, N_INSTRUCTION_COLUMNS,
66
};
7-
use lean_runner::ExecutionResult;
7+
use crate::execution_trace::ExecutionResult;
88
use lean_vm::*;
99
use p3_field::Field;
1010
use p3_field::PrimeCharacteristicRing;

crates/lean_runner/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
mod profiler;
1+
//! VM execution engine and memory management
2+
23
pub mod runner;
3-
pub mod stack_trace;
44

5-
pub use runner::{
6-
ExecutionHistory, ExecutionResult, build_public_memory, execute_bytecode,
7-
execute_bytecode_helper,
8-
};
5+
pub use runner::*;

crates/lean_runner/src/profiler.rs

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)