From ac881cbde0c1daeef29a5053fd14e6da0e29c664 Mon Sep 17 00:00:00 2001 From: Ian Joiner <14581281+iajoiner@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:01:22 -0500 Subject: [PATCH 1/3] feat: compute min and max of indices for multi-table queries - add `indexset!` macro - compute min and max of indices for multi-table queries --- crates/proof-of-sql/src/base/database/mod.rs | 1 + crates/proof-of-sql/src/base/map.rs | 18 +++++++ .../proof-of-sql/src/sql/proof/proof_plan.rs | 15 ++++++ .../proof-of-sql/src/sql/proof/query_proof.rs | 54 +++++++++---------- .../src/sql/proof/query_proof_test.rs | 44 ++++++++++----- .../sql/proof/verifiable_query_result_test.rs | 22 ++++++-- .../verifiable_query_result_test_utility.rs | 13 ++++- 7 files changed, 121 insertions(+), 46 deletions(-) diff --git a/crates/proof-of-sql/src/base/database/mod.rs b/crates/proof-of-sql/src/base/database/mod.rs index 234d077ec..5516fb61b 100644 --- a/crates/proof-of-sql/src/base/database/mod.rs +++ b/crates/proof-of-sql/src/base/database/mod.rs @@ -66,6 +66,7 @@ pub use expression_evaluation_error::{ExpressionEvaluationError, ExpressionEvalu mod test_accessor; pub use test_accessor::TestAccessor; #[cfg(test)] +#[allow(unused_imports)] pub(crate) use test_accessor::UnimplementedTestAccessor; #[cfg(test)] diff --git a/crates/proof-of-sql/src/base/map.rs b/crates/proof-of-sql/src/base/map.rs index 8eff85192..277cceaf7 100644 --- a/crates/proof-of-sql/src/base/map.rs +++ b/crates/proof-of-sql/src/base/map.rs @@ -21,4 +21,22 @@ macro_rules! indexmap_macro { }; } +/// Create an [`IndexSet`][self::IndexSet] from a list of values +#[cfg(test)] +macro_rules! indexset_macro { + ($($value:expr,)+) => { $crate::base::map::indexset!($($value),+) }; + ($($value:expr),*) => { + { + const CAP: usize = <[()]>::len(&[$({ stringify!($value); }),*]); + let mut set = $crate::base::map::IndexSet::with_capacity_and_hasher(CAP, <_>::default()); + $( + set.insert($value); + )* + set + } + }; +} + pub(crate) use indexmap_macro as indexmap; +#[cfg(test)] +pub(crate) use indexset_macro as indexset; diff --git a/crates/proof-of-sql/src/sql/proof/proof_plan.rs b/crates/proof-of-sql/src/sql/proof/proof_plan.rs index 6041c8667..b0539f54f 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_plan.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_plan.rs @@ -46,6 +46,21 @@ pub trait ProofPlan: Debug + Send + Sync + ProverEvaluate { /// Return all the tables referenced in the Query fn get_table_references(&self) -> IndexSet; + + /// Return the row number range of tables referenced in the Query + /// + /// Basically we are looking for the smallest offset and the largest offset + length + /// so that we have an index range of the table rows that the query is referencing. + fn get_index_range(&self, accessor: &dyn MetadataAccessor) -> (usize, usize) { + self.get_table_references().iter().fold( + (usize::MAX, 0), + |(min, max): (usize, usize), table_ref| { + let length = accessor.get_length(*table_ref); + let offset = accessor.get_offset(*table_ref); + (min.min(offset), max.max(offset + length)) + }, + ) + } } #[enum_dispatch::enum_dispatch(DynProofPlan)] diff --git a/crates/proof-of-sql/src/sql/proof/query_proof.rs b/crates/proof-of-sql/src/sql/proof/query_proof.rs index dfcf6575a..3ba379378 100644 --- a/crates/proof-of-sql/src/sql/proof/query_proof.rs +++ b/crates/proof-of-sql/src/sql/proof/query_proof.rs @@ -47,15 +47,15 @@ impl QueryProof { accessor: &impl DataAccessor, setup: &CP::ProverPublicSetup<'_>, ) -> (Self, ProvableQueryResult) { - let table_length = expr.get_length(accessor); - let num_sumcheck_variables = cmp::max(log2_up(table_length), 1); - let generator_offset = expr.get_offset(accessor); + let (min_row_num, max_row_num) = expr.get_index_range(accessor); + let range_length = max_row_num - min_row_num; + let num_sumcheck_variables = cmp::max(log2_up(range_length), 1); assert!(num_sumcheck_variables > 0); let alloc = Bump::new(); // Evaluate query result - let result_cols = expr.result_evaluate(table_length, &alloc, accessor); + let result_cols = expr.result_evaluate(range_length, &alloc, accessor); let output_length = result_cols.first().map_or(0, Column::len); let provable_result = ProvableQueryResult::new(output_length as u64, &result_cols); @@ -65,7 +65,7 @@ impl QueryProof { // construct a transcript for the proof let mut transcript: Keccak256Transcript = - make_transcript(expr, &provable_result, table_length, generator_offset); + make_transcript(expr, &provable_result, range_length, min_row_num); // These are the challenges that will be consumed by the proof // Specifically, these are the challenges that the verifier sends to @@ -78,14 +78,13 @@ impl QueryProof { .collect(); let mut builder = - FinalRoundBuilder::new(table_length, num_sumcheck_variables, post_result_challenges); + FinalRoundBuilder::new(range_length, num_sumcheck_variables, post_result_challenges); expr.final_round_evaluate(&mut builder, &alloc, accessor); let num_sumcheck_variables = builder.num_sumcheck_variables(); - let table_length = builder.table_length(); // commit to any intermediate MLEs - let commitments = builder.commit_intermediate_mles(generator_offset, setup); + let commitments = builder.commit_intermediate_mles(min_row_num, setup); // add the commitments and bit distributions to the proof extend_transcript(&mut transcript, &commitments, builder.bit_distributions()); @@ -98,7 +97,7 @@ impl QueryProof { .collect(); let poly = builder.make_sumcheck_polynomial(&SumcheckRandomScalars::new( &random_scalars, - table_length, + range_length, num_sumcheck_variables, )); @@ -107,7 +106,7 @@ impl QueryProof { let sumcheck_proof = SumcheckProof::create(&mut transcript, &mut evaluation_point, &poly); // evaluate the MLEs used in sumcheck except for the result columns - let mut evaluation_vec = vec![Zero::zero(); table_length]; + let mut evaluation_vec = vec![Zero::zero(); range_length]; compute_evaluation_vector(&mut evaluation_vec, &evaluation_point); let pcs_proof_evaluations = builder.evaluate_pcs_proof_mles(&evaluation_vec); @@ -127,7 +126,7 @@ impl QueryProof { &mut transcript, &folded_mle, &evaluation_point, - generator_offset as u64, + min_row_num as u64, setup, ); @@ -150,12 +149,13 @@ impl QueryProof { result: &ProvableQueryResult, setup: &CP::VerifierPublicSetup<'_>, ) -> QueryResult { - let input_length = expr.get_length(accessor); - let output_length = result.table_length(); - let generator_offset = expr.get_offset(accessor); - let num_sumcheck_variables = cmp::max(log2_up(input_length), 1); + let (min_row_num, max_row_num) = expr.get_index_range(accessor); + let range_length = max_row_num - min_row_num; + let num_sumcheck_variables = cmp::max(log2_up(range_length), 1); assert!(num_sumcheck_variables > 0); + let output_length = result.table_length(); + // validate bit decompositions for dist in &self.bit_distributions { if !dist.is_valid() { @@ -181,7 +181,7 @@ impl QueryProof { // construct a transcript for the proof let mut transcript: Keccak256Transcript = - make_transcript(expr, result, input_length, generator_offset); + make_transcript(expr, result, range_length, min_row_num); // These are the challenges that will be consumed by the proof // Specifically, these are the challenges that the verifier sends to @@ -203,7 +203,7 @@ impl QueryProof { .take(num_random_scalars) .collect(); let sumcheck_random_scalars = - SumcheckRandomScalars::new(&random_scalars, input_length, num_sumcheck_variables); + SumcheckRandomScalars::new(&random_scalars, range_length, num_sumcheck_variables); // verify sumcheck up to the evaluation check let poly_info = CompositePolynomialInfo { @@ -232,14 +232,14 @@ impl QueryProof { // pass over the provable AST to fill in the verification builder let sumcheck_evaluations = SumcheckMleEvaluations::new( - input_length, + range_length, output_length, &subclaim.evaluation_point, &sumcheck_random_scalars, &self.pcs_proof_evaluations, ); let mut builder = VerificationBuilder::new( - generator_offset, + min_row_num, sumcheck_evaluations, &self.bit_distributions, &self.commitments, @@ -279,8 +279,8 @@ impl QueryProof { builder.inner_product_multipliers(), &product, &subclaim.evaluation_point, - generator_offset as u64, - input_length, + min_row_num as u64, + range_length, setup, ) .map_err(|_e| ProofError::VerificationError { @@ -315,9 +315,9 @@ impl QueryProof { /// * `result` - A reference to a `ProvableQueryResult`, which is the result /// of a query that needs to be proven. /// -/// * `table_length` - The length of the table used in the proof, as a `usize`. +/// * `range_length` - The length of the range of the generator used in the proof, as a `usize`. /// -/// * `generator_offset` - The offset of the generator used in the proof, as a `usize`. +/// * `min_row_num` - The smallest offset of the generator used in the proof, as a `usize`. /// /// # Returns /// This function returns a `merlin::Transcript`. The transcript is a record @@ -326,14 +326,14 @@ impl QueryProof { fn make_transcript( expr: &(impl ProofPlan + Serialize), result: &ProvableQueryResult, - table_length: usize, - generator_offset: usize, + range_length: usize, + min_row_num: usize, ) -> T { let mut transcript = T::new(); transcript.extend_serialize_as_le(result); transcript.extend_serialize_as_le(expr); - transcript.extend_serialize_as_le(&table_length); - transcript.extend_serialize_as_le(&generator_offset); + transcript.extend_serialize_as_le(&range_length); + transcript.extend_serialize_as_le(&min_row_num); transcript } diff --git a/crates/proof-of-sql/src/sql/proof/query_proof_test.rs b/crates/proof-of-sql/src/sql/proof/query_proof_test.rs index 5943a19b1..6467d8d46 100644 --- a/crates/proof-of-sql/src/sql/proof/query_proof_test.rs +++ b/crates/proof-of-sql/src/sql/proof/query_proof_test.rs @@ -7,10 +7,9 @@ use crate::{ database::{ owned_table_utility::{bigint, owned_table}, Column, ColumnField, ColumnRef, ColumnType, CommitmentAccessor, DataAccessor, - MetadataAccessor, OwnedTable, OwnedTableTestAccessor, TableRef, TestAccessor, - UnimplementedTestAccessor, + MetadataAccessor, OwnedTable, OwnedTableTestAccessor, TableRef, }, - map::IndexSet, + map::{indexset, IndexSet}, proof::ProofError, scalar::{Curve25519Scalar, Scalar}, }, @@ -59,7 +58,7 @@ impl ProverEvaluate for TrivialTestProofPlan { alloc: &'a Bump, _accessor: &'a dyn DataAccessor, ) -> Vec> { - let col = alloc.alloc_slice_fill_copy(builder.table_length(), self.column_fill_value); + let col = alloc.alloc_slice_fill_copy(self.length, self.column_fill_value); builder.produce_intermediate_mle(col as &[_]); builder.produce_sumcheck_subpolynomial( SumcheckSubpolynomialType::Identity, @@ -106,7 +105,7 @@ impl ProofPlan for TrivialTestProofPlan { unimplemented!("no real usage for this function yet") } fn get_table_references(&self) -> IndexSet { - unimplemented!("no real usage for this function yet") + indexset! {TableRef::new("sxt.test".parse().unwrap())} } } @@ -116,7 +115,13 @@ fn verify_a_trivial_query_proof_with_given_offset(n: usize, offset_generators: u offset: offset_generators, ..Default::default() }; - let accessor = UnimplementedTestAccessor::new_empty(); + let column: Vec = vec![0_i64; n]; + let accessor = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("a1", column)]), + offset_generators, + (), + ); let (proof, result) = QueryProof::::new(&expr, &accessor, &()); let QueryData { verification_hash, @@ -149,7 +154,12 @@ fn verify_fails_if_the_summation_in_sumcheck_isnt_zero() { column_fill_value: 123, ..Default::default() }; - let accessor = UnimplementedTestAccessor::new_empty(); + let accessor = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("a1", [123_i64; 2])]), + 0, + (), + ); let (proof, result) = QueryProof::::new(&expr, &accessor, &()); assert!(proof.verify(&expr, &accessor, &result, &()).is_err()); } @@ -162,7 +172,12 @@ fn verify_fails_if_the_sumcheck_evaluation_isnt_correct() { evaluation: 123, ..Default::default() }; - let accessor = UnimplementedTestAccessor::new_empty(); + let accessor = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("a1", [123_i64; 2])]), + 0, + (), + ); let (proof, result) = QueryProof::::new(&expr, &accessor, &()); assert!(proof.verify(&expr, &accessor, &result, &()).is_err()); } @@ -175,7 +190,12 @@ fn verify_fails_if_counts_dont_match() { anchored_mle_count: 1, ..Default::default() }; - let accessor = UnimplementedTestAccessor::new_empty(); + let accessor = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("a1", [0_i64; 2])]), + 0, + (), + ); let (proof, result) = QueryProof::::new(&expr, &accessor, &()); assert!(proof.verify(&expr, &accessor, &result, &()).is_err()); } @@ -274,7 +294,7 @@ impl ProofPlan for SquareTestProofPlan { unimplemented!("no real usage for this function yet") } fn get_table_references(&self) -> IndexSet { - unimplemented!("no real usage for this function yet") + indexset! {TableRef::new("sxt.test".parse().unwrap())} } } @@ -476,7 +496,7 @@ impl ProofPlan for DoubleSquareTestProofPlan { unimplemented!("no real usage for this function yet") } fn get_table_references(&self) -> IndexSet { - unimplemented!("no real usage for this function yet") + indexset! {TableRef::new("sxt.test".parse().unwrap())} } } @@ -671,7 +691,7 @@ impl ProofPlan for ChallengeTestProofPlan { unimplemented!("no real usage for this function yet") } fn get_table_references(&self) -> IndexSet { - unimplemented!("no real usage for this function yet") + indexset! {TableRef::new("sxt.test".parse().unwrap())} } } diff --git a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs index b1dfe6914..a8f5ff37a 100644 --- a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs +++ b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs @@ -8,9 +8,9 @@ use crate::{ database::{ owned_table_utility::{bigint, owned_table}, Column, ColumnField, ColumnRef, ColumnType, CommitmentAccessor, DataAccessor, - MetadataAccessor, OwnedTable, TableRef, TestAccessor, UnimplementedTestAccessor, + MetadataAccessor, OwnedTable, OwnedTableTestAccessor, TableRef, }, - map::IndexSet, + map::{indexset, IndexSet}, proof::ProofError, scalar::Scalar, }, @@ -86,7 +86,7 @@ impl ProofPlan for EmptyTestQueryExpr { } fn get_table_references(&self) -> IndexSet { - unimplemented!("no real usage for this function yet") + indexset! {TableRef::new("sxt.test".parse().unwrap())} } } @@ -96,7 +96,13 @@ fn we_can_verify_queries_on_an_empty_table() { columns: 1, ..Default::default() }; - let accessor = UnimplementedTestAccessor::new_empty(); + let column: Vec = vec![0_i64; 0]; + let accessor = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("a1", column)]), + 0, + (), + ); let res = VerifiableQueryResult::::new(&expr, &accessor, &()); let QueryData { verification_hash: _, @@ -112,7 +118,13 @@ fn empty_verification_fails_if_the_result_contains_non_null_members() { columns: 1, ..Default::default() }; - let accessor = UnimplementedTestAccessor::new_empty(); + let column: Vec = vec![0_i64; 0]; + let accessor = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("a1", column)]), + 0, + (), + ); let res = VerifiableQueryResult:: { provable_result: Some(ProvableQueryResult::default()), proof: None, diff --git a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs index 8835fed8a..19ec95691 100644 --- a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs +++ b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test_utility.rs @@ -4,7 +4,10 @@ use super::{ }; use crate::base::{ commitment::{Commitment, CommittableColumn}, - database::{Column, CommitmentAccessor, OwnedTableTestAccessor, TableRef, TestAccessor}, + database::{ + owned_table_utility::*, Column, CommitmentAccessor, OwnedTableTestAccessor, TableRef, + TestAccessor, + }, scalar::Curve25519Scalar, }; use blitzar::proof::InnerProductProof; @@ -102,7 +105,13 @@ fn tamper_no_result( length: 1, ..Default::default() }; - let accessor_p = OwnedTableTestAccessor::::new_empty_with_setup(()); + let column = vec![1_i64; 1]; + let accessor_p = OwnedTableTestAccessor::::new_from_table( + "sxt.test".parse().unwrap(), + owned_table([bigint("bogus_col", column)]), + 0, + (), + ); let (proof, _result) = QueryProof::new(&expr_p, &accessor_p, &()); res_p.proof = Some(proof); assert!(res_p.verify(expr, accessor, &()).is_err()); From 4c1d451ee54742a5f1360f3df6c2419da108c4e8 Mon Sep 17 00:00:00 2001 From: Ian Joiner <14581281+iajoiner@users.noreply.github.com> Date: Sun, 10 Nov 2024 01:36:23 -0500 Subject: [PATCH 2/3] fix: move `get_index_range` to `query_proof.rs` --- .../proof-of-sql/src/sql/proof/proof_plan.rs | 15 ----------- .../proof-of-sql/src/sql/proof/query_proof.rs | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/crates/proof-of-sql/src/sql/proof/proof_plan.rs b/crates/proof-of-sql/src/sql/proof/proof_plan.rs index b0539f54f..6041c8667 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_plan.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_plan.rs @@ -46,21 +46,6 @@ pub trait ProofPlan: Debug + Send + Sync + ProverEvaluate { /// Return all the tables referenced in the Query fn get_table_references(&self) -> IndexSet; - - /// Return the row number range of tables referenced in the Query - /// - /// Basically we are looking for the smallest offset and the largest offset + length - /// so that we have an index range of the table rows that the query is referencing. - fn get_index_range(&self, accessor: &dyn MetadataAccessor) -> (usize, usize) { - self.get_table_references().iter().fold( - (usize::MAX, 0), - |(min, max): (usize, usize), table_ref| { - let length = accessor.get_length(*table_ref); - let offset = accessor.get_offset(*table_ref); - (min.min(offset), max.max(offset + length)) - }, - ) - } } #[enum_dispatch::enum_dispatch(DynProofPlan)] diff --git a/crates/proof-of-sql/src/sql/proof/query_proof.rs b/crates/proof-of-sql/src/sql/proof/query_proof.rs index 3ba379378..64e7869dd 100644 --- a/crates/proof-of-sql/src/sql/proof/query_proof.rs +++ b/crates/proof-of-sql/src/sql/proof/query_proof.rs @@ -6,7 +6,7 @@ use crate::{ base::{ bit::BitDistribution, commitment::CommitmentEvaluationProof, - database::{Column, CommitmentAccessor, DataAccessor}, + database::{Column, CommitmentAccessor, DataAccessor, MetadataAccessor, TableRef}, math::log2_up, polynomial::{compute_evaluation_vector, CompositePolynomialInfo}, proof::{Keccak256Transcript, ProofError, Transcript}, @@ -20,6 +20,26 @@ use core::cmp; use num_traits::Zero; use serde::{Deserialize, Serialize}; +/// Return the row number range of tables referenced in the Query +/// +/// Basically we are looking for the smallest offset and the largest offset + length +/// so that we have an index range of the table rows that the query is referencing. +fn get_index_range( + accessor: &dyn MetadataAccessor, + table_refs: impl IntoIterator, +) -> (usize, usize) { + table_refs + .into_iter() + .map(|table_ref| { + let length = accessor.get_length(table_ref); + let offset = accessor.get_offset(table_ref); + (offset, offset + length) + }) + .reduce(|(min_start, max_end), (start, end)| (min_start.min(start), max_end.max(end))) + // Only applies to `EmptyExec` where there are no tables + .unwrap_or((0, 1)) +} + /// The proof for a query. /// /// Note: Because the class is deserialized from untrusted data, it @@ -47,7 +67,7 @@ impl QueryProof { accessor: &impl DataAccessor, setup: &CP::ProverPublicSetup<'_>, ) -> (Self, ProvableQueryResult) { - let (min_row_num, max_row_num) = expr.get_index_range(accessor); + let (min_row_num, max_row_num) = get_index_range(accessor, expr.get_table_references()); let range_length = max_row_num - min_row_num; let num_sumcheck_variables = cmp::max(log2_up(range_length), 1); assert!(num_sumcheck_variables > 0); @@ -149,7 +169,7 @@ impl QueryProof { result: &ProvableQueryResult, setup: &CP::VerifierPublicSetup<'_>, ) -> QueryResult { - let (min_row_num, max_row_num) = expr.get_index_range(accessor); + let (min_row_num, max_row_num) = get_index_range(accessor, expr.get_table_references()); let range_length = max_row_num - min_row_num; let num_sumcheck_variables = cmp::max(log2_up(range_length), 1); assert!(num_sumcheck_variables > 0); From e09d93a98a9a1e4163b9513ffb256c001caeef3c Mon Sep 17 00:00:00 2001 From: Ian Joiner <14581281+iajoiner@users.noreply.github.com> Date: Sun, 10 Nov 2024 01:44:00 -0500 Subject: [PATCH 3/3] refactor!: remove `ProofPlan::get_offset` and `ProofPlan::get_length` --- .../proof-of-sql/src/sql/proof/proof_plan.rs | 11 +++----- .../src/sql/proof/query_proof_test.rs | 26 +------------------ .../sql/proof/verifiable_query_result_test.rs | 9 ++----- .../src/sql/proof_plans/empty_exec.rs | 11 +------- .../src/sql/proof_plans/filter_exec.rs | 10 +------ .../src/sql/proof_plans/group_by_exec.rs | 10 +------ .../src/sql/proof_plans/projection_exec.rs | 11 +------- 7 files changed, 11 insertions(+), 77 deletions(-) diff --git a/crates/proof-of-sql/src/sql/proof/proof_plan.rs b/crates/proof-of-sql/src/sql/proof/proof_plan.rs index 6041c8667..d2cda0b80 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_plan.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_plan.rs @@ -19,15 +19,12 @@ pub trait ProofPlan: Debug + Send + Sync + ProverEvaluate { /// Count terms used within the Query's proof fn count(&self, builder: &mut CountBuilder) -> Result<(), ProofError>; - /// The length of the input table - fn get_length(&self, accessor: &dyn MetadataAccessor) -> usize; - - /// The offset of the query, that is, how many rows to skip before starting to read the input table - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize; - /// Check if the input table is empty fn is_empty(&self, accessor: &dyn MetadataAccessor) -> bool { - self.get_length(accessor) == 0 + let table_refs = self.get_table_references(); + table_refs + .iter() + .all(|table_ref| accessor.get_length(*table_ref) == 0) } /// Form components needed to verify and proof store into `VerificationBuilder` diff --git a/crates/proof-of-sql/src/sql/proof/query_proof_test.rs b/crates/proof-of-sql/src/sql/proof/query_proof_test.rs index 6467d8d46..96db177d5 100644 --- a/crates/proof-of-sql/src/sql/proof/query_proof_test.rs +++ b/crates/proof-of-sql/src/sql/proof/query_proof_test.rs @@ -7,7 +7,7 @@ use crate::{ database::{ owned_table_utility::{bigint, owned_table}, Column, ColumnField, ColumnRef, ColumnType, CommitmentAccessor, DataAccessor, - MetadataAccessor, OwnedTable, OwnedTableTestAccessor, TableRef, + OwnedTable, OwnedTableTestAccessor, TableRef, }, map::{indexset, IndexSet}, proof::ProofError, @@ -75,12 +75,6 @@ impl ProofPlan for TrivialTestProofPlan { builder.count_anchored_mles(self.anchored_mle_count); Ok(()) } - fn get_length(&self, _accessor: &dyn MetadataAccessor) -> usize { - self.length - } - fn get_offset(&self, _accessor: &dyn MetadataAccessor) -> usize { - self.offset - } fn verifier_evaluate( &self, builder: &mut VerificationBuilder, @@ -261,12 +255,6 @@ impl ProofPlan for SquareTestProofPlan { builder.count_anchored_mles(1); Ok(()) } - fn get_length(&self, _accessor: &dyn MetadataAccessor) -> usize { - 2 - } - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_offset("sxt.test".parse().unwrap()) - } fn verifier_evaluate( &self, builder: &mut VerificationBuilder, @@ -455,12 +443,6 @@ impl ProofPlan for DoubleSquareTestProofPlan { builder.count_anchored_mles(1); Ok(()) } - fn get_length(&self, _accessor: &dyn MetadataAccessor) -> usize { - 2 - } - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_offset("sxt.test".parse().unwrap()) - } fn verifier_evaluate( &self, builder: &mut VerificationBuilder, @@ -657,12 +639,6 @@ impl ProofPlan for ChallengeTestProofPlan { builder.count_post_result_challenges(2); Ok(()) } - fn get_length(&self, _accessor: &dyn MetadataAccessor) -> usize { - 2 - } - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_offset("sxt.test".parse().unwrap()) - } fn verifier_evaluate( &self, builder: &mut VerificationBuilder, diff --git a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs index a8f5ff37a..ab739c372 100644 --- a/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs +++ b/crates/proof-of-sql/src/sql/proof/verifiable_query_result_test.rs @@ -8,7 +8,7 @@ use crate::{ database::{ owned_table_utility::{bigint, owned_table}, Column, ColumnField, ColumnRef, ColumnType, CommitmentAccessor, DataAccessor, - MetadataAccessor, OwnedTable, OwnedTableTestAccessor, TableRef, + OwnedTable, OwnedTableTestAccessor, TableRef, }, map::{indexset, IndexSet}, proof::ProofError, @@ -55,12 +55,7 @@ impl ProofPlan for EmptyTestQueryExpr { builder.count_intermediate_mles(self.columns); Ok(()) } - fn get_length(&self, _accessor: &dyn MetadataAccessor) -> usize { - self.length - } - fn get_offset(&self, _accessor: &dyn MetadataAccessor) -> usize { - 0 - } + fn verifier_evaluate( &self, builder: &mut VerificationBuilder, diff --git a/crates/proof-of-sql/src/sql/proof_plans/empty_exec.rs b/crates/proof-of-sql/src/sql/proof_plans/empty_exec.rs index 5e3d65a08..575c781c8 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/empty_exec.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/empty_exec.rs @@ -2,8 +2,7 @@ use crate::{ base::{ commitment::Commitment, database::{ - Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, MetadataAccessor, - OwnedTable, TableRef, + Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -42,14 +41,6 @@ impl ProofPlan for EmptyExec { Ok(()) } - fn get_length(&self, _accessor: &dyn MetadataAccessor) -> usize { - 0 - } - - fn get_offset(&self, _accessor: &dyn MetadataAccessor) -> usize { - 0 - } - #[allow(unused_variables)] fn verifier_evaluate( &self, diff --git a/crates/proof-of-sql/src/sql/proof_plans/filter_exec.rs b/crates/proof-of-sql/src/sql/proof_plans/filter_exec.rs index 3f857937b..5ee0cd40f 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/filter_exec.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/filter_exec.rs @@ -4,7 +4,7 @@ use crate::{ commitment::Commitment, database::{ filter_util::filter_columns, Column, ColumnField, ColumnRef, CommitmentAccessor, - DataAccessor, MetadataAccessor, OwnedTable, TableRef, + DataAccessor, OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -73,14 +73,6 @@ where Ok(()) } - fn get_length(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_length(self.table.table_ref) - } - - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_offset(self.table.table_ref) - } - #[allow(unused_variables)] fn verifier_evaluate( &self, diff --git a/crates/proof-of-sql/src/sql/proof_plans/group_by_exec.rs b/crates/proof-of-sql/src/sql/proof_plans/group_by_exec.rs index ff0020e33..bc369377f 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/group_by_exec.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/group_by_exec.rs @@ -7,7 +7,7 @@ use crate::{ aggregate_columns, compare_indexes_by_owned_columns, AggregatedColumns, }, Column, ColumnField, ColumnRef, ColumnType, CommitmentAccessor, DataAccessor, - MetadataAccessor, OwnedTable, TableRef, + OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -88,14 +88,6 @@ impl ProofPlan for GroupByExec { Ok(()) } - fn get_length(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_length(self.table.table_ref) - } - - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_offset(self.table.table_ref) - } - #[allow(unused_variables)] fn verifier_evaluate( &self, diff --git a/crates/proof-of-sql/src/sql/proof_plans/projection_exec.rs b/crates/proof-of-sql/src/sql/proof_plans/projection_exec.rs index f941478f3..dd40414ea 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/projection_exec.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/projection_exec.rs @@ -2,8 +2,7 @@ use crate::{ base::{ commitment::Commitment, database::{ - Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, MetadataAccessor, - OwnedTable, TableRef, + Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -51,14 +50,6 @@ impl ProofPlan for ProjectionExec { Ok(()) } - fn get_length(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_length(self.table.table_ref) - } - - fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { - accessor.get_offset(self.table.table_ref) - } - #[allow(unused_variables)] fn verifier_evaluate( &self,