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
impl Program
pub fn new(labelled_instructions: &[LabelledInstruction]) -> Self
sourcepub fn from_code(code: &str) -> Result<Self, ParseError<'_>>
pub fn from_code(code: &str) -> Result<Self, ParseError<'_>>
Create a Program by parsing source code.
pub fn labelled_instructions(&self) -> Vec<LabelledInstruction>
pub fn is_breakpoint(&self, address: u64) -> bool
pub fn type_hints_at(&self, address: u64) -> Vec<TypeHint>
sourcepub fn to_bwords(&self) -> Vec<BFieldElement>
pub fn to_bwords(&self) -> Vec<BFieldElement>
sourcepub fn len_bwords(&self) -> usize
pub fn len_bwords(&self) -> usize
The total length of the program as BFieldElements. Double-word instructions contribute
two BFieldElements.
pub fn is_empty(&self) -> bool
sourcepub fn hash<H: AlgebraicHasher>(&self) -> Digest
pub fn hash<H: AlgebraicHasher>(&self) -> Digest
Produces the program’s canonical hash digest for the given AlgebraicHasher.
sourcepub fn run(
&self,
public_input: PublicInput,
non_determinism: NonDeterminism
) -> Result<Vec<BFieldElement>, VMError>
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.
sourcepub fn trace_execution(
&self,
public_input: PublicInput,
non_determinism: NonDeterminism
) -> Result<(AlgebraicExecutionTrace, Vec<BFieldElement>), VMError>
pub fn trace_execution( &self, public_input: PublicInput, non_determinism: NonDeterminism ) -> Result<(AlgebraicExecutionTrace, Vec<BFieldElement>), VMError>
sourcepub fn trace_execution_of_state(
&self,
state: VMState
) -> Result<(AlgebraicExecutionTrace, VMState), VMError>
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.
sourcepub fn profile(
&self,
public_input: PublicInput,
non_determinism: NonDeterminism
) -> Result<(Vec<BFieldElement>, VMProfilingReport), VMError>
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.
sourcepub fn label_for_address(&self, address: u64) -> String
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
impl<'a> Arbitrary<'a> for Program
source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moresource§impl BFieldCodec for Program
impl BFieldCodec for Program
type Error = ProgramDecodingError
fn decode(sequence: &[BFieldElement]) -> Result<Box<Self>, Self::Error>
fn encode(&self) -> Vec<BFieldElement>
source§fn static_length() -> Option<usize>
fn static_length() -> Option<usize>
source§impl<'de> Deserialize<'de> for Program
impl<'de> Deserialize<'de> for Program
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl GetSize for Program
impl GetSize for Program
source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
source§fn get_stack_size() -> usize
fn get_stack_size() -> usize
source§impl IntoIterator for Program
impl IntoIterator for Program
§type Item = AnInstruction<BFieldElement>
type Item = AnInstruction<BFieldElement>
§type IntoIter = InstructionIter
type IntoIter = InstructionIter
source§impl PartialEq for Program
impl PartialEq for Program
impl Eq for Program
Auto Trait Implementations§
impl Freeze for Program
impl RefUnwindSafe for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl UnwindSafe for Program
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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