Skip to content

Commit

Permalink
Component mask_points api (#567)
Browse files Browse the repository at this point in the history
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/stwo/567)
<!-- Reviewable:end -->
  • Loading branch information
shaharsamocha7 authored Apr 4, 2024
2 parents 42e6cf6 + 9f74d86 commit 950abfe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
16 changes: 6 additions & 10 deletions src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ pub trait AirExt<B: Backend>: Air<B> {
&self,
point: CirclePoint<SecureField>,
) -> ComponentVec<Vec<CirclePoint<SecureField>>> {
let mut points = ComponentVec(Vec::new());
self.components().iter().for_each(|component| {
let domains = component
.trace_log_degree_bounds()
.iter()
.map(|&log_size| CanonicCoset::new(log_size))
.collect_vec();
points.push(component.mask().to_points(&domains, point));
});
points
let mut component_points = ComponentVec(Vec::new());
for component in self.components() {
let points = component.mask_points(point);
component_points.push(points);
}
component_points
}

fn eval_composition_polynomial_at_point(
Expand Down
14 changes: 6 additions & 8 deletions src/core/air/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::iter::zip;
use std::ops::Deref;

use itertools::Itertools;

use self::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator};
use super::backend::Backend;
use super::circle::CirclePoint;
Expand Down Expand Up @@ -76,6 +74,11 @@ pub trait Component<B: Backend> {

fn mask(&self) -> Mask;

fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>>;

/// Calculates the mask points and evaluates them at each column.
/// The mask values are used to evaluate the composition polynomial at a certain point.
/// Returns two vectors with an entry for each column. Each entry holds the points/values
Expand All @@ -88,12 +91,7 @@ pub trait Component<B: Backend> {
ColumnVec<Vec<CirclePoint<SecureField>>>,
ColumnVec<Vec<SecureField>>,
) {
let domains = trace
.columns
.iter()
.map(|col| CanonicCoset::new(col.log_size()))
.collect_vec();
let points = self.mask().to_points(&domains, point);
let points = self.mask_points(point);
let values = zip(&points, &trace.columns)
.map(|(col_points, col)| {
col_points
Expand Down
7 changes: 7 additions & 0 deletions src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ mod tests {
Mask(vec![vec![0]])
}

fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> crate::core::ColumnVec<Vec<CirclePoint<SecureField>>> {
vec![vec![point]]
}

fn evaluate_constraint_quotients_at_point(
&self,
_point: CirclePoint<SecureField>,
Expand Down
8 changes: 8 additions & 0 deletions src/examples/fibonacci/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ impl Component<CPUBackend> for FibonacciComponent {
Mask(vec![vec![0, 1, 2]])
}

fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>> {
self.mask()
.to_points(&[CanonicCoset::new(self.log_size)], point)
}

fn evaluate_constraint_quotients_at_point(
&self,
point: CirclePoint<SecureField>,
Expand Down
10 changes: 10 additions & 0 deletions src/examples/wide_fibonacci/constraint_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ impl Component<CPUBackend> for WideFibComponent {
Mask(vec![vec![0_usize]; 256])
}

fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>> {
self.mask()
.iter()
.map(|col| col.iter().map(|_| point).collect())
.collect()
}

// TODO(ShaharS), precompute random coeff powers.
// TODO(ShaharS), use intermidiate value to save the computation of the squares.
fn evaluate_constraint_quotients_on_domain(
Expand Down

0 comments on commit 950abfe

Please sign in to comment.