Skip to content

Commit

Permalink
Remove InteractionElements and LookupValues
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmilson committed Aug 28, 2024
1 parent e3858fb commit bdbb4a3
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 2,205 deletions.
10 changes: 1 addition & 9 deletions crates/prover/src/constraint_framework/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::core::fields::FieldExpOps;
use crate::core::pcs::{TreeSubspan, 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.
Expand Down Expand Up @@ -121,8 +121,6 @@ impl<E: FrameworkEval> Component for FrameworkComponent<E> {
point: CirclePoint<SecureField>,
mask: &TreeVec<ColumnVec<Vec<SecureField>>>,
evaluation_accumulator: &mut PointEvaluationAccumulator,
_interaction_elements: &InteractionElements,
_lookup_values: &LookupValues,
) {
self.eval.evaluate(PointEvaluator::new(
mask.sub_tree(&self.trace_locations),
Expand All @@ -137,8 +135,6 @@ impl<E: FrameworkEval> ComponentProver<SimdBackend> for FrameworkComponent<E> {
&self,
trace: &Trace<'_, SimdBackend>,
evaluation_accumulator: &mut DomainEvaluationAccumulator<SimdBackend>,
_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());
Expand Down Expand Up @@ -203,10 +199,6 @@ impl<E: FrameworkEval> ComponentProver<SimdBackend> for FrameworkComponent<E> {
}
}
}

fn lookup_values(&self, _trace: &Trace<'_, SimdBackend>) -> LookupValues {
LookupValues::default()
}
}

impl<E: FrameworkEval> Deref for FrameworkComponent<E> {
Expand Down
5 changes: 1 addition & 4 deletions crates/prover/src/constraint_framework/logup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ impl LogupTraceGenerator {
.into_iter()
.flat_map(|eval| {
eval.columns.map(|c| {
CircleEvaluation::<SimdBackend, _, BitReversedOrder>::new(
CanonicCoset::new(self.log_size).circle_domain(),
c,
)
CircleEvaluation::new(CanonicCoset::new(self.log_size).circle_domain(), c)
})
})
.collect_vec();
Expand Down
23 changes: 2 additions & 21 deletions crates/prover/src/core/air/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>);

Expand All @@ -32,17 +32,13 @@ impl<'a> Components<'a> {
point: CirclePoint<SecureField>,
mask_values: &TreeVec<Vec<Vec<SecureField>>>,
random_coeff: SecureField,
interaction_elements: &InteractionElements,
lookup_values: &LookupValues,
) -> SecureField {
let mut evaluation_accumulator = PointEvaluationAccumulator::new(random_coeff);
for component in &self.0 {
component.evaluate_constraint_quotients_at_point(
point,
mask_values,
&mut evaluation_accumulator,
interaction_elements,
lookup_values,
)
}
evaluation_accumulator.finalize()
Expand All @@ -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<B> {
let total_constraints: usize = self.0.iter().map(|c| c.n_constraints()).sum();
let mut accumulator = DomainEvaluationAccumulator::new(
Expand All @@ -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
}
}
9 changes: 1 addition & 8 deletions crates/prover/src/core/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,8 +52,6 @@ pub trait Component {
point: CirclePoint<SecureField>,
mask: &TreeVec<ColumnVec<Vec<SecureField>>>,
evaluation_accumulator: &mut PointEvaluationAccumulator,
interaction_elements: &InteractionElements,
lookup_values: &LookupValues,
);
}

Expand All @@ -64,12 +62,7 @@ pub trait ComponentProver<B: Backend>: Component {
&self,
trace: &Trace<'_, B>,
evaluation_accumulator: &mut DomainEvaluationAccumulator<B>,
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.
Expand Down
9 changes: 2 additions & 7 deletions crates/prover/src/core/backend/simd/quotients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,8 @@ mod tests {
}];
let cpu_columns = columns
.iter()
.map(|c| {
CircleEvaluation::<CpuBackend, _, BitReversedOrder>::new(
c.domain,
c.values.to_cpu(),
)
})
.collect::<Vec<_>>();
.map(|c| CircleEvaluation::new(c.domain, c.values.to_cpu()))
.collect_vec();
let cpu_result = CpuBackend::accumulate_quotients(
domain,
&cpu_columns.iter().collect_vec(),
Expand Down
52 changes: 1 addition & 51 deletions crates/prover/src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -63,47 +57,3 @@ impl<T> DerefMut for ComponentVec<T> {
&mut self.0
}
}

#[derive(Default, Debug)]
pub struct InteractionElements(BTreeMap<String, SecureField>);

impl InteractionElements {
pub fn new(elements: BTreeMap<String, SecureField>) -> 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<String, BaseField>);

impl LookupValues {
pub fn new(values: BTreeMap<String, BaseField>) -> 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]
}
}
20 changes: 9 additions & 11 deletions crates/prover/src/core/pcs/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,28 @@ pub struct TreeBuilder<'a, 'b, B: BackendForChannel<MC>, MC: MerkleChannel> {
impl<'a, 'b, B: BackendForChannel<MC>, MC: MerkleChannel> TreeBuilder<'a, 'b, B, MC> {
pub fn extend_evals(
&mut self,
columns: ColumnVec<CircleEvaluation<B, BaseField, BitReversedOrder>>,
columns: impl IntoIterator<Item = CircleEvaluation<B, BaseField, BitReversedOrder>>,
) -> TreeSubspan {
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);
TreeSubspan {
tree_index: self.tree_index,
col_start,
col_end: self.polys.len(),
}
self.extend_polys(polys)
}

pub fn extend_polys(&mut self, polys: ColumnVec<CirclePoly<B>>) -> TreeSubspan {
pub fn extend_polys(
&mut self,
columns: impl IntoIterator<Item = CirclePoly<B>>,
) -> TreeSubspan {
let col_start = self.polys.len();
self.polys.extend(polys);
self.polys.extend(columns);
let col_end = self.polys.len();
TreeSubspan {
tree_index: self.tree_index,
col_start,
col_end: self.polys.len(),
col_end,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/prover/src/core/poly/circle/secure_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl<B: PolyOps> SecureCirclePoly<B> {
let columns = polys.map(|poly| poly.evaluate_with_twiddles(domain, twiddles).values);
SecureEvaluation::new(domain, SecureColumnByCoords { columns })
}

pub fn into_coordinate_polys(self) -> [CirclePoly<B>; SECURE_EXTENSION_DEGREE] {
self.0
}
}

impl<B: FieldOps<BaseField>> Deref for SecureCirclePoly<B> {
Expand Down
36 changes: 3 additions & 33 deletions crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,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<H: MerkleHasher> {
pub commitments: TreeVec<H::Hash>,
pub lookup_values: LookupValues,
pub commitment_scheme_proof: CommitmentSchemeProof<H>,
}

#[derive(Debug)]
pub struct AdditionalProofData {
pub composition_polynomial_oods_value: SecureField,
pub composition_polynomial_random_coeff: SecureField,
pub oods_point: CirclePoint<SecureField>,
pub oods_quotients: Vec<CircleEvaluation<CpuBackend, SecureField, BitReversedOrder>>,
}

pub fn prove<B: BackendForChannel<MC>, MC: MerkleChannel>(
components: &[&dyn ComponentProver<B>],
channel: &mut MC::C,
interaction_elements: &InteractionElements,
commitment_scheme: &mut CommitmentSchemeProver<'_, B, MC>,
) -> Result<StarkProof<MC::H>, 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();

Expand All @@ -83,28 +63,20 @@ pub fn prove<B: BackendForChannel<MC>, 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,
})
}

pub fn verify<MC: MerkleChannel>(
components: &[&dyn Component],
channel: &mut MC::C,
interaction_elements: &InteractionElements,
commitment_scheme: &mut CommitmentSchemeVerifier<MC>,
proof: StarkProof<MC::H>,
) -> Result<(), VerificationError> {
Expand Down Expand Up @@ -136,8 +108,6 @@ pub fn verify<MC: MerkleChannel>(
oods_point,
sampled_oods_values,
random_coeff,
interaction_elements,
&proof.lookup_values,
)
{
return Err(VerificationError::OodsNotMatching);
Expand Down
10 changes: 1 addition & 9 deletions crates/prover/src/examples/blake/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -390,13 +389,7 @@ where

// Prove constraints.
let components = BlakeComponents::new(&stmt0, &all_elements, &stmt1);
let stark_proof = prove::<SimdBackend, _>(
&components.component_provers(),
channel,
&InteractionElements::default(),
commitment_scheme,
)
.unwrap();
let stark_proof = prove(&components.component_provers(), channel, commitment_scheme).unwrap();

BlakeProof {
stmt0,
Expand Down Expand Up @@ -450,7 +443,6 @@ pub fn verify_blake<MC: MerkleChannel>(
verify(
&components.components(),
channel,
&InteractionElements::default(), // Not in use.
commitment_scheme,
stark_proof,
)
Expand Down
Loading

0 comments on commit bdbb4a3

Please sign in to comment.