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

Check error types in vm_core.rs + simplify code #837

Merged
merged 9 commits into from
Feb 15, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Check error types used
  • Loading branch information
fmoletta committed Feb 14, 2023
commit 13f3c201cff7830897de41ccf8eedc35f7fe6166
2 changes: 2 additions & 0 deletions src/vm/errors/memory_errors.rs
Original file line number Diff line number Diff line change
@@ -75,4 +75,6 @@ pub enum MemoryError {
MsgNonInt(Relocatable),
#[error("Failed to convert String: {0} to FieldElement")]
FailedStringToFieldElementConversion(String),
#[error("Failed to fetch {0} return values, ap is only {1}")]
FailedToGetReturnValues(usize, Relocatable),
}
2 changes: 2 additions & 0 deletions src/vm/errors/vm_errors.rs
Original file line number Diff line number Diff line change
@@ -144,6 +144,8 @@ pub enum VirtualMachineError {
NegBuiltinBase,
#[error("Security Error: Invalid Memory Value: temporary address not relocated: {0}")]
InvalidMemoryValueTemporaryAddress(Relocatable),
#[error("accessed_addresses is None.")]
MissingAccessedAddresses,
#[error(transparent)]
Other(Box<dyn Error>),
}
11 changes: 5 additions & 6 deletions src/vm/vm_core.rs
Original file line number Diff line number Diff line change
@@ -332,10 +332,9 @@ impl VirtualMachine {
) -> Result<Option<MaybeRelocatable>, VirtualMachineError> {
for (_, builtin) in self.builtin_runners.iter() {
if builtin.base() == address.segment_index {
match builtin.deduce_memory_cell(address, &self.memory) {
Ok(maybe_reloc) => return Ok(maybe_reloc),
Err(error) => return Err(VirtualMachineError::RunnerError(error)),
};
return builtin
.deduce_memory_cell(address, &self.memory)
.map_err(VirtualMachineError::RunnerError);
}
}
Ok(None)
@@ -749,7 +748,7 @@ impl VirtualMachine {
}
self.accessed_addresses
.as_mut()
.ok_or(VirtualMachineError::RunNotFinished)?
.ok_or(VirtualMachineError::MissingAccessedAddresses)?
.extend((0..len).map(|i: usize| base + i));
Ok(())
}
@@ -900,7 +899,7 @@ impl VirtualMachine {
.run_context
.get_ap()
.sub_usize(n_ret)
.map_err(|_| MemoryError::NumOutOfBounds)?;
.map_err(|_| MemoryError::FailedToGetReturnValues(n_ret, self.get_ap()))?;
self.memory.get_continuous_range(&addr.into(), n_ret)
}