Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling in initialize_state #1657

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#### Upcoming Changes
* feat: add a `--tracer` option which hosts a web server that shows the line by line execution of cairo code along with memory registers [#1265](https://github.com/lambdaclass/cairo-vm/pull/1265)

* feat: Make air public inputs deserializable [#1648](https://github.com/lambdaclass/cairo-vm/pull/1648)
* feat: Fix error handling in `initialize_state`[#1657](https://github.com/lambdaclass/cairo-vm/pull/1657)

* feat: Make air public inputs deserializable [#1657](https://github.com/lambdaclass/cairo-vm/pull/1648)

* feat: Show only layout builtins in air private input [#1651](https://github.com/lambdaclass/cairo-vm/pull/1651)

Expand Down
35 changes: 12 additions & 23 deletions vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,30 +436,19 @@ impl CairoRunner {
entrypoint: usize,
stack: Vec<MaybeRelocatable>,
) -> Result<(), RunnerError> {
if let Some(prog_base) = self.program_base {
let initial_pc = Relocatable {
segment_index: prog_base.segment_index,
offset: prog_base.offset + entrypoint,
};
self.initial_pc = Some(initial_pc);
vm.load_data(prog_base, &self.program.shared_program_data.data)
.map_err(RunnerError::MemoryInitializationError)?;

// Mark all addresses from the program segment as accessed
let base = self
.program_base
.unwrap_or_else(|| Relocatable::from((0, 0)));
for i in 0..self.program.shared_program_data.data.len() {
vm.segments.memory.mark_as_accessed((base + i)?);
}
}
if let Some(exec_base) = self.execution_base {
vm.segments
.load_data(exec_base, &stack)
.map_err(RunnerError::MemoryInitializationError)?;
} else {
return Err(RunnerError::NoProgBase);
let prog_base = self.program_base.ok_or(RunnerError::NoProgBase)?;
let exec_base = self.execution_base.ok_or(RunnerError::NoExecBase)?;
self.initial_pc = Some((prog_base + entrypoint)?);
vm.load_data(prog_base, &self.program.shared_program_data.data)
.map_err(RunnerError::MemoryInitializationError)?;

// Mark all addresses from the program segment as accessed
for i in 0..self.program.shared_program_data.data.len() {
vm.segments.memory.mark_as_accessed((prog_base + i)?);
}
vm.segments
.load_data(exec_base, &stack)
.map_err(RunnerError::MemoryInitializationError)?;
Ok(())
}

Expand Down
Loading