Skip to content

Commit

Permalink
Verify lookups. (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
alonh5 authored Jul 11, 2024
1 parent 56e997c commit 7fdbdf2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
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};

pub mod accumulation;
Expand All @@ -22,6 +23,9 @@ pub use air_ext::{AirExt, AirProverExt};
// TODO(spapini): consider renaming this struct.
pub trait Air {
fn components(&self) -> Vec<&dyn Component>;

/// Verifies the lookups done in the Air.
fn verify_lookups(&self, lookup_values: &LookupValues) -> Result<(), VerificationError>;
}

pub trait AirProver<B: Backend>: Air {
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 @@ -224,6 +224,8 @@ pub fn verify(
);
}

air.verify_lookups(&proof.lookup_values)?;

channel.mix_felts(
&proof
.lookup_values
Expand Down Expand Up @@ -332,6 +334,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 @@ -349,6 +353,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 @@ -378,6 +383,10 @@ mod tests {
fn components(&self) -> Vec<&dyn Component> {
vec![&self.component]
}

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

impl AirTraceVerifier for TestAir<TestComponent> {
Expand Down
11 changes: 10 additions & 1 deletion crates/prover/src/examples/fibonacci/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::core::channel::Blake2sChannel;
use crate::core::fields::m31::BaseField;
use crate::core::poly::circle::CircleEvaluation;
use crate::core::poly::BitReversedOrder;
use crate::core::{ColumnVec, InteractionElements};
use crate::core::prover::VerificationError;
use crate::core::{ColumnVec, InteractionElements, LookupValues};
use crate::trace_generation::registry::ComponentGenerationRegistry;
use crate::trace_generation::{AirTraceGenerator, AirTraceVerifier, ComponentTraceGenerator};

Expand Down Expand Up @@ -79,6 +80,10 @@ impl Air for FibonacciAir {
fn components(&self) -> Vec<&dyn Component> {
vec![&self.component]
}

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

impl AirTraceVerifier for FibonacciAir {
Expand Down Expand Up @@ -133,6 +138,10 @@ impl Air for MultiFibonacciAir {
.map(|c| c as &dyn Component)
.collect_vec()
}

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

impl AirTraceVerifier for MultiFibonacciAir {
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 @@ -65,6 +66,10 @@ impl Air for PoseidonAir {
fn components(&self) -> Vec<&dyn Component> {
vec![&self.component]
}

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

impl AirTraceVerifier for PoseidonAir {
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};
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 @@ -182,6 +183,10 @@ impl Air for WideFibAir {
fn components(&self) -> Vec<&dyn Component> {
vec![&self.component]
}

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

impl Component 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::N_COLUMNS;
use crate::trace_generation::registry::ComponentGenerationRegistry;
Expand Down Expand Up @@ -59,6 +59,10 @@ impl Air for SimdWideFibAir {
fn components(&self) -> Vec<&dyn Component> {
vec![&self.component]
}

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

impl AirTraceVerifier for SimdWideFibAir {
Expand Down

0 comments on commit 7fdbdf2

Please sign in to comment.