Skip to content

Commit

Permalink
[move] Full loader integration on MoveVM side (#14075)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Aug 18, 2024
1 parent 8825060 commit f49e8b1
Show file tree
Hide file tree
Showing 55 changed files with 2,097 additions and 700 deletions.
6 changes: 5 additions & 1 deletion aptos-move/aptos-release-builder/src/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ use move_core_types::{
language_storage::{ModuleId, StructTag},
move_resource::MoveResource,
};
use move_vm_runtime::module_traversal::{TraversalContext, TraversalStorage};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
DummyCodeStorage,
};
use move_vm_types::{gas::UnmeteredGasMeter, resolver::ModuleResolver};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
Expand Down Expand Up @@ -480,6 +483,7 @@ fn force_end_epoch(state_view: &SimulationStateView<impl StateView>) -> Result<(
vec![bcs::to_bytes(&AccountAddress::ONE)?],
&mut UnmeteredGasMeter,
&mut TraversalContext::new(&traversal_storage),
&DummyCodeStorage,
)?;
let (mut change_set, module_write_set) = sess.finish(&change_set_configs)?;
change_set.try_materialize_aggregator_v1_delta_set(&resolver)?;
Expand Down
6 changes: 5 additions & 1 deletion aptos-move/aptos-vm-profiling/src/bins/run_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use move_core_types::{account_address::AccountAddress, ident_str, identifier::Id
use move_ir_compiler::Compiler;
use move_vm_runtime::{
module_traversal::*, move_vm::MoveVM, native_extensions::NativeContextExtensions,
native_functions::NativeFunction,
native_functions::NativeFunction, DummyCodeStorage,
};
use move_vm_test_utils::InMemoryStorage;
use move_vm_types::{
Expand Down Expand Up @@ -176,6 +176,8 @@ fn main() -> Result<()> {
args,
&mut UnmeteredGasMeter,
&mut TraversalContext::new(&traversal_storage),
&DummyCodeStorage,
&DummyCodeStorage,
)?;
} else {
let module = Compiler::new(test_modules.iter().collect()).into_compiled_module(&src)?;
Expand All @@ -186,6 +188,7 @@ fn main() -> Result<()> {
module_blob,
*module.self_id().address(),
&mut UnmeteredGasMeter,
&DummyCodeStorage,
)?;
let args: Vec<Vec<u8>> = vec![];
let res = sess.execute_function_bypass_visibility(
Expand All @@ -195,6 +198,7 @@ fn main() -> Result<()> {
args,
&mut UnmeteredGasMeter,
&mut TraversalContext::new(&traversal_storage),
&DummyCodeStorage,
)?;
println!("{:?}", res);
}
Expand Down
53 changes: 43 additions & 10 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ use move_core_types::{
use move_vm_runtime::{
logging::expect_no_verification_errors,
module_traversal::{TraversalContext, TraversalStorage},
DummyCodeStorage,
};
use move_vm_types::gas::{GasMeter, UnmeteredGasMeter};
use num_cpus;
Expand Down Expand Up @@ -731,13 +732,20 @@ impl AptosVM {
// the error semantics.
if self.gas_feature_version >= 15 {
session.check_script_dependencies_and_check_gas(
&DummyCodeStorage,
&DummyCodeStorage,

Check warning on line 736 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L735-L736

Added lines #L735 - L736 were not covered by tests
gas_meter,
traversal_context,
script.code(),
)?;
}

let func = session.load_script(script.code(), script.ty_args())?;
let func = session.load_script(
&DummyCodeStorage,
&DummyCodeStorage,
script.code(),
script.ty_args(),
)?;

Check warning on line 748 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L743-L748

Added lines #L743 - L748 were not covered by tests

let compiled_script = match CompiledScript::deserialize_with_config(
script.code(),
Expand Down Expand Up @@ -778,6 +786,8 @@ impl AptosVM {
args,
gas_meter,
traversal_context,
&DummyCodeStorage,
&DummyCodeStorage,

Check warning on line 790 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L789-L790

Added lines #L789 - L790 were not covered by tests
)?;
Ok(())
}
Expand All @@ -799,14 +809,20 @@ impl AptosVM {
let module_id = traversal_context
.referenced_module_ids
.alloc(entry_fn.module().clone());
session.check_dependencies_and_charge_gas(gas_meter, traversal_context, [(
module_id.address(),
module_id.name(),
)])?;
session.check_dependencies_and_charge_gas(
&DummyCodeStorage,
gas_meter,
traversal_context,
[(module_id.address(), module_id.name())],
)?;

Check warning on line 817 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L812-L817

Added lines #L812 - L817 were not covered by tests
}

let function =
session.load_function(entry_fn.module(), entry_fn.function(), entry_fn.ty_args())?;
let function = session.load_function(
&DummyCodeStorage,
entry_fn.module(),
entry_fn.function(),
entry_fn.ty_args(),
)?;

Check warning on line 825 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L820-L825

Added lines #L820 - L825 were not covered by tests

// Native entry function is forbidden.
if self
Expand Down Expand Up @@ -843,7 +859,13 @@ impl AptosVM {
&function,
struct_constructors_enabled,
)?;
session.execute_entry_function(function, args, gas_meter, traversal_context)?;
session.execute_entry_function(
function,
args,
gas_meter,
traversal_context,
&DummyCodeStorage,
)?;

Check warning on line 868 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L862-L868

Added lines #L862 - L868 were not covered by tests
Ok(())
}

Expand Down Expand Up @@ -1103,6 +1125,7 @@ impl AptosVM {
]),
gas_meter,
traversal_context,
&DummyCodeStorage,

Check warning on line 1128 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1128

Added line #L1128 was not covered by tests
)
})?
.return_values
Expand Down Expand Up @@ -1201,6 +1224,7 @@ impl AptosVM {
cleanup_args,
&mut UnmeteredGasMeter,
traversal_context,
&DummyCodeStorage,

Check warning on line 1227 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1227

Added line #L1227 was not covered by tests
)
.map_err(|e| e.into_vm_status())
})?;
Expand Down Expand Up @@ -1333,6 +1357,7 @@ impl AptosVM {
cleanup_args,
&mut UnmeteredGasMeter,
traversal_context,
&DummyCodeStorage,

Check warning on line 1360 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1360

Added line #L1360 was not covered by tests
)
.map_err(|e| e.into_vm_status())
})?;
Expand All @@ -1357,7 +1382,8 @@ impl AptosVM {
continue;
}
*new_published_modules_loaded = true;
let init_function = session.load_function(&module.self_id(), init_func_name, &[]);
let init_function =
session.load_function(&DummyCodeStorage, &module.self_id(), init_func_name, &[]);

