Skip to content

Commit

Permalink
[move] Upgrade move version to include runtime checks (aptos-labs#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou authored Sep 30, 2022
1 parent 53cabe3 commit 985f19d
Show file tree
Hide file tree
Showing 26 changed files with 402 additions and 656 deletions.
822 changes: 257 additions & 565 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ aptos-vm = { path = "../aptos-move/aptos-vm" }

storage-interface = { path = "../storage/storage-interface" }

move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }

[dev-dependencies]
aptos-api-test-context = { path = "./test-context", package = "aptos-api-test-context" }
Expand All @@ -56,7 +56,7 @@ regex = "1.5.5"
reqwest = { version = "0.11.10", features = ["blocking", "json"], default_features = false }
warp = { version = "0.3.2", features = ["default"] }

move-package = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-package = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

[features]
failpoints = ["fail/failpoints"]
6 changes: 3 additions & 3 deletions api/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ aptos-vm = { path = "../../aptos-move/aptos-vm" }

storage-interface = { path = "../../storage/storage-interface" }

move-binary-format = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-resource-viewer = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }
move-resource-viewer = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
6 changes: 3 additions & 3 deletions aptos-move/aptos-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ smallvec = "1.8.0"
aptos-crypto = { path = "../../crates/aptos-crypto" }
aptos-state-view = { path = "../../storage/state-view" }
aptos-types = { path = "../../types" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-table-extension = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }
move-table-extension = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

[dev-dependencies]
claims = "0.7"
Expand Down
12 changes: 6 additions & 6 deletions aptos-move/aptos-gas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ anyhow = "1.0.57"
bcs = "0.1.3"
clap = { version = "3.1.17", features = ["derive"] }

move-binary-format = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-model = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-stdlib = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-table-extension = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-model = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-stdlib = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-table-extension = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-vm-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

aptos-global-constants = { path = "../../config/global-constants" }
aptos-types = { path = "../../types" }
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/aptos-module-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ publish = false
edition = "2021"

[dependencies]
move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-binary-format = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }
move-binary-format = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
2 changes: 1 addition & 1 deletion aptos-move/aptos-sdk-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ textwrap = "0.15.0"

aptos-types = { path = "../../types" }

move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }

[dev-dependencies]
cached-packages = { path = "../../aptos-move/framework/cached-packages" }
Expand Down
22 changes: 11 additions & 11 deletions aptos-move/aptos-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ aptos-state-view = { path = "../../storage/state-view" }
aptos-types = { path = "../../types" }

framework = { path = "../framework" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-stdlib = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-bytecode-verifier = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }
move-stdlib = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
mvhashmap = { path = "../mvhashmap" }

move-table-extension = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-vm-runtime = { git = "https://github.com/move-language/move", features = ["lazy_natives"], rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-vm-test-utils = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["table-extension"] }
move-vm-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
read-write-set-dynamic = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-table-extension = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-vm-runtime = { git = "https://github.com/move-language/move", features = ["lazy_natives"], rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-vm-test-utils = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["table-extension"] }
move-vm-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
read-write-set-dynamic = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

move-unit-test = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["table-extension"], optional = true }
move-unit-test = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["table-extension"], optional = true }

[dev-dependencies]
proptest = "1.0.0"
Expand Down
38 changes: 37 additions & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use aptos_types::{
Transaction, TransactionOutput, TransactionPayload, TransactionStatus, VMValidatorResult,
WriteSetPayload,
},
vm_status::{AbortLocation, StatusCode, VMStatus},
vm_status::{AbortLocation, DiscardedVMStatus, StatusCode, VMStatus},
write_set::WriteSet,
};
use fail::fail_point;
Expand All @@ -56,6 +56,7 @@ use move_core_types::{
transaction_argument::convert_txn_args,
value::{serialize_values, MoveValue},
};
use move_vm_runtime::move_vm::RuntimeConfig;
use move_vm_types::gas::UnmeteredGasMeter;
use num_cpus;
use once_cell::sync::OnceCell;
Expand All @@ -71,6 +72,7 @@ use std::{

static EXECUTION_CONCURRENCY_LEVEL: OnceCell<usize> = OnceCell::new();
static NUM_PROOF_READING_THREADS: OnceCell<usize> = OnceCell::new();
static RUNTIME_CHECKS: OnceCell<RuntimeConfig> = OnceCell::new();

/// Remove this once the bundle is removed from the code.
static MODULE_BUNDLE_DISALLOWED: AtomicBool = AtomicBool::new(true);
Expand Down Expand Up @@ -112,6 +114,29 @@ impl AptosVM {
}
}

