Skip to content

Commit

Permalink
chore: Use “main” & “aux over “base” & “ext”
Browse files Browse the repository at this point in the history
This completes the transition started in 07fdf15.

changelog: ignore
  • Loading branch information
jan-ferdinand committed Sep 12, 2024
1 parent f9139c4 commit b842ec5
Show file tree
Hide file tree
Showing 18 changed files with 630 additions and 633 deletions.
60 changes: 30 additions & 30 deletions triton-air/src/table/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3190,8 +3190,8 @@ mod tests {
fn instruction_deselector_gives_0_for_all_other_instructions() {
let circuit_builder = ConstraintCircuitBuilder::new();

let mut master_base_table = Array2::zeros([2, NUM_MAIN_COLUMNS]);
let master_ext_table = Array2::zeros([2, NUM_AUX_COLUMNS]);
let mut master_main_table = Array2::zeros([2, NUM_MAIN_COLUMNS]);
let master_aux_table = Array2::zeros([2, NUM_AUX_COLUMNS]);

// For this test, dummy challenges suffice to evaluate the constraints.
let dummy_challenges = (0..ChallengeId::COUNT)
Expand All @@ -3208,7 +3208,7 @@ mod tests {
.into_iter()
.filter(|other_instruction| *other_instruction != instruction)
{
let mut curr_row = master_base_table.slice_mut(s![0, ..]);
let mut curr_row = master_main_table.slice_mut(s![0, ..]);
curr_row[IB0.master_main_index()] = other_instruction.ib(InstructionBit::IB0);
curr_row[IB1.master_main_index()] = other_instruction.ib(InstructionBit::IB1);
curr_row[IB2.master_main_index()] = other_instruction.ib(InstructionBit::IB2);
Expand All @@ -3217,8 +3217,8 @@ mod tests {
curr_row[IB5.master_main_index()] = other_instruction.ib(InstructionBit::IB5);
curr_row[IB6.master_main_index()] = other_instruction.ib(InstructionBit::IB6);
let result = deselector.clone().consume().evaluate(
master_base_table.view(),
master_ext_table.view(),
master_main_table.view(),
master_aux_table.view(),
&dummy_challenges,
);

Expand All @@ -3231,7 +3231,7 @@ mod tests {
}

// Positive tests
let mut curr_row = master_base_table.slice_mut(s![0, ..]);
let mut curr_row = master_main_table.slice_mut(s![0, ..]);
curr_row[IB0.master_main_index()] = instruction.ib(InstructionBit::IB0);
curr_row[IB1.master_main_index()] = instruction.ib(InstructionBit::IB1);
curr_row[IB2.master_main_index()] = instruction.ib(InstructionBit::IB2);
Expand All @@ -3240,8 +3240,8 @@ mod tests {
curr_row[IB5.master_main_index()] = instruction.ib(InstructionBit::IB5);
curr_row[IB6.master_main_index()] = instruction.ib(InstructionBit::IB6);
let result = deselector.consume().evaluate(
master_base_table.view(),
master_ext_table.view(),
master_main_table.view(),
master_aux_table.view(),
&dummy_challenges,
);
assert!(
Expand Down Expand Up @@ -3328,17 +3328,17 @@ mod tests {
#[strategy(0_usize..16)] indicator_poly_index: usize,
#[strategy(0_u64..16)] query_index: u64,
) {
let mut base_table = Array2::ones([2, NUM_MAIN_COLUMNS]);
let mut main_table = Array2::ones([2, NUM_MAIN_COLUMNS]);
let aux_table = Array2::ones([2, NUM_AUX_COLUMNS]);

base_table[[0, HV0.master_main_index()]] = bfe!(query_index % 2);
base_table[[0, HV1.master_main_index()]] = bfe!((query_index >> 1) % 2);
base_table[[0, HV2.master_main_index()]] = bfe!((query_index >> 2) % 2);
base_table[[0, HV3.master_main_index()]] = bfe!((query_index >> 3) % 2);
main_table[[0, HV0.master_main_index()]] = bfe!(query_index % 2);
main_table[[0, HV1.master_main_index()]] = bfe!((query_index >> 1) % 2);
main_table[[0, HV2.master_main_index()]] = bfe!((query_index >> 2) % 2);
main_table[[0, HV3.master_main_index()]] = bfe!((query_index >> 3) % 2);

let builder = ConstraintCircuitBuilder::new();
let indicator_poly = indicator_polynomial(&builder, indicator_poly_index).consume();
let evaluation = indicator_poly.evaluate(base_table.view(), aux_table.view(), &[]);
let evaluation = indicator_poly.evaluate(main_table.view(), aux_table.view(), &[]);

if indicator_poly_index as u64 == query_index {
prop_assert_eq!(xfe!(1), evaluation);
Expand Down Expand Up @@ -3387,18 +3387,18 @@ mod tests {
|col: ProcessorMainColumn| circuit_builder.input(Main(col.master_main_index()));
let [x0, x1, x2, y0, y1, y2] = [ST0, ST1, ST2, ST3, ST4, ST5].map(main_row);

let mut base_table = Array2::zeros([1, NUM_MAIN_COLUMNS]);
let ext_table = Array2::zeros([1, NUM_AUX_COLUMNS]);
base_table[[0, ST0.master_main_index()]] = a.coefficients[0];
base_table[[0, ST1.master_main_index()]] = a.coefficients[1];
base_table[[0, ST2.master_main_index()]] = a.coefficients[2];
base_table[[0, ST3.master_main_index()]] = b.coefficients[0];
base_table[[0, ST4.master_main_index()]] = b.coefficients[1];
base_table[[0, ST5.master_main_index()]] = b.coefficients[2];
let mut main_table = Array2::zeros([1, NUM_MAIN_COLUMNS]);
let aux_table = Array2::zeros([1, NUM_AUX_COLUMNS]);
main_table[[0, ST0.master_main_index()]] = a.coefficients[0];
main_table[[0, ST1.master_main_index()]] = a.coefficients[1];
main_table[[0, ST2.master_main_index()]] = a.coefficients[2];
main_table[[0, ST3.master_main_index()]] = b.coefficients[0];
main_table[[0, ST4.master_main_index()]] = b.coefficients[1];
main_table[[0, ST5.master_main_index()]] = b.coefficients[2];

let [c0, c1, c2] = xx_product([x0, x1, x2], [y0, y1, y2])
.map(|c| c.consume())
.map(|c| c.evaluate(base_table.view(), ext_table.view(), &[]))
.map(|c| c.evaluate(main_table.view(), aux_table.view(), &[]))
.map(|xfe| xfe.unlift().unwrap());

let c = a * b;
Expand All @@ -3417,16 +3417,16 @@ mod tests {
|col: ProcessorMainColumn| circuit_builder.input(Main(col.master_main_index()));
let [x0, x1, x2, y] = [ST0, ST1, ST2, ST3].map(main_row);

let mut base_table = Array2::zeros([1, NUM_MAIN_COLUMNS]);
let ext_table = Array2::zeros([1, NUM_AUX_COLUMNS]);
base_table[[0, ST0.master_main_index()]] = a.coefficients[0];
base_table[[0, ST1.master_main_index()]] = a.coefficients[1];
base_table[[0, ST2.master_main_index()]] = a.coefficients[2];
base_table[[0, ST3.master_main_index()]] = b;
let mut main_table = Array2::zeros([1, NUM_MAIN_COLUMNS]);
let aux_table = Array2::zeros([1, NUM_AUX_COLUMNS]);
main_table[[0, ST0.master_main_index()]] = a.coefficients[0];
main_table[[0, ST1.master_main_index()]] = a.coefficients[1];
main_table[[0, ST2.master_main_index()]] = a.coefficients[2];
main_table[[0, ST3.master_main_index()]] = b;

let [c0, c1, c2] = xb_product([x0, x1, x2], y)
.map(|c| c.consume())
.map(|c| c.evaluate(base_table.view(), ext_table.view(), &[]))
.map(|c| c.evaluate(main_table.view(), aux_table.view(), &[]))
.map(|xfe| xfe.unlift().unwrap());

let c = a * b;
Expand Down
30 changes: 15 additions & 15 deletions triton-air/src/table_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,16 @@ pub enum U32AuxColumn {
LookupServerLogDerivative,
}

/// A trait for the columns of the master base table. This trait is implemented for all enums
/// relating to the base tables. This trait provides two methods:
/// - one to get the index of the column in the “local” base table, _i.e., not the master base
/// A trait for the columns of the master main table. This trait is implemented for all enums
/// relating to the main tables. This trait provides two methods:
/// - one to get the index of the column in the “local” main table, _i.e., not the master base
/// table, and
/// - one to get the index of the column in the master base table.
/// - one to get the index of the column in the master main table.
pub trait MasterMainColumn {
/// The index of the column in the “local” base table, _i.e., not the master base table.
/// The index of the column in the “local” main table, _i.e., not the master base table.
fn main_index(&self) -> usize;

/// The index of the column in the master base table.
/// The index of the column in the master main table.
fn master_main_index(&self) -> usize;
}

Expand Down Expand Up @@ -604,17 +604,17 @@ impl MasterMainColumn for U32MainColumn {
}
}

/// A trait for the columns in the master extension table. This trait is implemented for all enums
/// relating to the extension tables. The trait provides two methods:
/// - one to get the index of the column in the “local” extension table, _i.e._, not the master
/// extension table, and
/// - one to get the index of the column in the master extension table.
/// A trait for the columns in the master auxiliary table. This trait is implemented for all enums
/// relating to the auxiliary tables. The trait provides two methods:
/// - one to get the index of the column in the “local” auxiliary table, _i.e._, not the master
/// auxiliary table, and
/// - one to get the index of the column in the master auxiliary table.
pub trait MasterAuxColumn {
/// The index of the column in the “local” extension table, _i.e._, not the master extension
/// The index of the column in the “local” auxiliary table, _i.e._, not the master extension
/// table.
fn aux_index(&self) -> usize;

/// The index of the column in the master extension table.
/// The index of the column in the master auxiliary table.
fn master_aux_index(&self) -> usize;
}

Expand Down Expand Up @@ -733,7 +733,7 @@ mod tests {
use super::*;

#[test]
fn master_base_table_is_contiguous() {
fn master_main_table_is_contiguous() {
let mut expected_column_index = 0;
for column in ProgramMainColumn::iter() {
assert_eq!(expected_column_index, column.master_main_index());
Expand Down Expand Up @@ -774,7 +774,7 @@ mod tests {
}

#[test]
fn master_ext_table_is_contiguous() {
fn master_aux_table_is_contiguous() {
let mut expected_column_index = 0;
for column in ProgramAuxColumn::iter() {
assert_eq!(expected_column_index, column.master_aux_index());
Expand Down
42 changes: 21 additions & 21 deletions triton-constraint-builder/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ impl RustBackend {
/// well as their degrees. In particular:
/// 1. The first stream contains code that, when evaluated, produces the constraints' degrees,
/// 1. the second stream contains code that, when evaluated, produces the constraints' values,
/// with the input type for the base row being `BFieldElement`, and
/// 1. the third stream is like the second, except that the input type for the base row is
/// with the input type for the main row being `BFieldElement`, and
/// 1. the third stream is like the second, except that the input type for the main row is
/// `XFieldElement`.
fn tokenize_circuits<II: InputIndicator>(
constraints: &[ConstraintCircuit<II>],
Expand All @@ -210,7 +210,7 @@ impl RustBackend {
.partition(|constraint| constraint.evaluates_to_base_element());

// The order of the constraints' degrees must match the order of the constraints.
// Hence, listing the degrees is only possible after the partition into base and extension
// Hence, listing the degrees is only possible after the partition into main and auxiliary
// constraints is known.
let tokenized_degree_bounds = main_constraints
.iter()
Expand All @@ -232,7 +232,7 @@ impl RustBackend {
let tokenized_main_constraints = tokenize_constraint_evaluation(&main_constraints);
let tokenized_aux_constraints = tokenize_constraint_evaluation(&aux_constraints);

// If there are no base constraints, the type needs to be explicitly declared.
// If there are no main constraints, the type needs to be explicitly declared.
let tokenized_bfe_main_constraints = match main_constraints.is_empty() {
true => quote!(let main_constraints: [BFieldElement; 0] = []),
false => quote!(let main_constraints = [#(#tokenized_main_constraints),*]),
Expand Down Expand Up @@ -652,10 +652,10 @@ impl TasmBackend {
};

[
IOList::NextExtRow,
IOList::NextBaseRow,
IOList::CurrExtRow,
IOList::CurrBaseRow,
IOList::NextAuxRow,
IOList::NextMainRow,
IOList::CurrAuxRow,
IOList::CurrMainRow,
]
.into_iter()
.flat_map(write_pointer_to_ram)
Expand All @@ -669,7 +669,7 @@ impl TasmBackend {
self.scope = HashSet::new();
let store_shared_nodes = self.store_all_shared_nodes(constraints);

// to match the `RustBackend`, base constraints must be emitted first
// to match the `RustBackend`, main constraints must be emitted first
let (main_constraints, aux_constraints): (Vec<_>, Vec<_>) = constraints
.iter()
.partition(|constraint| constraint.evaluates_to_base_element());
Expand Down Expand Up @@ -780,10 +780,10 @@ impl TasmBackend {

fn load_input<II: InputIndicator>(&self, input: II) -> Vec<TokenStream> {
let list = match (input.is_current_row(), input.is_main_table_column()) {
(true, true) => IOList::CurrBaseRow,
(true, false) => IOList::CurrExtRow,
(false, true) => IOList::NextBaseRow,
(false, false) => IOList::NextExtRow,
(true, true) => IOList::CurrMainRow,
(true, false) => IOList::CurrAuxRow,
(false, true) => IOList::NextMainRow,
(false, false) => IOList::NextAuxRow,
};
if self.input_location_is_static {
Self::load_ext_field_element_from_list(list, input.column())
Expand Down Expand Up @@ -859,21 +859,21 @@ impl TasmBackend {
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
enum IOList {
FreeMemPage,
CurrBaseRow,
CurrExtRow,
NextBaseRow,
NextExtRow,
CurrMainRow,
CurrAuxRow,
NextMainRow,
NextAuxRow,
Challenges,
}

impl ToTokens for IOList {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
IOList::FreeMemPage => tokens.extend(quote!(free_mem_page_ptr)),
IOList::CurrBaseRow => tokens.extend(quote!(curr_main_row_ptr)),
IOList::CurrExtRow => tokens.extend(quote!(curr_aux_row_ptr)),
IOList::NextBaseRow => tokens.extend(quote!(next_main_row_ptr)),
IOList::NextExtRow => tokens.extend(quote!(next_aux_row_ptr)),
IOList::CurrMainRow => tokens.extend(quote!(curr_main_row_ptr)),
IOList::CurrAuxRow => tokens.extend(quote!(curr_aux_row_ptr)),
IOList::NextMainRow => tokens.extend(quote!(next_main_row_ptr)),
IOList::NextAuxRow => tokens.extend(quote!(next_aux_row_ptr)),
IOList::Challenges => tokens.extend(quote!(challenges_ptr)),
}
}
Expand Down
49 changes: 23 additions & 26 deletions triton-constraint-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,55 +143,52 @@ impl Constraints {
) -> AllSubstitutions {
let mut info = lowering_info;

let (init_base_substitutions, init_ext_substitutions) =
let (init_main_substitutions, init_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut self.init, info);
info.num_main_cols += init_base_substitutions.len();
info.num_aux_cols += init_ext_substitutions.len();
info.num_main_cols += init_main_substitutions.len();
info.num_aux_cols += init_aux_substitutions.len();

let (cons_base_substitutions, cons_ext_substitutions) =
let (cons_main_substitutions, cons_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut self.cons, info);
info.num_main_cols += cons_base_substitutions.len();
info.num_aux_cols += cons_ext_substitutions.len();
info.num_main_cols += cons_main_substitutions.len();
info.num_aux_cols += cons_aux_substitutions.len();

let (tran_base_substitutions, tran_ext_substitutions) =
let (tran_main_substitutions, tran_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut self.tran, info);
info.num_main_cols += tran_base_substitutions.len();
info.num_aux_cols += tran_ext_substitutions.len();
info.num_main_cols += tran_main_substitutions.len();
info.num_aux_cols += tran_aux_substitutions.len();

let (term_base_substitutions, term_ext_substitutions) =
let (term_main_substitutions, term_aux_substitutions) =
ConstraintCircuitMonad::lower_to_degree(&mut self.term, info);

AllSubstitutions {
main: Substitutions {
lowering_info,
init: init_base_substitutions,
cons: cons_base_substitutions,
tran: tran_base_substitutions,
term: term_base_substitutions,
init: init_main_substitutions,
cons: cons_main_substitutions,
tran: tran_main_substitutions,
term: term_main_substitutions,
},
aux: Substitutions {
lowering_info,
init: init_ext_substitutions,
cons: cons_ext_substitutions,
tran: tran_ext_substitutions,
term: term_ext_substitutions,
init: init_aux_substitutions,
cons: cons_aux_substitutions,
tran: tran_aux_substitutions,
term: term_aux_substitutions,
},
}
}

#[must_use]
pub fn combine_with_substitution_induced_constraints(
self,
AllSubstitutions {
main: base,
aux: ext,
}: AllSubstitutions,
AllSubstitutions { main, aux }: AllSubstitutions,
) -> Self {
Self {
init: [self.init, base.init, ext.init].concat(),
cons: [self.cons, base.cons, ext.cons].concat(),
tran: [self.tran, base.tran, ext.tran].concat(),
term: [self.term, base.term, ext.term].concat(),
init: [self.init, main.init, aux.init].concat(),
cons: [self.cons, main.cons, aux.cons].concat(),
tran: [self.tran, main.tran, aux.tran].concat(),
term: [self.term, main.term, aux.term].concat(),
}
}

Expand Down
Loading

0 comments on commit b842ec5

Please sign in to comment.