Skip to content

Commit 62e9262

Browse files
committed
rename fields of signature
1 parent c1d935a commit 62e9262

File tree

3 files changed

+55
-53
lines changed

3 files changed

+55
-53
lines changed

mithril-stm/src/signature_scheme/schnorr_signature/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod tests {
168168
let recovered_signature = SchnorrSignature::from_bytes(&signature_bytes).unwrap();
169169
assert_eq!(signature, recovered_signature, "Recovered signature does not match with the original!");
170170

171-
// Test invalid `sigma`
171+
// Test invalid `commitment_point`
172172
let mut corrupted_bytes = signature_bytes.clone();
173173
corrupted_bytes[31] |= 0xff;
174174
let result = SchnorrSignature::from_bytes(&corrupted_bytes).expect_err("From bytes conversion of signature should fail");
@@ -180,7 +180,7 @@ mod tests {
180180
"Unexpected error: {result:?}"
181181
);
182182

183-
// Test invalid `signature`
183+
// Test invalid `response`
184184
let mut corrupted_bytes = signature_bytes.clone();
185185
corrupted_bytes[63] |= 0xff;
186186
let result = SchnorrSignature::from_bytes(&corrupted_bytes).expect_err("From bytes conversion should fail");

mithril-stm/src/signature_scheme/schnorr_signature/signature.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ use crate::StmResult;
88

99
/// Structure of the Schnorr signature to use with the SNARK
1010
///
11-
/// This signature includes a value `sigma` which depends only on
11+
/// This signature includes a value `commitment_point` which depends only on
1212
/// the message and the signing key.
1313
/// This value is used in the lottery process to determine the correct indices.
1414
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1515
pub struct SchnorrSignature {
1616
/// Deterministic value depending on the message and secret key
17-
pub(crate) sigma: ProjectivePoint,
17+
pub(crate) commitment_point: ProjectivePoint,
1818
/// Part of the Schnorr signature depending on the secret key
19-
pub(crate) signature: ScalarFieldElement,
19+
pub(crate) response: ScalarFieldElement,
2020
/// Part of the Schnorr signature NOT depending on the secret key
2121
pub(crate) challenge: ScalarFieldElement,
2222
}
@@ -33,11 +33,11 @@ impl SchnorrSignature {
3333
/// - Ok(()) if the signature verifies and an error if not
3434
///
3535
/// The protocol computes:
36-
/// - msg_hash = H(Sha256(msg))
37-
/// - random_point_1_recomputed = msg_hash * signature + sigma * challenge
38-
/// - random_point_2_recomputed = generator * signature + verification_key * challenge
36+
/// - msg_hash_point = H(Sha256(msg))
37+
/// - random_point_1_recomputed = response * msg_hash_point + challenge * commitment_point
38+
/// - random_point_2_recomputed = response * prime_order_generator_point + challenge * verification_key
3939
/// - challenge_recomputed = Poseidon(DST || H(Sha256(msg)) || verification_key
40-
/// || sigma || random_point_1_recomputed || random_point_2_recomputed)
40+
/// || commitment_point || random_point_1_recomputed || random_point_2_recomputed)
4141
///
4242
/// Check: challenge == challenge_recomputed
4343
///
@@ -47,27 +47,30 @@ impl SchnorrSignature {
4747
.is_valid()
4848
.with_context(|| "Signature verification failed due to invalid verification key")?;
4949

50-
let generator = PrimeOrderProjectivePoint::create_generator();
50+
let prime_order_generator_point = PrimeOrderProjectivePoint::create_generator();
5151

5252
// First hashing the message to a scalar then hashing it to a curve point
53-
let msg_hash = ProjectivePoint::hash_to_projective_point(msg);
53+
let msg_hash_point = ProjectivePoint::hash_to_projective_point(msg);
5454

55-
// Computing R1 = H(msg) * s + sigma * c
56-
let msg_hash_times_signature = msg_hash.scalar_multiplication(&self.signature);
57-
let sigma_times_challenge = self.sigma.scalar_multiplication(&self.challenge);
58-
let random_point_1_recomputed = msg_hash_times_signature.add(sigma_times_challenge);
55+
// Computing random_point_1_recomputed = response * H(msg) + challenge * commitment_point
56+
let response_time_msg_hash_point = msg_hash_point.scalar_multiplication(&self.response);
57+
let challenge_times_commitment_point =
58+
self.commitment_point.scalar_multiplication(&self.challenge);
59+
let random_point_1_recomputed =
60+
response_time_msg_hash_point.add(challenge_times_commitment_point);
5961

60-
// Computing R2 = g * s + vk * c
61-
let generator_times_signature = generator.scalar_multiplication(&self.signature);
62-
let vk_times_challenge = verification_key.0.scalar_multiplication(&self.challenge);
63-
let random_point_2_recomputed = generator_times_signature.add(vk_times_challenge);
62+
// Computing random_point_2_recomputed = response * prime_order_generator_point + challenge * vk
63+
let response_times_generator_point =
64+
prime_order_generator_point.scalar_multiplication(&self.response);
65+
let challenge_times_vk = verification_key.0.scalar_multiplication(&self.challenge);
66+
let random_point_2_recomputed = response_times_generator_point.add(challenge_times_vk);
6467

6568
// Since the hash function takes as input scalar elements
6669
// We need to convert the EC points to their coordinates
6770
let points_coordinates = collect_coordinates_of_list_of_points(&[
68-
msg_hash,
71+
msg_hash_point,
6972
ProjectivePoint::from_prime_order_projective_point(verification_key.0),
70-
self.sigma,
73+
self.commitment_point,
7174
random_point_1_recomputed,
7275
ProjectivePoint::from_prime_order_projective_point(random_point_2_recomputed),
7376
]);
@@ -86,8 +89,8 @@ impl SchnorrSignature {
8689
/// Convert an `SchnorrSignature` into bytes.
8790
pub fn to_bytes(self) -> [u8; 96] {
8891
let mut out = [0; 96];
89-
out[0..32].copy_from_slice(&self.sigma.to_bytes());
90-
out[32..64].copy_from_slice(&self.signature.to_bytes());
92+
out[0..32].copy_from_slice(&self.commitment_point.to_bytes());
93+
out[32..64].copy_from_slice(&self.response.to_bytes());
9194
out[64..96].copy_from_slice(&self.challenge.to_bytes());
9295

9396
out
@@ -106,19 +109,19 @@ impl SchnorrSignature {
106109
bytes
107110
.get(0..32)
108111
.ok_or(SchnorrSignatureError::SerializationError)
109-
.with_context(|| "Could not get the bytes of `sigma`")?,
112+
.with_context(|| "Could not get the bytes of `commitment_point`")?,
110113
);
111-
let sigma = ProjectivePoint::from_bytes(&u8bytes)
112-
.with_context(|| "Could not convert bytes to `sigma`")?;
114+
let commitment_point = ProjectivePoint::from_bytes(&u8bytes)
115+
.with_context(|| "Could not convert bytes to `commitment_point`")?;
113116

114117
u8bytes.copy_from_slice(
115118
bytes
116119
.get(32..64)
117120
.ok_or(SchnorrSignatureError::SerializationError)
118-
.with_context(|| "Could not get the bytes of `signature`")?,
121+
.with_context(|| "Could not get the bytes of `response`")?,
119122
);
120-
let signature = ScalarFieldElement::from_bytes(&u8bytes)
121-
.with_context(|| "Could not convert the bytes to `signature`")?;
123+
let response = ScalarFieldElement::from_bytes(&u8bytes)
124+
.with_context(|| "Could not convert the bytes to `response`")?;
122125

123126
u8bytes.copy_from_slice(
124127
bytes
@@ -130,8 +133,8 @@ impl SchnorrSignature {
130133
.with_context(|| "Could not convert bytes to `challenge`")?;
131134

132135
Ok(Self {
133-
sigma,
134-
signature,
136+
commitment_point,
137+
response,
135138
challenge,
136139
})
137140
}

mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,66 @@ impl SchnorrSigningKey {
2121
}
2222

2323
/// This function is an adapted version of the Schnorr signature scheme that includes
24-
/// the computation of a deterministic value (called sigma) based on the message and the signing key
24+
/// the computation of a deterministic value (called commitment_point) based on the message and the signing key
2525
/// and works with the Jubjub elliptic curve and the Poseidon hash function.
2626
///
2727
/// Input:
2828
/// - a message: some bytes
2929
/// - a secret key: an element of the scalar field of the Jubjub curve
3030
/// Output:
31-
/// - a signature of the form (sigma, signature, challenge):
32-
/// - sigma is deterministic depending only on the message and secret key
33-
/// - the signature and challenge depends on a random value generated during the signature
31+
/// - a signature of the form (commitment_point, response, challenge):
32+
/// - commitment_point is deterministic depending only on the message and secret key
33+
/// - the response and challenge depends on a random value generated during the signature
3434
///
3535
/// The protocol computes:
36-
/// - sigma = H(Sha256(msg)) * secret_key
36+
/// - commitment_point = secret_key * H(Sha256(msg))
3737
/// - random_scalar, a random value
38-
/// - random_point_1 = H(Sha256(msg)) * random_scalar
39-
/// - random_point_2 = generator * random_scalar, where generator is a generator of the prime-order subgroup of Jubjub
40-
/// - challenge = Poseidon(DST || H(Sha256(msg)) || verification_key || sigma || random_point_1 || random_point_2)
41-
/// - signature = random_scalar - challenge * signing_key
38+
/// - random_point_1 = random_scalar * H(Sha256(msg))
39+
/// - random_point_2 = random_scalar * prime_order_generator_point, where generator is a generator of the prime-order subgroup of Jubjub
40+
/// - challenge = Poseidon(DST || H(Sha256(msg)) || verification_key || commitment_point || random_point_1 || random_point_2)
41+
/// - response = random_scalar - challenge * signing_key
4242
///
43-
/// Output the signature (sigma, signature, challenge)
43+
/// Output the signature (commitment_point, response, challenge)
4444
///
4545
pub fn sign<R: RngCore + CryptoRng>(
4646
&self,
4747
msg: &[u8],
4848
rng: &mut R,
4949
) -> StmResult<SchnorrSignature> {
5050
// Use the subgroup generator to compute the curve points
51-
let generator = PrimeOrderProjectivePoint::create_generator();
51+
let prime_order_generator_point = PrimeOrderProjectivePoint::create_generator();
5252
let verification_key = SchnorrVerificationKey::new_from_signing_key(self.clone())
5353
.with_context(|| "Could not generate verification key from signing key.")?;
5454

5555
// First hashing the message to a scalar then hashing it to a curve point
56-
let msg_hash = ProjectivePoint::hash_to_projective_point(msg);
56+
let msg_hash_point = ProjectivePoint::hash_to_projective_point(msg);
5757

58-
let sigma = msg_hash.scalar_multiplication(&self.0);
58+
let commitment_point = msg_hash_point.scalar_multiplication(&self.0);
5959

60-
// r1 = H(msg) * r, r2 = g * r
6160
let random_scalar = ScalarFieldElement::new_random_nonzero_scalar(rng)
6261
.with_context(|| "Random scalar generation failed during signing.")?;
6362

64-
let random_point_1 = msg_hash.scalar_multiplication(&random_scalar);
65-
let random_point_2 = generator.scalar_multiplication(&random_scalar);
63+
let random_point_1 = msg_hash_point.scalar_multiplication(&random_scalar);
64+
let random_point_2 = prime_order_generator_point.scalar_multiplication(&random_scalar);
6665

6766
// Since the hash function takes as input scalar elements
6867
// We need to convert the EC points to their coordinates
6968
// The order must be preserved
7069
let points_coordinates = collect_coordinates_of_list_of_points(&[
71-
msg_hash,
70+
msg_hash_point,
7271
ProjectivePoint::from_prime_order_projective_point(verification_key.0),
73-
sigma,
72+
commitment_point,
7473
random_point_1,
7574
ProjectivePoint::from_prime_order_projective_point(random_point_2),
7675
]);
7776

7877
let challenge = compute_truncated_digest(&points_coordinates);
79-
let mut signature = challenge.mul(&self.0);
80-
signature = random_scalar.sub(&signature);
78+
let mut response = challenge.mul(&self.0);
79+
response = random_scalar.sub(&response);
8180

8281
Ok(SchnorrSignature {
83-
sigma,
84-
signature,
82+
commitment_point,
83+
response,
8584
challenge,
8685
})
8786
}

0 commit comments

Comments
 (0)