From e8048c4bc7f1ab92a4fbd1f5ac97e01521267261 Mon Sep 17 00:00:00 2001 From: Alon Haramati Date: Mon, 24 Jun 2024 17:12:43 +0300 Subject: [PATCH] Verify lookups. --- crates/prover/src/core/air/air_ext.rs | 8 +++++++- crates/prover/src/core/air/mod.rs | 4 ++++ crates/prover/src/core/prover/mod.rs | 9 +++++++++ crates/prover/src/examples/fibonacci/component.rs | 6 +++++- crates/prover/src/examples/poseidon/mod.rs | 5 +++++ crates/prover/src/examples/wide_fibonacci/component.rs | 5 +++++ crates/prover/src/examples/wide_fibonacci/simd.rs | 6 +++++- crates/prover/src/trace_generation/registry.rs | 7 +++++++ 8 files changed, 47 insertions(+), 3 deletions(-) diff --git a/crates/prover/src/core/air/air_ext.rs b/crates/prover/src/core/air/air_ext.rs index 26d50cbb6..46286a71c 100644 --- a/crates/prover/src/core/air/air_ext.rs +++ b/crates/prover/src/core/air/air_ext.rs @@ -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}; @@ -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 AirExt for A {} diff --git a/crates/prover/src/core/air/mod.rs b/crates/prover/src/core/air/mod.rs index 0b32c789f..471e4667b 100644 --- a/crates/prover/src/core/air/mod.rs +++ b/crates/prover/src/core/air/mod.rs @@ -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; @@ -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: Component { diff --git a/crates/prover/src/core/prover/mod.rs b/crates/prover/src/core/prover/mod.rs index c829456df..bbf24d9b4 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -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(); @@ -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( @@ -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; @@ -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 for TestComponent { diff --git a/crates/prover/src/examples/fibonacci/component.rs b/crates/prover/src/examples/fibonacci/component.rs index 73a8161b5..9b6cb3e0c 100644 --- a/crates/prover/src/examples/fibonacci/component.rs +++ b/crates/prover/src/examples/fibonacci/component.rs @@ -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; @@ -128,6 +128,10 @@ impl Component for FibonacciComponent { ), ); } + + fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> { + Ok(()) + } } impl ComponentTraceGenerator for FibonacciComponent { diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index 6057f211a..816c73d0c 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -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}; @@ -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)] diff --git a/crates/prover/src/examples/wide_fibonacci/component.rs b/crates/prover/src/examples/wide_fibonacci/component.rs index 714ada265..5b3d05abb 100644 --- a/crates/prover/src/examples/wide_fibonacci/component.rs +++ b/crates/prover/src/examples/wide_fibonacci/component.rs @@ -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; @@ -252,6 +253,10 @@ impl Component for WideFibComponent { constraint_zero_domain, ); } + + fn verify_lookups(&self, _lookup_values: &LookupValues) -> Result<(), VerificationError> { + Ok(()) + } } impl ComponentTraceGenerator for WideFibComponent { diff --git a/crates/prover/src/examples/wide_fibonacci/simd.rs b/crates/prover/src/examples/wide_fibonacci/simd.rs index d3ba4adbd..fd5435569 100644 --- a/crates/prover/src/examples/wide_fibonacci/simd.rs +++ b/crates/prover/src/examples/wide_fibonacci/simd.rs @@ -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; @@ -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 for SimdWideFibAir { diff --git a/crates/prover/src/trace_generation/registry.rs b/crates/prover/src/trace_generation/registry.rs index dcb2d7e66..176cccee1 100644 --- a/crates/prover/src/trace_generation/registry.rs +++ b/crates/prover/src/trace_generation/registry.rs @@ -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)>;