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

Add new error type HintError #676

Merged
merged 59 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c47e701
Start get_traceback_entries + add convenience methos
fmoletta Dec 22, 2022
51219ca
Add fn is_call_instruction
fmoletta Dec 22, 2022
3b276db
add code
fmoletta Dec 22, 2022
05f0bdd
Merge branch 'main' of github.com:lambdaclass/cairo-rs into traceback
fmoletta Dec 22, 2022
c89eb3f
Refactor code
fmoletta Dec 22, 2022
f02db3e
Clippy
fmoletta Dec 22, 2022
05813bd
Add get_traceback method
fmoletta Dec 22, 2022
58992c3
Fix get_error_attr_value
fmoletta Dec 22, 2022
b381624
Add traceback to VmException
fmoletta Dec 22, 2022
936eadc
Make traceback non-optional
fmoletta Dec 22, 2022
e72dff5
Add tests for is_call_instruction
fmoletta Dec 22, 2022
93eae26
Add traceback to error display
fmoletta Dec 22, 2022
67ccc39
Add test + fix logic for get_traceback_entries
fmoletta Dec 22, 2022
ba410b0
Code refactor
fmoletta Dec 22, 2022
acf3299
Add one more test for get_traceback_entries
fmoletta Dec 22, 2022
bc66d0f
Fix string format + add test for get_traceback
fmoletta Dec 22, 2022
b3952cb
Improve fn
fmoletta Dec 27, 2022
c2fa8a0
Add reference to is_call_instruction signature
fmoletta Dec 27, 2022
88e4b52
Add reference to immediate in decode_instruction + remove clone
fmoletta Dec 27, 2022
7a03cec
Merge branch 'main' of github.com:lambdaclass/cairo-rs into traceback
fmoletta Dec 27, 2022
371dc43
Fix hint_processor mutability in tests
fmoletta Dec 27, 2022
46a7202
Add Location::get_location_marks
fmoletta Dec 27, 2022
fd0b9c6
Fix method to_string_with_contents
fmoletta Dec 27, 2022
5e753bb
Fix string format
fmoletta Dec 27, 2022
09ee596
Fix string format
fmoletta Dec 28, 2022
9eac613
Update traceback tests
fmoletta Dec 28, 2022
3612b01
Add tests for Location::to_string_with_contents()
fmoletta Dec 28, 2022
f56122d
Fix intermediate string format
fmoletta Dec 28, 2022
00ccd31
Fix test
fmoletta Dec 28, 2022
2ed2287
Add tests for Location::get_location_marks()
fmoletta Dec 28, 2022
839cbf1
Update VmException display
fmoletta Dec 28, 2022
8937c87
Fix string format
fmoletta Dec 28, 2022
747bb77
Fix string format
fmoletta Dec 28, 2022
1dbe083
Merge branch 'main' of github.com:lambdaclass/cairo-rs into input_fil…
fmoletta Dec 28, 2022
5f78c47
Remove debug print
fmoletta Dec 28, 2022
542e06e
Fix Display
fmoletta Dec 28, 2022
d33f6e1
Implement Display for MaybeRelocatable
fmoletta Dec 28, 2022
2fdef4a
Add real-case test for VmException Display
fmoletta Dec 28, 2022
9845fc5
Remove debug format from erros containing MaybeRelocatable and Reloca…
fmoletta Dec 28, 2022
8b1e11c
Add tests for display implementation
fmoletta Dec 28, 2022
f46e49a
Update Changelog
fmoletta Dec 28, 2022
e9ecfe4
Clippy
fmoletta Dec 28, 2022
40d06cb
Remove unnecessary &
fmoletta Dec 29, 2022
c7b5cfe
Add hint location to InstructionLocation
fmoletta Dec 29, 2022
160fe32
Use InstructionLocation instead of Location in insruction_locations f…
fmoletta Dec 29, 2022
bd6111a
Add hint location logic to get_location
fmoletta Dec 29, 2022
a9045fa
Add rought version of VirtualMachineError::Hint
fmoletta Dec 29, 2022
085d6eb
Add test for error display on HintError
fmoletta Dec 29, 2022
2909f1b
Add test for get_location with hint_index
fmoletta Dec 29, 2022
5542e3f
Start refactor
fmoletta Dec 29, 2022
4a9e6dd
Update changelog
fmoletta Dec 29, 2022
7f6e049
Merge branch 'hint-location' into hint-error
fmoletta Dec 29, 2022
68f7384
Finnish changing hint fns to HintError
fmoletta Dec 29, 2022
94aa1f1
Update custom hint example
fmoletta Dec 29, 2022
c683b6d
Fix changelog format
fmoletta Dec 29, 2022
31fdb1e
Add changelog entry for this PR
fmoletta Dec 29, 2022
3695a11
Merge branch 'hint-location' into hint-error
fmoletta Dec 29, 2022
6b142e7
Merge branch 'main' of github.com:lambdaclass/cairo-rs into hint-error
fmoletta Jan 2, 2023
d17c74d
Merge branch 'main' of github.com:lambdaclass/cairo-rs into hint-error
fmoletta Jan 3, 2023
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
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@
* `pub fn get_location(pc: &usize, runner: &CairoRunner) -> Option<Location>` is now `pub fn get_location(pc: usize, runner: &CairoRunner) -> Option<Location>`
* `pub fn decode_instruction(encoded_instr: i64, mut imm: Option<BigInt>) -> Result<instruction::Instruction, VirtualMachineError>` is now `pub fn decode_instruction(encoded_instr: i64, mut imm: Option<&BigInt>) -> Result<instruction::Instruction, VirtualMachineError>`
* `VmExcepion` field's string format now mirror their cairo-lang conterparts.

