@@ -41,6 +41,10 @@ module aptos_framework::sui_derivable_account {
4141 const EINVALID_PUBLIC_KEY : u64 = 6 ;
4242 /// Account address mismatch.
4343 const EACCOUNT_ADDRESS_MISMATCH : u64 = 7 ;
44+ /// Malformed data with trailing bytes.
45+ const EMALFORMED_DATA : u64 = 8 ;
46+ /// Function is deprecated and should not be called.
47+ const EDEPRECATED : u64 = 9 ;
4448
4549 enum SuiAbstractSignature has drop {
4650 MessageV1 {
@@ -110,6 +114,7 @@ module aptos_framework::sui_derivable_account {
110114 let stream = bcs_stream::new (*abstract_public_key);
111115 let sui_account_address = bcs_stream::deserialize_vector <u8 >(&mut stream, |x| deserialize_u8 (x));
112116 let domain = bcs_stream::deserialize_vector <u8 >(&mut stream, |x| deserialize_u8 (x));
117+ assert ! (!bcs_stream::has_remaining (&mut stream), EMALFORMED_DATA );
113118 SuiAbstractPublicKey { sui_account_address, domain }
114119 }
115120
@@ -119,6 +124,7 @@ module aptos_framework::sui_derivable_account {
119124 let signature_type = bcs_stream::deserialize_u8 (&mut stream);
120125 if (signature_type == 0x00 ) {
121126 let signature = bcs_stream::deserialize_vector <u8 >(&mut stream, |x| deserialize_u8 (x));
127+ assert ! (!bcs_stream::has_remaining (&mut stream), EMALFORMED_DATA );
122128 SuiAbstractSignature::MessageV1 { signature }
123129 } else {
124130 abort (EINVALID_SIGNATURE_TYPE )
@@ -189,7 +195,21 @@ module aptos_framework::sui_derivable_account {
189195 pragma verify = false ;
190196 }
191197
198+ /// @deprecated This function is deprecated and will always abort.
192199 public fun authenticate_auth_data (
200+ _aa_auth_data: AbstractionAuthData ,
201+ _entry_function_name: &vector <u8 >
202+ ) {
203+ abort (EDEPRECATED )
204+ }
205+
206+ spec authenticate_auth_data_internal {
207+ // TODO: Issue with `cannot appear in both arithmetic and bitwise
208+ // operation`
209+ pragma verify = false ;
210+ }
211+
212+ fun authenticate_auth_data_internal (
193213 aa_auth_data: AbstractionAuthData ,
194214 entry_function_name: &vector <u8 >
195215 ) {
@@ -244,13 +264,13 @@ module aptos_framework::sui_derivable_account {
244264 }
245265
246266 spec authenticate {
247- // TODO: Issue with spec for authenticate_auth_data
267+ // TODO: Issue with spec for authenticate_auth_data_internal
248268 pragma verify = false ;
249269 }
250270
251271 /// Authorization function for domain account abstraction.
252272 public fun authenticate (account: signer , aa_auth_data: AbstractionAuthData ): signer {
253- daa_authenticate (account, aa_auth_data, |auth_data, entry_name| authenticate_auth_data (auth_data, entry_name))
273+ daa_authenticate (account, aa_auth_data, |auth_data, entry_name| authenticate_auth_data_internal (auth_data, entry_name))
254274 }
255275
256276 #[test_only]
@@ -322,7 +342,7 @@ module aptos_framework::sui_derivable_account {
322342
323343 let auth_data = create_derivable_auth_data (digest, abstract_signature, abstract_public_key);
324344
325- authenticate_auth_data (auth_data, &entry_function_name);
345+ authenticate_auth_data_internal (auth_data, &entry_function_name);
326346 }
327347
328348 #[test(framework = @0x1 )]
@@ -342,7 +362,7 @@ module aptos_framework::sui_derivable_account {
342362
343363 let auth_data = create_derivable_auth_data (digest, abstract_signature, abstract_public_key);
344364
345- authenticate_auth_data (auth_data, &entry_function_name);
365+ authenticate_auth_data_internal (auth_data, &entry_function_name);
346366 }
347367
348368 #[test(framework = @0x1 )]
@@ -362,7 +382,7 @@ module aptos_framework::sui_derivable_account {
362382
363383 let auth_data = create_derivable_auth_data (digest, abstract_signature, abstract_public_key);
364384
365- authenticate_auth_data (auth_data, &entry_function_name);
385+ authenticate_auth_data_internal (auth_data, &entry_function_name);
366386 }
367387
368388
@@ -383,7 +403,36 @@ module aptos_framework::sui_derivable_account {
383403
384404 let auth_data = create_derivable_auth_data (digest, abstract_signature, abstract_public_key);
385405
386- authenticate_auth_data (auth_data, &entry_function_name);
406+ authenticate_auth_data_internal (auth_data, &entry_function_name);
407+ }
408+
409+ #[test]
410+ #[expected_failure(abort_code = EMALFORMED_DATA)]
411+ fun test_deserialize_abstract_signature_with_trailing_bytes () {
412+ let signature_bytes = vector [0 , 151 , 47 , 171 , 144 , 115 , 16 , 129 , 17 , 202 , 212 , 180 , 155 , 213 , 223 , 249 , 203 , 195 , 0 , 84 , 142 , 121 , 167 , 29 , 113 , 159 , 33 , 177 , 108 , 137 , 113 , 160 , 118 , 41 , 246 , 199 , 202 , 79 , 151 , 27 , 86 , 235 , 219 , 123 , 168 , 152 , 38 , 124 , 147 , 146 , 118 , 101 , 37 , 187 , 223 , 206 , 120 , 101 , 148 , 33 , 141 , 80 , 60 , 155 , 13 , 25 , 200 , 235 , 92 , 139 , 72 , 175 , 189 , 40 , 0 , 65 , 76 , 215 , 148 , 94 , 194 , 78 , 134 , 60 , 189 , 212 , 116 , 40 , 134 , 179 , 104 , 31 , 249 , 222 , 84 , 104 , 202 ];
413+ let abstract_signature = create_raw_signature (signature_bytes);
414+ // Append trailing bytes to simulate griefing attack
415+ abstract_signature.push_back (0xDE );
416+ abstract_signature.push_back (0xAD );
417+ abstract_signature.push_back (0xBE );
418+ abstract_signature.push_back (0xEF );
419+ // This should fail with EMALFORMED_DATA due to trailing bytes
420+ deserialize_abstract_signature (&abstract_signature);
421+ }
422+
423+ #[test]
424+ #[expected_failure(abort_code = EMALFORMED_DATA)]
425+ fun test_deserialize_abstract_public_key_with_trailing_bytes () {
426+ let sui_account_address = b"0x8d6ce7a3c13617b29aaf7ec58bee5a611606a89c62c5efbea32e06d8d167bd49 ";
427+ let domain = b"localhost:3001 ";
428+ let abstract_public_key = create_abstract_public_key (sui_account_address, domain);
429+ // Append trailing bytes to simulate griefing attack
430+ abstract_public_key.push_back (0xDE );
431+ abstract_public_key.push_back (0xAD );
432+ abstract_public_key.push_back (0xBE );
433+ abstract_public_key.push_back (0xEF );
434+ // This should fail with EMALFORMED_DATA due to trailing bytes
435+ deserialize_abstract_public_key (&abstract_public_key);
387436 }
388437
389438}
0 commit comments