@@ -33,20 +33,29 @@ use stacks_common::types::chainstate::StacksPrivateKey;
33
33
use stacks_common:: util:: hash;
34
34
35
35
pub use self :: signatures:: {
36
- AssetIdentifier , BUFF_1 , BUFF_20 , BUFF_21 , BUFF_32 , BUFF_33 , BUFF_64 , BUFF_65 , BufferLength ,
37
- ListTypeData , SequenceSubtype , StringSubtype , StringUTF8Length , TupleTypeSignature ,
38
- TypeSignature ,
36
+ AssetIdentifier , BufferLength , ListTypeData , SequenceSubtype , StringSubtype , StringUTF8Length ,
37
+ TupleTypeSignature , TypeSignature ,
39
38
} ;
40
39
use crate :: errors:: { CheckErrors , InterpreterError , InterpreterResult as Result , RuntimeErrorType } ;
41
40
use crate :: representations:: { ClarityName , ContractName , SymbolicExpression } ;
42
- // use crate::vm::ClarityVersion;
43
41
42
+ /// Maximum size in bytes allowed for types.
44
43
pub const MAX_VALUE_SIZE : u32 = 1024 * 1024 ; // 1MB
44
+ /// Bytes serialization upper limit.
45
45
pub const BOUND_VALUE_SERIALIZATION_BYTES : u32 = MAX_VALUE_SIZE * 2 ;
46
+ /// Hex serialization upper limit.
46
47
pub const BOUND_VALUE_SERIALIZATION_HEX : u32 = BOUND_VALUE_SERIALIZATION_BYTES * 2 ;
47
-
48
+ /// Maximum length for UFT8 string.
49
+ pub const MAX_UTF8_VALUE_SIZE : u32 = MAX_VALUE_SIZE / 4 ;
50
+ /// Maximum string length returned from `to-ascii?`.
51
+ /// 5 bytes reserved for embedding in response.
52
+ pub const MAX_TO_ASCII_RESULT_LEN : u32 = MAX_VALUE_SIZE - 5 ;
53
+ /// Maximum buffer length returned from `to-ascii?`.
54
+ /// 2 bytes reserved for "0x" prefix and 2 characters per byte.
55
+ pub const MAX_TO_ASCII_BUFFER_LEN : u32 = ( MAX_TO_ASCII_RESULT_LEN - 2 ) / 2 ;
56
+ /// Maximum allowed nesting depth of types.
48
57
pub const MAX_TYPE_DEPTH : u8 = 32 ;
49
- // this is the charged size for wrapped values, i.e., response or optionals
58
+ /// this is the charged size for wrapped values, i.e., response or optionals
50
59
pub const WRAPPER_VALUE_SIZE : u32 = 1 ;
51
60
52
61
#[ derive( Debug , Clone , Eq , Serialize , Deserialize ) ]
@@ -342,10 +351,10 @@ impl SequenceData {
342
351
343
352
pub fn element_size ( & self ) -> Result < u32 > {
344
353
let out = match self {
345
- SequenceData :: Buffer ( ..) => TypeSignature :: min_buffer ( ) ? . size ( ) ,
354
+ SequenceData :: Buffer ( ..) => TypeSignature :: BUFFER_MIN . size ( ) ,
346
355
SequenceData :: List ( data) => data. type_signature . get_list_item_type ( ) . size ( ) ,
347
- SequenceData :: String ( CharType :: ASCII ( ..) ) => TypeSignature :: min_string_ascii ( ) ? . size ( ) ,
348
- SequenceData :: String ( CharType :: UTF8 ( ..) ) => TypeSignature :: min_string_utf8 ( ) ? . size ( ) ,
356
+ SequenceData :: String ( CharType :: ASCII ( ..) ) => TypeSignature :: STRING_ASCII_MIN . size ( ) ,
357
+ SequenceData :: String ( CharType :: UTF8 ( ..) ) => TypeSignature :: STRING_UTF8_MIN . size ( ) ,
349
358
} ?;
350
359
Ok ( out)
351
360
}
@@ -455,7 +464,7 @@ impl SequenceData {
455
464
}
456
465
} else {
457
466
Err ( CheckErrors :: TypeValueError (
458
- Box :: new ( TypeSignature :: min_buffer ( ) ? ) ,
467
+ Box :: new ( TypeSignature :: BUFFER_MIN ) ,
459
468
Box :: new ( to_find) ,
460
469
)
461
470
. into ( ) )
@@ -484,7 +493,7 @@ impl SequenceData {
484
493
}
485
494
} else {
486
495
Err ( CheckErrors :: TypeValueError (
487
- Box :: new ( TypeSignature :: min_string_ascii ( ) ? ) ,
496
+ Box :: new ( TypeSignature :: STRING_ASCII_MIN ) ,
488
497
Box :: new ( to_find) ,
489
498
)
490
499
. into ( ) )
@@ -505,7 +514,7 @@ impl SequenceData {
505
514
}
506
515
} else {
507
516
Err ( CheckErrors :: TypeValueError (
508
- Box :: new ( TypeSignature :: min_string_utf8 ( ) ? ) ,
517
+ Box :: new ( TypeSignature :: STRING_UTF8_MIN ) ,
509
518
Box :: new ( to_find) ,
510
519
)
511
520
. into ( ) )
0 commit comments