diff --git a/clarity-types/src/errors/mod.rs b/clarity-types/src/errors/mod.rs index 58b42b8a99..4f1d070d26 100644 --- a/clarity-types/src/errors/mod.rs +++ b/clarity-types/src/errors/mod.rs @@ -109,7 +109,7 @@ pub enum ShortReturnType { AssertionFailed(Box), } -pub type InterpreterResult = Result; +pub type VmExecutionResult = Result; impl PartialEq> for IncomparableError { fn eq(&self, _other: &IncomparableError) -> bool { diff --git a/clarity-types/src/types/mod.rs b/clarity-types/src/types/mod.rs index 5fb3e36a1c..9129f96eaf 100644 --- a/clarity-types/src/types/mod.rs +++ b/clarity-types/src/types/mod.rs @@ -37,7 +37,7 @@ pub use self::signatures::{ ListTypeData, SequenceSubtype, StringSubtype, StringUTF8Length, TupleTypeSignature, TypeSignature, }; -use crate::errors::{CheckErrors, InterpreterError, InterpreterResult as Result, RuntimeErrorType}; +use crate::errors::{CheckErrors, InterpreterError, RuntimeErrorType, VmExecutionResult}; use crate::representations::{ClarityName, ContractName, SymbolicExpression}; // use crate::vm::ClarityVersion; @@ -81,7 +81,7 @@ impl StandardPrincipalData { } impl StandardPrincipalData { - pub fn new(version: u8, bytes: [u8; 20]) -> std::result::Result { + pub fn new(version: u8, bytes: [u8; 20]) -> Result { if version >= 32 { return Err(InterpreterError::Expect("Unexpected principal data".into())); } @@ -165,7 +165,7 @@ impl QualifiedContractIdentifier { Self { issuer, name } } - pub fn local(name: &str) -> Result { + pub fn local(name: &str) -> VmExecutionResult { let name = name.to_string().try_into()?; Ok(Self::new(StandardPrincipalData::transient(), name)) } @@ -184,7 +184,7 @@ impl QualifiedContractIdentifier { self.issuer.1 == [0; 20] } - pub fn parse(literal: &str) -> Result { + pub fn parse(literal: &str) -> VmExecutionResult { let split: Vec<_> = literal.splitn(2, '.').collect(); if split.len() != 2 { return Err(RuntimeErrorType::ParseError( @@ -273,20 +273,20 @@ impl TraitIdentifier { } } - pub fn parse_fully_qualified(literal: &str) -> Result { + pub fn parse_fully_qualified(literal: &str) -> VmExecutionResult { let (issuer, contract_name, name) = Self::parse(literal)?; let issuer = issuer.ok_or(RuntimeErrorType::BadTypeConstruction)?; Ok(TraitIdentifier::new(issuer, contract_name, name)) } - pub fn parse_sugared_syntax(literal: &str) -> Result<(ContractName, ClarityName)> { + pub fn parse_sugared_syntax(literal: &str) -> VmExecutionResult<(ContractName, ClarityName)> { let (_, contract_name, name) = Self::parse(literal)?; Ok((contract_name, name)) } pub fn parse( literal: &str, - ) -> Result<(Option, ContractName, ClarityName)> { + ) -> VmExecutionResult<(Option, ContractName, ClarityName)> { let split: Vec<_> = literal.splitn(3, '.').collect(); if split.len() != 3 { return Err(RuntimeErrorType::ParseError( @@ -331,7 +331,7 @@ pub enum SequenceData { } impl SequenceData { - pub fn atom_values(&mut self) -> Result> { + pub fn atom_values(&mut self) -> VmExecutionResult> { match self { SequenceData::Buffer(data) => data.atom_values(), SequenceData::List(data) => data.atom_values(), @@ -340,7 +340,7 @@ impl SequenceData { } } - pub fn element_size(&self) -> Result { + pub fn element_size(&self) -> VmExecutionResult { let out = match self { SequenceData::Buffer(..) => TypeSignature::min_buffer()?.size(), SequenceData::List(data) => data.type_signature.get_list_item_type().size(), @@ -363,7 +363,7 @@ impl SequenceData { self.len() == 0 } - pub fn element_at(self, index: usize) -> Result> { + pub fn element_at(self, index: usize) -> VmExecutionResult> { if self.len() <= index { return Ok(None); } @@ -387,7 +387,12 @@ impl SequenceData { Ok(Some(result)) } - pub fn replace_at(self, epoch: &StacksEpochId, index: usize, element: Value) -> Result { + pub fn replace_at( + self, + epoch: &StacksEpochId, + index: usize, + element: Value, + ) -> VmExecutionResult { let seq_length = self.len(); // Check that the length of the provided element is 1. In the case that SequenceData @@ -439,7 +444,7 @@ impl SequenceData { Value::some(Value::Sequence(new_seq_data)) } - pub fn contains(&self, to_find: Value) -> Result> { + pub fn contains(&self, to_find: Value) -> VmExecutionResult> { match self { SequenceData::Buffer(data) => { if let Value::Sequence(SequenceData::Buffer(to_find_vec)) = to_find { @@ -514,9 +519,9 @@ impl SequenceData { } } - pub fn filter(&mut self, filter: &mut F) -> Result<()> + pub fn filter(&mut self, filter: &mut F) -> VmExecutionResult<()> where - F: FnMut(SymbolicExpression) -> Result, + F: FnMut(SymbolicExpression) -> VmExecutionResult, { // Note: this macro can probably get removed once // ```Vec::drain_filter(&mut self, filter: F) -> DrainFilter``` @@ -557,7 +562,11 @@ impl SequenceData { Ok(()) } - pub fn concat(&mut self, epoch: &StacksEpochId, other_seq: SequenceData) -> Result<()> { + pub fn concat( + &mut self, + epoch: &StacksEpochId, + other_seq: SequenceData, + ) -> VmExecutionResult<()> { match (self, other_seq) { (SequenceData::List(inner_data), SequenceData::List(other_inner_data)) => { inner_data.append(epoch, other_inner_data)?; @@ -583,7 +592,7 @@ impl SequenceData { epoch: &StacksEpochId, left_position: usize, right_position: usize, - ) -> Result { + ) -> VmExecutionResult { let empty_seq = left_position == right_position; let result = match self { @@ -691,15 +700,15 @@ impl fmt::Display for UTF8Data { } pub trait SequencedValue { - fn type_signature(&self) -> std::result::Result; + fn type_signature(&self) -> Result; fn items(&self) -> &Vec; fn drained_items(&mut self) -> Vec; - fn to_value(v: &T) -> Result; + fn to_value(v: &T) -> VmExecutionResult; - fn atom_values(&mut self) -> Result> { + fn atom_values(&mut self) -> VmExecutionResult> { self.drained_items() .iter() .map(|item| Ok(SymbolicExpression::atom_value(Self::to_value(item)?))) @@ -716,13 +725,13 @@ impl SequencedValue for ListData { self.data.drain(..).collect() } - fn type_signature(&self) -> std::result::Result { + fn type_signature(&self) -> Result { Ok(TypeSignature::SequenceType(SequenceSubtype::ListType( self.type_signature.clone(), ))) } - fn to_value(v: &Value) -> Result { + fn to_value(v: &Value) -> VmExecutionResult { Ok(v.clone()) } } @@ -736,7 +745,7 @@ impl SequencedValue for BuffData { self.data.drain(..).collect() } - fn type_signature(&self) -> std::result::Result { + fn type_signature(&self) -> Result { let buff_length = BufferLength::try_from(self.data.len()).map_err(|_| { CheckErrors::Expects("ERROR: Too large of a buffer successfully constructed.".into()) })?; @@ -745,7 +754,7 @@ impl SequencedValue for BuffData { ))) } - fn to_value(v: &u8) -> Result { + fn to_value(v: &u8) -> VmExecutionResult { Ok(Value::buff_from_byte(*v)) } } @@ -759,7 +768,7 @@ impl SequencedValue for ASCIIData { self.data.drain(..).collect() } - fn type_signature(&self) -> std::result::Result { + fn type_signature(&self) -> Result { let buff_length = BufferLength::try_from(self.data.len()).map_err(|_| { CheckErrors::Expects("ERROR: Too large of a buffer successfully constructed.".into()) })?; @@ -768,7 +777,7 @@ impl SequencedValue for ASCIIData { ))) } - fn to_value(v: &u8) -> Result { + fn to_value(v: &u8) -> VmExecutionResult { Value::string_ascii_from_bytes(vec![*v]).map_err(|_| { InterpreterError::Expect("ERROR: Invalid ASCII string successfully constructed".into()) .into() @@ -785,7 +794,7 @@ impl SequencedValue> for UTF8Data { self.data.drain(..).collect() } - fn type_signature(&self) -> std::result::Result { + fn type_signature(&self) -> Result { let str_len = StringUTF8Length::try_from(self.data.len()).map_err(|_| { CheckErrors::Expects("ERROR: Too large of a buffer successfully constructed.".into()) })?; @@ -794,7 +803,7 @@ impl SequencedValue> for UTF8Data { ))) } - fn to_value(v: &Vec) -> Result { + fn to_value(v: &Vec) -> VmExecutionResult { Value::string_utf8_from_bytes(v.clone()).map_err(|_| { InterpreterError::Expect("ERROR: Invalid UTF8 string successfully constructed".into()) .into() @@ -803,7 +812,7 @@ impl SequencedValue> for UTF8Data { } impl OptionalData { - pub fn type_signature(&self) -> std::result::Result { + pub fn type_signature(&self) -> Result { let type_result = match self.data { Some(ref v) => TypeSignature::new_option(TypeSignature::type_of(v)?), None => TypeSignature::new_option(TypeSignature::NoType), @@ -815,7 +824,7 @@ impl OptionalData { } impl ResponseData { - pub fn type_signature(&self) -> std::result::Result { + pub fn type_signature(&self) -> Result { let type_result = match self.committed { true => TypeSignature::new_response( TypeSignature::type_of(&self.data)?, @@ -847,7 +856,7 @@ impl PartialEq for TupleData { pub const NONE: Value = Value::Optional(OptionalData { data: None }); impl Value { - pub fn some(data: Value) -> Result { + pub fn some(data: Value) -> VmExecutionResult { if data.size()? + WRAPPER_VALUE_SIZE > MAX_VALUE_SIZE { Err(CheckErrors::ValueTooLarge.into()) } else if data.depth()? + 1 > MAX_TYPE_DEPTH { @@ -884,7 +893,7 @@ impl Value { }) } - pub fn okay(data: Value) -> Result { + pub fn okay(data: Value) -> VmExecutionResult { if data.size()? + WRAPPER_VALUE_SIZE > MAX_VALUE_SIZE { Err(CheckErrors::ValueTooLarge.into()) } else if data.depth()? + 1 > MAX_TYPE_DEPTH { @@ -897,7 +906,7 @@ impl Value { } } - pub fn error(data: Value) -> Result { + pub fn error(data: Value) -> VmExecutionResult { if data.size()? + WRAPPER_VALUE_SIZE > MAX_VALUE_SIZE { Err(CheckErrors::ValueTooLarge.into()) } else if data.depth()? + 1 > MAX_TYPE_DEPTH { @@ -910,11 +919,11 @@ impl Value { } } - pub fn size(&self) -> Result { + pub fn size(&self) -> VmExecutionResult { Ok(TypeSignature::type_of(self)?.size()?) } - pub fn depth(&self) -> Result { + pub fn depth(&self) -> VmExecutionResult { Ok(TypeSignature::type_of(self)?.depth()) } @@ -925,7 +934,7 @@ impl Value { epoch: &StacksEpochId, list_data: Vec, expected_type: ListTypeData, - ) -> Result { + ) -> VmExecutionResult { // Constructors for TypeSignature ensure that the size of the Value cannot // be greater than MAX_VALUE_SIZE (they error on such constructions) // so we do not need to perform that check here. @@ -949,7 +958,7 @@ impl Value { }))) } - pub fn cons_list_unsanitized(list_data: Vec) -> Result { + pub fn cons_list_unsanitized(list_data: Vec) -> VmExecutionResult { let type_sig = TypeSignature::construct_parent_list_type(&list_data)?; Ok(Value::Sequence(SequenceData::List(ListData { data: list_data, @@ -958,11 +967,11 @@ impl Value { } #[cfg(any(test, feature = "testing"))] - pub fn list_from(list_data: Vec) -> Result { + pub fn list_from(list_data: Vec) -> VmExecutionResult { Value::cons_list_unsanitized(list_data) } - pub fn cons_list(list_data: Vec, epoch: &StacksEpochId) -> Result { + pub fn cons_list(list_data: Vec, epoch: &StacksEpochId) -> VmExecutionResult { // Constructors for TypeSignature ensure that the size of the Value cannot // be greater than MAX_VALUE_SIZE (they error on such constructions) // Aaron: at this point, we've _already_ allocated memory for this type. @@ -986,7 +995,7 @@ impl Value { /// # Errors /// - CheckErrors::ValueTooLarge if `buff_data` is too large. - pub fn buff_from(buff_data: Vec) -> Result { + pub fn buff_from(buff_data: Vec) -> VmExecutionResult { // check the buffer size BufferLength::try_from(buff_data.len())?; // construct the buffer @@ -999,7 +1008,7 @@ impl Value { Value::Sequence(SequenceData::Buffer(BuffData { data: vec![byte] })) } - pub fn string_ascii_from_bytes(bytes: Vec) -> Result { + pub fn string_ascii_from_bytes(bytes: Vec) -> VmExecutionResult { // check the string size BufferLength::try_from(bytes.len())?; @@ -1014,7 +1023,7 @@ impl Value { )))) } - pub fn string_utf8_from_string_utf8_literal(tokenized_str: String) -> Result { + pub fn string_utf8_from_string_utf8_literal(tokenized_str: String) -> VmExecutionResult { let wrapped_codepoints_matcher = Regex::new("^\\\\u\\{(?P[[:xdigit:]]+)\\}") .map_err(|_| InterpreterError::Expect("Bad regex".into()))?; let mut window = tokenized_str.as_str(); @@ -1053,7 +1062,7 @@ impl Value { )))) } - pub fn string_utf8_from_bytes(bytes: Vec) -> Result { + pub fn string_utf8_from_bytes(bytes: Vec) -> VmExecutionResult { let validated_utf8_str = match str::from_utf8(&bytes) { Ok(string) => string, _ => return Err(CheckErrors::InvalidCharactersDetected.into()), @@ -1074,7 +1083,7 @@ impl Value { )))) } - pub fn expect_ascii(self) -> Result { + pub fn expect_ascii(self) -> VmExecutionResult { if let Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { data }))) = self { Ok(String::from_utf8(data) .map_err(|_| InterpreterError::Expect("Non UTF-8 data in string".into()))?) @@ -1084,7 +1093,7 @@ impl Value { } } - pub fn expect_u128(self) -> Result { + pub fn expect_u128(self) -> VmExecutionResult { if let Value::UInt(inner) = self { Ok(inner) } else { @@ -1093,7 +1102,7 @@ impl Value { } } - pub fn expect_i128(self) -> Result { + pub fn expect_i128(self) -> VmExecutionResult { if let Value::Int(inner) = self { Ok(inner) } else { @@ -1102,7 +1111,7 @@ impl Value { } } - pub fn expect_buff(self, sz: usize) -> Result> { + pub fn expect_buff(self, sz: usize) -> VmExecutionResult> { if let Value::Sequence(SequenceData::Buffer(buffdata)) = self { if buffdata.data.len() <= sz { Ok(buffdata.data) @@ -1119,7 +1128,7 @@ impl Value { } } - pub fn expect_list(self) -> Result> { + pub fn expect_list(self) -> VmExecutionResult> { if let Value::Sequence(SequenceData::List(listdata)) = self { Ok(listdata.data) } else { @@ -1128,7 +1137,7 @@ impl Value { } } - pub fn expect_buff_padded(self, sz: usize, pad: u8) -> Result> { + pub fn expect_buff_padded(self, sz: usize, pad: u8) -> VmExecutionResult> { let mut data = self.expect_buff(sz)?; if sz > data.len() { for _ in data.len()..sz { @@ -1138,7 +1147,7 @@ impl Value { Ok(data) } - pub fn expect_bool(self) -> Result { + pub fn expect_bool(self) -> VmExecutionResult { if let Value::Bool(b) = self { Ok(b) } else { @@ -1147,7 +1156,7 @@ impl Value { } } - pub fn expect_tuple(self) -> Result { + pub fn expect_tuple(self) -> VmExecutionResult { if let Value::Tuple(data) = self { Ok(data) } else { @@ -1156,7 +1165,7 @@ impl Value { } } - pub fn expect_optional(self) -> Result> { + pub fn expect_optional(self) -> VmExecutionResult> { if let Value::Optional(opt) = self { match opt.data { Some(boxed_value) => Ok(Some(*boxed_value)), @@ -1168,7 +1177,7 @@ impl Value { } } - pub fn expect_principal(self) -> Result { + pub fn expect_principal(self) -> VmExecutionResult { if let Value::Principal(p) = self { Ok(p) } else { @@ -1177,7 +1186,7 @@ impl Value { } } - pub fn expect_callable(self) -> Result { + pub fn expect_callable(self) -> VmExecutionResult { if let Value::CallableContract(t) = self { Ok(t) } else { @@ -1186,7 +1195,7 @@ impl Value { } } - pub fn expect_result(self) -> Result> { + pub fn expect_result(self) -> VmExecutionResult> { if let Value::Response(res_data) = self { if res_data.committed { Ok(Ok(*res_data.data)) @@ -1199,7 +1208,7 @@ impl Value { } } - pub fn expect_result_ok(self) -> Result { + pub fn expect_result_ok(self) -> VmExecutionResult { if let Value::Response(res_data) = self { if res_data.committed { Ok(*res_data.data) @@ -1213,7 +1222,7 @@ impl Value { } } - pub fn expect_result_err(self) -> Result { + pub fn expect_result_err(self) -> VmExecutionResult { if let Value::Response(res_data) = self { if !res_data.committed { Ok(*res_data.data) @@ -1229,7 +1238,7 @@ impl Value { } impl BuffData { - pub fn len(&self) -> Result { + pub fn len(&self) -> VmExecutionResult { self.data .len() .try_into() @@ -1250,7 +1259,7 @@ impl BuffData { } impl ListData { - pub fn len(&self) -> Result { + pub fn len(&self) -> VmExecutionResult { self.data .len() .try_into() @@ -1261,7 +1270,7 @@ impl ListData { self.data.is_empty() } - fn append(&mut self, epoch: &StacksEpochId, other_seq: ListData) -> Result<()> { + fn append(&mut self, epoch: &StacksEpochId, other_seq: ListData) -> VmExecutionResult<()> { let entry_type_a = self.type_signature.get_list_item_type(); let entry_type_b = other_seq.type_signature.get_list_item_type(); let entry_type = TypeSignature::factor_out_no_type(epoch, entry_type_a, entry_type_b)?; @@ -1282,7 +1291,7 @@ impl ASCIIData { self.data.append(&mut other_seq.data); } - pub fn len(&self) -> Result { + pub fn len(&self) -> VmExecutionResult { self.data .len() .try_into() @@ -1295,7 +1304,7 @@ impl UTF8Data { self.data.append(&mut other_seq.data); } - pub fn len(&self) -> Result { + pub fn len(&self) -> VmExecutionResult { self.data .len() .try_into() @@ -1384,7 +1393,7 @@ impl PrincipalData { self.version() < 32 } - pub fn parse(literal: &str) -> Result { + pub fn parse(literal: &str) -> VmExecutionResult { // be permissive about leading single-quote let literal = literal.strip_prefix('\'').unwrap_or(literal); @@ -1395,12 +1404,12 @@ impl PrincipalData { } } - pub fn parse_qualified_contract_principal(literal: &str) -> Result { + pub fn parse_qualified_contract_principal(literal: &str) -> VmExecutionResult { let contract_id = QualifiedContractIdentifier::parse(literal)?; Ok(PrincipalData::Contract(contract_id)) } - pub fn parse_standard_principal(literal: &str) -> Result { + pub fn parse_standard_principal(literal: &str) -> VmExecutionResult { let (version, data) = c32::c32_address_decode(literal) .map_err(|x| RuntimeErrorType::ParseError(format!("Invalid principal literal: {x}")))?; if data.len() != 20 { @@ -1544,7 +1553,7 @@ impl TupleData { // TODO: add tests from mutation testing results #4833 #[cfg_attr(test, mutants::skip)] - pub fn from_data(data: Vec<(ClarityName, Value)>) -> Result { + pub fn from_data(data: Vec<(ClarityName, Value)>) -> VmExecutionResult { let mut type_map = BTreeMap::new(); let mut data_map = BTreeMap::new(); for (name, value) in data.into_iter() { @@ -1566,7 +1575,7 @@ impl TupleData { epoch: &StacksEpochId, data: Vec<(ClarityName, Value)>, expected: &TupleTypeSignature, - ) -> Result { + ) -> VmExecutionResult { let mut data_map = BTreeMap::new(); for (name, value) in data.into_iter() { let expected_type = expected @@ -1580,19 +1589,19 @@ impl TupleData { Ok(Self::new(expected.clone(), data_map)) } - pub fn get(&self, name: &str) -> Result<&Value> { + pub fn get(&self, name: &str) -> VmExecutionResult<&Value> { self.data_map.get(name).ok_or_else(|| { CheckErrors::NoSuchTupleField(name.to_string(), self.type_signature.clone()).into() }) } - pub fn get_owned(mut self, name: &str) -> Result { + pub fn get_owned(mut self, name: &str) -> VmExecutionResult { self.data_map.remove(name).ok_or_else(|| { CheckErrors::NoSuchTupleField(name.to_string(), self.type_signature.clone()).into() }) } - pub fn shallow_merge(mut base: TupleData, updates: TupleData) -> Result { + pub fn shallow_merge(mut base: TupleData, updates: TupleData) -> VmExecutionResult { let TupleData { data_map, mut type_signature, diff --git a/clarity/src/vm/callables.rs b/clarity/src/vm/callables.rs index b697b3a095..4c8e84d7ca 100644 --- a/clarity/src/vm/callables.rs +++ b/clarity/src/vm/callables.rs @@ -28,7 +28,7 @@ use crate::vm::analysis::errors::CheckErrors; use crate::vm::contexts::ContractContext; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; -use crate::vm::errors::{check_argument_count, Error, InterpreterResult as Result}; +use crate::vm::errors::{check_argument_count, Error, VmExecutionResult}; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{ CallableData, ListData, ListTypeData, OptionalData, PrincipalData, ResponseData, SequenceData, @@ -47,11 +47,15 @@ pub enum CallableType { &'static str, NativeHandle, ClarityCostFunction, - &'static dyn Fn(&[Value]) -> Result, + &'static dyn Fn(&[Value]) -> VmExecutionResult, ), SpecialFunction( &'static str, - &'static dyn Fn(&[SymbolicExpression], &mut Environment, &LocalContext) -> Result, + &'static dyn Fn( + &[SymbolicExpression], + &mut Environment, + &LocalContext, + ) -> VmExecutionResult, ), } @@ -76,14 +80,14 @@ pub struct DefinedFunction { /// implementing a native function. Each variant handles /// different expected number of arguments. pub enum NativeHandle { - SingleArg(&'static dyn Fn(Value) -> Result), - DoubleArg(&'static dyn Fn(Value, Value) -> Result), - MoreArg(&'static dyn Fn(Vec) -> Result), - MoreArgEnv(&'static dyn Fn(Vec, &mut Environment) -> Result), + SingleArg(&'static dyn Fn(Value) -> VmExecutionResult), + DoubleArg(&'static dyn Fn(Value, Value) -> VmExecutionResult), + MoreArg(&'static dyn Fn(Vec) -> VmExecutionResult), + MoreArgEnv(&'static dyn Fn(Vec, &mut Environment) -> VmExecutionResult), } impl NativeHandle { - pub fn apply(&self, mut args: Vec, env: &mut Environment) -> Result { + pub fn apply(&self, mut args: Vec, env: &mut Environment) -> VmExecutionResult { match self { Self::SingleArg(function) => { check_argument_count(1, &args)?; @@ -108,7 +112,7 @@ impl NativeHandle { } } -pub fn cost_input_sized_vararg(args: &[Value]) -> Result { +pub fn cost_input_sized_vararg(args: &[Value]) -> VmExecutionResult { args.iter() .try_fold(0, |sum, value| { (value @@ -139,7 +143,7 @@ impl DefinedFunction { } } - pub fn execute_apply(&self, args: &[Value], env: &mut Environment) -> Result { + pub fn execute_apply(&self, args: &[Value], env: &mut Environment) -> VmExecutionResult { runtime_cost( ClarityCostFunction::UserFunctionApplication, env, @@ -305,7 +309,7 @@ impl DefinedFunction { epoch: &StacksEpochId, contract_defining_trait: &ContractContext, trait_identifier: &TraitIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let trait_name = trait_identifier.name.to_string(); let constraining_trait = contract_defining_trait .lookup_trait_definition(&trait_name) @@ -332,7 +336,7 @@ impl DefinedFunction { self.define_type == DefineType::ReadOnly } - pub fn apply(&self, args: &[Value], env: &mut Environment) -> Result { + pub fn apply(&self, args: &[Value], env: &mut Environment) -> VmExecutionResult { match self.define_type { DefineType::Private => self.execute_apply(args, env), DefineType::Public => env.execute_function_as_transaction(self, args, None, false), @@ -389,7 +393,7 @@ impl CallableType { // recursing into compound types. This function does not check for legality of // these casts, as that is done in the type-checker. Note: depth of recursion // should be capped by earlier checks on the types/values. -fn clarity2_implicit_cast(type_sig: &TypeSignature, value: &Value) -> Result { +fn clarity2_implicit_cast(type_sig: &TypeSignature, value: &Value) -> VmExecutionResult { Ok(match (type_sig, value) { ( TypeSignature::OptionalType(inner_type), diff --git a/clarity/src/vm/contexts.rs b/clarity/src/vm/contexts.rs index 355a0e9d53..1aa40a6b9b 100644 --- a/clarity/src/vm/contexts.rs +++ b/clarity/src/vm/contexts.rs @@ -37,7 +37,7 @@ use crate::vm::database::{ NonFungibleTokenMetadata, }; use crate::vm::errors::{ - CheckErrors, InterpreterError, InterpreterResult as Result, RuntimeErrorType, + CheckErrors, Error, InterpreterError, RuntimeErrorType, VmExecutionResult, }; use crate::vm::events::*; use crate::vm::representations::SymbolicExpression; @@ -268,7 +268,11 @@ impl AssetMap { } // This will get the next amount for a (principal, stx) entry in the stx table. - fn get_next_stx_amount(&self, principal: &PrincipalData, amount: u128) -> Result { + fn get_next_stx_amount( + &self, + principal: &PrincipalData, + amount: u128, + ) -> VmExecutionResult { let current_amount = self.stx_map.get(principal).unwrap_or(&0); current_amount .checked_add(amount) @@ -276,7 +280,11 @@ impl AssetMap { } // This will get the next amount for a (principal, stx) entry in the burn table. - fn get_next_stx_burn_amount(&self, principal: &PrincipalData, amount: u128) -> Result { + fn get_next_stx_burn_amount( + &self, + principal: &PrincipalData, + amount: u128, + ) -> VmExecutionResult { let current_amount = self.burn_map.get(principal).unwrap_or(&0); current_amount .checked_add(amount) @@ -289,7 +297,7 @@ impl AssetMap { principal: &PrincipalData, asset: &AssetIdentifier, amount: u128, - ) -> Result { + ) -> VmExecutionResult { let current_amount = self .token_map .get(principal) @@ -300,14 +308,22 @@ impl AssetMap { .ok_or(RuntimeErrorType::ArithmeticOverflow.into()) } - pub fn add_stx_transfer(&mut self, principal: &PrincipalData, amount: u128) -> Result<()> { + pub fn add_stx_transfer( + &mut self, + principal: &PrincipalData, + amount: u128, + ) -> VmExecutionResult<()> { let next_amount = self.get_next_stx_amount(principal, amount)?; self.stx_map.insert(principal.clone(), next_amount); Ok(()) } - pub fn add_stx_burn(&mut self, principal: &PrincipalData, amount: u128) -> Result<()> { + pub fn add_stx_burn( + &mut self, + principal: &PrincipalData, + amount: u128, + ) -> VmExecutionResult<()> { let next_amount = self.get_next_stx_burn_amount(principal, amount)?; self.burn_map.insert(principal.clone(), next_amount); @@ -334,7 +350,7 @@ impl AssetMap { principal: &PrincipalData, asset: AssetIdentifier, amount: u128, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let next_amount = self.get_next_amount(principal, &asset, amount)?; let principal_map = self.token_map.entry(principal.clone()).or_default(); @@ -345,7 +361,7 @@ impl AssetMap { // This will add any asset transfer data from other to self, // aborting _all_ changes in the event of an error, leaving self unchanged - pub fn commit_other(&mut self, mut other: AssetMap) -> Result<()> { + pub fn commit_other(&mut self, mut other: AssetMap) -> VmExecutionResult<()> { let mut to_add = Vec::new(); let mut stx_to_add = Vec::with_capacity(other.stx_map.len()); let mut stx_burn_to_add = Vec::with_capacity(other.burn_map.len()); @@ -436,7 +452,7 @@ impl AssetMap { self.burn_map.get(principal).copied() } - pub fn get_stx_burned_total(&self) -> Result { + pub fn get_stx_burned_total(&self) -> VmExecutionResult { let mut total: u128 = 0; for principal in self.burn_map.keys() { total = total @@ -603,10 +619,10 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { sponsor: Option, initial_context: Option, f: F, - ) -> std::result::Result<(A, AssetMap, Vec), E> + ) -> Result<(A, AssetMap, Vec), E> where - E: From, - F: FnOnce(&mut Environment) -> std::result::Result, + E: From, + F: FnOnce(&mut Environment) -> Result, { assert!(self.context.is_top_level()); self.begin(); @@ -641,7 +657,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { contract_content: &str, sponsor: Option, ast_rules: ASTRules, - ) -> Result<((), AssetMap, Vec)> { + ) -> VmExecutionResult<((), AssetMap, Vec)> { self.execute_in_env( contract_identifier.issuer.clone().into(), sponsor, @@ -659,7 +675,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { contract_content: &str, sponsor: Option, ast_rules: ASTRules, - ) -> Result<((), AssetMap, Vec)> { + ) -> VmExecutionResult<((), AssetMap, Vec)> { self.execute_in_env( contract_identifier.issuer.clone().into(), sponsor, @@ -680,7 +696,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { contract_content: &ContractAST, contract_string: &str, sponsor: Option, - ) -> Result<((), AssetMap, Vec)> { + ) -> VmExecutionResult<((), AssetMap, Vec)> { self.execute_in_env( contract_identifier.issuer.clone().into(), sponsor, @@ -706,7 +722,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { contract_identifier: QualifiedContractIdentifier, tx_name: &str, args: &[SymbolicExpression], - ) -> Result<(Value, AssetMap, Vec)> { + ) -> VmExecutionResult<(Value, AssetMap, Vec)> { self.execute_in_env(sender, sponsor, None, |exec_env| { exec_env.execute_contract(&contract_identifier, tx_name, args, false) }) @@ -718,7 +734,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { to: &PrincipalData, amount: u128, memo: &BuffData, - ) -> Result<(Value, AssetMap, Vec)> { + ) -> VmExecutionResult<(Value, AssetMap, Vec)> { self.execute_in_env(from.clone(), None, None, |exec_env| { exec_env.stx_transfer(from, to, amount, memo) }) @@ -730,29 +746,24 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { #[cfg(any(test, feature = "testing"))] pub fn stx_faucet(&mut self, recipient: &PrincipalData, amount: u128) { - self.execute_in_env::<_, _, crate::vm::errors::Error>( - recipient.clone(), - None, - None, - |env| { - let mut snapshot = env - .global_context - .database - .get_stx_balance_snapshot(recipient) - .unwrap(); + self.execute_in_env::<_, _, Error>(recipient.clone(), None, None, |env| { + let mut snapshot = env + .global_context + .database + .get_stx_balance_snapshot(recipient) + .unwrap(); - snapshot.credit(amount).unwrap(); - snapshot.save().unwrap(); + snapshot.credit(amount).unwrap(); + snapshot.save().unwrap(); - env.global_context - .database - .increment_ustx_liquid_supply(amount) - .unwrap(); + env.global_context + .database + .increment_ustx_liquid_supply(amount) + .unwrap(); - let res: std::result::Result<(), crate::vm::errors::Error> = Ok(()); - res - }, - ) + let res: Result<(), Error> = Ok(()); + res + }) .unwrap(); } @@ -760,7 +771,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { pub fn eval_raw( &mut self, program: &str, - ) -> Result<(Value, AssetMap, Vec)> { + ) -> VmExecutionResult<(Value, AssetMap, Vec)> { self.execute_in_env( QualifiedContractIdentifier::transient().issuer.into(), None, @@ -774,7 +785,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { contract: &QualifiedContractIdentifier, program: &str, ast_rules: ast::ASTRules, - ) -> Result<(Value, AssetMap, Vec)> { + ) -> VmExecutionResult<(Value, AssetMap, Vec)> { self.execute_in_env( QualifiedContractIdentifier::transient().issuer.into(), None, @@ -788,7 +799,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { &mut self, contract: &QualifiedContractIdentifier, program: &str, - ) -> Result<(Value, AssetMap, Vec)> { + ) -> VmExecutionResult<(Value, AssetMap, Vec)> { self.eval_read_only_with_rules(contract, program, ast::ASTRules::Typical) } @@ -796,7 +807,7 @@ impl<'a, 'hooks> OwnedEnvironment<'a, 'hooks> { self.context.begin(); } - pub fn commit(&mut self) -> Result<(AssetMap, EventBatch)> { + pub fn commit(&mut self) -> VmExecutionResult<(AssetMap, EventBatch)> { let (asset_map, event_batch) = self.context.commit()?; let asset_map = asset_map.ok_or(InterpreterError::FailedToConstructAssetTable)?; let event_batch = event_batch.ok_or(InterpreterError::FailedToConstructEventBatch)?; @@ -835,18 +846,18 @@ impl CostTracker for Environment<'_, '_, '_> { &mut self, cost_function: ClarityCostFunction, input: &[u64], - ) -> std::result::Result { + ) -> Result { self.global_context .cost_track .compute_cost(cost_function, input) } - fn add_cost(&mut self, cost: ExecutionCost) -> std::result::Result<(), CostErrors> { + fn add_cost(&mut self, cost: ExecutionCost) -> Result<(), CostErrors> { self.global_context.cost_track.add_cost(cost) } - fn add_memory(&mut self, memory: u64) -> std::result::Result<(), CostErrors> { + fn add_memory(&mut self, memory: u64) -> Result<(), CostErrors> { self.global_context.cost_track.add_memory(memory) } - fn drop_memory(&mut self, memory: u64) -> std::result::Result<(), CostErrors> { + fn drop_memory(&mut self, memory: u64) -> Result<(), CostErrors> { self.global_context.cost_track.drop_memory(memory) } fn reset_memory(&mut self) { @@ -857,7 +868,7 @@ impl CostTracker for Environment<'_, '_, '_> { contract: &QualifiedContractIdentifier, function: &ClarityName, input: &[u64], - ) -> std::result::Result { + ) -> Result { self.global_context .cost_track .short_circuit_contract_call(contract, function, input) @@ -869,17 +880,17 @@ impl CostTracker for GlobalContext<'_, '_> { &mut self, cost_function: ClarityCostFunction, input: &[u64], - ) -> std::result::Result { + ) -> Result { self.cost_track.compute_cost(cost_function, input) } - fn add_cost(&mut self, cost: ExecutionCost) -> std::result::Result<(), CostErrors> { + fn add_cost(&mut self, cost: ExecutionCost) -> Result<(), CostErrors> { self.cost_track.add_cost(cost) } - fn add_memory(&mut self, memory: u64) -> std::result::Result<(), CostErrors> { + fn add_memory(&mut self, memory: u64) -> Result<(), CostErrors> { self.cost_track.add_memory(memory) } - fn drop_memory(&mut self, memory: u64) -> std::result::Result<(), CostErrors> { + fn drop_memory(&mut self, memory: u64) -> Result<(), CostErrors> { self.cost_track.drop_memory(memory) } fn reset_memory(&mut self) { @@ -890,7 +901,7 @@ impl CostTracker for GlobalContext<'_, '_> { contract: &QualifiedContractIdentifier, function: &ClarityName, input: &[u64], - ) -> std::result::Result { + ) -> Result { self.cost_track .short_circuit_contract_call(contract, function, input) } @@ -954,7 +965,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { contract_identifier: &QualifiedContractIdentifier, program: &str, rules: ast::ASTRules, - ) -> Result { + ) -> VmExecutionResult { let clarity_version = self.contract_context.clarity_version; let parsed = ast::build_ast_with_rules( @@ -1008,11 +1019,15 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { &mut self, contract_identifier: &QualifiedContractIdentifier, program: &str, - ) -> Result { + ) -> VmExecutionResult { self.eval_read_only_with_rules(contract_identifier, program, ast::ASTRules::Typical) } - pub fn eval_raw_with_rules(&mut self, program: &str, rules: ast::ASTRules) -> Result { + pub fn eval_raw_with_rules( + &mut self, + program: &str, + rules: ast::ASTRules, + ) -> VmExecutionResult { let contract_id = QualifiedContractIdentifier::transient(); let clarity_version = self.contract_context.clarity_version; @@ -1037,7 +1052,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { } #[cfg(any(test, feature = "testing"))] - pub fn eval_raw(&mut self, program: &str) -> Result { + pub fn eval_raw(&mut self, program: &str) -> VmExecutionResult { self.eval_raw_with_rules(program, ast::ASTRules::Typical) } @@ -1073,7 +1088,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { tx_name: &str, args: &[SymbolicExpression], read_only: bool, - ) -> Result { + ) -> VmExecutionResult { self.inner_execute_contract(contract, tx_name, args, read_only, false) } @@ -1086,7 +1101,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { tx_name: &str, args: &[SymbolicExpression], read_only: bool, - ) -> Result { + ) -> VmExecutionResult { self.inner_execute_contract(contract, tx_name, args, read_only, true) } @@ -1103,7 +1118,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { args: &[SymbolicExpression], read_only: bool, allow_private: bool, - ) -> Result { + ) -> VmExecutionResult { let contract_size = self .global_context .database @@ -1123,7 +1138,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { return Err(CheckErrors::PublicFunctionNotReadOnly(contract_identifier.to_string(), tx_name.to_string()).into()); } - let args: Result> = args.iter() + let args: VmExecutionResult> = args.iter() .map(|arg| { let value = arg.match_atom_value() .ok_or_else(|| InterpreterError::InterpreterError(format!("Passed non-value expression to exec_tx on {tx_name}!")))?; @@ -1180,7 +1195,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { args: &[Value], next_contract_context: Option<&ContractContext>, allow_private: bool, - ) -> Result { + ) -> VmExecutionResult { let make_read_only = function.is_read_only(); if make_read_only { @@ -1217,7 +1232,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { bhh: StacksBlockId, closure: &SymbolicExpression, local: &LocalContext, - ) -> Result { + ) -> VmExecutionResult { self.global_context.begin_read_only(); let result = self @@ -1247,7 +1262,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { contract_identifier: QualifiedContractIdentifier, contract_content: &str, ast_rules: ASTRules, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let clarity_version = self.contract_context.clarity_version; let contract_ast = ast::build_ast_with_rules( @@ -1272,7 +1287,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { contract_version: ClarityVersion, contract_content: &ContractAST, contract_string: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { self.global_context.begin(); // wrap in a closure so that `?` can be caught and the global_context can roll_back() @@ -1344,7 +1359,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { to: &PrincipalData, amount: u128, memo: &BuffData, - ) -> Result { + ) -> VmExecutionResult { self.global_context.begin(); let result = stx_transfer_consolidated(self, from, to, amount, memo); match result { @@ -1365,10 +1380,10 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { } } - pub fn run_as_transaction(&mut self, f: F) -> std::result::Result + pub fn run_as_transaction(&mut self, f: F) -> Result where - F: FnOnce(&mut Self) -> std::result::Result, - E: From, + F: FnOnce(&mut Self) -> Result, + E: From, { self.global_context.begin(); let result = f(self); @@ -1402,7 +1417,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { StacksTransactionEvent::SmartContractEvent(print_event) } - pub fn register_print_event(&mut self, value: Value) -> Result<()> { + pub fn register_print_event(&mut self, value: Value) -> VmExecutionResult<()> { let event = Self::construct_print_transaction_event( &self.contract_context.contract_identifier, &value, @@ -1418,7 +1433,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { recipient: PrincipalData, amount: u128, memo: BuffData, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = STXTransferEventData { sender, recipient, @@ -1431,7 +1446,11 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { Ok(()) } - pub fn register_stx_burn_event(&mut self, sender: PrincipalData, amount: u128) -> Result<()> { + pub fn register_stx_burn_event( + &mut self, + sender: PrincipalData, + amount: u128, + ) -> VmExecutionResult<()> { let event_data = STXBurnEventData { sender, amount }; let event = StacksTransactionEvent::STXEvent(STXEventType::STXBurnEvent(event_data)); @@ -1445,7 +1464,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { recipient: PrincipalData, value: Value, asset_identifier: AssetIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = NFTTransferEventData { sender, recipient, @@ -1463,7 +1482,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { recipient: PrincipalData, value: Value, asset_identifier: AssetIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = NFTMintEventData { recipient, asset_identifier, @@ -1480,7 +1499,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { sender: PrincipalData, value: Value, asset_identifier: AssetIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = NFTBurnEventData { sender, asset_identifier, @@ -1498,7 +1517,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { recipient: PrincipalData, amount: u128, asset_identifier: AssetIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = FTTransferEventData { sender, recipient, @@ -1516,7 +1535,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { recipient: PrincipalData, amount: u128, asset_identifier: AssetIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = FTMintEventData { recipient, asset_identifier, @@ -1533,7 +1552,7 @@ impl<'a, 'b, 'hooks> Environment<'a, 'b, 'hooks> { sender: PrincipalData, amount: u128, asset_identifier: AssetIdentifier, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let event_data = FTBurnEventData { sender, asset_identifier, @@ -1580,7 +1599,7 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { } } - fn get_asset_map(&mut self) -> Result<&mut AssetMap> { + fn get_asset_map(&mut self) -> VmExecutionResult<&mut AssetMap> { self.asset_maps .last_mut() .ok_or_else(|| InterpreterError::Expect("Failed to obtain asset map".into()).into()) @@ -1592,7 +1611,7 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { contract_identifier: &QualifiedContractIdentifier, asset_name: &ClarityName, transfered: Value, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let asset_identifier = AssetIdentifier { contract_identifier: contract_identifier.clone(), asset_name: asset_name.clone(), @@ -1608,7 +1627,7 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { contract_identifier: &QualifiedContractIdentifier, asset_name: &ClarityName, transfered: u128, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let asset_identifier = AssetIdentifier { contract_identifier: contract_identifier.clone(), asset_name: asset_name.clone(), @@ -1617,17 +1636,25 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { .add_token_transfer(sender, asset_identifier, transfered) } - pub fn log_stx_transfer(&mut self, sender: &PrincipalData, transfered: u128) -> Result<()> { + pub fn log_stx_transfer( + &mut self, + sender: &PrincipalData, + transfered: u128, + ) -> VmExecutionResult<()> { self.get_asset_map()?.add_stx_transfer(sender, transfered) } - pub fn log_stx_burn(&mut self, sender: &PrincipalData, transfered: u128) -> Result<()> { + pub fn log_stx_burn( + &mut self, + sender: &PrincipalData, + transfered: u128, + ) -> VmExecutionResult<()> { self.get_asset_map()?.add_stx_burn(sender, transfered) } - pub fn execute(&mut self, f: F) -> Result + pub fn execute(&mut self, f: F) -> VmExecutionResult where - F: FnOnce(&mut Self) -> Result, + F: FnOnce(&mut Self) -> VmExecutionResult, { self.begin(); let result = f(self).or_else(|e| { @@ -1647,10 +1674,10 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { sponsor: Option, contract_context: ContractContext, f: F, - ) -> std::result::Result + ) -> Result where - E: From, - F: FnOnce(&mut Environment) -> std::result::Result, + E: From, + F: FnOnce(&mut Environment) -> Result, { self.begin(); @@ -1696,7 +1723,7 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { self.read_only.push(true); } - pub fn commit(&mut self) -> Result<(Option, Option)> { + pub fn commit(&mut self) -> VmExecutionResult<(Option, Option)> { trace!("Calling commit"); self.read_only.pop(); let asset_map = self.asset_maps.pop().ok_or_else(|| { @@ -1729,7 +1756,7 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { Ok((out_map, out_batch)) } - pub fn roll_back(&mut self) -> Result<()> { + pub fn roll_back(&mut self) -> VmExecutionResult<()> { let popped = self.asset_maps.pop(); if popped.is_none() { return Err(InterpreterError::Expect("Expected entry to rollback".into()).into()); @@ -1751,9 +1778,9 @@ impl<'a, 'hooks> GlobalContext<'a, 'hooks> { // clarity = { version = "*", features = ["devtools"] } pub fn handle_tx_result( &mut self, - result: Result, + result: VmExecutionResult, allow_private: bool, - ) -> Result { + ) -> VmExecutionResult { if let Ok(result) = result { if let Value::Response(data) = result { if data.committed { @@ -1885,7 +1912,7 @@ impl<'a> LocalContext<'a> { } } - pub fn extend(&'a self) -> Result> { + pub fn extend(&'a self) -> VmExecutionResult> { if self.depth >= MAX_CONTEXT_DEPTH { Err(RuntimeErrorType::MaxContextDepthReached.into()) } else { @@ -1958,7 +1985,11 @@ impl CallStack { self.apply_depth -= 1; } - pub fn remove(&mut self, function: &FunctionIdentifier, tracked: bool) -> Result<()> { + pub fn remove( + &mut self, + function: &FunctionIdentifier, + tracked: bool, + ) -> VmExecutionResult<()> { if let Some(removed) = self.stack.pop() { if removed != *function { return Err(InterpreterError::InterpreterError( diff --git a/clarity/src/vm/contracts.rs b/clarity/src/vm/contracts.rs index 17493a978f..d806313d25 100644 --- a/clarity/src/vm/contracts.rs +++ b/clarity/src/vm/contracts.rs @@ -18,7 +18,7 @@ use stacks_common::types::StacksEpochId; use crate::vm::ast::ContractAST; use crate::vm::contexts::{ContractContext, GlobalContext}; -use crate::vm::errors::InterpreterResult as Result; +use crate::vm::errors::VmExecutionResult; use crate::vm::eval_all; use crate::vm::types::{PrincipalData, QualifiedContractIdentifier}; use crate::vm::version::ClarityVersion; @@ -37,7 +37,7 @@ impl Contract { sponsor: Option, global_context: &mut GlobalContext, version: ClarityVersion, - ) -> Result { + ) -> VmExecutionResult { let mut contract_context = ContractContext::new(contract_identifier, version); eval_all( diff --git a/clarity/src/vm/costs/cost_functions.rs b/clarity/src/vm/costs/cost_functions.rs index 6abbaec555..f6d22f59b4 100644 --- a/clarity/src/vm/costs/cost_functions.rs +++ b/clarity/src/vm/costs/cost_functions.rs @@ -15,7 +15,7 @@ // along with this program. If not, see . use super::ExecutionCost; -use crate::vm::errors::{InterpreterResult, RuntimeErrorType}; +use crate::vm::errors::{RuntimeErrorType, VmExecutionResult}; define_named_enum!(ClarityCostFunction { AnalysisTypeAnnotate("cost_analysis_type_annotate"), @@ -167,7 +167,7 @@ define_named_enum!(ClarityCostFunction { pub fn linear(n: u64, a: u64, b: u64) -> u64 { a.saturating_mul(n).saturating_add(b) } -pub fn logn(n: u64, a: u64, b: u64) -> InterpreterResult { +pub fn logn(n: u64, a: u64, b: u64) -> VmExecutionResult { if n < 1 { return Err(crate::vm::errors::Error::Runtime( RuntimeErrorType::Arithmetic("log2 must be passed a positive integer".to_string()), @@ -177,7 +177,7 @@ pub fn logn(n: u64, a: u64, b: u64) -> InterpreterResult { let nlog2 = u64::from(64 - 1 - n.leading_zeros()); Ok(a.saturating_mul(nlog2).saturating_add(b)) } -pub fn nlogn(n: u64, a: u64, b: u64) -> InterpreterResult { +pub fn nlogn(n: u64, a: u64, b: u64) -> VmExecutionResult { if n < 1 { return Err(crate::vm::errors::Error::Runtime( RuntimeErrorType::Arithmetic("log2 must be passed a positive integer".to_string()), @@ -189,151 +189,151 @@ pub fn nlogn(n: u64, a: u64, b: u64) -> InterpreterResult { } pub trait CostValues { - fn cost_analysis_type_annotate(n: u64) -> InterpreterResult; - fn cost_analysis_type_check(n: u64) -> InterpreterResult; - fn cost_analysis_type_lookup(n: u64) -> InterpreterResult; - fn cost_analysis_visit(n: u64) -> InterpreterResult; - fn cost_analysis_iterable_func(n: u64) -> InterpreterResult; - fn cost_analysis_option_cons(n: u64) -> InterpreterResult; - fn cost_analysis_option_check(n: u64) -> InterpreterResult; - fn cost_analysis_bind_name(n: u64) -> InterpreterResult; - fn cost_analysis_list_items_check(n: u64) -> InterpreterResult; - fn cost_analysis_check_tuple_get(n: u64) -> InterpreterResult; - fn cost_analysis_check_tuple_merge(n: u64) -> InterpreterResult; - fn cost_analysis_check_tuple_cons(n: u64) -> InterpreterResult; - fn cost_analysis_tuple_items_check(n: u64) -> InterpreterResult; - fn cost_analysis_check_let(n: u64) -> InterpreterResult; - fn cost_analysis_lookup_function(n: u64) -> InterpreterResult; - fn cost_analysis_lookup_function_types(n: u64) -> InterpreterResult; - fn cost_analysis_lookup_variable_const(n: u64) -> InterpreterResult; - fn cost_analysis_lookup_variable_depth(n: u64) -> InterpreterResult; - fn cost_ast_parse(n: u64) -> InterpreterResult; - fn cost_ast_cycle_detection(n: u64) -> InterpreterResult; - fn cost_analysis_storage(n: u64) -> InterpreterResult; - fn cost_analysis_use_trait_entry(n: u64) -> InterpreterResult; - fn cost_analysis_get_function_entry(n: u64) -> InterpreterResult; - fn cost_analysis_fetch_contract_entry(n: u64) -> InterpreterResult; - fn cost_lookup_variable_depth(n: u64) -> InterpreterResult; - fn cost_lookup_variable_size(n: u64) -> InterpreterResult; - fn cost_lookup_function(n: u64) -> InterpreterResult; - fn cost_bind_name(n: u64) -> InterpreterResult; - fn cost_inner_type_check_cost(n: u64) -> InterpreterResult; - fn cost_user_function_application(n: u64) -> InterpreterResult; - fn cost_let(n: u64) -> InterpreterResult; - fn cost_if(n: u64) -> InterpreterResult; - fn cost_asserts(n: u64) -> InterpreterResult; - fn cost_map(n: u64) -> InterpreterResult; - fn cost_filter(n: u64) -> InterpreterResult; - fn cost_len(n: u64) -> InterpreterResult; - fn cost_element_at(n: u64) -> InterpreterResult; - fn cost_index_of(n: u64) -> InterpreterResult; - fn cost_fold(n: u64) -> InterpreterResult; - fn cost_list_cons(n: u64) -> InterpreterResult; - fn cost_type_parse_step(n: u64) -> InterpreterResult; - fn cost_tuple_get(n: u64) -> InterpreterResult; - fn cost_tuple_merge(n: u64) -> InterpreterResult; - fn cost_tuple_cons(n: u64) -> InterpreterResult; - fn cost_add(n: u64) -> InterpreterResult; - fn cost_sub(n: u64) -> InterpreterResult; - fn cost_mul(n: u64) -> InterpreterResult; - fn cost_div(n: u64) -> InterpreterResult; - fn cost_geq(n: u64) -> InterpreterResult; - fn cost_leq(n: u64) -> InterpreterResult; - fn cost_le(n: u64) -> InterpreterResult; - fn cost_ge(n: u64) -> InterpreterResult; - fn cost_int_cast(n: u64) -> InterpreterResult; - fn cost_mod(n: u64) -> InterpreterResult; - fn cost_pow(n: u64) -> InterpreterResult; - fn cost_sqrti(n: u64) -> InterpreterResult; - fn cost_log2(n: u64) -> InterpreterResult; - fn cost_xor(n: u64) -> InterpreterResult; - fn cost_not(n: u64) -> InterpreterResult; - fn cost_eq(n: u64) -> InterpreterResult; - fn cost_begin(n: u64) -> InterpreterResult; - fn cost_hash160(n: u64) -> InterpreterResult; - fn cost_sha256(n: u64) -> InterpreterResult; - fn cost_sha512(n: u64) -> InterpreterResult; - fn cost_sha512t256(n: u64) -> InterpreterResult; - fn cost_keccak256(n: u64) -> InterpreterResult; - fn cost_secp256k1recover(n: u64) -> InterpreterResult; - fn cost_secp256k1verify(n: u64) -> InterpreterResult; - fn cost_print(n: u64) -> InterpreterResult; - fn cost_some_cons(n: u64) -> InterpreterResult; - fn cost_ok_cons(n: u64) -> InterpreterResult; - fn cost_err_cons(n: u64) -> InterpreterResult; - fn cost_default_to(n: u64) -> InterpreterResult; - fn cost_unwrap_ret(n: u64) -> InterpreterResult; - fn cost_unwrap_err_or_ret(n: u64) -> InterpreterResult; - fn cost_is_okay(n: u64) -> InterpreterResult; - fn cost_is_none(n: u64) -> InterpreterResult; - fn cost_is_err(n: u64) -> InterpreterResult; - fn cost_is_some(n: u64) -> InterpreterResult; - fn cost_unwrap(n: u64) -> InterpreterResult; - fn cost_unwrap_err(n: u64) -> InterpreterResult; - fn cost_try_ret(n: u64) -> InterpreterResult; - fn cost_match(n: u64) -> InterpreterResult; - fn cost_or(n: u64) -> InterpreterResult; - fn cost_and(n: u64) -> InterpreterResult; - fn cost_append(n: u64) -> InterpreterResult; - fn cost_concat(n: u64) -> InterpreterResult; - fn cost_as_max_len(n: u64) -> InterpreterResult; - fn cost_contract_call(n: u64) -> InterpreterResult; - fn cost_contract_of(n: u64) -> InterpreterResult; - fn cost_principal_of(n: u64) -> InterpreterResult; - fn cost_at_block(n: u64) -> InterpreterResult; - fn cost_load_contract(n: u64) -> InterpreterResult; - fn cost_create_map(n: u64) -> InterpreterResult; - fn cost_create_var(n: u64) -> InterpreterResult; - fn cost_create_nft(n: u64) -> InterpreterResult; - fn cost_create_ft(n: u64) -> InterpreterResult; - fn cost_fetch_entry(n: u64) -> InterpreterResult; - fn cost_set_entry(n: u64) -> InterpreterResult; - fn cost_fetch_var(n: u64) -> InterpreterResult; - fn cost_set_var(n: u64) -> InterpreterResult; - fn cost_contract_storage(n: u64) -> InterpreterResult; - fn cost_block_info(n: u64) -> InterpreterResult; - fn cost_stx_balance(n: u64) -> InterpreterResult; - fn cost_stx_transfer(n: u64) -> InterpreterResult; - fn cost_ft_mint(n: u64) -> InterpreterResult; - fn cost_ft_transfer(n: u64) -> InterpreterResult; - fn cost_ft_balance(n: u64) -> InterpreterResult; - fn cost_ft_get_supply(n: u64) -> InterpreterResult; - fn cost_ft_burn(n: u64) -> InterpreterResult; - fn cost_nft_mint(n: u64) -> InterpreterResult; - fn cost_nft_transfer(n: u64) -> InterpreterResult; - fn cost_nft_owner(n: u64) -> InterpreterResult; - fn cost_nft_burn(n: u64) -> InterpreterResult; - fn poison_microblock(n: u64) -> InterpreterResult; - fn cost_buff_to_int_le(n: u64) -> InterpreterResult; - fn cost_buff_to_uint_le(n: u64) -> InterpreterResult; - fn cost_buff_to_int_be(n: u64) -> InterpreterResult; - fn cost_buff_to_uint_be(n: u64) -> InterpreterResult; - fn cost_is_standard(n: u64) -> InterpreterResult; - fn cost_principal_destruct(n: u64) -> InterpreterResult; - fn cost_principal_construct(n: u64) -> InterpreterResult; - fn cost_string_to_int(n: u64) -> InterpreterResult; - fn cost_string_to_uint(n: u64) -> InterpreterResult; - fn cost_int_to_ascii(n: u64) -> InterpreterResult; - fn cost_int_to_utf8(n: u64) -> InterpreterResult; - fn cost_burn_block_info(n: u64) -> InterpreterResult; - fn cost_stx_account(n: u64) -> InterpreterResult; - fn cost_slice(n: u64) -> InterpreterResult; - fn cost_to_consensus_buff(n: u64) -> InterpreterResult; - fn cost_from_consensus_buff(n: u64) -> InterpreterResult; - fn cost_stx_transfer_memo(n: u64) -> InterpreterResult; - fn cost_replace_at(n: u64) -> InterpreterResult; - fn cost_as_contract(n: u64) -> InterpreterResult; - fn cost_bitwise_and(n: u64) -> InterpreterResult; - fn cost_bitwise_or(n: u64) -> InterpreterResult; - fn cost_bitwise_not(n: u64) -> InterpreterResult; - fn cost_bitwise_left_shift(n: u64) -> InterpreterResult; - fn cost_bitwise_right_shift(n: u64) -> InterpreterResult; - fn cost_contract_hash(n: u64) -> InterpreterResult; - fn cost_to_ascii(n: u64) -> InterpreterResult; + fn cost_analysis_type_annotate(n: u64) -> VmExecutionResult; + fn cost_analysis_type_check(n: u64) -> VmExecutionResult; + fn cost_analysis_type_lookup(n: u64) -> VmExecutionResult; + fn cost_analysis_visit(n: u64) -> VmExecutionResult; + fn cost_analysis_iterable_func(n: u64) -> VmExecutionResult; + fn cost_analysis_option_cons(n: u64) -> VmExecutionResult; + fn cost_analysis_option_check(n: u64) -> VmExecutionResult; + fn cost_analysis_bind_name(n: u64) -> VmExecutionResult; + fn cost_analysis_list_items_check(n: u64) -> VmExecutionResult; + fn cost_analysis_check_tuple_get(n: u64) -> VmExecutionResult; + fn cost_analysis_check_tuple_merge(n: u64) -> VmExecutionResult; + fn cost_analysis_check_tuple_cons(n: u64) -> VmExecutionResult; + fn cost_analysis_tuple_items_check(n: u64) -> VmExecutionResult; + fn cost_analysis_check_let(n: u64) -> VmExecutionResult; + fn cost_analysis_lookup_function(n: u64) -> VmExecutionResult; + fn cost_analysis_lookup_function_types(n: u64) -> VmExecutionResult; + fn cost_analysis_lookup_variable_const(n: u64) -> VmExecutionResult; + fn cost_analysis_lookup_variable_depth(n: u64) -> VmExecutionResult; + fn cost_ast_parse(n: u64) -> VmExecutionResult; + fn cost_ast_cycle_detection(n: u64) -> VmExecutionResult; + fn cost_analysis_storage(n: u64) -> VmExecutionResult; + fn cost_analysis_use_trait_entry(n: u64) -> VmExecutionResult; + fn cost_analysis_get_function_entry(n: u64) -> VmExecutionResult; + fn cost_analysis_fetch_contract_entry(n: u64) -> VmExecutionResult; + fn cost_lookup_variable_depth(n: u64) -> VmExecutionResult; + fn cost_lookup_variable_size(n: u64) -> VmExecutionResult; + fn cost_lookup_function(n: u64) -> VmExecutionResult; + fn cost_bind_name(n: u64) -> VmExecutionResult; + fn cost_inner_type_check_cost(n: u64) -> VmExecutionResult; + fn cost_user_function_application(n: u64) -> VmExecutionResult; + fn cost_let(n: u64) -> VmExecutionResult; + fn cost_if(n: u64) -> VmExecutionResult; + fn cost_asserts(n: u64) -> VmExecutionResult; + fn cost_map(n: u64) -> VmExecutionResult; + fn cost_filter(n: u64) -> VmExecutionResult; + fn cost_len(n: u64) -> VmExecutionResult; + fn cost_element_at(n: u64) -> VmExecutionResult; + fn cost_index_of(n: u64) -> VmExecutionResult; + fn cost_fold(n: u64) -> VmExecutionResult; + fn cost_list_cons(n: u64) -> VmExecutionResult; + fn cost_type_parse_step(n: u64) -> VmExecutionResult; + fn cost_tuple_get(n: u64) -> VmExecutionResult; + fn cost_tuple_merge(n: u64) -> VmExecutionResult; + fn cost_tuple_cons(n: u64) -> VmExecutionResult; + fn cost_add(n: u64) -> VmExecutionResult; + fn cost_sub(n: u64) -> VmExecutionResult; + fn cost_mul(n: u64) -> VmExecutionResult; + fn cost_div(n: u64) -> VmExecutionResult; + fn cost_geq(n: u64) -> VmExecutionResult; + fn cost_leq(n: u64) -> VmExecutionResult; + fn cost_le(n: u64) -> VmExecutionResult; + fn cost_ge(n: u64) -> VmExecutionResult; + fn cost_int_cast(n: u64) -> VmExecutionResult; + fn cost_mod(n: u64) -> VmExecutionResult; + fn cost_pow(n: u64) -> VmExecutionResult; + fn cost_sqrti(n: u64) -> VmExecutionResult; + fn cost_log2(n: u64) -> VmExecutionResult; + fn cost_xor(n: u64) -> VmExecutionResult; + fn cost_not(n: u64) -> VmExecutionResult; + fn cost_eq(n: u64) -> VmExecutionResult; + fn cost_begin(n: u64) -> VmExecutionResult; + fn cost_hash160(n: u64) -> VmExecutionResult; + fn cost_sha256(n: u64) -> VmExecutionResult; + fn cost_sha512(n: u64) -> VmExecutionResult; + fn cost_sha512t256(n: u64) -> VmExecutionResult; + fn cost_keccak256(n: u64) -> VmExecutionResult; + fn cost_secp256k1recover(n: u64) -> VmExecutionResult; + fn cost_secp256k1verify(n: u64) -> VmExecutionResult; + fn cost_print(n: u64) -> VmExecutionResult; + fn cost_some_cons(n: u64) -> VmExecutionResult; + fn cost_ok_cons(n: u64) -> VmExecutionResult; + fn cost_err_cons(n: u64) -> VmExecutionResult; + fn cost_default_to(n: u64) -> VmExecutionResult; + fn cost_unwrap_ret(n: u64) -> VmExecutionResult; + fn cost_unwrap_err_or_ret(n: u64) -> VmExecutionResult; + fn cost_is_okay(n: u64) -> VmExecutionResult; + fn cost_is_none(n: u64) -> VmExecutionResult; + fn cost_is_err(n: u64) -> VmExecutionResult; + fn cost_is_some(n: u64) -> VmExecutionResult; + fn cost_unwrap(n: u64) -> VmExecutionResult; + fn cost_unwrap_err(n: u64) -> VmExecutionResult; + fn cost_try_ret(n: u64) -> VmExecutionResult; + fn cost_match(n: u64) -> VmExecutionResult; + fn cost_or(n: u64) -> VmExecutionResult; + fn cost_and(n: u64) -> VmExecutionResult; + fn cost_append(n: u64) -> VmExecutionResult; + fn cost_concat(n: u64) -> VmExecutionResult; + fn cost_as_max_len(n: u64) -> VmExecutionResult; + fn cost_contract_call(n: u64) -> VmExecutionResult; + fn cost_contract_of(n: u64) -> VmExecutionResult; + fn cost_principal_of(n: u64) -> VmExecutionResult; + fn cost_at_block(n: u64) -> VmExecutionResult; + fn cost_load_contract(n: u64) -> VmExecutionResult; + fn cost_create_map(n: u64) -> VmExecutionResult; + fn cost_create_var(n: u64) -> VmExecutionResult; + fn cost_create_nft(n: u64) -> VmExecutionResult; + fn cost_create_ft(n: u64) -> VmExecutionResult; + fn cost_fetch_entry(n: u64) -> VmExecutionResult; + fn cost_set_entry(n: u64) -> VmExecutionResult; + fn cost_fetch_var(n: u64) -> VmExecutionResult; + fn cost_set_var(n: u64) -> VmExecutionResult; + fn cost_contract_storage(n: u64) -> VmExecutionResult; + fn cost_block_info(n: u64) -> VmExecutionResult; + fn cost_stx_balance(n: u64) -> VmExecutionResult; + fn cost_stx_transfer(n: u64) -> VmExecutionResult; + fn cost_ft_mint(n: u64) -> VmExecutionResult; + fn cost_ft_transfer(n: u64) -> VmExecutionResult; + fn cost_ft_balance(n: u64) -> VmExecutionResult; + fn cost_ft_get_supply(n: u64) -> VmExecutionResult; + fn cost_ft_burn(n: u64) -> VmExecutionResult; + fn cost_nft_mint(n: u64) -> VmExecutionResult; + fn cost_nft_transfer(n: u64) -> VmExecutionResult; + fn cost_nft_owner(n: u64) -> VmExecutionResult; + fn cost_nft_burn(n: u64) -> VmExecutionResult; + fn poison_microblock(n: u64) -> VmExecutionResult; + fn cost_buff_to_int_le(n: u64) -> VmExecutionResult; + fn cost_buff_to_uint_le(n: u64) -> VmExecutionResult; + fn cost_buff_to_int_be(n: u64) -> VmExecutionResult; + fn cost_buff_to_uint_be(n: u64) -> VmExecutionResult; + fn cost_is_standard(n: u64) -> VmExecutionResult; + fn cost_principal_destruct(n: u64) -> VmExecutionResult; + fn cost_principal_construct(n: u64) -> VmExecutionResult; + fn cost_string_to_int(n: u64) -> VmExecutionResult; + fn cost_string_to_uint(n: u64) -> VmExecutionResult; + fn cost_int_to_ascii(n: u64) -> VmExecutionResult; + fn cost_int_to_utf8(n: u64) -> VmExecutionResult; + fn cost_burn_block_info(n: u64) -> VmExecutionResult; + fn cost_stx_account(n: u64) -> VmExecutionResult; + fn cost_slice(n: u64) -> VmExecutionResult; + fn cost_to_consensus_buff(n: u64) -> VmExecutionResult; + fn cost_from_consensus_buff(n: u64) -> VmExecutionResult; + fn cost_stx_transfer_memo(n: u64) -> VmExecutionResult; + fn cost_replace_at(n: u64) -> VmExecutionResult; + fn cost_as_contract(n: u64) -> VmExecutionResult; + fn cost_bitwise_and(n: u64) -> VmExecutionResult; + fn cost_bitwise_or(n: u64) -> VmExecutionResult; + fn cost_bitwise_not(n: u64) -> VmExecutionResult; + fn cost_bitwise_left_shift(n: u64) -> VmExecutionResult; + fn cost_bitwise_right_shift(n: u64) -> VmExecutionResult; + fn cost_contract_hash(n: u64) -> VmExecutionResult; + fn cost_to_ascii(n: u64) -> VmExecutionResult; } impl ClarityCostFunction { - pub fn eval(&self, n: u64) -> InterpreterResult { + pub fn eval(&self, n: u64) -> VmExecutionResult { match self { ClarityCostFunction::AnalysisTypeAnnotate => C::cost_analysis_type_annotate(n), ClarityCostFunction::AnalysisTypeCheck => C::cost_analysis_type_check(n), diff --git a/clarity/src/vm/costs/costs_1.rs b/clarity/src/vm/costs/costs_1.rs index 1e400f56bd..e42e437809 100644 --- a/clarity/src/vm/costs/costs_1.rs +++ b/clarity/src/vm/costs/costs_1.rs @@ -16,92 +16,92 @@ /// This file implements the cost functions from costs.clar in Rust. use super::cost_functions::{linear, logn, nlogn, CostValues}; use super::ExecutionCost; -use crate::vm::errors::{InterpreterResult, RuntimeErrorType}; +use crate::vm::errors::{RuntimeErrorType, VmExecutionResult}; pub struct Costs1; impl CostValues for Costs1 { - fn cost_analysis_type_annotate(n: u64) -> InterpreterResult { + fn cost_analysis_type_annotate(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_type_check(n: u64) -> InterpreterResult { + fn cost_analysis_type_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_type_lookup(n: u64) -> InterpreterResult { + fn cost_analysis_type_lookup(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_visit(_n: u64) -> InterpreterResult { + fn cost_analysis_visit(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_analysis_iterable_func(n: u64) -> InterpreterResult { + fn cost_analysis_iterable_func(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_option_cons(_n: u64) -> InterpreterResult { + fn cost_analysis_option_cons(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_analysis_option_check(_n: u64) -> InterpreterResult { + fn cost_analysis_option_check(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_analysis_bind_name(n: u64) -> InterpreterResult { + fn cost_analysis_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_list_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_list_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_check_tuple_get(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(logn(n, 1000, 1000)?)) } - fn cost_analysis_check_tuple_merge(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_check_tuple_cons(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1000, 1000)?)) } - fn cost_analysis_tuple_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_tuple_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_check_let(n: u64) -> InterpreterResult { + fn cost_analysis_check_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_lookup_function(_n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_analysis_lookup_function_types(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function_types(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_lookup_variable_const(_n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_const(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_analysis_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1000, 1000)?)) } - fn cost_ast_parse(n: u64) -> InterpreterResult { + fn cost_ast_parse(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 10000, 1000))) } - fn cost_ast_cycle_detection(n: u64) -> InterpreterResult { + fn cost_ast_cycle_detection(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_storage(n: u64) -> InterpreterResult { + fn cost_analysis_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -111,7 +111,7 @@ impl CostValues for Costs1 { }) } - fn cost_analysis_use_trait_entry(n: u64) -> InterpreterResult { + fn cost_analysis_use_trait_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -121,7 +121,7 @@ impl CostValues for Costs1 { }) } - fn cost_analysis_get_function_entry(n: u64) -> InterpreterResult { + fn cost_analysis_get_function_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -131,7 +131,7 @@ impl CostValues for Costs1 { }) } - fn cost_analysis_fetch_contract_entry(n: u64) -> InterpreterResult { + fn cost_analysis_fetch_contract_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -141,275 +141,275 @@ impl CostValues for Costs1 { }) } - fn cost_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_lookup_variable_size(n: u64) -> InterpreterResult { + fn cost_lookup_variable_size(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 0))) } - fn cost_lookup_function(_n: u64) -> InterpreterResult { + fn cost_lookup_function(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_bind_name(_n: u64) -> InterpreterResult { + fn cost_bind_name(_n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_inner_type_check_cost(n: u64) -> InterpreterResult { + fn cost_inner_type_check_cost(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_user_function_application(n: u64) -> InterpreterResult { + fn cost_user_function_application(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_let(n: u64) -> InterpreterResult { + fn cost_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_if(n: u64) -> InterpreterResult { + fn cost_if(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_asserts(n: u64) -> InterpreterResult { + fn cost_asserts(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_map(n: u64) -> InterpreterResult { + fn cost_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_filter(n: u64) -> InterpreterResult { + fn cost_filter(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_len(n: u64) -> InterpreterResult { + fn cost_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_element_at(n: u64) -> InterpreterResult { + fn cost_element_at(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_index_of(n: u64) -> InterpreterResult { + fn cost_index_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_fold(n: u64) -> InterpreterResult { + fn cost_fold(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_list_cons(n: u64) -> InterpreterResult { + fn cost_list_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_type_parse_step(n: u64) -> InterpreterResult { + fn cost_type_parse_step(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_tuple_get(n: u64) -> InterpreterResult { + fn cost_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1000, 1000)?)) } - fn cost_tuple_merge(n: u64) -> InterpreterResult { + fn cost_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_tuple_cons(n: u64) -> InterpreterResult { + fn cost_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1000, 1000)?)) } - fn cost_add(n: u64) -> InterpreterResult { + fn cost_add(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_sub(n: u64) -> InterpreterResult { + fn cost_sub(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_mul(n: u64) -> InterpreterResult { + fn cost_mul(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_div(n: u64) -> InterpreterResult { + fn cost_div(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_geq(n: u64) -> InterpreterResult { + fn cost_geq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_leq(n: u64) -> InterpreterResult { + fn cost_leq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_le(n: u64) -> InterpreterResult { + fn cost_le(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_ge(n: u64) -> InterpreterResult { + fn cost_ge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_int_cast(n: u64) -> InterpreterResult { + fn cost_int_cast(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_mod(n: u64) -> InterpreterResult { + fn cost_mod(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_pow(n: u64) -> InterpreterResult { + fn cost_pow(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_sqrti(n: u64) -> InterpreterResult { + fn cost_sqrti(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_log2(n: u64) -> InterpreterResult { + fn cost_log2(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_xor(n: u64) -> InterpreterResult { + fn cost_xor(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_not(n: u64) -> InterpreterResult { + fn cost_not(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_eq(n: u64) -> InterpreterResult { + fn cost_eq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_begin(n: u64) -> InterpreterResult { + fn cost_begin(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_hash160(n: u64) -> InterpreterResult { + fn cost_hash160(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_sha256(n: u64) -> InterpreterResult { + fn cost_sha256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_sha512(n: u64) -> InterpreterResult { + fn cost_sha512(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_sha512t256(n: u64) -> InterpreterResult { + fn cost_sha512t256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_keccak256(n: u64) -> InterpreterResult { + fn cost_keccak256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_secp256k1recover(n: u64) -> InterpreterResult { + fn cost_secp256k1recover(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_secp256k1verify(n: u64) -> InterpreterResult { + fn cost_secp256k1verify(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_print(n: u64) -> InterpreterResult { + fn cost_print(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_some_cons(n: u64) -> InterpreterResult { + fn cost_some_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_ok_cons(n: u64) -> InterpreterResult { + fn cost_ok_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_err_cons(n: u64) -> InterpreterResult { + fn cost_err_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_default_to(n: u64) -> InterpreterResult { + fn cost_default_to(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_unwrap_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_unwrap_err_or_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_err_or_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_is_okay(n: u64) -> InterpreterResult { + fn cost_is_okay(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_is_none(n: u64) -> InterpreterResult { + fn cost_is_none(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_is_err(n: u64) -> InterpreterResult { + fn cost_is_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_is_some(n: u64) -> InterpreterResult { + fn cost_is_some(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_unwrap(n: u64) -> InterpreterResult { + fn cost_unwrap(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_unwrap_err(n: u64) -> InterpreterResult { + fn cost_unwrap_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_try_ret(n: u64) -> InterpreterResult { + fn cost_try_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_match(n: u64) -> InterpreterResult { + fn cost_match(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_or(n: u64) -> InterpreterResult { + fn cost_or(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_and(n: u64) -> InterpreterResult { + fn cost_and(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_append(n: u64) -> InterpreterResult { + fn cost_append(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_concat(n: u64) -> InterpreterResult { + fn cost_concat(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_as_max_len(n: u64) -> InterpreterResult { + fn cost_as_max_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_contract_call(n: u64) -> InterpreterResult { + fn cost_contract_call(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_contract_of(n: u64) -> InterpreterResult { + fn cost_contract_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_principal_of(n: u64) -> InterpreterResult { + fn cost_principal_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1000)) } - fn cost_at_block(n: u64) -> InterpreterResult { + fn cost_at_block(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 0, @@ -419,7 +419,7 @@ impl CostValues for Costs1 { }) } - fn cost_load_contract(n: u64) -> InterpreterResult { + fn cost_load_contract(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -430,7 +430,7 @@ impl CostValues for Costs1 { }) } - fn cost_create_map(n: u64) -> InterpreterResult { + fn cost_create_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -440,7 +440,7 @@ impl CostValues for Costs1 { }) } - fn cost_create_var(n: u64) -> InterpreterResult { + fn cost_create_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -450,7 +450,7 @@ impl CostValues for Costs1 { }) } - fn cost_create_nft(n: u64) -> InterpreterResult { + fn cost_create_nft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -460,7 +460,7 @@ impl CostValues for Costs1 { }) } - fn cost_create_ft(n: u64) -> InterpreterResult { + fn cost_create_ft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 1, @@ -470,7 +470,7 @@ impl CostValues for Costs1 { }) } - fn cost_fetch_entry(n: u64) -> InterpreterResult { + fn cost_fetch_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -480,7 +480,7 @@ impl CostValues for Costs1 { }) } - fn cost_set_entry(n: u64) -> InterpreterResult { + fn cost_set_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -490,7 +490,7 @@ impl CostValues for Costs1 { }) } - fn cost_fetch_var(n: u64) -> InterpreterResult { + fn cost_fetch_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -500,7 +500,7 @@ impl CostValues for Costs1 { }) } - fn cost_set_var(n: u64) -> InterpreterResult { + fn cost_set_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -510,7 +510,7 @@ impl CostValues for Costs1 { }) } - fn cost_contract_storage(n: u64) -> InterpreterResult { + fn cost_contract_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: linear(n, 1, 1), @@ -520,7 +520,7 @@ impl CostValues for Costs1 { }) } - fn cost_block_info(n: u64) -> InterpreterResult { + fn cost_block_info(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 0, @@ -530,7 +530,7 @@ impl CostValues for Costs1 { }) } - fn cost_stx_balance(n: u64) -> InterpreterResult { + fn cost_stx_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 0, @@ -540,7 +540,7 @@ impl CostValues for Costs1 { }) } - fn cost_stx_transfer(n: u64) -> InterpreterResult { + fn cost_stx_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 1, @@ -550,7 +550,7 @@ impl CostValues for Costs1 { }) } - fn cost_ft_mint(n: u64) -> InterpreterResult { + fn cost_ft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 1, @@ -560,7 +560,7 @@ impl CostValues for Costs1 { }) } - fn cost_ft_transfer(n: u64) -> InterpreterResult { + fn cost_ft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 1, @@ -570,7 +570,7 @@ impl CostValues for Costs1 { }) } - fn cost_ft_balance(n: u64) -> InterpreterResult { + fn cost_ft_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 0, @@ -580,7 +580,7 @@ impl CostValues for Costs1 { }) } - fn cost_nft_mint(n: u64) -> InterpreterResult { + fn cost_nft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 1, @@ -590,7 +590,7 @@ impl CostValues for Costs1 { }) } - fn cost_nft_transfer(n: u64) -> InterpreterResult { + fn cost_nft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 1, @@ -600,7 +600,7 @@ impl CostValues for Costs1 { }) } - fn cost_nft_owner(n: u64) -> InterpreterResult { + fn cost_nft_owner(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -610,7 +610,7 @@ impl CostValues for Costs1 { }) } - fn cost_ft_get_supply(n: u64) -> InterpreterResult { + fn cost_ft_get_supply(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 0, @@ -620,7 +620,7 @@ impl CostValues for Costs1 { }) } - fn cost_ft_burn(n: u64) -> InterpreterResult { + fn cost_ft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 1, @@ -630,7 +630,7 @@ impl CostValues for Costs1 { }) } - fn cost_nft_burn(n: u64) -> InterpreterResult { + fn cost_nft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 1, @@ -640,7 +640,7 @@ impl CostValues for Costs1 { }) } - fn poison_microblock(n: u64) -> InterpreterResult { + fn poison_microblock(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1000, write_length: 1, @@ -650,107 +650,107 @@ impl CostValues for Costs1 { }) } - fn cost_buff_to_int_le(n: u64) -> InterpreterResult { + fn cost_buff_to_int_le(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_uint_le(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_le(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_int_be(n: u64) -> InterpreterResult { + fn cost_buff_to_int_be(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_uint_be(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_be(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_is_standard(n: u64) -> InterpreterResult { + fn cost_is_standard(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_principal_destruct(n: u64) -> InterpreterResult { + fn cost_principal_destruct(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_principal_construct(n: u64) -> InterpreterResult { + fn cost_principal_construct(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_string_to_int(n: u64) -> InterpreterResult { + fn cost_string_to_int(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_string_to_uint(n: u64) -> InterpreterResult { + fn cost_string_to_uint(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_int_to_ascii(n: u64) -> InterpreterResult { + fn cost_int_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_int_to_utf8(n: u64) -> InterpreterResult { + fn cost_int_to_utf8(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_burn_block_info(n: u64) -> InterpreterResult { + fn cost_burn_block_info(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_stx_account(n: u64) -> InterpreterResult { + fn cost_stx_account(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_slice(n: u64) -> InterpreterResult { + fn cost_slice(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_consensus_buff(n: u64) -> InterpreterResult { + fn cost_to_consensus_buff(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_from_consensus_buff(n: u64) -> InterpreterResult { + fn cost_from_consensus_buff(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_stx_transfer_memo(n: u64) -> InterpreterResult { + fn cost_stx_transfer_memo(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_replace_at(n: u64) -> InterpreterResult { + fn cost_replace_at(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_as_contract(n: u64) -> InterpreterResult { + fn cost_as_contract(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_and(n: u64) -> InterpreterResult { + fn cost_bitwise_and(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_or(n: u64) -> InterpreterResult { + fn cost_bitwise_or(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_not(n: u64) -> InterpreterResult { + fn cost_bitwise_not(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_left_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_left_shift(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_right_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_right_shift(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_contract_hash(n: u64) -> InterpreterResult { + fn cost_contract_hash(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_ascii(n: u64) -> InterpreterResult { + fn cost_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } } diff --git a/clarity/src/vm/costs/costs_2.rs b/clarity/src/vm/costs/costs_2.rs index 451008bd1b..3a2f78ce66 100644 --- a/clarity/src/vm/costs/costs_2.rs +++ b/clarity/src/vm/costs/costs_2.rs @@ -16,92 +16,92 @@ /// This file implements the cost functions from costs-2.clar in Rust. use super::cost_functions::{linear, logn, nlogn, CostValues}; use super::ExecutionCost; -use crate::vm::errors::{InterpreterResult, RuntimeErrorType}; +use crate::vm::errors::{RuntimeErrorType, VmExecutionResult}; pub struct Costs2; impl CostValues for Costs2 { - fn cost_analysis_type_annotate(n: u64) -> InterpreterResult { + fn cost_analysis_type_annotate(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 9))) } - fn cost_analysis_type_check(n: u64) -> InterpreterResult { + fn cost_analysis_type_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 113, 1))) } - fn cost_analysis_type_lookup(n: u64) -> InterpreterResult { + fn cost_analysis_type_lookup(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 6))) } - fn cost_analysis_visit(n: u64) -> InterpreterResult { + fn cost_analysis_visit(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1)) } - fn cost_analysis_iterable_func(n: u64) -> InterpreterResult { + fn cost_analysis_iterable_func(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 14))) } - fn cost_analysis_option_cons(n: u64) -> InterpreterResult { + fn cost_analysis_option_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(6)) } - fn cost_analysis_option_check(n: u64) -> InterpreterResult { + fn cost_analysis_option_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(3)) } - fn cost_analysis_bind_name(n: u64) -> InterpreterResult { + fn cost_analysis_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 176))) } - fn cost_analysis_list_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_list_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 4))) } - fn cost_analysis_check_tuple_get(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(logn(n, 1, 2)?)) } - fn cost_analysis_check_tuple_merge(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_check_tuple_cons(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 3, 5)?)) } - fn cost_analysis_tuple_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_tuple_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 59))) } - fn cost_analysis_check_let(n: u64) -> InterpreterResult { + fn cost_analysis_check_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 12))) } - fn cost_analysis_lookup_function(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(20)) } - fn cost_analysis_lookup_function_types(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function_types(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 28))) } - fn cost_analysis_lookup_variable_const(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_const(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(15)) } - fn cost_analysis_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1, 34)?)) } - fn cost_ast_parse(n: u64) -> InterpreterResult { + fn cost_ast_parse(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 172, 287441))) } - fn cost_ast_cycle_detection(n: u64) -> InterpreterResult { + fn cost_ast_cycle_detection(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 141, 72))) } - fn cost_analysis_storage(n: u64) -> InterpreterResult { + fn cost_analysis_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 2, 100), write_length: linear(n, 1, 1), @@ -111,7 +111,7 @@ impl CostValues for Costs2 { }) } - fn cost_analysis_use_trait_entry(n: u64) -> InterpreterResult { + fn cost_analysis_use_trait_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 723), write_length: linear(n, 1, 1), @@ -121,7 +121,7 @@ impl CostValues for Costs2 { }) } - fn cost_analysis_get_function_entry(n: u64) -> InterpreterResult { + fn cost_analysis_get_function_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 81, 1303), write_length: 0, @@ -131,7 +131,7 @@ impl CostValues for Costs2 { }) } - fn cost_analysis_fetch_contract_entry(n: u64) -> InterpreterResult { + fn cost_analysis_fetch_contract_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -141,275 +141,275 @@ impl CostValues for Costs2 { }) } - fn cost_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 14))) } - fn cost_lookup_variable_size(n: u64) -> InterpreterResult { + fn cost_lookup_variable_size(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 1))) } - fn cost_lookup_function(n: u64) -> InterpreterResult { + fn cost_lookup_function(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(16)) } - fn cost_bind_name(n: u64) -> InterpreterResult { + fn cost_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(256)) } - fn cost_inner_type_check_cost(n: u64) -> InterpreterResult { + fn cost_inner_type_check_cost(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 9))) } - fn cost_user_function_application(n: u64) -> InterpreterResult { + fn cost_user_function_application(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 26, 140))) } - fn cost_let(n: u64) -> InterpreterResult { + fn cost_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 146, 862))) } - fn cost_if(n: u64) -> InterpreterResult { + fn cost_if(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(200)) } - fn cost_asserts(n: u64) -> InterpreterResult { + fn cost_asserts(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_map(n: u64) -> InterpreterResult { + fn cost_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1210, 3314))) } - fn cost_filter(n: u64) -> InterpreterResult { + fn cost_filter(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(460)) } - fn cost_len(n: u64) -> InterpreterResult { + fn cost_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(486)) } - fn cost_element_at(n: u64) -> InterpreterResult { + fn cost_element_at(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(619)) } - fn cost_index_of(n: u64) -> InterpreterResult { + fn cost_index_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 243))) } - fn cost_fold(n: u64) -> InterpreterResult { + fn cost_fold(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(483)) } - fn cost_list_cons(n: u64) -> InterpreterResult { + fn cost_list_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 198))) } - fn cost_type_parse_step(n: u64) -> InterpreterResult { + fn cost_type_parse_step(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(5)) } - fn cost_tuple_get(n: u64) -> InterpreterResult { + fn cost_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 4, 1780)?)) } - fn cost_tuple_merge(n: u64) -> InterpreterResult { + fn cost_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 4, 646))) } - fn cost_tuple_cons(n: u64) -> InterpreterResult { + fn cost_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 11, 1101)?)) } - fn cost_add(n: u64) -> InterpreterResult { + fn cost_add(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 157))) } - fn cost_sub(n: u64) -> InterpreterResult { + fn cost_sub(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 157))) } - fn cost_mul(n: u64) -> InterpreterResult { + fn cost_mul(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 157))) } - fn cost_div(n: u64) -> InterpreterResult { + fn cost_div(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 157))) } - fn cost_geq(n: u64) -> InterpreterResult { + fn cost_geq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_leq(n: u64) -> InterpreterResult { + fn cost_leq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_le(n: u64) -> InterpreterResult { + fn cost_le(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_ge(n: u64) -> InterpreterResult { + fn cost_ge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_int_cast(n: u64) -> InterpreterResult { + fn cost_int_cast(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_mod(n: u64) -> InterpreterResult { + fn cost_mod(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_pow(n: u64) -> InterpreterResult { + fn cost_pow(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_sqrti(n: u64) -> InterpreterResult { + fn cost_sqrti(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_log2(n: u64) -> InterpreterResult { + fn cost_log2(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_xor(n: u64) -> InterpreterResult { + fn cost_xor(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_not(n: u64) -> InterpreterResult { + fn cost_not(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_eq(n: u64) -> InterpreterResult { + fn cost_eq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 172))) } - fn cost_begin(n: u64) -> InterpreterResult { + fn cost_begin(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(202)) } - fn cost_hash160(n: u64) -> InterpreterResult { + fn cost_hash160(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 201))) } - fn cost_sha256(n: u64) -> InterpreterResult { + fn cost_sha256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 100))) } - fn cost_sha512(n: u64) -> InterpreterResult { + fn cost_sha512(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 176))) } - fn cost_sha512t256(n: u64) -> InterpreterResult { + fn cost_sha512t256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 188))) } - fn cost_keccak256(n: u64) -> InterpreterResult { + fn cost_keccak256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 221))) } - fn cost_secp256k1recover(n: u64) -> InterpreterResult { + fn cost_secp256k1recover(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(14344)) } - fn cost_secp256k1verify(n: u64) -> InterpreterResult { + fn cost_secp256k1verify(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(13540)) } - fn cost_print(n: u64) -> InterpreterResult { + fn cost_print(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 1413))) } - fn cost_some_cons(n: u64) -> InterpreterResult { + fn cost_some_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(230)) } - fn cost_ok_cons(n: u64) -> InterpreterResult { + fn cost_ok_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(230)) } - fn cost_err_cons(n: u64) -> InterpreterResult { + fn cost_err_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(230)) } - fn cost_default_to(n: u64) -> InterpreterResult { + fn cost_default_to(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_unwrap_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(339)) } - fn cost_unwrap_err_or_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_err_or_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(339)) } - fn cost_is_okay(n: u64) -> InterpreterResult { + fn cost_is_okay(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_is_none(n: u64) -> InterpreterResult { + fn cost_is_none(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_is_err(n: u64) -> InterpreterResult { + fn cost_is_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_is_some(n: u64) -> InterpreterResult { + fn cost_is_some(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_unwrap(n: u64) -> InterpreterResult { + fn cost_unwrap(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_unwrap_err(n: u64) -> InterpreterResult { + fn cost_unwrap_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_try_ret(n: u64) -> InterpreterResult { + fn cost_try_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_match(n: u64) -> InterpreterResult { + fn cost_match(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_or(n: u64) -> InterpreterResult { + fn cost_or(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 149))) } - fn cost_and(n: u64) -> InterpreterResult { + fn cost_and(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 149))) } - fn cost_append(n: u64) -> InterpreterResult { + fn cost_append(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 71, 176))) } - fn cost_concat(n: u64) -> InterpreterResult { + fn cost_concat(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 75, 244))) } - fn cost_as_max_len(n: u64) -> InterpreterResult { + fn cost_as_max_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(475)) } - fn cost_contract_call(n: u64) -> InterpreterResult { + fn cost_contract_call(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(153)) } - fn cost_contract_of(n: u64) -> InterpreterResult { + fn cost_contract_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(13400)) } - fn cost_principal_of(n: u64) -> InterpreterResult { + fn cost_principal_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(999)) } - fn cost_at_block(n: u64) -> InterpreterResult { + fn cost_at_block(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 210, write_length: 0, @@ -419,7 +419,7 @@ impl CostValues for Costs2 { }) } - fn cost_load_contract(n: u64) -> InterpreterResult { + fn cost_load_contract(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 157), write_length: 0, @@ -430,7 +430,7 @@ impl CostValues for Costs2 { }) } - fn cost_create_map(n: u64) -> InterpreterResult { + fn cost_create_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1631), write_length: linear(n, 1, 1), @@ -440,7 +440,7 @@ impl CostValues for Costs2 { }) } - fn cost_create_var(n: u64) -> InterpreterResult { + fn cost_create_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 7, 2152), write_length: linear(n, 1, 1), @@ -450,7 +450,7 @@ impl CostValues for Costs2 { }) } - fn cost_create_nft(n: u64) -> InterpreterResult { + fn cost_create_nft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1610), write_length: linear(n, 1, 1), @@ -460,7 +460,7 @@ impl CostValues for Costs2 { }) } - fn cost_create_ft(n: u64) -> InterpreterResult { + fn cost_create_ft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1972, write_length: 1, @@ -470,7 +470,7 @@ impl CostValues for Costs2 { }) } - fn cost_fetch_entry(n: u64) -> InterpreterResult { + fn cost_fetch_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1539), write_length: 0, @@ -480,7 +480,7 @@ impl CostValues for Costs2 { }) } - fn cost_set_entry(n: u64) -> InterpreterResult { + fn cost_set_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 4, 2204), write_length: linear(n, 1, 1), @@ -490,7 +490,7 @@ impl CostValues for Costs2 { }) } - fn cost_fetch_var(n: u64) -> InterpreterResult { + fn cost_fetch_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 543), write_length: 0, @@ -500,7 +500,7 @@ impl CostValues for Costs2 { }) } - fn cost_set_var(n: u64) -> InterpreterResult { + fn cost_set_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 5, 691), write_length: linear(n, 1, 1), @@ -510,7 +510,7 @@ impl CostValues for Costs2 { }) } - fn cost_contract_storage(n: u64) -> InterpreterResult { + fn cost_contract_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 13, 7982), write_length: linear(n, 1, 1), @@ -520,7 +520,7 @@ impl CostValues for Costs2 { }) } - fn cost_block_info(n: u64) -> InterpreterResult { + fn cost_block_info(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 6321, write_length: 0, @@ -530,7 +530,7 @@ impl CostValues for Costs2 { }) } - fn cost_stx_balance(n: u64) -> InterpreterResult { + fn cost_stx_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1385, write_length: 0, @@ -540,7 +540,7 @@ impl CostValues for Costs2 { }) } - fn cost_stx_transfer(n: u64) -> InterpreterResult { + fn cost_stx_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1430, write_length: 1, @@ -550,7 +550,7 @@ impl CostValues for Costs2 { }) } - fn cost_ft_mint(n: u64) -> InterpreterResult { + fn cost_ft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1645, write_length: 1, @@ -560,7 +560,7 @@ impl CostValues for Costs2 { }) } - fn cost_ft_transfer(n: u64) -> InterpreterResult { + fn cost_ft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 612, write_length: 1, @@ -570,7 +570,7 @@ impl CostValues for Costs2 { }) } - fn cost_ft_balance(n: u64) -> InterpreterResult { + fn cost_ft_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 547, write_length: 0, @@ -580,7 +580,7 @@ impl CostValues for Costs2 { }) } - fn cost_nft_mint(n: u64) -> InterpreterResult { + fn cost_nft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 1, @@ -590,7 +590,7 @@ impl CostValues for Costs2 { }) } - fn cost_nft_transfer(n: u64) -> InterpreterResult { + fn cost_nft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 1, @@ -600,7 +600,7 @@ impl CostValues for Costs2 { }) } - fn cost_nft_owner(n: u64) -> InterpreterResult { + fn cost_nft_owner(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 0, @@ -610,7 +610,7 @@ impl CostValues for Costs2 { }) } - fn cost_ft_get_supply(n: u64) -> InterpreterResult { + fn cost_ft_get_supply(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 483, write_length: 0, @@ -620,7 +620,7 @@ impl CostValues for Costs2 { }) } - fn cost_ft_burn(n: u64) -> InterpreterResult { + fn cost_ft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 612, write_length: 1, @@ -630,7 +630,7 @@ impl CostValues for Costs2 { }) } - fn cost_nft_burn(n: u64) -> InterpreterResult { + fn cost_nft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 1, @@ -640,7 +640,7 @@ impl CostValues for Costs2 { }) } - fn poison_microblock(n: u64) -> InterpreterResult { + fn poison_microblock(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 29568, write_length: 1, @@ -650,107 +650,107 @@ impl CostValues for Costs2 { }) } - fn cost_buff_to_int_le(n: u64) -> InterpreterResult { + fn cost_buff_to_int_le(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_uint_le(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_le(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_int_be(n: u64) -> InterpreterResult { + fn cost_buff_to_int_be(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_uint_be(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_be(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_is_standard(n: u64) -> InterpreterResult { + fn cost_is_standard(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_principal_destruct(n: u64) -> InterpreterResult { + fn cost_principal_destruct(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_principal_construct(n: u64) -> InterpreterResult { + fn cost_principal_construct(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_string_to_int(n: u64) -> InterpreterResult { + fn cost_string_to_int(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_string_to_uint(n: u64) -> InterpreterResult { + fn cost_string_to_uint(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_int_to_ascii(n: u64) -> InterpreterResult { + fn cost_int_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_int_to_utf8(n: u64) -> InterpreterResult { + fn cost_int_to_utf8(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_burn_block_info(n: u64) -> InterpreterResult { + fn cost_burn_block_info(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_stx_account(n: u64) -> InterpreterResult { + fn cost_stx_account(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_slice(n: u64) -> InterpreterResult { + fn cost_slice(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_consensus_buff(n: u64) -> InterpreterResult { + fn cost_to_consensus_buff(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_from_consensus_buff(n: u64) -> InterpreterResult { + fn cost_from_consensus_buff(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_stx_transfer_memo(n: u64) -> InterpreterResult { + fn cost_stx_transfer_memo(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_replace_at(n: u64) -> InterpreterResult { + fn cost_replace_at(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_as_contract(n: u64) -> InterpreterResult { + fn cost_as_contract(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_and(n: u64) -> InterpreterResult { + fn cost_bitwise_and(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_or(n: u64) -> InterpreterResult { + fn cost_bitwise_or(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_not(n: u64) -> InterpreterResult { + fn cost_bitwise_not(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_left_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_left_shift(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_right_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_right_shift(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_contract_hash(n: u64) -> InterpreterResult { + fn cost_contract_hash(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_ascii(n: u64) -> InterpreterResult { + fn cost_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } } diff --git a/clarity/src/vm/costs/costs_2_testnet.rs b/clarity/src/vm/costs/costs_2_testnet.rs index 647bafedb9..ccbab70fab 100644 --- a/clarity/src/vm/costs/costs_2_testnet.rs +++ b/clarity/src/vm/costs/costs_2_testnet.rs @@ -16,92 +16,92 @@ /// This file implements the cost functions from costs-2-testnet.clar in Rust. use super::cost_functions::{linear, logn, nlogn, CostValues}; use super::ExecutionCost; -use crate::vm::errors::{InterpreterResult, RuntimeErrorType}; +use crate::vm::errors::{RuntimeErrorType, VmExecutionResult}; pub struct Costs2Testnet; impl CostValues for Costs2Testnet { - fn cost_analysis_type_annotate(n: u64) -> InterpreterResult { + fn cost_analysis_type_annotate(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 9))) } - fn cost_analysis_type_check(n: u64) -> InterpreterResult { + fn cost_analysis_type_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 113, 1))) } - fn cost_analysis_type_lookup(n: u64) -> InterpreterResult { + fn cost_analysis_type_lookup(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 6))) } - fn cost_analysis_visit(n: u64) -> InterpreterResult { + fn cost_analysis_visit(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1)) } - fn cost_analysis_iterable_func(n: u64) -> InterpreterResult { + fn cost_analysis_iterable_func(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 14))) } - fn cost_analysis_option_cons(n: u64) -> InterpreterResult { + fn cost_analysis_option_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(6)) } - fn cost_analysis_option_check(n: u64) -> InterpreterResult { + fn cost_analysis_option_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(3)) } - fn cost_analysis_bind_name(n: u64) -> InterpreterResult { + fn cost_analysis_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 176))) } - fn cost_analysis_list_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_list_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 4))) } - fn cost_analysis_check_tuple_get(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(logn(n, 1, 2)?)) } - fn cost_analysis_check_tuple_merge(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1000, 1000))) } - fn cost_analysis_check_tuple_cons(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 3, 5)?)) } - fn cost_analysis_tuple_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_tuple_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 59))) } - fn cost_analysis_check_let(n: u64) -> InterpreterResult { + fn cost_analysis_check_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 12))) } - fn cost_analysis_lookup_function(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(20)) } - fn cost_analysis_lookup_function_types(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function_types(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 28))) } - fn cost_analysis_lookup_variable_const(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_const(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(15)) } - fn cost_analysis_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1, 34)?)) } - fn cost_ast_parse(n: u64) -> InterpreterResult { + fn cost_ast_parse(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 172, 287441))) } - fn cost_ast_cycle_detection(n: u64) -> InterpreterResult { + fn cost_ast_cycle_detection(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 141, 72))) } - fn cost_analysis_storage(n: u64) -> InterpreterResult { + fn cost_analysis_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 2, 100), write_length: linear(n, 1, 1), @@ -111,7 +111,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_analysis_use_trait_entry(n: u64) -> InterpreterResult { + fn cost_analysis_use_trait_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 723), write_length: linear(n, 1, 1), @@ -121,7 +121,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_analysis_get_function_entry(n: u64) -> InterpreterResult { + fn cost_analysis_get_function_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 81, 1303), write_length: 0, @@ -131,7 +131,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_analysis_fetch_contract_entry(n: u64) -> InterpreterResult { + fn cost_analysis_fetch_contract_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1000, 1000), write_length: 0, @@ -141,275 +141,275 @@ impl CostValues for Costs2Testnet { }) } - fn cost_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 14))) } - fn cost_lookup_variable_size(n: u64) -> InterpreterResult { + fn cost_lookup_variable_size(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 1))) } - fn cost_lookup_function(n: u64) -> InterpreterResult { + fn cost_lookup_function(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(16)) } - fn cost_bind_name(n: u64) -> InterpreterResult { + fn cost_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(256)) } - fn cost_inner_type_check_cost(n: u64) -> InterpreterResult { + fn cost_inner_type_check_cost(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 9))) } - fn cost_user_function_application(n: u64) -> InterpreterResult { + fn cost_user_function_application(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 26, 140))) } - fn cost_let(n: u64) -> InterpreterResult { + fn cost_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 146, 862))) } - fn cost_if(n: u64) -> InterpreterResult { + fn cost_if(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(200)) } - fn cost_asserts(n: u64) -> InterpreterResult { + fn cost_asserts(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(158)) } - fn cost_map(n: u64) -> InterpreterResult { + fn cost_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1210, 3314))) } - fn cost_filter(n: u64) -> InterpreterResult { + fn cost_filter(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(460)) } - fn cost_len(n: u64) -> InterpreterResult { + fn cost_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(486)) } - fn cost_element_at(n: u64) -> InterpreterResult { + fn cost_element_at(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(619)) } - fn cost_index_of(n: u64) -> InterpreterResult { + fn cost_index_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 243))) } - fn cost_fold(n: u64) -> InterpreterResult { + fn cost_fold(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(483)) } - fn cost_list_cons(n: u64) -> InterpreterResult { + fn cost_list_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 198))) } - fn cost_type_parse_step(n: u64) -> InterpreterResult { + fn cost_type_parse_step(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(5)) } - fn cost_tuple_get(n: u64) -> InterpreterResult { + fn cost_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 4, 1780)?)) } - fn cost_tuple_merge(n: u64) -> InterpreterResult { + fn cost_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 4, 646))) } - fn cost_tuple_cons(n: u64) -> InterpreterResult { + fn cost_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 11, 1101)?)) } - fn cost_add(n: u64) -> InterpreterResult { + fn cost_add(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 12, 156))) } - fn cost_sub(n: u64) -> InterpreterResult { + fn cost_sub(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 12, 156))) } - fn cost_mul(n: u64) -> InterpreterResult { + fn cost_mul(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 157))) } - fn cost_div(n: u64) -> InterpreterResult { + fn cost_div(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 157))) } - fn cost_geq(n: u64) -> InterpreterResult { + fn cost_geq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(166)) } - fn cost_leq(n: u64) -> InterpreterResult { + fn cost_leq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(166)) } - fn cost_le(n: u64) -> InterpreterResult { + fn cost_le(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(166)) } - fn cost_ge(n: u64) -> InterpreterResult { + fn cost_ge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(166)) } - fn cost_int_cast(n: u64) -> InterpreterResult { + fn cost_int_cast(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(164)) } - fn cost_mod(n: u64) -> InterpreterResult { + fn cost_mod(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(168)) } - fn cost_pow(n: u64) -> InterpreterResult { + fn cost_pow(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(170)) } - fn cost_sqrti(n: u64) -> InterpreterResult { + fn cost_sqrti(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(167)) } - fn cost_log2(n: u64) -> InterpreterResult { + fn cost_log2(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(161)) } - fn cost_xor(n: u64) -> InterpreterResult { + fn cost_xor(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(167)) } - fn cost_not(n: u64) -> InterpreterResult { + fn cost_not(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(162)) } - fn cost_eq(n: u64) -> InterpreterResult { + fn cost_eq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 172))) } - fn cost_begin(n: u64) -> InterpreterResult { + fn cost_begin(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(202)) } - fn cost_hash160(n: u64) -> InterpreterResult { + fn cost_hash160(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 201))) } - fn cost_sha256(n: u64) -> InterpreterResult { + fn cost_sha256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 100))) } - fn cost_sha512(n: u64) -> InterpreterResult { + fn cost_sha512(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 176))) } - fn cost_sha512t256(n: u64) -> InterpreterResult { + fn cost_sha512t256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 188))) } - fn cost_keccak256(n: u64) -> InterpreterResult { + fn cost_keccak256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 221))) } - fn cost_secp256k1recover(n: u64) -> InterpreterResult { + fn cost_secp256k1recover(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(14344)) } - fn cost_secp256k1verify(n: u64) -> InterpreterResult { + fn cost_secp256k1verify(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(13540)) } - fn cost_print(n: u64) -> InterpreterResult { + fn cost_print(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 1413))) } - fn cost_some_cons(n: u64) -> InterpreterResult { + fn cost_some_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(230)) } - fn cost_ok_cons(n: u64) -> InterpreterResult { + fn cost_ok_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(230)) } - fn cost_err_cons(n: u64) -> InterpreterResult { + fn cost_err_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(230)) } - fn cost_default_to(n: u64) -> InterpreterResult { + fn cost_default_to(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(249)) } - fn cost_unwrap_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(299)) } - fn cost_unwrap_err_or_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_err_or_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(339)) } - fn cost_is_okay(n: u64) -> InterpreterResult { + fn cost_is_okay(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_is_none(n: u64) -> InterpreterResult { + fn cost_is_none(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_is_err(n: u64) -> InterpreterResult { + fn cost_is_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_is_some(n: u64) -> InterpreterResult { + fn cost_is_some(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(287)) } - fn cost_unwrap(n: u64) -> InterpreterResult { + fn cost_unwrap(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(284)) } - fn cost_unwrap_err(n: u64) -> InterpreterResult { + fn cost_unwrap_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(264)) } - fn cost_try_ret(n: u64) -> InterpreterResult { + fn cost_try_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(256)) } - fn cost_match(n: u64) -> InterpreterResult { + fn cost_match(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(286)) } - fn cost_or(n: u64) -> InterpreterResult { + fn cost_or(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 149))) } - fn cost_and(n: u64) -> InterpreterResult { + fn cost_and(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 149))) } - fn cost_append(n: u64) -> InterpreterResult { + fn cost_append(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 71, 176))) } - fn cost_concat(n: u64) -> InterpreterResult { + fn cost_concat(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 75, 244))) } - fn cost_as_max_len(n: u64) -> InterpreterResult { + fn cost_as_max_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(475)) } - fn cost_contract_call(n: u64) -> InterpreterResult { + fn cost_contract_call(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(153)) } - fn cost_contract_of(n: u64) -> InterpreterResult { + fn cost_contract_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(13400)) } - fn cost_principal_of(n: u64) -> InterpreterResult { + fn cost_principal_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(39)) } - fn cost_at_block(n: u64) -> InterpreterResult { + fn cost_at_block(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 210, write_length: 0, @@ -419,7 +419,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_load_contract(n: u64) -> InterpreterResult { + fn cost_load_contract(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 157), write_length: 0, @@ -430,7 +430,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_create_map(n: u64) -> InterpreterResult { + fn cost_create_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1631), write_length: linear(n, 1, 1), @@ -440,7 +440,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_create_var(n: u64) -> InterpreterResult { + fn cost_create_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 7, 2152), write_length: linear(n, 1, 1), @@ -450,7 +450,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_create_nft(n: u64) -> InterpreterResult { + fn cost_create_nft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1610), write_length: linear(n, 1, 1), @@ -460,7 +460,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_create_ft(n: u64) -> InterpreterResult { + fn cost_create_ft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1972, write_length: 1, @@ -470,7 +470,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_fetch_entry(n: u64) -> InterpreterResult { + fn cost_fetch_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1539), write_length: 0, @@ -480,7 +480,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_set_entry(n: u64) -> InterpreterResult { + fn cost_set_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 4, 2204), write_length: linear(n, 1, 1), @@ -490,7 +490,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_fetch_var(n: u64) -> InterpreterResult { + fn cost_fetch_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 543), write_length: 0, @@ -500,7 +500,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_set_var(n: u64) -> InterpreterResult { + fn cost_set_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 5, 691), write_length: linear(n, 1, 1), @@ -510,7 +510,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_contract_storage(n: u64) -> InterpreterResult { + fn cost_contract_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 13, 7982), write_length: linear(n, 1, 1), @@ -520,7 +520,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_block_info(n: u64) -> InterpreterResult { + fn cost_block_info(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 6321, write_length: 0, @@ -530,7 +530,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_stx_balance(n: u64) -> InterpreterResult { + fn cost_stx_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1385, write_length: 0, @@ -540,7 +540,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_stx_transfer(n: u64) -> InterpreterResult { + fn cost_stx_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1430, write_length: 1, @@ -550,7 +550,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_ft_mint(n: u64) -> InterpreterResult { + fn cost_ft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1645, write_length: 1, @@ -560,7 +560,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_ft_transfer(n: u64) -> InterpreterResult { + fn cost_ft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 612, write_length: 1, @@ -570,7 +570,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_ft_balance(n: u64) -> InterpreterResult { + fn cost_ft_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 547, write_length: 0, @@ -580,7 +580,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_nft_mint(n: u64) -> InterpreterResult { + fn cost_nft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 1, @@ -590,7 +590,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_nft_transfer(n: u64) -> InterpreterResult { + fn cost_nft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 1, @@ -600,7 +600,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_nft_owner(n: u64) -> InterpreterResult { + fn cost_nft_owner(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 0, @@ -610,7 +610,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_ft_get_supply(n: u64) -> InterpreterResult { + fn cost_ft_get_supply(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 483, write_length: 0, @@ -620,7 +620,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_ft_burn(n: u64) -> InterpreterResult { + fn cost_ft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 612, write_length: 1, @@ -630,7 +630,7 @@ impl CostValues for Costs2Testnet { }) } - fn cost_nft_burn(n: u64) -> InterpreterResult { + fn cost_nft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 1, @@ -640,7 +640,7 @@ impl CostValues for Costs2Testnet { }) } - fn poison_microblock(n: u64) -> InterpreterResult { + fn poison_microblock(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 29568, write_length: 1, @@ -650,107 +650,107 @@ impl CostValues for Costs2Testnet { }) } - fn cost_buff_to_int_le(n: u64) -> InterpreterResult { + fn cost_buff_to_int_le(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_uint_le(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_le(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_int_be(n: u64) -> InterpreterResult { + fn cost_buff_to_int_be(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_buff_to_uint_be(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_be(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_is_standard(n: u64) -> InterpreterResult { + fn cost_is_standard(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_principal_destruct(n: u64) -> InterpreterResult { + fn cost_principal_destruct(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_principal_construct(n: u64) -> InterpreterResult { + fn cost_principal_construct(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_string_to_int(n: u64) -> InterpreterResult { + fn cost_string_to_int(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_string_to_uint(n: u64) -> InterpreterResult { + fn cost_string_to_uint(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_int_to_ascii(n: u64) -> InterpreterResult { + fn cost_int_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_int_to_utf8(n: u64) -> InterpreterResult { + fn cost_int_to_utf8(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_burn_block_info(n: u64) -> InterpreterResult { + fn cost_burn_block_info(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_stx_account(n: u64) -> InterpreterResult { + fn cost_stx_account(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_slice(n: u64) -> InterpreterResult { + fn cost_slice(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_consensus_buff(n: u64) -> InterpreterResult { + fn cost_to_consensus_buff(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_from_consensus_buff(n: u64) -> InterpreterResult { + fn cost_from_consensus_buff(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_stx_transfer_memo(n: u64) -> InterpreterResult { + fn cost_stx_transfer_memo(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_replace_at(n: u64) -> InterpreterResult { + fn cost_replace_at(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_as_contract(n: u64) -> InterpreterResult { + fn cost_as_contract(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_and(n: u64) -> InterpreterResult { + fn cost_bitwise_and(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_or(n: u64) -> InterpreterResult { + fn cost_bitwise_or(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_not(n: u64) -> InterpreterResult { + fn cost_bitwise_not(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_left_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_left_shift(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_bitwise_right_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_right_shift(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_contract_hash(n: u64) -> InterpreterResult { + fn cost_contract_hash(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_ascii(n: u64) -> InterpreterResult { + fn cost_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } } diff --git a/clarity/src/vm/costs/costs_3.rs b/clarity/src/vm/costs/costs_3.rs index b195303510..b98d21b09f 100644 --- a/clarity/src/vm/costs/costs_3.rs +++ b/clarity/src/vm/costs/costs_3.rs @@ -16,92 +16,92 @@ /// This file implements the cost functions from costs-3.clar in Rust. use super::cost_functions::{linear, logn, nlogn, CostValues}; use super::ExecutionCost; -use crate::vm::errors::{InterpreterResult, RuntimeErrorType}; +use crate::vm::errors::{RuntimeErrorType, VmExecutionResult}; pub struct Costs3; impl CostValues for Costs3 { - fn cost_analysis_type_annotate(n: u64) -> InterpreterResult { + fn cost_analysis_type_annotate(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 9))) } - fn cost_analysis_type_check(n: u64) -> InterpreterResult { + fn cost_analysis_type_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 113, 1))) } - fn cost_analysis_type_lookup(n: u64) -> InterpreterResult { + fn cost_analysis_type_lookup(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 4))) } - fn cost_analysis_visit(n: u64) -> InterpreterResult { + fn cost_analysis_visit(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(1)) } - fn cost_analysis_iterable_func(n: u64) -> InterpreterResult { + fn cost_analysis_iterable_func(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 14))) } - fn cost_analysis_option_cons(n: u64) -> InterpreterResult { + fn cost_analysis_option_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(5)) } - fn cost_analysis_option_check(n: u64) -> InterpreterResult { + fn cost_analysis_option_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(4)) } - fn cost_analysis_bind_name(n: u64) -> InterpreterResult { + fn cost_analysis_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 59))) } - fn cost_analysis_list_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_list_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 4))) } - fn cost_analysis_check_tuple_get(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(logn(n, 1, 2)?)) } - fn cost_analysis_check_tuple_merge(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 45, 49)?)) } - fn cost_analysis_check_tuple_cons(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 3, 5)?)) } - fn cost_analysis_tuple_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_tuple_items_check(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 28))) } - fn cost_analysis_check_let(n: u64) -> InterpreterResult { + fn cost_analysis_check_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 10))) } - fn cost_analysis_lookup_function(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(18)) } - fn cost_analysis_lookup_function_types(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function_types(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 26))) } - fn cost_analysis_lookup_variable_const(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_const(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(15)) } - fn cost_analysis_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 1, 12)?)) } - fn cost_ast_parse(n: u64) -> InterpreterResult { + fn cost_ast_parse(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 27, 81))) } - fn cost_ast_cycle_detection(n: u64) -> InterpreterResult { + fn cost_ast_cycle_detection(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 141, 72))) } - fn cost_analysis_storage(n: u64) -> InterpreterResult { + fn cost_analysis_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 2, 94), write_length: linear(n, 1, 1), @@ -111,7 +111,7 @@ impl CostValues for Costs3 { }) } - fn cost_analysis_use_trait_entry(n: u64) -> InterpreterResult { + fn cost_analysis_use_trait_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 698), write_length: linear(n, 1, 1), @@ -121,7 +121,7 @@ impl CostValues for Costs3 { }) } - fn cost_analysis_fetch_contract_entry(n: u64) -> InterpreterResult { + fn cost_analysis_fetch_contract_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1516), write_length: 0, @@ -131,7 +131,7 @@ impl CostValues for Costs3 { }) } - fn cost_analysis_get_function_entry(n: u64) -> InterpreterResult { + fn cost_analysis_get_function_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 78, 1307), write_length: 0, @@ -141,275 +141,275 @@ impl CostValues for Costs3 { }) } - fn cost_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_lookup_variable_depth(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 1))) } - fn cost_lookup_variable_size(n: u64) -> InterpreterResult { + fn cost_lookup_variable_size(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 1))) } - fn cost_lookup_function(n: u64) -> InterpreterResult { + fn cost_lookup_function(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(16)) } - fn cost_bind_name(n: u64) -> InterpreterResult { + fn cost_bind_name(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(216)) } - fn cost_inner_type_check_cost(n: u64) -> InterpreterResult { + fn cost_inner_type_check_cost(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 2, 5))) } - fn cost_user_function_application(n: u64) -> InterpreterResult { + fn cost_user_function_application(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 26, 5))) } - fn cost_let(n: u64) -> InterpreterResult { + fn cost_let(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 117, 178))) } - fn cost_if(n: u64) -> InterpreterResult { + fn cost_if(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(168)) } - fn cost_asserts(n: u64) -> InterpreterResult { + fn cost_asserts(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(128)) } - fn cost_map(n: u64) -> InterpreterResult { + fn cost_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1198, 3067))) } - fn cost_filter(n: u64) -> InterpreterResult { + fn cost_filter(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(407)) } - fn cost_len(n: u64) -> InterpreterResult { + fn cost_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(429)) } - fn cost_element_at(n: u64) -> InterpreterResult { + fn cost_element_at(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(498)) } - fn cost_index_of(n: u64) -> InterpreterResult { + fn cost_index_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 211))) } - fn cost_fold(n: u64) -> InterpreterResult { + fn cost_fold(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(460)) } - fn cost_list_cons(n: u64) -> InterpreterResult { + fn cost_list_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 14, 164))) } - fn cost_type_parse_step(n: u64) -> InterpreterResult { + fn cost_type_parse_step(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(4)) } - fn cost_tuple_get(n: u64) -> InterpreterResult { + fn cost_tuple_get(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 4, 1736)?)) } - fn cost_tuple_merge(n: u64) -> InterpreterResult { + fn cost_tuple_merge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 4, 408))) } - fn cost_tuple_cons(n: u64) -> InterpreterResult { + fn cost_tuple_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 10, 1876)?)) } - fn cost_add(n: u64) -> InterpreterResult { + fn cost_add(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 11, 125))) } - fn cost_sub(n: u64) -> InterpreterResult { + fn cost_sub(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 11, 125))) } - fn cost_mul(n: u64) -> InterpreterResult { + fn cost_mul(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 13, 125))) } - fn cost_div(n: u64) -> InterpreterResult { + fn cost_div(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 13, 125))) } - fn cost_geq(n: u64) -> InterpreterResult { + fn cost_geq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 128))) } - fn cost_leq(n: u64) -> InterpreterResult { + fn cost_leq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 128))) } - fn cost_le(n: u64) -> InterpreterResult { + fn cost_le(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 128))) } - fn cost_ge(n: u64) -> InterpreterResult { + fn cost_ge(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 128))) } - fn cost_int_cast(n: u64) -> InterpreterResult { + fn cost_int_cast(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(135)) } - fn cost_mod(n: u64) -> InterpreterResult { + fn cost_mod(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(141)) } - fn cost_pow(n: u64) -> InterpreterResult { + fn cost_pow(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(143)) } - fn cost_sqrti(n: u64) -> InterpreterResult { + fn cost_sqrti(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(142)) } - fn cost_log2(n: u64) -> InterpreterResult { + fn cost_log2(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(133)) } - fn cost_xor(n: u64) -> InterpreterResult { + fn cost_xor(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 15, 129))) } - fn cost_not(n: u64) -> InterpreterResult { + fn cost_not(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(138)) } - fn cost_eq(n: u64) -> InterpreterResult { + fn cost_eq(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 7, 151))) } - fn cost_begin(n: u64) -> InterpreterResult { + fn cost_begin(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(151)) } - fn cost_hash160(n: u64) -> InterpreterResult { + fn cost_hash160(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 188))) } - fn cost_sha256(n: u64) -> InterpreterResult { + fn cost_sha256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 100))) } - fn cost_sha512(n: u64) -> InterpreterResult { + fn cost_sha512(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 176))) } - fn cost_sha512t256(n: u64) -> InterpreterResult { + fn cost_sha512t256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 56))) } - fn cost_keccak256(n: u64) -> InterpreterResult { + fn cost_keccak256(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 127))) } - fn cost_secp256k1recover(n: u64) -> InterpreterResult { + fn cost_secp256k1recover(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(8655)) } - fn cost_secp256k1verify(n: u64) -> InterpreterResult { + fn cost_secp256k1verify(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(8349)) } - fn cost_print(n: u64) -> InterpreterResult { + fn cost_print(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 15, 1458))) } - fn cost_some_cons(n: u64) -> InterpreterResult { + fn cost_some_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(199)) } - fn cost_ok_cons(n: u64) -> InterpreterResult { + fn cost_ok_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(199)) } - fn cost_err_cons(n: u64) -> InterpreterResult { + fn cost_err_cons(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(199)) } - fn cost_default_to(n: u64) -> InterpreterResult { + fn cost_default_to(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(268)) } - fn cost_unwrap_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(274)) } - fn cost_unwrap_err_or_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_err_or_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(302)) } - fn cost_is_okay(n: u64) -> InterpreterResult { + fn cost_is_okay(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(258)) } - fn cost_is_none(n: u64) -> InterpreterResult { + fn cost_is_none(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(214)) } - fn cost_is_err(n: u64) -> InterpreterResult { + fn cost_is_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(245)) } - fn cost_is_some(n: u64) -> InterpreterResult { + fn cost_is_some(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(195)) } - fn cost_unwrap(n: u64) -> InterpreterResult { + fn cost_unwrap(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(252)) } - fn cost_unwrap_err(n: u64) -> InterpreterResult { + fn cost_unwrap_err(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(248)) } - fn cost_try_ret(n: u64) -> InterpreterResult { + fn cost_try_ret(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(240)) } - fn cost_match(n: u64) -> InterpreterResult { + fn cost_match(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(264)) } - fn cost_or(n: u64) -> InterpreterResult { + fn cost_or(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 120))) } - fn cost_and(n: u64) -> InterpreterResult { + fn cost_and(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 3, 120))) } - fn cost_append(n: u64) -> InterpreterResult { + fn cost_append(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 73, 285))) } - fn cost_concat(n: u64) -> InterpreterResult { + fn cost_concat(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 37, 220))) } - fn cost_as_max_len(n: u64) -> InterpreterResult { + fn cost_as_max_len(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(475)) } - fn cost_contract_call(n: u64) -> InterpreterResult { + fn cost_contract_call(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(134)) } - fn cost_contract_of(n: u64) -> InterpreterResult { + fn cost_contract_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(13400)) } - fn cost_principal_of(n: u64) -> InterpreterResult { + fn cost_principal_of(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(984)) } - fn cost_at_block(n: u64) -> InterpreterResult { + fn cost_at_block(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1327, write_length: 0, @@ -419,7 +419,7 @@ impl CostValues for Costs3 { }) } - fn cost_load_contract(n: u64) -> InterpreterResult { + fn cost_load_contract(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 80), write_length: 0, @@ -430,7 +430,7 @@ impl CostValues for Costs3 { }) } - fn cost_create_map(n: u64) -> InterpreterResult { + fn cost_create_map(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1564), write_length: linear(n, 1, 1), @@ -440,7 +440,7 @@ impl CostValues for Costs3 { }) } - fn cost_create_var(n: u64) -> InterpreterResult { + fn cost_create_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 7, 2025), write_length: linear(n, 1, 1), @@ -450,7 +450,7 @@ impl CostValues for Costs3 { }) } - fn cost_create_nft(n: u64) -> InterpreterResult { + fn cost_create_nft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1570), write_length: linear(n, 1, 1), @@ -460,7 +460,7 @@ impl CostValues for Costs3 { }) } - fn cost_create_ft(n: u64) -> InterpreterResult { + fn cost_create_ft(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1831, write_length: 1, @@ -470,7 +470,7 @@ impl CostValues for Costs3 { }) } - fn cost_fetch_entry(n: u64) -> InterpreterResult { + fn cost_fetch_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 1025), write_length: 0, @@ -480,7 +480,7 @@ impl CostValues for Costs3 { }) } - fn cost_set_entry(n: u64) -> InterpreterResult { + fn cost_set_entry(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 4, 1899), write_length: linear(n, 1, 1), @@ -490,7 +490,7 @@ impl CostValues for Costs3 { }) } - fn cost_fetch_var(n: u64) -> InterpreterResult { + fn cost_fetch_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 1, 468), write_length: 0, @@ -500,7 +500,7 @@ impl CostValues for Costs3 { }) } - fn cost_set_var(n: u64) -> InterpreterResult { + fn cost_set_var(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 5, 655), write_length: linear(n, 1, 1), @@ -510,7 +510,7 @@ impl CostValues for Costs3 { }) } - fn cost_contract_storage(n: u64) -> InterpreterResult { + fn cost_contract_storage(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 11, 7165), write_length: linear(n, 1, 1), @@ -520,7 +520,7 @@ impl CostValues for Costs3 { }) } - fn cost_block_info(n: u64) -> InterpreterResult { + fn cost_block_info(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 6321, write_length: 0, @@ -530,7 +530,7 @@ impl CostValues for Costs3 { }) } - fn cost_stx_balance(n: u64) -> InterpreterResult { + fn cost_stx_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 4294, write_length: 0, @@ -540,7 +540,7 @@ impl CostValues for Costs3 { }) } - fn cost_stx_transfer(n: u64) -> InterpreterResult { + fn cost_stx_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 4640, write_length: 1, @@ -550,7 +550,7 @@ impl CostValues for Costs3 { }) } - fn cost_ft_mint(n: u64) -> InterpreterResult { + fn cost_ft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 1479, write_length: 1, @@ -560,7 +560,7 @@ impl CostValues for Costs3 { }) } - fn cost_ft_transfer(n: u64) -> InterpreterResult { + fn cost_ft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 549, write_length: 1, @@ -570,7 +570,7 @@ impl CostValues for Costs3 { }) } - fn cost_ft_balance(n: u64) -> InterpreterResult { + fn cost_ft_balance(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 479, write_length: 0, @@ -580,7 +580,7 @@ impl CostValues for Costs3 { }) } - fn cost_nft_mint(n: u64) -> InterpreterResult { + fn cost_nft_mint(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 575), write_length: 1, @@ -590,7 +590,7 @@ impl CostValues for Costs3 { }) } - fn cost_nft_transfer(n: u64) -> InterpreterResult { + fn cost_nft_transfer(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 572), write_length: 1, @@ -600,7 +600,7 @@ impl CostValues for Costs3 { }) } - fn cost_nft_owner(n: u64) -> InterpreterResult { + fn cost_nft_owner(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 795), write_length: 0, @@ -610,7 +610,7 @@ impl CostValues for Costs3 { }) } - fn cost_ft_get_supply(n: u64) -> InterpreterResult { + fn cost_ft_get_supply(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 420, write_length: 0, @@ -620,7 +620,7 @@ impl CostValues for Costs3 { }) } - fn cost_ft_burn(n: u64) -> InterpreterResult { + fn cost_ft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 549, write_length: 1, @@ -630,7 +630,7 @@ impl CostValues for Costs3 { }) } - fn cost_nft_burn(n: u64) -> InterpreterResult { + fn cost_nft_burn(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: linear(n, 9, 572), write_length: 1, @@ -640,7 +640,7 @@ impl CostValues for Costs3 { }) } - fn poison_microblock(n: u64) -> InterpreterResult { + fn poison_microblock(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 17485, write_length: 1, @@ -650,51 +650,51 @@ impl CostValues for Costs3 { }) } - fn cost_buff_to_int_le(n: u64) -> InterpreterResult { + fn cost_buff_to_int_le(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(141)) } - fn cost_buff_to_uint_le(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_le(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(141)) } - fn cost_buff_to_int_be(n: u64) -> InterpreterResult { + fn cost_buff_to_int_be(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(141)) } - fn cost_buff_to_uint_be(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_be(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(141)) } - fn cost_is_standard(n: u64) -> InterpreterResult { + fn cost_is_standard(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(127)) } - fn cost_principal_destruct(n: u64) -> InterpreterResult { + fn cost_principal_destruct(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(314)) } - fn cost_principal_construct(n: u64) -> InterpreterResult { + fn cost_principal_construct(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(398)) } - fn cost_string_to_int(n: u64) -> InterpreterResult { + fn cost_string_to_int(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(168)) } - fn cost_string_to_uint(n: u64) -> InterpreterResult { + fn cost_string_to_uint(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(168)) } - fn cost_int_to_ascii(n: u64) -> InterpreterResult { + fn cost_int_to_ascii(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(147)) } - fn cost_int_to_utf8(n: u64) -> InterpreterResult { + fn cost_int_to_utf8(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(181)) } - fn cost_burn_block_info(n: u64) -> InterpreterResult { + fn cost_burn_block_info(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 96479, write_length: 0, @@ -704,7 +704,7 @@ impl CostValues for Costs3 { }) } - fn cost_stx_account(n: u64) -> InterpreterResult { + fn cost_stx_account(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 4654, write_length: 0, @@ -714,19 +714,19 @@ impl CostValues for Costs3 { }) } - fn cost_slice(n: u64) -> InterpreterResult { + fn cost_slice(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(448)) } - fn cost_to_consensus_buff(n: u64) -> InterpreterResult { + fn cost_to_consensus_buff(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 233))) } - fn cost_from_consensus_buff(n: u64) -> InterpreterResult { + fn cost_from_consensus_buff(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(nlogn(n, 3, 185)?)) } - fn cost_stx_transfer_memo(n: u64) -> InterpreterResult { + fn cost_stx_transfer_memo(n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 4709, write_length: 1, @@ -736,39 +736,39 @@ impl CostValues for Costs3 { }) } - fn cost_replace_at(n: u64) -> InterpreterResult { + fn cost_replace_at(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 1, 561))) } - fn cost_as_contract(n: u64) -> InterpreterResult { + fn cost_as_contract(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(138)) } - fn cost_bitwise_and(n: u64) -> InterpreterResult { + fn cost_bitwise_and(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 15, 129))) } - fn cost_bitwise_or(n: u64) -> InterpreterResult { + fn cost_bitwise_or(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(linear(n, 15, 129))) } - fn cost_bitwise_not(n: u64) -> InterpreterResult { + fn cost_bitwise_not(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(147)) } - fn cost_bitwise_left_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_left_shift(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(167)) } - fn cost_bitwise_right_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_right_shift(n: u64) -> VmExecutionResult { Ok(ExecutionCost::runtime(167)) } - fn cost_contract_hash(n: u64) -> InterpreterResult { + fn cost_contract_hash(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } - fn cost_to_ascii(n: u64) -> InterpreterResult { + fn cost_to_ascii(n: u64) -> VmExecutionResult { Err(RuntimeErrorType::NotImplemented.into()) } } diff --git a/clarity/src/vm/costs/costs_4.rs b/clarity/src/vm/costs/costs_4.rs index d1c92732d9..f4561e4ded 100644 --- a/clarity/src/vm/costs/costs_4.rs +++ b/clarity/src/vm/costs/costs_4.rs @@ -22,432 +22,432 @@ use super::cost_functions::CostValues; use super::costs_3::Costs3; use super::ExecutionCost; use crate::vm::costs::cost_functions::linear; -use crate::vm::errors::InterpreterResult; +use crate::vm::errors::VmExecutionResult; pub struct Costs4; impl CostValues for Costs4 { // Forward all costs to Costs3 to avoid duplication. - fn cost_analysis_type_annotate(n: u64) -> InterpreterResult { + fn cost_analysis_type_annotate(n: u64) -> VmExecutionResult { Costs3::cost_analysis_type_annotate(n) } - fn cost_analysis_type_check(n: u64) -> InterpreterResult { + fn cost_analysis_type_check(n: u64) -> VmExecutionResult { Costs3::cost_analysis_type_check(n) } - fn cost_analysis_type_lookup(n: u64) -> InterpreterResult { + fn cost_analysis_type_lookup(n: u64) -> VmExecutionResult { Costs3::cost_analysis_type_lookup(n) } - fn cost_analysis_visit(n: u64) -> InterpreterResult { + fn cost_analysis_visit(n: u64) -> VmExecutionResult { Costs3::cost_analysis_visit(n) } - fn cost_analysis_iterable_func(n: u64) -> InterpreterResult { + fn cost_analysis_iterable_func(n: u64) -> VmExecutionResult { Costs3::cost_analysis_iterable_func(n) } - fn cost_analysis_option_cons(n: u64) -> InterpreterResult { + fn cost_analysis_option_cons(n: u64) -> VmExecutionResult { Costs3::cost_analysis_option_cons(n) } - fn cost_analysis_option_check(n: u64) -> InterpreterResult { + fn cost_analysis_option_check(n: u64) -> VmExecutionResult { Costs3::cost_analysis_option_check(n) } - fn cost_analysis_bind_name(n: u64) -> InterpreterResult { + fn cost_analysis_bind_name(n: u64) -> VmExecutionResult { Costs3::cost_analysis_bind_name(n) } - fn cost_analysis_list_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_list_items_check(n: u64) -> VmExecutionResult { Costs3::cost_analysis_list_items_check(n) } - fn cost_analysis_check_tuple_get(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_get(n: u64) -> VmExecutionResult { Costs3::cost_analysis_check_tuple_get(n) } - fn cost_analysis_check_tuple_merge(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_merge(n: u64) -> VmExecutionResult { Costs3::cost_analysis_check_tuple_merge(n) } - fn cost_analysis_check_tuple_cons(n: u64) -> InterpreterResult { + fn cost_analysis_check_tuple_cons(n: u64) -> VmExecutionResult { Costs3::cost_analysis_check_tuple_cons(n) } - fn cost_analysis_tuple_items_check(n: u64) -> InterpreterResult { + fn cost_analysis_tuple_items_check(n: u64) -> VmExecutionResult { Costs3::cost_analysis_tuple_items_check(n) } - fn cost_analysis_check_let(n: u64) -> InterpreterResult { + fn cost_analysis_check_let(n: u64) -> VmExecutionResult { Costs3::cost_analysis_check_let(n) } - fn cost_analysis_lookup_function(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function(n: u64) -> VmExecutionResult { Costs3::cost_analysis_lookup_function(n) } - fn cost_analysis_lookup_function_types(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_function_types(n: u64) -> VmExecutionResult { Costs3::cost_analysis_lookup_function_types(n) } - fn cost_analysis_lookup_variable_const(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_const(n: u64) -> VmExecutionResult { Costs3::cost_analysis_lookup_variable_const(n) } - fn cost_analysis_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_analysis_lookup_variable_depth(n: u64) -> VmExecutionResult { Costs3::cost_analysis_lookup_variable_depth(n) } - fn cost_ast_parse(n: u64) -> InterpreterResult { + fn cost_ast_parse(n: u64) -> VmExecutionResult { Costs3::cost_ast_parse(n) } - fn cost_ast_cycle_detection(n: u64) -> InterpreterResult { + fn cost_ast_cycle_detection(n: u64) -> VmExecutionResult { Costs3::cost_ast_cycle_detection(n) } - fn cost_analysis_storage(n: u64) -> InterpreterResult { + fn cost_analysis_storage(n: u64) -> VmExecutionResult { Costs3::cost_analysis_storage(n) } - fn cost_analysis_use_trait_entry(n: u64) -> InterpreterResult { + fn cost_analysis_use_trait_entry(n: u64) -> VmExecutionResult { Costs3::cost_analysis_use_trait_entry(n) } - fn cost_analysis_get_function_entry(n: u64) -> InterpreterResult { + fn cost_analysis_get_function_entry(n: u64) -> VmExecutionResult { Costs3::cost_analysis_get_function_entry(n) } - fn cost_analysis_fetch_contract_entry(n: u64) -> InterpreterResult { + fn cost_analysis_fetch_contract_entry(n: u64) -> VmExecutionResult { Costs3::cost_analysis_fetch_contract_entry(n) } - fn cost_lookup_variable_depth(n: u64) -> InterpreterResult { + fn cost_lookup_variable_depth(n: u64) -> VmExecutionResult { Costs3::cost_lookup_variable_depth(n) } - fn cost_lookup_variable_size(n: u64) -> InterpreterResult { + fn cost_lookup_variable_size(n: u64) -> VmExecutionResult { Costs3::cost_lookup_variable_size(n) } - fn cost_lookup_function(n: u64) -> InterpreterResult { + fn cost_lookup_function(n: u64) -> VmExecutionResult { Costs3::cost_lookup_function(n) } - fn cost_bind_name(n: u64) -> InterpreterResult { + fn cost_bind_name(n: u64) -> VmExecutionResult { Costs3::cost_bind_name(n) } - fn cost_inner_type_check_cost(n: u64) -> InterpreterResult { + fn cost_inner_type_check_cost(n: u64) -> VmExecutionResult { Costs3::cost_inner_type_check_cost(n) } - fn cost_user_function_application(n: u64) -> InterpreterResult { + fn cost_user_function_application(n: u64) -> VmExecutionResult { Costs3::cost_user_function_application(n) } - fn cost_let(n: u64) -> InterpreterResult { + fn cost_let(n: u64) -> VmExecutionResult { Costs3::cost_let(n) } - fn cost_if(n: u64) -> InterpreterResult { + fn cost_if(n: u64) -> VmExecutionResult { Costs3::cost_if(n) } - fn cost_asserts(n: u64) -> InterpreterResult { + fn cost_asserts(n: u64) -> VmExecutionResult { Costs3::cost_asserts(n) } - fn cost_map(n: u64) -> InterpreterResult { + fn cost_map(n: u64) -> VmExecutionResult { Costs3::cost_map(n) } - fn cost_filter(n: u64) -> InterpreterResult { + fn cost_filter(n: u64) -> VmExecutionResult { Costs3::cost_filter(n) } - fn cost_len(n: u64) -> InterpreterResult { + fn cost_len(n: u64) -> VmExecutionResult { Costs3::cost_len(n) } - fn cost_element_at(n: u64) -> InterpreterResult { + fn cost_element_at(n: u64) -> VmExecutionResult { Costs3::cost_element_at(n) } - fn cost_index_of(n: u64) -> InterpreterResult { + fn cost_index_of(n: u64) -> VmExecutionResult { Costs3::cost_index_of(n) } - fn cost_fold(n: u64) -> InterpreterResult { + fn cost_fold(n: u64) -> VmExecutionResult { Costs3::cost_fold(n) } - fn cost_list_cons(n: u64) -> InterpreterResult { + fn cost_list_cons(n: u64) -> VmExecutionResult { Costs3::cost_list_cons(n) } - fn cost_type_parse_step(n: u64) -> InterpreterResult { + fn cost_type_parse_step(n: u64) -> VmExecutionResult { Costs3::cost_type_parse_step(n) } - fn cost_tuple_get(n: u64) -> InterpreterResult { + fn cost_tuple_get(n: u64) -> VmExecutionResult { Costs3::cost_tuple_get(n) } - fn cost_tuple_merge(n: u64) -> InterpreterResult { + fn cost_tuple_merge(n: u64) -> VmExecutionResult { Costs3::cost_tuple_merge(n) } - fn cost_tuple_cons(n: u64) -> InterpreterResult { + fn cost_tuple_cons(n: u64) -> VmExecutionResult { Costs3::cost_tuple_cons(n) } - fn cost_add(n: u64) -> InterpreterResult { + fn cost_add(n: u64) -> VmExecutionResult { Costs3::cost_add(n) } - fn cost_sub(n: u64) -> InterpreterResult { + fn cost_sub(n: u64) -> VmExecutionResult { Costs3::cost_sub(n) } - fn cost_mul(n: u64) -> InterpreterResult { + fn cost_mul(n: u64) -> VmExecutionResult { Costs3::cost_mul(n) } - fn cost_div(n: u64) -> InterpreterResult { + fn cost_div(n: u64) -> VmExecutionResult { Costs3::cost_div(n) } - fn cost_geq(n: u64) -> InterpreterResult { + fn cost_geq(n: u64) -> VmExecutionResult { Costs3::cost_geq(n) } - fn cost_leq(n: u64) -> InterpreterResult { + fn cost_leq(n: u64) -> VmExecutionResult { Costs3::cost_leq(n) } - fn cost_le(n: u64) -> InterpreterResult { + fn cost_le(n: u64) -> VmExecutionResult { Costs3::cost_le(n) } - fn cost_ge(n: u64) -> InterpreterResult { + fn cost_ge(n: u64) -> VmExecutionResult { Costs3::cost_ge(n) } - fn cost_int_cast(n: u64) -> InterpreterResult { + fn cost_int_cast(n: u64) -> VmExecutionResult { Costs3::cost_int_cast(n) } - fn cost_mod(n: u64) -> InterpreterResult { + fn cost_mod(n: u64) -> VmExecutionResult { Costs3::cost_mod(n) } - fn cost_pow(n: u64) -> InterpreterResult { + fn cost_pow(n: u64) -> VmExecutionResult { Costs3::cost_pow(n) } - fn cost_sqrti(n: u64) -> InterpreterResult { + fn cost_sqrti(n: u64) -> VmExecutionResult { Costs3::cost_sqrti(n) } - fn cost_log2(n: u64) -> InterpreterResult { + fn cost_log2(n: u64) -> VmExecutionResult { Costs3::cost_log2(n) } - fn cost_xor(n: u64) -> InterpreterResult { + fn cost_xor(n: u64) -> VmExecutionResult { Costs3::cost_xor(n) } - fn cost_not(n: u64) -> InterpreterResult { + fn cost_not(n: u64) -> VmExecutionResult { Costs3::cost_not(n) } - fn cost_eq(n: u64) -> InterpreterResult { + fn cost_eq(n: u64) -> VmExecutionResult { Costs3::cost_eq(n) } - fn cost_begin(n: u64) -> InterpreterResult { + fn cost_begin(n: u64) -> VmExecutionResult { Costs3::cost_begin(n) } - fn cost_hash160(n: u64) -> InterpreterResult { + fn cost_hash160(n: u64) -> VmExecutionResult { Costs3::cost_hash160(n) } - fn cost_sha256(n: u64) -> InterpreterResult { + fn cost_sha256(n: u64) -> VmExecutionResult { Costs3::cost_sha256(n) } - fn cost_sha512(n: u64) -> InterpreterResult { + fn cost_sha512(n: u64) -> VmExecutionResult { Costs3::cost_sha512(n) } - fn cost_sha512t256(n: u64) -> InterpreterResult { + fn cost_sha512t256(n: u64) -> VmExecutionResult { Costs3::cost_sha512t256(n) } - fn cost_keccak256(n: u64) -> InterpreterResult { + fn cost_keccak256(n: u64) -> VmExecutionResult { Costs3::cost_keccak256(n) } - fn cost_secp256k1recover(n: u64) -> InterpreterResult { + fn cost_secp256k1recover(n: u64) -> VmExecutionResult { Costs3::cost_secp256k1recover(n) } - fn cost_secp256k1verify(n: u64) -> InterpreterResult { + fn cost_secp256k1verify(n: u64) -> VmExecutionResult { Costs3::cost_secp256k1verify(n) } - fn cost_print(n: u64) -> InterpreterResult { + fn cost_print(n: u64) -> VmExecutionResult { Costs3::cost_print(n) } - fn cost_some_cons(n: u64) -> InterpreterResult { + fn cost_some_cons(n: u64) -> VmExecutionResult { Costs3::cost_some_cons(n) } - fn cost_ok_cons(n: u64) -> InterpreterResult { + fn cost_ok_cons(n: u64) -> VmExecutionResult { Costs3::cost_ok_cons(n) } - fn cost_err_cons(n: u64) -> InterpreterResult { + fn cost_err_cons(n: u64) -> VmExecutionResult { Costs3::cost_err_cons(n) } - fn cost_default_to(n: u64) -> InterpreterResult { + fn cost_default_to(n: u64) -> VmExecutionResult { Costs3::cost_default_to(n) } - fn cost_unwrap_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_ret(n: u64) -> VmExecutionResult { Costs3::cost_unwrap_ret(n) } - fn cost_unwrap_err_or_ret(n: u64) -> InterpreterResult { + fn cost_unwrap_err_or_ret(n: u64) -> VmExecutionResult { Costs3::cost_unwrap_err_or_ret(n) } - fn cost_is_okay(n: u64) -> InterpreterResult { + fn cost_is_okay(n: u64) -> VmExecutionResult { Costs3::cost_is_okay(n) } - fn cost_is_none(n: u64) -> InterpreterResult { + fn cost_is_none(n: u64) -> VmExecutionResult { Costs3::cost_is_none(n) } - fn cost_is_err(n: u64) -> InterpreterResult { + fn cost_is_err(n: u64) -> VmExecutionResult { Costs3::cost_is_err(n) } - fn cost_is_some(n: u64) -> InterpreterResult { + fn cost_is_some(n: u64) -> VmExecutionResult { Costs3::cost_is_some(n) } - fn cost_unwrap(n: u64) -> InterpreterResult { + fn cost_unwrap(n: u64) -> VmExecutionResult { Costs3::cost_unwrap(n) } - fn cost_unwrap_err(n: u64) -> InterpreterResult { + fn cost_unwrap_err(n: u64) -> VmExecutionResult { Costs3::cost_unwrap_err(n) } - fn cost_try_ret(n: u64) -> InterpreterResult { + fn cost_try_ret(n: u64) -> VmExecutionResult { Costs3::cost_try_ret(n) } - fn cost_match(n: u64) -> InterpreterResult { + fn cost_match(n: u64) -> VmExecutionResult { Costs3::cost_match(n) } - fn cost_or(n: u64) -> InterpreterResult { + fn cost_or(n: u64) -> VmExecutionResult { Costs3::cost_or(n) } - fn cost_and(n: u64) -> InterpreterResult { + fn cost_and(n: u64) -> VmExecutionResult { Costs3::cost_and(n) } - fn cost_append(n: u64) -> InterpreterResult { + fn cost_append(n: u64) -> VmExecutionResult { Costs3::cost_append(n) } - fn cost_concat(n: u64) -> InterpreterResult { + fn cost_concat(n: u64) -> VmExecutionResult { Costs3::cost_concat(n) } - fn cost_as_max_len(n: u64) -> InterpreterResult { + fn cost_as_max_len(n: u64) -> VmExecutionResult { Costs3::cost_as_max_len(n) } - fn cost_contract_call(n: u64) -> InterpreterResult { + fn cost_contract_call(n: u64) -> VmExecutionResult { Costs3::cost_contract_call(n) } - fn cost_contract_of(n: u64) -> InterpreterResult { + fn cost_contract_of(n: u64) -> VmExecutionResult { Costs3::cost_contract_of(n) } - fn cost_principal_of(n: u64) -> InterpreterResult { + fn cost_principal_of(n: u64) -> VmExecutionResult { Costs3::cost_principal_of(n) } - fn cost_at_block(n: u64) -> InterpreterResult { + fn cost_at_block(n: u64) -> VmExecutionResult { Costs3::cost_at_block(n) } - fn cost_load_contract(n: u64) -> InterpreterResult { + fn cost_load_contract(n: u64) -> VmExecutionResult { Costs3::cost_load_contract(n) } - fn cost_create_map(n: u64) -> InterpreterResult { + fn cost_create_map(n: u64) -> VmExecutionResult { Costs3::cost_create_map(n) } - fn cost_create_var(n: u64) -> InterpreterResult { + fn cost_create_var(n: u64) -> VmExecutionResult { Costs3::cost_create_var(n) } - fn cost_create_nft(n: u64) -> InterpreterResult { + fn cost_create_nft(n: u64) -> VmExecutionResult { Costs3::cost_create_nft(n) } - fn cost_create_ft(n: u64) -> InterpreterResult { + fn cost_create_ft(n: u64) -> VmExecutionResult { Costs3::cost_create_ft(n) } - fn cost_fetch_entry(n: u64) -> InterpreterResult { + fn cost_fetch_entry(n: u64) -> VmExecutionResult { Costs3::cost_fetch_entry(n) } - fn cost_set_entry(n: u64) -> InterpreterResult { + fn cost_set_entry(n: u64) -> VmExecutionResult { Costs3::cost_set_entry(n) } - fn cost_fetch_var(n: u64) -> InterpreterResult { + fn cost_fetch_var(n: u64) -> VmExecutionResult { Costs3::cost_fetch_var(n) } - fn cost_set_var(n: u64) -> InterpreterResult { + fn cost_set_var(n: u64) -> VmExecutionResult { Costs3::cost_set_var(n) } - fn cost_contract_storage(n: u64) -> InterpreterResult { + fn cost_contract_storage(n: u64) -> VmExecutionResult { Costs3::cost_contract_storage(n) } - fn cost_block_info(n: u64) -> InterpreterResult { + fn cost_block_info(n: u64) -> VmExecutionResult { Costs3::cost_block_info(n) } - fn cost_stx_balance(n: u64) -> InterpreterResult { + fn cost_stx_balance(n: u64) -> VmExecutionResult { Costs3::cost_stx_balance(n) } - fn cost_stx_transfer(n: u64) -> InterpreterResult { + fn cost_stx_transfer(n: u64) -> VmExecutionResult { Costs3::cost_stx_transfer(n) } - fn cost_ft_mint(n: u64) -> InterpreterResult { + fn cost_ft_mint(n: u64) -> VmExecutionResult { Costs3::cost_ft_mint(n) } - fn cost_ft_transfer(n: u64) -> InterpreterResult { + fn cost_ft_transfer(n: u64) -> VmExecutionResult { Costs3::cost_ft_transfer(n) } - fn cost_ft_balance(n: u64) -> InterpreterResult { + fn cost_ft_balance(n: u64) -> VmExecutionResult { Costs3::cost_ft_balance(n) } - fn cost_ft_get_supply(n: u64) -> InterpreterResult { + fn cost_ft_get_supply(n: u64) -> VmExecutionResult { Costs3::cost_ft_get_supply(n) } - fn cost_ft_burn(n: u64) -> InterpreterResult { + fn cost_ft_burn(n: u64) -> VmExecutionResult { Costs3::cost_ft_burn(n) } - fn cost_nft_mint(n: u64) -> InterpreterResult { + fn cost_nft_mint(n: u64) -> VmExecutionResult { Costs3::cost_nft_mint(n) } - fn cost_nft_transfer(n: u64) -> InterpreterResult { + fn cost_nft_transfer(n: u64) -> VmExecutionResult { Costs3::cost_nft_transfer(n) } - fn cost_nft_owner(n: u64) -> InterpreterResult { + fn cost_nft_owner(n: u64) -> VmExecutionResult { Costs3::cost_nft_owner(n) } - fn cost_nft_burn(n: u64) -> InterpreterResult { + fn cost_nft_burn(n: u64) -> VmExecutionResult { Costs3::cost_nft_burn(n) } - fn poison_microblock(n: u64) -> InterpreterResult { + fn poison_microblock(n: u64) -> VmExecutionResult { Costs3::poison_microblock(n) } - fn cost_buff_to_int_le(n: u64) -> InterpreterResult { + fn cost_buff_to_int_le(n: u64) -> VmExecutionResult { Costs3::cost_buff_to_int_le(n) } - fn cost_buff_to_uint_le(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_le(n: u64) -> VmExecutionResult { Costs3::cost_buff_to_uint_le(n) } - fn cost_buff_to_int_be(n: u64) -> InterpreterResult { + fn cost_buff_to_int_be(n: u64) -> VmExecutionResult { Costs3::cost_buff_to_int_be(n) } - fn cost_buff_to_uint_be(n: u64) -> InterpreterResult { + fn cost_buff_to_uint_be(n: u64) -> VmExecutionResult { Costs3::cost_buff_to_uint_be(n) } - fn cost_is_standard(n: u64) -> InterpreterResult { + fn cost_is_standard(n: u64) -> VmExecutionResult { Costs3::cost_is_standard(n) } - fn cost_principal_destruct(n: u64) -> InterpreterResult { + fn cost_principal_destruct(n: u64) -> VmExecutionResult { Costs3::cost_principal_destruct(n) } - fn cost_principal_construct(n: u64) -> InterpreterResult { + fn cost_principal_construct(n: u64) -> VmExecutionResult { Costs3::cost_principal_construct(n) } - fn cost_string_to_int(n: u64) -> InterpreterResult { + fn cost_string_to_int(n: u64) -> VmExecutionResult { Costs3::cost_string_to_int(n) } - fn cost_string_to_uint(n: u64) -> InterpreterResult { + fn cost_string_to_uint(n: u64) -> VmExecutionResult { Costs3::cost_string_to_uint(n) } - fn cost_int_to_ascii(n: u64) -> InterpreterResult { + fn cost_int_to_ascii(n: u64) -> VmExecutionResult { Costs3::cost_int_to_ascii(n) } - fn cost_int_to_utf8(n: u64) -> InterpreterResult { + fn cost_int_to_utf8(n: u64) -> VmExecutionResult { Costs3::cost_int_to_utf8(n) } - fn cost_burn_block_info(n: u64) -> InterpreterResult { + fn cost_burn_block_info(n: u64) -> VmExecutionResult { Costs3::cost_burn_block_info(n) } - fn cost_stx_account(n: u64) -> InterpreterResult { + fn cost_stx_account(n: u64) -> VmExecutionResult { Costs3::cost_stx_account(n) } - fn cost_slice(n: u64) -> InterpreterResult { + fn cost_slice(n: u64) -> VmExecutionResult { Costs3::cost_slice(n) } - fn cost_to_consensus_buff(n: u64) -> InterpreterResult { + fn cost_to_consensus_buff(n: u64) -> VmExecutionResult { Costs3::cost_to_consensus_buff(n) } - fn cost_from_consensus_buff(n: u64) -> InterpreterResult { + fn cost_from_consensus_buff(n: u64) -> VmExecutionResult { Costs3::cost_from_consensus_buff(n) } - fn cost_stx_transfer_memo(n: u64) -> InterpreterResult { + fn cost_stx_transfer_memo(n: u64) -> VmExecutionResult { Costs3::cost_stx_transfer_memo(n) } - fn cost_replace_at(n: u64) -> InterpreterResult { + fn cost_replace_at(n: u64) -> VmExecutionResult { Costs3::cost_replace_at(n) } - fn cost_as_contract(n: u64) -> InterpreterResult { + fn cost_as_contract(n: u64) -> VmExecutionResult { Costs3::cost_as_contract(n) } - fn cost_bitwise_and(n: u64) -> InterpreterResult { + fn cost_bitwise_and(n: u64) -> VmExecutionResult { Costs3::cost_bitwise_and(n) } - fn cost_bitwise_or(n: u64) -> InterpreterResult { + fn cost_bitwise_or(n: u64) -> VmExecutionResult { Costs3::cost_bitwise_or(n) } - fn cost_bitwise_not(n: u64) -> InterpreterResult { + fn cost_bitwise_not(n: u64) -> VmExecutionResult { Costs3::cost_bitwise_not(n) } - fn cost_bitwise_left_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_left_shift(n: u64) -> VmExecutionResult { Costs3::cost_bitwise_left_shift(n) } - fn cost_bitwise_right_shift(n: u64) -> InterpreterResult { + fn cost_bitwise_right_shift(n: u64) -> VmExecutionResult { Costs3::cost_bitwise_right_shift(n) } // New in costs-4 - fn cost_contract_hash(_n: u64) -> InterpreterResult { + fn cost_contract_hash(_n: u64) -> VmExecutionResult { Ok(ExecutionCost { runtime: 100, // TODO: needs criterion benchmark write_length: 0, @@ -457,7 +457,7 @@ impl CostValues for Costs4 { }) } - fn cost_to_ascii(n: u64) -> InterpreterResult { + fn cost_to_ascii(n: u64) -> VmExecutionResult { // TODO: needs criterion benchmark Ok(ExecutionCost::runtime(linear(n, 1, 100))) } diff --git a/clarity/src/vm/costs/mod.rs b/clarity/src/vm/costs/mod.rs index 669f6f483d..7288ce7e25 100644 --- a/clarity/src/vm/costs/mod.rs +++ b/clarity/src/vm/costs/mod.rs @@ -34,7 +34,7 @@ use crate::vm::contexts::{ContractContext, GlobalContext}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::database::clarity_store::NullBackingStore; use crate::vm::database::ClarityDatabase; -use crate::vm::errors::InterpreterResult; +use crate::vm::errors::VmExecutionResult; use crate::vm::types::signatures::FunctionType::Fixed; use crate::vm::types::signatures::TupleTypeSignature; use crate::vm::types::Value::UInt; @@ -1004,7 +1004,7 @@ impl LimitedCostTracker { pub fn parse_cost( cost_function_name: &str, - eval_result: InterpreterResult>, + eval_result: VmExecutionResult>, ) -> Result { match eval_result { Ok(Some(Value::Tuple(data))) => { diff --git a/clarity/src/vm/database/clarity_db.rs b/clarity/src/vm/database/clarity_db.rs index a895b00ddb..25411a7823 100644 --- a/clarity/src/vm/database/clarity_db.rs +++ b/clarity/src/vm/database/clarity_db.rs @@ -38,7 +38,7 @@ use crate::vm::database::structures::{ }; use crate::vm::database::{ClarityBackingStore, RollbackWrapper}; use crate::vm::errors::{ - CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType, + CheckErrors, Error, InterpreterError, RuntimeErrorType, VmExecutionResult, }; use crate::vm::representations::ClarityName; use crate::vm::types::serialization::NONE_SERIALIZATION_LEN; @@ -76,7 +76,7 @@ pub enum StoreType { impl TryFrom<&str> for StoreType { type Error = String; - fn try_from(value: &str) -> core::result::Result { + fn try_from(value: &str) -> Result { use self::StoreType::*; let hex_value = value.parse::().map_err(|e| e.to_string())?; @@ -123,7 +123,7 @@ impl ContractDataVarName { impl TryFrom<&str> for ContractDataVarName { type Error = String; - fn try_from(value: &str) -> core::result::Result { + fn try_from(value: &str) -> Result { use self::ContractDataVarName::*; match value { "contract" => Ok(Contract), @@ -485,12 +485,12 @@ impl<'a> ClarityDatabase<'a> { } /// Commit current key-value wrapper layer - pub fn commit(&mut self) -> Result<()> { + pub fn commit(&mut self) -> VmExecutionResult<()> { self.store.commit().map_err(|e| e.into()) } /// Drop current key-value wrapper layer - pub fn roll_back(&mut self) -> Result<()> { + pub fn roll_back(&mut self) -> VmExecutionResult<()> { self.store.rollback().map_err(|e| e.into()) } @@ -498,11 +498,15 @@ impl<'a> ClarityDatabase<'a> { &mut self, bhh: StacksBlockId, query_pending_data: bool, - ) -> Result { + ) -> VmExecutionResult { self.store.set_block_hash(bhh, query_pending_data) } - pub fn put_data(&mut self, key: &str, value: &T) -> Result<()> { + pub fn put_data( + &mut self, + key: &str, + value: &T, + ) -> VmExecutionResult<()> { self.store.put_data(key, &value.serialize()) } @@ -511,27 +515,32 @@ impl<'a> ClarityDatabase<'a> { &mut self, key: &str, value: &T, - ) -> Result { + ) -> VmExecutionResult { let serialized = value.serialize(); self.store.put_data(key, &serialized)?; Ok(byte_len_of_serialization(&serialized)) } - pub fn get_data(&mut self, key: &str) -> Result> + pub fn get_data(&mut self, key: &str) -> VmExecutionResult> where T: ClarityDeserializable, { self.store.get_data::(key) } - pub fn get_data_by_hash(&mut self, hash: &TrieHash) -> Result> + pub fn get_data_by_hash(&mut self, hash: &TrieHash) -> VmExecutionResult> where T: ClarityDeserializable, { self.store.get_data_by_hash::(hash) } - pub fn put_value(&mut self, key: &str, value: Value, epoch: &StacksEpochId) -> Result<()> { + pub fn put_value( + &mut self, + key: &str, + value: Value, + epoch: &StacksEpochId, + ) -> VmExecutionResult<()> { self.put_value_with_size(key, value, epoch)?; Ok(()) } @@ -541,7 +550,7 @@ impl<'a> ClarityDatabase<'a> { key: &str, value: Value, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let sanitize = epoch.value_sanitizing(); let mut pre_sanitized_size = None; @@ -575,13 +584,13 @@ impl<'a> ClarityDatabase<'a> { key: &str, expected: &TypeSignature, epoch: &StacksEpochId, - ) -> Result> { + ) -> VmExecutionResult> { self.store .get_value(key, expected, epoch) .map_err(|e| InterpreterError::DBError(e.to_string()).into()) } - pub fn get_data_with_proof(&mut self, key: &str) -> Result)>> + pub fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> where T: ClarityDeserializable, { @@ -591,7 +600,7 @@ impl<'a> ClarityDatabase<'a> { pub fn get_data_with_proof_by_hash( &mut self, hash: &TrieHash, - ) -> Result)>> + ) -> VmExecutionResult)>> where T: ClarityDeserializable, { @@ -630,7 +639,7 @@ impl<'a> ClarityDatabase<'a> { &mut self, contract_identifier: &QualifiedContractIdentifier, contract_content: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let hash = Sha512Trunc256Sum::from_data(contract_content.as_bytes()); self.store .prepare_for_contract_metadata(contract_identifier, hash)?; @@ -668,7 +677,7 @@ impl<'a> ClarityDatabase<'a> { pub fn get_contract_hash( &mut self, contract_identifier: &QualifiedContractIdentifier, - ) -> Result> { + ) -> VmExecutionResult> { self.store.get_contract_hash(contract_identifier) } @@ -677,7 +686,7 @@ impl<'a> ClarityDatabase<'a> { contract_identifier: &QualifiedContractIdentifier, key: &str, data: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { self.store .insert_metadata(contract_identifier, key, data) .map_err(|e| e.into()) @@ -691,7 +700,7 @@ impl<'a> ClarityDatabase<'a> { contract_identifier: &QualifiedContractIdentifier, key: &str, data: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { if self.store.has_metadata_entry(contract_identifier, key) { Err(Error::Runtime(RuntimeErrorType::MetadataAlreadySet, None)) } else { @@ -704,7 +713,7 @@ impl<'a> ClarityDatabase<'a> { contract_identifier: &QualifiedContractIdentifier, key: &str, data: &T, - ) -> Result<()> { + ) -> VmExecutionResult<()> { if self.store.has_metadata_entry(contract_identifier, key) { Err(InterpreterError::Expect(format!( "Metadata entry '{key}' already exists for contract: {contract_identifier}" @@ -721,7 +730,7 @@ impl<'a> ClarityDatabase<'a> { &mut self, contract_identifier: &QualifiedContractIdentifier, key: &str, - ) -> Result> + ) -> VmExecutionResult> where T: ClarityDeserializable, { @@ -737,7 +746,7 @@ impl<'a> ClarityDatabase<'a> { at_height: u32, contract_identifier: &QualifiedContractIdentifier, key: &str, - ) -> Result> + ) -> VmExecutionResult> where T: ClarityDeserializable, { @@ -757,7 +766,7 @@ impl<'a> ClarityDatabase<'a> { pub fn load_contract_analysis( &mut self, contract_identifier: &QualifiedContractIdentifier, - ) -> Result> { + ) -> VmExecutionResult> { self.store .get_metadata(contract_identifier, AnalysisDatabase::storage_key()) // treat NoSuchContract error thrown by get_metadata as an Option::None -- @@ -771,7 +780,7 @@ impl<'a> ClarityDatabase<'a> { pub fn get_contract_size( &mut self, contract_identifier: &QualifiedContractIdentifier, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_metadata_key( StoreType::Contract, ContractDataVarName::ContractSize.as_str(), @@ -804,7 +813,7 @@ impl<'a> ClarityDatabase<'a> { &mut self, contract_identifier: &QualifiedContractIdentifier, data_size: u64, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_metadata_key( StoreType::Contract, ContractDataVarName::ContractSize.as_str(), @@ -830,7 +839,7 @@ impl<'a> ClarityDatabase<'a> { &mut self, contract_identifier: &QualifiedContractIdentifier, contract: Contract, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_metadata_key( StoreType::Contract, ContractDataVarName::Contract.as_str(), @@ -850,7 +859,7 @@ impl<'a> ClarityDatabase<'a> { pub fn get_contract( &mut self, contract_identifier: &QualifiedContractIdentifier, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_metadata_key( StoreType::Contract, ContractDataVarName::Contract.as_str(), @@ -871,7 +880,7 @@ impl<'a> ClarityDatabase<'a> { /// Since Clarity did not exist in stacks 1.0, the lowest valid epoch ID is stacks 2.0. /// The instantiation of subsequent epochs may bump up the epoch version in the clarity DB if /// Clarity is updated in that epoch. - pub fn get_clarity_epoch_version(&mut self) -> Result { + pub fn get_clarity_epoch_version(&mut self) -> VmExecutionResult { let out = match self.get_data(Self::clarity_state_epoch_key())? { Some(x) => u32::try_into(x).map_err(|_| { InterpreterError::Expect("Bad Clarity epoch version in stored Clarity state".into()) @@ -882,13 +891,13 @@ impl<'a> ClarityDatabase<'a> { } /// Should be called _after_ all of the epoch's initialization has been invoked - pub fn set_clarity_epoch_version(&mut self, epoch: StacksEpochId) -> Result<()> { + pub fn set_clarity_epoch_version(&mut self, epoch: StacksEpochId) -> VmExecutionResult<()> { self.put_data(Self::clarity_state_epoch_key(), &(epoch as u32)) } /// Setup block metadata at the beginning of a block /// This stores block-specific data that can be accessed during Clarity execution - pub fn setup_block_metadata(&mut self, block_time: Option) -> Result<()> { + pub fn setup_block_metadata(&mut self, block_time: Option) -> VmExecutionResult<()> { let epoch = self.get_clarity_epoch_version()?; if epoch.uses_marfed_block_time() { let block_time = block_time.ok_or_else(|| { @@ -901,7 +910,7 @@ impl<'a> ClarityDatabase<'a> { Ok(()) } - pub fn get_current_block_time(&mut self) -> Result { + pub fn get_current_block_time(&mut self) -> VmExecutionResult { match self.get_data(CLARITY_STORAGE_BLOCK_TIME_KEY)? { Some(value) => Ok(value), None => Err(RuntimeErrorType::BlockTimeNotAvailable.into()), @@ -909,7 +918,7 @@ impl<'a> ClarityDatabase<'a> { } /// Returns the _current_ total liquid ustx - pub fn get_total_liquid_ustx(&mut self) -> Result { + pub fn get_total_liquid_ustx(&mut self) -> VmExecutionResult { let epoch = self.get_clarity_epoch_version()?; Ok(self .get_value( @@ -927,7 +936,7 @@ impl<'a> ClarityDatabase<'a> { .unwrap_or(0)) } - fn set_ustx_liquid_supply(&mut self, set_to: u128) -> Result<()> { + fn set_ustx_liquid_supply(&mut self, set_to: u128) -> VmExecutionResult<()> { self.put_value( ClarityDatabase::ustx_liquid_supply_key(), Value::UInt(set_to), @@ -939,7 +948,7 @@ impl<'a> ClarityDatabase<'a> { }) } - pub fn increment_ustx_liquid_supply(&mut self, incr_by: u128) -> Result<()> { + pub fn increment_ustx_liquid_supply(&mut self, incr_by: u128) -> VmExecutionResult<()> { let current = self.get_total_liquid_ustx()?; let next = current.checked_add(incr_by).ok_or_else(|| { error!("Overflowed `ustx-liquid-supply`"); @@ -949,7 +958,7 @@ impl<'a> ClarityDatabase<'a> { Ok(()) } - pub fn decrement_ustx_liquid_supply(&mut self, decr_by: u128) -> Result<()> { + pub fn decrement_ustx_liquid_supply(&mut self, decr_by: u128) -> VmExecutionResult<()> { let current = self.get_total_liquid_ustx()?; let next = current.checked_sub(decr_by).ok_or_else(|| { error!("`stx-burn?` accepted that reduces `ustx-liquid-supply` below 0"); @@ -960,7 +969,7 @@ impl<'a> ClarityDatabase<'a> { } /// Returns the tenure height of the current block. - pub fn get_tenure_height(&mut self) -> Result { + pub fn get_tenure_height(&mut self) -> VmExecutionResult { if self.get_clarity_epoch_version()? < StacksEpochId::Epoch30 { // Before epoch 3.0, the tenure height was not stored in the // Clarity state. Instead, it was the same as the block height. @@ -982,7 +991,7 @@ impl<'a> ClarityDatabase<'a> { /// Set the tenure height of the current block. In the first block of a new /// tenure, this height must be incremented before evaluating any /// transactions in the block. - pub fn set_tenure_height(&mut self, height: u32) -> Result<()> { + pub fn set_tenure_height(&mut self, height: u32) -> VmExecutionResult<()> { if self.get_clarity_epoch_version()? < StacksEpochId::Epoch30 { return Err(Error::Interpreter(InterpreterError::Expect( "Setting tenure height in Clarity state is not supported before epoch 3.0".into(), @@ -1006,7 +1015,10 @@ impl ClarityDatabase<'_> { /// Returns the ID of a *Stacks* block, by a *Stacks* block height. /// /// Fails if `block_height` >= the "currently" under construction Stacks block height. - pub fn get_index_block_header_hash(&mut self, block_height: u32) -> Result { + pub fn get_index_block_header_hash( + &mut self, + block_height: u32, + ) -> VmExecutionResult { self.store .get_block_header_hash(block_height) // the caller is responsible for ensuring that the block_height given @@ -1042,7 +1054,7 @@ impl ClarityDatabase<'_> { /// Return the height for PoX v2 -> v3 auto unlocks /// from the burn state db - pub fn get_v2_unlock_height(&mut self) -> Result { + pub fn get_v2_unlock_height(&mut self) -> VmExecutionResult { if self.get_clarity_epoch_version()? >= StacksEpochId::Epoch22 { Ok(self.burn_state_db.get_v2_unlock_height()) } else { @@ -1052,7 +1064,7 @@ impl ClarityDatabase<'_> { /// Return the height for PoX v3 -> v4 auto unlocks /// from the burn state db - pub fn get_v3_unlock_height(&mut self) -> Result { + pub fn get_v3_unlock_height(&mut self) -> VmExecutionResult { if self.get_clarity_epoch_version()? >= StacksEpochId::Epoch25 { Ok(self.burn_state_db.get_v3_unlock_height()) } else { @@ -1071,7 +1083,7 @@ impl ClarityDatabase<'_> { pub fn get_block_height_for_tenure_height( &mut self, tenure_height: u32, - ) -> Result> { + ) -> VmExecutionResult> { let current_tenure_height = self.get_tenure_height()?; if current_tenure_height < tenure_height { return Ok(None); @@ -1098,7 +1110,7 @@ impl ClarityDatabase<'_> { /// This is the burnchain block height of the parent of the Stacks block at the current Stacks /// block height (i.e. that returned by `get_index_block_header_hash` for /// `get_current_block_height`). - pub fn get_current_burnchain_block_height(&mut self) -> Result { + pub fn get_current_burnchain_block_height(&mut self) -> VmExecutionResult { let cur_stacks_height = self.store.get_current_block_height(); // Before epoch 3.0, we can only access the burn block associated with the last block @@ -1130,7 +1142,10 @@ impl ClarityDatabase<'_> { } } - pub fn get_block_header_hash(&mut self, block_height: u32) -> Result { + pub fn get_block_header_hash( + &mut self, + block_height: u32, + ) -> VmExecutionResult { let id_bhh = self.get_index_block_header_hash(block_height)?; let epoch = self.get_stacks_epoch_for_block(&id_bhh)?; self.headers_db @@ -1142,7 +1157,7 @@ impl ClarityDatabase<'_> { &mut self, block_height: u32, id_bhh_opt: Option, - ) -> Result { + ) -> VmExecutionResult { let id_bhh = match id_bhh_opt { Some(x) => x, None => self.get_index_block_header_hash(block_height)?, @@ -1153,7 +1168,7 @@ impl ClarityDatabase<'_> { .ok_or_else(|| InterpreterError::Expect("Failed to get block data.".into()).into()) } - pub fn get_block_time(&mut self, block_height: u32) -> Result { + pub fn get_block_time(&mut self, block_height: u32) -> VmExecutionResult { let id_bhh = self.get_index_block_header_hash(block_height)?; let epoch = self.get_stacks_epoch_for_block(&id_bhh)?; if !epoch.uses_nakamoto_blocks() { @@ -1168,7 +1183,7 @@ impl ClarityDatabase<'_> { pub fn get_burnchain_block_header_hash( &mut self, block_height: u32, - ) -> Result { + ) -> VmExecutionResult { let id_bhh = self.get_index_block_header_hash(block_height)?; self.headers_db .get_burn_header_hash_for_block(&id_bhh) @@ -1183,7 +1198,7 @@ impl ClarityDatabase<'_> { /// 4. Resolve the consensus hash to the associated SortitionId /// In Epoch 3+: /// 1. Get the SortitionId of the current Stacks tip - fn get_sortition_id_for_stacks_tip(&mut self) -> Result> { + fn get_sortition_id_for_stacks_tip(&mut self) -> VmExecutionResult> { if !self .get_clarity_epoch_version()? .clarity_uses_tip_burn_block() @@ -1236,7 +1251,7 @@ impl ClarityDatabase<'_> { pub fn get_burnchain_block_header_hash_for_burnchain_height( &mut self, burnchain_block_height: u32, - ) -> Result> { + ) -> VmExecutionResult> { let sortition_id = match self.get_sortition_id_for_stacks_tip()? { Some(x) => x, None => return Ok(None), @@ -1251,7 +1266,7 @@ impl ClarityDatabase<'_> { pub fn get_pox_payout_addrs_for_burnchain_height( &mut self, burnchain_block_height: u32, - ) -> Result, u128)>> { + ) -> VmExecutionResult, u128)>> { let sortition_id = match self.get_sortition_id_for_stacks_tip()? { Some(x) => x, None => return Ok(None), @@ -1265,7 +1280,7 @@ impl ClarityDatabase<'_> { self.headers_db.get_burn_block_height_for_block(id_bhh) } - pub fn get_block_vrf_seed(&mut self, block_height: u32) -> Result { + pub fn get_block_vrf_seed(&mut self, block_height: u32) -> VmExecutionResult { let id_bhh = self.get_index_block_header_hash(block_height)?; let epoch = self.get_stacks_epoch_for_block(&id_bhh)?; self.headers_db @@ -1273,7 +1288,10 @@ impl ClarityDatabase<'_> { .ok_or_else(|| InterpreterError::Expect("Failed to get block data.".into()).into()) } - pub fn get_miner_address(&mut self, block_height: u32) -> Result { + pub fn get_miner_address( + &mut self, + block_height: u32, + ) -> VmExecutionResult { let id_bhh = self.get_index_block_header_hash(block_height)?; let epoch = self.get_stacks_epoch_for_block(&id_bhh)?; Ok(self @@ -1283,7 +1301,7 @@ impl ClarityDatabase<'_> { .into()) } - pub fn get_miner_spend_winner(&mut self, block_height: u32) -> Result { + pub fn get_miner_spend_winner(&mut self, block_height: u32) -> VmExecutionResult { if block_height == 0 { return Ok(0); } @@ -1300,7 +1318,7 @@ impl ClarityDatabase<'_> { })?) } - pub fn get_miner_spend_total(&mut self, block_height: u32) -> Result { + pub fn get_miner_spend_total(&mut self, block_height: u32) -> VmExecutionResult { if block_height == 0 { return Ok(0); } @@ -1317,7 +1335,7 @@ impl ClarityDatabase<'_> { })?) } - pub fn get_block_reward(&mut self, block_height: u32) -> Result> { + pub fn get_block_reward(&mut self, block_height: u32) -> VmExecutionResult> { if block_height == 0 { return Ok(None); } @@ -1342,13 +1360,13 @@ impl ClarityDatabase<'_> { Ok(Some(reward)) } - pub fn get_stx_btc_ops_processed(&mut self) -> Result { + pub fn get_stx_btc_ops_processed(&mut self) -> VmExecutionResult { Ok(self .get_data("vm_pox::stx_btc_ops::processed_blocks")? .unwrap_or(0)) } - pub fn set_stx_btc_ops_processed(&mut self, processed: u64) -> Result<()> { + pub fn set_stx_btc_ops_processed(&mut self, processed: u64) -> VmExecutionResult<()> { self.put_data("vm_pox::stx_btc_ops::processed_blocks", &processed) } } @@ -1368,7 +1386,7 @@ impl ClarityDatabase<'_> { &mut self, pubkey_hash: &Hash160, height: u32, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_microblock_pubkey_height_key(pubkey_hash); let value = format!("{height}"); self.put_data(&key, &value) @@ -1384,7 +1402,7 @@ impl ClarityDatabase<'_> { height: u32, reporter: &StandardPrincipalData, seq: u16, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_microblock_poison_key(height); let value = Value::Tuple( TupleData::from_data(vec![ @@ -1415,7 +1433,7 @@ impl ClarityDatabase<'_> { pub fn get_microblock_pubkey_hash_height( &mut self, pubkey_hash: &Hash160, - ) -> Result> { + ) -> VmExecutionResult> { let key = ClarityDatabase::make_microblock_pubkey_height_key(pubkey_hash); self.get_data(&key)? .map(|height_str: String| { @@ -1433,7 +1451,7 @@ impl ClarityDatabase<'_> { pub fn get_microblock_poison_report( &mut self, height: u32, - ) -> Result> { + ) -> VmExecutionResult> { let key = ClarityDatabase::make_microblock_poison_key(height); self.get_data(&key)? .map(|reporter_hex_str: String| { @@ -1483,7 +1501,7 @@ impl ClarityDatabase<'_> { // this is used so that things like load_map, load_var, load_nft, etc. // will throw NoSuchFoo errors instead of NoSuchContract errors. -fn map_no_contract_as_none(res: Result>) -> Result> { +fn map_no_contract_as_none(res: VmExecutionResult>) -> VmExecutionResult> { res.or_else(|e| match e { Error::Unchecked(CheckErrors::NoSuchContract(_)) => Ok(None), x => Err(x), @@ -1497,7 +1515,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, variable_name: &str, value_type: TypeSignature, - ) -> Result { + ) -> VmExecutionResult { let variable_data = DataVariableMetadata { value_type }; let key = ClarityDatabase::make_metadata_key(StoreType::VariableMeta, variable_name); @@ -1509,7 +1527,7 @@ impl ClarityDatabase<'_> { &mut self, contract_identifier: &QualifiedContractIdentifier, variable_name: &str, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_metadata_key(StoreType::VariableMeta, variable_name); map_no_contract_as_none(self.fetch_metadata(contract_identifier, &key))? @@ -1522,7 +1540,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, variable_name: &str, value: Value, - ) -> Result { + ) -> VmExecutionResult { let epoch = self.get_clarity_epoch_version()?; let descriptor = self.load_variable(contract_identifier, variable_name)?; self.set_variable( @@ -1542,7 +1560,7 @@ impl ClarityDatabase<'_> { value: Value, variable_descriptor: &DataVariableMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { if !variable_descriptor .value_type .admits(&self.get_clarity_epoch_version()?, &value)? @@ -1573,7 +1591,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, variable_name: &str, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let descriptor = self.load_variable(contract_identifier, variable_name)?; self.lookup_variable(contract_identifier, variable_name, &descriptor, epoch) } @@ -1584,7 +1602,7 @@ impl ClarityDatabase<'_> { variable_name: &str, variable_descriptor: &DataVariableMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_key_for_trip( contract_identifier, StoreType::Variable, @@ -1607,7 +1625,7 @@ impl ClarityDatabase<'_> { variable_name: &str, variable_descriptor: &DataVariableMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_key_for_trip( contract_identifier, StoreType::Variable, @@ -1634,7 +1652,7 @@ impl ClarityDatabase<'_> { map_name: &str, key_type: TypeSignature, value_type: TypeSignature, - ) -> Result { + ) -> VmExecutionResult { let data = DataMapMetadata { key_type, value_type, @@ -1650,7 +1668,7 @@ impl ClarityDatabase<'_> { &mut self, contract_identifier: &QualifiedContractIdentifier, map_name: &str, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_metadata_key(StoreType::DataMapMeta, map_name); map_no_contract_as_none(self.fetch_metadata(contract_identifier, &key))? @@ -1661,7 +1679,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, map_name: &str, key_value: &Value, - ) -> Result { + ) -> VmExecutionResult { Ok(ClarityDatabase::make_key_for_data_map_entry_serialized( contract_identifier, map_name, @@ -1688,7 +1706,7 @@ impl ClarityDatabase<'_> { map_name: &str, key_value: &Value, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let descriptor = self.load_map(contract_identifier, map_name)?; self.fetch_entry(contract_identifier, map_name, key_value, &descriptor, epoch) } @@ -1701,7 +1719,7 @@ impl ClarityDatabase<'_> { key_value: &Value, map_descriptor: &DataMapMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { if !map_descriptor .key_type .admits(&self.get_clarity_epoch_version()?, key_value)? @@ -1732,7 +1750,7 @@ impl ClarityDatabase<'_> { key_value: &Value, map_descriptor: &DataMapMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { if !map_descriptor .key_type .admits(&self.get_clarity_epoch_version()?, key_value)? @@ -1781,7 +1799,7 @@ impl ClarityDatabase<'_> { value: Value, map_descriptor: &DataMapMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { self.inner_set_entry( contract_identifier, map_name, @@ -1800,7 +1818,7 @@ impl ClarityDatabase<'_> { key: Value, value: Value, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let descriptor = self.load_map(contract_identifier, map_name)?; self.set_entry( contract_identifier, @@ -1820,7 +1838,7 @@ impl ClarityDatabase<'_> { key: Value, value: Value, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { let descriptor = self.load_map(contract_identifier, map_name)?; self.insert_entry( contract_identifier, @@ -1841,7 +1859,7 @@ impl ClarityDatabase<'_> { value: Value, map_descriptor: &DataMapMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { self.inner_set_entry( contract_identifier, map_name, @@ -1858,7 +1876,7 @@ impl ClarityDatabase<'_> { key: &str, expected_value: &TypeSignature, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { match self.get_value(key, expected_value, epoch)? { None => Ok(false), Some(value) => Ok(value.value != Value::none()), @@ -1875,7 +1893,7 @@ impl ClarityDatabase<'_> { return_if_exists: bool, map_descriptor: &DataMapMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { if !map_descriptor .key_type .admits(&self.get_clarity_epoch_version()?, &key_value)? @@ -1934,7 +1952,7 @@ impl ClarityDatabase<'_> { key_value: &Value, map_descriptor: &DataMapMetadata, epoch: &StacksEpochId, - ) -> Result { + ) -> VmExecutionResult { if !map_descriptor .key_type .admits(&self.get_clarity_epoch_version()?, key_value)? @@ -1983,7 +2001,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, token_name: &str, total_supply: &Option, - ) -> Result { + ) -> VmExecutionResult { let data = FungibleTokenMetadata { total_supply: *total_supply, }; @@ -2006,7 +2024,7 @@ impl ClarityDatabase<'_> { &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_metadata_key(StoreType::FungibleTokenMeta, token_name); map_no_contract_as_none(self.fetch_metadata(contract_identifier, &key))? @@ -2018,7 +2036,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, token_name: &str, key_type: &TypeSignature, - ) -> Result { + ) -> VmExecutionResult { let data = NonFungibleTokenMetadata { key_type: key_type.clone(), }; @@ -2032,7 +2050,7 @@ impl ClarityDatabase<'_> { &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_metadata_key(StoreType::NonFungibleTokenMeta, token_name); map_no_contract_as_none(self.fetch_metadata(contract_identifier, &key))? @@ -2045,7 +2063,7 @@ impl ClarityDatabase<'_> { token_name: &str, amount: u128, descriptor: &FungibleTokenMetadata, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_key_for_trip( contract_identifier, StoreType::CirculatingSupply, @@ -2073,7 +2091,7 @@ impl ClarityDatabase<'_> { contract_identifier: &QualifiedContractIdentifier, token_name: &str, amount: u128, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_key_for_trip( contract_identifier, StoreType::CirculatingSupply, @@ -2098,7 +2116,7 @@ impl ClarityDatabase<'_> { token_name: &str, principal: &PrincipalData, descriptor: Option<&FungibleTokenMetadata>, - ) -> Result { + ) -> VmExecutionResult { if descriptor.is_none() { self.load_ft(contract_identifier, token_name)?; } @@ -2123,7 +2141,7 @@ impl ClarityDatabase<'_> { token_name: &str, principal: &PrincipalData, balance: u128, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_key_for_quad( contract_identifier, StoreType::FungibleToken, @@ -2137,7 +2155,7 @@ impl ClarityDatabase<'_> { &mut self, contract_identifier: &QualifiedContractIdentifier, token_name: &str, - ) -> Result { + ) -> VmExecutionResult { let key = ClarityDatabase::make_key_for_trip( contract_identifier, StoreType::CirculatingSupply, @@ -2155,7 +2173,7 @@ impl ClarityDatabase<'_> { asset_name: &str, asset: &Value, key_type: &TypeSignature, - ) -> Result { + ) -> VmExecutionResult { if !key_type.admits(&self.get_clarity_epoch_version()?, asset)? { return Err(CheckErrors::TypeValueError( Box::new(key_type.clone()), @@ -2195,7 +2213,7 @@ impl ClarityDatabase<'_> { &mut self, contract_identifier: &QualifiedContractIdentifier, asset_name: &str, - ) -> Result { + ) -> VmExecutionResult { let descriptor = self.load_nft(contract_identifier, asset_name)?; Ok(descriptor.key_type) } @@ -2208,7 +2226,7 @@ impl ClarityDatabase<'_> { principal: &PrincipalData, key_type: &TypeSignature, epoch: &StacksEpochId, - ) -> Result<()> { + ) -> VmExecutionResult<()> { if !key_type.admits(&self.get_clarity_epoch_version()?, asset)? { return Err(CheckErrors::TypeValueError( Box::new(key_type.clone()), @@ -2237,7 +2255,7 @@ impl ClarityDatabase<'_> { asset: &Value, key_type: &TypeSignature, epoch: &StacksEpochId, - ) -> Result<()> { + ) -> VmExecutionResult<()> { if !key_type.admits(&self.get_clarity_epoch_version()?, asset)? { return Err(CheckErrors::TypeValueError( Box::new(key_type.clone()), @@ -2283,7 +2301,7 @@ impl<'a> ClarityDatabase<'a> { pub fn get_stx_balance_snapshot<'conn>( &'conn mut self, principal: &PrincipalData, - ) -> Result> { + ) -> VmExecutionResult> { let stx_balance = self.get_account_stx_balance(principal)?; let cur_burn_height = u64::from(self.get_current_burnchain_block_height()?); @@ -2317,7 +2335,7 @@ impl<'a> ClarityDatabase<'a> { pub fn get_stx_balance_snapshot_genesis<'conn>( &'conn mut self, principal: &PrincipalData, - ) -> Result> { + ) -> VmExecutionResult> { let stx_balance = self.get_account_stx_balance(principal)?; let cur_burn_height = 0; @@ -2348,20 +2366,27 @@ impl<'a> ClarityDatabase<'a> { )) } - pub fn get_account_stx_balance(&mut self, principal: &PrincipalData) -> Result { + pub fn get_account_stx_balance( + &mut self, + principal: &PrincipalData, + ) -> VmExecutionResult { let key = ClarityDatabase::make_key_for_account_balance(principal); debug!("Fetching account balance"; "principal" => %principal.to_string()); let result = self.get_data(&key)?; Ok(result.unwrap_or_default()) } - pub fn get_account_nonce(&mut self, principal: &PrincipalData) -> Result { + pub fn get_account_nonce(&mut self, principal: &PrincipalData) -> VmExecutionResult { let key = ClarityDatabase::make_key_for_account_nonce(principal); let result = self.get_data(&key)?; Ok(result.unwrap_or_default()) } - pub fn set_account_nonce(&mut self, principal: &PrincipalData, nonce: u64) -> Result<()> { + pub fn set_account_nonce( + &mut self, + principal: &PrincipalData, + nonce: u64, + ) -> VmExecutionResult<()> { let key = ClarityDatabase::make_key_for_account_nonce(principal); self.put_data(&key, &nonce) } @@ -2379,7 +2404,10 @@ impl ClarityDatabase<'_> { self.burn_state_db.get_stacks_epoch(height) } - pub fn get_stacks_epoch_for_block(&self, id_bhh: &StacksBlockId) -> Result { + pub fn get_stacks_epoch_for_block( + &self, + id_bhh: &StacksBlockId, + ) -> VmExecutionResult { let burn_block = self.get_burnchain_block_height(id_bhh).ok_or_else(|| { InterpreterError::Expect(format!( "FATAL: no burnchain block height found for Stacks block {id_bhh}" diff --git a/clarity/src/vm/database/clarity_store.rs b/clarity/src/vm/database/clarity_store.rs index e1d6dacaee..97d11ca878 100644 --- a/clarity/src/vm/database/clarity_store.rs +++ b/clarity/src/vm/database/clarity_store.rs @@ -24,7 +24,7 @@ use crate::vm::contexts::GlobalContext; use crate::vm::database::{ ClarityDatabase, ClarityDeserializable, ClaritySerializable, NULL_BURN_STATE_DB, NULL_HEADER_DB, }; -use crate::vm::errors::{InterpreterError, InterpreterResult as Result}; +use crate::vm::errors::{InterpreterError, VmExecutionResult}; use crate::vm::types::{PrincipalData, QualifiedContractIdentifier}; use crate::vm::Value; @@ -45,33 +45,33 @@ pub type SpecialCaseHandler = &'static dyn Fn( &[Value], // the result of the function call &Value, -) -> Result<()>; +) -> VmExecutionResult<()>; // These functions generally _do not_ return errors, rather, any errors in the underlying storage // will _panic_. The rationale for this is that under no condition should the interpreter // attempt to continue processing in the event of an unexpected storage error. pub trait ClarityBackingStore { /// put K-V data into the committed datastore - fn put_all_data(&mut self, items: Vec<(String, String)>) -> Result<()>; + fn put_all_data(&mut self, items: Vec<(String, String)>) -> VmExecutionResult<()>; /// fetch K-V out of the committed datastore - fn get_data(&mut self, key: &str) -> Result>; + fn get_data(&mut self, key: &str) -> VmExecutionResult>; /// fetch Hash(K)-V out of the commmitted datastore - fn get_data_from_path(&mut self, hash: &TrieHash) -> Result>; + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult>; /// fetch K-V out of the committed datastore, along with the byte representation /// of the Merkle proof for that key-value pair - fn get_data_with_proof(&mut self, key: &str) -> Result)>>; + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>>; fn get_data_with_proof_from_path( &mut self, hash: &TrieHash, - ) -> Result)>>; - fn has_entry(&mut self, key: &str) -> Result { + ) -> VmExecutionResult)>>; + fn has_entry(&mut self, key: &str) -> VmExecutionResult { Ok(self.get_data(key)?.is_some()) } /// change the current MARF context to service reads from a different chain_tip /// used to implement time-shifted evaluation. /// returns the previous block header hash on success - fn set_block_hash(&mut self, bhh: StacksBlockId) -> Result; + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult; /// Is None if `block_height` >= the "currently" under construction Stacks block height. fn get_block_at_height(&mut self, height: u32) -> Option; @@ -108,32 +108,32 @@ pub trait ClarityBackingStore { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> Result<(StacksBlockId, Sha512Trunc256Sum)>; + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)>; fn insert_metadata( &mut self, contract: &QualifiedContractIdentifier, key: &str, value: &str, - ) -> Result<()>; + ) -> VmExecutionResult<()>; fn get_metadata( &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> Result>; + ) -> VmExecutionResult>; fn get_metadata_manual( &mut self, at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> Result>; + ) -> VmExecutionResult>; fn put_all_metadata( &mut self, items: Vec<((QualifiedContractIdentifier, String), String)>, - ) -> Result<()> { + ) -> VmExecutionResult<()> { for ((contract, key), value) in items.into_iter() { self.insert_metadata(&contract, &key, &value)?; } @@ -158,7 +158,7 @@ impl ClaritySerializable for ContractCommitment { } impl ClarityDeserializable for ContractCommitment { - fn deserialize(input: &str) -> Result { + fn deserialize(input: &str) -> VmExecutionResult { if input.len() != 72 { return Err(InterpreterError::Expect("Unexpected input length".into()).into()); } @@ -198,26 +198,26 @@ impl NullBackingStore { #[allow(clippy::panic)] impl ClarityBackingStore for NullBackingStore { - fn set_block_hash(&mut self, _bhh: StacksBlockId) -> Result { + fn set_block_hash(&mut self, _bhh: StacksBlockId) -> VmExecutionResult { panic!("NullBackingStore can't set block hash") } - fn get_data(&mut self, _key: &str) -> Result> { + fn get_data(&mut self, _key: &str) -> VmExecutionResult> { panic!("NullBackingStore can't retrieve data") } - fn get_data_from_path(&mut self, _hash: &TrieHash) -> Result> { + fn get_data_from_path(&mut self, _hash: &TrieHash) -> VmExecutionResult> { panic!("NullBackingStore can't retrieve data") } - fn get_data_with_proof(&mut self, _key: &str) -> Result)>> { + fn get_data_with_proof(&mut self, _key: &str) -> VmExecutionResult)>> { panic!("NullBackingStore can't retrieve data") } fn get_data_with_proof_from_path( &mut self, _hash: &TrieHash, - ) -> Result)>> { + ) -> VmExecutionResult)>> { panic!("NullBackingStore can't retrieve data") } @@ -242,14 +242,14 @@ impl ClarityBackingStore for NullBackingStore { panic!("NullBackingStore can't get current block height") } - fn put_all_data(&mut self, mut _items: Vec<(String, String)>) -> Result<()> { + fn put_all_data(&mut self, mut _items: Vec<(String, String)>) -> VmExecutionResult<()> { panic!("NullBackingStore cannot put") } fn get_contract_hash( &mut self, _contract: &QualifiedContractIdentifier, - ) -> Result<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { panic!("NullBackingStore cannot get_contract_hash") } @@ -258,7 +258,7 @@ impl ClarityBackingStore for NullBackingStore { _contract: &QualifiedContractIdentifier, _key: &str, _value: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { panic!("NullBackingStore cannot insert_metadata") } @@ -266,7 +266,7 @@ impl ClarityBackingStore for NullBackingStore { &mut self, _contract: &QualifiedContractIdentifier, _key: &str, - ) -> Result> { + ) -> VmExecutionResult> { panic!("NullBackingStore cannot get_metadata") } @@ -275,7 +275,7 @@ impl ClarityBackingStore for NullBackingStore { _at_height: u32, _contract: &QualifiedContractIdentifier, _key: &str, - ) -> Result> { + ) -> VmExecutionResult> { panic!("NullBackingStore cannot get_metadata_manual") } } diff --git a/clarity/src/vm/database/key_value_wrapper.rs b/clarity/src/vm/database/key_value_wrapper.rs index 5578ac549d..2591a4f22a 100644 --- a/clarity/src/vm/database/key_value_wrapper.rs +++ b/clarity/src/vm/database/key_value_wrapper.rs @@ -24,7 +24,7 @@ use stacks_common::util::hash::Sha512Trunc256Sum; use super::clarity_store::SpecialCaseHandler; use super::{ClarityBackingStore, ClarityDeserializable}; use crate::vm::database::clarity_store::{make_contract_hash_key, ContractCommitment}; -use crate::vm::errors::{InterpreterError, InterpreterResult}; +use crate::vm::errors::{InterpreterError, VmExecutionResult}; use crate::vm::types::serialization::SerializationError; use crate::vm::types::{QualifiedContractIdentifier, TypeSignature}; use crate::vm::Value; @@ -320,7 +320,7 @@ fn inner_put_data( } impl RollbackWrapper<'_> { - pub fn put_data(&mut self, key: &str, value: &str) -> InterpreterResult<()> { + pub fn put_data(&mut self, key: &str, value: &str) -> VmExecutionResult<()> { let current = self.stack.last_mut().ok_or_else(|| { InterpreterError::Expect( "ERROR: Clarity VM attempted PUT on non-nested context.".into(), @@ -345,7 +345,7 @@ impl RollbackWrapper<'_> { &mut self, bhh: StacksBlockId, query_pending_data: bool, - ) -> InterpreterResult { + ) -> VmExecutionResult { self.store.set_block_hash(bhh).inspect(|_| { // use and_then so that query_pending_data is only set once set_block_hash succeeds // this doesn't matter in practice, because a set_block_hash failure always aborts @@ -357,7 +357,7 @@ impl RollbackWrapper<'_> { /// this function will only return commitment proofs for values _already_ materialized /// in the underlying store. otherwise it returns None. - pub fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult)>> + pub fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> where T: ClarityDeserializable, { @@ -372,7 +372,7 @@ impl RollbackWrapper<'_> { pub fn get_data_with_proof_by_hash( &mut self, hash: &TrieHash, - ) -> InterpreterResult)>> + ) -> VmExecutionResult)>> where T: ClarityDeserializable, { @@ -382,7 +382,7 @@ impl RollbackWrapper<'_> { .transpose() } - pub fn get_data(&mut self, key: &str) -> InterpreterResult> + pub fn get_data(&mut self, key: &str) -> VmExecutionResult> where T: ClarityDeserializable, { @@ -412,7 +412,7 @@ impl RollbackWrapper<'_> { /// /// This should never be called from within the Clarity VM, or via block-processing. It's only /// meant to be used by the RPC system. - pub fn get_data_by_hash(&mut self, hash: &TrieHash) -> InterpreterResult> + pub fn get_data_by_hash(&mut self, hash: &TrieHash) -> VmExecutionResult> where T: ClarityDeserializable, { @@ -478,7 +478,7 @@ impl RollbackWrapper<'_> { pub fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { let key = make_contract_hash_key(contract); let s = match self.get_data::(&key)? { Some(s) => s, @@ -492,7 +492,7 @@ impl RollbackWrapper<'_> { &mut self, contract: &QualifiedContractIdentifier, content_hash: Sha512Trunc256Sum, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { let key = make_contract_hash_key(contract); let value = self.store.make_contract_commitment(content_hash); self.put_data(&key, &value) @@ -527,7 +527,7 @@ impl RollbackWrapper<'_> { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { self.stack.last().ok_or_else(|| { InterpreterError::Expect( "ERROR: Clarity VM attempted GET on non-nested context.".into(), @@ -558,7 +558,7 @@ impl RollbackWrapper<'_> { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { self.stack.last().ok_or_else(|| { InterpreterError::Expect( "ERROR: Clarity VM attempted GET on non-nested context.".into(), @@ -582,7 +582,7 @@ impl RollbackWrapper<'_> { } } - pub fn has_entry(&mut self, key: &str) -> InterpreterResult { + pub fn has_entry(&mut self, key: &str) -> VmExecutionResult { self.stack.last().ok_or_else(|| { InterpreterError::Expect( "ERROR: Clarity VM attempted GET on non-nested context.".into(), diff --git a/clarity/src/vm/database/sqlite.rs b/clarity/src/vm/database/sqlite.rs index c1af553041..65a5bb7c60 100644 --- a/clarity/src/vm/database/sqlite.rs +++ b/clarity/src/vm/database/sqlite.rs @@ -26,9 +26,7 @@ use super::{ NULL_BURN_STATE_DB, NULL_HEADER_DB, }; use crate::vm::analysis::{AnalysisDatabase, CheckErrors}; -use crate::vm::errors::{ - IncomparableError, InterpreterError, InterpreterResult as Result, RuntimeErrorType, -}; +use crate::vm::errors::{IncomparableError, InterpreterError, RuntimeErrorType, VmExecutionResult}; use crate::vm::types::QualifiedContractIdentifier; const SQL_FAIL_MESSAGE: &str = "PANIC: SQL Failure in Smart Contract VM."; @@ -37,7 +35,7 @@ pub struct SqliteConnection { conn: Connection, } -fn sqlite_put(conn: &Connection, key: &str, value: &str) -> Result<()> { +fn sqlite_put(conn: &Connection, key: &str, value: &str) -> VmExecutionResult<()> { let params = params![key, value]; match conn.execute("REPLACE INTO data_table (key, value) VALUES (?, ?)", params) { Ok(_) => Ok(()), @@ -48,7 +46,7 @@ fn sqlite_put(conn: &Connection, key: &str, value: &str) -> Result<()> { } } -fn sqlite_get(conn: &Connection, key: &str) -> Result> { +fn sqlite_get(conn: &Connection, key: &str) -> VmExecutionResult> { trace!("sqlite_get {key}"); let params = params![key]; let res = match conn @@ -70,14 +68,14 @@ fn sqlite_get(conn: &Connection, key: &str) -> Result> { res } -fn sqlite_has_entry(conn: &Connection, key: &str) -> Result { +fn sqlite_has_entry(conn: &Connection, key: &str) -> VmExecutionResult { Ok(sqlite_get(conn, key)?.is_some()) } pub fn sqlite_get_contract_hash( store: &mut dyn ClarityBackingStore, contract: &QualifiedContractIdentifier, -) -> Result<(StacksBlockId, Sha512Trunc256Sum)> { +) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { let key = make_contract_hash_key(contract); let contract_commitment = store .get_data(&key)? @@ -97,7 +95,7 @@ pub fn sqlite_insert_metadata( contract: &QualifiedContractIdentifier, key: &str, value: &str, -) -> Result<()> { +) -> VmExecutionResult<()> { let bhh = store.get_open_chain_tip(); SqliteConnection::insert_metadata( store.get_side_store(), @@ -112,7 +110,7 @@ pub fn sqlite_get_metadata( store: &mut dyn ClarityBackingStore, contract: &QualifiedContractIdentifier, key: &str, -) -> Result> { +) -> VmExecutionResult> { let (bhh, _) = store.get_contract_hash(contract)?; SqliteConnection::get_metadata(store.get_side_store(), &bhh, &contract.to_string(), key) } @@ -122,7 +120,7 @@ pub fn sqlite_get_metadata_manual( at_height: u32, contract: &QualifiedContractIdentifier, key: &str, -) -> Result> { +) -> VmExecutionResult> { let bhh = store.get_block_at_height(at_height).ok_or_else(|| { warn!("Unknown block height when manually querying metadata"; "block_height" => at_height); RuntimeErrorType::BadBlockHeight(at_height.to_string()) @@ -131,11 +129,11 @@ pub fn sqlite_get_metadata_manual( } impl SqliteConnection { - pub fn put(conn: &Connection, key: &str, value: &str) -> Result<()> { + pub fn put(conn: &Connection, key: &str, value: &str) -> VmExecutionResult<()> { sqlite_put(conn, key, value) } - pub fn get(conn: &Connection, key: &str) -> Result> { + pub fn get(conn: &Connection, key: &str) -> VmExecutionResult> { sqlite_get(conn, key) } @@ -145,7 +143,7 @@ impl SqliteConnection { contract_hash: &str, key: &str, value: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let key = format!("clr-meta::{contract_hash}::{key}"); let params = params![bhh, key, value]; @@ -163,7 +161,7 @@ impl SqliteConnection { conn: &Connection, from: &StacksBlockId, to: &StacksBlockId, - ) -> Result<()> { + ) -> VmExecutionResult<()> { let params = params![to, from]; if let Err(e) = conn.execute( "UPDATE metadata_table SET blockhash = ? WHERE blockhash = ?", @@ -175,7 +173,7 @@ impl SqliteConnection { Ok(()) } - pub fn drop_metadata(conn: &Connection, from: &StacksBlockId) -> Result<()> { + pub fn drop_metadata(conn: &Connection, from: &StacksBlockId) -> VmExecutionResult<()> { if let Err(e) = conn.execute( "DELETE FROM metadata_table WHERE blockhash = ?", params![from], @@ -191,7 +189,7 @@ impl SqliteConnection { bhh: &StacksBlockId, contract_hash: &str, key: &str, - ) -> Result> { + ) -> VmExecutionResult> { let key = format!("clr-meta::{contract_hash}::{key}"); let params = params![bhh, key]; @@ -211,13 +209,13 @@ impl SqliteConnection { } } - pub fn has_entry(conn: &Connection, key: &str) -> Result { + pub fn has_entry(conn: &Connection, key: &str) -> VmExecutionResult { sqlite_has_entry(conn, key) } } impl SqliteConnection { - pub fn initialize_conn(conn: &Connection) -> Result<()> { + pub fn initialize_conn(conn: &Connection) -> VmExecutionResult<()> { conn.query_row("PRAGMA journal_mode = WAL;", NO_PARAMS, |_row| Ok(())) .map_err(|x| InterpreterError::SqliteError(IncomparableError { err: x }))?; @@ -247,13 +245,13 @@ impl SqliteConnection { Ok(()) } - pub fn memory() -> Result { + pub fn memory() -> VmExecutionResult { let contract_db = SqliteConnection::inner_open(":memory:")?; SqliteConnection::initialize_conn(&contract_db)?; Ok(contract_db) } - pub fn check_schema(conn: &Connection) -> Result<()> { + pub fn check_schema(conn: &Connection) -> VmExecutionResult<()> { let sql = "SELECT sql FROM sqlite_master WHERE name=?"; let _: String = conn .query_row(sql, params!["data_table"], |row| row.get(0)) @@ -267,7 +265,7 @@ impl SqliteConnection { Ok(()) } - fn inner_open(filename: &str) -> Result { + fn inner_open(filename: &str) -> VmExecutionResult { let conn = Connection::open(filename) .map_err(|x| InterpreterError::SqliteError(IncomparableError { err: x }))?; @@ -310,26 +308,26 @@ impl MemoryBackingStore { } impl ClarityBackingStore for MemoryBackingStore { - fn set_block_hash(&mut self, bhh: StacksBlockId) -> Result { + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult { Err(RuntimeErrorType::UnknownBlockHeaderHash(BlockHeaderHash(bhh.0)).into()) } - fn get_data(&mut self, key: &str) -> Result> { + fn get_data(&mut self, key: &str) -> VmExecutionResult> { SqliteConnection::get(self.get_side_store(), key) } - fn get_data_from_path(&mut self, hash: &TrieHash) -> Result> { + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult> { SqliteConnection::get(self.get_side_store(), hash.to_string().as_str()) } - fn get_data_with_proof(&mut self, key: &str) -> Result)>> { + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> { Ok(SqliteConnection::get(self.get_side_store(), key)?.map(|x| (x, vec![]))) } fn get_data_with_proof_from_path( &mut self, hash: &TrieHash, - ) -> Result)>> { + ) -> VmExecutionResult)>> { self.get_data_with_proof(&hash.to_string()) } @@ -361,7 +359,7 @@ impl ClarityBackingStore for MemoryBackingStore { None } - fn put_all_data(&mut self, items: Vec<(String, String)>) -> Result<()> { + fn put_all_data(&mut self, items: Vec<(String, String)>) -> VmExecutionResult<()> { for (key, value) in items.into_iter() { SqliteConnection::put(self.get_side_store(), &key, &value)?; } @@ -371,7 +369,7 @@ impl ClarityBackingStore for MemoryBackingStore { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> Result<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { sqlite_get_contract_hash(self, contract) } @@ -380,7 +378,7 @@ impl ClarityBackingStore for MemoryBackingStore { contract: &QualifiedContractIdentifier, key: &str, value: &str, - ) -> Result<()> { + ) -> VmExecutionResult<()> { sqlite_insert_metadata(self, contract, key, value) } @@ -388,7 +386,7 @@ impl ClarityBackingStore for MemoryBackingStore { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> Result> { + ) -> VmExecutionResult> { sqlite_get_metadata(self, contract, key) } @@ -397,7 +395,7 @@ impl ClarityBackingStore for MemoryBackingStore { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> Result> { + ) -> VmExecutionResult> { sqlite_get_metadata_manual(self, at_height, contract, key) } } diff --git a/clarity/src/vm/errors.rs b/clarity/src/vm/errors.rs index 764ac466e5..2367edd70a 100644 --- a/clarity/src/vm/errors.rs +++ b/clarity/src/vm/errors.rs @@ -15,8 +15,8 @@ // along with this program. If not, see . pub use clarity_types::errors::{ - Error, IncomparableError, InterpreterError, InterpreterResult, RuntimeErrorType, - ShortReturnType, + Error, IncomparableError, InterpreterError, RuntimeErrorType, ShortReturnType, + VmExecutionResult, }; pub use crate::vm::analysis::errors::{ diff --git a/clarity/src/vm/functions/arithmetic.rs b/clarity/src/vm/functions/arithmetic.rs index 2d5c2aff3a..c8c4c3eadf 100644 --- a/clarity/src/vm/functions/arithmetic.rs +++ b/clarity/src/vm/functions/arithmetic.rs @@ -21,7 +21,7 @@ use integer_sqrt::IntegerSquareRoot; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; use crate::vm::errors::{ - check_argument_count, CheckErrors, InterpreterError, InterpreterResult, RuntimeErrorType, + check_argument_count, CheckErrors, InterpreterError, RuntimeErrorType, VmExecutionResult, }; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{ @@ -37,25 +37,25 @@ struct UTF8Ops(); struct BuffOps(); impl U128Ops { - fn make_value(x: u128) -> InterpreterResult { + fn make_value(x: u128) -> VmExecutionResult { Ok(Value::UInt(x)) } } impl I128Ops { - fn make_value(x: i128) -> InterpreterResult { + fn make_value(x: i128) -> VmExecutionResult { Ok(Value::Int(x)) } } impl ASCIIOps { - fn make_value(x: Vec) -> InterpreterResult { + fn make_value(x: Vec) -> VmExecutionResult { Ok(Value::Sequence(SequenceData::String(CharType::ASCII( ASCIIData { data: x }, )))) } } impl UTF8Ops { - fn make_value(x: Vec>) -> InterpreterResult { + fn make_value(x: Vec>) -> VmExecutionResult { Ok(Value::Sequence(SequenceData::String(CharType::UTF8( UTF8Data { data: x }, )))) @@ -63,7 +63,7 @@ impl UTF8Ops { } impl BuffOps { - fn make_value(x: Vec) -> InterpreterResult { + fn make_value(x: Vec) -> VmExecutionResult { Ok(Value::Sequence(SequenceData::Buffer(BuffData { data: x }))) } } @@ -199,16 +199,16 @@ macro_rules! type_force_variadic_arithmetic { macro_rules! make_comparison_ops { ($struct_name: ident, $type:ty) => { impl $struct_name { - fn greater(x: $type, y: $type) -> InterpreterResult { + fn greater(x: $type, y: $type) -> VmExecutionResult { Ok(Value::Bool(x > y)) } - fn less(x: $type, y: $type) -> InterpreterResult { + fn less(x: $type, y: $type) -> VmExecutionResult { Ok(Value::Bool(x < y)) } - fn leq(x: $type, y: $type) -> InterpreterResult { + fn leq(x: $type, y: $type) -> VmExecutionResult { Ok(Value::Bool(x <= y)) } - fn geq(x: $type, y: $type) -> InterpreterResult { + fn geq(x: $type, y: $type) -> VmExecutionResult { Ok(Value::Bool(x >= y)) } } @@ -222,14 +222,14 @@ macro_rules! make_comparison_ops { macro_rules! make_arithmetic_ops { ($struct_name: ident, $type:ty) => { impl $struct_name { - fn xor(x: $type, y: $type) -> InterpreterResult { + fn xor(x: $type, y: $type) -> VmExecutionResult { Self::make_value(x ^ y) } - fn bitwise_xor2(args: &[$type]) -> InterpreterResult { + fn bitwise_xor2(args: &[$type]) -> VmExecutionResult { let result = args.iter().fold(0, |acc: $type, x: &$type| (acc ^ x)); Self::make_value(result) } - fn bitwise_and(args: &[$type]) -> InterpreterResult { + fn bitwise_and(args: &[$type]) -> VmExecutionResult { let first: $type = args[0]; let result = args .iter() @@ -237,21 +237,21 @@ macro_rules! make_arithmetic_ops { .fold(first, |acc: $type, x: &$type| (acc & x)); Self::make_value(result) } - fn bitwise_or(args: &[$type]) -> InterpreterResult { + fn bitwise_or(args: &[$type]) -> VmExecutionResult { let result = args.iter().fold(0, |acc: $type, x: &$type| (acc | x)); Self::make_value(result) } - fn bitwise_not(x: $type) -> InterpreterResult { + fn bitwise_not(x: $type) -> VmExecutionResult { Self::make_value(!x) } - fn add(args: &[$type]) -> InterpreterResult { + fn add(args: &[$type]) -> VmExecutionResult { let result = args .iter() .try_fold(0, |acc: $type, x: &$type| acc.checked_add(*x)) .ok_or(RuntimeErrorType::ArithmeticOverflow)?; Self::make_value(result) } - fn sub(args: &[$type]) -> InterpreterResult { + fn sub(args: &[$type]) -> VmExecutionResult { let (first, rest) = args .split_first() .ok_or(CheckErrors::IncorrectArgumentCount(1, 0))?; @@ -270,14 +270,14 @@ macro_rules! make_arithmetic_ops { .ok_or(RuntimeErrorType::ArithmeticUnderflow)?; Self::make_value(result) } - fn mul(args: &[$type]) -> InterpreterResult { + fn mul(args: &[$type]) -> VmExecutionResult { let result = args .iter() .try_fold(1, |acc: $type, x: &$type| acc.checked_mul(*x)) .ok_or(RuntimeErrorType::ArithmeticOverflow)?; Self::make_value(result) } - fn div(args: &[$type]) -> InterpreterResult { + fn div(args: &[$type]) -> VmExecutionResult { let (first, rest) = args .split_first() .ok_or(CheckErrors::IncorrectArgumentCount(1, 0))?; @@ -287,14 +287,14 @@ macro_rules! make_arithmetic_ops { .ok_or(RuntimeErrorType::DivisionByZero)?; Self::make_value(result) } - fn modulo(numerator: $type, denominator: $type) -> InterpreterResult { + fn modulo(numerator: $type, denominator: $type) -> VmExecutionResult { let result = numerator .checked_rem(denominator) .ok_or(RuntimeErrorType::DivisionByZero)?; Self::make_value(result) } #[allow(unused_comparisons)] - fn pow(base: $type, power: $type) -> InterpreterResult { + fn pow(base: $type, power: $type) -> VmExecutionResult { if base == 0 && power == 0 { // Note that 0⁰ (pow(0, 0)) returns 1. Mathematically this is undefined (https://docs.rs/num-traits/0.2.10/num_traits/pow/fn.pow.html) return Self::make_value(1); @@ -325,7 +325,7 @@ macro_rules! make_arithmetic_ops { .ok_or(RuntimeErrorType::ArithmeticOverflow)?; Self::make_value(result) } - fn sqrti(n: $type) -> InterpreterResult { + fn sqrti(n: $type) -> VmExecutionResult { match n.integer_sqrt_checked() { Some(result) => Self::make_value(result), None => { @@ -336,7 +336,7 @@ macro_rules! make_arithmetic_ops { } } } - fn log2(n: $type) -> InterpreterResult { + fn log2(n: $type) -> VmExecutionResult { if n < 1 { return Err(RuntimeErrorType::Arithmetic( "log2 must be passed a positive integer".to_string(), @@ -360,24 +360,24 @@ make_comparison_ops!(UTF8Ops, Vec>); make_comparison_ops!(BuffOps, Vec); // Used for the `xor` function. -pub fn native_xor(a: Value, b: Value) -> InterpreterResult { +pub fn native_xor(a: Value, b: Value) -> VmExecutionResult { type_force_binary_arithmetic!(xor, a, b) } // Used for the `^` xor function. -pub fn native_bitwise_xor(mut args: Vec) -> InterpreterResult { +pub fn native_bitwise_xor(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(bitwise_xor2, args) } -pub fn native_bitwise_and(mut args: Vec) -> InterpreterResult { +pub fn native_bitwise_and(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(bitwise_and, args) } -pub fn native_bitwise_or(mut args: Vec) -> InterpreterResult { +pub fn native_bitwise_or(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(bitwise_or, args) } -pub fn native_bitwise_not(a: Value) -> InterpreterResult { +pub fn native_bitwise_not(a: Value) -> VmExecutionResult { type_force_unary_arithmetic!(bitwise_not, a) } @@ -387,7 +387,7 @@ fn special_geq_v1( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -401,7 +401,7 @@ fn special_geq_v2( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -419,7 +419,7 @@ pub fn special_geq( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { if *env.contract_context.get_clarity_version() >= ClarityVersion::Clarity2 { special_geq_v2(args, env, context) } else { @@ -434,7 +434,7 @@ fn special_leq_v1( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -448,7 +448,7 @@ fn special_leq_v2( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -466,7 +466,7 @@ pub fn special_leq( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { if *env.contract_context.get_clarity_version() >= ClarityVersion::Clarity2 { special_leq_v2(args, env, context) } else { @@ -480,7 +480,7 @@ fn special_greater_v1( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -494,7 +494,7 @@ fn special_greater_v2( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -508,7 +508,7 @@ pub fn special_greater( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { if *env.contract_context.get_clarity_version() >= ClarityVersion::Clarity2 { special_greater_v2(args, env, context) } else { @@ -522,7 +522,7 @@ fn special_less_v1( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -536,7 +536,7 @@ fn special_less_v2( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { check_argument_count(2, args)?; let a = eval(&args[0], env, context)?; let b = eval(&args[1], env, context)?; @@ -550,7 +550,7 @@ pub fn special_less( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> InterpreterResult { +) -> VmExecutionResult { if *env.contract_context.get_clarity_version() >= ClarityVersion::Clarity2 { special_less_v2(args, env, context) } else { @@ -558,32 +558,32 @@ pub fn special_less( } } -pub fn native_add(mut args: Vec) -> InterpreterResult { +pub fn native_add(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(add, args) } -pub fn native_sub(mut args: Vec) -> InterpreterResult { +pub fn native_sub(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(sub, args) } -pub fn native_mul(mut args: Vec) -> InterpreterResult { +pub fn native_mul(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(mul, args) } -pub fn native_div(mut args: Vec) -> InterpreterResult { +pub fn native_div(mut args: Vec) -> VmExecutionResult { type_force_variadic_arithmetic!(div, args) } -pub fn native_pow(a: Value, b: Value) -> InterpreterResult { +pub fn native_pow(a: Value, b: Value) -> VmExecutionResult { type_force_binary_arithmetic!(pow, a, b) } -pub fn native_sqrti(n: Value) -> InterpreterResult { +pub fn native_sqrti(n: Value) -> VmExecutionResult { type_force_unary_arithmetic!(sqrti, n) } -pub fn native_log2(n: Value) -> InterpreterResult { +pub fn native_log2(n: Value) -> VmExecutionResult { type_force_unary_arithmetic!(log2, n) } -pub fn native_mod(a: Value, b: Value) -> InterpreterResult { +pub fn native_mod(a: Value, b: Value) -> VmExecutionResult { type_force_binary_arithmetic!(modulo, a, b) } -pub fn native_bitwise_left_shift(input: Value, pos: Value) -> InterpreterResult { +pub fn native_bitwise_left_shift(input: Value, pos: Value) -> VmExecutionResult { if let Value::UInt(u128_val) = pos { let shamt = u32::try_from(u128_val & 0x7f).map_err(|_| { InterpreterError::Expect("FATAL: lower 32 bits did not convert to u32".into()) @@ -609,7 +609,7 @@ pub fn native_bitwise_left_shift(input: Value, pos: Value) -> InterpreterResult< } } -pub fn native_bitwise_right_shift(input: Value, pos: Value) -> InterpreterResult { +pub fn native_bitwise_right_shift(input: Value, pos: Value) -> VmExecutionResult { if let Value::UInt(u128_val) = pos { let shamt = u32::try_from(u128_val & 0x7f).map_err(|_| { InterpreterError::Expect("FATAL: lower 32 bits did not convert to u32".into()) @@ -635,7 +635,7 @@ pub fn native_bitwise_right_shift(input: Value, pos: Value) -> InterpreterResult } } -pub fn native_to_uint(input: Value) -> InterpreterResult { +pub fn native_to_uint(input: Value) -> VmExecutionResult { if let Value::Int(int_val) = input { let uint_val = u128::try_from(int_val).map_err(|_| RuntimeErrorType::ArithmeticUnderflow)?; @@ -645,7 +645,7 @@ pub fn native_to_uint(input: Value) -> InterpreterResult { } } -pub fn native_to_int(input: Value) -> InterpreterResult { +pub fn native_to_int(input: Value) -> VmExecutionResult { if let Value::UInt(uint_val) = input { let int_val = i128::try_from(uint_val).map_err(|_| RuntimeErrorType::ArithmeticOverflow)?; Ok(Value::Int(int_val)) diff --git a/clarity/src/vm/functions/assets.rs b/clarity/src/vm/functions/assets.rs index 62763fa3fc..303d9deb31 100644 --- a/clarity/src/vm/functions/assets.rs +++ b/clarity/src/vm/functions/assets.rs @@ -20,8 +20,7 @@ use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{runtime_cost, CostTracker}; use crate::vm::database::STXBalance; use crate::vm::errors::{ - check_argument_count, CheckErrors, Error, InterpreterError, InterpreterResult as Result, - RuntimeErrorType, + check_argument_count, CheckErrors, Error, InterpreterError, RuntimeErrorType, VmExecutionResult, }; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{ @@ -91,7 +90,7 @@ pub fn special_stx_balance( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; runtime_cost(ClarityCostFunction::StxBalance, env, 0)?; @@ -124,7 +123,7 @@ pub fn stx_transfer_consolidated( to: &PrincipalData, amount: u128, memo: &BuffData, -) -> Result { +) -> VmExecutionResult { if amount == 0 { return clarity_ecode!(StxErrorCodes::NON_POSITIVE_AMOUNT); } @@ -162,7 +161,7 @@ pub fn special_stx_transfer( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::StxTransfer, env, 0)?; @@ -189,7 +188,7 @@ pub fn special_stx_transfer_memo( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(4, args)?; runtime_cost(ClarityCostFunction::StxTransferMemo, env, 0)?; @@ -216,7 +215,7 @@ pub fn special_stx_account( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; runtime_cost(ClarityCostFunction::StxGetAccount, env, 0)?; @@ -272,7 +271,7 @@ pub fn special_stx_burn( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; runtime_cost(ClarityCostFunction::StxTransfer, env, 0)?; @@ -317,7 +316,7 @@ pub fn special_mint_token( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::FtMint, env, 0)?; @@ -382,7 +381,7 @@ pub fn special_mint_asset_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; let asset_name = args[0].match_atom().ok_or(CheckErrors::BadTokenName)?; @@ -457,7 +456,7 @@ pub fn special_mint_asset_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; let asset_name = args[0].match_atom().ok_or(CheckErrors::BadTokenName)?; @@ -529,7 +528,7 @@ pub fn special_transfer_asset_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(4, args)?; let asset_name = args[0].match_atom().ok_or(CheckErrors::BadTokenName)?; @@ -624,7 +623,7 @@ pub fn special_transfer_asset_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(4, args)?; let asset_name = args[0].match_atom().ok_or(CheckErrors::BadTokenName)?; @@ -716,7 +715,7 @@ pub fn special_transfer_token( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(4, args)?; runtime_cost(ClarityCostFunction::FtTransfer, env, 0)?; @@ -817,7 +816,7 @@ pub fn special_get_balance( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; runtime_cost(ClarityCostFunction::FtBalance, env, 0)?; @@ -852,7 +851,7 @@ pub fn special_get_owner_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let asset_name = args[0].match_atom().ok_or(CheckErrors::BadTokenName)?; @@ -900,7 +899,7 @@ pub fn special_get_owner_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let asset_name = args[0].match_atom().ok_or(CheckErrors::BadTokenName)?; @@ -945,7 +944,7 @@ pub fn special_get_token_supply( args: &[SymbolicExpression], env: &mut Environment, _context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; runtime_cost(ClarityCostFunction::FtSupply, env, 0)?; @@ -963,7 +962,7 @@ pub fn special_burn_token( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::FtBurn, env, 0)?; @@ -1030,7 +1029,7 @@ pub fn special_burn_asset_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::NftBurn, env, 0)?; @@ -1119,7 +1118,7 @@ pub fn special_burn_asset_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::NftBurn, env, 0)?; diff --git a/clarity/src/vm/functions/boolean.rs b/clarity/src/vm/functions/boolean.rs index e692b4ad71..cfab82180d 100644 --- a/clarity/src/vm/functions/boolean.rs +++ b/clarity/src/vm/functions/boolean.rs @@ -17,12 +17,12 @@ use crate::vm::contexts::{Environment, LocalContext}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; -use crate::vm::errors::{check_arguments_at_least, CheckErrors, InterpreterResult as Result}; +use crate::vm::errors::{check_arguments_at_least, CheckErrors, VmExecutionResult}; use crate::vm::eval; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{TypeSignature, Value}; -fn type_force_bool(value: &Value) -> Result { +fn type_force_bool(value: &Value) -> VmExecutionResult { match *value { Value::Bool(boolean) => Ok(boolean), _ => Err(CheckErrors::TypeValueError( @@ -37,7 +37,7 @@ pub fn special_or( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_arguments_at_least(1, args)?; runtime_cost(ClarityCostFunction::Or, env, args.len())?; @@ -57,7 +57,7 @@ pub fn special_and( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_arguments_at_least(1, args)?; runtime_cost(ClarityCostFunction::And, env, args.len())?; @@ -73,7 +73,7 @@ pub fn special_and( Ok(Value::Bool(true)) } -pub fn native_not(input: Value) -> Result { +pub fn native_not(input: Value) -> VmExecutionResult { let value = type_force_bool(&input)?; Ok(Value::Bool(!value)) } diff --git a/clarity/src/vm/functions/conversions.rs b/clarity/src/vm/functions/conversions.rs index bd7834a552..0d6fcbba92 100644 --- a/clarity/src/vm/functions/conversions.rs +++ b/clarity/src/vm/functions/conversions.rs @@ -18,9 +18,7 @@ use clarity_types::types::serialization::SerializationError; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; -use crate::vm::errors::{ - check_argument_count, CheckErrors, InterpreterError, InterpreterResult as Result, -}; +use crate::vm::errors::{check_argument_count, CheckErrors, InterpreterError, VmExecutionResult}; use crate::vm::representations::SymbolicExpression; use crate::vm::types::signatures::TO_ASCII_MAX_BUFF; use crate::vm::types::SequenceSubtype::BufferType; @@ -50,7 +48,7 @@ pub fn buff_to_int_generic( value: Value, direction: EndianDirection, conversion_fn: fn([u8; 16]) -> Value, -) -> Result { +) -> VmExecutionResult { match value { Value::Sequence(SequenceData::Buffer(ref sequence_data)) => { if sequence_data.len()? @@ -94,7 +92,7 @@ pub fn buff_to_int_generic( } } -pub fn native_buff_to_int_le(value: Value) -> Result { +pub fn native_buff_to_int_le(value: Value) -> VmExecutionResult { fn convert_to_int_le(buffer: [u8; 16]) -> Value { let value = i128::from_le_bytes(buffer); Value::Int(value) @@ -102,7 +100,7 @@ pub fn native_buff_to_int_le(value: Value) -> Result { buff_to_int_generic(value, EndianDirection::LittleEndian, convert_to_int_le) } -pub fn native_buff_to_uint_le(value: Value) -> Result { +pub fn native_buff_to_uint_le(value: Value) -> VmExecutionResult { fn convert_to_uint_le(buffer: [u8; 16]) -> Value { let value = u128::from_le_bytes(buffer); Value::UInt(value) @@ -111,7 +109,7 @@ pub fn native_buff_to_uint_le(value: Value) -> Result { buff_to_int_generic(value, EndianDirection::LittleEndian, convert_to_uint_le) } -pub fn native_buff_to_int_be(value: Value) -> Result { +pub fn native_buff_to_int_be(value: Value) -> VmExecutionResult { fn convert_to_int_be(buffer: [u8; 16]) -> Value { let value = i128::from_be_bytes(buffer); Value::Int(value) @@ -119,7 +117,7 @@ pub fn native_buff_to_int_be(value: Value) -> Result { buff_to_int_generic(value, EndianDirection::BigEndian, convert_to_int_be) } -pub fn native_buff_to_uint_be(value: Value) -> Result { +pub fn native_buff_to_uint_be(value: Value) -> VmExecutionResult { fn convert_to_uint_be(buffer: [u8; 16]) -> Value { let value = u128::from_be_bytes(buffer); Value::UInt(value) @@ -133,8 +131,8 @@ pub fn native_buff_to_uint_be(value: Value) -> Result { // either a Int or UInt, depending on the desired result. pub fn native_string_to_int_generic( value: Value, - string_to_value_fn: fn(String) -> Result, -) -> Result { + string_to_value_fn: fn(String) -> VmExecutionResult, +) -> VmExecutionResult { match value { Value::Sequence(SequenceData::String(CharType::ASCII(ASCIIData { data }))) => { match String::from_utf8(data) { @@ -160,7 +158,7 @@ pub fn native_string_to_int_generic( } } -fn safe_convert_string_to_int(raw_string: String) -> Result { +fn safe_convert_string_to_int(raw_string: String) -> VmExecutionResult { let possible_int = raw_string.parse::(); match possible_int { Ok(val) => Value::some(Value::Int(val)), @@ -168,11 +166,11 @@ fn safe_convert_string_to_int(raw_string: String) -> Result { } } -pub fn native_string_to_int(value: Value) -> Result { +pub fn native_string_to_int(value: Value) -> VmExecutionResult { native_string_to_int_generic(value, safe_convert_string_to_int) } -fn safe_convert_string_to_uint(raw_string: String) -> Result { +fn safe_convert_string_to_uint(raw_string: String) -> VmExecutionResult { let possible_int = raw_string.parse::(); match possible_int { Ok(val) => Value::some(Value::UInt(val)), @@ -180,7 +178,7 @@ fn safe_convert_string_to_uint(raw_string: String) -> Result { } } -pub fn native_string_to_uint(value: Value) -> Result { +pub fn native_string_to_uint(value: Value) -> VmExecutionResult { native_string_to_int_generic(value, safe_convert_string_to_uint) } @@ -190,8 +188,8 @@ pub fn native_string_to_uint(value: Value) -> Result { // either an ASCII or UTF8 string, depending on the desired result. pub fn native_int_to_string_generic( value: Value, - bytes_to_value_fn: fn(bytes: Vec) -> Result, -) -> Result { + bytes_to_value_fn: fn(bytes: Vec) -> VmExecutionResult, +) -> VmExecutionResult { match value { Value::Int(ref int_value) => { let as_string = int_value.to_string(); @@ -213,19 +211,19 @@ pub fn native_int_to_string_generic( } } -pub fn native_int_to_ascii(value: Value) -> Result { +pub fn native_int_to_ascii(value: Value) -> VmExecutionResult { // Given an integer, convert this to Clarity ASCII value. native_int_to_string_generic(value, Value::string_ascii_from_bytes) } -pub fn native_int_to_utf8(value: Value) -> Result { +pub fn native_int_to_utf8(value: Value) -> VmExecutionResult { // Given an integer, convert this to Clarity UTF8 value. native_int_to_string_generic(value, Value::string_utf8_from_bytes) } /// Helper function to convert a string to ASCII and wrap in Ok response /// This should only fail due to system errors, not conversion failures -fn convert_string_to_ascii_ok(s: String) -> Result { +fn convert_string_to_ascii_ok(s: String) -> VmExecutionResult { let ascii_value = Value::string_ascii_from_bytes(s.into_bytes()).map_err(|_| { InterpreterError::Expect("Unexpected error converting string to ASCII".into()) })?; @@ -233,7 +231,7 @@ fn convert_string_to_ascii_ok(s: String) -> Result { } /// Helper function for UTF8 conversion that can return err u1 for non-ASCII characters -fn convert_utf8_to_ascii(s: String) -> Result { +fn convert_utf8_to_ascii(s: String) -> VmExecutionResult { match Value::string_ascii_from_bytes(s.into_bytes()) { Ok(ascii_value) => Value::okay(ascii_value), Err(_) => Ok(Value::err_uint(1)), // Non-ASCII characters in UTF8 @@ -244,7 +242,7 @@ pub fn special_to_ascii( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; let value = eval(&args[0], env, context)?; @@ -289,7 +287,7 @@ pub fn special_to_ascii( /// Returns `value` consensus serialized into a `(optional buff)` object. /// If the value cannot fit as serialized into the maximum buffer size, /// this returns `none`, otherwise, it will be `(some consensus-serialized-buffer)` -pub fn to_consensus_buff(value: Value) -> Result { +pub fn to_consensus_buff(value: Value) -> VmExecutionResult { let mut clar_buff_serialized = vec![]; value .serialize_write(&mut clar_buff_serialized) @@ -313,7 +311,7 @@ pub fn from_consensus_buff( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let type_arg = TypeSignature::parse_type_repr(*env.epoch(), &args[0], env)?; diff --git a/clarity/src/vm/functions/crypto.rs b/clarity/src/vm/functions/crypto.rs index 3b5223bd72..44858763f2 100644 --- a/clarity/src/vm/functions/crypto.rs +++ b/clarity/src/vm/functions/crypto.rs @@ -23,16 +23,14 @@ use stacks_common::util::secp256k1::{secp256k1_recover, secp256k1_verify, Secp25 use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; -use crate::vm::errors::{ - check_argument_count, CheckErrors, InterpreterError, InterpreterResult as Result, -}; +use crate::vm::errors::{check_argument_count, CheckErrors, InterpreterError, VmExecutionResult}; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{BuffData, SequenceData, TypeSignature, Value, BUFF_32, BUFF_33, BUFF_65}; use crate::vm::{eval, ClarityVersion, Environment, LocalContext}; macro_rules! native_hash_func { ($name:ident, $module:ty) => { - pub fn $name(input: Value) -> Result { + pub fn $name(input: Value) -> VmExecutionResult { let bytes = match input { Value::Int(value) => Ok(value.to_le_bytes().to_vec()), Value::UInt(value) => Ok(value.to_le_bytes().to_vec()), @@ -60,7 +58,7 @@ native_hash_func!(native_keccak256, hash::Keccak256Hash); // Note: Clarity1 had a bug in how the address is computed (issues/2619). // This method preserves the old, incorrect behavior for those running Clarity1. -fn pubkey_to_address_v1(pub_key: Secp256k1PublicKey) -> Result { +fn pubkey_to_address_v1(pub_key: Secp256k1PublicKey) -> VmExecutionResult { StacksAddress::from_public_keys( C32_ADDRESS_VERSION_TESTNET_SINGLESIG, &AddressHashMode::SerializeP2PKH, @@ -72,7 +70,10 @@ fn pubkey_to_address_v1(pub_key: Secp256k1PublicKey) -> Result { // Note: Clarity1 had a bug in how the address is computed (issues/2619). // This version contains the code for Clarity2 and going forward. -fn pubkey_to_address_v2(pub_key: Secp256k1PublicKey, is_mainnet: bool) -> Result { +fn pubkey_to_address_v2( + pub_key: Secp256k1PublicKey, + is_mainnet: bool, +) -> VmExecutionResult { let network_byte = if is_mainnet { C32_ADDRESS_VERSION_MAINNET_SINGLESIG } else { @@ -91,7 +92,7 @@ pub fn special_principal_of( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (principal-of? (..)) // arg0 => (buff 33) check_argument_count(1, args)?; @@ -137,7 +138,7 @@ pub fn special_secp256k1_recover( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (secp256k1-recover? (..)) // arg0 => (buff 32), arg1 => (buff 65) check_argument_count(2, args)?; @@ -199,7 +200,7 @@ pub fn special_secp256k1_verify( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (secp256k1-verify (..)) // arg0 => (buff 32), arg1 => (buff 65), arg2 => (buff 33) check_argument_count(3, args)?; diff --git a/clarity/src/vm/functions/database.rs b/clarity/src/vm/functions/database.rs index 93fbef0258..ac69f1784e 100644 --- a/clarity/src/vm/functions/database.rs +++ b/clarity/src/vm/functions/database.rs @@ -23,7 +23,7 @@ use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{constants as cost_constants, runtime_cost, CostTracker, MemoryConsumer}; use crate::vm::errors::{ check_argument_count, check_arguments_at_least, CheckErrors, InterpreterError, - InterpreterResult as Result, RuntimeErrorType, + RuntimeErrorType, VmExecutionResult, }; use crate::vm::representations::{SymbolicExpression, SymbolicExpressionType}; use crate::vm::types::{ @@ -61,7 +61,7 @@ pub fn special_contract_call( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_arguments_at_least(2, args)?; // the second part of the contract_call cost (i.e., the load contract cost) @@ -225,7 +225,7 @@ pub fn special_fetch_variable_v200( args: &[SymbolicExpression], env: &mut Environment, _context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; let var_name = args[0].match_atom().ok_or(CheckErrors::ExpectedName)?; @@ -256,7 +256,7 @@ pub fn special_fetch_variable_v205( args: &[SymbolicExpression], env: &mut Environment, _context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; let var_name = args[0].match_atom().ok_or(CheckErrors::ExpectedName)?; @@ -289,7 +289,7 @@ pub fn special_set_variable_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -329,7 +329,7 @@ pub fn special_set_variable_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -370,7 +370,7 @@ pub fn special_fetch_entry_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let map_name = args[0].match_atom().ok_or(CheckErrors::ExpectedName)?; @@ -403,7 +403,7 @@ pub fn special_fetch_entry_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let map_name = args[0].match_atom().ok_or(CheckErrors::ExpectedName)?; @@ -438,7 +438,7 @@ pub fn special_at_block( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; runtime_cost(ClarityCostFunction::AtBlock, env, 0)?; @@ -467,7 +467,7 @@ pub fn special_set_entry_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -510,7 +510,7 @@ pub fn special_set_entry_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -553,7 +553,7 @@ pub fn special_insert_entry_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -597,7 +597,7 @@ pub fn special_insert_entry_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -640,7 +640,7 @@ pub fn special_delete_entry_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -680,7 +680,7 @@ pub fn special_delete_entry_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if env.global_context.is_read_only() { return Err(CheckErrors::WriteAttemptedInReadOnly.into()); } @@ -739,7 +739,7 @@ pub fn special_get_block_info( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (get-block-info? property-name block-height-uint) runtime_cost(ClarityCostFunction::BlockInfo, env, 0)?; @@ -891,7 +891,7 @@ pub fn special_get_burn_block_info( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { runtime_cost(ClarityCostFunction::GetBurnBlockInfo, env, 0)?; check_argument_count(2, args)?; @@ -992,7 +992,7 @@ pub fn special_get_stacks_block_info( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (get-stacks-block-info? property-name block-height-uint) runtime_cost(ClarityCostFunction::BlockInfo, env, 0)?; @@ -1074,7 +1074,7 @@ pub fn special_get_tenure_info( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (get-tenure-info? property-name block-height-uint) runtime_cost(ClarityCostFunction::BlockInfo, env, 0)?; @@ -1172,7 +1172,7 @@ pub fn special_contract_hash( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; let contract_expr = args .first() diff --git a/clarity/src/vm/functions/define.rs b/clarity/src/vm/functions/define.rs index 7fc3ba77b6..2e70e1a325 100644 --- a/clarity/src/vm/functions/define.rs +++ b/clarity/src/vm/functions/define.rs @@ -19,8 +19,8 @@ use std::collections::BTreeMap; use crate::vm::callables::{DefineType, DefinedFunction}; use crate::vm::contexts::{ContractContext, Environment, LocalContext}; use crate::vm::errors::{ - check_argument_count, check_arguments_at_least, CheckErrors, InterpreterResult as Result, - SyntaxBindingErrorType, + check_argument_count, check_arguments_at_least, CheckErrors, SyntaxBindingErrorType, + VmExecutionResult, }; use crate::vm::eval; use crate::vm::representations::SymbolicExpressionType::Field; @@ -108,7 +108,7 @@ pub enum DefineResult { NoDefine, } -fn check_legal_define(name: &str, contract_context: &ContractContext) -> Result<()> { +fn check_legal_define(name: &str, contract_context: &ContractContext) -> VmExecutionResult<()> { if contract_context.is_name_used(name) { Err(CheckErrors::NameAlreadyUsed(name.to_string()).into()) } else { @@ -120,7 +120,7 @@ fn handle_define_variable( variable: &ClarityName, expression: &SymbolicExpression, env: &mut Environment, -) -> Result { +) -> VmExecutionResult { // is the variable name legal? check_legal_define(variable, env.contract_context)?; let context = LocalContext::new(); @@ -133,7 +133,7 @@ fn handle_define_function( expression: &SymbolicExpression, env: &mut Environment, define_type: DefineType, -) -> Result { +) -> VmExecutionResult { let (function_symbol, arg_symbols) = signature .split_first() .ok_or(CheckErrors::DefineFunctionBadSignature)?; @@ -171,7 +171,7 @@ fn handle_define_persisted_variable( value_type: &SymbolicExpression, value: &SymbolicExpression, env: &mut Environment, -) -> Result { +) -> VmExecutionResult { check_legal_define(variable_str, env.contract_context)?; let value_type_signature = TypeSignature::parse_type_repr(*env.epoch(), value_type, env)?; @@ -190,7 +190,7 @@ fn handle_define_nonfungible_asset( asset_name: &ClarityName, key_type: &SymbolicExpression, env: &mut Environment, -) -> Result { +) -> VmExecutionResult { check_legal_define(asset_name, env.contract_context)?; let key_type_signature = TypeSignature::parse_type_repr(*env.epoch(), key_type, env)?; @@ -205,7 +205,7 @@ fn handle_define_fungible_token( asset_name: &ClarityName, total_supply: Option<&SymbolicExpression>, env: &mut Environment, -) -> Result { +) -> VmExecutionResult { check_legal_define(asset_name, env.contract_context)?; if let Some(total_supply_expr) = total_supply { @@ -233,7 +233,7 @@ fn handle_define_map( key_type: &SymbolicExpression, value_type: &SymbolicExpression, env: &mut Environment, -) -> Result { +) -> VmExecutionResult { check_legal_define(map_str, env.contract_context)?; let key_type_signature = TypeSignature::parse_type_repr(*env.epoch(), key_type, env)?; @@ -250,7 +250,7 @@ fn handle_define_trait( name: &ClarityName, functions: &[SymbolicExpression], env: &mut Environment, -) -> Result { +) -> VmExecutionResult { check_legal_define(name, env.contract_context)?; let trait_signature = TypeSignature::parse_trait_type_repr( @@ -288,7 +288,7 @@ impl<'a> DefineFunctionsParsed<'a> { /// a define-statement, returns None if the supplied expression is not a define. pub fn try_parse( expression: &'a SymbolicExpression, - ) -> std::result::Result>, CheckErrors> { + ) -> Result>, CheckErrors> { let (define_type, args) = match DefineFunctions::try_parse(expression) { Some(x) => x, None => return Ok(None), @@ -408,7 +408,7 @@ impl<'a> DefineFunctionsParsed<'a> { pub fn evaluate_define( expression: &SymbolicExpression, env: &mut Environment, -) -> Result { +) -> VmExecutionResult { if let Some(define_type) = DefineFunctionsParsed::try_parse(expression)? { match define_type { DefineFunctionsParsed::Constant { name, value } => { diff --git a/clarity/src/vm/functions/mod.rs b/clarity/src/vm/functions/mod.rs index f458c282e6..bac0cd5afa 100644 --- a/clarity/src/vm/functions/mod.rs +++ b/clarity/src/vm/functions/mod.rs @@ -20,8 +20,8 @@ use crate::vm::callables::{cost_input_sized_vararg, CallableType, NativeHandle}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{constants as cost_constants, runtime_cost, CostTracker, MemoryConsumer}; use crate::vm::errors::{ - check_argument_count, check_arguments_at_least, CheckErrors, Error, - InterpreterResult as Result, ShortReturnType, SyntaxBindingError, SyntaxBindingErrorType, + check_argument_count, check_arguments_at_least, CheckErrors, Error, ShortReturnType, + SyntaxBindingError, SyntaxBindingErrorType, VmExecutionResult, }; pub use crate::vm::functions::assets::stx_transfer_consolidated; use crate::vm::representations::{ClarityName, SymbolicExpression, SymbolicExpressionType}; @@ -35,7 +35,7 @@ macro_rules! switch_on_global_epoch { args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, - ) -> Result { + ) -> VmExecutionResult { match env.epoch() { StacksEpochId::Epoch10 => { panic!("Executing Clarity method during Epoch 1.0, before Clarity") @@ -572,7 +572,7 @@ pub fn lookup_reserved_functions(name: &str, version: &ClarityVersion) -> Option } } -fn native_eq(args: Vec, env: &mut Environment) -> Result { +fn native_eq(args: Vec, env: &mut Environment) -> VmExecutionResult { // TODO: this currently uses the derived equality checks of Value, // however, that's probably not how we want to implement equality // checks on the ::ListTypes @@ -597,7 +597,7 @@ fn native_eq(args: Vec, env: &mut Environment) -> Result { } } -fn native_begin(mut args: Vec) -> Result { +fn native_begin(mut args: Vec) -> VmExecutionResult { match args.pop() { Some(v) => Ok(v), None => Err(CheckErrors::RequiresAtLeastArguments(1, 0).into()), @@ -608,7 +608,7 @@ fn special_print( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { let arg = args.first().ok_or_else(|| { InterpreterError::BadSymbolicRepresentation("Print should have an argument".into()) })?; @@ -628,7 +628,7 @@ fn special_if( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::If, env, 0)?; @@ -654,7 +654,7 @@ fn special_asserts( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; runtime_cost(ClarityCostFunction::Asserts, env, 0)?; @@ -682,9 +682,9 @@ pub fn handle_binding_list( bindings: &[SymbolicExpression], binding_error_type: SyntaxBindingErrorType, mut handler: F, -) -> std::result::Result<(), E> +) -> Result<(), E> where - F: FnMut(&ClarityName, &SymbolicExpression) -> std::result::Result<(), E>, + F: FnMut(&ClarityName, &SymbolicExpression) -> Result<(), E>, E: for<'a> From<(CheckErrors, &'a SymbolicExpression)>, { for (i, binding) in bindings.iter().enumerate() { @@ -719,7 +719,7 @@ pub fn parse_eval_bindings( binding_error_type: SyntaxBindingErrorType, env: &mut Environment, context: &LocalContext, -) -> Result> { +) -> VmExecutionResult> { let mut result = Vec::with_capacity(bindings.len()); handle_binding_list(bindings, binding_error_type, |var_name, var_sexp| { eval(var_sexp, env, context).map(|value| result.push((var_name.clone(), value))) @@ -732,7 +732,7 @@ fn special_let( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (let ((x 1) (y 2)) (+ x y)) -> 3 // arg0 => binding list // arg1..n => body @@ -785,7 +785,7 @@ fn special_as_contract( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (as-contract (..)) // arg0 => body check_argument_count(1, args)?; @@ -812,7 +812,7 @@ fn special_contract_of( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (contract-of (..)) // arg0 => trait check_argument_count(1, args)?; diff --git a/clarity/src/vm/functions/options.rs b/clarity/src/vm/functions/options.rs index c47dae91cc..0762743b0d 100644 --- a/clarity/src/vm/functions/options.rs +++ b/clarity/src/vm/functions/options.rs @@ -18,14 +18,14 @@ use crate::vm::contexts::{Environment, LocalContext}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{runtime_cost, CostTracker, MemoryConsumer}; use crate::vm::errors::{ - check_arguments_at_least, CheckErrors, InterpreterError, InterpreterResult as Result, - RuntimeErrorType, ShortReturnType, + check_arguments_at_least, CheckErrors, InterpreterError, RuntimeErrorType, ShortReturnType, + VmExecutionResult, }; use crate::vm::types::{CallableData, OptionalData, ResponseData, TypeSignature, Value}; use crate::vm::Value::CallableContract; use crate::vm::{self, ClarityName, ClarityVersion, SymbolicExpression}; -fn inner_unwrap(to_unwrap: Value) -> Result> { +fn inner_unwrap(to_unwrap: Value) -> VmExecutionResult> { let result = match to_unwrap { Value::Optional(data) => data.data.map(|data| *data), Value::Response(data) => { @@ -41,7 +41,7 @@ fn inner_unwrap(to_unwrap: Value) -> Result> { Ok(result) } -fn inner_unwrap_err(to_unwrap: Value) -> Result> { +fn inner_unwrap_err(to_unwrap: Value) -> VmExecutionResult> { let result = match to_unwrap { Value::Response(data) => { if !data.committed { @@ -56,35 +56,35 @@ fn inner_unwrap_err(to_unwrap: Value) -> Result> { Ok(result) } -pub fn native_unwrap(input: Value) -> Result { +pub fn native_unwrap(input: Value) -> VmExecutionResult { inner_unwrap(input).and_then(|opt_value| match opt_value { Some(v) => Ok(v), None => Err(RuntimeErrorType::UnwrapFailure.into()), }) } -pub fn native_unwrap_or_ret(input: Value, thrown: Value) -> Result { +pub fn native_unwrap_or_ret(input: Value, thrown: Value) -> VmExecutionResult { inner_unwrap(input).and_then(|opt_value| match opt_value { Some(v) => Ok(v), None => Err(ShortReturnType::ExpectedValue(Box::new(thrown)).into()), }) } -pub fn native_unwrap_err(input: Value) -> Result { +pub fn native_unwrap_err(input: Value) -> VmExecutionResult { inner_unwrap_err(input).and_then(|opt_value| match opt_value { Some(v) => Ok(v), None => Err(RuntimeErrorType::UnwrapFailure.into()), }) } -pub fn native_unwrap_err_or_ret(input: Value, thrown: Value) -> Result { +pub fn native_unwrap_err_or_ret(input: Value, thrown: Value) -> VmExecutionResult { inner_unwrap_err(input).and_then(|opt_value| match opt_value { Some(v) => Ok(v), None => Err(ShortReturnType::ExpectedValue(Box::new(thrown)).into()), }) } -pub fn native_try_ret(input: Value) -> Result { +pub fn native_try_ret(input: Value) -> VmExecutionResult { match input { Value::Optional(data) => match data.data { Some(data) => Ok(*data), @@ -112,7 +112,7 @@ fn eval_with_new_binding( bind_value: Value, env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { let mut inner_context = context.extend()?; if vm::is_reserved(&bind_name, env.contract_context.get_clarity_version()) || env.contract_context.lookup_function(&bind_name).is_some() @@ -148,7 +148,7 @@ fn special_match_opt( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if args.len() != 3 { Err(CheckErrors::BadMatchOptionSyntax(Box::new( CheckErrors::IncorrectArgumentCount(4, args.len() + 1), @@ -173,7 +173,7 @@ fn special_match_resp( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { if args.len() != 4 { Err(CheckErrors::BadMatchResponseSyntax(Box::new( CheckErrors::IncorrectArgumentCount(5, args.len() + 1), @@ -202,7 +202,7 @@ pub fn special_match( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_arguments_at_least(1, args)?; let input = vm::eval(&args[0], env, context)?; @@ -216,49 +216,49 @@ pub fn special_match( } } -pub fn native_some(input: Value) -> Result { +pub fn native_some(input: Value) -> VmExecutionResult { Value::some(input) } -fn is_some(input: Value) -> Result { +fn is_some(input: Value) -> VmExecutionResult { match input { Value::Optional(ref data) => Ok(data.data.is_some()), _ => Err(CheckErrors::ExpectedOptionalValue(Box::new(input)).into()), } } -fn is_okay(input: Value) -> Result { +fn is_okay(input: Value) -> VmExecutionResult { match input { Value::Response(data) => Ok(data.committed), _ => Err(CheckErrors::ExpectedResponseValue(Box::new(input)).into()), } } -pub fn native_is_some(input: Value) -> Result { +pub fn native_is_some(input: Value) -> VmExecutionResult { is_some(input).map(Value::Bool) } -pub fn native_is_none(input: Value) -> Result { +pub fn native_is_none(input: Value) -> VmExecutionResult { is_some(input).map(|is_some| Value::Bool(!is_some)) } -pub fn native_is_okay(input: Value) -> Result { +pub fn native_is_okay(input: Value) -> VmExecutionResult { is_okay(input).map(Value::Bool) } -pub fn native_is_err(input: Value) -> Result { +pub fn native_is_err(input: Value) -> VmExecutionResult { is_okay(input).map(|is_ok| Value::Bool(!is_ok)) } -pub fn native_okay(input: Value) -> Result { +pub fn native_okay(input: Value) -> VmExecutionResult { Value::okay(input) } -pub fn native_error(input: Value) -> Result { +pub fn native_error(input: Value) -> VmExecutionResult { Value::error(input) } -pub fn native_default_to(default: Value, input: Value) -> Result { +pub fn native_default_to(default: Value, input: Value) -> VmExecutionResult { match input { Value::Optional(data) => match data.data { Some(data) => Ok(*data), diff --git a/clarity/src/vm/functions/principals.rs b/clarity/src/vm/functions/principals.rs index 51fc33136f..3f183b42a2 100644 --- a/clarity/src/vm/functions/principals.rs +++ b/clarity/src/vm/functions/principals.rs @@ -8,7 +8,7 @@ use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; use crate::vm::errors::{ check_argument_count, check_arguments_at_least, check_arguments_at_most, CheckErrors, - InterpreterError, InterpreterResult as Result, + InterpreterError, VmExecutionResult, }; use crate::vm::representations::{ SymbolicExpression, CONTRACT_MAX_NAME_LENGTH, CONTRACT_MIN_NAME_LENGTH, @@ -53,7 +53,7 @@ pub fn special_is_standard( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; runtime_cost(ClarityCostFunction::IsStandard, env, 0)?; let owner = eval(&args[0], env, context)?; @@ -80,7 +80,7 @@ fn create_principal_destruct_tuple( version: u8, hash_bytes: &[u8; 20], name_opt: Option, -) -> Result { +) -> VmExecutionResult { Ok(Value::Tuple( TupleData::from_data(vec![ ( @@ -110,7 +110,9 @@ fn create_principal_destruct_tuple( /// /// The response is an error Response, where the `err` value is a tuple `{error_code, parse_tuple}`. /// `error_int` is of type `UInt`, `parse_tuple` is None. -fn create_principal_true_error_response(error_int: PrincipalConstructErrorCode) -> Result { +fn create_principal_true_error_response( + error_int: PrincipalConstructErrorCode, +) -> VmExecutionResult { Value::error(Value::Tuple( TupleData::from_data(vec![ ("error_code".into(), Value::UInt(error_int as u128)), @@ -131,7 +133,7 @@ fn create_principal_true_error_response(error_int: PrincipalConstructErrorCode) fn create_principal_value_error_response( error_int: PrincipalConstructErrorCode, value: Value, -) -> Result { +) -> VmExecutionResult { Value::error(Value::Tuple( TupleData::from_data(vec![ ("error_code".into(), Value::UInt(error_int as u128)), @@ -153,7 +155,7 @@ pub fn special_principal_destruct( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(1, args)?; runtime_cost(ClarityCostFunction::PrincipalDestruct, env, 0)?; @@ -192,7 +194,7 @@ pub fn special_principal_construct( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_arguments_at_least(2, args)?; check_arguments_at_most(3, args)?; runtime_cost(ClarityCostFunction::PrincipalConstruct, env, 0)?; diff --git a/clarity/src/vm/functions/sequences.rs b/clarity/src/vm/functions/sequences.rs index cafc795d36..2e853d8404 100644 --- a/clarity/src/vm/functions/sequences.rs +++ b/clarity/src/vm/functions/sequences.rs @@ -21,8 +21,8 @@ use stacks_common::types::StacksEpochId; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::{runtime_cost, CostOverflowingMath}; use crate::vm::errors::{ - check_argument_count, check_arguments_at_least, CheckErrors, InterpreterResult as Result, - RuntimeErrorType, + check_argument_count, check_arguments_at_least, CheckErrors, RuntimeErrorType, + VmExecutionResult, }; use crate::vm::representations::SymbolicExpression; use crate::vm::types::signatures::ListTypeData; @@ -34,8 +34,9 @@ pub fn list_cons( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { - let eval_tried: Result> = args.iter().map(|x| eval(x, env, context)).collect(); +) -> VmExecutionResult { + let eval_tried: VmExecutionResult> = + args.iter().map(|x| eval(x, env, context)).collect(); let args = eval_tried?; let mut arg_size = 0; @@ -52,7 +53,7 @@ pub fn special_filter( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; runtime_cost(ClarityCostFunction::Filter, env, 0)?; @@ -90,7 +91,7 @@ pub fn special_fold( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; runtime_cost(ClarityCostFunction::Fold, env, 0)?; @@ -123,7 +124,7 @@ pub fn special_map( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_arguments_at_least(2, args)?; runtime_cost(ClarityCostFunction::Map, env, args.len())?; @@ -184,7 +185,7 @@ pub fn special_append( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let sequence = eval(&args[0], env, context)?; @@ -232,7 +233,7 @@ pub fn special_concat_v200( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let mut wrapped_seq = eval(&args[0], env, context)?; @@ -258,7 +259,7 @@ pub fn special_concat_v205( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let mut wrapped_seq = eval(&args[0], env, context)?; @@ -287,7 +288,7 @@ pub fn special_as_max_len( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(2, args)?; let mut sequence = eval(&args[0], env, context)?; @@ -322,7 +323,7 @@ pub fn special_as_max_len( } } -pub fn native_len(sequence: Value) -> Result { +pub fn native_len(sequence: Value) -> VmExecutionResult { match sequence { Value::Sequence(sequence_data) => Ok(Value::UInt(sequence_data.len() as u128)), _ => { @@ -331,7 +332,7 @@ pub fn native_len(sequence: Value) -> Result { } } -pub fn native_index_of(sequence: Value, to_find: Value) -> Result { +pub fn native_index_of(sequence: Value, to_find: Value) -> VmExecutionResult { if let Value::Sequence(sequence_data) = sequence { match sequence_data.contains(to_find)? { Some(index) => Value::some(Value::UInt(index as u128)), @@ -342,7 +343,7 @@ pub fn native_index_of(sequence: Value, to_find: Value) -> Result { } } -pub fn native_element_at(sequence: Value, index: Value) -> Result { +pub fn native_element_at(sequence: Value, index: Value) -> VmExecutionResult { let sequence_data = if let Value::Sequence(sequence_data) = sequence { sequence_data } else { @@ -377,7 +378,7 @@ pub fn special_slice( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; let seq = eval(&args[0], env, context)?; @@ -427,7 +428,7 @@ pub fn special_replace_at( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { check_argument_count(3, args)?; let seq = eval(&args[0], env, context)?; diff --git a/clarity/src/vm/functions/tuples.rs b/clarity/src/vm/functions/tuples.rs index 7db8f13959..163fdbb1a7 100644 --- a/clarity/src/vm/functions/tuples.rs +++ b/clarity/src/vm/functions/tuples.rs @@ -17,7 +17,7 @@ use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; use crate::vm::errors::{ check_argument_count, check_arguments_at_least, CheckErrors, InterpreterError, - InterpreterResult as Result, SyntaxBindingErrorType, + SyntaxBindingErrorType, VmExecutionResult, }; use crate::vm::representations::SymbolicExpression; use crate::vm::types::{TupleData, TypeSignature, Value}; @@ -27,7 +27,7 @@ pub fn tuple_cons( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (tuple (arg-name value) // (arg-name value)) use super::parse_eval_bindings; @@ -44,7 +44,7 @@ pub fn tuple_get( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { // (get arg-name (tuple ...)) // if the tuple argument is an option type, then return option(field-name). check_argument_count(2, args)?; @@ -82,7 +82,7 @@ pub fn tuple_get( } } -pub fn tuple_merge(base: Value, update: Value) -> Result { +pub fn tuple_merge(base: Value, update: Value) -> VmExecutionResult { let initial_values = match base { Value::Tuple(initial_values) => Ok(initial_values), _ => Err(CheckErrors::ExpectedTuple(Box::new( diff --git a/clarity/src/vm/mod.rs b/clarity/src/vm/mod.rs index 781c7d4d7b..65f2de8ad5 100644 --- a/clarity/src/vm/mod.rs +++ b/clarity/src/vm/mod.rs @@ -73,7 +73,7 @@ use crate::vm::costs::{ // publish the non-generic StacksEpoch form for use throughout module pub use crate::vm::database::clarity_db::StacksEpoch; use crate::vm::errors::{ - CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType, + CheckErrors, Error, InterpreterError, RuntimeErrorType, VmExecutionResult, }; use crate::vm::events::StacksTransactionEvent; use crate::vm::functions::define::DefineResult; @@ -155,14 +155,18 @@ pub trait EvalHook { _env: &mut Environment, _context: &LocalContext, _expr: &SymbolicExpression, - _res: &core::result::Result, + _res: &VmExecutionResult, ); // Called upon completion of the execution - fn did_complete(&mut self, _result: core::result::Result<&mut ExecutionResult, String>); + fn did_complete(&mut self, _result: Result<&mut ExecutionResult, String>); } -fn lookup_variable(name: &str, context: &LocalContext, env: &mut Environment) -> Result { +fn lookup_variable( + name: &str, + context: &LocalContext, + env: &mut Environment, +) -> VmExecutionResult { if name.starts_with(char::is_numeric) || name.starts_with('\'') { Err(InterpreterError::BadSymbolicRepresentation(format!( "Unexpected variable name: {name}" @@ -197,7 +201,7 @@ fn lookup_variable(name: &str, context: &LocalContext, env: &mut Environment) -> } } -pub fn lookup_function(name: &str, env: &mut Environment) -> Result { +pub fn lookup_function(name: &str, env: &mut Environment) -> VmExecutionResult { runtime_cost(ClarityCostFunction::LookupFunction, env, 0)?; if let Some(result) = @@ -213,7 +217,7 @@ pub fn lookup_function(name: &str, env: &mut Environment) -> Result, env: &Environment) { +fn add_stack_trace(result: &mut VmExecutionResult, env: &Environment) { if let Err(Error::Runtime(_, ref mut stack_trace)) = result { if stack_trace.is_none() { stack_trace.replace(env.call_stack.make_stack_trace()); @@ -226,7 +230,7 @@ pub fn apply( args: &[SymbolicExpression], env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { let identifier = function.get_identifier(); // Aaron: in non-debug executions, we shouldn't track a full call-stack. // only enough to do recursion detection. @@ -301,7 +305,7 @@ pub fn apply( } } -fn check_max_execution_time_expired(global_context: &GlobalContext) -> Result<()> { +fn check_max_execution_time_expired(global_context: &GlobalContext) -> VmExecutionResult<()> { match global_context.execution_time_tracker { ExecutionTimeTracker::NoTracking => Ok(()), ExecutionTimeTracker::MaxTime { @@ -321,7 +325,7 @@ pub fn eval( exp: &SymbolicExpression, env: &mut Environment, context: &LocalContext, -) -> Result { +) -> VmExecutionResult { use crate::vm::representations::SymbolicExpressionType::{ Atom, AtomValue, Field, List, LiteralValue, TraitReference, }; @@ -380,7 +384,7 @@ pub fn eval_all( contract_context: &mut ContractContext, global_context: &mut GlobalContext, sponsor: Option, -) -> Result> { +) -> VmExecutionResult> { let mut last_executed = None; let context = LocalContext::new(); let mut total_memory_use = 0; @@ -492,7 +496,7 @@ pub fn eval_all( /// This method executes the program in Epoch 2.0 *and* Epoch 2.05 and asserts /// that the result is the same before returning the result #[cfg(any(test, feature = "testing"))] -pub fn execute_on_network(program: &str, use_mainnet: bool) -> Result> { +pub fn execute_on_network(program: &str, use_mainnet: bool) -> VmExecutionResult> { let epoch_200_result = execute_with_parameters( program, ClarityVersion::Clarity2, @@ -524,9 +528,9 @@ pub fn execute_with_parameters_and_call_in_global_context( ast_rules: ast::ASTRules, use_mainnet: bool, mut global_context_function: F, -) -> Result> +) -> VmExecutionResult> where - F: FnMut(&mut GlobalContext) -> Result<()>, + F: FnMut(&mut GlobalContext) -> VmExecutionResult<()>, { use crate::vm::database::MemoryBackingStore; use crate::vm::tests::test_only_mainnet_to_chain_id; @@ -566,7 +570,7 @@ pub fn execute_with_parameters( epoch: StacksEpochId, ast_rules: ast::ASTRules, use_mainnet: bool, -) -> Result> { +) -> VmExecutionResult> { execute_with_parameters_and_call_in_global_context( program, clarity_version, @@ -579,7 +583,10 @@ pub fn execute_with_parameters( /// Execute for test with `version`, Epoch20, testnet. #[cfg(any(test, feature = "testing"))] -pub fn execute_against_version(program: &str, version: ClarityVersion) -> Result> { +pub fn execute_against_version( + program: &str, + version: ClarityVersion, +) -> VmExecutionResult> { execute_with_parameters( program, version, @@ -591,7 +598,7 @@ pub fn execute_against_version(program: &str, version: ClarityVersion) -> Result /// Execute for test in Clarity1, Epoch20, testnet. #[cfg(any(test, feature = "testing"))] -pub fn execute(program: &str) -> Result> { +pub fn execute(program: &str) -> VmExecutionResult> { execute_with_parameters( program, ClarityVersion::Clarity1, @@ -606,7 +613,7 @@ pub fn execute(program: &str) -> Result> { pub fn execute_with_limited_execution_time( program: &str, max_execution_time: std::time::Duration, -) -> Result> { +) -> VmExecutionResult> { execute_with_parameters_and_call_in_global_context( program, ClarityVersion::Clarity1, @@ -622,7 +629,7 @@ pub fn execute_with_limited_execution_time( /// Execute for test in Clarity2, Epoch21, testnet. #[cfg(any(test, feature = "testing"))] -pub fn execute_v2(program: &str) -> Result> { +pub fn execute_v2(program: &str) -> VmExecutionResult> { execute_with_parameters( program, ClarityVersion::Clarity2, diff --git a/clarity/src/vm/variables.rs b/clarity/src/vm/variables.rs index cb84336dc9..2d8ae71687 100644 --- a/clarity/src/vm/variables.rs +++ b/clarity/src/vm/variables.rs @@ -21,7 +21,7 @@ use super::errors::InterpreterError; use crate::vm::contexts::{Environment, LocalContext}; use crate::vm::costs::cost_functions::ClarityCostFunction; use crate::vm::costs::runtime_cost; -use crate::vm::errors::{InterpreterResult as Result, RuntimeErrorType}; +use crate::vm::errors::{RuntimeErrorType, VmExecutionResult}; use crate::vm::types::Value; use crate::vm::ClarityVersion; @@ -52,7 +52,7 @@ pub fn lookup_reserved_variable( name: &str, _context: &LocalContext, env: &mut Environment, -) -> Result> { +) -> VmExecutionResult> { if let Some(variable) = NativeVariables::lookup_by_name_at_version(name, env.contract_context.get_clarity_version()) { diff --git a/stackslib/src/clarity_cli.rs b/stackslib/src/clarity_cli.rs index 7caa21903d..18b7a4b50b 100644 --- a/stackslib/src/clarity_cli.rs +++ b/stackslib/src/clarity_cli.rs @@ -51,7 +51,7 @@ use crate::clarity::vm::costs::{ExecutionCost, LimitedCostTracker}; use crate::clarity::vm::database::{ BurnStateDB, ClarityDatabase, HeadersDB, STXBalance, NULL_BURN_STATE_DB, }; -use crate::clarity::vm::errors::{Error, InterpreterResult, RuntimeErrorType}; +use crate::clarity::vm::errors::{Error, RuntimeErrorType, VmExecutionResult}; use crate::clarity::vm::types::{PrincipalData, QualifiedContractIdentifier}; use crate::clarity::vm::{ analysis, ast, eval_all, ClarityVersion, ContractContext, ContractName, SymbolicExpression, @@ -879,7 +879,7 @@ fn install_boot_code(header_db: &CLIHeadersDB, marf: &mut C) None, None, |env| { - let res: InterpreterResult<_> = Ok(env + let res: VmExecutionResult<_> = Ok(env .global_context .database .set_clarity_epoch_version(DEFAULT_CLI_EPOCH)); diff --git a/stackslib/src/clarity_vm/clarity.rs b/stackslib/src/clarity_vm/clarity.rs index 342a698ecd..900c567ef7 100644 --- a/stackslib/src/clarity_vm/clarity.rs +++ b/stackslib/src/clarity_vm/clarity.rs @@ -28,7 +28,7 @@ use clarity::vm::database::{ BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, RollbackWrapper, RollbackWrapperPersistedLog, STXBalance, NULL_BURN_STATE_DB, NULL_HEADER_DB, }; -use clarity::vm::errors::{Error as InterpreterError, InterpreterResult}; +use clarity::vm::errors::{Error as InterpreterError, VmExecutionResult}; use clarity::vm::events::{STXEventType, STXMintEventData}; use clarity::vm::representations::SymbolicExpression; use clarity::vm::types::{PrincipalData, QualifiedContractIdentifier, Value}; @@ -187,7 +187,7 @@ pub trait ClarityMarfStoreTransaction { /// It can later be deleted via `drop_metadata_for()` if given the same taret. /// Returns Ok(()) on success /// Returns Err(..) on error - fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()>; + fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()>; /// Drop metadata for a particular block trie that was stored previously via `commit_metadata_to()`. /// This function is idempotent. @@ -195,7 +195,7 @@ pub trait ClarityMarfStoreTransaction { /// Returns Ok(()) if the metadata for the trie identified by `target` was dropped. /// It will be possible to insert it again afterwards. /// Returns Err(..) if the metadata was not successfully dropped. - fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()>; + fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()>; /// Compute the ID of the trie being built. /// In Stacks, this will only be called once all key/value pairs are inserted (and will only be @@ -212,7 +212,7 @@ pub trait ClarityMarfStoreTransaction { /// Returns Ok(()) on successful deletion of the data /// Returns Err(..) if the deletion failed (this usually isn't recoverable, but recovery is up /// to the caller) - fn drop_unconfirmed(self) -> InterpreterResult<()>; + fn drop_unconfirmed(self) -> VmExecutionResult<()>; /// Store the processed block's trie that this transaction was creating. /// The trie's ID must be `target`, so that subsequent tries can be built on it (and so that @@ -221,7 +221,7 @@ pub trait ClarityMarfStoreTransaction { /// /// Returns Ok(()) if the block trie was successfully persisted. /// Returns Err(..) if there was an error in trying to persist this block trie. - fn commit_to_processed_block(self, target: &StacksBlockId) -> InterpreterResult<()>; + fn commit_to_processed_block(self, target: &StacksBlockId) -> VmExecutionResult<()>; /// Store a mined block's trie that this transaction was creating. /// This function is distinct from `commit_to_processed_block()` in that the stored block will @@ -230,7 +230,7 @@ pub trait ClarityMarfStoreTransaction { /// /// Returns Ok(()) if the block trie was successfully persisted. /// Returns Err(..) if there was an error trying to persist this MARF trie. - fn commit_to_mined_block(self, target: &StacksBlockId) -> InterpreterResult<()>; + fn commit_to_mined_block(self, target: &StacksBlockId) -> VmExecutionResult<()>; /// Persist the unconfirmed state trie so that other parts of the Stacks node can read from it /// (such as to handle pending transactions or process RPC requests on it). diff --git a/stackslib/src/clarity_vm/database/ephemeral.rs b/stackslib/src/clarity_vm/database/ephemeral.rs index eb6ac7ce53..ae44d6265c 100644 --- a/stackslib/src/clarity_vm/database/ephemeral.rs +++ b/stackslib/src/clarity_vm/database/ephemeral.rs @@ -21,7 +21,7 @@ use clarity::vm::database::sqlite::{ sqlite_insert_metadata, }; use clarity::vm::database::{ClarityBackingStore, SpecialCaseHandler, SqliteConnection}; -use clarity::vm::errors::{InterpreterError, InterpreterResult, RuntimeErrorType}; +use clarity::vm::errors::{InterpreterError, RuntimeErrorType, VmExecutionResult}; use clarity::vm::types::QualifiedContractIdentifier; use rusqlite; use rusqlite::Connection; @@ -68,7 +68,7 @@ impl ClarityMarfStoreTransaction for EphemeralMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()> { if let Some(tip) = self.ephemeral_marf.get_open_chain_tip() { self.teardown_views(); let res = @@ -86,7 +86,7 @@ impl ClarityMarfStoreTransaction for EphemeralMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()> { self.teardown_views(); let res = SqliteConnection::drop_metadata(self.ephemeral_marf.sqlite_tx(), target); self.setup_views(); @@ -112,7 +112,7 @@ impl ClarityMarfStoreTransaction for EphemeralMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn drop_unconfirmed(mut self) -> InterpreterResult<()> { + fn drop_unconfirmed(mut self) -> VmExecutionResult<()> { if let Some(tip) = self.ephemeral_marf.get_open_chain_tip().cloned() { debug!("Drop unconfirmed MARF trie {}", tip); self.drop_metadata_for_trie(&tip)?; @@ -128,7 +128,7 @@ impl ClarityMarfStoreTransaction for EphemeralMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn commit_to_processed_block(mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_to_processed_block(mut self, target: &StacksBlockId) -> VmExecutionResult<()> { if self.ephemeral_marf.get_open_chain_tip().is_some() { self.commit_metadata_for_trie(target)?; let _ = self.ephemeral_marf.commit_to(target).map_err(|e| { @@ -146,7 +146,7 @@ impl ClarityMarfStoreTransaction for EphemeralMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn commit_to_mined_block(mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_to_mined_block(mut self, target: &StacksBlockId) -> VmExecutionResult<()> { if let Some(tip) = self.ephemeral_marf.get_open_chain_tip().cloned() { // rollback the side_store // the side_store shouldn't commit data for blocks that won't be @@ -313,8 +313,8 @@ impl<'a> EphemeralMarfStore<'a> { } } - /// Helper function to cast a Result, Error> into InterpreterResult> - fn handle_marf_result(res: Result, Error>) -> InterpreterResult> { + /// Helper function to cast a Result, Error> into VmExecutionResult> + fn handle_marf_result(res: Result, Error>) -> VmExecutionResult> { match res { Ok(result_opt) => Ok(result_opt), Err(Error::NotFoundError) => { @@ -340,14 +340,14 @@ impl<'a> EphemeralMarfStore<'a> { key: Key, tx_getter: TxGetter, marf_getter: MarfGetter, - ) -> InterpreterResult> + ) -> VmExecutionResult> where TxGetter: FnOnce( &mut MarfTransaction, &StacksBlockId, Key, - ) -> InterpreterResult>, - MarfGetter: FnOnce(&mut ReadOnlyMarfStore, Key) -> InterpreterResult>, + ) -> VmExecutionResult>, + MarfGetter: FnOnce(&mut ReadOnlyMarfStore, Key) -> VmExecutionResult>, Key: std::fmt::Debug + Copy, { let value_opt = if let EphemeralTip::RAM(tip) = &self.open_tip { @@ -378,7 +378,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { /// Returns Ok(old-chain-tip) on success. /// Returns Err(..) if the given chain tip does not exist or is on a different fork (e.g. is /// not an ancestor of this struct's tip). - fn set_block_hash(&mut self, bhh: StacksBlockId) -> InterpreterResult { + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult { if self.is_ephemeral_tip(&bhh)? { // open the disk-backed MARF to the base tip, so we can carry out reads on disk-backed // data in the event that a read on a key is `None` for the ephemeral MARF. @@ -427,7 +427,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { /// Returns Ok(Some(value)) if the key was mapped to the given value at the opened chain tip. /// Returns Ok(None) if the key was not mapped to the given value at the opened chain tip. /// Returns Err(..) on all other failures. - fn get_data(&mut self, key: &str) -> InterpreterResult> { + fn get_data(&mut self, key: &str) -> VmExecutionResult> { trace!( "Ephemeral MarfedKV get_data: {key:?} tip={:?}", &self.open_tip @@ -455,7 +455,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { /// Returns Ok(Some(value)) if the key was mapped to the given value at the opeend chain tip. /// Returns Ok(None) if the key was not mapped to the given value at the opened chain tip. /// Returns Err(..) on all other failures - fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult> { + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult> { trace!( "Ephemeral MarfedKV get_from_hash: {:?} tip={:?}", hash, @@ -492,7 +492,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { /// Returns Ok(Some(value)) if the key was mapped to the given value at the opened chain tip. /// Returns Ok(None) if the key was not mapped to the given value at the opened chain tip. /// Returns Err(..) on all other failures - fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult)>> { + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> { trace!( "Ephemeral MarfedKV get_data_with_proof: '{}' tip={:?}", key, @@ -527,7 +527,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { fn get_data_with_proof_from_path( &mut self, hash: &TrieHash, - ) -> InterpreterResult)>> { + ) -> VmExecutionResult)>> { trace!( "Ephemeral MarfedKV get_data_with_proof_from_hash: {:?} tip={:?}", hash, @@ -676,7 +676,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { /// Write all (key, value) pairs to the ephemeral MARF. /// Returns Ok(()) on success /// Returns Err(..) on inner MARF errors. - fn put_all_data(&mut self, items: Vec<(String, String)>) -> InterpreterResult<()> { + fn put_all_data(&mut self, items: Vec<(String, String)>) -> VmExecutionResult<()> { let mut keys = Vec::with_capacity(items.len()); let mut values = Vec::with_capacity(items.len()); @@ -721,7 +721,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> InterpreterResult<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { sqlite_get_contract_hash(self, contract) } @@ -736,7 +736,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { contract: &QualifiedContractIdentifier, key: &str, value: &str, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { self.teardown_views(); let res = sqlite_insert_metadata(self, contract, key, value); self.setup_views(); @@ -752,7 +752,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata(self, contract, key) } @@ -766,7 +766,7 @@ impl ClarityBackingStore for EphemeralMarfStore<'_> { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata_manual(self, at_height, contract, key) } } diff --git a/stackslib/src/clarity_vm/database/marf.rs b/stackslib/src/clarity_vm/database/marf.rs index c5832fda6a..0057d6eaff 100644 --- a/stackslib/src/clarity_vm/database/marf.rs +++ b/stackslib/src/clarity_vm/database/marf.rs @@ -25,7 +25,7 @@ use clarity::vm::database::sqlite::{ }; use clarity::vm::database::{ClarityBackingStore, SpecialCaseHandler, SqliteConnection}; use clarity::vm::errors::{ - IncomparableError, InterpreterError, InterpreterResult, RuntimeErrorType, + IncomparableError, InterpreterError, RuntimeErrorType, VmExecutionResult, }; use clarity::vm::types::QualifiedContractIdentifier; use rusqlite; @@ -67,7 +67,7 @@ impl MarfedKV { path_str: &str, unconfirmed: bool, marf_opts: Option, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { let mut path = PathBuf::from(path_str); std::fs::create_dir_all(&path) @@ -110,7 +110,7 @@ impl MarfedKV { path_str: &str, miner_tip: Option<&StacksBlockId>, marf_opts: Option, - ) -> InterpreterResult { + ) -> VmExecutionResult { let marf = MarfedKV::setup_db(path_str, false, marf_opts)?; let chain_tip = match miner_tip { Some(miner_tip) => miner_tip.clone(), @@ -128,7 +128,7 @@ impl MarfedKV { path_str: &str, miner_tip: Option<&StacksBlockId>, marf_opts: Option, - ) -> InterpreterResult { + ) -> VmExecutionResult { let marf = MarfedKV::setup_db(path_str, true, marf_opts)?; let chain_tip = match miner_tip { Some(miner_tip) => miner_tip.clone(), @@ -200,7 +200,7 @@ impl MarfedKV { pub fn begin_read_only_checked<'a>( &'a mut self, at_block: Option<&StacksBlockId>, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { let chain_tip = if let Some(at_block) = at_block { self.marf.open_block(at_block).map_err(|e| { debug!( @@ -290,7 +290,7 @@ impl MarfedKV { &'a mut self, base_tip: &StacksBlockId, ephemeral_next: &StacksBlockId, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { // sanity check -- `base_tip` must be mapped self.marf.open_block(&base_tip).map_err(|e| { debug!( @@ -407,7 +407,7 @@ impl ClarityMarfStoreTransaction for PersistentWritableMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()> { SqliteConnection::commit_metadata_to(self.marf.sqlite_tx(), &self.chain_tip, target) } @@ -416,7 +416,7 @@ impl ClarityMarfStoreTransaction for PersistentWritableMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()> { SqliteConnection::drop_metadata(self.marf.sqlite_tx(), target) } @@ -439,7 +439,7 @@ impl ClarityMarfStoreTransaction for PersistentWritableMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn drop_unconfirmed(mut self) -> InterpreterResult<()> { + fn drop_unconfirmed(mut self) -> VmExecutionResult<()> { let chain_tip = self.chain_tip.clone(); debug!("Drop unconfirmed MARF trie {}", &chain_tip); self.drop_metadata_for_trie(&chain_tip)?; @@ -453,7 +453,7 @@ impl ClarityMarfStoreTransaction for PersistentWritableMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn commit_to_processed_block(mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_to_processed_block(mut self, target: &StacksBlockId) -> VmExecutionResult<()> { debug!("commit_to({})", target); self.commit_metadata_for_trie(target)?; let _ = self.marf.commit_to(target).map_err(|e| { @@ -469,7 +469,7 @@ impl ClarityMarfStoreTransaction for PersistentWritableMarfStore<'_> { /// /// Returns Ok(()) on success /// Returns Err(InterpreterError(..)) on sqlite failure - fn commit_to_mined_block(mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_to_mined_block(mut self, target: &StacksBlockId) -> VmExecutionResult<()> { debug!("commit_mined_block: ({}->{})", &self.chain_tip, target); // rollback the side_store // the side_store shouldn't commit data for blocks that won't be @@ -540,7 +540,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { } /// Sets the chain tip at which queries will happen. Used for `(at-block ..)` - fn set_block_hash(&mut self, bhh: StacksBlockId) -> InterpreterResult { + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult { self.marf .check_ancestor_block_hash(&bhh) .map_err(|e| match e { @@ -629,7 +629,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { .expect("Attempted to get the open chain tip from an unopened context.") } - fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult)>> { + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> { self.marf .get_with_proof(&self.chain_tip, key) .or_else(|e| match e { @@ -654,7 +654,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { fn get_data_with_proof_from_path( &mut self, hash: &TrieHash, - ) -> InterpreterResult)>> { + ) -> VmExecutionResult)>> { self.marf .get_with_proof_from_hash(&self.chain_tip, hash) .or_else(|e| match e { @@ -676,7 +676,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { .transpose() } - fn get_data(&mut self, key: &str) -> InterpreterResult> { + fn get_data(&mut self, key: &str) -> VmExecutionResult> { self.marf .get(&self.chain_tip, key) .or_else(|e| match e { @@ -712,7 +712,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { .transpose() } - fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult> { + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult> { trace!("MarfedKV get_from_hash: {:?} tip={}", hash, &self.chain_tip); self.marf .get_from_hash(&self.chain_tip, hash) @@ -742,7 +742,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { .transpose() } - fn put_all_data(&mut self, _items: Vec<(String, String)>) -> InterpreterResult<()> { + fn put_all_data(&mut self, _items: Vec<(String, String)>) -> VmExecutionResult<()> { error!("Attempted to commit changes to read-only MARF"); panic!("BUG: attempted commit to read-only MARF"); } @@ -750,7 +750,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> InterpreterResult<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { sqlite_get_contract_hash(self, contract) } @@ -759,7 +759,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { _contract: &QualifiedContractIdentifier, _key: &str, _value: &str, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { error!("Attempted to commit metadata changes to read-only MARF"); panic!("BUG: attempted metadata commit to read-only MARF"); } @@ -768,7 +768,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata(self, contract, key) } @@ -777,7 +777,7 @@ impl ClarityBackingStore for ReadOnlyMarfStore<'_> { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata_manual(self, at_height, contract, key) } } @@ -791,7 +791,7 @@ impl PersistentWritableMarfStore<'_> { } impl ClarityBackingStore for PersistentWritableMarfStore<'_> { - fn set_block_hash(&mut self, bhh: StacksBlockId) -> InterpreterResult { + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult { self.marf .check_ancestor_block_hash(&bhh) .map_err(|e| match e { @@ -821,7 +821,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { Some(&handle_contract_call_special_cases) } - fn get_data(&mut self, key: &str) -> InterpreterResult> { + fn get_data(&mut self, key: &str) -> VmExecutionResult> { trace!("MarfedKV get: {:?} tip={}", key, &self.chain_tip); self.marf .get(&self.chain_tip, key) @@ -851,7 +851,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { .transpose() } - fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult> { + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult> { trace!("MarfedKV get_from_hash: {:?} tip={}", hash, &self.chain_tip); self.marf .get_from_hash(&self.chain_tip, hash) @@ -881,7 +881,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { .transpose() } - fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult)>> { + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> { self.marf .get_with_proof(&self.chain_tip, key) .or_else(|e| match e { @@ -906,7 +906,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { fn get_data_with_proof_from_path( &mut self, hash: &TrieHash, - ) -> InterpreterResult)>> { + ) -> VmExecutionResult)>> { self.marf .get_with_proof_from_hash(&self.chain_tip, hash) .or_else(|e| match e { @@ -991,7 +991,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { } } - fn put_all_data(&mut self, items: Vec<(String, String)>) -> InterpreterResult<()> { + fn put_all_data(&mut self, items: Vec<(String, String)>) -> VmExecutionResult<()> { let mut keys = Vec::with_capacity(items.len()); let mut values = Vec::with_capacity(items.len()); for (key, value) in items.into_iter() { @@ -1008,7 +1008,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> InterpreterResult<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { sqlite_get_contract_hash(self, contract) } @@ -1017,7 +1017,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { contract: &QualifiedContractIdentifier, key: &str, value: &str, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { sqlite_insert_metadata(self, contract, key, value) } @@ -1025,7 +1025,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata(self, contract, key) } @@ -1034,7 +1034,7 @@ impl ClarityBackingStore for PersistentWritableMarfStore<'_> { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata_manual(self, at_height, contract, key) } } @@ -1060,15 +1060,15 @@ impl WritableMarfStore for PersistentWritableMarfStore<'_> {} /// corresponding function in `ClarityMarfStoreTransaction` with a reference to the boxed instance. pub trait BoxedClarityMarfStoreTransaction { fn boxed_drop_current_trie(self: Box); - fn boxed_drop_unconfirmed(self: Box) -> InterpreterResult<()>; + fn boxed_drop_unconfirmed(self: Box) -> VmExecutionResult<()>; fn boxed_commit_to_processed_block( self: Box, target: &StacksBlockId, - ) -> InterpreterResult<()>; + ) -> VmExecutionResult<()>; fn boxed_commit_to_mined_block( self: Box, target: &StacksBlockId, - ) -> InterpreterResult<()>; + ) -> VmExecutionResult<()>; fn boxed_commit_unconfirmed(self: Box); #[cfg(test)] @@ -1080,21 +1080,21 @@ impl BoxedClarityMarfStoreTransaction for T { ::drop_current_trie(*self) } - fn boxed_drop_unconfirmed(self: Box) -> InterpreterResult<()> { + fn boxed_drop_unconfirmed(self: Box) -> VmExecutionResult<()> { ::drop_unconfirmed(*self) } fn boxed_commit_to_processed_block( self: Box, target: &StacksBlockId, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { ::commit_to_processed_block(*self, target) } fn boxed_commit_to_mined_block( self: Box, target: &StacksBlockId, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { ::commit_to_mined_block(*self, target) } @@ -1109,11 +1109,11 @@ impl BoxedClarityMarfStoreTransaction for T { } impl<'a> ClarityMarfStoreTransaction for Box { - fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()> { ClarityMarfStoreTransaction::commit_metadata_for_trie(self.deref_mut(), target) } - fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> InterpreterResult<()> { + fn drop_metadata_for_trie(&mut self, target: &StacksBlockId) -> VmExecutionResult<()> { ClarityMarfStoreTransaction::drop_metadata_for_trie(self.deref_mut(), target) } @@ -1125,14 +1125,14 @@ impl<'a> ClarityMarfStoreTransaction for Box { BoxedClarityMarfStoreTransaction::boxed_drop_current_trie(self) } - fn drop_unconfirmed(self) -> InterpreterResult<()> { + fn drop_unconfirmed(self) -> VmExecutionResult<()> { BoxedClarityMarfStoreTransaction::boxed_drop_unconfirmed(self) } - fn commit_to_processed_block(self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_to_processed_block(self, target: &StacksBlockId) -> VmExecutionResult<()> { BoxedClarityMarfStoreTransaction::boxed_commit_to_processed_block(self, target) } - fn commit_to_mined_block(self, target: &StacksBlockId) -> InterpreterResult<()> { + fn commit_to_mined_block(self, target: &StacksBlockId) -> VmExecutionResult<()> { BoxedClarityMarfStoreTransaction::boxed_commit_to_mined_block(self, target) } @@ -1147,30 +1147,30 @@ impl<'a> ClarityMarfStoreTransaction for Box { } impl<'a> ClarityBackingStore for Box { - fn put_all_data(&mut self, items: Vec<(String, String)>) -> InterpreterResult<()> { + fn put_all_data(&mut self, items: Vec<(String, String)>) -> VmExecutionResult<()> { ClarityBackingStore::put_all_data(self.deref_mut(), items) } - fn get_data(&mut self, key: &str) -> InterpreterResult> { + fn get_data(&mut self, key: &str) -> VmExecutionResult> { ClarityBackingStore::get_data(self.deref_mut(), key) } - fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult> { + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult> { ClarityBackingStore::get_data_from_path(self.deref_mut(), hash) } - fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult)>> { + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> { ClarityBackingStore::get_data_with_proof(self.deref_mut(), key) } fn get_data_with_proof_from_path( &mut self, hash: &TrieHash, - ) -> InterpreterResult)>> { + ) -> VmExecutionResult)>> { ClarityBackingStore::get_data_with_proof_from_path(self.deref_mut(), hash) } - fn set_block_hash(&mut self, bhh: StacksBlockId) -> InterpreterResult { + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult { ClarityBackingStore::set_block_hash(self.deref_mut(), bhh) } @@ -1201,7 +1201,7 @@ impl<'a> ClarityBackingStore for Box { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> InterpreterResult<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { ClarityBackingStore::get_contract_hash(self.deref_mut(), contract) } @@ -1210,7 +1210,7 @@ impl<'a> ClarityBackingStore for Box { contract: &QualifiedContractIdentifier, key: &str, value: &str, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { ClarityBackingStore::insert_metadata(self.deref_mut(), contract, key, value) } @@ -1218,7 +1218,7 @@ impl<'a> ClarityBackingStore for Box { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { ClarityBackingStore::get_metadata(self.deref_mut(), contract, key) } @@ -1227,7 +1227,7 @@ impl<'a> ClarityBackingStore for Box { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { ClarityBackingStore::get_metadata_manual(self.deref_mut(), at_height, contract, key) } } diff --git a/stackslib/src/clarity_vm/database/mod.rs b/stackslib/src/clarity_vm/database/mod.rs index b221ac09e4..a38c013e65 100644 --- a/stackslib/src/clarity_vm/database/mod.rs +++ b/stackslib/src/clarity_vm/database/mod.rs @@ -11,7 +11,7 @@ use clarity::vm::database::{ BurnStateDB, ClarityBackingStore, ClarityDatabase, HeadersDB, SpecialCaseHandler, SqliteConnection, NULL_BURN_STATE_DB, NULL_HEADER_DB, }; -use clarity::vm::errors::{InterpreterResult, RuntimeErrorType}; +use clarity::vm::errors::{RuntimeErrorType, VmExecutionResult}; use clarity::vm::types::{QualifiedContractIdentifier, TupleData}; use rusqlite::{params, Connection, OptionalExtension, Row}; use stacks_common::types::chainstate::{ @@ -1219,26 +1219,26 @@ impl MemoryBackingStore { } impl ClarityBackingStore for MemoryBackingStore { - fn set_block_hash(&mut self, bhh: StacksBlockId) -> InterpreterResult { + fn set_block_hash(&mut self, bhh: StacksBlockId) -> VmExecutionResult { Err(RuntimeErrorType::UnknownBlockHeaderHash(BlockHeaderHash(bhh.0)).into()) } - fn get_data(&mut self, key: &str) -> InterpreterResult> { + fn get_data(&mut self, key: &str) -> VmExecutionResult> { SqliteConnection::get(self.get_side_store(), key) } - fn get_data_from_path(&mut self, hash: &TrieHash) -> InterpreterResult> { + fn get_data_from_path(&mut self, hash: &TrieHash) -> VmExecutionResult> { SqliteConnection::get(self.get_side_store(), hash.to_string().as_str()) } - fn get_data_with_proof(&mut self, key: &str) -> InterpreterResult)>> { + fn get_data_with_proof(&mut self, key: &str) -> VmExecutionResult)>> { Ok(SqliteConnection::get(self.get_side_store(), key)?.map(|x| (x, vec![]))) } fn get_data_with_proof_from_path( &mut self, key: &TrieHash, - ) -> InterpreterResult)>> { + ) -> VmExecutionResult)>> { Ok( SqliteConnection::get(self.get_side_store(), key.to_string().as_str())? .map(|x| (x, vec![])), @@ -1273,7 +1273,7 @@ impl ClarityBackingStore for MemoryBackingStore { Some(&handle_contract_call_special_cases) } - fn put_all_data(&mut self, items: Vec<(String, String)>) -> InterpreterResult<()> { + fn put_all_data(&mut self, items: Vec<(String, String)>) -> VmExecutionResult<()> { for (key, value) in items.into_iter() { SqliteConnection::put(self.get_side_store(), &key, &value)?; } @@ -1283,7 +1283,7 @@ impl ClarityBackingStore for MemoryBackingStore { fn get_contract_hash( &mut self, contract: &QualifiedContractIdentifier, - ) -> InterpreterResult<(StacksBlockId, Sha512Trunc256Sum)> { + ) -> VmExecutionResult<(StacksBlockId, Sha512Trunc256Sum)> { sqlite_get_contract_hash(self, contract) } @@ -1292,7 +1292,7 @@ impl ClarityBackingStore for MemoryBackingStore { contract: &QualifiedContractIdentifier, key: &str, value: &str, - ) -> InterpreterResult<()> { + ) -> VmExecutionResult<()> { sqlite_insert_metadata(self, contract, key, value) } @@ -1300,7 +1300,7 @@ impl ClarityBackingStore for MemoryBackingStore { &mut self, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata(self, contract, key) } @@ -1309,7 +1309,7 @@ impl ClarityBackingStore for MemoryBackingStore { at_height: u32, contract: &QualifiedContractIdentifier, key: &str, - ) -> InterpreterResult> { + ) -> VmExecutionResult> { sqlite_get_metadata_manual(self, at_height, contract, key) } } diff --git a/stackslib/src/clarity_vm/tests/forking.rs b/stackslib/src/clarity_vm/tests/forking.rs index b05322f9ee..6e8a2e3bad 100644 --- a/stackslib/src/clarity_vm/tests/forking.rs +++ b/stackslib/src/clarity_vm/tests/forking.rs @@ -17,7 +17,7 @@ use clarity::vm::analysis::errors::CheckErrors; use clarity::vm::ast::ASTRules; use clarity::vm::contexts::OwnedEnvironment; -use clarity::vm::errors::{Error, InterpreterResult as Result, RuntimeErrorType}; +use clarity::vm::errors::{Error, RuntimeErrorType, VmExecutionResult}; use clarity::vm::test_util::{ execute, is_committed, is_err_code, symbols_from_values, TEST_BURN_STATE_DB, TEST_HEADER_DB, }; @@ -78,7 +78,7 @@ fn test_at_block_mutations(#[case] version: ClarityVersion, #[case] epoch: Stack version: ClarityVersion, expected_value: i128, to_exec: &str, - ) -> Result { + ) -> VmExecutionResult { let c = QualifiedContractIdentifier::local("contract").unwrap(); let p1 = execute(p1_str).expect_principal().unwrap(); let placeholder_context = @@ -157,7 +157,7 @@ fn test_at_block_good(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc version: ClarityVersion, expected_value: i128, to_exec: &str, - ) -> Result { + ) -> VmExecutionResult { let c = QualifiedContractIdentifier::local("contract").unwrap(); let p1 = execute(p1_str).expect_principal().unwrap(); let placeholder_context =