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 22, 2024
1 parent 1a5d58a commit 9647453
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 @@ -733,13 +734,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 738 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#L737-L738

Added lines #L737 - L738 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 750 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#L745-L750

Added lines #L745 - L750 were not covered by tests

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

Check warning on line 792 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#L791-L792

Added lines #L791 - L792 were not covered by tests
)?;
Ok(())
}
Expand All @@ -801,14 +811,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 819 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#L814-L819

Added lines #L814 - L819 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 827 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#L822-L827

Added lines #L822 - L827 were not covered by tests

// Native entry function is forbidden.
if self
Expand Down Expand Up @@ -845,7 +861,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 870 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#L864-L870

Added lines #L864 - L870 were not covered by tests
Ok(())
}

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

Check warning on line 1130 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#L1130

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

Check warning on line 1229 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#L1229

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

Check warning on line 1368 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#L1368

Added line #L1368 was not covered by tests
)
.map_err(|e| e.into_vm_status())
})?;
Expand All @@ -1365,7 +1390,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 1394 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#L1393-L1394

Added lines #L1393 - L1394 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 @@ -1384,6 +1410,7 @@ impl AptosVM {
args,
gas_meter,
traversal_context,
&DummyCodeStorage,

Check warning on line 1413 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#L1413

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

session.check_dependencies_and_charge_gas(
&DummyCodeStorage,

Check warning on line 1525 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#L1525

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

Check warning on line 1574 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#L1574

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

Check warning on line 2171 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#L2171

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

Check warning on line 2251 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#L2251

Added line #L2251 was not covered by tests
)
.map(|_return_vals| ())
.or_else(|e| {
Expand Down Expand Up @@ -2308,7 +2339,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 2342 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#L2342

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

Check warning on line 2363 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#L2363

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

Check warning on line 2811 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#L2811

Added line #L2811 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 @@ -216,6 +218,7 @@ pub(crate) fn run_script_prologue(
serialize_values(&args),
&mut gas_meter,
traversal_context,
&DummyCodeStorage,

Check warning on line 221 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#L221

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

Check warning on line 265 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#L265

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

Check warning on line 324 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#L324

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

Check warning on line 360 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#L360

Added line #L360 was not covered by tests
)
}
.map(|_return_vals| ())
Expand Down Expand Up @@ -380,6 +386,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 389 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#L389

Added line #L389 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 9647453

Please sign in to comment.