TraceTable

Struct TraceTable 

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

  1. Lengths of all columns in the execution trace must be the same.
  2. 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:

  1. The first closure is responsible for initializing the first state of the computation (the first row of the execution trace).
  2. 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>

Source

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:

  • width is zero or greater than 255.
  • length is smaller than 8, greater than biggest multiplicative subgroup in the field B, or is not a power of two.
Source

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:

  • width is zero or greater than 255.
  • length is smaller than 8, greater than the biggest multiplicative subgroup in the field B, or is not a power of two.
  • Length of meta is greater than 65535;
Source

pub fn init(columns: Vec<Vec<B>>) -> Self

Creates a new execution trace from a list of provided trace columns.

§Panics

Panics if:

  • The columns vector 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.
Source

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.

Source

pub fn fill<I, U>(&mut self, init: I, update: U)
where I: FnOnce(&mut [B]), U: FnMut(usize, &mut [B]),

Fill all rows in the execution trace.

The rows are filled by executing the provided closures as follows:

  • init closure 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.
  • update closure 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.
Source

pub fn update_row(&mut self, step: usize, state: &[B])

Updates a single row in the execution trace with provided data.

Source

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.

Source

pub fn width(&self) -> usize

Returns the number of columns in this execution trace.

Source

pub fn get_column(&self, col_idx: usize) -> &[B]

Returns the entire trace column at the specified index.

Source

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.

Source

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>

Source§

fn clone(&self) -> TraceTable<B>

Returns a duplicate 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<B: Debug + StarkField> Debug for TraceTable<B>

Source§

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

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

impl<B: StarkField> Trace for TraceTable<B>

Source§

type BaseField = B

Base field for this execution trace. Read more
Source§

fn info(&self) -> &TraceInfo

Returns trace info for this trace.
Source§

fn read_main_frame( &self, row_idx: usize, frame: &mut EvaluationFrame<Self::BaseField>, )

Reads an evaluation frame from the main trace segment at the specified row.
Source§

fn main_segment(&self) -> &ColMatrix<B>

Returns a reference to a [Matrix] describing the main segment of this trace.
Source§

fn length(&self) -> usize

Returns the number of rows in this trace.
Source§

fn main_trace_width(&self) -> usize

Returns the number of columns in the main segment of this trace.
Source§

fn aux_trace_width(&self) -> usize

Returns the number of columns in the auxiliary trace segment.
Source§

fn validate<A, E>( &self, air: &A, aux_trace_with_metadata: Option<&AuxTraceWithMetadata<E>>, )
where A: Air<BaseField = Self::BaseField>, E: FieldElement<BaseField = Self::BaseField>,

Checks if this trace is valid against the specified AIR, and panics if not. Read more

Auto Trait Implementations§

§

impl<B> Freeze for TraceTable<B>

§

impl<B> RefUnwindSafe for TraceTable<B>
where B: RefUnwindSafe,

§

impl<B> Send for TraceTable<B>

§

impl<B> Sync for TraceTable<B>

§

impl<B> Unpin for TraceTable<B>
where B: Unpin,

§

impl<B> UnwindSafe for TraceTable<B>
where B: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more