Skip to content

Commit

Permalink
Modify mask_points for interaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 committed Jun 23, 2024
1 parent 3d2728c commit 7443767
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 45 deletions.
17 changes: 13 additions & 4 deletions crates/prover/src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ pub trait AirExt: Air {
fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ComponentVec<Vec<CirclePoint<SecureField>>> {
let mut component_points = ComponentVec(Vec::new());
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>> {
let mut trace_component_points = vec![];
let mut interaction_component_points = vec![];
for component in self.components() {
let points = component.mask_points(point);
component_points.push(points);
trace_component_points.extend(points[0].clone());
interaction_component_points.extend(points[1].clone());
}
component_points
let mut points = TreeVec::new(vec![trace_component_points]);
if !interaction_component_points
.iter()
.all(|column| column.is_empty())
{
points.push(interaction_component_points);
}
points
}

fn eval_composition_polynomial_at_point(
Expand Down
7 changes: 5 additions & 2 deletions crates/prover/src/core/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ pub trait Component {
/// Returns the number of interaction phases done by the component.
fn n_interaction_phases(&self) -> u32;

/// Returns the degree bounds of each trace column.
/// Returns the degree bounds of each trace column. The returned TreeVec should be of size
/// `n_interaction_phases`.
fn trace_log_degree_bounds(&self) -> TreeVec<ColumnVec<u32>>;

/// Returns the mask points for each trace column. The returned TreeVec should be of size
/// `n_interaction_phases`.
fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>>;
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>>;

/// Returns the ids of the interaction elements used by the component.
fn interaction_element_ids(&self) -> Vec<String>;
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod vcs;
pub type ColumnVec<T> = Vec<T>;

/// A vector of [ColumnVec]s. Each [ColumnVec] relates (by index) to a component in the air.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ComponentVec<T>(pub Vec<ColumnVec<T>>);

impl<T> ComponentVec<T> {
Expand Down
42 changes: 14 additions & 28 deletions crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,9 @@ pub fn generate_proof<B: Backend + MerkleOps<MerkleHasher>>(
let oods_point = CirclePoint::<SecureField>::get_random_point(channel);

// Get mask sample points relative to oods point.
let sample_points = air.mask_points(oods_point);
let mut sample_points = air.mask_points(oods_point);

// TODO(spapini): Change when we support multiple interactions.
// First tree - trace.
let mut sample_points = TreeVec::new(vec![sample_points.flatten()]);
if air.n_interaction_phases() == 2 {
// Second tree - interaction trace.
sample_points.push(vec![
vec![oods_point];
commitment_scheme.trees[1].polynomials.len()
]);
}
// Final tree - composition polynomial.
// Get composition polynomial sample points.
sample_points.push(vec![vec![oods_point]; 4]);

// Prove the trace and composition OODS values, and retrieve them.
Expand Down Expand Up @@ -227,17 +217,9 @@ pub fn verify(
let oods_point = CirclePoint::<SecureField>::get_random_point(channel);

// Get mask sample points relative to oods point.
let trace_sample_points = air.mask_points(oods_point);
let mut sample_points = air.mask_points(oods_point);

// TODO(spapini): Change when we support multiple interactions.
// First tree - trace.
let mut sample_points = TreeVec::new(vec![trace_sample_points.flatten()]);
if air.n_interaction_phases() == 2 {
// Second tree - interaction trace.
// TODO(AlonH): Get the number of interaction traces from the air.
sample_points.push(vec![vec![oods_point]; 1]);
}
// Final tree - composition polynomial.
// Get composition polynomial sample points.
sample_points.push(vec![vec![oods_point]; 4]);

// TODO(spapini): Save clone.
Expand Down Expand Up @@ -278,7 +260,7 @@ fn sampled_values_to_mask(
air.components().iter().for_each(|component| {
trace_oods_values.push(
flat_trace_values
.take(component.mask_points(CirclePoint::zero()).len())
.take(component.mask_points(CirclePoint::zero())[0].len())
.cloned()
.collect_vec(),
)
Expand All @@ -293,9 +275,13 @@ fn sampled_values_to_mask(
air.components()
.iter()
.zip_eq(&mut trace_oods_values)
.for_each(|(_component, values)| {
// TODO(AlonH): Implement n_interaction_columns() for component.
values.extend(interaction_values.take(1).cloned().collect_vec())
.for_each(|(component, values)| {
values.extend(
interaction_values
.take(component.mask_points(CirclePoint::zero())[1].len())
.cloned()
.collect_vec(),
)
});
}

Expand Down Expand Up @@ -437,8 +423,8 @@ mod tests {
fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> crate::core::ColumnVec<Vec<CirclePoint<SecureField>>> {
vec![vec![point]]
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>> {
TreeVec::new(vec![vec![vec![point]], vec![]])
}

fn interaction_element_ids(&self) -> Vec<String> {
Expand Down
15 changes: 9 additions & 6 deletions crates/prover/src/examples/fibonacci/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ impl Component for FibonacciComponent {
fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>> {
shifted_mask_points(
&vec![vec![0, 1, 2]],
&[CanonicCoset::new(self.log_size)],
point,
)
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>> {
TreeVec::new(vec![
shifted_mask_points(
&vec![vec![0, 1, 2]],
&[CanonicCoset::new(self.log_size)],
point,
),
vec![],
])
}

fn interaction_element_ids(&self) -> Vec<String> {
Expand Down
7 changes: 5 additions & 2 deletions crates/prover/src/examples/wide_fibonacci/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ impl Component for WideFibComponent {
fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>> {
fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point)
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>> {
TreeVec::new(vec![
fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point),
vec![vec![point]],
])
}

fn interaction_element_ids(&self) -> Vec<String> {
Expand Down
7 changes: 5 additions & 2 deletions crates/prover/src/examples/wide_fibonacci/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ impl Component for SimdWideFibComponent {
fn mask_points(
&self,
point: CirclePoint<SecureField>,
) -> ColumnVec<Vec<CirclePoint<SecureField>>> {
fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point)
) -> TreeVec<ColumnVec<Vec<CirclePoint<SecureField>>>> {
TreeVec::new(vec![
fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point),
vec![],
])
}

fn interaction_element_ids(&self) -> Vec<String> {
Expand Down

0 comments on commit 7443767

Please sign in to comment.