diff --git a/crates/lean_vm/src/diagnostics/stack_trace.rs b/crates/lean_vm/src/diagnostics/stack_trace.rs index e9100de7..c3b4487e 100644 --- a/crates/lean_vm/src/diagnostics/stack_trace.rs +++ b/crates/lean_vm/src/diagnostics/stack_trace.rs @@ -10,6 +10,7 @@ pub(crate) fn pretty_stack_trace( source_code: &str, instructions: &[SourceLineNumber], // SourceLineNumber = usize function_locations: &BTreeMap, + last_pc: usize, ) -> String { let source_lines: Vec<&str> = source_code.lines().collect(); let mut result = String::new(); @@ -97,7 +98,11 @@ pub(crate) fn pretty_stack_trace( if !call_stack.is_empty() { result.push_str("\nCall stack:\n"); for (i, (line, func)) in call_stack.iter().enumerate() { - result.push_str(&format!(" {}. {} (line {})\n", i + 1, func, line)); + if i + 1 == call_stack.len() { + result.push_str(&format!(" {}. {} (line {}, pc {})\n", i + 1, func, line, last_pc)); + } else { + result.push_str(&format!(" {}. {} (line {})\n", i + 1, func, line)); + } } } diff --git a/crates/lean_vm/src/execution/runner.rs b/crates/lean_vm/src/execution/runner.rs index 2abb0bbe..78f72ced 100644 --- a/crates/lean_vm/src/execution/runner.rs +++ b/crates/lean_vm/src/execution/runner.rs @@ -70,7 +70,7 @@ pub fn execute_bytecode( profiling, (poseidons_16_precomputed, poseidons_24_precomputed), ) - .unwrap_or_else(|err| { + .unwrap_or_else(|(last_pc, err)| { let lines_history = &instruction_history.lines; let latest_instructions = &lines_history[lines_history.len().saturating_sub(STACK_TRACE_INSTRUCTIONS)..]; println!( @@ -78,7 +78,8 @@ pub fn execute_bytecode( crate::diagnostics::pretty_stack_trace( &bytecode.program, latest_instructions, - &bytecode.function_locations + &bytecode.function_locations, + last_pc ) ); if !std_out.is_empty() { @@ -146,7 +147,7 @@ fn execute_bytecode_helper( no_vec_runtime_memory: usize, profiling: bool, (poseidons_16_precomputed, poseidons_24_precomputed): (&Poseidon16History, &Poseidon24History), -) -> Result { +) -> Result { // set public memory let mut memory = Memory::new(build_public_memory(public_input)); @@ -154,7 +155,7 @@ fn execute_bytecode_helper( let mut fp = public_memory_size; for (i, value) in private_input.iter().enumerate() { - memory.set(fp + i, *value)?; + memory.set(fp + i, *value).expect("to set private input in memory"); } let mut mem_profile = MemoryProfile { @@ -199,7 +200,7 @@ fn execute_bytecode_helper( while pc != ENDING_PC { if pc >= bytecode.instructions.len() { - return Err(RunnerError::PCOutOfBounds); + return Err((pc, RunnerError::PCOutOfBounds)); } pcs.push(pc); @@ -225,7 +226,7 @@ fn execute_bytecode_helper( profiling, memory_profile: &mut mem_profile, }; - hint.execute_hint(&mut hint_ctx)?; + hint.execute_hint(&mut hint_ctx).map_err(|e| (pc, e))?; } let instruction = &bytecode.instructions[pc]; @@ -244,7 +245,9 @@ fn execute_bytecode_helper( n_poseidon16_precomputed_used: &mut n_poseidon16_precomputed_used, n_poseidon24_precomputed_used: &mut n_poseidon24_precomputed_used, }; - instruction.execute_instruction(&mut instruction_ctx)?; + instruction + .execute_instruction(&mut instruction_ctx) + .map_err(|e| (pc, e))?; } assert_eq!(