Skip to content

Commit 8fd2d2f

Browse files
committed
Merge branch 'main' into modular_precompiles
2 parents 3b7eee3 + 5ad5619 commit 8fd2d2f

File tree

8 files changed

+40
-14
lines changed

8 files changed

+40
-14
lines changed

crates/lean_compiler/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ pub fn compile_program(program: String) -> Bytecode {
2424
// for (loc, name) in function_locations.iter() {
2525
// println!("{name}: {loc}");
2626
// }
27+
/* let compiled = */
28+
compile_to_low_level_bytecode(intermediate_bytecode, program, function_locations).unwrap() // ;
2729
// println!("\n\nCompiled Program:\n\n{compiled}");
28-
compile_to_low_level_bytecode(intermediate_bytecode, program, function_locations).unwrap()
30+
// compiled
2931
}
3032

3133
pub fn compile_and_run(

crates/lean_prover/tests/test_zkvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ fn test_zk_vm_helper(
191191
);
192192
let proof_time = time.elapsed();
193193
verify_execution(&bytecode, public_input, proof, whir_config_builder()).unwrap();
194-
println!("{}", summary);
194+
println!("{summary}");
195195
println!("Proof time: {:.3} s", proof_time.as_secs_f32());
196196
}

crates/lean_vm/src/diagnostics/error.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ pub enum RunnerError {
99
#[error("Out of memory")]
1010
OutOfMemory,
1111

12-
#[error("Memory already set")]
13-
MemoryAlreadySet,
12+
#[error("Memory already set: m[{address}] = {prev_value} != {new_value}")]
13+
MemoryAlreadySet {
14+
address: usize,
15+
prev_value: F,
16+
new_value: F,
17+
},
1418

1519
#[error("Not a pointer")]
1620
NotAPointer,

crates/lean_vm/src/diagnostics/stack_trace.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) fn pretty_stack_trace(
1010
source_code: &str,
1111
instructions: &[SourceLineNumber], // SourceLineNumber = usize
1212
function_locations: &BTreeMap<usize, String>,
13+
last_pc: usize,
1314
) -> String {
1415
let source_lines: Vec<&str> = source_code.lines().collect();
1516
let mut result = String::new();
@@ -97,7 +98,11 @@ pub(crate) fn pretty_stack_trace(
9798
if !call_stack.is_empty() {
9899
result.push_str("\nCall stack:\n");
99100
for (i, (line, func)) in call_stack.iter().enumerate() {
100-
result.push_str(&format!(" {}. {} (line {})\n", i + 1, func, line));
101+
if i + 1 == call_stack.len() {
102+
result.push_str(&format!(" {}. {} (line {}, pc {})\n", i + 1, func, line, last_pc));
103+
} else {
104+
result.push_str(&format!(" {}. {} (line {})\n", i + 1, func, line));
105+
}
101106
}
102107
}
103108

crates/lean_vm/src/execution/memory.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ impl Memory {
4141
}
4242
if let Some(existing) = &mut self.0[index] {
4343
if *existing != value {
44-
return Err(RunnerError::MemoryAlreadySet);
44+
return Err(RunnerError::MemoryAlreadySet {
45+
address: index,
46+
prev_value: *existing,
47+
new_value: value,
48+
});
4549
}
4650
} else {
4751
self.0[index] = Some(value);

crates/lean_vm/src/execution/runner.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ pub fn execute_bytecode(
7171
(poseidons_16_precomputed, poseidons_24_precomputed),
7272
merkle_path_hints,
7373
)
74-
.unwrap_or_else(|err| {
74+
.unwrap_or_else(|(last_pc, err)| {
7575
let lines_history = &instruction_history.lines;
7676
let latest_instructions = &lines_history[lines_history.len().saturating_sub(STACK_TRACE_INSTRUCTIONS)..];
7777
println!(
7878
"\n{}",
7979
crate::diagnostics::pretty_stack_trace(
8080
&bytecode.program,
8181
latest_instructions,
82-
&bytecode.function_locations
82+
&bytecode.function_locations,
83+
last_pc
8384
)
8485
);
8586
if !std_out.is_empty() {
@@ -148,15 +149,15 @@ fn execute_bytecode_helper(
148149
profiling: bool,
149150
(poseidons_16_precomputed, poseidons_24_precomputed): (&Poseidon16History, &Poseidon24History),
150151
mut merkle_path_hints: VecDeque<Vec<[F; 8]>>,
151-
) -> Result<ExecutionResult, RunnerError> {
152+
) -> Result<ExecutionResult, (CodeAddress, RunnerError)> {
152153
// set public memory
153154
let mut memory = Memory::new(build_public_memory(public_input));
154155

155156
let public_memory_size = (NONRESERVED_PROGRAM_INPUT_START + public_input.len()).next_power_of_two();
156157
let mut fp = public_memory_size;
157158

158159
for (i, value) in private_input.iter().enumerate() {
159-
memory.set(fp + i, *value)?;
160+
memory.set(fp + i, *value).expect("to set private input in memory");
160161
}
161162

162163
let mut mem_profile = MemoryProfile {
@@ -200,7 +201,7 @@ fn execute_bytecode_helper(
200201

201202
while pc != ENDING_PC {
202203
if pc >= bytecode.instructions.len() {
203-
return Err(RunnerError::PCOutOfBounds);
204+
return Err((pc, RunnerError::PCOutOfBounds));
204205
}
205206

206207
pcs.push(pc);
@@ -227,7 +228,7 @@ fn execute_bytecode_helper(
227228
profiling,
228229
memory_profile: &mut mem_profile,
229230
};
230-
hint.execute_hint(&mut hint_ctx)?;
231+
hint.execute_hint(&mut hint_ctx).map_err(|e| (pc, e))?;
231232
}
232233

233234
let instruction = &bytecode.instructions[pc];
@@ -247,7 +248,9 @@ fn execute_bytecode_helper(
247248
n_poseidon16_precomputed_used: &mut n_poseidon16_precomputed_used,
248249
n_poseidon24_precomputed_used: &mut n_poseidon24_precomputed_used,
249250
};
250-
instruction.execute_instruction(&mut instruction_ctx)?;
251+
instruction
252+
.execute_instruction(&mut instruction_ctx)
253+
.map_err(|e| (pc, e))?;
251254
}
252255

253256
assert_eq!(

crates/lean_vm/src/execution/tests.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ fn test_memory_already_set_error() {
2525
memory.set(0, F::ONE).unwrap();
2626

2727
// Setting different value should fail
28-
assert!(matches!(memory.set(0, F::ZERO), Err(RunnerError::MemoryAlreadySet)));
28+
assert!(matches!(
29+
memory.set(0, F::ZERO),
30+
Err(RunnerError::MemoryAlreadySet {
31+
address: 0,
32+
prev_value: F::ONE,
33+
new_value: F::ZERO,
34+
})
35+
));
2936
}
3037

3138
#[test]

crates/rec_aggregation/src/xmss_aggregate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub fn xmss_verify_aggregated_signatures(
232232
proof_bytes: &[u8],
233233
slot: u64,
234234
) -> Result<(), ProofError> {
235+
let _ = slot; // TODO
235236
let program = get_xmss_aggregation_program();
236237

237238
let proof = info_span!("Proof deserialization")

0 commit comments

Comments
 (0)