@@ -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,8 @@ impl Default for CairoRunConfig<'_> {
5154 entrypoint : "main" ,
5255 trace_enabled : false ,
5356 relocate_mem : false ,
57+ // Set to true to match expected behavior: trace is relocated only if trace_enabled is true.
58+ relocate_trace : true ,
5459 layout : LayoutName :: plain,
5560 proof_mode : false ,
5661 secure_run : None ,
@@ -113,7 +118,10 @@ pub fn cairo_run_program_with_initial_scope(
113118 if secure_run {
114119 verify_secure_runner ( & cairo_runner, true , None ) ?;
115120 }
116- cairo_runner. relocate ( cairo_run_config. relocate_mem ) ?;
121+ cairo_runner. relocate (
122+ cairo_run_config. relocate_mem ,
123+ cairo_run_config. relocate_trace ,
124+ ) ?;
117125
118126 Ok ( cairo_runner)
119127}
@@ -218,7 +226,10 @@ pub fn cairo_run_pie(
218226 // Check that the Cairo PIE produced by this run is compatible with the Cairo PIE received
219227 cairo_runner. get_cairo_pie ( ) ?. check_pie_compatibility ( pie) ?;
220228 }
221- cairo_runner. relocate ( cairo_run_config. relocate_mem ) ?;
229+ cairo_runner. relocate (
230+ cairo_run_config. relocate_mem ,
231+ cairo_run_config. relocate_trace ,
232+ ) ?;
222233
223234 Ok ( cairo_runner)
224235}
@@ -267,7 +278,10 @@ pub fn cairo_run_fuzzed_program(
267278 if secure_run {
268279 verify_secure_runner ( & cairo_runner, true , None ) ?;
269280 }
270- cairo_runner. relocate ( cairo_run_config. relocate_mem ) ?;
281+ cairo_runner. relocate (
282+ cairo_run_config. relocate_mem ,
283+ cairo_run_config. relocate_trace ,
284+ ) ?;
271285
272286 Ok ( cairo_runner)
273287}
@@ -367,7 +381,7 @@ mod tests {
367381
368382 let end = cairo_runner. initialize ( false ) . unwrap ( ) ;
369383 assert ! ( cairo_runner. run_until_pc( end, & mut hint_processor) . is_ok( ) ) ;
370- assert ! ( cairo_runner. relocate( true ) . is_ok( ) ) ;
384+ assert ! ( cairo_runner. relocate( true , true ) . is_ok( ) ) ;
371385 // `main` returns without doing nothing, but `not_main` sets `[ap]` to `1`
372386 // Memory location was found empirically and simply hardcoded
373387 assert_eq ! ( cairo_runner. relocated_memory[ 2 ] , Some ( Felt252 :: from( 123 ) ) ) ;
@@ -433,7 +447,7 @@ mod tests {
433447 let mut hint_processor = BuiltinHintProcessor :: new_empty ( ) ;
434448 let mut cairo_runner = run_test_program ( program_content, & mut hint_processor) . unwrap ( ) ;
435449
436- assert ! ( cairo_runner. relocate( false ) . is_ok( ) ) ;
450+ assert ! ( cairo_runner. relocate( false , true ) . is_ok( ) ) ;
437451
438452 let trace_entries = cairo_runner. relocated_trace . unwrap ( ) ;
439453 let mut buffer = [ 0 ; 24 ] ;
@@ -457,7 +471,7 @@ mod tests {
457471 let mut cairo_runner = run_test_program ( program_content, & mut hint_processor) . unwrap ( ) ;
458472
459473 // relocate memory so we can dump it to file
460- assert ! ( cairo_runner. relocate( true ) . is_ok( ) ) ;
474+ assert ! ( cairo_runner. relocate( true , true ) . is_ok( ) ) ;
461475
462476 let mut buffer = [ 0 ; 120 ] ;
463477 let mut buff_writer = SliceWriter :: new ( & mut buffer) ;
@@ -481,7 +495,7 @@ mod tests {
481495 let mut cairo_runner = cairo_runner ! ( program) ;
482496 let end = cairo_runner. initialize ( false ) . unwrap ( ) ;
483497 assert ! ( cairo_runner. run_until_pc( end, & mut hint_processor) . is_ok( ) ) ;
484- assert ! ( cairo_runner. relocate( false ) . is_ok( ) ) ;
498+ assert ! ( cairo_runner. relocate( false , false ) . is_ok( ) ) ;
485499 assert ! ( cairo_runner. relocated_trace. is_none( ) ) ;
486500 }
487501
0 commit comments