Skip to content

Commit 4c4ec02

Browse files
committed
add relocate trace flag to the runner
1 parent 4226352 commit 4c4ec02

File tree

9 files changed

+31
-12
lines changed

9 files changed

+31
-12
lines changed

cairo-vm-cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ 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+
relocate_trace: trace_enabled,
192193
layout: args.layout,
193194
proof_mode: args.proof_mode,
194195
secure_run: args.secure_run,

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
}

examples/wasm-demo/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn run_cairo_program() -> Result<String, JsError> {
3636
layout: LayoutName::all_cairo,
3737
relocate_mem: true,
3838
trace_enabled: true,
39+
relocate_trace: true,
3940
..Default::default()
4041
};
4142

vm/src/air_public_input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ mod tests {
197197
relocate_mem: true,
198198
trace_enabled: true,
199199
layout: LayoutName::all_cairo,
200+
relocate_trace: true,
200201
..Default::default()
201202
};
202203
let runner = crate::cairo_run::cairo_run(program_content, &config, &mut crate::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor::new_empty()).unwrap();

vm/src/cairo_run.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ pub struct CairoRunConfig<'a> {
2727
#[cfg_attr(feature = "test_utils", arbitrary(value = "main"))]
2828
pub entrypoint: &'a str,
2929
pub trace_enabled: bool,
30+
/// Relocate memory if `true`, otherwise memory is not relocated.
3031
pub relocate_mem: bool,
32+
// When `relocate_trace` is set to `false`, the trace will not be relocated even if `trace_enabled` is `true`.
33+
pub relocate_trace: bool,
3134
pub layout: LayoutName,
3235
/// The `dynamic_layout_params` argument should only be used with dynamic layout.
3336
/// It is ignored otherwise.
@@ -51,6 +54,7 @@ impl Default for CairoRunConfig<'_> {
5154
entrypoint: "main",
5255
trace_enabled: false,
5356
relocate_mem: false,
57+
relocate_trace: false,
5458
layout: LayoutName::plain,
5559
proof_mode: false,
5660
secure_run: None,
@@ -113,7 +117,10 @@ pub fn cairo_run_program_with_initial_scope(
113117
if secure_run {
114118
verify_secure_runner(&cairo_runner, true, None)?;
115119
}
116-
cairo_runner.relocate(cairo_run_config.relocate_mem)?;
120+
cairo_runner.relocate(
121+
cairo_run_config.relocate_mem,
122+
cairo_run_config.relocate_trace,
123+
)?;
117124

118125
Ok(cairo_runner)
119126
}
@@ -218,7 +225,10 @@ pub fn cairo_run_pie(
218225
// Check that the Cairo PIE produced by this run is compatible with the Cairo PIE received
219226
cairo_runner.get_cairo_pie()?.check_pie_compatibility(pie)?;
220227
}
221-
cairo_runner.relocate(cairo_run_config.relocate_mem)?;
228+
cairo_runner.relocate(
229+
cairo_run_config.relocate_mem,
230+
cairo_run_config.relocate_trace,
231+
)?;
222232

223233
Ok(cairo_runner)
224234
}
@@ -267,7 +277,10 @@ pub fn cairo_run_fuzzed_program(
267277
if secure_run {
268278
verify_secure_runner(&cairo_runner, true, None)?;
269279
}
270-
cairo_runner.relocate(cairo_run_config.relocate_mem)?;
280+
cairo_runner.relocate(
281+
cairo_run_config.relocate_mem,
282+
cairo_run_config.relocate_trace,
283+
)?;
271284

272285
Ok(cairo_runner)
273286
}
@@ -367,7 +380,7 @@ mod tests {
367380

368381
let end = cairo_runner.initialize(false).unwrap();
369382
assert!(cairo_runner.run_until_pc(end, &mut hint_processor).is_ok());
370-
assert!(cairo_runner.relocate(true).is_ok());
383+
assert!(cairo_runner.relocate(true, true).is_ok());
371384
// `main` returns without doing nothing, but `not_main` sets `[ap]` to `1`
372385
// Memory location was found empirically and simply hardcoded
373386
assert_eq!(cairo_runner.relocated_memory[2], Some(Felt252::from(123)));
@@ -433,7 +446,7 @@ mod tests {
433446
let mut hint_processor = BuiltinHintProcessor::new_empty();
434447
let mut cairo_runner = run_test_program(program_content, &mut hint_processor).unwrap();
435448

436-
assert!(cairo_runner.relocate(false).is_ok());
449+
assert!(cairo_runner.relocate(false, true).is_ok());
437450

438451
let trace_entries = cairo_runner.relocated_trace.unwrap();
439452
let mut buffer = [0; 24];
@@ -457,7 +470,7 @@ mod tests {
457470
let mut cairo_runner = run_test_program(program_content, &mut hint_processor).unwrap();
458471

459472
// relocate memory so we can dump it to file
460-
assert!(cairo_runner.relocate(true).is_ok());
473+
assert!(cairo_runner.relocate(true, true).is_ok());
461474

462475
let mut buffer = [0; 120];
463476
let mut buff_writer = SliceWriter::new(&mut buffer);
@@ -481,7 +494,7 @@ mod tests {
481494
let mut cairo_runner = cairo_runner!(program);
482495
let end = cairo_runner.initialize(false).unwrap();
483496
assert!(cairo_runner.run_until_pc(end, &mut hint_processor).is_ok());
484-
assert!(cairo_runner.relocate(false).is_ok());
497+
assert!(cairo_runner.relocate(false, false).is_ok());
485498
assert!(cairo_runner.relocated_trace.is_none());
486499
}
487500

vm/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ fn run_program(
7575
relocate_mem: true,
7676
trace_enabled: true,
7777
proof_mode,
78+
relocate_trace: true,
7879
..Default::default()
7980
};
8081
let res = cairo_run(data, &cairo_run_config, &mut hint_executor);

vm/src/tests/run_deprecated_contract_class_simplified.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ fn run_deprecated_cc() {
330330
program_content,
331331
&CairoRunConfig {
332332
trace_enabled: true,
333-
..Default::default()
333+
relocate_trace: true..Default::default(),
334334
},
335335
&mut hint_processor,
336336
)

vm/src/tests/segment_arena_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ fn test_segment_arena() {
156156
relocate_mem: true,
157157
trace_enabled: true,
158158
proof_mode: false,
159+
relocate_trace: true,
159160
..Default::default()
160161
};
161162
let runner =

vm/src/vm/runners/cairo_runner.rs

Lines changed: 4 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);
@@ -4002,6 +4002,7 @@ mod tests {
40024002
layout: LayoutName::all_cairo,
40034003
proof_mode: false,
40044004
secure_run: Some(false),
4005+
relocate_trace: true,
40054006
..Default::default()
40064007
};
40074008
let mut hint_executor = BuiltinHintProcessor::new_empty();

0 commit comments

Comments
 (0)