proof_of_sql/base/commitment/
commitment_evaluation_proof.rs

1use super::Commitment;
2use crate::base::{proof::Transcript, scalar::Scalar};
3use serde::{Deserialize, Serialize};
4
5/// A trait for using commitment schemes generically. Specifically, this trait is for the evaluation proof of a commitment scheme.
6pub trait CommitmentEvaluationProof {
7    /// The associated scalar that the commitment is for.
8    type Scalar: Scalar + Serialize + for<'a> Deserialize<'a>;
9    /// The associated commitment type.
10    type Commitment: for<'a> Commitment<Scalar = Self::Scalar, PublicSetup<'a> = Self::ProverPublicSetup<'a>>
11        + Serialize
12        + for<'a> Deserialize<'a>;
13    /// The error type for the proof.
14    type Error;
15    /// The public setup parameters required by the prover.
16    /// This is simply precomputed data that is required by the prover to create a proof.
17    type ProverPublicSetup<'a>: Copy;
18    /// The public setup parameters required by the verifier.
19    /// This is simply precomputed data that is required by the verifier to verify a proof.
20    type VerifierPublicSetup<'a>: Copy;
21    /// Create a new proof.
22    ///
23    /// Note: `b_point` must have length `nu`, where `2^nu` is at least the length of `a`.
24    /// `b_point` are the values for the variables that are being evaluated.
25    /// The resulting evaluation is the inner product of `a` and `b`, where `b` is the expanded vector form of `b_point`.
26    fn new(
27        transcript: &mut impl Transcript,
28        a: &[Self::Scalar],
29        b_point: &[Self::Scalar],
30        generators_offset: u64,
31        setup: &Self::ProverPublicSetup<'_>,
32    ) -> Self;
33    /// Verify a proof.
34    ///
35    /// Note: `b_point` must have length `nu`, where `2^nu` is at least the length of `a`.
36    /// `b_point` are the values for the variables that are being evaluated.
37    /// The resulting evaluation is the inner product of `a` and `b`, where `b` is the expanded vector form of `b_point`.
38    #[expect(clippy::too_many_arguments)]
39    fn verify_proof(
40        &self,
41        transcript: &mut impl Transcript,
42        a_commit: &Self::Commitment,
43        product: &Self::Scalar,
44        b_point: &[Self::Scalar],
45        generators_offset: u64,
46        table_length: usize,
47        setup: &Self::VerifierPublicSetup<'_>,
48    ) -> Result<(), Self::Error> {
49        self.verify_batched_proof(
50            transcript,
51            core::slice::from_ref(a_commit),
52            &[Self::Scalar::ONE],
53            core::slice::from_ref(product),
54            b_point,
55            generators_offset,
56            table_length,
57            setup,
58        )
59    }
60    /// Verify a batch proof. This can be more efficient than verifying individual proofs for some schemes.
61    #[expect(clippy::too_many_arguments)]
62    fn verify_batched_proof(
63        &self,
64        transcript: &mut impl Transcript,
65        commit_batch: &[Self::Commitment],
66        batching_factors: &[Self::Scalar],
67        evaluations: &[Self::Scalar],
68        b_point: &[Self::Scalar],
69        generators_offset: u64,
70        table_length: usize,
71        setup: &Self::VerifierPublicSetup<'_>,
72    ) -> Result<(), Self::Error>;
73}