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 430485308..42ceceab1 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_plan.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_plan.rs @@ -3,7 +3,7 @@ use crate::base::{ commitment::Commitment, database::{ Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, MetadataAccessor, - OwnedTable, + OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -46,6 +46,9 @@ pub trait ProofPlan: Debug + Send + Sync + ProverEvaluate IndexSet; + + /// Return all the tables referenced in the Query + fn get_table_references(&self) -> IndexSet; } pub trait ProverEvaluate { 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 a4fa8a65a..e6e685673 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, TestAccessor, + MetadataAccessor, OwnedTable, OwnedTableTestAccessor, TableRef, TestAccessor, UnimplementedTestAccessor, }, map::IndexSet, @@ -109,6 +109,9 @@ impl ProofPlan for TrivialTestProofPlan { fn get_column_references(&self) -> IndexSet { unimplemented!("no real usage for this function yet") } + fn get_table_references(&self) -> IndexSet { + unimplemented!("no real usage for this function yet") + } } fn verify_a_trivial_query_proof_with_given_offset(n: usize, offset_generators: usize) { @@ -278,6 +281,9 @@ impl ProofPlan for SquareTestProofPlan { fn get_column_references(&self) -> IndexSet { unimplemented!("no real usage for this function yet") } + fn get_table_references(&self) -> IndexSet { + unimplemented!("no real usage for this function yet") + } } fn verify_a_proof_with_an_anchored_commitment_and_given_offset(offset_generators: usize) { @@ -481,6 +487,9 @@ impl ProofPlan for DoubleSquareTestProofPlan { fn get_column_references(&self) -> IndexSet { unimplemented!("no real usage for this function yet") } + fn get_table_references(&self) -> IndexSet { + unimplemented!("no real usage for this function yet") + } } fn verify_a_proof_with_an_intermediate_commitment_and_given_offset(offset_generators: usize) { @@ -677,6 +686,9 @@ impl ProofPlan for ChallengeTestProofPlan { fn get_column_references(&self) -> IndexSet { unimplemented!("no real usage for this function yet") } + fn get_table_references(&self) -> IndexSet { + unimplemented!("no real usage for this function yet") + } } fn verify_a_proof_with_a_post_result_challenge_and_given_offset(offset_generators: usize) { 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 5d299e408..d2db5df0e 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, TestAccessor, UnimplementedTestAccessor, + MetadataAccessor, OwnedTable, TableRef, TestAccessor, UnimplementedTestAccessor, }, map::IndexSet, proof::ProofError, @@ -88,6 +88,10 @@ impl ProofPlan for EmptyTestQueryExpr { fn get_column_references(&self) -> IndexSet { unimplemented!("no real usage for this function yet") } + + fn get_table_references(&self) -> IndexSet { + unimplemented!("no real usage for this function yet") + } } #[test] diff --git a/crates/proof-of-sql/src/sql/proof_plans/dyn_proof_plan.rs b/crates/proof-of-sql/src/sql/proof_plans/dyn_proof_plan.rs index c524a2c76..b7edcc70a 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/dyn_proof_plan.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/dyn_proof_plan.rs @@ -1,9 +1,21 @@ use super::{FilterExec, GroupByExec, ProjectionExec}; use crate::{ - base::{commitment::Commitment, database::Column, map::IndexSet}, - sql::proof::{ProofPlan, ProverEvaluate}, + base::{ + commitment::Commitment, + database::{ + Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, MetadataAccessor, + OwnedTable, TableRef, + }, + map::IndexSet, + proof::ProofError, + }, + sql::proof::{ + CountBuilder, FinalRoundBuilder, FirstRoundBuilder, ProofPlan, ProverEvaluate, + VerificationBuilder, + }, }; use alloc::vec::Vec; +use bumpalo::Bump; use serde::{Deserialize, Serialize}; /// The query plan for proving a query @@ -34,9 +46,9 @@ pub enum DynProofPlan { impl ProofPlan for DynProofPlan { fn count( &self, - builder: &mut crate::sql::proof::CountBuilder, - accessor: &dyn crate::base::database::MetadataAccessor, - ) -> Result<(), crate::base::proof::ProofError> { + builder: &mut CountBuilder, + accessor: &dyn MetadataAccessor, + ) -> Result<(), ProofError> { match self { DynProofPlan::Projection(expr) => expr.count(builder, accessor), DynProofPlan::GroupBy(expr) => expr.count(builder, accessor), @@ -44,7 +56,7 @@ impl ProofPlan for DynProofPlan { } } - fn get_length(&self, accessor: &dyn crate::base::database::MetadataAccessor) -> usize { + fn get_length(&self, accessor: &dyn MetadataAccessor) -> usize { match self { DynProofPlan::Projection(expr) => expr.get_length(accessor), DynProofPlan::GroupBy(expr) => expr.get_length(accessor), @@ -52,7 +64,7 @@ impl ProofPlan for DynProofPlan { } } - fn get_offset(&self, accessor: &dyn crate::base::database::MetadataAccessor) -> usize { + fn get_offset(&self, accessor: &dyn MetadataAccessor) -> usize { match self { DynProofPlan::Projection(expr) => expr.get_offset(accessor), DynProofPlan::GroupBy(expr) => expr.get_offset(accessor), @@ -63,10 +75,10 @@ impl ProofPlan for DynProofPlan { #[tracing::instrument(name = "DynProofPlan::verifier_evaluate", level = "debug", skip_all)] fn verifier_evaluate( &self, - builder: &mut crate::sql::proof::VerificationBuilder, - accessor: &dyn crate::base::database::CommitmentAccessor, - result: Option<&crate::base::database::OwnedTable>, - ) -> Result, crate::base::proof::ProofError> { + builder: &mut VerificationBuilder, + accessor: &dyn CommitmentAccessor, + result: Option<&OwnedTable>, + ) -> Result, ProofError> { match self { DynProofPlan::Projection(expr) => expr.verifier_evaluate(builder, accessor, result), DynProofPlan::GroupBy(expr) => expr.verifier_evaluate(builder, accessor, result), @@ -74,7 +86,7 @@ impl ProofPlan for DynProofPlan { } } - fn get_column_result_fields(&self) -> Vec { + fn get_column_result_fields(&self) -> Vec { match self { DynProofPlan::Projection(expr) => expr.get_column_result_fields(), DynProofPlan::GroupBy(expr) => expr.get_column_result_fields(), @@ -82,13 +94,21 @@ impl ProofPlan for DynProofPlan { } } - fn get_column_references(&self) -> IndexSet { + fn get_column_references(&self) -> IndexSet { match self { DynProofPlan::Projection(expr) => expr.get_column_references(), DynProofPlan::GroupBy(expr) => expr.get_column_references(), DynProofPlan::Filter(expr) => expr.get_column_references(), } } + + fn get_table_references(&self) -> IndexSet { + match self { + DynProofPlan::Projection(expr) => expr.get_table_references(), + DynProofPlan::GroupBy(expr) => expr.get_table_references(), + DynProofPlan::Filter(expr) => expr.get_table_references(), + } + } } impl ProverEvaluate for DynProofPlan { @@ -96,8 +116,8 @@ impl ProverEvaluate for DynProofPlan { fn result_evaluate<'a>( &self, input_length: usize, - alloc: &'a bumpalo::Bump, - accessor: &'a dyn crate::base::database::DataAccessor, + alloc: &'a Bump, + accessor: &'a dyn DataAccessor, ) -> Vec> { match self { DynProofPlan::Projection(expr) => expr.result_evaluate(input_length, alloc, accessor), @@ -106,7 +126,7 @@ impl ProverEvaluate for DynProofPlan { } } - fn first_round_evaluate(&self, builder: &mut crate::sql::proof::FirstRoundBuilder) { + fn first_round_evaluate(&self, builder: &mut FirstRoundBuilder) { match self { DynProofPlan::Projection(expr) => expr.first_round_evaluate(builder), DynProofPlan::GroupBy(expr) => expr.first_round_evaluate(builder), @@ -117,9 +137,9 @@ impl ProverEvaluate for DynProofPlan { #[tracing::instrument(name = "DynProofPlan::final_round_evaluate", level = "debug", skip_all)] fn final_round_evaluate<'a>( &self, - builder: &mut crate::sql::proof::FinalRoundBuilder<'a, C::Scalar>, - alloc: &'a bumpalo::Bump, - accessor: &'a dyn crate::base::database::DataAccessor, + builder: &mut FinalRoundBuilder<'a, C::Scalar>, + alloc: &'a Bump, + accessor: &'a dyn DataAccessor, ) -> Vec> { match self { DynProofPlan::Projection(expr) => expr.final_round_evaluate(builder, alloc, accessor), 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 4259d3d88..5a1b6106b 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, + DataAccessor, MetadataAccessor, OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -139,6 +139,10 @@ where columns } + + fn get_table_references(&self) -> IndexSet { + IndexSet::from_iter([self.table.table_ref]) + } } /// Alias for a filter expression with a honest prover. diff --git a/crates/proof-of-sql/src/sql/proof_plans/filter_exec_test.rs b/crates/proof-of-sql/src/sql/proof_plans/filter_exec_test.rs index c6252d133..062781985 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/filter_exec_test.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/filter_exec_test.rs @@ -153,6 +153,10 @@ fn we_can_correctly_fetch_all_the_referenced_columns() { ) ]) ); + + let ref_tables = provable_ast.get_table_references(); + + assert_eq!(ref_tables, IndexSet::from_iter([table_ref])); } #[test] 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 0a43da82f..385b8a2e7 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, + MetadataAccessor, OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -202,6 +202,10 @@ impl ProofPlan for GroupByExec { columns } + + fn get_table_references(&self) -> IndexSet { + IndexSet::from_iter([self.table.table_ref]) + } } impl ProverEvaluate for GroupByExec { 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 fb66bff00..f3038b310 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 @@ -3,7 +3,7 @@ use crate::{ commitment::Commitment, database::{ Column, ColumnField, ColumnRef, CommitmentAccessor, DataAccessor, MetadataAccessor, - OwnedTable, + OwnedTable, TableRef, }, map::IndexSet, proof::ProofError, @@ -92,6 +92,10 @@ impl ProofPlan for ProjectionExec { }); columns } + + fn get_table_references(&self) -> IndexSet { + IndexSet::from_iter([self.table.table_ref]) + } } impl ProverEvaluate for ProjectionExec { diff --git a/crates/proof-of-sql/src/sql/proof_plans/projection_exec_test.rs b/crates/proof-of-sql/src/sql/proof_plans/projection_exec_test.rs index 3addcfb17..c97ecf471 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/projection_exec_test.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/projection_exec_test.rs @@ -102,6 +102,10 @@ fn we_can_correctly_fetch_all_the_referenced_columns() { ), ]) ); + + let ref_tables = provable_ast.get_table_references(); + + assert_eq!(ref_tables, IndexSet::from_iter([table_ref])); } #[test]