Skip to content

refactoring: Isolate clarity VM behind feature gate for lightweight serialization #6239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 3 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ members = [

# Dependencies we want to keep the same between workspace members
[workspace.dependencies]
ed25519-dalek = { version = "2.1.1", features = ["serde", "rand_core"] }
ed25519-dalek = { version = "2.1.1", default-features = false }
hashbrown = { version = "0.15.2", features = ["serde"] }
lazy_static = "1.4.0"
rand_core = "0.6.4"
rand = "0.8"
rand_chacha = "0.3.1"
tikv-jemallocator = "0.5.4"
serde = "1"
serde_derive = "1"
serde_json = { version = "1.0", features = ["arbitrary_precision", "unbounded_depth"] }
slog = { version = "2.5.2", features = [ "max_level_trace" ] }
rusqlite = { version = "0.31.0", features = ["blob", "serde_json", "i128_blob", "bundled", "trace"] }
tikv-jemallocator = "0.5.4"
thiserror = "1.0.65"
toml = "0.5.6"

# Use a bit more than default optimization for
# dev builds to speed up test execution
# dev builds to speed up test execution
[profile.dev]
opt-level = 1

# Use release-level optimization for dependencies
# This slows down "first" builds on development environments,
# but won't impact subsequent builds.
# but won't impact subsequent builds.
[profile.dev.package."*"]
opt-level = 3

Expand Down
59 changes: 30 additions & 29 deletions clarity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,43 @@ name = "clarity"
path = "./src/libclarity.rs"

[dependencies]
rand = { workspace = true }
rand_chacha = { workspace = true }
serde = "1"
serde_derive = "1"
serde_stacker = "0.1"
hashbrown = { workspace = true }
lazy_static = { workspace = true }
regex = "1"
lazy_static = "1.4.0"
integer-sqrt = "0.1.3"
slog = { version = "2.5.2", features = [ "max_level_trace" ] }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
slog = { workspace = true }
stacks_common = { package = "stacks-common", path = "../stacks-common", default-features = false }
rstest = "0.17.0"
rstest_reuse = "0.5.0"
hashbrown = { workspace = true }
rusqlite = { workspace = true, optional = true }

[dependencies.serde_json]
version = "1.0"
features = ["arbitrary_precision", "unbounded_depth"]

[dependencies.time]
version = "0.2.23"
features = ["std"]
# Optional dependencies for vm functionality
rand = { workspace = true, optional = true }
rand_chacha = { workspace = true , optional = true }
serde_stacker = { version = "0.1", optional = true }
integer-sqrt = { version = "0.1.3", optional = true }
rusqlite = { workspace = true, optional = true }
rstest = { version = "0.17.0", optional = true }
rstest_reuse = { version = "0.5.0", optional = true }

[dev-dependencies]
assert-json-diff = "1.0.0"
mutants = "0.0.3"
# 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"

[features]
default = ["rusqlite"]
developer-mode = ["stacks_common/developer-mode"]
# The default feature set provides the full Clarity virtual machine with its SQLite-based
# database backend.
# To use `clarity` as a lightweight serialization/deserialization library,
# depend on it with `default-features = false`.
default = ["vm", "rusqlite"]
# Enables the complete Clarity Virtual Machine. This includes the parser, analyzer,
# cost-checking system, and execution engine. It transitively enables all necessary
# dependencies for running smart contracts. This feature is required for any on-chain
# contract execution or local contract testing.
vm = ["dep:rand", "dep:rand_chacha", "dep:serde_stacker", "dep:integer-sqrt"]
developer-mode = ["vm", "stacks_common/developer-mode"]
devtools = ["vm"]
testing = ["vm", "dep:rstest", "dep:rstest_reuse", "rusqlite"]
rusqlite = ["vm", "stacks_common/rusqlite", "dep:rusqlite"]
slog_json = ["stacks_common/slog_json"]
rusqlite = ["stacks_common/rusqlite", "dep:rusqlite"]
testing = []
devtools = []
rollback_value_check = []
disable-costs = []
rollback_value_check = ["vm"]
disable-costs = ["vm"]
1 change: 1 addition & 0 deletions clarity/src/libclarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub use stacks_common::{
/// The Clarity virtual machine
pub mod vm;

#[cfg(feature = "vm")]
pub mod boot_util {

use stacks_common::types::chainstate::StacksAddress;
Expand Down
10 changes: 5 additions & 5 deletions clarity/src/vm/analysis/arithmetic_checker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ fn test_functions_clarity1() {
Err(FunctionNotPermitted(NativeFunctions::SetVar))),
("(define-private (foo (a principal)) (ft-get-balance tokaroos a))",
Err(FunctionNotPermitted(NativeFunctions::GetTokenBalance))),
("(define-private (foo (a principal))
("(define-private (foo (a principal))
(ft-transfer? stackaroo u50 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 'SPAXYA5XS51713FDTQ8H94EJ4V579CXMTRNBZKSF))",
Err(FunctionNotPermitted(NativeFunctions::TransferToken))),
("(define-private (foo (a principal))
("(define-private (foo (a principal))
(ft-mint? stackaroo u100 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))",
Err(FunctionNotPermitted(NativeFunctions::MintToken))),
("(define-private (foo (a principal))
("(define-private (foo (a principal))
(nft-mint? stackaroo \"Roo\" 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))",
Err(FunctionNotPermitted(NativeFunctions::MintAsset))),
("(nft-transfer? stackaroo \"Roo\" 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR 'SPAXYA5XS51713FDTQ8H94EJ4V579CXMTRNBZKSF)",
Expand Down Expand Up @@ -293,7 +293,7 @@ fn test_functions_clarity1() {
Ok(())),
("(buff-to-uint-be 0x0001)",
Ok(())),
("(is-standard 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6)",
("(is-standard 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6)",
Ok(())),
("(principal-destruct? 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6)",
Ok(())),
Expand Down Expand Up @@ -358,7 +358,7 @@ fn test_functions_clarity2() {
Err(FunctionNotPermitted(NativeFunctions::IsStandard))),
("(principal-destruct? 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6)",
Err(FunctionNotPermitted(NativeFunctions::PrincipalDestruct))),
("(principal-construct? 0x22 0xfa6bf38ed557fe417333710d6033e9419391a320)",
("(principal-construct? 0x22 0xfa6bf38ed557fe417333710d6033e9419391a320)",
Err(FunctionNotPermitted(NativeFunctions::PrincipalConstruct))),
("(string-to-int? \"-1\")",
Err(FunctionNotPermitted(NativeFunctions::StringToInt))),
Expand Down
Loading
Loading