@@ -7,8 +7,7 @@ use cosmwasm_crypto::{
7
7
ed25519_batch_verify, ed25519_verify, secp256k1_recover_pubkey, secp256k1_verify, CryptoError ,
8
8
} ;
9
9
use cosmwasm_crypto:: {
10
- BATCH_MAX_LEN , ECDSA_PUBKEY_MAX_LEN , ECDSA_SIGNATURE_LEN , EDDSA_PUBKEY_LEN ,
11
- MESSAGE_HASH_MAX_LEN , MESSAGE_MAX_LEN ,
10
+ ECDSA_PUBKEY_MAX_LEN , ECDSA_SIGNATURE_LEN , EDDSA_PUBKEY_LEN , MESSAGE_HASH_MAX_LEN ,
12
11
} ;
13
12
14
13
#[ cfg( feature = "iterator" ) ]
@@ -42,6 +41,14 @@ const MAX_LENGTH_HUMAN_ADDRESS: usize = 90;
42
41
const MAX_LENGTH_QUERY_CHAIN_REQUEST : usize = 64 * KI ;
43
42
/// Length of a serialized Ed25519 signature
44
43
const MAX_LENGTH_ED25519_SIGNATURE : usize = 64 ;
44
+ /// Max length of a Ed25519 message in bytes.
45
+ /// This is an arbitrary value, for performance / memory contraints. If you need to verify larger
46
+ /// messages, let us know.
47
+ const MAX_LENGTH_ED25519_MESSAGE : usize = 128 * 1024 ;
48
+ /// Max number of batch Ed25519 messages / signatures / public_keys.
49
+ /// This is an arbitrary value, for performance / memory contraints. If you need to batch-verify a
50
+ /// larger number of signatures, let us know.
51
+ const MAX_COUNT_ED25519_BATCH : usize = 256 ;
45
52
46
53
/// Max length for a debug message
47
54
const MAX_LENGTH_DEBUG : usize = 2 * MI ;
@@ -326,9 +333,9 @@ fn do_secp256k1_verify<A: BackendApi, S: Storage, Q: Querier>(
326
333
| CryptoError :: InvalidPubkeyFormat { .. }
327
334
| CryptoError :: InvalidSignatureFormat { .. }
328
335
| CryptoError :: GenericErr { .. } => err. code ( ) ,
329
- CryptoError :: BatchErr { .. }
330
- | CryptoError :: InvalidRecoveryParam { .. }
331
- | CryptoError :: MessageTooLong { .. } => panic ! ( "Error must not happen for this call" ) ,
336
+ CryptoError :: BatchErr { .. } | CryptoError :: InvalidRecoveryParam { .. } => {
337
+ panic ! ( "Error must not happen for this call" )
338
+ }
332
339
} ,
333
340
|valid| if valid { 0 } else { 1 } ,
334
341
) )
@@ -360,9 +367,9 @@ fn do_secp256k1_recover_pubkey<A: BackendApi, S: Storage, Q: Querier>(
360
367
| CryptoError :: InvalidSignatureFormat { .. }
361
368
| CryptoError :: InvalidRecoveryParam { .. }
362
369
| CryptoError :: GenericErr { .. } => Ok ( to_high_half ( err. code ( ) ) ) ,
363
- CryptoError :: BatchErr { .. }
364
- | CryptoError :: InvalidPubkeyFormat { .. }
365
- | CryptoError :: MessageTooLong { .. } => panic ! ( "Error must not happen for this call" ) ,
370
+ CryptoError :: BatchErr { .. } | CryptoError :: InvalidPubkeyFormat { .. } => {
371
+ panic ! ( "Error must not happen for this call" )
372
+ }
366
373
} ,
367
374
}
368
375
}
@@ -373,7 +380,7 @@ fn do_ed25519_verify<A: BackendApi, S: Storage, Q: Querier>(
373
380
signature_ptr : u32 ,
374
381
pubkey_ptr : u32 ,
375
382
) -> VmResult < u32 > {
376
- let message = read_region ( & env. memory ( ) , message_ptr, MESSAGE_MAX_LEN ) ?;
383
+ let message = read_region ( & env. memory ( ) , message_ptr, MAX_LENGTH_ED25519_MESSAGE ) ?;
377
384
let signature = read_region ( & env. memory ( ) , signature_ptr, MAX_LENGTH_ED25519_SIGNATURE ) ?;
378
385
let pubkey = read_region ( & env. memory ( ) , pubkey_ptr, EDDSA_PUBKEY_LEN ) ?;
379
386
@@ -382,8 +389,7 @@ fn do_ed25519_verify<A: BackendApi, S: Storage, Q: Querier>(
382
389
process_gas_info :: < A , S , Q > ( env, gas_info) ?;
383
390
Ok ( result. map_or_else (
384
391
|err| match err {
385
- CryptoError :: MessageTooLong { .. }
386
- | CryptoError :: InvalidPubkeyFormat { .. }
392
+ CryptoError :: InvalidPubkeyFormat { .. }
387
393
| CryptoError :: InvalidSignatureFormat { .. }
388
394
| CryptoError :: GenericErr { .. } => err. code ( ) ,
389
395
CryptoError :: BatchErr { .. }
@@ -405,17 +411,17 @@ fn do_ed25519_batch_verify<A: BackendApi, S: Storage, Q: Querier>(
405
411
let messages = read_region (
406
412
& env. memory ( ) ,
407
413
messages_ptr,
408
- ( MESSAGE_MAX_LEN + 4 ) * BATCH_MAX_LEN ,
414
+ ( MAX_LENGTH_ED25519_MESSAGE + 4 ) * MAX_COUNT_ED25519_BATCH ,
409
415
) ?;
410
416
let signatures = read_region (
411
417
& env. memory ( ) ,
412
418
signatures_ptr,
413
- ( MAX_LENGTH_ED25519_SIGNATURE + 4 ) * BATCH_MAX_LEN ,
419
+ ( MAX_LENGTH_ED25519_SIGNATURE + 4 ) * MAX_COUNT_ED25519_BATCH ,
414
420
) ?;
415
421
let public_keys = read_region (
416
422
& env. memory ( ) ,
417
423
public_keys_ptr,
418
- ( EDDSA_PUBKEY_LEN + 4 ) * BATCH_MAX_LEN ,
424
+ ( EDDSA_PUBKEY_LEN + 4 ) * MAX_COUNT_ED25519_BATCH ,
419
425
) ?;
420
426
421
427
let messages = decode_sections ( & messages) ;
@@ -433,7 +439,6 @@ fn do_ed25519_batch_verify<A: BackendApi, S: Storage, Q: Querier>(
433
439
Ok ( result. map_or_else (
434
440
|err| match err {
435
441
CryptoError :: BatchErr { .. }
436
- | CryptoError :: MessageTooLong { .. }
437
442
| CryptoError :: InvalidPubkeyFormat { .. }
438
443
| CryptoError :: InvalidSignatureFormat { .. }
439
444
| CryptoError :: GenericErr { .. } => err. code ( ) ,
@@ -1561,7 +1566,7 @@ mod tests {
1561
1566
1562
1567
let mut msg = hex:: decode ( EDDSA_MSG_HEX ) . unwrap ( ) ;
1563
1568
// extend / break msg
1564
- msg. extend_from_slice ( & [ 0x00 ; MESSAGE_MAX_LEN + 1 ] ) ;
1569
+ msg. extend_from_slice ( & [ 0x00 ; MAX_LENGTH_ED25519_MESSAGE + 1 ] ) ;
1565
1570
let msg_ptr = write_data ( & env, & msg) ;
1566
1571
let sig = hex:: decode ( EDDSA_SIG_HEX ) . unwrap ( ) ;
1567
1572
let sig_ptr = write_data ( & env, & sig) ;
0 commit comments