Skip to content

Commit

Permalink
fix: add missing call to initialize in cairo_run_parsed_program (#…
Browse files Browse the repository at this point in the history
…1330)

* fix: add missing `CairoRunner::initialize` call

* Ignore `VirtualMachineError::EndOfProgram` error

* Update changelog

* Add "fuzzing" scope to changelog entry

* Remove whitespace
  • Loading branch information
MegaRedHand authored Jul 14, 2023
1 parent 3876ae7 commit cecba20
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions vm/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()?;
Expand Down
12 changes: 12 additions & 0 deletions vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cecba20

Please sign in to comment.