Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/lean_vm/src/diagnostics/stack_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) fn pretty_stack_trace(
source_code: &str,
instructions: &[SourceLineNumber], // SourceLineNumber = usize
function_locations: &BTreeMap<usize, String>,
last_pc: usize,
) -> String {
let source_lines: Vec<&str> = source_code.lines().collect();
let mut result = String::new();
Expand Down Expand Up @@ -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));
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions crates/lean_vm/src/execution/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ 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!(
"\n{}",
crate::diagnostics::pretty_stack_trace(
&bytecode.program,
latest_instructions,
&bytecode.function_locations
&bytecode.function_locations,
last_pc
)
);
if !std_out.is_empty() {
Expand Down Expand Up @@ -146,15 +147,15 @@ fn execute_bytecode_helper(
no_vec_runtime_memory: usize,
profiling: bool,
(poseidons_16_precomputed, poseidons_24_precomputed): (&Poseidon16History, &Poseidon24History),
) -> Result<ExecutionResult, RunnerError> {
) -> Result<ExecutionResult, (CodeAddress, RunnerError)> {
// set public memory
let mut memory = Memory::new(build_public_memory(public_input));

let public_memory_size = (NONRESERVED_PROGRAM_INPUT_START + public_input.len()).next_power_of_two();
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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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];
Expand All @@ -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!(
Expand Down