sp1_stark/air/machine.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
use p3_air::BaseAir;
use p3_field::Field;
use p3_matrix::dense::RowMajorMatrix;
use crate::MachineRecord;
pub use sp1_derive::MachineAir;
use super::InteractionScope;
/// An AIR that is part of a multi table AIR arithmetization.
pub trait MachineAir<F: Field>: BaseAir<F> + 'static + Send + Sync {
/// The execution record containing events for producing the air trace.
type Record: MachineRecord;
/// The program that defines the control flow of the machine.
type Program: MachineProgram<F>;
/// A unique identifier for this AIR as part of a machine.
fn name(&self) -> String;
/// Generate the trace for a given execution record.
///
/// - `input` is the execution record containing the events to be written to the trace.
/// - `output` is the execution record containing events that the `MachineAir` can add to the
/// record such as byte lookup requests.
fn generate_trace(&self, input: &Self::Record, output: &mut Self::Record) -> RowMajorMatrix<F>;
/// Generate the dependencies for a given execution record.
fn generate_dependencies(&self, input: &Self::Record, output: &mut Self::Record) {
self.generate_trace(input, output);
}
/// Whether this execution record contains events for this air.
fn included(&self, shard: &Self::Record) -> bool;
/// The width of the preprocessed trace.
fn preprocessed_width(&self) -> usize {
0
}
/// Generate the preprocessed trace given a specific program.
fn generate_preprocessed_trace(&self, _program: &Self::Program) -> Option<RowMajorMatrix<F>> {
None
}
/// Specifies whether it's trace should be part of either the global or local commit.
fn commit_scope(&self) -> InteractionScope {
InteractionScope::Local
}
}
/// A program that defines the control flow of a machine through a program counter.
pub trait MachineProgram<F>: Send + Sync {
/// Gets the starting program counter.
fn pc_start(&self) -> F;
}