Skip to content

Commit 9ab65d1

Browse files
authored
Merge pull request #6498 from fdefelici/refactor/aac-infallible-to-compile-phase-6467
refactor: aac convert infallible error to compile time
2 parents 4da4c6a + 246510c commit 9ab65d1

File tree

25 files changed

+897
-586
lines changed

25 files changed

+897
-586
lines changed

clarity-types/src/tests/types/signatures.rs

Lines changed: 372 additions & 75 deletions
Large diffs are not rendered by default.

clarity-types/src/types/mod.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,29 @@ use stacks_common::types::chainstate::StacksPrivateKey;
3333
use stacks_common::util::hash;
3434

3535
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,
3938
};
4039
use crate::errors::{CheckErrors, InterpreterError, InterpreterResult as Result, RuntimeErrorType};
4140
use crate::representations::{ClarityName, ContractName, SymbolicExpression};
42-
// use crate::vm::ClarityVersion;
4341

42+
/// Maximum size in bytes allowed for types.
4443
pub const MAX_VALUE_SIZE: u32 = 1024 * 1024; // 1MB
44+
/// Bytes serialization upper limit.
4545
pub const BOUND_VALUE_SERIALIZATION_BYTES: u32 = MAX_VALUE_SIZE * 2;
46+
/// Hex serialization upper limit.
4647
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.
4857
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
5059
pub const WRAPPER_VALUE_SIZE: u32 = 1;
5160

5261
#[derive(Debug, Clone, Eq, Serialize, Deserialize)]
@@ -342,10 +351,10 @@ impl SequenceData {
342351

343352
pub fn element_size(&self) -> Result<u32> {
344353
let out = match self {
345-
SequenceData::Buffer(..) => TypeSignature::min_buffer()?.size(),
354+
SequenceData::Buffer(..) => TypeSignature::BUFFER_MIN.size(),
346355
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(),
349358
}?;
350359
Ok(out)
351360
}
@@ -455,7 +464,7 @@ impl SequenceData {
455464
}
456465
} else {
457466
Err(CheckErrors::TypeValueError(
458-
Box::new(TypeSignature::min_buffer()?),
467+
Box::new(TypeSignature::BUFFER_MIN),
459468
Box::new(to_find),
460469
)
461470
.into())
@@ -484,7 +493,7 @@ impl SequenceData {
484493
}
485494
} else {
486495
Err(CheckErrors::TypeValueError(
487-
Box::new(TypeSignature::min_string_ascii()?),
496+
Box::new(TypeSignature::STRING_ASCII_MIN),
488497
Box::new(to_find),
489498
)
490499
.into())
@@ -505,7 +514,7 @@ impl SequenceData {
505514
}
506515
} else {
507516
Err(CheckErrors::TypeValueError(
508-
Box::new(TypeSignature::min_string_utf8()?),
517+
Box::new(TypeSignature::STRING_UTF8_MIN),
509518
Box::new(to_find),
510519
)
511520
.into())

0 commit comments

Comments
 (0)