Check warning on line 1386 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1385-L1386

Added lines #L1385 - L1386 were not covered by tests
// it is ok to not have init_module function
// init_module function should be (1) private and (2) has no return value
// Note that for historic reasons, verification here is treated
Expand All @@ -1376,6 +1402,7 @@ impl AptosVM {
args,
gas_meter,
traversal_context,
&DummyCodeStorage,

Check warning on line 1405 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1405

Added line #L1405 was not covered by tests
)?;
} else {
return Err(PartialVMError::new(StatusCode::CONSTRAINT_NOT_SATISFIED)
Expand Down Expand Up @@ -1487,6 +1514,7 @@ impl AptosVM {
.collect::<BTreeSet<_>>();

session.check_dependencies_and_charge_gas(
&DummyCodeStorage,

Check warning on line 1517 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1517

Added line #L1517 was not covered by tests
gas_meter,
traversal_context,
modules
Expand Down Expand Up @@ -1535,6 +1563,7 @@ impl AptosVM {
bundle.into_inner(),
destination,
gas_meter,
&DummyCodeStorage,

Check warning on line 1566 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L1566

Added line #L1566 was not covered by tests
Compatibility::new(
true,
!self
Expand Down Expand Up @@ -2131,6 +2160,7 @@ impl AptosVM {
args,
&mut gas_meter,
&mut TraversalContext::new(&storage),
&DummyCodeStorage,

Check warning on line 2163 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L2163

Added line #L2163 was not covered by tests
)
.map(|_return_vals| ())
.or_else(|e| {
Expand Down Expand Up @@ -2210,6 +2240,7 @@ impl AptosVM {
serialize_values(&args),
&mut gas_meter,
&mut TraversalContext::new(&storage),
&DummyCodeStorage,

Check warning on line 2243 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L2243

Added line #L2243 was not covered by tests
)
.map(|_return_vals| ())
.or_else(|e| {
Expand Down Expand Up @@ -2300,7 +2331,7 @@ impl AptosVM {
arguments: Vec<Vec<u8>>,
gas_meter: &mut impl AptosGasMeter,
) -> anyhow::Result<Vec<Vec<u8>>> {
let func = session.load_function(&module_id, &func_name, &type_args)?;
let func = session.load_function(&DummyCodeStorage, &module_id, &func_name, &type_args)?;

Check warning on line 2334 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L2334

Added line #L2334 was not covered by tests
let metadata = vm.extract_module_metadata(&module_id);
let arguments = verifier::view_function::validate_view_function(
session,
Expand All @@ -2321,6 +2352,7 @@ impl AptosVM {
arguments,
gas_meter,
&mut TraversalContext::new(&storage),
&DummyCodeStorage,

Check warning on line 2355 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L2355

Added line #L2355 was not covered by tests
)
.map_err(|err| anyhow!("Failed to execute function: {:?}", err))?
.return_values
Expand Down Expand Up @@ -2761,6 +2793,7 @@ fn create_account_if_does_not_exist(
serialize_values(&vec![MoveValue::Address(account)]),
gas_meter,
traversal_context,
&DummyCodeStorage,

Check warning on line 2796 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/aptos_vm.rs#L2796

Added line #L2796 was not covered by tests
)
.map(|_return_vals| ())
}
Expand Down
2 changes: 2 additions & 0 deletions aptos-move/aptos-vm/src/move_vm_ext/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ impl<'r, 'l> SessionExt<'r, 'l> {
let (modules, resources) = account_changeset.into_inner();

for (struct_tag, blob_op) in resources {
// TODO(George): Use ModuleStorage to resolve module metadata directly.
#[allow(deprecated)]
let resource_group_tag = runtime
.with_module_metadata(&struct_tag.module_id(), |md| {
get_resource_group_member_from_metadata(&struct_tag, md)
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-vm/src/move_vm_ext/warm_vm_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl WarmVmCache {
//
// Loading up `0x1::account` should be sufficient as this is the most common module
// used for prologue, epilogue and transfer functionality.
#[allow(deprecated)]

Check warning on line 112 in aptos-move/aptos-vm/src/move_vm_ext/warm_vm_cache.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/move_vm_ext/warm_vm_cache.rs#L112

Added line #L112 was not covered by tests
let _ = vm.load_module(
&ModuleId::new(CORE_CODE_ADDRESS, ident_str!("account").to_owned()),
resolver,
Expand Down
9 changes: 8 additions & 1 deletion aptos-move/aptos-vm/src/transaction_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use move_core_types::{
value::{serialize_values, MoveValue},
vm_status::{AbortLocation, StatusCode, VMStatus},
};
use move_vm_runtime::{logging::expect_no_verification_errors, module_traversal::TraversalContext};
use move_vm_runtime::{
logging::expect_no_verification_errors, module_traversal::TraversalContext, DummyCodeStorage,
};
use move_vm_types::gas::UnmeteredGasMeter;
use once_cell::sync::Lazy;

Expand Down Expand Up @@ -142,6 +144,7 @@ pub(crate) fn run_script_prologue(
serialize_values(&args),
&mut gas_meter,
traversal_context,
&DummyCodeStorage,

Check warning on line 147 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L147

Added line #L147 was not covered by tests
)
.map(|_return_vals| ())
.map_err(expect_no_verification_errors)
Expand Down Expand Up @@ -185,6 +188,7 @@ pub(crate) fn run_multisig_prologue(
]),
&mut UnmeteredGasMeter,
traversal_context,
&DummyCodeStorage,

Check warning on line 191 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L191

Added line #L191 was not covered by tests
)
.map(|_return_vals| ())
.map_err(expect_no_verification_errors)
Expand Down Expand Up @@ -226,6 +230,7 @@ fn run_epilogue(
serialize_values(&args),
&mut UnmeteredGasMeter,
traversal_context,
&DummyCodeStorage,

Check warning on line 233 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L233

Added line #L233 was not covered by tests
)
} else {
// Regular tx, run the normal epilogue
Expand All @@ -246,6 +251,7 @@ fn run_epilogue(
serialize_values(&args),
&mut UnmeteredGasMeter,
traversal_context,
&DummyCodeStorage,

Check warning on line 254 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L254

Added line #L254 was not covered by tests
)
}
.map(|_return_vals| ())
Expand Down Expand Up @@ -274,6 +280,7 @@ fn emit_fee_statement(
vec![bcs::to_bytes(&fee_statement).expect("Failed to serialize fee statement")],
&mut UnmeteredGasMeter,
traversal_context,
&DummyCodeStorage,

Check warning on line 283 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L283

Added line #L283 was not covered by tests
)
.map(|_return_vals| ())
}
Expand Down
6 changes: 5 additions & 1 deletion aptos-move/aptos-vm/src/validator_txns/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use move_core_types::{
value::{serialize_values, MoveValue},
vm_status::{AbortLocation, StatusCode, VMStatus},
};
use move_vm_runtime::module_traversal::{TraversalContext, TraversalStorage};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
DummyCodeStorage,
};
use move_vm_types::gas::UnmeteredGasMeter;

#[derive(Debug)]
Expand Down Expand Up @@ -114,6 +117,7 @@ impl AptosVM {
serialize_values(&args),
&mut gas_meter,
&mut TraversalContext::new(&module_storage),
&DummyCodeStorage,

Check warning on line 120 in aptos-move/aptos-vm/src/validator_txns/dkg.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/validator_txns/dkg.rs#L120

Added line #L120 was not covered by tests
)
.map_err(|e| {
expect_only_successful_execution(e, FINISH_WITH_DKG_RESULT.as_str(), log_context)
Expand Down
6 changes: 5 additions & 1 deletion aptos-move/aptos-vm/src/validator_txns/jwk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use move_core_types::{
value::{serialize_values, MoveValue},
vm_status::{AbortLocation, StatusCode, VMStatus},
};
use move_vm_runtime::module_traversal::{TraversalContext, TraversalStorage};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
DummyCodeStorage,
};
use move_vm_types::gas::UnmeteredGasMeter;
use std::collections::HashMap;

Expand Down Expand Up @@ -144,6 +147,7 @@ impl AptosVM {
serialize_values(&args),
&mut gas_meter,
&mut TraversalContext::new(&module_storage),
&DummyCodeStorage,

Check warning on line 150 in aptos-move/aptos-vm/src/validator_txns/jwk.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/validator_txns/jwk.rs#L150

Added line #L150 was not covered by tests
)
.map_err(|e| {
expect_only_successful_execution(e, UPSERT_INTO_OBSERVED_JWKS.as_str(), log_context)
Expand Down
17 changes: 10 additions & 7 deletions aptos-move/aptos-vm/src/verifier/event_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ pub(crate) fn extract_event_metadata_from_module(
session: &mut SessionExt,
module_id: &ModuleId,
) -> VMResult<HashSet<String>> {
let metadata = session.load_module(module_id).map(|module| {
CompiledModule::deserialize_with_config(
&module,
&session.get_vm_config().deserializer_config,
)
.map(|module| aptos_framework::get_metadata_from_compiled_module(&module))
});
#[allow(deprecated)]
let metadata = session
.fetch_module_from_data_store(module_id)
.map(|module| {
CompiledModule::deserialize_with_config(
&module,
&session.get_vm_config().deserializer_config,
)
.map(|module| aptos_framework::get_metadata_from_compiled_module(&module))
});

Check warning on line 132 in aptos-move/aptos-vm/src/verifier/event_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/verifier/event_validation.rs#L123-L132

Added lines #L123 - L132 were not covered by tests

if let Ok(Ok(Some(metadata))) = metadata {
extract_event_metadata(&metadata)
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-vm/src/verifier/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) fn get_randomness_annotation(
session: &mut SessionExt,
entry_fn: &EntryFunction,
) -> VMResult<Option<RandomnessAnnotation>> {
#[allow(deprecated)]
let module = session
.get_move_vm()
.load_module(entry_fn.module(), resolver)?;
Expand Down
15 changes: 9 additions & 6 deletions aptos-move/aptos-vm/src/verifier/resource_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ pub(crate) fn extract_resource_group_metadata_from_module(
BTreeMap<String, StructTag>,
BTreeSet<String>,
)> {
let module = session.load_module(module_id).map(|module| {
CompiledModule::deserialize_with_config(
&module,
&session.get_vm_config().deserializer_config,
)
});
#[allow(deprecated)]
let module = session
.fetch_module_from_data_store(module_id)
.map(|module| {
CompiledModule::deserialize_with_config(
&module,
&session.get_vm_config().deserializer_config,
)
});

Check warning on line 161 in aptos-move/aptos-vm/src/verifier/resource_groups.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/verifier/resource_groups.rs#L153-L161

Added lines #L153 - L161 were not covered by tests
let (metadata, module) = if let Ok(Ok(module)) = module {
(
aptos_framework::get_metadata_from_compiled_module(&module),
Expand Down
Loading

0 comments on commit f49e8b1

Please sign in to comment.