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
impl StackOutputs
pub const MAX_LEN: usize = 65_535usize
sourcepub fn new(
stack: Vec<BaseElement>,
overflow_addrs: Vec<BaseElement>
) -> Result<StackOutputs, OutputError>
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.
sourcepub fn try_from_ints(
stack: Vec<u64>,
overflow_addrs: Vec<u64>
) -> Result<StackOutputs, OutputError>
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.
sourcepub fn get_stack_item(&self, idx: usize) -> Option<BaseElement>
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.
sourcepub fn get_stack_word(&self, idx: usize) -> Option<[BaseElement; 4]>
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
.
sourcepub fn stack(&self) -> &[BaseElement]
pub fn stack(&self) -> &[BaseElement]
Returns the stack outputs, which is state of the stack at the end of execution converted to integers.
sourcepub fn stack_truncated(&self, num_outputs: usize) -> &[BaseElement]
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.
sourcepub fn stack_top(&self) -> [BaseElement; 16]
pub fn stack_top(&self) -> [BaseElement; 16]
Returns the state of the top of the stack at the end of execution.
sourcepub fn overflow_addrs(&self) -> &[BaseElement]
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.
sourcepub fn has_overflow(&self) -> bool
pub fn has_overflow(&self) -> bool
Returns true if the overflow table outputs are non-empty.
sourcepub fn overflow_prev(&self) -> BaseElement
pub fn overflow_prev(&self) -> BaseElement
Returns the previous address prev
for the first row in the stack overflow table
sourcepub fn stack_overflow(&self) -> Vec<(BaseElement, BaseElement)>
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).
sourcepub fn stack_mut(&mut self) -> &mut [BaseElement]
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
impl Clone for StackOutputs
source§fn clone(&self) -> StackOutputs
fn clone(&self) -> StackOutputs
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for StackOutputs
impl Debug for StackOutputs
source§impl Default for StackOutputs
impl Default for StackOutputs
source§fn default() -> StackOutputs
fn default() -> StackOutputs
source§impl Deserializable for StackOutputs
impl Deserializable for StackOutputs
source§fn read_from<R>(source: &mut R) -> Result<StackOutputs, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<StackOutputs, DeserializationError>where
R: ByteReader,
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl PartialEq for StackOutputs
impl PartialEq for StackOutputs
source§fn eq(&self, other: &StackOutputs) -> bool
fn eq(&self, other: &StackOutputs) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serializable for StackOutputs
impl Serializable for StackOutputs
source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self
into bytes and writes these bytes into the target
.