Skip to content

Commit

Permalink
Update for Tabular queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
silathdiir committed Dec 20, 2024
1 parent 0e7109b commit f91981f
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 118 deletions.
57 changes: 25 additions & 32 deletions lgn-messages/src/types/v1/query/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,37 @@ pub struct QueryInput
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum QueryStep
{
/// Combine the rows and revelation proving for tabular queries in one task,
/// next step is Groth16
#[serde(rename = "1")]
Prepare(Vec<QueryInputPart>),
Tabular(
Vec<MatchingRowInput>,
RevelationInput,
),

/// Aggregation batching queries, next step is Revelation
#[serde(rename = "2")]
Aggregation(Vec<AggregationInput>),

/// Revelation step, we only handle aggregation revelation for now, next step is Groth16
#[serde(rename = "3")]
Revelation(RevelationInput),
}

#[derive(Dbg, Clone, Deserialize, Serialize)]
pub enum QueryInputPart
#[derive(Clone, Dbg, PartialEq, Deserialize, Serialize)]
pub struct MatchingRowInput
{
#[serde(rename = "1")]
Aggregation(
ProofKey,
Box<ProofInputKind>,
),
pub proof_key: ProofKey,
pub column_cells: RowCells,
pub placeholders: PlaceHolderLgn,
pub is_leaf: bool,
}

// We only need to handle rows tree proving for now.
#[serde(rename = "2")]
Embedded(
ProofKey,
EmbeddedProofInputType,
),
#[derive(Dbg, Clone, Deserialize, Serialize)]
pub struct AggregationInput
{
pub proof_key: ProofKey,
pub input_kind: ProofInputKind,
}

#[derive(Clone, Dbg, Deserialize, Serialize)]
Expand All @@ -68,30 +77,14 @@ pub enum ProofInputKind
NonExistence(Box<NonExistenceInput>),
}

#[derive(Clone, PartialEq, Dbg, Deserialize, Serialize)]
pub enum EmbeddedProofInputType
{
#[serde(rename = "1")]
RowsTree(RowsEmbeddedProofInput),
}

#[derive(Dbg, Clone, PartialEq, Deserialize, Serialize)]
pub struct RowsEmbeddedProofInput
{
pub column_cells: RowCells,

pub placeholders: PlaceHolderLgn,

pub is_leaf: bool,
}

#[derive(Clone, Dbg, Serialize, Deserialize)]
pub struct HydratableMatchingRow
{
pub proof: Hydratable<db_keys::ProofKey>,
pub proof: Hydratable<ProofKey>,
pub path: RowPath,
pub result: Vec<U256>,
}

