Struct zksync_vm2::VirtualMachine

source ·
pub struct VirtualMachine<T, W> { /* private fields */ }
Expand description

High-performance out-of-circuit EraVM implementation.

Implementations§

source§

impl<T: Tracer, W: World<T>> VirtualMachine<T, W>

source

pub fn new( address: H160, program: Program<T, W>, caller: H160, calldata: &[u8], gas: u32, settings: Settings, ) -> Self

Creates a new VM instance.

source

pub fn world_diff(&self) -> &WorldDiff

Provides a reference to the World diff accumulated by VM execution so far.

source

pub fn run(&mut self, world: &mut W, tracer: &mut T) -> ExecutionEnd

Runs this VM with the specified World and Tracer until an end of execution due to a hook, or an error.

source

pub fn resume_with_additional_gas_limit( &mut self, world: &mut W, tracer: &mut T, gas_limit: u32, ) -> Option<(u32, ExecutionEnd)>

Returns how much of the extra gas limit is left and the stop reason, unless the extra gas limit was exceeded.

Needed to support account validation gas limit. We cannot simply reduce the available gas, as contracts might behave differently depending on remaining gas.

source

pub fn make_snapshot(&mut self)

Creates a VM snapshot. The snapshot can then be rolled back to, or discarded.

§Panics
  • Panics if called outside the initial (bootloader) callframe.
  • Panics if this VM already has a snapshot.
source

pub fn rollback(&mut self)

Returns the VM to the state it was in when Self::make_snapshot() was called.

§Panics
  • Panics if this VM doesn’t hold a snapshot.
  • Panics if called outside the initial (bootloader) callframe.
source

pub fn pop_snapshot(&mut self)

Pops a previously made snapshot without rolling back to it. This effectively commits all changes made up to this point, so that they cannot be rolled back.

§Panics
  • Panics if called outside the initial (bootloader) callframe.

Trait Implementations§

source§

impl<T: Debug, W: Debug> Debug for VirtualMachine<T, W>

source§

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

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

impl<T: Tracer, W: World<T>> StateInterface for VirtualMachine<T, W>

source§

fn read_register(&self, register: u8) -> (U256, bool)

Reads a register with the specified zero-based index. Returns a value together with a pointer flag.
source§

fn set_register(&mut self, register: u8, value: U256, is_pointer: bool)

Sets a register with the specified zero-based index
source§

fn number_of_callframes(&self) -> usize

Returns the total number of call frames.
source§

fn current_frame(&mut self) -> impl CallframeInterface + '_

Returns a mutable handle to the current call frame.
source§

fn callframe(&mut self, n: usize) -> impl CallframeInterface + '_

Returns a mutable handle to a call frame with the specified index, where zero is the current frame, one is the frame before that etc.
source§

fn read_heap_byte(&self, heap: HeapId, index: u32) -> u8

Reads a single byte from the specified heap at the specified 0-based offset.
source§

fn read_heap_u256(&self, heap: HeapId, index: u32) -> U256

Reads an entire U256 word in the big-endian order from the specified heap / offset (which is the index of the most significant byte of the read value).
source§

fn write_heap_u256(&mut self, heap: HeapId, index: u32, value: U256)

Writes an entire U256 word in the big-endian order to the specified heap at the specified offset (which is the index of the most significant byte of the written value).
source§

fn flags(&self) -> Flags

Returns current execution flags.
source§

fn set_flags(&mut self, flags: Flags)

Sets current execution flags.
source§

fn transaction_number(&self) -> u16

Returns the currently set 0-based transaction number.
source§

fn set_transaction_number(&mut self, value: u16)

Sets the current transaction number.
source§

fn context_u128_register(&self) -> u128

Returns the value of the context register.
source§

fn set_context_u128_register(&mut self, value: u128)

Sets the value of the context register.
source§

fn get_storage_state(&self) -> impl Iterator<Item = ((H160, U256), U256)>

Iterates over storage slots read or written during VM execution.
source§

fn get_transient_storage_state( &self, ) -> impl Iterator<Item = ((H160, U256), U256)>

Iterates over all transient storage slots set during VM execution.
source§

fn get_transient_storage(&self, address: H160, slot: U256) -> U256

Gets value of the specified transient storage slot.
source§

fn write_transient_storage(&mut self, address: H160, slot: U256, value: U256)

Sets value of the specified transient storage slot.
source§

fn events(&self) -> impl Iterator<Item = Event>

Iterates over events emitted during VM execution.
source§

fn l2_to_l1_logs(&self) -> impl Iterator<Item = L2ToL1Log>

Iterates over L2-to-L1 logs emitted during VM execution.
source§

fn pubdata(&self) -> i32

Gets the current amount of published pubdata.
source§

fn set_pubdata(&mut self, value: i32)

Sets the current amount of published pubdata.

Auto Trait Implementations§

§

impl<T, W> Freeze for VirtualMachine<T, W>

§

impl<T, W> RefUnwindSafe for VirtualMachine<T, W>

§

impl<T, W> !Send for VirtualMachine<T, W>

§

impl<T, W> !Sync for VirtualMachine<T, W>

§

impl<T, W> Unpin for VirtualMachine<T, W>

§

impl<T, W> UnwindSafe for VirtualMachine<T, W>

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

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

§

fn vzip(self) -> V