Skip to content

Commit

Permalink
is_first constant column
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Jul 8, 2024
1 parent 17a80c7 commit 890ee4c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
12 changes: 12 additions & 0 deletions crates/prover/src/builder/constant_cols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use num_traits::One;

use crate::core::backend::{Backend, Col, Column};
use crate::core::fields::m31::BaseField;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation};
use crate::core::poly::BitReversedOrder;

pub fn gen_is_first<B: Backend>(log_size: u32) -> CircleEvaluation<B, BaseField, BitReversedOrder> {
let mut col = Col::<B, BaseField>::zeros(1 << log_size);
col.set(0, BaseField::one());
CircleEvaluation::new(CanonicCoset::new(log_size).circle_domain(), col)
}
1 change: 1 addition & 0 deletions crates/prover/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod assert;
pub mod constant_cols;
mod domain;
mod info;
mod point;
Expand Down
3 changes: 3 additions & 0 deletions crates/prover/src/core/backend/cpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ impl<T: Debug + Clone + Default> Column<T> for Vec<T> {
fn at(&self, index: usize) -> T {
self[index].clone()
}
fn set(&mut self, index: usize, value: T) {
self[index] = value;
}
}

pub type CpuCirclePoly = CirclePoly<CpuBackend>;
Expand Down
2 changes: 2 additions & 0 deletions crates/prover/src/core/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ pub trait Column<T>: Clone + Debug + FromIterator<T> {
}
/// Retrieves the element at the given index.
fn at(&self, index: usize) -> T;
/// Sets the element at the given index.
fn set(&mut self, index: usize, value: T);
}
12 changes: 12 additions & 0 deletions crates/prover/src/core/backend/simd/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ impl Column<BaseField> for BaseFieldVec {
fn at(&self, index: usize) -> BaseField {
self.data[index / N_LANES].to_array()[index % N_LANES]
}

fn set(&mut self, index: usize, value: BaseField) {
let mut packed = self.data[index / N_LANES].to_array();
packed[index % N_LANES] = value;
self.data[index / N_LANES] = PackedBaseField::from_array(packed)
}
}

impl FromIterator<BaseField> for BaseFieldVec {
Expand Down Expand Up @@ -124,6 +130,12 @@ impl Column<SecureField> for SecureFieldVec {
fn at(&self, index: usize) -> SecureField {
self.data[index / N_LANES].to_array()[index % N_LANES]
}

fn set(&mut self, index: usize, value: SecureField) {
let mut packed = self.data[index / N_LANES].to_array();
packed[index % N_LANES] = value;
self.data[index / N_LANES] = PackedSecureField::from_array(packed)
}
}

impl FromIterator<SecureField> for SecureFieldVec {
Expand Down
17 changes: 13 additions & 4 deletions crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ impl Component for PoseidonComponent {
&self,
point: CirclePoint<SecureField>,
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>> {
TreeVec::new(vec![fixed_mask_points(
&vec![vec![0_usize]; N_COLUMNS],
point,
)])
TreeVec::new(vec![
fixed_mask_points(&vec![vec![0_usize]; N_COLUMNS], point),
vec![vec![point]],
])
}

fn interaction_element_ids(&self) -> Vec<String> {
Expand Down Expand Up @@ -414,6 +414,7 @@ mod tests {
use tracing::{span, Level};

use super::N_LOG_INSTANCES_PER_ROW;
use crate::builder::constant_cols::gen_is_first;
use crate::core::air::AirExt;
use crate::core::backend::simd::SimdBackend;
use crate::core::channel::{Blake2sChannel, Channel};
Expand Down Expand Up @@ -503,6 +504,11 @@ mod tests {
commitment_scheme.commit_on_evals(trace, channel, &twiddles);
span.exit();

// Constant trace.
let span = span!(Level::INFO, "Constant").entered();
commitment_scheme.commit_on_evals(vec![gen_is_first(log_n_rows)], channel, &twiddles);
span.exit();

// Prove constraints.
let component = PoseidonComponent { log_n_rows };
let air = PoseidonAir { component };
Expand All @@ -521,7 +527,10 @@ mod tests {

// Decommit.
let sizes = air.column_log_sizes();
// Trace columns.
commitment_scheme.commit(proof.commitments[0], &sizes[0], channel);
// Constant columns.
commitment_scheme.commit(proof.commitments[1], &[log_n_rows], channel);

verify_without_commit(
&air,
Expand Down

0 comments on commit 890ee4c

Please sign in to comment.