diff --git a/CHANGELOG.md b/CHANGELOG.md index 53928153d5..60a0eb6a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,11 @@ #### Upcoming Changes -* feat: add `arbitrary` feature to enable arbitrary derive in `Program` and `CairoRunConfig` +* feat(fuzzing): add `arbitrary` feature to enable arbitrary derive in `Program` and `CairoRunConfig` [#1306](https://github.com/lambdaclass/cairo-vm/pull/1306) [#1330](https://github.com/lambdaclass/cairo-vm/pull/1330) * perf: remove pointless iterator from rc limits tracking [#1316](https://github.com/lambdaclass/cairo-vm/pull/1316) -* feat: add `from_bytes_le` and `from_bytes_ne` methods [#1326](https://github.com/lambdaclass/cairo-vm/pull/1326) +* feat(felt): add `from_bytes_le` and `from_bytes_ne` methods to `Felt252` [#1326](https://github.com/lambdaclass/cairo-vm/pull/1326) #### [0.8.2] - 2023-7-10 @@ -16,7 +16,6 @@ * feat: add dependency installation script `install.sh` [#1298](https://github.com/lambdaclass/cairo-vm/pull/1298) - * fix: specify resolver version 2 in the virtual workspace's manifest [#1311](https://github.com/lambdaclass/cairo-vm/pull/1311) * feat: add `lambdaworks-felt` feature to `cairo-vm-cli` [#1308](https://github.com/lambdaclass/cairo-vm/pull/1308) diff --git a/vm/src/cairo_run.rs b/vm/src/cairo_run.rs index c47a50138b..6a1435a36c 100644 --- a/vm/src/cairo_run.rs +++ b/vm/src/cairo_run.rs @@ -86,6 +86,8 @@ pub fn cairo_run_parsed_program( hint_executor: &mut dyn HintProcessor, steps_limit: usize, ) -> Result<(CairoRunner, VirtualMachine), CairoRunError> { + use crate::vm::errors::vm_errors::VirtualMachineError; + let secure_run = cairo_run_config .secure_run .unwrap_or(!cairo_run_config.proof_mode); @@ -98,9 +100,15 @@ pub fn cairo_run_parsed_program( let mut vm = VirtualMachine::new(cairo_run_config.trace_enabled); - cairo_runner - .run_until_steps(steps_limit, &mut vm, hint_executor) - .map_err(|err| VmException::from_vm_error(&cairo_runner, &vm, err))?; + let _end = cairo_runner.initialize(&mut vm)?; + + let res = match cairo_runner.run_until_steps(steps_limit, &mut vm, hint_executor) { + Err(VirtualMachineError::EndOfProgram(_remaining)) => Ok(()), // program ran OK but ended before steps limit + res => res, + }; + + res.map_err(|err| VmException::from_vm_error(&cairo_runner, &vm, err))?; + cairo_runner.end_run(false, false, &mut vm, hint_executor)?; vm.verify_auto_deductions()?; diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 026cabb719..ad21942c50 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -3020,6 +3020,18 @@ mod tests { ); } + #[test] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn run_empty() { + let program = program!(); + let mut cairo_runner = cairo_runner!(&program); + let mut vm = vm!(true); + assert_matches!( + cairo_runner.initialize(&mut vm), + Err(RunnerError::MissingMain) + ); + } + #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] /*Program used: