Skip to content

Commit

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

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};

pub mod accumulation;
Expand Down Expand Up @@ -58,6 +59,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 @@ -222,6 +222,8 @@ pub fn verify(
);
}

air.verify_lookups(&proof.lookup_values)?;

channel.mix_felts(
&proof
.lookup_values
Expand Down Expand Up @@ -330,6 +332,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 @@ -347,6 +351,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 @@ -448,6 +453,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 @@ -120,6 +120,10 @@ impl Component for FibonacciComponent {
&mask[0][0][..1].try_into().unwrap(),
));
}

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

#[derive(Copy, Clone)]
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 @@ -140,6 +141,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};
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 @@ -253,6 +254,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::N_COLUMNS;
use crate::trace_generation::registry::ComponentGenerationRegistry;
Expand Down Expand Up @@ -128,6 +128,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 @@ -85,6 +85,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 f759f41

Please sign in to comment.