@@ -157,6 +157,8 @@ pub struct CairoRunnerBuilder {
157157 program_base : Option < Relocatable > ,
158158 execution_base : Option < Relocatable > ,
159159 memory : MemorySegmentManager ,
160+ // Set after loading program.
161+ loaded_program : bool ,
160162 // Set after loading instruction cache.
161163 // instructions: Vec<Option<Instruction>>,
162164 // Set after compiling hints.
@@ -200,6 +202,7 @@ impl CairoRunnerBuilder {
200202 program_base : None ,
201203 execution_base : None ,
202204 memory : MemorySegmentManager :: new ( ) ,
205+ loaded_program : false ,
203206 } )
204207 }
205208
@@ -365,6 +368,7 @@ impl CairoRunnerBuilder {
365368 for i in 0 ..self . program . shared_program_data . data . len ( ) {
366369 self . memory . memory . mark_as_accessed ( ( program_base + i) ?) ;
367370 }
371+ self . loaded_program = true ;
368372 Ok ( ( ) )
369373 }
370374
@@ -396,6 +400,7 @@ impl CairoRunnerBuilder {
396400 exec_scopes : ExecutionScopes :: new ( ) ,
397401 relocated_trace : None ,
398402 program : self . program ,
403+ loaded_program : self . loaded_program ,
399404 } )
400405 }
401406}
@@ -418,6 +423,7 @@ pub struct CairoRunner {
418423 pub relocated_memory : Vec < Option < Felt252 > > ,
419424 pub exec_scopes : ExecutionScopes ,
420425 pub relocated_trace : Option < Vec < RelocatedTraceEntry > > ,
426+ loaded_program : bool ,
421427}
422428
423429#[ derive( Clone , Debug , PartialEq ) ]
@@ -479,6 +485,7 @@ impl CairoRunner {
479485 None
480486 } ,
481487 relocated_trace : None ,
488+ loaded_program : false ,
482489 } )
483490 }
484491
@@ -745,13 +752,16 @@ impl CairoRunner {
745752 let prog_base = self . program_base . ok_or ( RunnerError :: NoProgBase ) ?;
746753 let exec_base = self . execution_base . ok_or ( RunnerError :: NoExecBase ) ?;
747754 self . initial_pc = Some ( ( prog_base + entrypoint) ?) ;
748- self . vm
749- . load_data ( prog_base, & self . program . shared_program_data . data )
750- . map_err ( RunnerError :: MemoryInitializationError ) ?;
751-
752- // Mark all addresses from the program segment as accessed
753- for i in 0 ..self . program . shared_program_data . data . len ( ) {
754- self . vm . segments . memory . mark_as_accessed ( ( prog_base + i) ?) ;
755+ if !self . loaded_program {
756+ self . vm
757+ . load_data ( prog_base, & self . program . shared_program_data . data )
758+ . map_err ( RunnerError :: MemoryInitializationError ) ?;
759+
760+ // Mark all addresses from the program segment as accessed
761+ for i in 0 ..self . program . shared_program_data . data . len ( ) {
762+ self . vm . segments . memory . mark_as_accessed ( ( prog_base + i) ?) ;
763+ }
764+ self . loaded_program = true
755765 }
756766 self . vm
757767 . segments
0 commit comments