proof_of_sql/base/commitment/
mod.rs

1//! Types for creation and utilization of cryptographic commitments to proof-of-sql data.
2use crate::base::scalar::Scalar;
3use alloc::vec::Vec;
4#[cfg(feature = "blitzar")]
5pub use blitzar::{
6    compute::{init_backend, init_backend_with_config, BackendConfig},
7    proof::InnerProductProof,
8};
9use core::ops::{AddAssign, SubAssign};
10mod committable_column;
11pub use committable_column::CommittableColumn;
12
13mod vec_commitment_ext;
14pub use vec_commitment_ext::{NumColumnsMismatch, VecCommitmentExt};
15
16mod column_bounds;
17pub use column_bounds::{Bounds, ColumnBounds, NegativeBounds};
18
19mod column_commitment_metadata;
20pub use column_commitment_metadata::ColumnCommitmentMetadata;
21
22mod column_commitment_metadata_map;
23pub use column_commitment_metadata_map::{
24    ColumnCommitmentMetadataMap, ColumnCommitmentMetadataMapExt, ColumnCommitmentsMismatch,
25};
26
27mod column_commitments;
28pub use column_commitments::{AppendColumnCommitmentsError, ColumnCommitments, DuplicateIdents};
29
30mod table_commitment;
31pub use table_commitment::{
32    AppendTableCommitmentError, MixedLengthColumns, NegativeRange, TableCommitment,
33    TableCommitmentArithmeticError, TableCommitmentFromColumnsError,
34};
35
36mod query_commitments;
37pub use query_commitments::{QueryCommitments, QueryCommitmentsExt};
38
39/// Module for providing a mock commitment.
40#[cfg(test)]
41pub mod naive_commitment;
42
43/// Module for providing a test commitment evaluation proof.
44#[cfg(test)]
45pub mod naive_evaluation_proof;
46
47#[cfg(test)]
48mod naive_commitment_test;
49
50/// A trait for using commitment schemes generically.
51pub trait Commitment:
52    AddAssign
53    + SubAssign
54    + Sized
55    + Default
56    + Clone
57    + core::ops::Neg<Output = Self>
58    + Eq
59    + core::ops::Sub<Output = Self>
60    + core::fmt::Debug
61    + core::marker::Sync
62    + core::marker::Send
63{
64    /// The associated scalar that the commitment is for.
65    /// There are multiple possible commitment schemes for a scalar, but only one scalar for any commitment.
66    type Scalar: Scalar
67        + for<'a> core::ops::Mul<&'a Self, Output = Self>
68        + core::ops::Mul<Self, Output = Self>
69        + serde::Serialize
70        + for<'a> serde::Deserialize<'a>;
71
72    /// The public setup for the commitment scheme.
73    type PublicSetup<'a>;
74
75    /// Compute the commitments for the given columns.
76    ///
77    /// The resulting commitments are written to the slice in `commitments`, which is a buffer.
78    /// `commitments` is expected to have the same length as `committable_columns` and the behavior is undefined if it does not.
79    /// The length of each [`CommittableColumn`] should be the same.
80    ///
81    /// `offset` is the amount that `committable_columns` is "offset" by. Logically adding `offset` many 0s to the beginning of each of the `committable_columns`.
82    fn compute_commitments(
83        committable_columns: &[CommittableColumn],
84        offset: usize,
85        setup: &Self::PublicSetup<'_>,
86    ) -> Vec<Self>;
87
88    /// Converts the commitment to bytes that will be appended to the transcript.
89    ///
90    /// This is also useful for serialization purposes.
91    fn to_transcript_bytes(&self) -> Vec<u8>;
92}
93
94mod commitment_evaluation_proof;
95pub use commitment_evaluation_proof::CommitmentEvaluationProof;
96
97#[cfg(test)]
98pub(crate) mod commitment_evaluation_proof_test;