/// Sets runtime config when invoked the first time.
pub fn set_runtime_config(paranoid_type_checks: bool, paranoid_hot_potato_checks: bool) {
// Only the first call succeeds, due to OnceCell semantics.
RUNTIME_CHECKS
.set(RuntimeConfig {
paranoid_type_checks,
paranoid_hot_potato_checks,
})
.ok();
}

/// Get the concurrency level if already set, otherwise return default true
/// (paranoid execution mode).
pub fn get_runtime_config() -> RuntimeConfig {
match RUNTIME_CHECKS.get() {
Some(config) => *config,
None => RuntimeConfig {
paranoid_type_checks: true,
paranoid_hot_potato_checks: true,
},
}
}

/// Sets the # of async proof reading threads.
pub fn set_num_proof_reading_threads_once(mut num_threads: usize) {
// TODO(grao): Do more analysis to tune this magic number.
Expand Down Expand Up @@ -1045,6 +1070,17 @@ impl VMAdapter for AptosVM {
let (vm_status, output) =
self.execute_user_transaction(data_cache, txn, log_context);

if let Err(DiscardedVMStatus::UNKNOWN_INVARIANT_VIOLATION_ERROR) =
vm_status.clone().keep_or_discard()
{
error!(
*log_context,
"[aptos_vm] Transaction breaking invariant violation. txn: {:?}",
bcs::to_bytes::<SignedTransaction>(&**txn),
);
TRANSACTIONS_INVARIANT_VIOLATION.inc();
}

// Increment the counter for user transactions executed.
let counter_label = match output.txn_output().status() {
TransactionStatus::Keep(_) => Some("success"),
Expand Down
9 changes: 9 additions & 0 deletions aptos-move/aptos-vm/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ use aptos_metrics_core::{
};
use once_cell::sync::Lazy;

/// Count the number of transactions that brake invariants of VM.
pub static TRANSACTIONS_INVARIANT_VIOLATION: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"aptos_vm_transactions_invariant_violation",
"Number of transactions that broke VM invariant",
)
.unwrap()
});

/// Count the number of transactions validated, with a "status" label to
/// distinguish success or failure results.
pub static TRANSACTIONS_VALIDATED: Lazy<IntCounterVec> = Lazy::new(|| {
Expand Down
3 changes: 2 additions & 1 deletion aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ impl MoveVmExt {
treat_friend_as_private: bool,
) -> VMResult<Self> {
Ok(Self {
inner: MoveVM::new_with_verifier_config(
inner: MoveVM::new_with_configs(
aptos_natives(native_gas_params, abs_val_size_gas_params),
VerifierConfig {
max_loop_depth: Some(5),
treat_friend_as_private,
},
crate::AptosVM::get_runtime_config(),
)?,
})
}
Expand Down
24 changes: 12 additions & 12 deletions aptos-move/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ aptos-sdk-builder = { path = "../aptos-sdk-builder" }
aptos-state-view = { path = "../../storage/state-view" }
aptos-types = { path = "../../types" }
gas-algebra-ext = { path = "../gas-algebra-ext" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-binary-format = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

move-command-line-common = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-compiler ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-model ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-package ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-table-extension ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-vm-runtime ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-vm-types ={ git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-command-line-common = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-compiler ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-core-types ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }
move-model ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-package ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-table-extension ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-vm-runtime ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-vm-types ={ git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

[dev-dependencies]
claims = "0.7"

aptos-gas = { path = "../../aptos-move/aptos-gas" }
aptos-vm = { path = "../../aptos-move/aptos-vm", features = ["testing"] }
move-cli = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-prover = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-cli = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
move-prover = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

move-unit-test = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-unit-test = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/cached-packages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proptest = { version = "1.0.0", optional = true }
proptest-derive = { version = "0.3.0", optional = true }
tempfile = "3.3.0"

move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5", features = ["address32"] }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82", features = ["address32"] }

[build-dependencies]
framework = { path = ".." }
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/gas-algebra-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
move-core-types = { git = "https://github.com/move-language/move", rev = "94552a7fd7381b84376f6d7008d1f3110b5eccc5" }
move-core-types = { git = "https://github.com/move-language/move", rev = "0155b47808de249f4030e84354fde154a1500a82" }
Loading

0 comments on commit 985f19d

Please sign in to comment.