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
impl Program
sourcepub fn new(input: &[LabelledInstruction]) -> Self
pub fn new(input: &[LabelledInstruction]) -> Self
Create a Program from a slice of Instruction.
sourcepub fn to_bwords(&self) -> Vec<BFieldElement>
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.
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
Hash the program using the given AlgebraicHasher.
sourcepub fn run(
&self,
public_input: PublicInput,
non_determinism: NonDeterminism<BFieldElement>
) -> Result<Vec<BFieldElement>>
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.
sourcepub fn trace_execution(
&self,
public_input: PublicInput,
non_determinism: NonDeterminism<BFieldElement>
) -> Result<(AlgebraicExecutionTrace, Vec<BFieldElement>)>
pub fn trace_execution( &self, public_input: PublicInput, non_determinism: NonDeterminism<BFieldElement> ) -> Result<(AlgebraicExecutionTrace, Vec<BFieldElement>)>
sourcepub 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>)
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.
sourcepub 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>)>
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.
sourcepub fn profile(
labelled_instructions: &[LabelledInstruction],
public_input: PublicInput,
non_determinism: NonDeterminism<BFieldElement>
) -> Result<(Vec<BFieldElement>, Vec<ProfileLine>)>
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.