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 de961efea..dfa0bc26e 100644 --- a/crates/proof-of-sql/src/sql/proof/proof_plan.rs +++ b/crates/proof-of-sql/src/sql/proof/proof_plan.rs @@ -38,7 +38,7 @@ pub trait ProofPlan: Debug + Send + Sync + ProverEvaluate, accessor: &dyn CommitmentAccessor, result: Option<&OwnedTable>, - ) -> Result<(), ProofError>; + ) -> Result, ProofError>; /// Return all the result column fields fn get_column_result_fields(&self) -> Vec; 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 ede164b20..41a106dad 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 @@ -91,10 +91,10 @@ impl ProofPlan for TrivialTestProofPlan { builder: &mut VerificationBuilder, _accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { assert_eq!(builder.consume_result_mle(), C::Scalar::ZERO); builder.produce_sumcheck_subpolynomial_evaluation(&C::Scalar::from(self.evaluation)); - Ok(()) + Ok(vec![C::Scalar::ZERO]) } fn get_column_result_fields(&self) -> Vec { vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)] @@ -266,7 +266,7 @@ impl ProofPlan for SquareTestProofPlan { builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { let res_eval = builder.consume_result_mle(); let x_commit = C::Scalar::from(self.anchored_commit_multiplier) * accessor.get_commitment(ColumnRef::new( @@ -277,7 +277,7 @@ impl ProofPlan for SquareTestProofPlan { let x_eval = builder.consume_anchored_mle(x_commit); let eval = builder.mle_evaluations.random_evaluation * (res_eval - x_eval * x_eval); builder.produce_sumcheck_subpolynomial_evaluation(&eval); - Ok(()) + Ok(vec![res_eval]) } fn get_column_result_fields(&self) -> Vec { vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)] @@ -459,7 +459,7 @@ impl ProofPlan for DoubleSquareTestProofPlan { builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { let x_commit = accessor.get_commitment(ColumnRef::new( "sxt.test".parse().unwrap(), "x".parse().unwrap(), @@ -476,7 +476,7 @@ impl ProofPlan for DoubleSquareTestProofPlan { // poly2 let eval = builder.mle_evaluations.random_evaluation * (res_eval - z_eval * z_eval); builder.produce_sumcheck_subpolynomial_evaluation(&eval); - Ok(()) + Ok(vec![res_eval]) } fn get_column_result_fields(&self) -> Vec { vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)] @@ -656,7 +656,7 @@ impl ProofPlan for ChallengeTestProofPlan { builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { let alpha = builder.consume_post_result_challenge(); let _beta = builder.consume_post_result_challenge(); let res_eval = builder.consume_result_mle(); @@ -669,7 +669,7 @@ impl ProofPlan for ChallengeTestProofPlan { let eval = builder.mle_evaluations.random_evaluation * (alpha * res_eval - alpha * x_eval * x_eval); builder.produce_sumcheck_subpolynomial_evaluation(&eval); - Ok(()) + Ok(vec![res_eval]) } fn get_column_result_fields(&self) -> Vec { vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)] 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 430c84e5b..3e86a9eca 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 @@ -66,8 +66,8 @@ impl ProofPlan for EmptyTestQueryExpr { _builder: &mut VerificationBuilder, _accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable<::Scalar>>, - ) -> Result<(), ProofError> { - Ok(()) + ) -> Result, ProofError> { + Ok(vec![C::Scalar::ZERO]) } fn get_column_result_fields(&self) -> Vec { diff --git a/crates/proof-of-sql/src/sql/proof_plans/dense_filter_exec.rs b/crates/proof-of-sql/src/sql/proof_plans/dense_filter_exec.rs index 59b6fc993..1a8eef910 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/dense_filter_exec.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/dense_filter_exec.rs @@ -89,7 +89,7 @@ where builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { // 1. selection let selection_eval = self.where_clause.verifier_evaluate(builder, accessor)?; // 2. columns @@ -227,7 +227,7 @@ fn verify_filter( c_evals: Vec, s_eval: C::Scalar, d_evals: Vec, -) -> Result<(), ProofError> { +) -> Result, ProofError> { let one_eval = builder.mle_evaluations.one_evaluation; let rand_eval = builder.mle_evaluations.random_evaluation; @@ -254,7 +254,7 @@ fn verify_filter( &(rand_eval * (d_bar_fold_eval * d_star_eval - chi_eval)), ); - Ok(()) + Ok(c_evals) } #[allow(clippy::too_many_arguments)] 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 94b604946..e028c1586 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 @@ -73,7 +73,7 @@ impl ProofPlan for DynProofPlan { builder: &mut crate::sql::proof::VerificationBuilder, accessor: &dyn crate::base::database::CommitmentAccessor, result: Option<&crate::base::database::OwnedTable>, - ) -> Result<(), crate::base::proof::ProofError> { + ) -> Result, crate::base::proof::ProofError> { match self { DynProofPlan::Projection(expr) => expr.verifier_evaluate(builder, accessor, result), DynProofPlan::Filter(expr) => expr.verifier_evaluate(builder, accessor, result), 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 990b706c4..7d1b03fd3 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 @@ -83,12 +83,13 @@ where builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { let selection_eval = self.where_clause.verifier_evaluate(builder, accessor)?; - for expr in self.results.iter() { - expr.verifier_evaluate(builder, accessor, &selection_eval); - } - Ok(()) + Ok(self + .results + .iter() + .map(|expr| expr.verifier_evaluate(builder, accessor, &selection_eval)) + .collect()) } fn get_column_result_fields(&self) -> Vec { diff --git a/crates/proof-of-sql/src/sql/proof_plans/filter_result_expr.rs b/crates/proof-of-sql/src/sql/proof_plans/filter_result_expr.rs index 3b1b2e00f..8f8a46102 100644 --- a/crates/proof-of-sql/src/sql/proof_plans/filter_result_expr.rs +++ b/crates/proof-of-sql/src/sql/proof_plans/filter_result_expr.rs @@ -89,7 +89,7 @@ impl FilterResultExpr { builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, selection_eval: &C::Scalar, - ) { + ) -> C::Scalar { let col_commit = accessor.get_commitment(self.column_ref); let result_eval = builder.consume_result_mle(); @@ -98,6 +98,7 @@ impl FilterResultExpr { let poly_eval = builder.mle_evaluations.random_evaluation * (result_eval - col_eval * *selection_eval); builder.produce_sumcheck_subpolynomial_evaluation(&poly_eval); + result_eval } } 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 d81aafd30..f867b3290 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 @@ -104,7 +104,7 @@ impl ProofPlan for GroupByExec { builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { // 1. selection let where_eval = self.where_clause.verifier_evaluate(builder, accessor)?; // 2. columns @@ -141,8 +141,8 @@ impl ProofPlan for GroupByExec { beta, (group_by_evals, aggregate_evals, where_eval), ( - group_by_result_columns_evals, - sum_result_columns_evals, + group_by_result_columns_evals.clone(), + sum_result_columns_evals.clone(), count_column_eval, ), )?; @@ -166,7 +166,13 @@ impl ProofPlan for GroupByExec { } None => todo!("GroupByExec currently only supported at top level of query plan."), } - Ok(()) + + Ok(Vec::from_iter( + group_by_result_columns_evals + .into_iter() + .chain(sum_result_columns_evals) + .chain(std::iter::once(count_column_eval)), + )) } fn get_column_result_fields(&self) -> Vec { 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 57213b9a3..22db5bd45 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 @@ -67,15 +67,14 @@ impl ProofPlan for ProjectionExec { builder: &mut VerificationBuilder, accessor: &dyn CommitmentAccessor, _result: Option<&OwnedTable>, - ) -> Result<(), ProofError> { + ) -> Result, ProofError> { self.aliased_results .iter() .map(|aliased_expr| aliased_expr.expr.verifier_evaluate(builder, accessor)) .collect::, _>>()?; - let _columns_evals = Vec::from_iter( + Ok(Vec::from_iter( repeat_with(|| builder.consume_result_mle()).take(self.aliased_results.len()), - ); - Ok(()) + )) } fn get_column_result_fields(&self) -> Vec {