Skip to content

Commit

Permalink
Add SyscallError (#1357)
Browse files Browse the repository at this point in the history
* Add constant string to VirtualMachineError::Hint error

* Add SycallError

* update CHANGELOG.md

* Update doc

* Fix str constant
  • Loading branch information
pefontana committed Aug 10, 2023
1 parent fced122 commit c249cd9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* Add HintError::SyscallError and VmErrors::HINT_ERROR_STR constant [#1357](https://github.com/lambdaclass/cairo-rs/pull/1357)

* feat: make *arbitrary* feature also enable a `proptest::arbitrary::Arbitrary` implementation for `Felt252` [#1355](https://github.com/lambdaclass/cairo-vm/pull/1355)

* fix: correctly display invalid signature error message [#1361](https://github.com/lambdaclass/cairo-vm/pull/1361)
Expand Down
2 changes: 1 addition & 1 deletion docs/hint_processor/builtin_hint_processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ There are also some helpers that dont depend on the hint processor used that can
You can also find plenty of example implementations in the [builtin hint processor folder](../../../src/hint_processor/builtin_hint_processor).

### Error Handling
This API uses VirtualMachineError as error return type for hint functions, while its not possible to add error types to VirtualMachineError, you can use VirtualMachineError::CustomHint which receives a string and prints an error message with the format: "Custom Hint Error: [your message]".
This API uses VirtualMachineError as error return type for hint functions, while its not possible to add error types to VirtualMachineError, you can use VirtualMachineError::CustomHint which receives a string and prints an error message with the format: "Hint Error: [your message]".
For example, if we want our hint to return an error if ids.a is less than 0 we could write:

```rust
Expand Down
4 changes: 3 additions & 1 deletion vm/src/vm/errors/hint_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub enum HintError {
UnknownIdentifierInternal,
#[error("Wrong identifier type at address {0}")]
WrongIdentifierTypeInternal(Box<Relocatable>),
#[error("Custom Hint Error: {0}")]
#[error("Hint Error: {0}")]
CustomHint(Box<str>),
#[error("Missing constant: {0}")]
MissingConstant(Box<&'static str>),
Expand Down Expand Up @@ -182,6 +182,8 @@ pub enum HintError {
InvalidValue(Box<(&'static str, Felt252, Felt252)>),
#[error("Attempt to subtract with overflow: ids.m - 1")]
NPairBitsTooLowM,
#[error("{0}")]
SyscallError(Box<str>),
}

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion vm/src/vm/errors/vm_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::{
};
use felt::Felt252;

pub const HINT_ERROR_STR: &str = "Got an exception while executing a hint: ";

#[derive(Debug, Error)]
pub enum VirtualMachineError {
#[error(transparent)]
Expand Down Expand Up @@ -111,7 +113,7 @@ pub enum VirtualMachineError {
InvalidArgCount(Box<(usize, usize)>),
#[error("Couldn't parse prime: {0}")]
CouldntParsePrime(Box<str>),
#[error("Got an exception while executing a hint: {}", (*.0).1)]
#[error("{HINT_ERROR_STR}{}", (*.0).1)]
Hint(Box<(usize, HintError)>),
#[error("Unexpected Failure")]
Unexpected,
Expand Down

1 comment on commit c249cd9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: c249cd9 Previous: fced122 Ratio
add_u64_with_felt/1 4 ns/iter (± 0) 3 ns/iter (± 0) 1.33
add_u64_with_felt/2 4 ns/iter (± 0) 3 ns/iter (± 0) 1.33
add_u64_with_felt/3 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/4 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/5 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/6 5 ns/iter (± 0) 3 ns/iter (± 0) 1.67
add_u64_with_felt/7 5 ns/iter (± 0) 3 ns/iter (± 0) 1.67
add_u64_with_felt/8 4 ns/iter (± 0) 2 ns/iter (± 0) 2

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.