proof_of_sql/proof_primitive/inner_product/
ristretto_point.rs

1use crate::{
2    base::commitment::{Commitment, CommittableColumn},
3    proof_primitive::inner_product::curve_25519_scalar::Curve25519Scalar,
4};
5use alloc::vec::Vec;
6use curve25519_dalek::RistrettoPoint;
7
8impl Commitment for RistrettoPoint {
9    type Scalar = Curve25519Scalar;
10    type PublicSetup<'a> = ();
11    #[cfg(feature = "blitzar")]
12    fn compute_commitments(
13        committable_columns: &[CommittableColumn],
14        offset: usize,
15        _setup: &Self::PublicSetup<'_>,
16    ) -> Vec<Self> {
17        use curve25519_dalek::ristretto::CompressedRistretto;
18
19        let sequences: Vec<_> = committable_columns.iter().map(Into::into).collect();
20        let mut compressed_commitments =
21            vec![CompressedRistretto::default(); committable_columns.len()];
22        blitzar::compute::compute_curve25519_commitments(
23            &mut compressed_commitments,
24            &sequences,
25            offset as u64,
26        );
27        compressed_commitments
28            .into_iter()
29            .map(|cc| {
30                cc.decompress().expect(
31                    "invalid ristretto point decompression in Commitment::compute_commitments",
32                )
33            })
34            .collect()
35    }
36    #[cfg(not(feature = "blitzar"))]
37    fn compute_commitments(
38        _committable_columns: &[CommittableColumn],
39        _offset: usize,
40        _setup: &Self::PublicSetup<'_>,
41    ) -> Vec<Self> {
42        unimplemented!()
43    }
44
45    fn to_transcript_bytes(&self) -> Vec<u8> {
46        self.compress().as_bytes().to_vec()
47    }
48}
49
50#[cfg(test)]
51mod tests {
52    use crate::base::commitment::*;
53    use curve25519_dalek::{constants::RISTRETTO_BASEPOINT_POINT, ristretto::RistrettoPoint};
54
55    #[test]
56    fn we_get_different_transcript_bytes_from_different_ristretto_point_commitments() {
57        let commitment1 = RistrettoPoint::default();
58        let commitment2 = RISTRETTO_BASEPOINT_POINT;
59
60        assert_ne!(
61            commitment1.to_transcript_bytes(),
62            commitment2.to_transcript_bytes()
63        );
64    }
65}