Open
Description
Describe the bug
It's possible to initialize the runner with self.execution_base != (1, 0)
as the initialize_segments
function just adds segments without constraint on already existing segments
pub fn initialize_segments(&mut self, program_base: Option<Relocatable>) {
self.program_base = match program_base {
Some(base) => Some(base),
None => Some(self.vm.add_memory_segment()),
};
self.execution_base = Some(self.vm.add_memory_segment());
In this context, runner.initial_(f/a)p
are properly targeting the right segment but this info is dropped during the initialization of the RunContext
pub fn initialize_vm(&mut self) -> Result<(), RunnerError> {
self.vm.run_context.pc = *self.initial_pc.as_ref().ok_or(RunnerError::NoPC)?;
self.vm.run_context.ap = self.initial_ap.as_ref().ok_or(RunnerError::NoAP)?.offset;
self.vm.run_context.fp = self.initial_fp.as_ref().ok_or(RunnerError::NoFP)?.offset;
which actually has a hard-coded 1
impl RunContext {
pub fn get_ap(&self) -> Relocatable {
Relocatable::from((1, self.ap))
}
pub fn get_fp(&self) -> Relocatable {
Relocatable::from((1, self.fp))
}
All together, this makes the VM unable to run since ap
and fp
are pointing to the wrong segment.
Since there is no reason to enforce the execution segment to be 1, the easiest and most reasonable fix to me is to add a execution_base_segment_index
to the RunContext
and to update the get_ap
and get_fp
methods.