Skip to main content

sigma_proof_compiler/sigmas/
chaum.rs

1use crate::{
2    absorb::{SymInstance, SymPoint, SymScalar, SymWitness},
3    compiler::SigmaProof,
4    sigmas::{G, H},
5};
6
7pub struct Chaum;
8
9#[derive(SymWitness, Clone)]
10pub struct ChaumWitness {
11    x: SymScalar,
12}
13
14#[derive(SymInstance, Clone)]
15pub struct ChaumInstance {
16    point1: SymPoint,
17    point2: SymPoint,
18}
19
20impl SigmaProof for Chaum {
21    const LABEL: &'static [u8] = b"chaum-protocol";
22
23    type WITNESS = ChaumWitness;
24    type INSTANCE = ChaumInstance;
25
26    fn f(instance: &Self::INSTANCE) -> Vec<SymPoint> {
27        let Self::INSTANCE { point1, point2 } = instance.clone();
28        vec![point1, point2]
29    }
30
31    fn psi(witness: &Self::WITNESS, _instance: &Self::INSTANCE) -> Vec<SymPoint> {
32        let Self::WITNESS { x } = witness.clone();
33        vec![&x * SymPoint::Const(*G), &x * SymPoint::Const(*H)]
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use curve25519_dalek::Scalar;
40
41    use super::*;
42
43    #[test]
44    fn test_chaum_identity_protocol() {
45        let rng = &mut rand::rngs::OsRng;
46        let sk = Scalar::random(rng);
47        let witness = ChaumWitness {
48            x: SymScalar::Const(sk),
49        };
50
51        let instance = ChaumInstance {
52            point1: SymPoint::Const(sk * *G),
53            point2: SymPoint::Const(sk * *H),
54        };
55
56        let proof = Chaum::prove(&witness, &instance).unwrap();
57
58        println!("Chaum proof: {:?}", proof);
59
60        Chaum::verify(&instance, &proof).unwrap();
61    }
62
63    #[test]
64    fn test_chaum_spec_generation() {
65        let spec = Chaum::spec();
66        println!("{spec}");
67    }
68}