Skip to content

Commit 29fc7dc

Browse files
committed
add relocate trace flag to the runner
1 parent 9277002 commit 29fc7dc

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

cairo-vm-cli/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ fn run(args: impl Iterator<Item = String>) -> Result<(), Error> {
189189
entrypoint: &args.entrypoint,
190190
trace_enabled,
191191
relocate_mem: args.memory_file.is_some() || args.air_public_input.is_some(),
192+
// If trace not enabled, it is not relevant. Otherwise, we need to relocate the trace only if
193+
// we need air public input or trace file.
194+
relocate_trace: trace_enabled
195+
&& (args.trace_file.is_some() || args.air_public_input.is_some()),
192196
layout: args.layout,
193197
proof_mode: args.proof_mode,
194198
secure_run: args.secure_run,

cairo1-run/cairo

Lines changed: 0 additions & 1 deletion
This file was deleted.

cairo1-run/src/cairo_run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn cairo_run_program(
341341
}
342342
}
343343

344-
runner.relocate(true)?;
344+
runner.relocate(true, true)?;
345345

346346
Ok((runner, return_values, serialized_output))
347347
}

vm/src/cairo_run.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct CairoRunConfig<'a> {
2828
pub entrypoint: &'a str,
2929
pub trace_enabled: bool,
3030
pub relocate_mem: bool,
31+
pub relocate_trace: bool,
3132
pub layout: LayoutName,
3233
/// The `dynamic_layout_params` argument should only be used with dynamic layout.
3334
/// It is ignored otherwise.
@@ -51,6 +52,7 @@ impl Default for CairoRunConfig<'_> {
5152
entrypoint: "main",
5253
trace_enabled: false,
5354
relocate_mem: false,
55+
relocate_trace: true,
5456
layout: LayoutName::plain,
5557
proof_mode: false,
5658
secure_run: None,
@@ -113,7 +115,10 @@ pub fn cairo_run_program_with_initial_scope(
113115
if secure_run {
114116
verify_secure_runner(&cairo_runner, true, None)?;
115117
}
116-
cairo_runner.relocate(cairo_run_config.relocate_mem)?;
118+
cairo_runner.relocate(
119+
cairo_run_config.relocate_mem,
120+
cairo_run_config.relocate_trace,
121+
)?;
117122

118123
Ok(cairo_runner)
119124
}
@@ -218,7 +223,10 @@ pub fn cairo_run_pie(
218223
// Check that the Cairo PIE produced by this run is compatible with the Cairo PIE received
219224
cairo_runner.get_cairo_pie()?.check_pie_compatibility(pie)?;
220225
}
221-
cairo_runner.relocate(cairo_run_config.relocate_mem)?;
226+
cairo_runner.relocate(
227+
cairo_run_config.relocate_mem,
228+
cairo_run_config.relocate_trace,
229+
)?;
222230

223231
Ok(cairo_runner)
224232
}
@@ -267,7 +275,10 @@ pub fn cairo_run_fuzzed_program(
267275
if secure_run {
268276
verify_secure_runner(&cairo_runner, true, None)?;
269277
}
270-
cairo_runner.relocate(cairo_run_config.relocate_mem)?;
278+
cairo_runner.relocate(
279+
cairo_run_config.relocate_mem,
280+
cairo_run_config.relocate_trace,
281+
)?;
271282

272283
Ok(cairo_runner)
273284
}
@@ -367,7 +378,7 @@ mod tests {
367378

368379
let end = cairo_runner.initialize(false).unwrap();
369380
assert!(cairo_runner.run_until_pc(end, &mut hint_processor).is_ok());
370-
assert!(cairo_runner.relocate(true).is_ok());
381+
assert!(cairo_runner.relocate(true, true).is_ok());
371382
// `main` returns without doing nothing, but `not_main` sets `[ap]` to `1`
372383
// Memory location was found empirically and simply hardcoded
373384
assert_eq!(cairo_runner.relocated_memory[2], Some(Felt252::from(123)));
@@ -433,7 +444,7 @@ mod tests {
433444
let mut hint_processor = BuiltinHintProcessor::new_empty();
434445
let mut cairo_runner = run_test_program(program_content, &mut hint_processor).unwrap();
435446

436-
assert!(cairo_runner.relocate(false).is_ok());
447+
assert!(cairo_runner.relocate(false, true).is_ok());
437448

438449
let trace_entries = cairo_runner.relocated_trace.unwrap();
439450
let mut buffer = [0; 24];
@@ -457,7 +468,7 @@ mod tests {
457468
let mut cairo_runner = run_test_program(program_content, &mut hint_processor).unwrap();
458469

459470
// relocate memory so we can dump it to file
460-
assert!(cairo_runner.relocate(true).is_ok());
471+
assert!(cairo_runner.relocate(true, true).is_ok());
461472

462473
let mut buffer = [0; 120];
463474
let mut buff_writer = SliceWriter::new(&mut buffer);
@@ -481,7 +492,7 @@ mod tests {
481492
let mut cairo_runner = cairo_runner!(program);
482493
let end = cairo_runner.initialize(false).unwrap();
483494
assert!(cairo_runner.run_until_pc(end, &mut hint_processor).is_ok());
484-
assert!(cairo_runner.relocate(false).is_ok());
495+
assert!(cairo_runner.relocate(false, true).is_ok());
485496
assert!(cairo_runner.relocated_trace.is_none());
486497
}
487498

vm/src/vm/runners/cairo_runner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,9 @@ impl CairoRunner {
984984
Ok(())
985985
}
986986

987-
pub fn relocate(&mut self, relocate_mem: bool) -> Result<(), TraceError> {
987+
pub fn relocate(&mut self, relocate_mem: bool, relocate_trace: bool) -> Result<(), TraceError> {
988988
self.vm.segments.compute_effective_sizes();
989-
if !relocate_mem && self.vm.trace.is_none() {
989+
if !relocate_mem && (self.vm.trace.is_none() || !relocate_trace) {
990990
return Ok(());
991991
}
992992
// relocate_segments can fail if compute_effective_sizes is not called before.
@@ -1002,7 +1002,7 @@ impl CairoRunner {
10021002
return Err(TraceError::MemoryError(memory_error));
10031003
}
10041004
}
1005-
if self.vm.trace.is_some() {
1005+
if self.vm.trace.is_some() && relocate_trace {
10061006
self.relocate_trace(&relocation_table)?;
10071007
}
10081008
self.vm.relocation_table = Some(relocation_table);

0 commit comments

Comments
 (0)