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 VmException to CairoRunner::run_from_entrypoint #775

Merged
merged 11 commits into from
Jan 27, 2023
Prev Previous commit
Next Next commit
Merge branch 'main' of github.com:lambdaclass/cairo-rs into add-vm-ex…
…ception-to-run-from-entrypoint
  • Loading branch information
fmoletta committed Jan 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f47845200b111b67cc4ddfb230797675606a2447
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,11 +2,40 @@

#### Upcoming Changes

<<<<<<< HEAD
* Add `VmException` to `CairoRunner::run_from_entrypoint`[#775](https://github.com/lambdaclass/cairo-rs/pull/775)
* Public Api Changes:
* Change error return type of `CairoRunner::run_from_entrypoint` to `CairoRunError`.
* Convert `VirtualMachineError`s outputed during the vm run to `VmException` in `CairoRunner::run_from_entrypoint`.
* Make `VmException` fields public
=======
* Fix `BuiltinRunner::final_stack` and remove quick fix [#778](https://github.com/lambdaclass/cairo-rs/pull/778)
* Public Api changes:
* Various changes to public `BuiltinRunner` method's signatures:
* `final_stack(&self, vm: &VirtualMachine, pointer: Relocatable) -> Result<(Relocatable, usize), RunnerError>` to `final_stack(&mut self, segments: &MemorySegmentManager, memory: &Memory, pointer: Relocatable) -> Result<Relocatable,RunnerError>`.
* `get_used_cells(&self, vm: &VirtualMachine) -> Result<usize, MemoryError>` to `get_used_cells(&self, segments: &MemorySegmentManager) -> Result<usize, MemoryError>`.
* `get_used_instances(&self, vm: &VirtualMachine) -> Result<usize, MemoryError>` to `get_used_instances(&self, segments: &MemorySegmentManager) -> Result<usize, MemoryError>`.
* Bugfixes:
* `BuiltinRunner::final_stack` now updates the builtin's stop_ptr instead of returning it. This replaces the bugfix on PR #768.

#### [0.1.3] - 2023-01-26
* Add secure_run flag + integrate verify_secure_runner into cairo-run [#771](https://github.com/lambdaclass/cairo-rs/pull/777)
* Public Api changes:
* Add command_line argument `secure_run`
* Add argument `secure_run: Option<bool>` to `cairo_run`
* `verify_secure_runner` is now called inside `cairo-run` when `secure_run` is set to true or when it not set and the run is not on `proof_mode`
* Bugfixes:
* `EcOpBuiltinRunner::deduce_memory_cell` now checks that both points are on the curve instead of only the first one
* `EcOpBuiltinRunner::deduce_memory_cell` now returns the values of the point coordinates instead of the indices when a `PointNotOnCurve` error is returned

* Refactor `Refactor verify_secure_runner` [#768](https://github.com/lambdaclass/cairo-rs/pull/768)
* Public Api changes:
* Remove builtin name from the return value of `BuiltinRunner::get_memory_segment_addresses`
* Simplify the return value of `CairoRunner::get_builtin_segments_info` to `Vec<(usize, usize)>`
* CairoRunner::read_return_values now receives a mutable reference to VirtualMachine
* Bugfixes:
* CairoRunner::read_return_values now updates the `stop_ptr` of each builtin after calling `BuiltinRunner::final_stack`
>>>>>>> 195f9ce1eaaa66093207078525e5158e78ce0590

* Use CairoArg enum instead of Any in CairoRunner::run_from_entrypoint [#686](https://github.com/lambdaclass/cairo-rs/pull/686)
* Public Api changes:
62 changes: 61 additions & 1 deletion src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
@@ -4291,7 +4291,7 @@ mod tests {
}

#[test]
fn run_from_entrypoint_csubstitute_error_message_test() {
fn run_from_entrypoint_substitute_error_message_test() {
let program = Program::from_file(
Path::new("cairo_programs/bad_programs/error_msg_function.json"),
None,
@@ -4331,4 +4331,64 @@ mod tests {
Ok(_) => panic!("Expected run to fail"),
}
}

#[test]
fn get_builtins_final_stack_range_check_builtin() {
let program = Program::from_file(
Path::new("cairo_programs/assert_le_felt_hint.json"),
Some("main"),
)
.unwrap();
let mut runner = cairo_runner!(program);
let mut vm = vm!();
let end = runner.initialize(&mut vm).unwrap();
runner
.run_until_pc(end, &mut vm, &mut BuiltinHintProcessor::new_empty())
.unwrap();
vm.segments.compute_effective_sizes(&vm.memory);
let initial_pointer = vm.get_ap();
let expected_pointer = vm.get_ap().sub_usize(1).unwrap();
assert_eq!(
runner.get_builtins_final_stack(&mut vm, initial_pointer),
Ok(expected_pointer)
);
}

#[test]
fn get_builtins_final_stack_4_builtins() {
let program =
Program::from_file(Path::new("cairo_programs/integration.json"), Some("main")).unwrap();
let mut runner = cairo_runner!(program);
let mut vm = vm!();
let end = runner.initialize(&mut vm).unwrap();
runner
.run_until_pc(end, &mut vm, &mut BuiltinHintProcessor::new_empty())
.unwrap();
vm.segments.compute_effective_sizes(&vm.memory);
let initial_pointer = vm.get_ap();
let expected_pointer = vm.get_ap().sub_usize(4).unwrap();
assert_eq!(
runner.get_builtins_final_stack(&mut vm, initial_pointer),
Ok(expected_pointer)
);
}

#[test]
fn get_builtins_final_stack_no_builtins() {
let program =
Program::from_file(Path::new("cairo_programs/fibonacci.json"), Some("main")).unwrap();
let mut runner = cairo_runner!(program);
let mut vm = vm!();
let end = runner.initialize(&mut vm).unwrap();
runner
.run_until_pc(end, &mut vm, &mut BuiltinHintProcessor::new_empty())
.unwrap();
vm.segments.compute_effective_sizes(&vm.memory);
let initial_pointer = vm.get_ap();
let expected_pointer = vm.get_ap();
assert_eq!(
runner.get_builtins_final_stack(&mut vm, initial_pointer),
Ok(expected_pointer)
);
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.