Skip to content

Commit b299a8c

Browse files
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into feat/expand-consensus-test-to-support-pre-nakamoto-epochs
2 parents 70727c6 + aa20011 commit b299a8c

File tree

23 files changed

+867
-70
lines changed

23 files changed

+867
-70
lines changed

clarity-types/src/errors/cost.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,43 @@ use std::fmt;
1616

1717
use crate::execution_cost::ExecutionCost;
1818

19+
/// Errors related to cost tracking and resource accounting in the Clarity VM.
20+
///
21+
/// Each error variant is annotated with "Invalidates Block" status, indicating
22+
/// whether the inclusion of the transaction that caused the error should cause
23+
/// an entire block to be rejected.
1924
#[derive(Debug, PartialEq, Eq)]
2025
pub enum CostErrors {
21-
CostComputationFailed(String),
26+
/// Arithmetic overflow in cost computation during type-checking, exceeding the maximum threshold.
27+
/// Invalidates Block: true.
2228
CostOverflow,
29+
/// Cumulative type-checking cost exceeds the allocated budget, indicating budget depletion.
30+
/// The first `ExecutionCost` represents the total consumed cost, and the second represents the budget limit.
31+
/// Invalidates Block: true.
2332
CostBalanceExceeded(ExecutionCost, ExecutionCost),
33+
/// Memory usage during type-checking exceeds the allocated budget.
34+
/// The first `u64` represents the total consumed memory, and the second represents the memory limit.
35+
/// Invalidates Block:
36+
/// - true if happens during contract analysis
37+
/// - false if happens during contract intitialization or contract call.
2438
MemoryBalanceExceeded(u64, u64),
39+
/// Failure to access or load cost-related contracts or their state during runtime operations.
40+
/// Invalidates Block: false.
2541
CostContractLoadFailure,
42+
/// Failure in cost-tracking due to an unexpected condition or invalid state.
43+
/// The `String` wraps the specific reason for the failure.
44+
/// Invalidates Block: false.
45+
CostComputationFailed(String),
46+
// Time checker errors
47+
/// Type-checking time exceeds the allowed budget, halting analysis to ensure responsiveness.
48+
/// Invalidates Block: true.
49+
ExecutionTimeExpired,
50+
/// Unexpected condition or failure, indicating a bug or invalid state.
51+
/// Invalidates Block: true.
2652
InterpreterFailure,
53+
/// Unexpected condition or failure, indicating a bug or invalid state.
54+
/// Invalidates Block: true.
2755
Expect(String),
28-
ExecutionTimeExpired,
2956
}
3057

3158
impl fmt::Display for CostErrors {

clarity-types/src/errors/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ impl fmt::Display for Error {
134134
match self {
135135
Error::Runtime(err, stack) => {
136136
write!(f, "{err}")?;
137-
if let Some(stack_trace) = stack {
137+
if let Some(stack_trace) = stack
138+
&& !stack_trace.is_empty()
139+
{
138140
writeln!(f, "\n Stack Trace: ")?;
139141
for item in stack_trace.iter() {
140142
writeln!(f, "{item}")?;

clarity/src/vm/clarity.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ impl From<CheckError> for Error {
8181
}
8282
}
8383

84+
/// Converts [`InterpreterError`] to [`Error`] for transaction execution contexts.
85+
///
86+
/// This conversion is used in:
87+
/// - [`TransactionConnection::initialize_smart_contract`]
88+
/// - [`TransactionConnection::run_contract_call`]
89+
/// - [`TransactionConnection::run_stx_transfer`]
90+
///
91+
/// # Notes
92+
///
93+
/// - [`CheckErrors::MemoryBalanceExceeded`] and [`CheckErrors::CostComputationFailed`]
94+
/// are intentionally not converted to [`Error::CostError`].
95+
/// Instead, they remain wrapped in `Error::Interpreter(Unchecked(CheckErrors::MemoryBalanceExceeded))`,
96+
/// which causes the transaction to fail, but still be included in the block.
97+
///
98+
/// - This behavior differs from direct conversions of [`CheckError`] and [`ParseError`] to [`Error`],
99+
/// where [`CheckErrors::MemoryBalanceExceeded`] is converted to [`Error::CostError`],
100+
/// during contract analysis.
101+
///
102+
/// As a result:
103+
/// - A `MemoryBalanceExceeded` during contract analysis causes the block to be rejected.
104+
/// - A `MemoryBalanceExceeded` during execution (initialization or contract call)
105+
/// causes the transaction to fail, but the block remains valid.
84106
impl From<InterpreterError> for Error {
85107
fn from(e: InterpreterError) -> Self {
86108
match &e {

0 commit comments

Comments
 (0)