@@ -44,7 +44,7 @@ type JubjubHashToCurve = HashToCurveGadget<
4444
4545type PoseidonHash = PoseidonChip < JubjubBase > ;
4646
47- pub const DST_SIGNATURE : JubjubBase = JubjubBase :: from_raw ( [ 2u64 , 0 , 0 , 0 ] ) ;
47+ pub ( crate ) const DST_SIGNATURE : JubjubBase = JubjubBase :: from_raw ( [ 2u64 , 0 , 0 , 0 ] ) ;
4848
4949
5050#[ derive( Debug , Error ) ]
@@ -58,59 +58,81 @@ pub enum SignatureError {
5858
5959
6060
61-
6261#[ cfg( test) ]
6362mod tests {
63+ // use blst::{blst_p1, blst_p2};
64+ use proptest:: prelude:: * ;
65+ use rand_chacha:: ChaCha20Rng ;
66+ use rand_core:: { RngCore , SeedableRng , OsRng } ;
67+
68+ // use crate::bls_multi_signature::helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk};
69+ use crate :: error:: { MultiSignatureError , RegisterError } ;
70+ use crate :: key_registration:: KeyRegistration ;
71+
6472 use super :: * ;
65- use rand_core:: OsRng ;
66-
67- /// Test signing functionality.
68- #[ test]
69- fn test_signature_verification_valid ( ) {
70- let mut rng = OsRng ;
71- let sk = SigningKey :: generate ( & mut rng) ;
72- let msg = JubjubBase :: random ( & mut rng) ;
73-
74- // Sign the message
75- let signature = sk. sign ( msg, & mut rng) ;
76-
77- // Ensure the components of the signature are non-default values
78- assert_ne ! (
79- signature. sigma,
80- JubjubSubgroup :: identity( ) ,
81- "Signature sigma should not be the identity element."
82- ) ;
83- assert_ne ! (
84- signature. s,
85- JubjubScalar :: ZERO ,
86- "Signature s component should not be zero."
87- ) ;
88- assert_ne ! (
89- signature. c,
90- JubjubBase :: ZERO ,
91- "Signature c component should not be zero."
92- ) ;
93-
94- signature. verify ( msg, & VerificationKey :: from ( & sk) ) . unwrap ( ) ;
73+
74+ impl PartialEq for SchnorrSigningKey {
75+ fn eq ( & self , other : & Self ) -> bool {
76+ self . to_bytes ( ) == other. to_bytes ( )
77+ }
9578 }
9679
97- #[ test]
98- fn test_signature_verification_invalid_signature ( ) {
99- let mut rng = OsRng ;
100- let sk = SigningKey :: generate ( & mut rng) ;
101- let msg = JubjubBase :: random ( & mut rng) ;
102- let vk: VerificationKey = ( & sk) . into ( ) ;
103-
104- // Generate signature and tamper with it
105- let mut signature = sk. sign ( msg, & mut rng) ;
106- signature. s = JubjubScalar :: random ( & mut rng) ; // Modify `s` component
107-
108- // Verify the modified signature
109- let result = signature. verify ( msg, & vk) ;
110- assert ! (
111- result. is_err( ) ,
112- "Invalid signature should fail verification, but it passed."
113- ) ;
80+ // impl Eq for SchnorrSigningKey {}
81+
82+ proptest ! {
83+ #![ proptest_config( ProptestConfig :: with_cases( 1000 ) ) ]
84+
85+ /// Test signing functionality.
86+ #[ test]
87+ fn test_signature_verification_valid( seed in any:: <u64 >( ) ) {
88+ let mut rng = OsRng ;
89+ let sk = SchnorrSigningKey :: generate( & mut rng) ;
90+ let msg = JubjubBase :: random( & mut rng) ;
91+
92+ // Sign the message
93+ let signature = sk. sign( msg, & mut rng) ;
94+
95+ // Ensure the components of the signature are non-default values
96+ assert_ne!(
97+ signature. sigma,
98+ JubjubSubgroup :: identity( ) ,
99+ "Signature sigma should not be the identity element."
100+ ) ;
101+ assert_ne!(
102+ signature. s,
103+ JubjubScalar :: ZERO ,
104+ "Signature s component should not be zero."
105+ ) ;
106+ assert_ne!(
107+ signature. c,
108+ JubjubBase :: ZERO ,
109+ "Signature c component should not be zero."
110+ ) ;
111+
112+ signature. verify( msg, & SchnorrVerificationKey :: from( & sk) ) . unwrap( ) ;
113+ }
114+
115+ #[ test]
116+ fn test_signature_verification_invalid_signature( seed in any:: <u64 >( ) ) {
117+ let mut rng = OsRng ;
118+ let sk = SchnorrSigningKey :: generate( & mut rng) ;
119+ let msg = JubjubBase :: random( & mut rng) ;
120+ let vk: SchnorrVerificationKey = ( & sk) . into( ) ;
121+
122+ // Generate signature and tamper with it
123+ let mut signature = sk. sign( msg, & mut rng) ;
124+ signature. s = JubjubScalar :: random( & mut rng) ; // Modify `s` component
125+
126+ // Verify the modified signature
127+ let result = signature. verify( msg, & vk) ;
128+ assert!(
129+ result. is_err( ) ,
130+ "Invalid signature should fail verification, but it passed."
131+ ) ;
132+ }
133+
134+
114135 }
115136
137+
116138}
0 commit comments