pub struct TraceTable<B: StarkField> { /* private fields */ }Expand description
A concrete implementation of the Trace trait.
This implementation supports concurrent trace generation and should be sufficient for most use cases. There are two ways to create a trace table trace.
First, you can use the TraceTable::init() function which takes a set of vectors as a parameter, where each vector contains values for a given column of the trace. This approach allows you to build an execution trace as you see fit, as long as it meets a basic set of requirements. These requirements are:
- Lengths of all columns in the execution trace must be the same.
- The length of the columns must be some power of two.
The other approach is to use TraceTable::new() function, which takes trace width and length as parameters. This function will allocate memory for the trace, but will not fill it with data. To fill the execution trace, you can use the fill() method, which takes two closures as parameters:
- The first closure is responsible for initializing the first state of the computation (the first row of the execution trace).
- The second closure receives the previous state of the execution trace as input, and must update it to the next state of the computation.
You can also use TraceTable::with_meta() function to create a blank execution trace. This function work just like TraceTable::new() function, but also takes a metadata parameter which can be an arbitrary sequence of bytes up to 64KB in size.
§Concurrent trace generation
For computations which consist of many small independent computations, we can generate the execution trace of the entire computation by building fragments of the trace in parallel, and then joining these fragments together.
For this purpose, TraceTable struct exposes fragments()
method, which takes fragment length as a parameter, breaks the execution trace into equally
sized fragments, and returns an iterator over these fragments. You can then use fragment’s
fill() method to fill all fragments with data in parallel.
The semantics of the fragment’s TraceTableFragment::fill() method are identical to the
semantics of the TraceTable::fill() method.
Implementations§
Source§impl<B: StarkField> TraceTable<B>
impl<B: StarkField> TraceTable<B>
Sourcepub fn new(width: usize, length: usize) -> Self
pub fn new(width: usize, length: usize) -> Self
Creates a new execution trace of the specified width and length.
This allocates all the required memory for the trace, but does not initialize it. It is expected that the trace will be filled using one of the data mutator methods.
§Panics
Panics if:
widthis zero or greater than 255.lengthis smaller than 8, greater than biggest multiplicative subgroup in the fieldB, or is not a power of two.
Sourcepub fn with_meta(width: usize, length: usize, meta: Vec<u8>) -> Self
pub fn with_meta(width: usize, length: usize, meta: Vec<u8>) -> Self
Creates a new execution trace of the specified width and length, and with the specified metadata.
This allocates all the required memory for the trace, but does not initialize it. It is expected that the trace will be filled using one of the data mutator methods.
§Panics
Panics if:
widthis zero or greater than 255.lengthis smaller than 8, greater than the biggest multiplicative subgroup in the fieldB, or is not a power of two.- Length of
metais greater than 65535;
Sourcepub fn init(columns: Vec<Vec<B>>) -> Self
pub fn init(columns: Vec<Vec<B>>) -> Self
Creates a new execution trace from a list of provided trace columns.
§Panics
Panics if:
- The
columnsvector is empty or has over 255 columns. - Number of elements in any of the columns is smaller than 8, greater than the biggest
multiplicative subgroup in the field
B, or is not a power of two. - Number of elements is not identical for all columns.
Sourcepub fn set(&mut self, column: usize, step: usize, value: B)
pub fn set(&mut self, column: usize, step: usize, value: B)
Updates a value in a single cell of the execution trace.
Specifically, the value in the specified column and the specified step is set to the
provide value.
§Panics
Panics if either column or step are out of bounds for this execution trace.
Sourcepub fn fill<I, U>(&mut self, init: I, update: U)
pub fn fill<I, U>(&mut self, init: I, update: U)
Fill all rows in the execution trace.
The rows are filled by executing the provided closures as follows:
initclosure is used to initialize the first row of the trace; it receives a mutable reference to the first state initialized to all zeros. The contents of the state are copied into the first row of the trace after the closure returns.updateclosure is used to populate all subsequent rows of the trace; it receives two parameters:- index of the last updated row (starting with 0).
- a mutable reference to the last updated state; the contents of the state are copied into the next row of the trace after the closure returns.
Sourcepub fn update_row(&mut self, step: usize, state: &[B])
pub fn update_row(&mut self, step: usize, state: &[B])
Updates a single row in the execution trace with provided data.
Sourcepub fn fragments(
&mut self,
fragment_length: usize,
) -> IntoIter<TraceTableFragment<'_, B>>
pub fn fragments( &mut self, fragment_length: usize, ) -> IntoIter<TraceTableFragment<'_, B>>
Breaks the execution trace into mutable fragments.
The number of rows in each fragment will be equal to fragment_length parameter. The
returned fragments can be used to update data in the trace from multiple threads.
§Panics
Panics if fragment_length is smaller than 2, greater than the length of the trace,
or is not a power of two.
Sourcepub fn get_column(&self, col_idx: usize) -> &[B]
pub fn get_column(&self, col_idx: usize) -> &[B]
Returns the entire trace column at the specified index.
Sourcepub fn get(&self, column: usize, step: usize) -> B
pub fn get(&self, column: usize, step: usize) -> B
Returns value of the cell in the specified column at the specified row of this trace.
Sourcepub fn read_row_into(&self, step: usize, target: &mut [B])
pub fn read_row_into(&self, step: usize, target: &mut [B])
Reads a single row from this execution trace into the provided target.
Trait Implementations§
Source§impl<B: Clone + StarkField> Clone for TraceTable<B>
impl<B: Clone + StarkField> Clone for TraceTable<B>
Source§fn clone(&self) -> TraceTable<B>
fn clone(&self) -> TraceTable<B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more