VirtualMachine

Struct VirtualMachine 

Source
pub struct VirtualMachine {
    pub builtin_runners: Vec<BuiltinRunner>,
    pub simulated_builtin_runners: Vec<BuiltinRunner>,
    pub segments: MemorySegmentManager,
    /* private fields */
}

Fields§

§builtin_runners: Vec<BuiltinRunner>§simulated_builtin_runners: Vec<BuiltinRunner>

A simulated builtin is being verified in the executed Cairo code (so proving them only involves proving cairo steps), rather than being outputted as their own segment and proven later using dedicated AIRs.

These builtins won’t be included in the layout, hence the builtin segment pointer won’t be passed as argument to the program. The program needs a mechanism for obtaining the segment pointer. See example implementation of this mechanism in simulated_builtins.cairo, or cairo-lang’s simple_bootloader.cairo.

§segments: MemorySegmentManager

Implementations§

Source§

impl VirtualMachine

Source

pub fn new(trace_enabled: bool, disable_trace_padding: bool) -> VirtualMachine

Source

pub fn compute_segments_effective_sizes(&mut self)

Source

pub fn step_hint( &mut self, hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &[Box<dyn Any>], ) -> Result<(), VirtualMachineError>

Available on non-crate feature extensive_hints only.
Source

pub fn step_instruction(&mut self) -> Result<(), VirtualMachineError>

Source

pub fn step( &mut self, hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &[Box<dyn Any>], ) -> Result<(), VirtualMachineError>

Source

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.

Source

pub fn complete_builtin_auto_deductions( &mut self, ) -> Result<(), VirtualMachineError>

Updates the memory with missing built-in deductions and verifies the existing ones.

Source

pub fn verify_auto_deductions(&self) -> Result<(), VirtualMachineError>

Makes sure that all assigned memory cells are consistent with their auto deduction rules.

Source

pub fn verify_auto_deductions_for_addr( &self, addr: Relocatable, builtin: &BuiltinRunner, ) -> Result<(), VirtualMachineError>

Source

pub fn end_run( &mut self, exec_scopes: &ExecutionScopes, fill_holes: bool, ) -> Result<(), VirtualMachineError>

Source

pub fn mark_address_range_as_accessed( &mut self, base: Relocatable, len: usize, ) -> Result<(), VirtualMachineError>

Source

pub fn get_traceback_entries(&self) -> Vec<(Relocatable, Relocatable)>

Returns the values (fp, pc) corresponding to each call instruction in the traceback. Returns the most recent call last.

Source

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.

Source

pub fn get_ap(&self) -> Relocatable

Source

pub fn get_fp(&self) -> Relocatable

Source

pub fn get_pc(&self) -> Relocatable

Source

pub fn get_current_step(&self) -> usize

Source

pub fn get_integer( &self, key: Relocatable, ) -> Result<Cow<'_, Felt252>, MemoryError>

Gets the integer value corresponding to the Relocatable address

Source

pub fn get_relocatable( &self, key: Relocatable, ) -> Result<Relocatable, MemoryError>

Gets the relocatable value corresponding to the Relocatable address

Source

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

Source

pub fn get_builtin_runners(&self) -> &Vec<BuiltinRunner>

Returns a reference to the vector with all builtins present in the virtual machine

Source

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

Source

pub fn get_all_builtin_runners_as_mut_iter( &mut self, ) -> impl Iterator<Item = &mut BuiltinRunner>

Returns a mutable iterator over all builtin runners used. That is, both builtin_runners and simulated_builtin_runners.

Source

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

Source

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.

Source

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.

Source

pub fn memcmp( &self, lhs: Relocatable, rhs: Relocatable, len: usize, ) -> (Ordering, usize)

Source

pub fn mem_eq(&self, lhs: Relocatable, rhs: Relocatable, len: usize) -> bool

Source

pub fn is_accessed(&self, addr: &Relocatable) -> Result<bool, MemoryError>

Source

pub fn get_return_values( &self, n_ret: usize, ) -> Result<Vec<MaybeRelocatable>, MemoryError>

Gets n_ret return values from memory

Source

pub fn get_range( &self, addr: Relocatable, size: usize, ) -> Vec<Option<Cow<'_, MaybeRelocatable>>>

Gets n elements from memory starting from addr (n being size)

Source

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)

Source

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),

Source

pub fn get_u32_range( &self, addr: Relocatable, size: usize, ) -> Result<Vec<u32>, MemoryError>

Gets n u32 values from memory starting from addr (n being size). Returns an error if any of the values inside the range is missing (memory gap) or is not a u32.

Source

pub fn get_range_check_builtin( &self, ) -> Result<&RangeCheckBuiltinRunner<RC_N_PARTS_STANDARD>, VirtualMachineError>

Source

pub fn get_signature_builtin( &mut self, ) -> Result<&mut SignatureBuiltinRunner, VirtualMachineError>

Source

pub fn get_output_builtin_mut( &mut self, ) -> Result<&mut OutputBuiltinRunner, VirtualMachineError>

Source

pub fn get_segment_used_size(&self, index: usize) -> Option<usize>

Source

pub fn get_segment_size(&self, index: usize) -> Option<usize>

Source

pub fn add_temporary_segment(&mut self) -> Relocatable

Source

pub fn add_relocation_rule( &mut self, src_ptr: Relocatable, dst_ptr: Relocatable, ) -> Result<(), MemoryError>

Add a new relocation rule.

When using feature “extensive_hints” the destination is allowed to be an Integer (via MaybeRelocatable). Relocating memory to anything other than a Relocatable is generally not useful, but it does make the implementation consistent with the pythonic version.

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.
Source

pub fn gen_arg( &mut self, arg: &dyn Any, ) -> Result<MaybeRelocatable, MemoryError>

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .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
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V