Repository: MystenLabs/sui
File: external-crates/move/crates/move-vm-runtime/src/runtime/mod.rs (Rust)

Code before:
                        // Anything better to do here?
                        return Err(err.finish(Location::Undefined));
                    }
                };

                let virtual_tables = if let Some(vtables) =
                    self.cache.cached_linkage_tables_at(&linkage_hash)  {
                    vtables
                } else {
                    self.load_and_cache_vtables(
                        package_store, txn_telemetry, &link_context, linkage_hash
                    )?
                };

                // This is more a sanity check than anything else. The VMDispatchTables should
                // never have precomputed type depths, as those are computed on-demand.
                if !virtual_tables.type_depths.is_empty() {
                    return Err(
                        move_binary_format::errors::PartialVMError::new(
                            StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
                        .with_message("VMDispatchTables has precomputed type depths".to_string())
                        .finish(Location::Undefined)
                    );
                }

                if !(link_context == *virtual_tables.link_context) {
                    return Err(
                        move_binary_format::errors::PartialVMError::new(
                            StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
                        .with_message("Cached VMDispatchTables linkage did not match hashed linkage".to_string())
                        .finish(Location::Undefined)
                    );
                }

                // Called and checked linkage, etc.
                let instance = MoveVM {
                    virtual_tables,
                    vm_config: self.vm_config.clone(),
                    interner: self.cache.interner.clone(),
                    link_context,
                    native_extensions: native_extensions.clone(),
                    telemetry: self.telemetry.clone(),
                };
                Ok(instance)
            };
            txn_telemetry.report_time(total_timer);
            instance
        })
    }

    /// Load and cache VTables for the provided linkage context

Review comment (suggestion):
```suggestion
                if link_context != *virtual_tables.link_context {
```

Code after:
                    self.cache.cached_linkage_tables_at(&linkage_hash)  {
                    vtables
                } else {
                    self.load_and_cache_vtables(
                        package_store, txn_telemetry, &link_context, linkage_hash
                    )?
                };

                // This is more a sanity check than anything else. The VMDispatchTables should
                // never have precomputed type depths, as those are computed on-demand.
                if !virtual_tables.type_depths.is_empty() {
                    return Err(
                        PartialVMError::new(
                            StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
                        .with_message("VMDispatchTables has precomputed type depths".to_string())
                        .finish(Location::Undefined)
                    );
                }

                if link_context != *virtual_tables.link_context {
                    return Err(
                        PartialVMError::new(
                            StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
                        .with_message("Cached VMDispatchTables linkage did not match hashed linkage".to_string())
                        .finish(Location::Undefined)
                    );
                }

                // Called and checked linkage, etc.
                let instance = MoveVM {
                    virtual_tables,
                    vm_config: self.vm_config.clone(),
                    interner: self.cache.interner.clone(),
                    link_context,
                    native_extensions: native_extensions.clone(),
                    telemetry: self.telemetry.clone(),
                };
                Ok(instance)
            };
            txn_telemetry.report_time(total_timer);
            instance
        })
    }

    /// Load and cache VTables for the provided linkage context
    /// .
    /// This will:
    /// - Load (or retrieve from the cache) all packages in the linkage context,
    /// - Perform cross-package verification,
    /// - Construct VTables for them,
    /// - Cache the VTables for future use,