use super::{
super::trace::AuxColumnBuilder, Felt, FieldElement, OverflowTableRow, OverflowTableUpdate, Vec,
};
use crate::Matrix;
pub struct AuxTraceBuilder {
pub(super) overflow_hints: Vec<(u64, OverflowTableUpdate)>,
pub(super) overflow_table_rows: Vec<OverflowTableRow>,
pub(super) num_init_rows: usize,
pub(super) final_rows: Vec<usize>,
}
impl AuxTraceBuilder {
pub fn build_aux_columns<E: FieldElement<BaseField = Felt>>(
&self,
main_trace: &Matrix<Felt>,
rand_elements: &[E],
) -> Vec<Vec<E>> {
let p1 = self.build_aux_column(main_trace, rand_elements);
vec![p1]
}
}
impl AuxColumnBuilder<OverflowTableUpdate, OverflowTableRow, u64> for AuxTraceBuilder {
fn get_table_rows(&self) -> &[OverflowTableRow] {
&self.overflow_table_rows
}
fn get_table_hints(&self) -> &[(u64, OverflowTableUpdate)] {
&self.overflow_hints[self.num_init_rows..]
}
fn get_multiplicand<E: FieldElement<BaseField = Felt>>(
&self,
hint: OverflowTableUpdate,
row_values: &[E],
inv_row_values: &[E],
) -> E {
match hint {
OverflowTableUpdate::RowInserted(inserted_row_idx) => {
row_values[inserted_row_idx as usize]
}
OverflowTableUpdate::RowRemoved(removed_row_idx) => {
inv_row_values[removed_row_idx as usize]
}
}
}
fn init_column_value<E: FieldElement<BaseField = Felt>>(&self, row_values: &[E]) -> E {
let mut init_column_value = E::ONE;
for (_, hint) in &self.overflow_hints[..self.num_init_rows] {
if let OverflowTableUpdate::RowInserted(row) = hint {
init_column_value *= row_values[*row as usize];
} else {
debug_assert!(
false,
"overflow table row incorrectly removed before execution started"
)
}
}
init_column_value
}
fn final_column_value<E: FieldElement<BaseField = Felt>>(&self, row_values: &[E]) -> E {
let mut final_column_value = E::ONE;
for &row in &self.final_rows {
final_column_value *= row_values[row];
}
final_column_value
}
}