Skip to content

Commit

Permalink
refactor: move proof pieces used by ProofExprs and ProofPlans to …
Browse files Browse the repository at this point in the history
…`proof_gadgets` (#433)

Please be sure to look over the pull request guidelines here:
https://github.com/spaceandtimelabs/sxt-proof-of-sql/blob/main/CONTRIBUTING.md#submit-pr.

# Please go through the following checklist
- [x] The PR title and commit messages adhere to guidelines here:
https://github.com/spaceandtimelabs/sxt-proof-of-sql/blob/main/CONTRIBUTING.md.
In particular `!` is used if and only if at least one breaking change
has been introduced.
- [x] I have run the ci check script with `source
scripts/run_ci_checks.sh`.

# Rationale for this change
Bitwise verification, sign checks, range checks, subset checks,
uniqueness checks etc are building blocks of `ProofExpr`s and
`ProofPlan`s but are not themselves either. Hence we would like to put
them in a separate `proof_gadgets` directory.
<!--
Why are you proposing this change? If this is already explained clearly
in the linked issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.

 Example:
 Add `NestedLoopJoinExec`.
 Closes #345.

Since we added `HashJoinExec` in #323 it has been possible to do
provable inner joins. However performance is not satisfactory in some
cases. Hence we need to fix the problem by implement
`NestedLoopJoinExec` and speed up the code
 for `HashJoinExec`.
-->

# What changes are included in this PR?
Move bitwise verification, sign checks & range checks to `proof_gadgets`
<!--
There is no need to duplicate the description in the ticket here but it
is sometimes worth providing a summary of the individual changes in this
PR.

Example:
- Add `NestedLoopJoinExec`.
- Speed up `HashJoinExec`.
- Route joins to `NestedLoopJoinExec` if the outer input is sufficiently
small.
-->

# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code

If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?

Example:
Yes.
-->
Existing tests do pass
  • Loading branch information
iajoiner authored Dec 16, 2024
2 parents 447f312 + db711cd commit 098f671
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 27 deletions.
1 change: 1 addition & 0 deletions crates/proof-of-sql/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod parse;
pub mod postprocessing;
pub mod proof;
pub mod proof_exprs;
pub mod proof_gadgets;
pub mod proof_plans;
12 changes: 7 additions & 5 deletions crates/proof-of-sql/src/sql/proof_exprs/inequality_expr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{
prover_evaluate_equals_zero, prover_evaluate_or, prover_evaluate_sign,
result_evaluate_equals_zero, result_evaluate_or, result_evaluate_sign,
scale_and_add_subtract_eval, scale_and_subtract, verifier_evaluate_equals_zero,
verifier_evaluate_or, verifier_evaluate_sign, DynProofExpr, ProofExpr,
prover_evaluate_equals_zero, prover_evaluate_or, result_evaluate_equals_zero,
result_evaluate_or, scale_and_add_subtract_eval, scale_and_subtract,
verifier_evaluate_equals_zero, verifier_evaluate_or, DynProofExpr, ProofExpr,
};
use crate::{
base::{
Expand All @@ -11,7 +10,10 @@ use crate::{
proof::ProofError,
scalar::Scalar,
},
sql::proof::{FinalRoundBuilder, VerificationBuilder},
sql::{
proof::{FinalRoundBuilder, VerificationBuilder},
proof_gadgets::{prover_evaluate_sign, result_evaluate_sign, verifier_evaluate_sign},
},
utils::log,
};
use alloc::boxed::Box;
Expand Down
10 changes: 0 additions & 10 deletions crates/proof-of-sql/src/sql/proof_exprs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ use multiply_expr::MultiplyExpr;
#[cfg(all(test, feature = "blitzar"))]
mod multiply_expr_test;

mod bitwise_verification;
use bitwise_verification::{verify_constant_abs_decomposition, verify_constant_sign_decomposition};
#[cfg(test)]
mod bitwise_verification_test;

mod dyn_proof_expr;
pub(crate) use dyn_proof_expr::DynProofExpr;

Expand Down Expand Up @@ -69,11 +64,6 @@ use equals_expr::{
#[cfg(all(test, feature = "blitzar"))]
mod equals_expr_test;

mod sign_expr;
use sign_expr::{prover_evaluate_sign, result_evaluate_sign, verifier_evaluate_sign};
#[cfg(all(test, feature = "blitzar"))]
mod sign_expr_test;

mod table_expr;
pub(crate) use table_expr::TableExpr;

Expand Down
12 changes: 12 additions & 0 deletions crates/proof-of-sql/src/sql/proof_gadgets/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! This module contains shared proof logic for multiple `ProofExpr` / `ProofPlan` implementations.
mod bitwise_verification;
use bitwise_verification::{verify_constant_abs_decomposition, verify_constant_sign_decomposition};
#[cfg(test)]
mod bitwise_verification_test;
mod sign_expr;
pub(crate) use sign_expr::{prover_evaluate_sign, result_evaluate_sign, verifier_evaluate_sign};
pub mod range_check;
#[cfg(all(test, feature = "blitzar"))]
pub mod range_check_test;
#[cfg(all(test, feature = "blitzar"))]
mod sign_expr_test;
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,10 @@ where

#[cfg(test)]
mod tests {
use super::*;
use crate::{
base::scalar::{Curve25519Scalar as S, Scalar},
sql::{
proof::FinalRoundBuilder,
proof_plans::range_check::{decompose_scalar_to_words, get_logarithmic_derivative},
},
sql::proof::FinalRoundBuilder,
};
use bumpalo::Bump;
use num_traits::Inv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ impl ProofPlan for RangeCheckTestPlan {

#[cfg(all(test, feature = "blitzar"))]
mod tests {

use super::*;
use crate::{
base::database::{
owned_table_utility::{owned_table, scalar},
ColumnRef, ColumnType, OwnedTableTestAccessor,
},
sql::{
proof::VerifiableQueryResult, proof_plans::range_check_test_plan::RangeCheckTestPlan,
},
sql::proof::VerifiableQueryResult,
};
use blitzar::proof::InnerProductProof;

Expand Down
4 changes: 0 additions & 4 deletions crates/proof-of-sql/src/sql/proof_plans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ pub use dyn_proof_plan::DynProofPlan;

#[cfg(test)]
mod demo_mock_plan;

pub mod range_check;
#[cfg(all(test, feature = "blitzar"))]
pub mod range_check_test_plan;

0 comments on commit 098f671

Please sign in to comment.