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