Struct essential_check::state_read_vm::Vm

source ·
pub struct Vm {
    pub pc: usize,
    pub stack: Stack,
    pub temp_memory: Memory,
    pub repeat: Repeat,
    pub state_slots_mut: StateSlotsMut,
}
Expand description

The operation execution state of the State Read VM.

Fields§

§pc: usize

The program counter, i.e. index of the current operation within the program.

§stack: Stack

The stack machine.

§temp_memory: Memory

The memory for temporary storage of words.

§repeat: Repeat

The repeat stack.

§state_slots_mut: StateSlotsMut

The state slots that will be written to by this program.

Implementations§

source§

impl Vm

source

pub async fn exec_ops<'a, S>( &mut self, ops: &[StateRead], access: Access<'a>, state_read: &S, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<u64, StateReadError<<S as StateRead>::Error>>
where S: StateRead,

Execute the given operations from the current state of the VM.

Upon reaching a Halt operation or reaching the end of the operation sequence, returns the gas spent and the Vm will be left in the resulting state.

This is a wrapper around Vm::exec that expects operation access in the form of a &[Op].

If memory bloat is a concern, consider using the Vm::exec_bytecode or Vm::exec_bytecode_iter methods which allow for providing a more compact representation of the operations in the form of mapped bytecode.

source

pub async fn exec_bytecode<'a, S, B>( &mut self, bytecode_mapped: &BytecodeMapped<StateRead, B>, access: Access<'a>, state_read: &S, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<u64, StateReadError<<S as StateRead>::Error>>
where S: StateRead, B: Deref<Target = [u8]>,

Execute the given mapped bytecode from the current state of the VM.

Upon reaching a Halt operation or reaching the end of the operation sequence, returns the gas spent and the Vm will be left in the resulting state.

This is a wrapper around Vm::exec that expects operation access in the form of &BytecodeMapped.

This can be a more memory efficient alternative to Vm::exec_ops due to the compact representation of operations in the form of bytecode and indices.

source

pub async fn exec_bytecode_iter<'a, S, I>( &mut self, bytecode_iter: I, access: Access<'a>, state_read: &S, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<u64, StateReadError<<S as StateRead>::Error>>
where S: StateRead, I: IntoIterator<Item = u8>, <I as IntoIterator>::IntoIter: Unpin,

Execute the given bytecode from the current state of the VM.

Upon reaching a Halt operation or reaching the end of the operation sequence, returns the gas spent and the Vm will be left in the resulting state.

The given bytecode will be mapped lazily during execution. This can be more efficient than pre-mapping the bytecode and using Vm::exec_bytecode in the case that execution may fail early.

However, successful execution still requires building the full BytecodeMapped instance internally. So if bytecode has already been mapped, Vm::exec_bytecode should be preferred.

source

pub async fn exec<'a, S, OA>( &mut self, access: Access<'a>, state_read: &S, op_access: OA, op_gas_cost: &impl OpGasCost, gas_limit: GasLimit, ) -> Result<u64, StateReadError<<S as StateRead>::Error>>
where S: StateRead, OA: OpAccess<Op = StateRead> + Unpin, <OA as OpAccess>::Error: Into<OpError<<S as StateRead>::Error>>,

Execute over the given operation access from the current state of the VM.

Upon reaching a Halt operation or reaching the end of the operation sequence, returns the gas spent and the Vm will be left in the resulting state.

The type requirements for the op_access argument can make this finicky to use directly. You may prefer one of the convenience methods:

source

pub fn into_state_slots(self) -> Vec<Vec<i64>>

Consumes the Vm and returns the read state slots.

The returned slots correspond directly with the current memory content.

Trait Implementations§

source§

impl Debug for Vm

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Vm

source§

fn default() -> Vm

Returns the “default value” for a type. Read more
source§

impl<'a, S> From<StepOpAsyncFuture<'a, S>> for &'a mut Vm
where S: StateRead,

source§

fn from(future: StepOpAsyncFuture<'a, S>) -> &'a mut Vm

Converts to this type from the input type.
source§

impl PartialEq for Vm

source§

fn eq(&self, other: &Vm) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for Vm

Auto Trait Implementations§

§

impl Freeze for Vm

§

impl RefUnwindSafe for Vm

§

impl Send for Vm

§

impl Sync for Vm

§

impl Unpin for Vm

§

impl UnwindSafe for Vm

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> 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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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.