@@ -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 ) ]
1515pub 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 }
0 commit comments