|
1 | 1 | use rand::{rngs::OsRng, CryptoRng, Rng}; |
2 | | -use sigma_rs::toolbox::sigma::{proof_composition::OrEnum, AndProtocol, OrProtocol, SigmaProtocol}; |
| 2 | +use sigma_rs::toolbox::sigma::{proof_composition::OrEnum, SigmaProtocolSimulator, AndProtocol, OrProtocol, SigmaProtocol}; |
3 | 3 | use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; |
4 | 4 |
|
5 | 5 | pub struct SchnorrZkp { |
@@ -45,26 +45,32 @@ impl SigmaProtocol for SchnorrZkp { |
45 | 45 | false => Err(()), |
46 | 46 | } |
47 | 47 | } |
| 48 | +} |
48 | 49 |
|
| 50 | +#[allow(non_snake_case)] |
| 51 | +impl SigmaProtocolSimulator for SchnorrZkp { |
49 | 52 | fn simulate_proof( |
50 | | - &self, |
51 | | - challenge: &Self::Challenge, |
52 | | - rng: &mut (impl Rng + CryptoRng) |
53 | | - ) -> (Self::Commitment, Self::Response) { |
54 | | - let z = Scalar::random(rng); |
55 | | - let R = z * self.generator - challenge * self.target; |
56 | | - (R,z) |
57 | | - } |
| 53 | + &self, |
| 54 | + challenge: &Self::Challenge, |
| 55 | + rng: &mut (impl Rng + CryptoRng) |
| 56 | + ) -> (Self::Commitment, Self::Response) { |
| 57 | + let z = Scalar::random(rng); |
| 58 | + let R = z * self.generator - challenge * self.target; |
| 59 | + (R,z) |
| 60 | +} |
58 | 61 |
|
59 | | - fn simulate_transcription( |
60 | | - &self, rng: &mut (impl Rng + CryptoRng) |
61 | | - ) -> (Self::Commitment, Self::Challenge, Self::Response) { |
62 | | - let challenge = Scalar::random(rng); |
63 | | - let (commitment, response) = self.simulate_proof(&challenge, rng); |
64 | | - (commitment, challenge, response) |
65 | | - } |
| 62 | +fn simulate_transcription( |
| 63 | + &self, rng: &mut (impl Rng + CryptoRng) |
| 64 | +) -> (Self::Commitment, Self::Challenge, Self::Response) { |
| 65 | + let challenge = Scalar::random(rng); |
| 66 | + let (commitment, response) = self.simulate_proof(&challenge, rng); |
| 67 | + (commitment, challenge, response) |
| 68 | +} |
66 | 69 | } |
67 | 70 |
|
| 71 | + |
| 72 | +// Proof calculation and verification in an AND-protocol in the case where: |
| 73 | +// both protocols are SchnorrZkp and the proof is correct |
68 | 74 | #[allow(non_snake_case)] |
69 | 75 | #[test] |
70 | 76 | fn andproof_schnorr_correct() { |
@@ -101,6 +107,9 @@ fn andproof_schnorr_correct() { |
101 | 107 | assert!(result == Ok(())); |
102 | 108 | } |
103 | 109 |
|
| 110 | + |
| 111 | +// Proof calculation and verification in an AND-protocol in the case where: |
| 112 | +// both protocols are SchnorrZkp and the proof is incorrect |
104 | 113 | #[allow(non_snake_case)] |
105 | 114 | #[test] |
106 | 115 | fn andproof_schnorr_incorrect() { |
@@ -138,6 +147,9 @@ fn andproof_schnorr_incorrect() { |
138 | 147 | assert!(result == Err(())); |
139 | 148 | } |
140 | 149 |
|
| 150 | + |
| 151 | +// Proof calculation and verification in an OR-protocol in the case where: |
| 152 | +// both protocols are SchnorrZkp and the proof is correct |
141 | 153 | #[allow(non_snake_case)] |
142 | 154 | #[test] |
143 | 155 | fn orproof_schnorr_correct() { |
@@ -173,6 +185,9 @@ fn orproof_schnorr_correct() { |
173 | 185 | assert!(result == Ok(())); |
174 | 186 | } |
175 | 187 |
|
| 188 | + |
| 189 | +// Proof calculation and verification in an OR-protocol in the case where: |
| 190 | +// both protocols are SchnorrZkp and the proof is incorrect |
176 | 191 | #[allow(non_snake_case)] |
177 | 192 | #[test] |
178 | 193 | fn orproof_schnorr_incorrect() { |
|
0 commit comments