impl HydratableMatchingRow
{
pub fn into_matching_row(self) -> MatchingRow
Expand Down
4 changes: 2 additions & 2 deletions lgn-provers/src/provers/v1/query/dummy_prover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lgn_messages::types::v1::query::tasks::MatchingRowInput;
use lgn_messages::types::v1::query::tasks::NonExistenceInput;
use lgn_messages::types::v1::query::tasks::RowsChunkInput;
use lgn_messages::types::v1::query::tasks::RowsEmbeddedProofInput;
use parsil::assembler::DynamicCircuitPis;
use verifiable_db::query::computational_hash_ids::ColumnIDs;
use verifiable_db::query::universal_circuit::universal_circuit_inputs::Placeholders;
Expand All @@ -18,7 +18,7 @@ impl StorageQueryProver for DummyProver
{
fn prove_universal_circuit(
&self,
_input: RowsEmbeddedProofInput,
_input: MatchingRowInput,
_pis: &DynamicCircuitPis,
) -> anyhow::Result<Vec<u8>>
{
Expand Down
4 changes: 2 additions & 2 deletions lgn-provers/src/provers/v1/query/euclid_prover.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use lgn_messages::types::v1::query::tasks::MatchingRowInput;
use lgn_messages::types::v1::query::tasks::NonExistenceInput;
use lgn_messages::types::v1::query::tasks::RowsChunkInput;
use lgn_messages::types::v1::query::tasks::RowsEmbeddedProofInput;
use lgn_messages::types::v1::query::NUM_CHUNKS;
use lgn_messages::types::v1::query::NUM_ROWS;
use metrics::histogram;
Expand Down Expand Up @@ -98,7 +98,7 @@ impl StorageQueryProver for EuclidQueryProver
{
fn prove_universal_circuit(
&self,
input: RowsEmbeddedProofInput,
input: MatchingRowInput,
pis: &DynamicCircuitPis,
) -> anyhow::Result<Vec<u8>>
{
Expand Down
4 changes: 2 additions & 2 deletions lgn-provers/src/provers/v1/query/prover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lgn_messages::types::v1::query::tasks::MatchingRowInput;
use lgn_messages::types::v1::query::tasks::NonExistenceInput;
use lgn_messages::types::v1::query::tasks::RowsChunkInput;
use lgn_messages::types::v1::query::tasks::RowsEmbeddedProofInput;
use parsil::assembler::DynamicCircuitPis;
use verifiable_db::query::computational_hash_ids::ColumnIDs;
use verifiable_db::query::universal_circuit::universal_circuit_inputs::Placeholders;
Expand All @@ -10,7 +10,7 @@ pub trait StorageQueryProver
{
fn prove_universal_circuit(
&self,
input: RowsEmbeddedProofInput,
input: MatchingRowInput,
pis: &DynamicCircuitPis,
) -> anyhow::Result<Vec<u8>>;

Expand Down
208 changes: 128 additions & 80 deletions lgn-provers/src/provers/v1/query/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::collections::HashMap;

use anyhow::bail;
use lgn_messages::types::v1::query::keys::ProofKey;
use lgn_messages::types::v1::query::tasks::EmbeddedProofInputType;
use lgn_messages::types::v1::query::tasks::Hydratable;
use lgn_messages::types::v1::query::tasks::HydratableMatchingRow;
use lgn_messages::types::v1::query::tasks::ProofInputKind;
use lgn_messages::types::v1::query::tasks::QueryInputPart;
use lgn_messages::types::v1::query::tasks::QueryStep;
use lgn_messages::types::v1::query::tasks::RevelationInput;
use lgn_messages::types::v1::query::WorkerTask;
Expand Down Expand Up @@ -110,93 +108,143 @@ impl<P: StorageQueryProver> Querying<P>

match &input.query_step
{
QueryStep::Prepare(ref parts) =>
QueryStep::Tabular(rows_inputs, revelation_input) =>
{
for part in parts
for input in rows_inputs
{
match part
let proof_key = input
.proof_key
.clone();
let proof = self
.prover
.prove_universal_circuit(
input.clone(),
&pis,
)?;
proofs.insert(
proof_key,
proof,
);
}

match revelation_input
{
RevelationInput::Tabular {
placeholders,
indexing_proof,
matching_rows,
column_ids,
limit,
offset,
..
} =>
{
QueryInputPart::Aggregation(proof_key, proof_input) =>
{
match proof_input.as_ref()
{
ProofInputKind::RowsChunk(rc) =>
{
let proof = self
.prover
.prove_row_chunks(
rc.clone(),
&pis,
)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
},
ProofInputKind::ChunkAggregation(ca) =>
{
let chunks_proofs = ca
.child_proofs
.iter()
.map(
|proof| {
match proof {
Hydratable::Hydrated(_) => proof.clone_proof(),
Hydratable::Dehydrated(key) => proofs
let matching_rows = matching_rows
.iter()
.cloned()
.map(
|mut row| {
if let Hydratable::Dehydrated(key) = &row.proof
{
row.proof
.hydrate(
proofs
.remove(key)
.expect("Cannot find rows-chunk proof: {proof_key:?}"),
}
},
)
.collect::<Vec<_>>();
let proof = self
.prover
.prove_chunk_aggregation(&chunks_proofs)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
},
ProofInputKind::NonExistence(ne) =>
{
let proof = self
.prover
.prove_non_existence(
*ne.clone(),
&pis,
)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
.expect(
"Cannot find matching-row proof: {key:?}",
),
);
}

HydratableMatchingRow::into_matching_row(row)
},
}
)
.collect();
return self
.prover
.prove_tabular_revelation(
&pis,
placeholders
.clone()
.into(),
indexing_proof.clone_proof(),
matching_rows,
column_ids,
*limit,
*offset,
);
},
_ => panic!("Wrong RevelationInput for QueryStep::Tabular"),
}
},
QueryStep::Aggregation(inputs) =>
{
for input in inputs
{
let proof_key = input
.proof_key
.clone();
match &input.input_kind
{
ProofInputKind::RowsChunk(rc) =>
{
let proof = self
.prover
.prove_row_chunks(
rc.clone(),
&pis,
)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
},
QueryInputPart::Embedded(proof_key, proof_input) =>
ProofInputKind::ChunkAggregation(ca) =>
{
match proof_input
{
EmbeddedProofInputType::RowsTree(embedded_input) =>
{
let proof = self
.prover
.prove_universal_circuit(
embedded_input.to_owned(),
&pis,
)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
},
}
let chunks_proofs = ca
.child_proofs
.iter()
.map(
|proof| {
match proof
{
Hydratable::Hydrated(_) => proof.clone_proof(),
Hydratable::Dehydrated(key) => proofs
.remove(key)
.expect(
"Cannot find rows-chunk proof: {proof_key:?}",
),
}
},
)
.collect::<Vec<_>>();
let proof = self
.prover
.prove_chunk_aggregation(&chunks_proofs)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
},
ProofInputKind::NonExistence(ne) =>
{
let proof = self
.prover
.prove_non_existence(
*ne.clone(),
&pis,
)?;
proofs.insert(
proof_key.to_owned(),
proof,
);
},
}
}
},
QueryStep::Revelation(rev) =>
QueryStep::Revelation(input) =>
{
match rev
match input
{
RevelationInput::Aggregated {
placeholders,
Expand All @@ -218,7 +266,7 @@ impl<P: StorageQueryProver> Querying<P>
},
RevelationInput::Tabular {
placeholders,
indexing_proof: preprocessing_proof,
indexing_proof,
matching_rows,
column_ids,
limit,
Expand All @@ -233,7 +281,7 @@ impl<P: StorageQueryProver> Querying<P>
placeholders
.clone()
.into(),
preprocessing_proof.clone_proof(),
indexing_proof.clone_proof(),
matching_rows
.iter()
.cloned()
Expand All @@ -242,7 +290,7 @@ impl<P: StorageQueryProver> Querying<P>
column_ids,
*limit,
*offset,
)
);
},
}
},
Expand Down

0 comments on commit f91981f

Please sign in to comment.