Struct triton_vm::program::Program

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

A program for Triton VM. It can be run, profiled, and its execution can be traced.

Hashing a program under Tip5 yields a Digest that can be used in a Claim, i.e., is consistent with Triton VM’s program attestation.

A program may contain debug information, such as label names and breakpoints. Access this information through methods label_for_address() and is_breakpoint(). Some operations, most notably BField-encoding, discard this debug information.

Fields§

§instructions: Vec<Instruction>

Implementations§

source§

impl Program

source

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

source

pub fn from_code(code: &str) -> Result<Self, ParseError<'_>>

Create a Program by parsing source code.

source

pub fn labelled_instructions(&self) -> Vec<LabelledInstruction>

source

pub fn is_breakpoint(&self, address: u64) -> bool

source

pub fn type_hints_at(&self, address: u64) -> Vec<TypeHint>

source

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

Turn the program into a sequence of BFieldElements. Each instruction is encoded as its opcode, followed by its argument (if any).

Note: This is almost (but not quite!) equivalent to encoding the program. For that, use encode() instead.

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

Produces the program’s canonical hash digest for the given AlgebraicHasher.

source

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

Run Triton VM on the Program with the given public input and non-determinism. If an error is encountered, the returned VMError contains the VMState at the point of execution failure.

See also trace_execution and profile.

source

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

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 run and profile.

source

pub fn trace_execution_of_state( &self, state: VMState ) -> Result<(AlgebraicExecutionTrace, VMState), VMError>

Trace the execution of a Program from a given VMState. Consider using trace_execution, unless you know this is what you want.

Returns the AlgebraicExecutionTrace and the terminal VMState if execution succeeds.

source

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

Run Triton VM 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.

See also run and trace_execution.

source

pub fn label_for_address(&self, address: u64) -> String

The label for the given address, or a deterministic, unique substitute if no label is found.

Trait Implementations§

source§

impl<'a> Arbitrary<'a> for Program

source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
source§

impl BFieldCodec for Program

§

type Error = ProgramDecodingError

source§

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

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<'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<'_>) -> FmtResult

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

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, 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

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

Initializes a with the given initializer. Read more
source§

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

Dereferences the given pointer. Read more
source§

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

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where 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 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,