proof_of_sql/sql/proof/
proof_plan.rs

1use super::{verification_builder::VerificationBuilder, FinalRoundBuilder, FirstRoundBuilder};
2use crate::base::{
3    database::{ColumnField, ColumnRef, OwnedTable, Table, TableEvaluation, TableRef},
4    map::{IndexMap, IndexSet},
5    proof::ProofError,
6    scalar::Scalar,
7};
8use alloc::vec::Vec;
9use bumpalo::Bump;
10use core::fmt::Debug;
11
12/// Provable nodes in the provable AST.
13#[enum_dispatch::enum_dispatch(DynProofPlan)]
14pub trait ProofPlan: Debug + Send + Sync + ProverEvaluate {
15    /// Form components needed to verify and proof store into `VerificationBuilder`
16    fn verifier_evaluate<S: Scalar>(
17        &self,
18        builder: &mut impl VerificationBuilder<S>,
19        accessor: &IndexMap<ColumnRef, S>,
20        result: Option<&OwnedTable<S>>,
21        chi_eval_map: &IndexMap<TableRef, S>,
22    ) -> Result<TableEvaluation<S>, ProofError>;
23
24    /// Return all the result column fields
25    fn get_column_result_fields(&self) -> Vec<ColumnField>;
26
27    /// Return all the columns referenced in the Query
28    fn get_column_references(&self) -> IndexSet<ColumnRef>;
29
30    /// Return all the tables referenced in the Query
31    fn get_table_references(&self) -> IndexSet<TableRef>;
32}
33
34#[enum_dispatch::enum_dispatch(DynProofPlan)]
35pub trait ProverEvaluate {
36    /// Evaluate the query, modify `FirstRoundBuilder` and return the result.
37    fn first_round_evaluate<'a, S: Scalar>(
38        &self,
39        builder: &mut FirstRoundBuilder<'a, S>,
40        alloc: &'a Bump,
41        table_map: &IndexMap<TableRef, Table<'a, S>>,
42    ) -> Table<'a, S>;
43
44    /// Evaluate the query and modify `FinalRoundBuilder` to store an intermediate representation
45    /// of the query result and track all the components needed to form the query's proof.
46    ///
47    /// Intermediate values that are needed to form the proof are allocated into the arena
48    /// allocator alloc. These intermediate values will persist through proof creation and
49    /// will be bulk deallocated once the proof is formed.
50    fn final_round_evaluate<'a, S: Scalar>(
51        &self,
52        builder: &mut FinalRoundBuilder<'a, S>,
53        alloc: &'a Bump,
54        table_map: &IndexMap<TableRef, Table<'a, S>>,
55    ) -> Table<'a, S>;
56}
57
58/// Marker used as a trait bound for generic [`ProofPlan`] types to indicate the honesty of their implementation.
59///
60/// This allows us to define alternative prover implementations that misbehave, and test that the verifier rejects their results.
61pub trait ProverHonestyMarker: Debug + Send + Sync + PartialEq + 'static {}
62
63/// [`ProverHonestyMarker`] for generic [`ProofPlan`] types whose implementation is canonical/honest.
64#[derive(Debug, PartialEq, Clone)]
65pub struct HonestProver;
66impl ProverHonestyMarker for HonestProver {}