From 7c247f487fcfc09fb21706e3386e2c94aa0a0e57 Mon Sep 17 00:00:00 2001 From: Alon Haramati Date: Tue, 21 May 2024 17:21:35 +0300 Subject: [PATCH] Modify mask_points for interaction. --- crates/prover/src/core/air/air_ext.rs | 17 ++++++-- crates/prover/src/core/air/mod.rs | 2 +- crates/prover/src/core/mod.rs | 2 +- crates/prover/src/core/prover/mod.rs | 43 +++++++------------ .../src/examples/fibonacci/component.rs | 15 ++++--- .../src/examples/wide_fibonacci/component.rs | 7 ++- .../src/examples/wide_fibonacci/simd.rs | 7 ++- 7 files changed, 49 insertions(+), 44 deletions(-) diff --git a/crates/prover/src/core/air/air_ext.rs b/crates/prover/src/core/air/air_ext.rs index 6e42b3d2f..c77480e6e 100644 --- a/crates/prover/src/core/air/air_ext.rs +++ b/crates/prover/src/core/air/air_ext.rs @@ -28,13 +28,22 @@ pub trait AirExt: Air { fn mask_points( &self, point: CirclePoint, - ) -> ComponentVec>> { - let mut component_points = ComponentVec(Vec::new()); + ) -> TreeVec>>> { + 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 interaction_elements(&self, channel: &mut Blake2sChannel) -> InteractionElements { diff --git a/crates/prover/src/core/air/mod.rs b/crates/prover/src/core/air/mod.rs index 177d3105e..a52d7dcb5 100644 --- a/crates/prover/src/core/air/mod.rs +++ b/crates/prover/src/core/air/mod.rs @@ -40,7 +40,7 @@ pub trait Component { fn mask_points( &self, point: CirclePoint, - ) -> ColumnVec>>; + ) -> TreeVec>>>; /// Returns the ids of the interaction elements used by the component. fn interaction_element_ids(&self) -> Vec; diff --git a/crates/prover/src/core/mod.rs b/crates/prover/src/core/mod.rs index 28fbab5de..0c21afdae 100644 --- a/crates/prover/src/core/mod.rs +++ b/crates/prover/src/core/mod.rs @@ -26,7 +26,7 @@ pub mod vcs; pub type ColumnVec = Vec; /// A vector of [ColumnVec]s. Each [ColumnVec] relates (by index) to a component in the air. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ComponentVec(pub Vec>); impl ComponentVec { diff --git a/crates/prover/src/core/prover/mod.rs b/crates/prover/src/core/prover/mod.rs index 33c282cbe..b3c14a72f 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -113,19 +113,9 @@ pub fn generate_proof>( let oods_point = CirclePoint::::get_random_point(channel); // Get mask sample points relative to oods point. - let 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 commitment_scheme.trees.len() > 2 { - // Second tree - interaction trace. - sample_points.push(vec![ - vec![oods_point]; - commitment_scheme.trees[1].polynomials.len() - ]); - } - // Final tree - composition polynomial. + let mut sample_points = air.mask_points(oods_point); + + // Get composition polynomial sample points. sample_points.push(vec![vec![oods_point]; 4]); // Prove the trace and composition OODS values, and retrieve them. @@ -225,17 +215,9 @@ pub fn verify( let oods_point = CirclePoint::::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 proof.commitments.len() > 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. @@ -276,7 +258,7 @@ fn sampled_values_to_mask( air.components().iter().for_each(|c| { trace_oods_values.push( flat_trace_values - .take(c.mask_points(CirclePoint::zero()).len()) + .take(c.mask_points(CirclePoint::zero())[0].len()) .cloned() .collect_vec(), ) @@ -291,9 +273,14 @@ fn sampled_values_to_mask( air.components() .iter() .zip_eq(&mut trace_oods_values) - .for_each(|(_component, values)| { + .for_each(|(component, values)| { // TODO(AlonH): Implement n_interaction_columns() for component. - values.extend(interaction_values.take(1).cloned().collect_vec()) + values.extend( + interaction_values + .take(component.mask_points(CirclePoint::zero())[1].len()) + .cloned() + .collect_vec(), + ) }); } @@ -409,8 +396,8 @@ mod tests { fn mask_points( &self, point: CirclePoint, - ) -> crate::core::ColumnVec>> { - vec![vec![point]] + ) -> TreeVec>>> { + TreeVec::new(vec![vec![vec![point]], vec![]]) } fn interaction_element_ids(&self) -> Vec { diff --git a/crates/prover/src/examples/fibonacci/component.rs b/crates/prover/src/examples/fibonacci/component.rs index 634e6e189..270f2c6d1 100644 --- a/crates/prover/src/examples/fibonacci/component.rs +++ b/crates/prover/src/examples/fibonacci/component.rs @@ -88,12 +88,15 @@ impl Component for FibonacciComponent { fn mask_points( &self, point: CirclePoint, - ) -> ColumnVec>> { - shifted_mask_points( - &vec![vec![0, 1, 2]], - &[CanonicCoset::new(self.log_size)], - point, - ) + ) -> TreeVec>>> { + TreeVec::new(vec![ + shifted_mask_points( + &vec![vec![0, 1, 2]], + &[CanonicCoset::new(self.log_size)], + point, + ), + vec![], + ]) } fn interaction_element_ids(&self) -> Vec { diff --git a/crates/prover/src/examples/wide_fibonacci/component.rs b/crates/prover/src/examples/wide_fibonacci/component.rs index 770c5f6b7..9606ca256 100644 --- a/crates/prover/src/examples/wide_fibonacci/component.rs +++ b/crates/prover/src/examples/wide_fibonacci/component.rs @@ -76,8 +76,11 @@ impl Component for WideFibComponent { fn mask_points( &self, point: CirclePoint, - ) -> ColumnVec>> { - fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point) + ) -> TreeVec>>> { + TreeVec::new(vec![ + fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point), + vec![vec![point]], + ]) } fn interaction_element_ids(&self) -> Vec { diff --git a/crates/prover/src/examples/wide_fibonacci/simd.rs b/crates/prover/src/examples/wide_fibonacci/simd.rs index 0cb332c58..67fa6b865 100644 --- a/crates/prover/src/examples/wide_fibonacci/simd.rs +++ b/crates/prover/src/examples/wide_fibonacci/simd.rs @@ -73,8 +73,11 @@ impl Component for SimdWideFibComponent { fn mask_points( &self, point: CirclePoint, - ) -> ColumnVec>> { - fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point) + ) -> TreeVec>>> { + TreeVec::new(vec![ + fixed_mask_points(&vec![vec![0_usize]; self.n_columns()], point), + vec![], + ]) } fn interaction_element_ids(&self) -> Vec {