Struct triton_vm::program::Program

source ·
pub struct Program {
    pub instructions: Vec<Instruction>,
}
Expand description

A Program is a Vec<Instruction> that contains duplicate elements for instructions with a size of 2. This means that the index in the vector corresponds to the VM’s instruction_pointer. These duplicate values should most often be skipped/ignored, e.g. when pretty-printing.

Fields§

§instructions: Vec<Instruction>

Implementations§

source§

impl Program

source

pub fn new(input: &[LabelledInstruction]) -> Self

Create a Program from a slice of Instruction.

source

pub fn from_code(code: &str) -> Result<Self>

Create a Program by parsing source code.

source

pub fn to_bwords(&self) -> Vec<BFieldElement>

Convert a Program to a Vec<BFieldElement>.

Every single-word instruction is converted to a single word.

Every double-word instruction is converted to two words.

source

pub fn len_bwords(&self) -> usize

The total length of the program as BFieldElements. Double-word instructions contribute two BFieldElements.

source

pub fn is_empty(&self) -> bool

source

pub fn hash<H: AlgebraicHasher>(&self) -> Digest

Hash the program using the given AlgebraicHasher.

source

pub fn run( &self, public_input: PublicInput, non_determinism: NonDeterminism<BFieldElement> ) -> Result<Vec<BFieldElement>>

Run Triton VM on the given Program with the given public and secret input.

See also trace_execution and debug.

source

pub fn trace_execution( &self, public_input: PublicInput, non_determinism: NonDeterminism<BFieldElement> ) -> Result<(AlgebraicExecutionTrace, Vec<BFieldElement>)>

Trace the execution of a Program. That is, run the Program and additionally record that part of every encountered state that is necessary for proving correct execution. If execution succeeds, returns

  1. an AlgebraicExecutionTrace, and
  2. the output of the program.

See also debug and run.

source

pub fn debug<'pgm>( &'pgm self, public_input: PublicInput, non_determinism: NonDeterminism<BFieldElement>, initial_state: Option<VMState<'pgm>>, num_cycles_to_execute: Option<u32> ) -> (Vec<VMState<'pgm>>, Option<Error>)

Similar to run, but also returns a Vec of VMStates, one for each step of the VM. On premature termination of the VM, returns all VMStates up to the point of failure.

The VM’s initial state is either the provided initial_state, or a new VMState if initial_state is None. The initial state is included in the returned Vec of VMStates. If an initial state is provided, the program, public_input and private_input provided to this method are ignored and the initial state’s program and inputs are used instead.

If num_cycles_to_execute is Some(number_of_cycles), the VM will execute at most number_of_cycles cycles. If num_cycles_to_execute is None, the VM will execute until it halts or the maximum number of cycles (2^{32}) is reached.

See also debug_terminal_state and trace_execution.

source

pub fn debug_terminal_state<'pgm>( &'pgm self, public_input: PublicInput, non_determinism: NonDeterminism<BFieldElement>, initial_state: Option<VMState<'pgm>>, num_cycles_to_execute: Option<u32> ) -> Result<VMState<'pgm>, (Error, VMState<'pgm>)>

Run Triton VM on the given Program with the given public and secret input, and return the final VMState. Requires substantially less RAM than debug since no intermediate states are recorded.

Parameters initial_state and num_cycles_to_execute are handled like in debug; see there for more details.

If an error is encountered, returns the error and the VMState at the point of failure.

See also trace_execution and run.

source

pub fn profile( labelled_instructions: &[LabelledInstruction], public_input: PublicInput, non_determinism: NonDeterminism<BFieldElement> ) -> Result<(Vec<BFieldElement>, Vec<ProfileLine>)>

Run Triton VM on the given program with the given public and secret input, but record the number of cycles spent in each callable block of instructions. This function returns a Result wrapping a program profiler report, which is a Vec of ProfileLines.

Note that the program is given as a list of LabelledInstructions rather than as a Program because the labels are needed to build a meaningful profiler report.

See also run, trace_execution and debug.

Trait Implementations§

source§

impl BFieldCodec for Program

source§

fn decode(sequence: &[BFieldElement]) -> Result<Box<Self>>

source§

fn encode(&self) -> Vec<BFieldElement>

source§

fn static_length() -> Option<usize>

Returns the length in number of BFieldElements if it is known at compile-time. Otherwise, None.
source§

impl Clone for Program

source§

fn clone(&self) -> Program

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 Program

source§

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

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

impl Default for Program

source§

fn default() -> Program

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

impl<'de> Deserialize<'de> for Program

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Program

source§

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

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

impl GetSize for Program

source§

fn get_heap_size(&self) -> usize

Determines how many bytes this object occupies inside the heap. Read more
source§

fn get_stack_size() -> usize

Determines how may bytes this object occupies inside the stack. Read more
source§

fn get_size(&self) -> usize

Determines the total size of the object. Read more
source§

impl IntoIterator for Program

§

type Item = AnInstruction<BFieldElement>

The type of the elements being iterated over.
§

type IntoIter = InstructionIter

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<Program> for Program

source§

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

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Program

source§

impl StructuralEq for Program

source§

impl StructuralPartialEq for Program

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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 Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,