snark_verifier/util/
transcript.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Transcript traits.

use crate::{
    loader::{native::NativeLoader, Loader},
    {util::arithmetic::CurveAffine, Error},
};

/// Common methods for prover and verifier.
pub trait Transcript<C, L>
where
    C: CurveAffine,
    L: Loader<C>,
{
    /// Returns [`Loader`].
    fn loader(&self) -> &L;

    /// Squeeze a challenge.
    fn squeeze_challenge(&mut self) -> L::LoadedScalar;

    /// Squeeze `n` challenges.
    fn squeeze_n_challenges(&mut self, n: usize) -> Vec<L::LoadedScalar> {
        (0..n).map(|_| self.squeeze_challenge()).collect()
    }

    /// Update with an elliptic curve point.
    fn common_ec_point(&mut self, ec_point: &L::LoadedEcPoint) -> Result<(), Error>;

    /// Update with a scalar.
    fn common_scalar(&mut self, scalar: &L::LoadedScalar) -> Result<(), Error>;
}

/// Transcript for verifier.
pub trait TranscriptRead<C, L>: Transcript<C, L>
where
    C: CurveAffine,
    L: Loader<C>,
{
    /// Read a scalar.
    fn read_scalar(&mut self) -> Result<L::LoadedScalar, Error>;

    /// Read `n` scalar.
    fn read_n_scalars(&mut self, n: usize) -> Result<Vec<L::LoadedScalar>, Error> {
        (0..n).map(|_| self.read_scalar()).collect()
    }

    /// Read a elliptic curve point.
    fn read_ec_point(&mut self) -> Result<L::LoadedEcPoint, Error>;

    /// Read `n` elliptic curve point.
    fn read_n_ec_points(&mut self, n: usize) -> Result<Vec<L::LoadedEcPoint>, Error> {
        (0..n).map(|_| self.read_ec_point()).collect()
    }
}

/// Transcript for prover.
pub trait TranscriptWrite<C: CurveAffine>: Transcript<C, NativeLoader> {
    /// Write a scalar.
    fn write_scalar(&mut self, scalar: C::Scalar) -> Result<(), Error>;

    /// Write a elliptic curve point.
    fn write_ec_point(&mut self, ec_point: C) -> Result<(), Error>;
}