Skip to content

Commit

Permalink
refactor!: allow ProofPlan::verifier_evaluate to return a vec of ev…
Browse files Browse the repository at this point in the history
…als (#136)
  • Loading branch information
iajoiner authored Sep 9, 2024
1 parent 2a19752 commit 0f965a2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/sql/proof/proof_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait ProofPlan<C: Commitment>: Debug + Send + Sync + ProverEvaluate<C::Scal
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError>;
) -> Result<Vec<C::Scalar>, ProofError>;

/// Return all the result column fields
fn get_column_result_fields(&self) -> Vec<ColumnField>;
Expand Down
16 changes: 8 additions & 8 deletions crates/proof-of-sql/src/sql/proof/query_proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ impl<C: Commitment> ProofPlan<C> for TrivialTestProofPlan {
builder: &mut VerificationBuilder<C>,
_accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, 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<ColumnField> {
vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)]
Expand Down Expand Up @@ -266,7 +266,7 @@ impl<C: Commitment> ProofPlan<C> for SquareTestProofPlan {
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
let res_eval = builder.consume_result_mle();
let x_commit = C::Scalar::from(self.anchored_commit_multiplier)
* accessor.get_commitment(ColumnRef::new(
Expand All @@ -277,7 +277,7 @@ impl<C: Commitment> ProofPlan<C> 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<ColumnField> {
vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)]
Expand Down Expand Up @@ -459,7 +459,7 @@ impl<C: Commitment> ProofPlan<C> for DoubleSquareTestProofPlan {
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
let x_commit = accessor.get_commitment(ColumnRef::new(
"sxt.test".parse().unwrap(),
"x".parse().unwrap(),
Expand All @@ -476,7 +476,7 @@ impl<C: Commitment> ProofPlan<C> 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<ColumnField> {
vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)]
Expand Down Expand Up @@ -656,7 +656,7 @@ impl<C: Commitment> ProofPlan<C> for ChallengeTestProofPlan {
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
let alpha = builder.consume_post_result_challenge();
let _beta = builder.consume_post_result_challenge();
let res_eval = builder.consume_result_mle();
Expand All @@ -669,7 +669,7 @@ impl<C: Commitment> ProofPlan<C> 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<ColumnField> {
vec![ColumnField::new("a1".parse().unwrap(), ColumnType::BigInt)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl<C: Commitment> ProofPlan<C> for EmptyTestQueryExpr {
_builder: &mut VerificationBuilder<C>,
_accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<<C as Commitment>::Scalar>>,
) -> Result<(), ProofError> {
Ok(())
) -> Result<Vec<C::Scalar>, ProofError> {
Ok(vec![C::Scalar::ZERO])
}

fn get_column_result_fields(&self) -> Vec<ColumnField> {
Expand Down
6 changes: 3 additions & 3 deletions crates/proof-of-sql/src/sql/proof_plans/dense_filter_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
// 1. selection
let selection_eval = self.where_clause.verifier_evaluate(builder, accessor)?;
// 2. columns
Expand Down Expand Up @@ -227,7 +227,7 @@ fn verify_filter<C: Commitment>(
c_evals: Vec<C::Scalar>,
s_eval: C::Scalar,
d_evals: Vec<C::Scalar>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
let one_eval = builder.mle_evaluations.one_evaluation;
let rand_eval = builder.mle_evaluations.random_evaluation;

Expand All @@ -254,7 +254,7 @@ fn verify_filter<C: Commitment>(
&(rand_eval * (d_bar_fold_eval * d_star_eval - chi_eval)),
);

Ok(())
Ok(c_evals)
}

#[allow(clippy::too_many_arguments)]
Expand Down
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/sql/proof_plans/dyn_proof_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<C: Commitment> ProofPlan<C> for DynProofPlan<C> {
builder: &mut crate::sql::proof::VerificationBuilder<C>,
accessor: &dyn crate::base::database::CommitmentAccessor<C>,
result: Option<&crate::base::database::OwnedTable<C::Scalar>>,
) -> Result<(), crate::base::proof::ProofError> {
) -> Result<Vec<C::Scalar>, crate::base::proof::ProofError> {
match self {
DynProofPlan::Projection(expr) => expr.verifier_evaluate(builder, accessor, result),
DynProofPlan::Filter(expr) => expr.verifier_evaluate(builder, accessor, result),
Expand Down
11 changes: 6 additions & 5 deletions crates/proof-of-sql/src/sql/proof_plans/filter_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ where
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, 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<ColumnField> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl FilterResultExpr {
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
selection_eval: &C::Scalar,
) {
) -> C::Scalar {
let col_commit = accessor.get_commitment(self.column_ref);

let result_eval = builder.consume_result_mle();
Expand All @@ -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
}
}

Expand Down
14 changes: 10 additions & 4 deletions crates/proof-of-sql/src/sql/proof_plans/group_by_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<C: Commitment> ProofPlan<C> for GroupByExec<C> {
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
// 1. selection
let where_eval = self.where_clause.verifier_evaluate(builder, accessor)?;
// 2. columns
Expand Down Expand Up @@ -141,8 +141,8 @@ impl<C: Commitment> ProofPlan<C> for GroupByExec<C> {
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,
),
)?;
Expand All @@ -166,7 +166,13 @@ impl<C: Commitment> ProofPlan<C> for GroupByExec<C> {
}
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<ColumnField> {
Expand Down
7 changes: 3 additions & 4 deletions crates/proof-of-sql/src/sql/proof_plans/projection_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ impl<C: Commitment> ProofPlan<C> for ProjectionExec<C> {
builder: &mut VerificationBuilder<C>,
accessor: &dyn CommitmentAccessor<C>,
_result: Option<&OwnedTable<C::Scalar>>,
) -> Result<(), ProofError> {
) -> Result<Vec<C::Scalar>, ProofError> {
self.aliased_results
.iter()
.map(|aliased_expr| aliased_expr.expr.verifier_evaluate(builder, accessor))
.collect::<Result<Vec<_>, _>>()?;
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<ColumnField> {
Expand Down

0 comments on commit 0f965a2

Please sign in to comment.