Skip to content

Commit 9bf223d

Browse files
committed
add missing cost tracking errors
1 parent 8e3f0f7 commit 9bf223d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

clarity/src/vm/clarity_wasm.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ pub fn initialize_contract(
406406
})?;
407407
let mut store = Store::new(&engine, init_context);
408408
let mut linker = Linker::new(&engine);
409-
410409
// Link in the host interface functions.
411410
link_host_functions(&mut linker)?;
412411

@@ -500,7 +499,6 @@ pub fn call_function<'a>(
500499

501500
// Link in the host interface functions.
502501
link_host_functions(&mut linker)?;
503-
504502
let instance = linker
505503
.instantiate(&mut store, &module)
506504
.map_err(|e| Error::Wasm(WasmError::UnableToLoadModule(e)))?;
@@ -8900,6 +8898,7 @@ mod error_mapping {
89008898
read_bytes_from_wasm, read_from_wasm_indirect, read_identifier_from_wasm,
89018899
signature_from_string,
89028900
};
8901+
use crate::vm::costs::CostErrors;
89038902
use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType, ShortReturnType, WasmError};
89048903
use crate::vm::types::{OptionalData, ResponseData};
89058904
use crate::vm::{ClarityVersion, Value};
@@ -8974,6 +8973,21 @@ mod error_mapping {
89748973
/// Indicates an attempt to use a function with too many arguments
89758974
ArgumentCountAtMost = 15,
89768975

8976+
/// Indicates a runtime cost overrun
8977+
CostOverrunRuntime = 100,
8978+
8979+
/// Indicates a read count cost overrun
8980+
CostOverrunReadCount = 101,
8981+
8982+
/// Indicates a read length cost overrun
8983+
CostOverrunReadLength = 102,
8984+
8985+
/// Indicates a write count cost overrun
8986+
CostOverrunWriteCount = 103,
8987+
8988+
/// Indicates a write length cost overrun
8989+
CostOverrunWriteLength = 104,
8990+
89778991
/// A catch-all for errors that are not mapped to specific error codes.
89788992
/// This might be used for unexpected or unclassified errors.
89798993
NotMapped = 99,
@@ -8999,6 +9013,11 @@ mod error_mapping {
89999013
13 => ErrorMap::ArgumentCountMismatch,
90009014
14 => ErrorMap::ArgumentCountAtLeast,
90019015
15 => ErrorMap::ArgumentCountAtMost,
9016+
100 => ErrorMap::CostOverrunRuntime,
9017+
101 => ErrorMap::CostOverrunReadCount,
9018+
102 => ErrorMap::CostOverrunReadLength,
9019+
103 => ErrorMap::CostOverrunWriteCount,
9020+
104 => ErrorMap::CostOverrunWriteLength,
90029021
_ => ErrorMap::NotMapped,
90039022
}
90049023
}
@@ -9179,6 +9198,11 @@ mod error_mapping {
91799198
let (expected, got) = get_runtime_error_arg_lengths(&instance, &mut store);
91809199
Error::Unchecked(CheckErrors::RequiresAtMostArguments(expected, got))
91819200
}
9201+
ErrorMap::CostOverrunRuntime => Error::from(CostErrors::CostOverflow),
9202+
ErrorMap::CostOverrunReadCount => Error::from(CostErrors::CostOverflow),
9203+
ErrorMap::CostOverrunReadLength => Error::from(CostErrors::CostOverflow),
9204+
ErrorMap::CostOverrunWriteCount => Error::from(CostErrors::CostOverflow),
9205+
ErrorMap::CostOverrunWriteLength => Error::from(CostErrors::CostOverflow),
91829206
_ => panic!("Runtime error code {} not supported", runtime_error_code),
91839207
}
91849208
}

0 commit comments

Comments
 (0)