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
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
15 changes: 14 additions & 1 deletion src/types/relocatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use num_traits::{FromPrimitive, ToPrimitive, Zero};
use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Display},
ops::Add,
ops::{Add, AddAssign},
};

#[derive(Eq, Hash, PartialEq, PartialOrd, Clone, Copy, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -95,6 +95,12 @@ impl Add<usize> for Relocatable {
}
}

impl AddAssign<usize> for Relocatable {
fn add_assign(&mut self, rhs: usize) {
self.offset += rhs
}
}

impl Add<i32> for Relocatable {
type Output = Relocatable;
fn add(self, other: i32) -> Self {
Expand Down Expand Up @@ -825,4 +831,11 @@ mod tests {
String::from("6")
)
}

#[test]
fn relocatable_add_assign_usize() {
let mut addr = Relocatable::from((1, 0));
addr += 1;
assert_eq!(addr, Relocatable::from((1, 1)))
}
}
2 changes: 2 additions & 0 deletions src/vm/errors/memory_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
10 changes: 8 additions & 2 deletions src/vm/errors/vm_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub enum VirtualMachineError {
UnconstrainedResJumpRel,
#[error("Res.UNCONSTRAINED cannot be used with Opcode.ASSERT_EQ")]
UnconstrainedResAssertEq,
#[error("An integer value as Res cannot be used with PcUpdate.JUMP_REL")]
JumpRelNotInt,
#[error(
"Failed to compute Res.MUL: Could not complete computation of non pure values {0} * {1}"
)]
ComputeResRelocatableMul(MaybeRelocatable, MaybeRelocatable),
#[error("Couldn't compute operand {0} at address {1}")]
FailedToComputeOperands(String, Relocatable),
#[error("An ASSERT_EQ instruction failed: {0} != {1}.")]
Expand All @@ -42,8 +48,6 @@ pub enum VirtualMachineError {
CantWriteReturnFp(MaybeRelocatable, MaybeRelocatable),
#[error("Couldn't get or load dst")]
NoDst,
#[error("Pure Value Error")]
PureValue,
#[error("Invalid res value: {0}")]
InvalidRes(i64),
#[error("Invalid opcode value: {0}")]
Expand Down Expand Up @@ -144,6 +148,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>),
}
Loading