Skip to content

Commit

Permalink
Remove InteractionElements LookupValues and trace_generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharsamocha7 committed Aug 27, 2024
1 parent 1d16029 commit df22ee6
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 833 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 @@ -18,7 +18,7 @@ use crate::core::fields::FieldExpOps;
use crate::core::pcs::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};

/// A component defined solely in means of the constraints framework.
/// Implementing this trait introduces implementations for [Component] and [ComponentProver] for the
Expand Down Expand Up @@ -68,8 +68,6 @@ impl<C: FrameworkComponent> Component for C {
point: CirclePoint<SecureField>,
mask: &TreeVec<ColumnVec<Vec<SecureField>>>,
evaluation_accumulator: &mut PointEvaluationAccumulator,
_interaction_elements: &InteractionElements,
_lookup_values: &LookupValues,
) {
self.evaluate(PointEvaluator::new(
mask.as_ref(),
Expand All @@ -84,8 +82,6 @@ impl<C: FrameworkComponent> ComponentProver<SimdBackend> for C {
&self,
trace: &ComponentTrace<'_, 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.log_size());
Expand Down Expand Up @@ -149,8 +145,4 @@ impl<C: FrameworkComponent> ComponentProver<SimdBackend> for C {
}
}
}

fn lookup_values(&self, _trace: &ComponentTrace<'_, SimdBackend>) -> LookupValues {
LookupValues::default()
}
}
22 changes: 2 additions & 20 deletions crates/prover/src/core/air/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::core::circle::CirclePoint;
use crate::core::fields::qm31::SecureField;
use crate::core::pcs::{CommitmentTreeProver, 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 @@ -33,17 +33,13 @@ impl<'a> Components<'a> {
point: CirclePoint<SecureField>,
mask_values: &Vec<TreeVec<Vec<Vec<SecureField>>>>,
random_coeff: SecureField,
interaction_elements: &InteractionElements,
lookup_values: &LookupValues,
) -> SecureField {
let mut evaluation_accumulator = PointEvaluationAccumulator::new(random_coeff);
zip_eq(&self.0, mask_values).for_each(|(component, mask)| {
component.evaluate_constraint_quotients_at_point(
point,
mask,
&mut evaluation_accumulator,
interaction_elements,
lookup_values,
)
});
evaluation_accumulator.finalize()
Expand All @@ -68,8 +64,6 @@ impl<'a, B: Backend> ComponentProvers<'a, B> {
&self,
random_coeff: SecureField,
component_traces: &[ComponentTrace<'_, 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 @@ -78,12 +72,7 @@ impl<'a, B: Backend> ComponentProvers<'a, B> {
total_constraints,
);
zip_eq(&self.0, component_traces).for_each(|(component, trace)| {
component.evaluate_constraint_quotients_on_domain(
trace,
&mut accumulator,
interaction_elements,
lookup_values,
)
component.evaluate_constraint_quotients_on_domain(trace, &mut accumulator)
});
accumulator.finalize()
}
Expand Down Expand Up @@ -129,11 +118,4 @@ impl<'a, B: Backend> ComponentProvers<'a, B> {
})
.collect_vec()
}

pub fn lookup_values(&self, component_traces: &[ComponentTrace<'_, B>]) -> LookupValues {
let mut values = LookupValues::default();
zip_eq(&self.0, component_traces)
.for_each(|(component, trace)| 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: &ComponentTrace<'_, 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: &ComponentTrace<'_, B>) -> LookupValues;
}

/// A component trace is a set of polynomials for each column on that component.
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]
}
}
25 changes: 4 additions & 21 deletions crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::fields::secure_column::SECURE_EXTENSION_DEGREE;
use super::fri::FriVerificationError;
use super::pcs::{CommitmentSchemeProof, TreeVec};
use super::vcs::ops::MerkleHasher;
use super::{ColumnVec, InteractionElements, LookupValues};
use super::ColumnVec;
use crate::core::backend::CpuBackend;
use crate::core::channel::Channel;
use crate::core::circle::CirclePoint;
Expand All @@ -23,7 +23,6 @@ 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>,
}

Expand All @@ -38,24 +37,18 @@ pub struct AdditionalProofData {
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 component_traces = component_provers.component_traces(&commitment_scheme.trees);
let lookup_values = component_provers.lookup_values(&component_traces);

// 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,
&component_traces,
interaction_elements,
&lookup_values,
);
let composition_polynomial_poly =
component_provers.compute_composition_polynomial(random_coeff, &component_traces);
span1.exit();

let mut tree_builder = commitment_scheme.tree_builder();
Expand Down Expand Up @@ -86,28 +79,20 @@ pub fn prove<B: BackendForChannel<MC>, MC: MerkleChannel>(
if composition_oods_value
!= component_provers
.components()
.eval_composition_polynomial_at_point(
oods_point,
&trace_oods_values,
random_coeff,
interaction_elements,
&lookup_values,
)
.eval_composition_polynomial_at_point(oods_point, &trace_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 @@ -143,8 +128,6 @@ pub fn verify<MC: MerkleChannel>(
oods_point,
&trace_oods_values,
random_coeff,
interaction_elements,
&proof.lookup_values,
)
{
return Err(VerificationError::OodsNotMatching);
Expand Down
12 changes: 3 additions & 9 deletions crates/prover/src/examples/blake/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 @@ -365,13 +364,9 @@ 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::<SimdBackend, _>(&components.component_provers(), channel, commitment_scheme)
.unwrap();

BlakeProof {
stmt0,
Expand Down Expand Up @@ -425,7 +420,6 @@ pub fn verify_blake<MC: MerkleChannel>(
verify(
&components.components(),
channel,
&InteractionElements::default(), // Not in use.
commitment_scheme,
stark_proof,
)
Expand Down
20 changes: 3 additions & 17 deletions crates/prover/src/examples/plonk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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::{Blake2sMerkleChannel, Blake2sMerkleHasher};
use crate::core::{ColumnVec, InteractionElements};
use crate::core::ColumnVec;

#[derive(Clone)]
pub struct PlonkComponent {
Expand Down Expand Up @@ -230,13 +230,7 @@ pub fn prove_fibonacci_plonk(
component.evaluate(eval);
});

let proof = prove::<SimdBackend, _>(
&[&component],
channel,
&InteractionElements::default(),
commitment_scheme,
)
.unwrap();
let proof = prove::<SimdBackend, _>(&[&component], channel, commitment_scheme).unwrap();

(component, proof)
}
Expand All @@ -252,7 +246,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]
Expand Down Expand Up @@ -289,13 +282,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();
}
}
20 changes: 3 additions & 17 deletions crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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::{Blake2sMerkleChannel, 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;
Expand Down Expand Up @@ -370,13 +370,7 @@ pub fn prove_poseidon(
lookup_elements,
claimed_sum,
};
let proof = prove::<SimdBackend, _>(
&[&component],
channel,
&InteractionElements::default(),
commitment_scheme,
)
.unwrap();
let proof = prove::<SimdBackend, _>(&[&component], channel, commitment_scheme).unwrap();

(component, proof)
}
Expand All @@ -398,7 +392,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, gen_interaction_trace, gen_trace, prove_poseidon,
PoseidonElements, PoseidonEval,
Expand Down Expand Up @@ -515,13 +508,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();
}
}
Loading

0 comments on commit df22ee6

Please sign in to comment.