Skip to content

Commit 2b0d0ec

Browse files
committed
Finished changing variables name.
1 parent bb159a7 commit 2b0d0ec

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

mithril-stm/src/schnorr_signature/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ mod tests {
7979
assert_eq!(jjscalar, converted_base);
8080
}
8181

82+
#[test]
83+
fn test_generate_signing_key() {
84+
let mut rng = ChaCha20Rng::from_seed([0u8; 32]);
85+
let sk = SchnorrSigningKey::generate(&mut rng);
86+
let g = JubjubSubgroup::generator();
87+
let vk = g * sk.0;
88+
89+
let vk_from_sk = SchnorrVerificationKey::from(&sk);
90+
91+
assert_eq!(vk, vk_from_sk.0);
92+
}
93+
8294
#[test]
8395
fn test_sig_and_verify() {
8496
let msg = vec![0, 0, 0, 1];

mithril-stm/src/schnorr_signature/signature.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ impl SchnorrSignature {
6666

6767
// Computing R1 = H(msg) * s + sigma * c
6868
let challenge_scalar = jubjub_base_to_scalar(&self.challenge)?;
69-
let h_s = hash_msg * self.signature;
70-
let sigma_c = self.sigma * challenge_scalar;
71-
let r1_tilde = h_s + sigma_c;
69+
let hash_msg_times_sig = hash_msg * self.signature;
70+
let sigma_times_challenge = self.sigma * challenge_scalar;
71+
let random_value_1_recomputed = hash_msg_times_sig + sigma_times_challenge;
7272

7373
// Computing R2 = g * s + vk * c
74-
let g_s = generator * self.signature;
75-
let vk_c = vk.0 * challenge_scalar;
76-
let r2_tilde = g_s + vk_c;
74+
let generator_times_s = generator * self.signature;
75+
let vk_times_challenge = vk.0 * challenge_scalar;
76+
let random_value_2_recomputed = generator_times_s + vk_times_challenge;
7777

7878
let (hashx, hashy) = get_coordinates(hash_msg);
7979
let (vkx, vky) = get_coordinates(vk.0);
8080
let (sigmax, sigmay) = get_coordinates(self.sigma);
81-
let (r1x, r1y) = get_coordinates(r1_tilde);
82-
let (r2x, r2y) = get_coordinates(r2_tilde);
81+
let (r1x, r1y) = get_coordinates(random_value_1_recomputed);
82+
let (r2x, r2y) = get_coordinates(random_value_2_recomputed);
8383

84-
let c_tilde = PoseidonChip::<JubjubBase>::hash(&[
84+
let challenge_recomputed = PoseidonChip::<JubjubBase>::hash(&[
8585
DST_SIGNATURE,
8686
hashx,
8787
hashy,
@@ -95,7 +95,7 @@ impl SchnorrSignature {
9595
r2y,
9696
]);
9797

98-
if c_tilde != self.challenge {
98+
if challenge_recomputed != self.challenge {
9999
// TODO: Wrong error for now, need to change that once the errors are added
100100
return Err(anyhow!("Signature failed to verify."));
101101
}

mithril-stm/src/schnorr_signature/verification_key.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,10 @@ pub(crate) use crate::schnorr_signature::signing_key::SchnorrSigningKey;
1010
pub struct SchnorrVerificationKey(pub(crate) JubjubSubgroup);
1111

1212
impl SchnorrVerificationKey {
13-
/// TODO: Make sure this is correct as the previous implementation is
14-
/// using coordinates decomposition
1513
pub(crate) fn to_bytes(self) -> [u8; 32] {
16-
// let (x, y) = get_coordinates(self.0);
17-
// let mut bytes = [0u8; 64];
18-
// bytes[0..32].copy_from_slice(&x.to_bytes_le());
19-
// bytes[32..64].copy_from_slice(&y.to_bytes_le());
20-
// bytes
2114
self.0.to_bytes()
2215
}
2316

24-
/// Do we really need to separate the coordinates?
2517
pub(crate) fn from_bytes(bytes: &[u8]) -> Result<Self> {
2618
let bytes = bytes
2719
.get(0..32)
@@ -37,6 +29,7 @@ impl SchnorrVerificationKey {
3729

3830
impl From<&SchnorrSigningKey> for SchnorrVerificationKey {
3931
/// Convert a Shnorr secret key into a verification key
32+
///
4033
/// This is done by computing `vk = g * sk` where g is the generator
4134
/// of the subgroup and sk is the schnorr secret key
4235
fn from(sk: &SchnorrSigningKey) -> Self {
@@ -45,17 +38,3 @@ impl From<&SchnorrSigningKey> for SchnorrVerificationKey {
4538
SchnorrVerificationKey(g * sk.0)
4639
}
4740
}
48-
49-
#[cfg(test)]
50-
mod tests {
51-
use super::*;
52-
use rand_chacha::ChaCha20Rng;
53-
use rand_core::SeedableRng;
54-
55-
#[test]
56-
fn test_generate_signing_key() {
57-
let mut rng = ChaCha20Rng::from_seed([0u8; 32]);
58-
let sk = SchnorrSigningKey::generate(&mut rng);
59-
let _vk = SchnorrVerificationKey::from(&sk);
60-
}
61-
}

0 commit comments

Comments
 (0)