Skip to content

Commit

Permalink
feat: tabular SELECT Queries Without Aggregation Functions (#373)
Browse files Browse the repository at this point in the history
This PR introduces the support for simple `SELECT` queries without
aggregation functions

---------

Co-authored-by: Franklin Delehelle <[email protected]>
Co-authored-by: nikkolasg <[email protected]>
Co-authored-by: Nicolas Gailly <[email protected]>
  • Loading branch information
4 people authored Nov 13, 2024
1 parent 4255ab1 commit a03e407
Show file tree
Hide file tree
Showing 44 changed files with 4,184 additions and 853 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ in
}];
};

scripts.db.exec = "psql storage -h localhost -p ${builtins.toString config.env.PGPORT}";
scripts = {
# Open a shell to the DB
db.exec = "psql storage -h localhost -p ${builtins.toString config.env.PGPORT}";

# Wipe out the database
reset-db.exec = "rm -rf ${config.env.DEVENV_STATE}/postgres";
};

# https://devenv.sh/languages/
languages.rust = {
Expand Down
16 changes: 12 additions & 4 deletions groth16-framework/tests/common/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use verifiable_db::{
api::WrapCircuitParams,
revelation::api::Parameters as RevelationParameters,
test_utils::{
MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS, MAX_NUM_PLACEHOLDERS, MAX_NUM_PREDICATE_OPS,
MAX_NUM_RESULT_OPS,
INDEX_TREE_MAX_DEPTH, MAX_NUM_COLUMNS, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS,
MAX_NUM_PLACEHOLDERS, MAX_NUM_PREDICATE_OPS, MAX_NUM_RESULT_OPS, ROW_TREE_MAX_DEPTH,
},
};

Expand All @@ -18,10 +18,14 @@ pub(crate) struct TestContext {
pub(crate) preprocessing_circuits: TestingRecursiveCircuits<F, C, D, NUM_PREPROCESSING_IO>,
pub(crate) query_circuits: TestingRecursiveCircuits<F, C, D, NUM_QUERY_IO>,
pub(crate) revelation_params: RevelationParameters<
ROW_TREE_MAX_DEPTH,
INDEX_TREE_MAX_DEPTH,
MAX_NUM_COLUMNS,
MAX_NUM_PREDICATE_OPS,
MAX_NUM_RESULT_OPS,
MAX_NUM_OUTPUTS,
MAX_NUM_ITEMS_PER_OUTPUT,
MAX_NUM_PLACEHOLDERS,
{ 2 * (MAX_NUM_PREDICATE_OPS + MAX_NUM_RESULT_OPS) },
>,
pub(crate) wrap_circuit:
WrapCircuitParams<MAX_NUM_OUTPUTS, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_PLACEHOLDERS>,
Expand All @@ -39,10 +43,14 @@ impl TestContext {

// Create the revelation parameters.
let revelation_params = RevelationParameters::<
ROW_TREE_MAX_DEPTH,
INDEX_TREE_MAX_DEPTH,
MAX_NUM_COLUMNS,
MAX_NUM_PREDICATE_OPS,
MAX_NUM_RESULT_OPS,
MAX_NUM_OUTPUTS,
MAX_NUM_ITEMS_PER_OUTPUT,
MAX_NUM_PLACEHOLDERS,
{ 2 * (MAX_NUM_PREDICATE_OPS + MAX_NUM_RESULT_OPS) },
>::build(
query_circuits.get_recursive_circuit_set(),
preprocessing_circuits.get_recursive_circuit_set(),
Expand Down
20 changes: 4 additions & 16 deletions groth16-framework/tests/common/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ impl TestContext {
let max_block_number = 76;
let test_data = TestRevelationData::sample(min_block_number, max_block_number);

let placeholder_hash_ids = QueryInput::<
MAX_NUM_COLUMNS,
MAX_NUM_PREDICATE_OPS,
MAX_NUM_RESULT_OPS,
MAX_NUM_ITEMS_PER_OUTPUT,
>::ids_for_placeholder_hash(
test_data.predicate_operations(),
test_data.results(),
test_data.placeholders(),
test_data.query_bounds(),
)
.unwrap();

// Generate the query proof.
let [query_proof] = self
.query_circuits
Expand All @@ -60,17 +47,18 @@ impl TestContext {
let preprocessing_proof = serialize_proof(&preprocessing_proof).unwrap();

// Generate the revelation proof.
let input = CircuitInput::new_revelation_no_results_tree(
let input = CircuitInput::new_revelation_aggregated(
query_proof,
preprocessing_proof,
test_data.query_bounds(),
test_data.placeholders(),
placeholder_hash_ids,
test_data.predicate_operations(),
test_data.results(),
)
.unwrap();
let revelation_proof = self
.revelation_params
.generate_proof(input, self.query_circuits.get_recursive_circuit_set())
.generate_proof(input, self.query_circuits.get_recursive_circuit_set(), None)
.unwrap();
let revelation_proof = ProofWithVK::deserialize(&revelation_proof).unwrap();
let (revelation_proof_with_pi, _) = revelation_proof.clone().into();
Expand Down
5 changes: 1 addition & 4 deletions mp2-common/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ mod test {
};
use crate::utils::TryIntoBool;
use mp2_test::circuit::{run_circuit, UserCircuit};
use plonky2::{
field::types::Sample,
iop::witness::PartialWitness,
};
use plonky2::{field::types::Sample, iop::witness::PartialWitness};
use plonky2_ecgfp5::{
curve::curve::Point,
gadgets::curve::{CircuitBuilderEcGFp5, PartialWitnessCurve},
Expand Down
11 changes: 3 additions & 8 deletions mp2-common/src/group_hashing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,8 @@ pub fn cond_field_hashed_scalar_mul(cond: bool, mul: Point, base: Point) -> Poin
#[cfg(test)]
mod test {

use plonky2::{
field::types::Sample,
iop::witness::PartialWitness,
};

use plonky2::{field::types::Sample, iop::witness::PartialWitness};

use plonky2_ecgfp5::{
curve::curve::{Point, WeierstrassPoint},
gadgets::curve::{CircuitBuilderEcGFp5, CurveTarget, PartialWitnessCurve},
Expand All @@ -251,9 +248,7 @@ mod test {
};
use mp2_test::circuit::{run_circuit, UserCircuit};

use super::{
circuit_hashed_scalar_mul, field_hashed_scalar_mul, weierstrass_to_point,
};
use super::{circuit_hashed_scalar_mul, field_hashed_scalar_mul, weierstrass_to_point};

#[derive(Clone, Debug)]
struct TestScalarMul {
Expand Down
5 changes: 1 addition & 4 deletions mp2-common/src/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ pub const NUM_LIMBS: usize = 8;
/// the last, the comparison is defined as `l < r` or `l==r`.
/// It's corresponding to the `is_less_than_or_equal_to_u256_arr` gadget
/// function, and returns two flags: `left < right` and `left == right`.
pub fn is_less_than_or_equal_to_u256_arr<const L: usize>(
left: &[U256; L],
right: &[U256; L],
) -> (bool, bool) {
pub fn is_less_than_or_equal_to_u256_arr(left: &[U256], right: &[U256]) -> (bool, bool) {
zip_eq(left, right).fold((false, true), |(is_lt, is_eq), (l, r)| {
let borrow = if is_lt { U256::from(1) } else { U256::ZERO };
if let Some(l) = l.checked_sub(borrow) {
Expand Down
1 change: 1 addition & 0 deletions mp2-v1/src/final_extraction/base_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub(crate) struct BaseCircuitProofWires {

pub(crate) const CONTRACT_SET_NUM_IO: usize = contract_extraction::PublicInputs::<F>::TOTAL_LEN;
pub(crate) const VALUE_SET_NUM_IO: usize = values_extraction::PublicInputs::<F>::TOTAL_LEN;
// WARN: clippy is wrong on this one, it is used somewhere else.
pub(crate) const BLOCK_SET_NUM_IO: usize =
block_extraction::public_inputs::PublicInputs::<F>::TOTAL_LEN;

Expand Down
6 changes: 3 additions & 3 deletions mp2-v1/tests/common/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use contract::Contract;
use mp2_v1::values_extraction::{
identifier_for_mapping_key_column, identifier_for_mapping_value_column,
identifier_single_var_column,
};
identifier_for_mapping_key_column, identifier_for_mapping_value_column,
identifier_single_var_column,
};
use table_source::{ContractExtractionArgs, TableSource};

use super::table::Table;
Expand Down
4 changes: 2 additions & 2 deletions mp2-v1/tests/common/cases/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use parsil::{assembler::DynamicCircuitPis, ParsilSettings};
use ryhope::{storage::WideLineage, tree::NodeContext, Epoch};

use crate::common::{
cases::query::prove_non_existence_row,
cases::query::aggregated_queries::prove_non_existence_row,
index_tree::MerkleIndexTree,
proof_storage::{PlaceholderValues, ProofKey, ProofStorage, QueryID},
rowtree::MerkleRowTree,
table::{Table, TableColumns},
TestContext,
};

use super::query::{prove_single_row, QueryCooking};
use super::query::{aggregated_queries::prove_single_row, QueryCooking};

pub(crate) struct QueryPlanner<'a> {
pub(crate) query: QueryCooking,
Expand Down
Loading

0 comments on commit a03e407

Please sign in to comment.