From 894646d93e81d741083715c28e5f42255e8b3c50 Mon Sep 17 00:00:00 2001 From: George Mitenkov Date: Fri, 11 Oct 2024 12:13:48 +0100 Subject: [PATCH] [fix] Fix module validation and traversal for verified module loading --- move-vm/runtime/src/loader/modules.rs | 4 ++-- move-vm/runtime/src/loader/script.rs | 4 ++-- move-vm/runtime/src/move_vm.rs | 2 +- .../src/storage/implementations/unsync_module_storage.rs | 2 +- move-vm/types/src/code_storage/errors.rs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/move-vm/runtime/src/loader/modules.rs b/move-vm/runtime/src/loader/modules.rs index 2a16bc1a..babffc13 100644 --- a/move-vm/runtime/src/loader/modules.rs +++ b/move-vm/runtime/src/loader/modules.rs @@ -671,8 +671,8 @@ impl Module { &self.module } - pub fn as_compiled_module(&self) -> Arc { - self.module.clone() + pub fn compiled_module(&self) -> &Arc { + &self.module } pub(crate) fn field_offset(&self, idx: FieldHandleIndex) -> usize { diff --git a/move-vm/runtime/src/loader/script.rs b/move-vm/runtime/src/loader/script.rs index 43942cfe..0564569e 100644 --- a/move-vm/runtime/src/loader/script.rs +++ b/move-vm/runtime/src/loader/script.rs @@ -170,8 +170,8 @@ impl Script { }) } - pub fn as_compiled_script(&self) -> Arc { - self.script.clone() + pub fn compiled_script(&self) -> &Arc { + &self.script } pub(crate) fn entry_point(&self) -> Arc { diff --git a/move-vm/runtime/src/move_vm.rs b/move-vm/runtime/src/move_vm.rs index b82d112a..67bd38f2 100644 --- a/move-vm/runtime/src/move_vm.rs +++ b/move-vm/runtime/src/move_vm.rs @@ -135,7 +135,7 @@ impl MoveVM { ), &ModuleStorageAdapter::new(self.runtime.module_storage_v1()), )?; - Ok(module.as_compiled_module()) + Ok(module.compiled_module().clone()) }, Loader::V2(_) => Err(PartialVMError::new( StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR, diff --git a/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs b/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs index 79926d9e..99ce4ee1 100644 --- a/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs +++ b/move-vm/runtime/src/storage/implementations/unsync_module_storage.rs @@ -321,7 +321,7 @@ impl<'e, B: ModuleBytesStorage> ModuleStorage for UnsyncModuleStorage<'e, B> { Ok(Some(match entry { Deserialized { module, .. } => module.clone(), - Verified { module } => module.as_compiled_module(), + Verified { module } => module.compiled_module().clone(), })) } diff --git a/move-vm/types/src/code_storage/errors.rs b/move-vm/types/src/code_storage/errors.rs index 301dce66..c0ad3879 100644 --- a/move-vm/types/src/code_storage/errors.rs +++ b/move-vm/types/src/code_storage/errors.rs @@ -31,7 +31,7 @@ macro_rules! module_storage_error { // the same way, but ideally we should use proper formatting here. #[macro_export] macro_rules! module_linker_error { - ($addr:ident, $name:ident) => { + ($addr:expr, $name:expr) => { move_binary_format::errors::PartialVMError::new( move_core_types::vm_status::StatusCode::LINKER_ERROR, ) @@ -46,7 +46,7 @@ macro_rules! module_linker_error { #[macro_export] macro_rules! module_cyclic_dependency_error { - ($addr:ident, $name:ident) => { + ($addr:expr, $name:expr) => { move_binary_format::errors::PartialVMError::new( move_core_types::vm_status::StatusCode::CYCLIC_MODULE_DEPENDENCY, )