Skip to content

Commit

Permalink
[fix] Fix module validation and traversal for verified module loading
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Oct 14, 2024
1 parent 433a89c commit 894646d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions move-vm/runtime/src/loader/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ impl Module {
&self.module
}

pub fn as_compiled_module(&self) -> Arc<CompiledModule> {
self.module.clone()
pub fn compiled_module(&self) -> &Arc<CompiledModule> {
&self.module
}

pub(crate) fn field_offset(&self, idx: FieldHandleIndex) -> usize {
Expand Down
4 changes: 2 additions & 2 deletions move-vm/runtime/src/loader/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ impl Script {
})
}

pub fn as_compiled_script(&self) -> Arc<CompiledScript> {
self.script.clone()
pub fn compiled_script(&self) -> &Arc<CompiledScript> {
&self.script
}

pub(crate) fn entry_point(&self) -> Arc<Function> {
Expand Down
2 changes: 1 addition & 1 deletion move-vm/runtime/src/move_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}))
}

Expand Down
4 changes: 2 additions & 2 deletions move-vm/types/src/code_storage/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down

0 comments on commit 894646d

Please sign in to comment.