diff --git a/Cargo.lock b/Cargo.lock index 5ba814ea8b..2250f10db1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,12 +605,11 @@ name = "clarity" version = "0.0.1" dependencies = [ "assert-json-diff 1.1.0", + "getrandom 0.2.12", "hashbrown 0.15.2", "integer-sqrt", "lazy_static", "mutants", - "rand 0.8.5", - "rand_chacha 0.3.1", "regex", "rstest", "rstest_reuse", @@ -621,7 +620,6 @@ dependencies = [ "serde_stacker", "slog", "stacks-common 0.0.1", - "time 0.2.27", ] [[package]] @@ -810,9 +808,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.11" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e" dependencies = [ "powerfmt", ] @@ -1207,8 +1205,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -3086,7 +3086,7 @@ dependencies = [ "serde", "serde_json", "slog", - "time 0.3.36", + "time 0.3.41", ] [[package]] @@ -3099,7 +3099,7 @@ dependencies = [ "slog", "term", "thread_local", - "time 0.3.36", + "time 0.3.41", ] [[package]] @@ -3188,7 +3188,6 @@ dependencies = [ "slog", "slog-json", "slog-term", - "time 0.2.27", "toml", "winapi 0.3.9", ] @@ -3645,9 +3644,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.36" +version = "0.3.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40" dependencies = [ "deranged", "itoa", @@ -3657,14 +3656,14 @@ dependencies = [ "powerfmt", "serde", "time-core", - "time-macros 0.2.18", + "time-macros 0.2.22", ] [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c" [[package]] name = "time-macros" @@ -3678,9 +3677,9 @@ dependencies = [ [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49" dependencies = [ "num-conv", "time-core", diff --git a/clarity/Cargo.toml b/clarity/Cargo.toml index 9077834a70..c9b56905bf 100644 --- a/clarity/Cargo.toml +++ b/clarity/Cargo.toml @@ -18,8 +18,6 @@ name = "clarity" path = "./src/libclarity.rs" [dependencies] -rand = { workspace = true } -rand_chacha = { workspace = true } serde = "1" serde_derive = "1" serde_stacker = "0.1" @@ -28,22 +26,23 @@ lazy_static = "1.4.0" integer-sqrt = "0.1.3" slog = { version = "2.5.2", features = [ "max_level_trace" ] } stacks_common = { package = "stacks-common", path = "../stacks-common", default-features = false } -rstest = "0.17.0" -rstest_reuse = "0.5.0" +rstest = { version = "0.17.0", optional = true } +rstest_reuse = { version = "0.5.0", optional = true } hashbrown = { workspace = true } rusqlite = { workspace = true, optional = true } +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.2", features = ["js"] } + [dependencies.serde_json] version = "1.0" features = ["arbitrary_precision", "unbounded_depth"] -[dependencies.time] -version = "0.2.23" -features = ["std"] - [dev-dependencies] assert-json-diff = "1.0.0" mutants = "0.0.3" +rstest = { version = "0.17.0" } +rstest_reuse = { version = "0.5.0" } # a nightly rustc regression (35dbef235 2021-03-02) prevents criterion from compiling # but it isn't necessary for tests: only benchmarks. therefore, commenting out for now. # criterion = "0.3" @@ -53,7 +52,7 @@ default = ["rusqlite"] developer-mode = ["stacks_common/developer-mode"] slog_json = ["stacks_common/slog_json"] rusqlite = ["stacks_common/rusqlite", "dep:rusqlite"] -testing = [] +testing = ["rstest", "rstest_reuse"] devtools = [] rollback_value_check = [] disable-costs = [] diff --git a/clarity/src/vm/analysis/type_checker/v2_05/mod.rs b/clarity/src/vm/analysis/type_checker/v2_05/mod.rs index 82e1e50490..40bc742334 100644 --- a/clarity/src/vm/analysis/type_checker/v2_05/mod.rs +++ b/clarity/src/vm/analysis/type_checker/v2_05/mod.rs @@ -335,7 +335,7 @@ pub fn no_type() -> TypeSignature { } impl<'a, 'b> TypeChecker<'a, 'b> { - fn new( + pub fn new( db: &'a mut AnalysisDatabase<'b>, cost_track: LimitedCostTracker, build_type_map: bool, diff --git a/clarity/src/vm/costs/mod.rs b/clarity/src/vm/costs/mod.rs index 0b1559795f..c2f51f88bb 100644 --- a/clarity/src/vm/costs/mod.rs +++ b/clarity/src/vm/costs/mod.rs @@ -417,6 +417,25 @@ pub enum CostErrors { ExecutionTimeExpired, } +impl fmt::Display for CostErrors { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + CostErrors::CostComputationFailed(ref s) => write!(f, "Cost computation failed: {}", s), + CostErrors::CostOverflow => write!(f, "Cost overflow"), + CostErrors::CostBalanceExceeded(ref total, ref limit) => { + write!(f, "Cost balance exceeded: total {}, limit {}", total, limit) + } + CostErrors::MemoryBalanceExceeded(ref used, ref limit) => { + write!(f, "Memory balance exceeded: used {}, limit {}", used, limit) + } + CostErrors::CostContractLoadFailure => write!(f, "Failed to load cost contract"), + CostErrors::InterpreterFailure => write!(f, "Interpreter failure"), + CostErrors::Expect(ref s) => write!(f, "Expectation failed: {}", s), + CostErrors::ExecutionTimeExpired => write!(f, "Execution time expired"), + } + } +} + impl CostErrors { fn rejectable(&self) -> bool { matches!(self, CostErrors::InterpreterFailure | CostErrors::Expect(_)) diff --git a/clarity/src/vm/docs/mod.rs b/clarity/src/vm/docs/mod.rs index 54e1247f9b..42dfc5e3b6 100644 --- a/clarity/src/vm/docs/mod.rs +++ b/clarity/src/vm/docs/mod.rs @@ -2632,7 +2632,7 @@ pub fn make_api_reference(function: &NativeFunctions) -> FunctionAPI { } } -fn make_keyword_reference(variable: &NativeVariables) -> Option { +pub fn make_keyword_reference(variable: &NativeVariables) -> Option { let keyword = match variable { NativeVariables::TxSender => TX_SENDER_KEYWORD.clone(), NativeVariables::ContractCaller => CONTRACT_CALLER_KEYWORD.clone(), diff --git a/clarity/src/vm/mod.rs b/clarity/src/vm/mod.rs index 3dbe8a2951..fdade91bf5 100644 --- a/clarity/src/vm/mod.rs +++ b/clarity/src/vm/mod.rs @@ -56,7 +56,6 @@ pub mod clarity; use std::collections::BTreeMap; use costs::CostErrors; -use serde_json; use stacks_common::types::StacksEpochId; use self::analysis::ContractAnalysis; @@ -77,6 +76,7 @@ pub use crate::vm::database::clarity_db::StacksEpoch; use crate::vm::errors::{ CheckErrors, Error, InterpreterError, InterpreterResult as Result, RuntimeErrorType, }; +use crate::vm::events::StacksTransactionEvent; use crate::vm::functions::define::DefineResult; pub use crate::vm::functions::stx_transfer_consolidated; pub use crate::vm::representations::{ @@ -118,12 +118,12 @@ pub enum EvaluationResult { #[derive(Debug, Clone)] pub struct ExecutionResult { pub result: EvaluationResult, - pub events: Vec, + pub events: Vec, pub cost: Option, pub diagnostics: Vec, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize)] pub struct CostSynthesis { pub total: ExecutionCost, pub limit: ExecutionCost, diff --git a/clarity/src/vm/representations.rs b/clarity/src/vm/representations.rs index ce97d913b4..5b01f07b22 100644 --- a/clarity/src/vm/representations.rs +++ b/clarity/src/vm/representations.rs @@ -454,13 +454,17 @@ pub struct SymbolicExpression { pub id: u64, #[cfg(feature = "developer-mode")] + #[serde(default)] pub span: Span, #[cfg(feature = "developer-mode")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub pre_comments: Vec<(String, Span)>, #[cfg(feature = "developer-mode")] + #[serde(default, skip_serializing_if = "Option::is_none")] pub end_line_comment: Option, #[cfg(feature = "developer-mode")] + #[serde(default, skip_serializing_if = "Vec::is_empty")] pub post_comments: Vec<(String, Span)>, } @@ -650,7 +654,7 @@ impl fmt::Display for SymbolicExpression { } } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct Span { pub start_line: u32, pub start_column: u32, @@ -666,12 +670,7 @@ impl Span { end_column: 0, }; - pub fn zero() -> Span { - Span { - start_line: 0, - start_column: 0, - end_line: 0, - end_column: 0, - } + pub fn zero() -> Self { + Self::default() } } diff --git a/pox-locking/Cargo.toml b/pox-locking/Cargo.toml index 2ebca921d9..9863c2b5c4 100644 --- a/pox-locking/Cargo.toml +++ b/pox-locking/Cargo.toml @@ -19,8 +19,8 @@ name = "pox_locking" path = "src/lib.rs" [dependencies] -clarity = { package = "clarity", path = "../clarity" } -stacks_common = { package = "stacks-common", path = "../stacks-common" } +clarity = { package = "clarity", path = "../clarity", default-features = false} +stacks_common = { package = "stacks-common", path = "../stacks-common", default-features = false} slog = { version = "2.5.2", features = [ "max_level_trace" ] } [dev-dependencies] diff --git a/stacks-common/Cargo.toml b/stacks-common/Cargo.toml index a1a27ba6bf..45afb08452 100644 --- a/stacks-common/Cargo.toml +++ b/stacks-common/Cargo.toml @@ -68,10 +68,6 @@ workspace = true version = "4.1.3" features = ["serde"] -[dependencies.time] -version = "0.2.23" -features = ["std"] - [target.'cfg(not(target_family = "wasm"))'.dependencies] secp256k1 = { version = "0.24.3", features = ["serde", "recovery"] } diff --git a/stacks-common/src/deps_common/bitcoin/util/mod.rs b/stacks-common/src/deps_common/bitcoin/util/mod.rs index 7032ba41cd..6f3e332527 100644 --- a/stacks-common/src/deps_common/bitcoin/util/mod.rs +++ b/stacks-common/src/deps_common/bitcoin/util/mod.rs @@ -20,8 +20,6 @@ pub mod hash; use std::{error, fmt}; -use secp256k1; - use crate::deps_common::bitcoin::network; use crate::deps_common::bitcoin::network::serialize; @@ -50,8 +48,6 @@ pub trait BitArray { /// if appropriate. #[derive(Debug)] pub enum Error { - /// secp-related error - Secp256k1(secp256k1::Error), /// Serialization error Serialize(serialize::Error), /// Network error @@ -65,7 +61,6 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Error::Secp256k1(ref e) => fmt::Display::fmt(e, f), Error::Serialize(ref e) => fmt::Display::fmt(e, f), Error::Network(ref e) => fmt::Display::fmt(e, f), Error::SpvBadProofOfWork => f.write_str("target correct but not attained"), @@ -77,7 +72,6 @@ impl fmt::Display for Error { impl error::Error for Error { fn cause(&self) -> Option<&dyn error::Error> { match *self { - Error::Secp256k1(ref e) => Some(e), Error::Serialize(ref e) => Some(e), Error::Network(ref e) => Some(e), Error::SpvBadProofOfWork | Error::SpvBadTarget => None, @@ -85,13 +79,6 @@ impl error::Error for Error { } } -#[doc(hidden)] -impl From for Error { - fn from(e: secp256k1::Error) -> Error { - Error::Secp256k1(e) - } -} - #[doc(hidden)] impl From for Error { fn from(e: serialize::Error) -> Error { diff --git a/stacks-common/src/deps_common/mod.rs b/stacks-common/src/deps_common/mod.rs index 9140f7d0b9..ca53655572 100644 --- a/stacks-common/src/deps_common/mod.rs +++ b/stacks-common/src/deps_common/mod.rs @@ -16,6 +16,7 @@ pub mod bech32; pub mod bitcoin; +#[cfg(not(target_arch = "wasm32"))] pub mod ctrlc; pub mod httparse;