From 8b554c70c45d406ce9d41109f7dafd993079a515 Mon Sep 17 00:00:00 2001 From: Andrew Milson Date: Fri, 23 Aug 2024 22:20:20 -0400 Subject: [PATCH] Remove InteractionElements and LookupValues --- .../src/constraint_framework/component.rs | 10 +--- .../prover/src/constraint_framework/logup.rs | 5 +- crates/prover/src/core/air/components.rs | 23 +------- crates/prover/src/core/air/mod.rs | 9 +--- .../prover/src/core/backend/simd/quotients.rs | 9 +--- crates/prover/src/core/mod.rs | 52 +------------------ crates/prover/src/core/pcs/prover.rs | 20 ++++--- .../src/core/poly/circle/secure_poly.rs | 4 ++ crates/prover/src/core/prover/mod.rs | 36 ++----------- crates/prover/src/examples/blake/air.rs | 10 +--- crates/prover/src/examples/blake/round/gen.rs | 4 +- .../src/examples/blake/scheduler/gen.rs | 4 +- crates/prover/src/examples/mod.rs | 5 +- crates/prover/src/examples/plonk/mod.rs | 43 +++++---------- crates/prover/src/examples/poseidon/mod.rs | 24 ++------- .../src/examples/wide_fibonacci/component.rs | 28 +++++----- .../src/examples/wide_fibonacci/simd.rs | 4 +- crates/prover/src/lib.rs | 5 +- 18 files changed, 70 insertions(+), 225 deletions(-) diff --git a/crates/prover/src/constraint_framework/component.rs b/crates/prover/src/constraint_framework/component.rs index b323e7049..9950d5ca2 100644 --- a/crates/prover/src/constraint_framework/component.rs +++ b/crates/prover/src/constraint_framework/component.rs @@ -20,7 +20,7 @@ use crate::core::fields::FieldExpOps; use crate::core::pcs::{TreeColumnSpan, TreeVec}; use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps}; use crate::core::poly::BitReversedOrder; -use crate::core::{utils, ColumnVec, InteractionElements, LookupValues}; +use crate::core::{utils, ColumnVec}; // TODO(andrew): Docs. // TODO(andrew): Consider better location for this. @@ -123,8 +123,6 @@ impl Component for FrameworkComponent { point: CirclePoint, mask: &TreeVec>>, evaluation_accumulator: &mut PointEvaluationAccumulator, - _interaction_elements: &InteractionElements, - _lookup_values: &LookupValues, ) { self.eval.evaluate(PointEvaluator::new( mask.sub_tree(&self.trace_locations), @@ -139,8 +137,6 @@ impl ComponentProver for FrameworkComponent { &self, trace: &Trace<'_, SimdBackend>, evaluation_accumulator: &mut DomainEvaluationAccumulator, - _interaction_elements: &InteractionElements, - _lookup_values: &LookupValues, ) { let eval_domain = CanonicCoset::new(self.max_constraint_log_degree_bound()).circle_domain(); let trace_domain = CanonicCoset::new(self.eval.log_size()); @@ -205,10 +201,6 @@ impl ComponentProver for FrameworkComponent { } } } - - fn lookup_values(&self, _trace: &Trace<'_, SimdBackend>) -> LookupValues { - LookupValues::default() - } } impl Deref for FrameworkComponent { diff --git a/crates/prover/src/constraint_framework/logup.rs b/crates/prover/src/constraint_framework/logup.rs index 3cd58e1bf..b9c7b0866 100644 --- a/crates/prover/src/constraint_framework/logup.rs +++ b/crates/prover/src/constraint_framework/logup.rs @@ -227,10 +227,7 @@ impl LogupTraceGenerator { .into_iter() .flat_map(|eval| { eval.columns.map(|c| { - CircleEvaluation::::new( - CanonicCoset::new(self.log_size).circle_domain(), - c, - ) + CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), c) }) }) .collect_vec(); diff --git a/crates/prover/src/core/air/components.rs b/crates/prover/src/core/air/components.rs index 397468616..320ec35cb 100644 --- a/crates/prover/src/core/air/components.rs +++ b/crates/prover/src/core/air/components.rs @@ -7,7 +7,7 @@ use crate::core::circle::CirclePoint; use crate::core::fields::qm31::SecureField; use crate::core::pcs::TreeVec; use crate::core::poly::circle::SecureCirclePoly; -use crate::core::{ColumnVec, InteractionElements, LookupValues}; +use crate::core::ColumnVec; pub struct Components<'a>(pub Vec<&'a dyn Component>); @@ -32,8 +32,6 @@ impl<'a> Components<'a> { point: CirclePoint, mask_values: &TreeVec>>, random_coeff: SecureField, - interaction_elements: &InteractionElements, - lookup_values: &LookupValues, ) -> SecureField { let mut evaluation_accumulator = PointEvaluationAccumulator::new(random_coeff); for component in &self.0 { @@ -41,8 +39,6 @@ impl<'a> Components<'a> { point, mask_values, &mut evaluation_accumulator, - interaction_elements, - lookup_values, ) } evaluation_accumulator.finalize() @@ -67,8 +63,6 @@ impl<'a, B: Backend> ComponentProvers<'a, B> { &self, random_coeff: SecureField, trace: &Trace<'_, B>, - interaction_elements: &InteractionElements, - lookup_values: &LookupValues, ) -> SecureCirclePoly { let total_constraints: usize = self.0.iter().map(|c| c.n_constraints()).sum(); let mut accumulator = DomainEvaluationAccumulator::new( @@ -77,21 +71,8 @@ impl<'a, B: Backend> ComponentProvers<'a, B> { total_constraints, ); for component in &self.0 { - component.evaluate_constraint_quotients_on_domain( - trace, - &mut accumulator, - interaction_elements, - lookup_values, - ) + component.evaluate_constraint_quotients_on_domain(trace, &mut accumulator) } accumulator.finalize() } - - pub fn lookup_values(&self, trace: &Trace<'_, B>) -> LookupValues { - let mut values = LookupValues::default(); - for component in &self.0 { - values.extend(component.lookup_values(trace)) - } - values - } } diff --git a/crates/prover/src/core/air/mod.rs b/crates/prover/src/core/air/mod.rs index 39834296a..fcdd4d5f8 100644 --- a/crates/prover/src/core/air/mod.rs +++ b/crates/prover/src/core/air/mod.rs @@ -8,7 +8,7 @@ use super::fields::qm31::SecureField; use super::pcs::TreeVec; use super::poly::circle::{CircleEvaluation, CirclePoly}; use super::poly::BitReversedOrder; -use super::{ColumnVec, InteractionElements, LookupValues}; +use super::ColumnVec; pub mod accumulation; mod components; @@ -52,8 +52,6 @@ pub trait Component { point: CirclePoint, mask: &TreeVec>>, evaluation_accumulator: &mut PointEvaluationAccumulator, - interaction_elements: &InteractionElements, - lookup_values: &LookupValues, ); } @@ -64,12 +62,7 @@ pub trait ComponentProver: Component { &self, trace: &Trace<'_, B>, evaluation_accumulator: &mut DomainEvaluationAccumulator, - interaction_elements: &InteractionElements, - lookup_values: &LookupValues, ); - - /// Returns the values needed to evaluate the components lookup boundary constraints. - fn lookup_values(&self, _trace: &Trace<'_, B>) -> LookupValues; } /// The set of polynomials that make up the trace. diff --git a/crates/prover/src/core/backend/simd/quotients.rs b/crates/prover/src/core/backend/simd/quotients.rs index 3cb664aeb..382d2a14c 100644 --- a/crates/prover/src/core/backend/simd/quotients.rs +++ b/crates/prover/src/core/backend/simd/quotients.rs @@ -282,13 +282,8 @@ mod tests { }]; let cpu_columns = columns .iter() - .map(|c| { - CircleEvaluation::::new( - c.domain, - c.values.to_cpu(), - ) - }) - .collect::>(); + .map(|c| CircleEvaluation::new(c.domain, c.values.to_cpu())) + .collect_vec(); let cpu_result = CpuBackend::accumulate_quotients( domain, &cpu_columns.iter().collect_vec(), diff --git a/crates/prover/src/core/mod.rs b/crates/prover/src/core/mod.rs index 1daa2b6e7..a00aad687 100644 --- a/crates/prover/src/core/mod.rs +++ b/crates/prover/src/core/mod.rs @@ -1,10 +1,4 @@ -use std::collections::BTreeMap; -use std::ops::{Deref, DerefMut, Index}; - -use fields::m31::BaseField; -use serde::{Deserialize, Serialize}; - -use self::fields::qm31::SecureField; +use std::ops::{Deref, DerefMut}; pub mod air; pub mod backend; @@ -63,47 +57,3 @@ impl DerefMut for ComponentVec { &mut self.0 } } - -#[derive(Default, Debug)] -pub struct InteractionElements(BTreeMap); - -impl InteractionElements { - pub fn new(elements: BTreeMap) -> Self { - Self(elements) - } - - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } -} - -impl Index<&str> for InteractionElements { - type Output = SecureField; - - fn index(&self, index: &str) -> &Self::Output { - // TODO(AlonH): Return an error if the key is not found. - &self.0[index] - } -} - -#[derive(Default, Debug, Serialize, Deserialize)] -pub struct LookupValues(pub BTreeMap); - -impl LookupValues { - pub fn new(values: BTreeMap) -> Self { - Self(values) - } - - pub fn extend(&mut self, other: Self) { - self.0.extend(other.0); - } -} - -impl Index<&str> for LookupValues { - type Output = BaseField; - - fn index(&self, index: &str) -> &Self::Output { - // TODO(AlonH): Return an error if the key is not found. - &self.0[index] - } -} diff --git a/crates/prover/src/core/pcs/prover.rs b/crates/prover/src/core/pcs/prover.rs index d73874055..4d726aff5 100644 --- a/crates/prover/src/core/pcs/prover.rs +++ b/crates/prover/src/core/pcs/prover.rs @@ -167,30 +167,28 @@ pub struct TreeBuilder<'a, 'b, B: BackendForChannel, MC: MerkleChannel> { impl<'a, 'b, B: BackendForChannel, MC: MerkleChannel> TreeBuilder<'a, 'b, B, MC> { pub fn extend_evals( &mut self, - columns: ColumnVec>, + columns: impl IntoIterator>, ) -> TreeColumnSpan { let span = span!(Level::INFO, "Interpolation for commitment").entered(); - let col_start = self.polys.len(); let polys = columns .into_iter() .map(|eval| eval.interpolate_with_twiddles(self.commitment_scheme.twiddles)) .collect_vec(); span.exit(); - self.polys.extend(polys); - TreeColumnSpan { - tree_index: self.tree_index, - col_start, - col_end: self.polys.len(), - } + self.extend_polys(polys) } - pub fn extend_polys(&mut self, polys: ColumnVec>) -> TreeColumnSpan { + pub fn extend_polys( + &mut self, + columns: impl IntoIterator>, + ) -> TreeColumnSpan { let col_start = self.polys.len(); - self.polys.extend(polys); + self.polys.extend(columns); + let col_end = self.polys.len(); TreeColumnSpan { tree_index: self.tree_index, col_start, - col_end: self.polys.len(), + col_end, } } diff --git a/crates/prover/src/core/poly/circle/secure_poly.rs b/crates/prover/src/core/poly/circle/secure_poly.rs index a503bd2c6..de6d75d40 100644 --- a/crates/prover/src/core/poly/circle/secure_poly.rs +++ b/crates/prover/src/core/poly/circle/secure_poly.rs @@ -43,6 +43,10 @@ impl SecureCirclePoly { let columns = polys.map(|poly| poly.evaluate_with_twiddles(domain, twiddles).values); SecureEvaluation::new(domain, SecureColumnByCoords { columns }) } + + pub fn into_coordinate_polys(self) -> [CirclePoly; SECURE_EXTENSION_DEGREE] { + self.0 + } } impl> Deref for SecureCirclePoly { diff --git a/crates/prover/src/core/prover/mod.rs b/crates/prover/src/core/prover/mod.rs index b90897c8c..74a5d6d69 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -9,56 +9,36 @@ use super::fields::secure_column::SECURE_EXTENSION_DEGREE; use super::fri::FriVerificationError; use super::pcs::{CommitmentSchemeProof, TreeVec}; use super::vcs::ops::MerkleHasher; -use super::{InteractionElements, LookupValues}; -use crate::core::backend::CpuBackend; use crate::core::channel::Channel; use crate::core::circle::CirclePoint; use crate::core::fields::qm31::SecureField; use crate::core::pcs::{CommitmentSchemeProver, CommitmentSchemeVerifier}; -use crate::core::poly::circle::CircleEvaluation; -use crate::core::poly::BitReversedOrder; use crate::core::vcs::verifier::MerkleVerificationError; #[derive(Debug, Serialize, Deserialize)] pub struct StarkProof { pub commitments: TreeVec, - pub lookup_values: LookupValues, pub commitment_scheme_proof: CommitmentSchemeProof, } -#[derive(Debug)] -pub struct AdditionalProofData { - pub composition_polynomial_oods_value: SecureField, - pub composition_polynomial_random_coeff: SecureField, - pub oods_point: CirclePoint, - pub oods_quotients: Vec>, -} - pub fn prove, MC: MerkleChannel>( components: &[&dyn ComponentProver], channel: &mut MC::C, - interaction_elements: &InteractionElements, commitment_scheme: &mut CommitmentSchemeProver<'_, B, MC>, ) -> Result, ProvingError> { let component_provers = ComponentProvers(components.to_vec()); let trace = commitment_scheme.trace(); - let lookup_values = component_provers.lookup_values(&trace); // Evaluate and commit on composition polynomial. let random_coeff = channel.draw_felt(); let span = span!(Level::INFO, "Composition").entered(); let span1 = span!(Level::INFO, "Generation").entered(); - let composition_polynomial_poly = component_provers.compute_composition_polynomial( - random_coeff, - &trace, - interaction_elements, - &lookup_values, - ); + let composition_poly = component_provers.compute_composition_polynomial(random_coeff, &trace); span1.exit(); let mut tree_builder = commitment_scheme.tree_builder(); - tree_builder.extend_polys(composition_polynomial_poly.to_vec()); + tree_builder.extend_polys(composition_poly.into_coordinate_polys()); tree_builder.commit(channel); span.exit(); @@ -82,20 +62,13 @@ pub fn prove, MC: MerkleChannel>( if composition_oods_eval != component_provers .components() - .eval_composition_polynomial_at_point( - oods_point, - sampled_oods_values, - random_coeff, - interaction_elements, - &lookup_values, - ) + .eval_composition_polynomial_at_point(oods_point, sampled_oods_values, random_coeff) { return Err(ProvingError::ConstraintsNotSatisfied); } Ok(StarkProof { commitments: commitment_scheme.roots(), - lookup_values, commitment_scheme_proof, }) } @@ -103,7 +76,6 @@ pub fn prove, MC: MerkleChannel>( pub fn verify( components: &[&dyn Component], channel: &mut MC::C, - interaction_elements: &InteractionElements, commitment_scheme: &mut CommitmentSchemeVerifier, proof: StarkProof, ) -> Result<(), VerificationError> { @@ -136,8 +108,6 @@ pub fn verify( oods_point, sampled_oods_values, random_coeff, - interaction_elements, - &proof.lookup_values, ) { return Err(VerificationError::OodsNotMatching); diff --git a/crates/prover/src/examples/blake/air.rs b/crates/prover/src/examples/blake/air.rs index 75219e6bd..f28bb7cf2 100644 --- a/crates/prover/src/examples/blake/air.rs +++ b/crates/prover/src/examples/blake/air.rs @@ -19,7 +19,6 @@ use crate::core::pcs::{CommitmentSchemeProver, CommitmentSchemeVerifier, PcsConf use crate::core::poly::circle::{CanonicCoset, PolyOps}; use crate::core::prover::{prove, verify, StarkProof, VerificationError}; use crate::core::vcs::ops::MerkleHasher; -use crate::core::InteractionElements; use crate::examples::blake::round::RoundElements; use crate::examples::blake::scheduler::{self, blake_scheduler_info, BlakeElements, BlakeInput}; use crate::examples::blake::{ @@ -390,13 +389,7 @@ where // Prove constraints. let components = BlakeComponents::new(&stmt0, &all_elements, &stmt1); - let stark_proof = prove::( - &components.component_provers(), - channel, - &InteractionElements::default(), - commitment_scheme, - ) - .unwrap(); + let stark_proof = prove(&components.component_provers(), channel, commitment_scheme).unwrap(); BlakeProof { stmt0, @@ -450,7 +443,6 @@ pub fn verify_blake( verify( &components.components(), channel, - &InteractionElements::default(), // Not in use. commitment_scheme, stark_proof, ) diff --git a/crates/prover/src/examples/blake/round/gen.rs b/crates/prover/src/examples/blake/round/gen.rs index ce0966381..9bddcdd40 100644 --- a/crates/prover/src/examples/blake/round/gen.rs +++ b/crates/prover/src/examples/blake/round/gen.rs @@ -230,8 +230,8 @@ pub fn generate_trace( generator .trace .into_iter() - .map(|eval| CircleEvaluation::::new(domain, eval)) - .collect_vec(), + .map(|eval| CircleEvaluation::new(domain, eval)) + .collect(), BlakeRoundLookupData { xor_lookups: generator.xor_lookups, round_lookup: generator.round_lookup, diff --git a/crates/prover/src/examples/blake/scheduler/gen.rs b/crates/prover/src/examples/blake/scheduler/gen.rs index 0581b2fe1..cd6a99b2f 100644 --- a/crates/prover/src/examples/blake/scheduler/gen.rs +++ b/crates/prover/src/examples/blake/scheduler/gen.rs @@ -107,8 +107,8 @@ pub fn gen_trace( let domain = CanonicCoset::new(log_size).circle_domain(); let trace = trace .into_iter() - .map(|eval| CircleEvaluation::::new(domain, eval)) - .collect_vec(); + .map(|eval| CircleEvaluation::new(domain, eval)) + .collect(); (trace, lookup_data, round_inputs) } diff --git a/crates/prover/src/examples/mod.rs b/crates/prover/src/examples/mod.rs index 330662de9..40d986559 100644 --- a/crates/prover/src/examples/mod.rs +++ b/crates/prover/src/examples/mod.rs @@ -1,5 +1,8 @@ pub mod blake; pub mod plonk; pub mod poseidon; -pub mod wide_fibonacci; +// TODO: Add back once InteractionElements and LookupValues get refactored out. InteractionElements +// removed in favour of storing interaction elements the components directly with LookupElements. +// LookupValues removed in favour of storing lookup values on a claim struct. +// pub mod wide_fibonacci; pub mod xor; diff --git a/crates/prover/src/examples/plonk/mod.rs b/crates/prover/src/examples/plonk/mod.rs index 2a3d416b2..796b00ecd 100644 --- a/crates/prover/src/examples/plonk/mod.rs +++ b/crates/prover/src/examples/plonk/mod.rs @@ -19,7 +19,7 @@ use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps}; use crate::core::poly::BitReversedOrder; use crate::core::prover::{prove, StarkProof}; use crate::core::vcs::blake2_merkle::Blake2sMerkleHasher; -use crate::core::{ColumnVec, InteractionElements}; +use crate::core::ColumnVec; pub type PlonkComponent = FrameworkComponent; @@ -108,8 +108,8 @@ pub fn gen_trace( &circuit.c_val, ] .into_iter() - .map(|eval| CircleEvaluation::::new(domain, eval.clone())) - .collect_vec() + .map(|eval| CircleEvaluation::new(domain, eval.clone())) + .collect() } pub fn gen_interaction_trace( @@ -206,17 +206,14 @@ pub fn prove_fibonacci_plonk( // Constant trace. let span = span!(Level::INFO, "Constant").entered(); let mut tree_builder = commitment_scheme.tree_builder(); - let constants_trace_location = tree_builder.extend_evals( - chain!([circuit.a_wire, circuit.b_wire, circuit.c_wire, circuit.op] - .into_iter() - .map(|col| { - CircleEvaluation::::new( - CanonicCoset::new(log_n_rows).circle_domain(), - col, - ) - })) - .collect_vec(), - ); + let constants_trace_location = tree_builder.extend_evals(chain!([ + circuit.a_wire, + circuit.b_wire, + circuit.c_wire, + circuit.op + ] + .into_iter() + .map(|col| CircleEvaluation::new(CanonicCoset::new(log_n_rows).circle_domain(), col)))); tree_builder.commit(channel); span.exit(); @@ -242,13 +239,7 @@ pub fn prove_fibonacci_plonk( component.evaluate(eval); }); - let proof = prove::( - &[&component], - channel, - &InteractionElements::default(), - commitment_scheme, - ) - .unwrap(); + let proof = prove(&[&component], channel, commitment_scheme).unwrap(); (component, proof) } @@ -264,7 +255,6 @@ mod tests { use crate::core::pcs::{CommitmentSchemeVerifier, PcsConfig}; use crate::core::prover::verify; use crate::core::vcs::blake2_merkle::Blake2sMerkleChannel; - use crate::core::InteractionElements; use crate::examples::plonk::prove_fibonacci_plonk; #[test_log::test] @@ -301,13 +291,6 @@ mod tests { // Constant columns. commitment_scheme.commit(proof.commitments[2], &sizes[2], channel); - verify( - &[&component], - channel, - &InteractionElements::default(), - commitment_scheme, - proof, - ) - .unwrap(); + verify(&[&component], channel, commitment_scheme, proof).unwrap(); } } diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index e329d57cf..2b0dceacc 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -24,7 +24,7 @@ use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps}; use crate::core::poly::BitReversedOrder; use crate::core::prover::{prove, StarkProof}; use crate::core::vcs::blake2_merkle::Blake2sMerkleHasher; -use crate::core::{ColumnVec, InteractionElements}; +use crate::core::ColumnVec; const N_LOG_INSTANCES_PER_ROW: usize = 3; const N_INSTANCES_PER_ROW: usize = 1 << N_LOG_INSTANCES_PER_ROW; @@ -278,8 +278,8 @@ pub fn gen_trace( let domain = CanonicCoset::new(log_size).circle_domain(); let trace = trace .into_iter() - .map(|eval| CircleEvaluation::::new(domain, eval)) - .collect_vec(); + .map(|eval| CircleEvaluation::new(domain, eval)) + .collect(); (trace, lookup_data) } @@ -366,13 +366,7 @@ pub fn prove_poseidon( claimed_sum, }, ); - let proof = prove::( - &[&component], - channel, - &InteractionElements::default(), - commitment_scheme, - ) - .unwrap(); + let proof = prove(&[&component], channel, commitment_scheme).unwrap(); (component, proof) } @@ -394,7 +388,6 @@ mod tests { use crate::core::poly::circle::CanonicCoset; use crate::core::prover::verify; use crate::core::vcs::blake2_merkle::Blake2sMerkleChannel; - use crate::core::InteractionElements; use crate::examples::poseidon::{ apply_internal_round_matrix, apply_m4, eval_poseidon_constraints, gen_interaction_trace, gen_trace, prove_poseidon, PoseidonElements, @@ -510,13 +503,6 @@ mod tests { // Interaction columns. commitment_scheme.commit(proof.commitments[1], &sizes[1], channel); - verify( - &[&component], - channel, - &InteractionElements::default(), - commitment_scheme, - proof, - ) - .unwrap(); + verify(&[&component], channel, commitment_scheme, proof).unwrap(); } } diff --git a/crates/prover/src/examples/wide_fibonacci/component.rs b/crates/prover/src/examples/wide_fibonacci/component.rs index 4eb08740f..c14cdd8b0 100644 --- a/crates/prover/src/examples/wide_fibonacci/component.rs +++ b/crates/prover/src/examples/wide_fibonacci/component.rs @@ -1,5 +1,6 @@ use itertools::Itertools; +use crate::constraint_framework::logup::LookupElements; use crate::core::air::accumulation::PointEvaluationAccumulator; use crate::core::air::mask::fixed_mask_points; use crate::core::air::{Air, Component}; @@ -30,6 +31,8 @@ pub const LOOKUP_VALUE_1_ID: &str = "wide_fibonacci_1"; pub const LOOKUP_VALUE_N_MINUS_2_ID: &str = "wide_fibonacci_n-2"; pub const LOOKUP_VALUE_N_MINUS_1_ID: &str = "wide_fibonacci_n-1"; +pub type WideFibElements = LookupElements<2>; + /// Component that computes 2^`self.log_n_instances` instances of fibonacci sequences of size /// 2^`self.log_fibonacci_size`. The numbers are computes over [N_COLUMNS] trace columns. The /// number of rows (i.e the size of the columns) is determined by the parameters above (see @@ -38,6 +41,11 @@ pub const LOOKUP_VALUE_N_MINUS_1_ID: &str = "wide_fibonacci_n-1"; pub struct WideFibComponent { pub log_fibonacci_size: u32, pub log_n_instances: u32, + pub lookup_elements: WideFibElements, + pub lookup_value_0: SecureField, + pub lookup_value_1: SecureField, + pub lookup_value_n_minus_2: SecureField, + pub lookup_value_n_minus_1: SecureField, } impl WideFibComponent { @@ -104,10 +112,10 @@ impl WideFibComponent { mask: &TreeVec>>, evaluation_accumulator: &mut PointEvaluationAccumulator, constraint_zero_domain: Coset, - interaction_elements: &InteractionElements, - lookup_values: &LookupValues, + _interaction_elements: &InteractionElements, + _lookup_values: &LookupValues, ) { - let (alpha, z) = (interaction_elements[ALPHA_ID], interaction_elements[Z_ID]); + let WideFibElements { alpha, z, .. } = self.lookup_elements; let value = SecureField::from_partial_evals(std::array::from_fn(|i| mask[1][i][0])); let numerator = (value * shifted_secure_combination( @@ -124,21 +132,11 @@ impl WideFibComponent { let numerator = (value * shifted_secure_combination( - &[ - lookup_values[LOOKUP_VALUE_N_MINUS_2_ID], - lookup_values[LOOKUP_VALUE_N_MINUS_1_ID], - ], + &[self.lookup_value_n_minus_2, self.lookup_value_n_minus_1], alpha, z, )) - - shifted_secure_combination( - &[ - lookup_values[LOOKUP_VALUE_0_ID], - lookup_values[LOOKUP_VALUE_1_ID], - ], - alpha, - z, - ); + - shifted_secure_combination(&[self.lookup_value_0, self.lookup_value_1], alpha, z); let denom = point_vanishing( constraint_zero_domain.at(constraint_zero_domain.size() - 1), point, diff --git a/crates/prover/src/examples/wide_fibonacci/simd.rs b/crates/prover/src/examples/wide_fibonacci/simd.rs index a7ed4dcec..d764374fe 100644 --- a/crates/prover/src/examples/wide_fibonacci/simd.rs +++ b/crates/prover/src/examples/wide_fibonacci/simd.rs @@ -160,8 +160,8 @@ pub fn gen_trace( let domain = CanonicCoset::new(log_size).circle_domain(); trace .into_iter() - .map(|eval| CircleEvaluation::::new(domain, eval)) - .collect_vec() + .map(|eval| CircleEvaluation::new(domain, eval)) + .collect() } impl ComponentTraceGenerator for SimdWideFibComponent { diff --git a/crates/prover/src/lib.rs b/crates/prover/src/lib.rs index a06b0c2d1..cee5cde34 100644 --- a/crates/prover/src/lib.rs +++ b/crates/prover/src/lib.rs @@ -20,4 +20,7 @@ pub mod constraint_framework; pub mod core; pub mod examples; pub mod math; -pub mod trace_generation; +// TODO: Add back once InteractionElements and LookupValues get refactored out. InteractionElements +// removed in favour of storing interaction elements the components directly with LookupElements. +// LookupValues removed in favour of storing lookup values on a claim struct. +// pub mod trace_generation;