Skip to content

Commit a03e407

Browse files
nicholas-mainardidelehefnikkolasg
authored
feat: tabular SELECT Queries Without Aggregation Functions (#373)
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]>
1 parent 4255ab1 commit a03e407

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4184
-853
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

devenv.nix

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ in
5555
}];
5656
};
5757

58-
scripts.db.exec = "psql storage -h localhost -p ${builtins.toString config.env.PGPORT}";
58+
scripts = {
59+
# Open a shell to the DB
60+
db.exec = "psql storage -h localhost -p ${builtins.toString config.env.PGPORT}";
61+
62+
# Wipe out the database
63+
reset-db.exec = "rm -rf ${config.env.DEVENV_STATE}/postgres";
64+
};
5965

6066
# https://devenv.sh/languages/
6167
languages.rust = {

groth16-framework/tests/common/context.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use verifiable_db::{
88
api::WrapCircuitParams,
99
revelation::api::Parameters as RevelationParameters,
1010
test_utils::{
11-
MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS, MAX_NUM_PLACEHOLDERS, MAX_NUM_PREDICATE_OPS,
12-
MAX_NUM_RESULT_OPS,
11+
INDEX_TREE_MAX_DEPTH, MAX_NUM_COLUMNS, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_OUTPUTS,
12+
MAX_NUM_PLACEHOLDERS, MAX_NUM_PREDICATE_OPS, MAX_NUM_RESULT_OPS, ROW_TREE_MAX_DEPTH,
1313
},
1414
};
1515

@@ -18,10 +18,14 @@ pub(crate) struct TestContext {
1818
pub(crate) preprocessing_circuits: TestingRecursiveCircuits<F, C, D, NUM_PREPROCESSING_IO>,
1919
pub(crate) query_circuits: TestingRecursiveCircuits<F, C, D, NUM_QUERY_IO>,
2020
pub(crate) revelation_params: RevelationParameters<
21+
ROW_TREE_MAX_DEPTH,
22+
INDEX_TREE_MAX_DEPTH,
23+
MAX_NUM_COLUMNS,
24+
MAX_NUM_PREDICATE_OPS,
25+
MAX_NUM_RESULT_OPS,
2126
MAX_NUM_OUTPUTS,
2227
MAX_NUM_ITEMS_PER_OUTPUT,
2328
MAX_NUM_PLACEHOLDERS,
24-
{ 2 * (MAX_NUM_PREDICATE_OPS + MAX_NUM_RESULT_OPS) },
2529
>,
2630
pub(crate) wrap_circuit:
2731
WrapCircuitParams<MAX_NUM_OUTPUTS, MAX_NUM_ITEMS_PER_OUTPUT, MAX_NUM_PLACEHOLDERS>,
@@ -39,10 +43,14 @@ impl TestContext {
3943

4044
// Create the revelation parameters.
4145
let revelation_params = RevelationParameters::<
46+
ROW_TREE_MAX_DEPTH,
47+
INDEX_TREE_MAX_DEPTH,
48+
MAX_NUM_COLUMNS,
49+
MAX_NUM_PREDICATE_OPS,
50+
MAX_NUM_RESULT_OPS,
4251
MAX_NUM_OUTPUTS,
4352
MAX_NUM_ITEMS_PER_OUTPUT,
4453
MAX_NUM_PLACEHOLDERS,
45-
{ 2 * (MAX_NUM_PREDICATE_OPS + MAX_NUM_RESULT_OPS) },
4654
>::build(
4755
query_circuits.get_recursive_circuit_set(),
4856
preprocessing_circuits.get_recursive_circuit_set(),

groth16-framework/tests/common/query.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@ impl TestContext {
2929
let max_block_number = 76;
3030
let test_data = TestRevelationData::sample(min_block_number, max_block_number);
3131

32-
let placeholder_hash_ids = QueryInput::<
33-
MAX_NUM_COLUMNS,
34-
MAX_NUM_PREDICATE_OPS,
35-
MAX_NUM_RESULT_OPS,
36-
MAX_NUM_ITEMS_PER_OUTPUT,
37-
>::ids_for_placeholder_hash(
38-
test_data.predicate_operations(),
39-
test_data.results(),
40-
test_data.placeholders(),
41-
test_data.query_bounds(),
42-
)
43-
.unwrap();
44-
4532
// Generate the query proof.
4633
let [query_proof] = self
4734
.query_circuits
@@ -60,17 +47,18 @@ impl TestContext {
6047
let preprocessing_proof = serialize_proof(&preprocessing_proof).unwrap();
6148

6249
// Generate the revelation proof.
63-
let input = CircuitInput::new_revelation_no_results_tree(
50+
let input = CircuitInput::new_revelation_aggregated(
6451
query_proof,
6552
preprocessing_proof,
6653
test_data.query_bounds(),
6754
test_data.placeholders(),
68-
placeholder_hash_ids,
55+
test_data.predicate_operations(),
56+
test_data.results(),
6957
)
7058
.unwrap();
7159
let revelation_proof = self
7260
.revelation_params
73-
.generate_proof(input, self.query_circuits.get_recursive_circuit_set())
61+
.generate_proof(input, self.query_circuits.get_recursive_circuit_set(), None)
7462
.unwrap();
7563
let revelation_proof = ProofWithVK::deserialize(&revelation_proof).unwrap();
7664
let (revelation_proof_with_pi, _) = revelation_proof.clone().into();

mp2-common/src/digest.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ mod test {
189189
};
190190
use crate::utils::TryIntoBool;
191191
use mp2_test::circuit::{run_circuit, UserCircuit};
192-
use plonky2::{
193-
field::types::Sample,
194-
iop::witness::PartialWitness,
195-
};
192+
use plonky2::{field::types::Sample, iop::witness::PartialWitness};
196193
use plonky2_ecgfp5::{
197194
curve::curve::Point,
198195
gadgets::curve::{CircuitBuilderEcGFp5, PartialWitnessCurve},

mp2-common/src/group_hashing/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,8 @@ pub fn cond_field_hashed_scalar_mul(cond: bool, mul: Point, base: Point) -> Poin
234234
#[cfg(test)]
235235
mod test {
236236

237-
use plonky2::{
238-
field::types::Sample,
239-
iop::witness::PartialWitness,
240-
};
241-
237+
use plonky2::{field::types::Sample, iop::witness::PartialWitness};
238+
242239
use plonky2_ecgfp5::{
243240
curve::curve::{Point, WeierstrassPoint},
244241
gadgets::curve::{CircuitBuilderEcGFp5, CurveTarget, PartialWitnessCurve},
@@ -251,9 +248,7 @@ mod test {
251248
};
252249
use mp2_test::circuit::{run_circuit, UserCircuit};
253250

254-
use super::{
255-
circuit_hashed_scalar_mul, field_hashed_scalar_mul, weierstrass_to_point,
256-
};
251+
use super::{circuit_hashed_scalar_mul, field_hashed_scalar_mul, weierstrass_to_point};
257252

258253
#[derive(Clone, Debug)]
259254
struct TestScalarMul {

mp2-common/src/u256.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ pub const NUM_LIMBS: usize = 8;
4848
/// the last, the comparison is defined as `l < r` or `l==r`.
4949
/// It's corresponding to the `is_less_than_or_equal_to_u256_arr` gadget
5050
/// function, and returns two flags: `left < right` and `left == right`.
51-
pub fn is_less_than_or_equal_to_u256_arr<const L: usize>(
52-
left: &[U256; L],
53-
right: &[U256; L],
54-
) -> (bool, bool) {
51+
pub fn is_less_than_or_equal_to_u256_arr(left: &[U256], right: &[U256]) -> (bool, bool) {
5552
zip_eq(left, right).fold((false, true), |(is_lt, is_eq), (l, r)| {
5653
let borrow = if is_lt { U256::from(1) } else { U256::ZERO };
5754
if let Some(l) = l.checked_sub(borrow) {

mp2-v1/src/final_extraction/base_circuit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ pub(crate) struct BaseCircuitProofWires {
113113

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

mp2-v1/tests/common/cases/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use contract::Contract;
44
use mp2_v1::values_extraction::{
5-
identifier_for_mapping_key_column, identifier_for_mapping_value_column,
6-
identifier_single_var_column,
7-
};
5+
identifier_for_mapping_key_column, identifier_for_mapping_value_column,
6+
identifier_single_var_column,
7+
};
88
use table_source::{ContractExtractionArgs, TableSource};
99

1010
use super::table::Table;

mp2-v1/tests/common/cases/planner.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use parsil::{assembler::DynamicCircuitPis, ParsilSettings};
1111
use ryhope::{storage::WideLineage, tree::NodeContext, Epoch};
1212

1313
use crate::common::{
14-
cases::query::prove_non_existence_row,
14+
cases::query::aggregated_queries::prove_non_existence_row,
1515
index_tree::MerkleIndexTree,
1616
proof_storage::{PlaceholderValues, ProofKey, ProofStorage, QueryID},
1717
rowtree::MerkleRowTree,
1818
table::{Table, TableColumns},
1919
TestContext,
2020
};
2121

22-
use super::query::{prove_single_row, QueryCooking};
22+
use super::query::{aggregated_queries::prove_single_row, QueryCooking};
2323

2424
pub(crate) struct QueryPlanner<'a> {
2525
pub(crate) query: QueryCooking,

0 commit comments

Comments
 (0)