Struct cairo_vm::vm::vm_core::VirtualMachine
source · pub struct VirtualMachine {
pub builtin_runners: Vec<BuiltinRunner>,
pub segments: MemorySegmentManager,
/* private fields */
}
Fields§
§builtin_runners: Vec<BuiltinRunner>
§segments: MemorySegmentManager
Implementations§
source§impl VirtualMachine
impl VirtualMachine
pub fn new(trace_enabled: bool) -> VirtualMachine
pub fn compute_segments_effective_sizes(&mut self)
pub fn step_hint( &mut self, hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &[Box<dyn Any>], constants: &HashMap<String, Felt252>, ) -> Result<(), VirtualMachineError>
pub fn step_instruction(&mut self) -> Result<(), VirtualMachineError>
pub fn step( &mut self, hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &[Box<dyn Any>], constants: &HashMap<String, Felt252>, ) -> Result<(), VirtualMachineError>
sourcepub fn compute_operands(
&self,
instruction: &Instruction,
) -> Result<(Operands, OperandsAddresses, DeducedOperands), VirtualMachineError>
pub fn compute_operands( &self, instruction: &Instruction, ) -> Result<(Operands, OperandsAddresses, DeducedOperands), VirtualMachineError>
Compute operands and result, trying to deduce them if normal memory access returns a None value.
sourcepub fn verify_auto_deductions(&self) -> Result<(), VirtualMachineError>
pub fn verify_auto_deductions(&self) -> Result<(), VirtualMachineError>
Makes sure that all assigned memory cells are consistent with their auto deduction rules.
pub fn verify_auto_deductions_for_addr( &self, addr: Relocatable, builtin: &BuiltinRunner, ) -> Result<(), VirtualMachineError>
pub fn end_run( &mut self, exec_scopes: &ExecutionScopes, ) -> Result<(), VirtualMachineError>
pub fn mark_address_range_as_accessed( &mut self, base: Relocatable, len: usize, ) -> Result<(), VirtualMachineError>
sourcepub fn add_memory_segment(&mut self) -> Relocatable
pub fn add_memory_segment(&mut self) -> Relocatable
Adds a new segment and to the memory and returns its starting location as a Relocatable value.
pub fn get_ap(&self) -> Relocatable
pub fn get_fp(&self) -> Relocatable
pub fn get_pc(&self) -> Relocatable
sourcepub fn get_integer(
&self,
key: Relocatable,
) -> Result<Cow<'_, Felt252>, MemoryError>
pub fn get_integer( &self, key: Relocatable, ) -> Result<Cow<'_, Felt252>, MemoryError>
Gets the integer value corresponding to the Relocatable address
sourcepub fn get_relocatable(
&self,
key: Relocatable,
) -> Result<Relocatable, MemoryError>
pub fn get_relocatable( &self, key: Relocatable, ) -> Result<Relocatable, MemoryError>
Gets the relocatable value corresponding to the Relocatable address
sourcepub fn get_maybe<'a, 'b: 'a, K: 'a>(
&'b self,
key: &'a K,
) -> Option<MaybeRelocatable>
pub fn get_maybe<'a, 'b: 'a, K: 'a>( &'b self, key: &'a K, ) -> Option<MaybeRelocatable>
Gets a MaybeRelocatable value from memory indicated by a generic address
sourcepub fn get_builtin_runners(&self) -> &Vec<BuiltinRunner>
pub fn get_builtin_runners(&self) -> &Vec<BuiltinRunner>
Returns a reference to the vector with all builtins present in the virtual machine
sourcepub fn get_builtin_runners_as_mut(&mut self) -> &mut Vec<BuiltinRunner>
pub fn get_builtin_runners_as_mut(&mut self) -> &mut Vec<BuiltinRunner>
Returns a mutable reference to the vector with all builtins present in the virtual machine
sourcepub fn insert_value<T: Into<MaybeRelocatable>>(
&mut self,
key: Relocatable,
val: T,
) -> Result<(), MemoryError>
pub fn insert_value<T: Into<MaybeRelocatable>>( &mut self, key: Relocatable, val: T, ) -> Result<(), MemoryError>
Inserts a value into a memory address given by a Relocatable value
sourcepub fn load_data(
&mut self,
ptr: Relocatable,
data: &[MaybeRelocatable],
) -> Result<Relocatable, MemoryError>
pub fn load_data( &mut self, ptr: Relocatable, data: &[MaybeRelocatable], ) -> Result<Relocatable, MemoryError>
Writes data into the memory from address ptr and returns the first address after the data.
sourcepub fn write_arg(
&mut self,
ptr: Relocatable,
arg: &dyn Any,
) -> Result<MaybeRelocatable, MemoryError>
pub fn write_arg( &mut self, ptr: Relocatable, arg: &dyn Any, ) -> Result<MaybeRelocatable, MemoryError>
Writes args into the memory from address ptr and returns the first address after the data.
pub fn memcmp( &self, lhs: Relocatable, rhs: Relocatable, len: usize, ) -> (Ordering, usize)
pub fn mem_eq(&self, lhs: Relocatable, rhs: Relocatable, len: usize) -> bool
sourcepub fn get_return_values(
&self,
n_ret: usize,
) -> Result<Vec<MaybeRelocatable>, MemoryError>
pub fn get_return_values( &self, n_ret: usize, ) -> Result<Vec<MaybeRelocatable>, MemoryError>
Gets n_ret
return values from memory
sourcepub fn get_range(
&self,
addr: Relocatable,
size: usize,
) -> Vec<Option<Cow<'_, MaybeRelocatable>>>
pub fn get_range( &self, addr: Relocatable, size: usize, ) -> Vec<Option<Cow<'_, MaybeRelocatable>>>
Gets n elements from memory starting from addr (n being size)
sourcepub fn get_continuous_range(
&self,
addr: Relocatable,
size: usize,
) -> Result<Vec<MaybeRelocatable>, MemoryError>
pub fn get_continuous_range( &self, addr: Relocatable, size: usize, ) -> Result<Vec<MaybeRelocatable>, MemoryError>
Gets n elements from memory starting from addr (n being size)
sourcepub fn get_integer_range(
&self,
addr: Relocatable,
size: usize,
) -> Result<Vec<Cow<'_, Felt252>>, MemoryError>
pub fn get_integer_range( &self, addr: Relocatable, size: usize, ) -> Result<Vec<Cow<'_, Felt252>>, MemoryError>
Gets n integer values from memory starting from addr (n being size),
pub fn get_range_check_builtin( &self, ) -> Result<&RangeCheckBuiltinRunner<RC_N_PARTS_STANDARD>, VirtualMachineError>
pub fn get_signature_builtin( &mut self, ) -> Result<&mut SignatureBuiltinRunner, VirtualMachineError>
pub fn get_output_builtin_mut( &mut self, ) -> Result<&mut OutputBuiltinRunner, VirtualMachineError>
pub fn get_segment_used_size(&self, index: usize) -> Option<usize>
pub fn get_segment_size(&self, index: usize) -> Option<usize>
pub fn add_temporary_segment(&mut self) -> Relocatable
sourcepub fn add_relocation_rule(
&mut self,
src_ptr: Relocatable,
dst_ptr: Relocatable,
) -> Result<(), MemoryError>
pub fn add_relocation_rule( &mut self, src_ptr: Relocatable, dst_ptr: Relocatable, ) -> Result<(), MemoryError>
Add a new relocation rule.
Will return an error if any of the following conditions are not met:
- Source address’s segment must be negative (temporary).
- Source address’s offset must be zero.
- There shouldn’t already be relocation at the source segment.
pub fn gen_arg( &mut self, arg: &dyn Any, ) -> Result<MaybeRelocatable, MemoryError>
sourcepub fn write_output(
&mut self,
writer: &mut impl Write,
) -> Result<(), VirtualMachineError>
pub fn write_output( &mut self, writer: &mut impl Write, ) -> Result<(), VirtualMachineError>
Write the values hosted in the output builtin’s segment. Does nothing if the output builtin is not present in the program.
sourcepub fn get_public_memory_addresses(
&self,
) -> Result<Vec<(usize, usize)>, VirtualMachineError>
pub fn get_public_memory_addresses( &self, ) -> Result<Vec<(usize, usize)>, VirtualMachineError>
Returns a list of addresses of memory cells that constitute the public memory.
sourcepub fn mod_builtin_fill_memory(
&mut self,
add_mod_ptr_n: Option<(Relocatable, usize)>,
mul_mod_ptr_n: Option<(Relocatable, usize)>,
batch_size: Option<usize>,
) -> Result<(), VirtualMachineError>
pub fn mod_builtin_fill_memory( &mut self, add_mod_ptr_n: Option<(Relocatable, usize)>, mul_mod_ptr_n: Option<(Relocatable, usize)>, batch_size: Option<usize>, ) -> Result<(), VirtualMachineError>
Fetches add_mod & mul_mod builtins according to the optional arguments and executes fill_memory
Returns an error if either of this optional parameters is true but the corresponding builtin is not present
Verifies that both builtin’s (if present) batch sizes match the batch_size arg if set
Auto Trait Implementations§
impl Freeze for VirtualMachine
impl !RefUnwindSafe for VirtualMachine
impl !Send for VirtualMachine
impl !Sync for VirtualMachine
impl Unpin for VirtualMachine
impl !UnwindSafe for VirtualMachine
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.