Struct miden_processor::StackOutputs

source ·
pub struct StackOutputs { /* private fields */ }
Expand description

Output container for Miden VM programs.

Miden program outputs contain the full state of the stack at the end of execution as well as the addresses in the overflow table which are required to reconstruct the table (when combined with the overflow values from the stack state).

stack is expected to be ordered as if the elements were popped off the stack one by one. Thus, the value at the top of the stack is expected to be in the first position, and the order of the rest of the output elements will also match the order on the stack.

overflow_addrs is expected to start with the prev address value from the first row in the overflow table (the row representing the deepest element in the stack) and then be followed by the address (clk value) of each row in the table starting from the deepest element in the stack and finishing with the row which was added to the table last.

Implementations§

source§

impl StackOutputs

source

pub const MAX_LEN: usize = 65_535usize

source

pub fn new( stack: Vec<BaseElement>, overflow_addrs: Vec<BaseElement> ) -> Result<StackOutputs, OutputError>

Constructs a new StackOutputs struct from the provided stack elements and overflow addresses.

§Errors

Returns an error if the number of stack elements is greater than STACK_TOP_SIZE (16) and overflow_addrs does not contain exactly stack.len() + 1 - STACK_TOP_SIZE elements.

source

pub fn try_from_ints( stack: Vec<u64>, overflow_addrs: Vec<u64> ) -> Result<StackOutputs, OutputError>

Attempts to create StackOutputs struct from the provided stack elements and overflow addresses represented as vectors of u64 values.

§Errors

Returns an error if:

  • Any of the provided stack elements are invalid field elements.
  • Any of the provided overflow addresses are invalid field elements.
source

pub fn get_stack_item(&self, idx: usize) -> Option<BaseElement>

Returns the element located at the specified position on the stack or None if out of bounds.

source

pub fn get_stack_word(&self, idx: usize) -> Option<[BaseElement; 4]>

Returns the word located starting at the specified Felt position on the stack or None if out of bounds. For example, passing in 0 returns the word at the top of the stack, and passing in 4 returns the word starting at element index 4.

source

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

Returns the stack outputs, which is state of the stack at the end of execution converted to integers.

source

pub fn stack_truncated(&self, num_outputs: usize) -> &[BaseElement]

Returns the number of requested stack outputs or returns the full stack if fewer than the requested number of stack values exist.

source

pub fn stack_top(&self) -> [BaseElement; 16]

Returns the state of the top of the stack at the end of execution.

source

pub fn overflow_addrs(&self) -> &[BaseElement]

Returns the overflow address outputs, which are the addresses required to reconstruct the overflow table (when combined with the stack overflow values) converted to integers.

source

pub fn has_overflow(&self) -> bool

Returns true if the overflow table outputs are non-empty.

source

pub fn overflow_prev(&self) -> BaseElement

Returns the previous address prev for the first row in the stack overflow table

source

pub fn stack_overflow(&self) -> Vec<(BaseElement, BaseElement)>

Returns (address, value) for all rows which were on the overflow table at the end of execution in the order in which they were added to the table (deepest stack item first).

source

pub fn stack_mut(&mut self) -> &mut [BaseElement]

Returns mutable access to the stack outputs, to be used for testing or running examples. TODO: this should be marked with #[cfg(test)] attribute, but that currently won’t work with the integration test handler util.

Trait Implementations§

source§

impl Clone for StackOutputs

source§

fn clone(&self) -> StackOutputs

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for StackOutputs

source§

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

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

impl Default for StackOutputs

source§

fn default() -> StackOutputs

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

impl Deserializable for StackOutputs

source§

fn read_from<R>(source: &mut R) -> Result<StackOutputs, DeserializationError>
where R: ByteReader,

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
source§

impl PartialEq for StackOutputs

source§

fn eq(&self, other: &StackOutputs) -> 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 Serializable for StackOutputs

source§

fn write_into<W>(&self, target: &mut W)
where W: ByteWriter,

Serializes self into bytes and writes these bytes into the target.
source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
source§

impl ToElements<BaseElement> for StackOutputs

source§

impl Eq for StackOutputs

source§

impl StructuralPartialEq for StackOutputs

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more