Skip to main content

sigma_proof_compiler/sigmas/
okamoto.rs

1use crate::{
2    absorb::{SymInstance, SymPoint, SymScalar, SymWitness},
3    compiler::SigmaProof,
4    sigmas::{G, H},
5};
6
7pub struct Okamoto;
8
9#[derive(SymWitness, Clone)]
10pub struct OkamotoWitness {
11    x: SymScalar,
12    y: SymScalar,
13}
14
15#[derive(SymInstance, Clone)]
16pub struct OkamotoInstance {
17    point: SymPoint,
18}
19
20impl SigmaProof for Okamoto {
21    const LABEL: &'static [u8] = b"okamoto-protocol";
22
23    type WITNESS = OkamotoWitness;
24    type INSTANCE = OkamotoInstance;
25
26    fn f(instance: &Self::INSTANCE) -> Vec<SymPoint> {
27        let Self::INSTANCE { point } = instance.clone();
28        vec![point]
29    }
30
31    fn psi(witness: &Self::WITNESS, _instance: &Self::INSTANCE) -> Vec<SymPoint> {
32        let Self::WITNESS { x, y } = witness.clone();
33        vec![(x * SymPoint::Const(*G)) + (y * 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_okamoto_identity_protocol() {
45        let rng = &mut rand::rngs::OsRng;
46        let sk = Scalar::random(rng);
47        let witness = OkamotoWitness {
48            x: SymScalar::Const(sk),
49            y: SymScalar::Const(sk),
50        };
51
52        let instance = OkamotoInstance {
53            point: SymPoint::Const((sk * *G) + (sk * *H)),
54        };
55
56        let proof = Okamoto::prove(&witness, &instance).unwrap();
57
58        println!("Okamoto proof: {:?}", proof);
59
60        Okamoto::verify(&instance, &proof).unwrap();
61    }
62
63    #[test]
64    fn test_okamoto_spec_generation() {
65        let spec = Okamoto::spec();
66        println!("{spec}");
67    }
68}