Struct EvalContext

Source
pub struct EvalContext<'a> { /* private fields */ }
Expand description

Evaluation context for the AVM

Implementations§

Source§

impl<'a> EvalContext<'a>

Source

pub fn new( program: &'a [u8], run_mode: RunMode, cost_budget: u64, version: TealVersion, group_index: usize, group_size: usize, ledger: &'a mut dyn LedgerAccess, ) -> Self

Create a new evaluation context

Source

pub fn set_trace_enabled(&mut self, enabled: bool)

Enable or disable execution tracing

Source

pub fn trace(&self) -> &[String]

Get the execution trace

Source

pub fn add_trace(&mut self, message: String)

Add a trace entry

Source

pub fn stack(&self) -> &[StackValue]

Get a read-only reference to the stack

Source

pub fn push(&mut self, value: StackValue) -> AvmResult<()>

Push a value onto the stack

Source

pub fn pop(&mut self) -> AvmResult<StackValue>

Pop a value from the stack

Source

pub fn peek(&self) -> AvmResult<&StackValue>

Peek at the top value on the stack without removing it

Source

pub fn stack_size(&self) -> usize

Get the current stack size

Source

pub fn stack_is_empty(&self) -> bool

Check if the stack is empty

Source

pub fn peek_at_depth(&self, depth: usize) -> AvmResult<&StackValue>

Get value at stack depth N (0 = top, 1 = one below top, etc.)

Source

pub fn remove_at_depth(&mut self, depth: usize) -> AvmResult<StackValue>

Remove value at stack depth N and return it

Source

pub fn insert_at_depth( &mut self, depth: usize, value: StackValue, ) -> AvmResult<()>

Insert value at stack depth N (0 = top)

Source

pub fn pc(&self) -> usize

Get the current program counter

Source

pub fn program_len(&self) -> usize

Get the program length

Source

pub fn set_pc(&mut self, pc: usize) -> AvmResult<()>

Set the program counter

Source

pub fn advance_pc(&mut self, offset: usize) -> AvmResult<()>

Advance the program counter

Source

pub fn current_byte(&self) -> AvmResult<u8>

Get the current program byte at PC

Source

pub fn read_bytes(&self, count: usize) -> AvmResult<&[u8]>

Read bytes from program starting at PC

Source

pub fn add_cost(&mut self, cost: u64) -> AvmResult<()>

Add to the execution cost

Source

pub fn cost(&self) -> u64

Get the current execution cost

Source

pub fn cost_budget(&self) -> u64

Get the cost budget

Source

pub fn version(&self) -> TealVersion

Get the TEAL version

Source

pub fn run_mode(&self) -> RunMode

Get the run mode

Source

pub fn group_index(&self) -> usize

Get the group index

Source

pub fn group_size(&self) -> usize

Get the group size

Source

pub fn get_scratch(&self, index: u8) -> AvmResult<&StackValue>

Get a value from scratch space

Source

pub fn set_scratch(&mut self, index: u8, value: StackValue) -> AvmResult<()>

Set a value in scratch space

Source

pub fn call_subroutine(&mut self, target: usize) -> AvmResult<()>

Call a subroutine

Source

pub fn return_from_subroutine(&mut self) -> AvmResult<()>

Return from a subroutine

Source

pub fn ledger(&self) -> &dyn LedgerAccess

Get the ledger access interface

Source

pub fn ledger_mut(&mut self) -> &mut dyn LedgerAccess

Get mutable access to the ledger

Source

pub fn is_finished(&self) -> bool

Check if execution is finished

Source

pub fn set_function_prototype( &mut self, args: usize, returns: usize, ) -> AvmResult<()>

Set function prototype

Source

pub fn frame_dig(&self, depth: i8) -> AvmResult<StackValue>

Dig value from function frame

Source

pub fn frame_bury(&mut self, depth: i8, value: StackValue) -> AvmResult<()>

Bury value in function frame

Source

pub fn set_int_constants(&mut self, constants: Vec<u64>)

Store integer constants from intcblock

Source

pub fn set_byte_constants(&mut self, constants: Vec<Vec<u8>>)

Store byte constants from bytecblock

Source

pub fn get_int_constant(&self, index: usize) -> AvmResult<u64>

Get integer constant by index

Source

pub fn get_byte_constant(&self, index: usize) -> AvmResult<&[u8]>

Get byte constant by index

Source

pub fn get_program(&self) -> &[u8]

Get program reference for reading bytes

Source

pub fn branch(&mut self, target: i16) -> AvmResult<()>

Branch to a relative target

Source

pub fn current_opcode_spec<'b>( &self, vm: &'b VirtualMachine, ) -> AvmResult<&'b OpSpec>

Get current opcode specification (for debugging)

Source

pub fn step( &mut self, vm: &VirtualMachine, config: &ExecutionConfig, ) -> AvmResult<()>

Execute a single step with the given VM and config

Trait Implementations§

Source§

impl<'a> Debug for EvalContext<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for EvalContext<'a>

§

impl<'a> !RefUnwindSafe for EvalContext<'a>

§

impl<'a> !Send for EvalContext<'a>

§

impl<'a> !Sync for EvalContext<'a>

§

impl<'a> Unpin for EvalContext<'a>

§

impl<'a> !UnwindSafe for EvalContext<'a>

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

Source§

type Output = T

Should always be Self
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.