diff --git a/crates/prover/src/core/air/air_ext.rs b/crates/prover/src/core/air/air_ext.rs index 8c0cf5b06..3389b2cf3 100644 --- a/crates/prover/src/core/air/air_ext.rs +++ b/crates/prover/src/core/air/air_ext.rs @@ -5,6 +5,7 @@ use super::{Air, AirProver, ComponentTrace}; use crate::core::backend::Backend; use crate::core::circle::CirclePoint; use crate::core::fields::qm31::SecureField; +use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; use crate::core::pcs::{CommitmentTreeProver, TreeVec}; use crate::core::poly::circle::SecureCirclePoly; use crate::core::vcs::blake2_merkle::Blake2sMerkleHasher; @@ -31,13 +32,24 @@ 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); + } + // Add the composition polynomial mask points. + points.push(vec![vec![point]; SECURE_EXTENSION_DEGREE]); + points } fn eval_composition_polynomial_at_point( diff --git a/crates/prover/src/core/air/mod.rs b/crates/prover/src/core/air/mod.rs index ae46a3fa9..8cf8c725e 100644 --- a/crates/prover/src/core/air/mod.rs +++ b/crates/prover/src/core/air/mod.rs @@ -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>; + /// Returns the mask points for each trace column. The returned TreeVec should be of size + /// `n_interaction_phases`. 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 f127f6515..3278e60cd 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 727d8f7c3..f297ae505 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -4,6 +4,7 @@ use tracing::{span, Level}; use super::air::{AirProver, AirTraceVerifier, AirTraceWriter}; use super::backend::Backend; +use super::fields::secure_column::SECURE_EXTENSION_DEGREE; use super::fri::FriVerificationError; use super::pcs::{CommitmentSchemeProof, TreeVec}; use super::poly::circle::{CanonicCoset, SecureCirclePoly, MAX_CIRCLE_DOMAIN_LOG_SIZE}; @@ -115,19 +116,6 @@ pub fn generate_proof>( // 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 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. - sample_points.push(vec![vec![oods_point]; 4]); - // Prove the trace and composition OODS values, and retrieve them. let commitment_scheme_proof = commitment_scheme.prove_values(sample_points, channel, twiddles); @@ -219,7 +207,7 @@ pub fn verify( // Read composition polynomial commitment. commitment_scheme.commit( *proof.commitments.last().unwrap(), - &[air.composition_log_degree_bound(); 4], + &[air.composition_log_degree_bound(); SECURE_EXTENSION_DEGREE], channel, ); @@ -227,18 +215,7 @@ 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); - - // 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. - sample_points.push(vec![vec![oods_point]; 4]); + let sample_points = air.mask_points(oods_point); // TODO(spapini): Save clone. let (trace_oods_values, composition_oods_value) = sampled_values_to_mask( @@ -276,9 +253,10 @@ fn sampled_values_to_mask( .iter(); let mut trace_oods_values = vec![]; air.components().iter().for_each(|component| { + let n_trace_points = component.mask_points(CirclePoint::zero())[0].len(); trace_oods_values.push( flat_trace_values - .take(component.mask_points(CirclePoint::zero()).len()) + .take(n_trace_points) .cloned() .collect_vec(), ) @@ -293,9 +271,14 @@ 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)| { + let n_interaction_points = component.mask_points(CirclePoint::zero())[1].len(); + values.extend( + interaction_values + .take(n_interaction_points) + .cloned() + .collect_vec(), + ) }); } @@ -437,8 +420,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 8c09f4589..2b45c4e4e 100644 --- a/crates/prover/src/examples/fibonacci/component.rs +++ b/crates/prover/src/examples/fibonacci/component.rs @@ -92,12 +92,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 c811c4fd3..758559abd 100644 --- a/crates/prover/src/examples/wide_fibonacci/component.rs +++ b/crates/prover/src/examples/wide_fibonacci/component.rs @@ -80,8 +80,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 564d65559..cd7698f3e 100644 --- a/crates/prover/src/examples/wide_fibonacci/simd.rs +++ b/crates/prover/src/examples/wide_fibonacci/simd.rs @@ -99,8 +99,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 {