Skip to content

Commit

Permalink
Struct for PreProcessed Columns ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Gali-StarkWare committed Jan 14, 2025
1 parent 8be88da commit e1cc994
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 32 deletions.
12 changes: 6 additions & 6 deletions crates/prover/src/constraint_framework/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tracing::{span, Level};

use super::cpu_domain::CpuDomainEvaluator;
use super::logup::LogupSums;
use super::preprocessed_columns::PreProcessedColumnId;
use super::{
EvalAtRow, InfoEvaluator, PointEvaluator, SimdDomainEvaluator, PREPROCESSED_TRACE_IDX,
};
Expand Down Expand Up @@ -47,8 +48,7 @@ pub struct TraceLocationAllocator {
/// Mapping of tree index to next available column offset.
next_tree_offsets: TreeVec<usize>,
/// Mapping of preprocessed columns to their index.
// TODO(Gali): Change Vec type to struct PreProcessedColumnId {pub id: String}.
preprocessed_columns: Vec<String>,
preprocessed_columns: Vec<PreProcessedColumnId>,
/// Controls whether the preprocessed columns are dynamic or static (default=Dynamic).
preprocessed_columns_allocation_mode: PreprocessedColumnsAllocationMode,
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl TraceLocationAllocator {
}

/// Create a new `TraceLocationAllocator` with fixed preprocessed columns setup.
pub fn new_with_preproccessed_columns(preprocessed_columns: &[String]) -> Self {
pub fn new_with_preproccessed_columns(preprocessed_columns: &[PreProcessedColumnId]) -> Self {
assert!(
preprocessed_columns.iter().all_unique(),
"Duplicate preprocessed columns are not allowed!"
Expand All @@ -92,14 +92,14 @@ impl TraceLocationAllocator {
}
}

pub const fn preprocessed_columns(&self) -> &Vec<String> {
pub const fn preprocessed_columns(&self) -> &Vec<PreProcessedColumnId> {
&self.preprocessed_columns
}

// validates that `self.preprocessed_columns` is consistent with
// `preprocessed_columns`.
// I.e. preprocessed_columns[i] == self.preprocessed_columns[i].
pub fn validate_preprocessed_columns(&self, preprocessed_columns: &[String]) {
pub fn validate_preprocessed_columns(&self, preprocessed_columns: &[PreProcessedColumnId]) {
assert_eq!(self.preprocessed_columns, preprocessed_columns);
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ impl<E: FrameworkEval> FrameworkComponent<E> {
if let Some(pos) = location_allocator
.preprocessed_columns
.iter()
.position(|x| x == col)
.position(|x| x.id == col.id)
{
pos
} else {
Expand Down
5 changes: 3 additions & 2 deletions crates/prover/src/constraint_framework/expr/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use num_traits::Zero;

use super::{BaseExpr, ExtExpr};
use crate::constraint_framework::expr::ColumnExpr;
use crate::constraint_framework::preprocessed_columns::PreProcessedColumnId;
use crate::constraint_framework::{EvalAtRow, Relation, RelationEntry, INTERACTION_TRACE_IDX};
use crate::core::fields::m31;
use crate::core::lookups::utils::Fraction;
Expand Down Expand Up @@ -173,8 +174,8 @@ impl EvalAtRow for ExprEvaluator {
intermediate
}

fn get_preprocessed_column(&mut self, column: String) -> Self::F {
BaseExpr::Param(column)
fn get_preprocessed_column(&mut self, column: PreProcessedColumnId) -> Self::F {
BaseExpr::Param(column.id)
}

crate::constraint_framework::logup_proxy!();
Expand Down
12 changes: 8 additions & 4 deletions crates/prover/src/constraint_framework/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::rc::Rc;
use num_traits::{One, Zero};

use super::logup::{LogupAtRow, LogupSums};
use super::preprocessed_columns::PreProcessedColumnId;
use super::{EvalAtRow, INTERACTION_TRACE_IDX};
use crate::constraint_framework::PREPROCESSED_TRACE_IDX;
use crate::core::fields::m31::BaseField;
Expand All @@ -21,13 +22,16 @@ use crate::core::pcs::TreeVec;
pub struct InfoEvaluator {
pub mask_offsets: TreeVec<Vec<Vec<isize>>>,
pub n_constraints: usize,
// TODO(Gali): Change Vec type to struct PreProcessedColumnId {pub id: String}.
pub preprocessed_columns: Vec<String>,
pub preprocessed_columns: Vec<PreProcessedColumnId>,
pub logup: LogupAtRow<Self>,
pub arithmetic_counts: ArithmeticCounts,
}
impl InfoEvaluator {
pub fn new(log_size: u32, preprocessed_columns: Vec<String>, logup_sums: LogupSums) -> Self {
pub fn new(
log_size: u32,
preprocessed_columns: Vec<PreProcessedColumnId>,
logup_sums: LogupSums,
) -> Self {
Self {
mask_offsets: Default::default(),
n_constraints: Default::default(),
Expand Down Expand Up @@ -66,7 +70,7 @@ impl EvalAtRow for InfoEvaluator {
array::from_fn(|_| FieldCounter::one())
}

fn get_preprocessed_column(&mut self, column: String) -> Self::F {
fn get_preprocessed_column(&mut self, column: PreProcessedColumnId) -> Self::F {
self.preprocessed_columns.push(column);
FieldCounter::one()
}
Expand Down
3 changes: 2 additions & 1 deletion crates/prover/src/constraint_framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use component::{FrameworkComponent, FrameworkEval, TraceLocationAllocator};
pub use info::InfoEvaluator;
use num_traits::{One, Zero};
pub use point::PointEvaluator;
use preprocessed_columns::PreProcessedColumnId;
pub use simd_domain::SimdDomainEvaluator;

use crate::core::fields::m31::BaseField;
Expand Down Expand Up @@ -86,7 +87,7 @@ pub trait EvalAtRow {
mask_item
}

fn get_preprocessed_column(&mut self, _column: String) -> Self::F {
fn get_preprocessed_column(&mut self, _column: PreProcessedColumnId) -> Self::F {
let [mask_item] = self.next_interaction_mask(PREPROCESSED_TRACE_IDX, [0]);
mask_item
}
Expand Down
13 changes: 11 additions & 2 deletions crates/prover/src/constraint_framework/preprocessed_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ use crate::core::fields::m31::BaseField;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation};
use crate::core::poly::BitReversedOrder;

/// Used for comparing preprocessed columns.
/// Column IDs must be unique in a given context.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PreProcessedColumnId {
pub id: String,
}

/// A column with `1` at the first position, and `0` elsewhere.
#[derive(Debug, Clone)]
pub struct IsFirst {
Expand Down Expand Up @@ -42,8 +49,10 @@ impl IsFirst {
CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), col)
}

pub fn id(&self) -> String {
format!("preprocessed_is_first_{}", self.log_size).to_string()
pub fn id(&self) -> PreProcessedColumnId {
PreProcessedColumnId {
id: format!("preprocessed_is_first_{}", self.log_size).to_string(),
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/prover/src/examples/blake/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::preprocessed_columns::XorTable;
use super::round::{blake_round_info, BlakeRoundComponent, BlakeRoundEval};
use super::scheduler::{BlakeSchedulerComponent, BlakeSchedulerEval};
use super::xor_table::{xor12, xor4, xor7, xor8, xor9};
use crate::constraint_framework::preprocessed_columns::IsFirst;
use crate::constraint_framework::preprocessed_columns::{IsFirst, PreProcessedColumnId};
use crate::constraint_framework::{TraceLocationAllocator, PREPROCESSED_TRACE_IDX};
use crate::core::air::{Component, ComponentProver};
use crate::core::backend::simd::m31::LOG_N_LANES;
Expand All @@ -27,7 +27,7 @@ use crate::examples::blake::{
round, xor_table, BlakeXorElements, XorAccums, N_ROUNDS, ROUND_LOG_SPLIT,
};

fn preprocessed_xor_columns() -> [String; 20] {
fn preprocessed_xor_columns() -> [PreProcessedColumnId; 20] {
[
XorTable::new(12, 4, 0).id(),
XorTable::new(12, 4, 1).id(),
Expand Down Expand Up @@ -188,7 +188,7 @@ impl BlakeComponents {
let log_size = stmt0.log_size;

let scheduler_is_first_column = IsFirst::new(log_size).id();
let blake_round_is_first_columns_iter: Vec<String> = ROUND_LOG_SPLIT
let blake_round_is_first_columns_iter: Vec<PreProcessedColumnId> = ROUND_LOG_SPLIT
.iter()
.map(|l| IsFirst::new(log_size + l).id())
.collect_vec();
Expand Down
14 changes: 8 additions & 6 deletions crates/prover/src/examples/blake/preprocessed_columns.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tracing::{span, Level};

use crate::constraint_framework::preprocessed_columns::IsFirst;
use crate::constraint_framework::preprocessed_columns::{IsFirst, PreProcessedColumnId};
use crate::core::backend::simd::column::BaseColumn;
use crate::core::backend::simd::SimdBackend;
use crate::core::fields::m31::BaseField;
Expand All @@ -24,11 +24,13 @@ impl XorTable {
}
}

pub fn id(&self) -> String {
format!(
"preprocessed_xor_table_{}_{}_{}",
self.n_bits, self.n_expand_bits, self.index_in_table
)
pub fn id(&self) -> PreProcessedColumnId {
PreProcessedColumnId {
id: format!(
"preprocessed_xor_table_{}_{}_{}",
self.n_bits, self.n_expand_bits, self.index_in_table
),
}
}

pub const fn limb_bits(&self) -> u32 {
Expand Down
8 changes: 5 additions & 3 deletions crates/prover/src/examples/plonk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use num_traits::One;
use tracing::{span, Level};

use crate::constraint_framework::logup::{ClaimedPrefixSum, LogupTraceGenerator, LookupElements};
use crate::constraint_framework::preprocessed_columns::IsFirst;
use crate::constraint_framework::preprocessed_columns::{IsFirst, PreProcessedColumnId};
use crate::constraint_framework::{
assert_constraints, relation, EvalAtRow, FrameworkComponent, FrameworkEval, RelationEntry,
TraceLocationAllocator,
Expand Down Expand Up @@ -280,8 +280,10 @@ impl Plonk {
Self { name }
}

pub fn id(&self) -> String {
format!("preprocessed_plonk_{}", self.name)
pub fn id(&self) -> PreProcessedColumnId {
PreProcessedColumnId {
id: format!("preprocessed_plonk_{}", self.name),
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use num_traits::One;

use crate::constraint_framework::preprocessed_columns::PreProcessedColumnId;
use crate::core::backend::simd::SimdBackend;
use crate::core::backend::{Col, Column};
use crate::core::fields::m31::BaseField;
Expand Down Expand Up @@ -38,10 +39,12 @@ impl IsStepWithOffset {
CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), col)
}

pub fn id(&self) -> String {
format!(
"preprocessed_is_step_with_offset_{}_{}_{}",
self.log_size, self.log_step, self.offset
)
pub fn id(&self) -> PreProcessedColumnId {
PreProcessedColumnId {
id: format!(
"preprocessed_is_step_with_offset_{}_{}_{}",
self.log_size, self.log_step, self.offset
),
}
}
}

0 comments on commit e1cc994

Please sign in to comment.