Skip to content

Commit

Permalink
Simple Select Queries with Unchecked Offset (#365)
Browse files Browse the repository at this point in the history
This PR introduces a circuit to expose the results of simple `SELECT`
queries without aggregation functions, avoiding the need to build a
results tree.
  • Loading branch information
nicholas-mainardi authored Oct 29, 2024
1 parent 85cdb54 commit 5e2df85
Show file tree
Hide file tree
Showing 33 changed files with 3,963 additions and 725 deletions.
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
18 changes: 3 additions & 15 deletions groth16-framework/tests/common/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,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 @@ -66,12 +53,13 @@ impl TestContext {
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/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
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 @@ -13,15 +13,15 @@ use ryhope::{storage::WideLineage, tree::NodeContext, Epoch, NodePayload};
use verifiable_db::query::aggregation::QueryBounds;

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 5e2df85

Please sign in to comment.