Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/lambdaclass/cairo-vm into r…
Browse files Browse the repository at this point in the history
…ange_check96_mod_integration_test
  • Loading branch information
fmoletta committed Apr 4, 2024
2 parents 2f5d5a0 + ec00e31 commit 8e83414
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
* Remove field `_bound`, replacing it with public method `bound`.
* Add public methods `name` & `n_parts`.

* BREAKING: Remove `CairoRunner::add_additional_hash_builtin` & `VirtualMachine::disable_trace`[#1658](https://github.com/lambdaclass/cairo-vm/pull/1658)

* feat: output builtin add_attribute method [#1691](https://github.com/lambdaclass/cairo-vm/pull/1691)
* feat(BREAKING): Add mod builtin [#1673](https://github.com/lambdaclass/cairo-vm/pull/1673)

Main Changes:
Expand All @@ -31,6 +28,12 @@
* Remove empty implementations of `deduce_memory_cell` & `add_validation_rules` from all builtin runners
* Remove duplicated implementation of `final_stack` from all builtin runners except output and move it to the enum implementation

* feat: add a method to retrieve the output builtin from the VM [#1690](https://github.com/lambdaclass/cairo-vm/pull/1690)

* BREAKING: Remove `CairoRunner::add_additional_hash_builtin` & `VirtualMachine::disable_trace`[#1658](https://github.com/lambdaclass/cairo-vm/pull/1658)

* feat: output builtin add_attribute method [#1691](https://github.com/lambdaclass/cairo-vm/pull/1691)

* feat: Add zero segment [#1668](https://github.com/lambdaclass/cairo-vm/pull/1668)

* feat: Bump cairo_lang to 0.13.1 in testing env [#1687](https://github.com/lambdaclass/cairo-vm/pull/1687)
Expand Down
2 changes: 2 additions & 0 deletions vm/src/vm/errors/vm_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub enum VirtualMachineError {
InconsistentAutoDeduction(Box<(&'static str, MaybeRelocatable, Option<MaybeRelocatable>)>),
#[error("Invalid hint encoding at pc: {0}")]
InvalidHintEncoding(Box<MaybeRelocatable>),
#[error("Expected output builtin to be present")]
NoOutputBuiltin,
#[error("Expected range_check builtin to be present")]
NoRangeCheckBuiltin,
#[error("Expected ecdsa builtin to be present")]
Expand Down
40 changes: 39 additions & 1 deletion vm/src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use crate::{
exec_scope_errors::ExecScopeError, memory_errors::MemoryError,
vm_errors::VirtualMachineError,
},
runners::builtin_runner::{BuiltinRunner, RangeCheckBuiltinRunner, SignatureBuiltinRunner},
runners::builtin_runner::{
BuiltinRunner, OutputBuiltinRunner, RangeCheckBuiltinRunner, SignatureBuiltinRunner,
},
trace::trace_entry::TraceEntry,
vm_memory::memory_segments::MemorySegmentManager,
},
Expand Down Expand Up @@ -948,6 +950,18 @@ impl VirtualMachine {
Err(VirtualMachineError::NoSignatureBuiltin)
}

pub fn get_output_builtin_mut(
&mut self,
) -> Result<&mut OutputBuiltinRunner, VirtualMachineError> {
for builtin in self.get_builtin_runners_as_mut() {
if let BuiltinRunner::Output(output_builtin) = builtin {
return Ok(output_builtin);
};
}

Err(VirtualMachineError::NoOutputBuiltin)
}

#[cfg(feature = "with_tracer")]
pub fn relocate_segments(&self) -> Result<Vec<usize>, MemoryError> {
self.segments.relocate_segments()
Expand Down Expand Up @@ -3891,6 +3905,30 @@ mod tests {
assert_eq!(builtins[1].name(), BITWISE_BUILTIN_NAME);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_get_output_builtin_mut() {
let mut vm = vm!();

assert_matches!(
vm.get_output_builtin_mut(),
Err(VirtualMachineError::NoOutputBuiltin)
);

let output_builtin = OutputBuiltinRunner::new(true);
vm.builtin_runners.push(output_builtin.clone().into());

let vm_output_builtin = vm
.get_output_builtin_mut()
.expect("Output builtin should be returned");

assert_eq!(vm_output_builtin.base(), output_builtin.base());
assert_eq!(vm_output_builtin.pages, output_builtin.pages);
assert_eq!(vm_output_builtin.attributes, output_builtin.attributes);
assert_eq!(vm_output_builtin.stop_ptr, output_builtin.stop_ptr);
assert_eq!(vm_output_builtin.included, output_builtin.included);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn get_range_for_continuous_memory() {
Expand Down

0 comments on commit 8e83414

Please sign in to comment.