From f759f417b907f24cc3a937f8acccd556e75c861d 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 | 7 +++++++ 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(+), 2 deletions(-) diff --git a/crates/prover/src/core/air/air_ext.rs b/crates/prover/src/core/air/air_ext.rs index abc47b960..0a9c091c2 100644 --- a/crates/prover/src/core/air/air_ext.rs +++ b/crates/prover/src/core/air/air_ext.rs @@ -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}; @@ -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 AirExt for A {} diff --git a/crates/prover/src/core/air/mod.rs b/crates/prover/src/core/air/mod.rs index 3595ba91b..80333b601 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}; pub mod accumulation; @@ -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: Component { diff --git a/crates/prover/src/core/prover/mod.rs b/crates/prover/src/core/prover/mod.rs index 1ba46fe7f..84ef0effa 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -222,6 +222,8 @@ pub fn verify( ); } + air.verify_lookups(&proof.lookup_values)?; + channel.mix_felts( &proof .lookup_values @@ -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( @@ -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; @@ -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 for TestComponent { diff --git a/crates/prover/src/examples/fibonacci/component.rs b/crates/prover/src/examples/fibonacci/component.rs index 40f298951..1d30adbd1 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; @@ -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)] diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index 85a51db83..5f64847c7 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}; @@ -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)] diff --git a/crates/prover/src/examples/wide_fibonacci/component.rs b/crates/prover/src/examples/wide_fibonacci/component.rs index 91edfe8f3..1c122549e 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}; 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; @@ -253,6 +254,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 1055ad962..6f4e8abd2 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::N_COLUMNS; use crate::trace_generation::registry::ComponentGenerationRegistry; @@ -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 for SimdWideFibAir { diff --git a/crates/prover/src/trace_generation/registry.rs b/crates/prover/src/trace_generation/registry.rs index 181ff6c8b..51f1b1acb 100644 --- a/crates/prover/src/trace_generation/registry.rs +++ b/crates/prover/src/trace_generation/registry.rs @@ -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)>;