* Add input file contents to traceback [#666](https://github.com/lambdaclass/cairo-rs/pull/666/files)
* Public Api changes:
* `VirtualMachineError` enum variants containing `MaybeRelocatable` and/or `Relocatable` values now use the `Display` format instead of `Debug` in their `Display` implementation
* `get_traceback` now adds the source code line to each traceback entry

* Use hint location instead of instruction location when building VmExceptions from hint failure [#673](https://github.com/lambdaclass/cairo-rs/pull/673/files)
* Public Api changes:
* `hints` field added to `InstructionLocation`
* `Program.instruction_locations` type changed from `Option<HashMap<usize, Location>>` to `Option<HashMap<usize, InstructionLocation>>`
* `VirtualMachineError`s produced by `HintProcessor::execute_hint()` will be wrapped in a `VirtualMachineError::Hint` error containing their hint_index
* `get_location()` now receives an an optional usize value `hint_index`, used to obtain hint locations

* Add new error type `HintError` [#676](https://github.com/lambdaclass/cairo-rs/pull/676)
* Public Api changes:
* `HintProcessor::execute_hint()` now returns a `HintError` instead of a `VirtualMachineError`
* helper functions on `hint_processor_utils.rs` now return a `HintError`

25 changes: 25 additions & 0 deletions cairo_programs/bad_programs/bad_range_check.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%builtins range_check

func check_range{range_check_ptr: felt*}(num: felt) {
with_attr error_message("Failed range-check") {
[range_check_ptr] = num;
}
return();
}

func sub_1_check_range{range_check_ptr: felt*}(num: felt) -> felt {
check_range(num - 1);
return num - 1;
}

func sub_by_1_check_range{range_check_ptr: felt*}(num: felt, sub_amount: felt) {
if (sub_amount == 0) {
return();
}
return sub_by_1_check_range(sub_1_check_range(num), sub_amount -1);
}

func main{range_check_ptr: felt*}() {
sub_by_1_check_range(6, 7);
return ();
}
72 changes: 42 additions & 30 deletions custom_hint_example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions custom_hint_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use cairo_rs::hint_processor::builtin_hint_processor::hint_utils::get_integer_fr
use cairo_rs::hint_processor::hint_processor_definition::HintReference;
use cairo_rs::types::exec_scope::ExecutionScopes;
use cairo_rs::serde::deserialize_program::ApTracking;
use cairo_rs::vm::{errors::vm_errors::VirtualMachineError, vm_core::VirtualMachine};
use cairo_rs::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use num_bigint::BigInt;
use std::collections::HashMap;
use std::path::Path;
use std::rc::Rc;

// Create the function that implements the custom hint
fn print_a_hint(
Expand All @@ -18,7 +19,7 @@ fn print_a_hint(
ids_data: &HashMap<String, HintReference>,
ap_tracking: &ApTracking,
_constants: &HashMap<String, BigInt>,
) -> Result<(), VirtualMachineError> {
) -> Result<(), HintError> {
let a = get_integer_from_var_name("a", vm, ids_data, ap_tracking)?;
println!("{}", a);
Ok(())
Expand All @@ -32,14 +33,16 @@ fn main() {
let mut hint_processor = BuiltinHintProcessor::new_empty();

//Add the custom hint, together with the Python code
hint_processor.add_hint(String::from("print(ids.a)"), hint);
hint_processor.add_hint(String::from("print(ids.a)"), Rc::new(hint));

//Run the cairo program
cairo_run(
Path::new("custom_hint.json"),
"main",
false,
false,
"all",
false,
&mut hint_processor,
)
.expect("Couldn't run program");
Expand Down
Loading