Skip to content

Commit

Permalink
Verify lookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 committed Jul 1, 2024
1 parent 2f0aac7 commit e8048c4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/prover/src/core/air/air_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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::prover::{BASE_TRACE, INTERACTION_TRACE};
use crate::core::prover::{VerificationError, BASE_TRACE, INTERACTION_TRACE};
use crate::core::vcs::blake2_merkle::Blake2sMerkleHasher;
use crate::core::vcs::ops::MerkleOps;
use crate::core::{ColumnVec, ComponentVec, InteractionElements, LookupValues};
Expand Down Expand Up @@ -123,6 +123,12 @@ pub trait AirExt: Air {
}
component_traces
}

fn verify_lookups(&self, lookup_values: &LookupValues) -> Result<(), VerificationError> {
self.components()
.iter()
.try_for_each(|component| component.verify_lookups(lookup_values))
}
}

impl<A: Air + ?Sized> AirExt for A {}
Expand Down
4 changes: 4 additions & 0 deletions crates/prover/src/core/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::fields::qm31::SecureField;
use super::pcs::TreeVec;
use super::poly::circle::{CircleEvaluation, CirclePoly};
use super::poly::BitReversedOrder;
use super::prover::VerificationError;
use super::{ColumnVec, InteractionElements, LookupValues};
use crate::trace_generation::AirTraceVerifier;

Expand Down Expand Up @@ -62,6 +63,9 @@ pub trait Component {
interaction_elements: &InteractionElements,
lookup_values: &LookupValues,
);

/// Verifies the lookups used by the component.
fn verify_lookups(&self, lookup_values: &LookupValues) -> Result<(), VerificationError>;
}

pub trait ComponentProver<B: Backend>: Component {
Expand Down
9 changes: 9 additions & 0 deletions crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ pub fn verify(
);
}

air.verify_lookups(&proof.lookup_values)?;

proof.lookup_values.mix_in_channel(channel);
let random_coeff = channel.draw_felt();

Expand Down Expand Up @@ -340,6 +342,8 @@ pub enum ProvingError {
pub enum VerificationError {
#[error("Proof has invalid structure: {0}.")]
InvalidStructure(String),
#[error("{0} lookup values do not match.")]
InvalidLookup(String),
#[error(transparent)]
Merkle(#[from] MerkleVerificationError),
#[error(
Expand All @@ -357,6 +361,7 @@ pub enum VerificationError {
mod tests {
use num_traits::Zero;

use super::VerificationError;
use crate::core::air::accumulation::{DomainEvaluationAccumulator, PointEvaluationAccumulator};
use crate::core::air::{Air, AirProver, Component, ComponentProver, ComponentTrace};
use crate::core::backend::cpu::CpuCircleEvaluation;
Expand Down Expand Up @@ -456,6 +461,10 @@ mod tests {
) {
evaluation_accumulator.accumulate(qm31!(0, 0, 0, 1))
}

fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> {
Ok(())
}
}

impl ComponentTraceGenerator<CpuBackend> for TestComponent {
Expand Down
6 changes: 5 additions & 1 deletion crates/prover/src/examples/fibonacci/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::core::fields::{ExtensionOf, FieldExpOps};
use crate::core::pcs::TreeVec;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation};
use crate::core::poly::BitReversedOrder;
use crate::core::prover::BASE_TRACE;
use crate::core::prover::{VerificationError, BASE_TRACE};
use crate::core::utils::bit_reverse_index;
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::trace_generation::registry::ComponentGenerationRegistry;
Expand Down Expand Up @@ -128,6 +128,10 @@ impl Component for FibonacciComponent {
),
);
}

fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> {
Ok(())
}
}

impl ComponentTraceGenerator<CpuBackend> for FibonacciComponent {
Expand Down
5 changes: 5 additions & 0 deletions crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::core::fields::{FieldExpOps, FieldOps};
use crate::core::pcs::TreeVec;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use crate::core::poly::BitReversedOrder;
use crate::core::prover::VerificationError;
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::trace_generation::{AirTraceGenerator, AirTraceVerifier, ComponentTraceGenerator};

Expand Down Expand Up @@ -138,6 +139,10 @@ impl Component for PoseidonComponent {
}
assert_eq!(eval.col_index, N_COLUMNS);
}

fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> {
Ok(())
}
}

#[inline(always)]
Expand Down
5 changes: 5 additions & 0 deletions crates/prover/src/examples/wide_fibonacci/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::core::fields::FieldExpOps;
use crate::core::pcs::TreeVec;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation, SecureCirclePoly};
use crate::core::poly::BitReversedOrder;
use crate::core::prover::VerificationError;
use crate::core::utils::shifted_secure_combination;
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::examples::wide_fibonacci::trace_gen::write_lookup_column;
Expand Down Expand Up @@ -252,6 +253,10 @@ impl Component for WideFibComponent {
constraint_zero_domain,
);
}

fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> {
Ok(())
}
}

impl ComponentTraceGenerator<CpuBackend> for WideFibComponent {
Expand Down
6 changes: 5 additions & 1 deletion crates/prover/src/examples/wide_fibonacci/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::core::fields::{FieldExpOps, FieldOps};
use crate::core::pcs::TreeVec;
use crate::core::poly::circle::{CanonicCoset, CircleEvaluation};
use crate::core::poly::BitReversedOrder;
use crate::core::prover::BASE_TRACE;
use crate::core::prover::{VerificationError, BASE_TRACE};
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::examples::wide_fibonacci::component::{ALPHA_ID, N_COLUMNS, Z_ID};
use crate::trace_generation::registry::ComponentGenerationRegistry;
Expand Down Expand Up @@ -126,6 +126,10 @@ impl Component for SimdWideFibComponent {
evaluation_accumulator.accumulate(numerator * denom_inverse);
}
}

fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> {
Ok(())
}
}

impl AirProver<SimdBackend> for SimdWideFibAir {
Expand Down
7 changes: 7 additions & 0 deletions crates/prover/src/trace_generation/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ mod tests {
) {
todo!()
}

fn verify_lookups(
&self,
_lookup_values: &LookupValues,
) -> Result<(), crate::core::prover::VerificationError> {
todo!()
}
}

type ComponentACpuInputs = Vec<(M31, M31)>;
Expand Down

0 comments on commit e8048c4

Please sign in to comment.