From 4da8cadf1434797c78c316bb4379c3c96170d9d8 Mon Sep 17 00:00:00 2001 From: George Mitenkov Date: Mon, 1 Jul 2024 23:55:26 +0100 Subject: [PATCH] cherrypick (#13882) --- aptos-move/aptos-gas-schedule/src/ver.rs | 5 +++- aptos-move/aptos-vm-types/src/environment.rs | 6 ++--- aptos-move/aptos-vm/src/move_vm_ext/vm.rs | 27 +++++++------------ .../move/move-vm/runtime/src/config.rs | 2 ++ .../move/move-vm/runtime/src/loader/mod.rs | 9 ++++++- types/src/vm/configs.rs | 7 +++-- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/aptos-move/aptos-gas-schedule/src/ver.rs b/aptos-move/aptos-gas-schedule/src/ver.rs index 713f79709a6e1..a16ddbc8b1907 100644 --- a/aptos-move/aptos-gas-schedule/src/ver.rs +++ b/aptos-move/aptos-gas-schedule/src/ver.rs @@ -8,6 +8,8 @@ /// - Changing how gas is calculated in any way /// /// Change log: +/// - V21 +/// - Fix type to type tag conversion in MoveVM /// - V20 /// - Limits for bounding MoveVM type sizes /// - V19 @@ -64,7 +66,7 @@ /// global operations. /// - V1 /// - TBA -pub const LATEST_GAS_FEATURE_VERSION: u64 = 20; +pub const LATEST_GAS_FEATURE_VERSION: u64 = gas_feature_versions::RELEASE_V1_16; pub mod gas_feature_versions { pub const RELEASE_V1_8: u64 = 11; @@ -76,4 +78,5 @@ pub mod gas_feature_versions { pub const RELEASE_V1_13: u64 = 18; pub const RELEASE_V1_14: u64 = 19; pub const RELEASE_V1_15: u64 = 20; + pub const RELEASE_V1_16: u64 = 21; } diff --git a/aptos-move/aptos-vm-types/src/environment.rs b/aptos-move/aptos-vm-types/src/environment.rs index af1e3b72fabab..1438884087e18 100644 --- a/aptos-move/aptos-vm-types/src/environment.rs +++ b/aptos-move/aptos-vm-types/src/environment.rs @@ -132,14 +132,12 @@ impl Environment { chain_id: ChainId, ty_builder: TypeBuilder, ) -> Self { - // By default, do not use delayed field optimization. Instead, clients should enable it - // manually where applicable. - let delayed_field_optimization_enabled = false; + let pseudo_meter_vector_ty_to_ty_tag_construction = true; let vm_config = aptos_prod_vm_config( &features, &timed_features, - delayed_field_optimization_enabled, + pseudo_meter_vector_ty_to_ty_tag_construction, ty_builder, ); diff --git a/aptos-move/aptos-vm/src/move_vm_ext/vm.rs b/aptos-move/aptos-vm/src/move_vm_ext/vm.rs index 2a68662478123..6f70bbe796167 100644 --- a/aptos-move/aptos-vm/src/move_vm_ext/vm.rs +++ b/aptos-move/aptos-vm/src/move_vm_ext/vm.rs @@ -8,7 +8,8 @@ use crate::{ use aptos_crypto::HashValue; use aptos_gas_algebra::DynamicExpression; use aptos_gas_schedule::{ - AptosGasParameters, MiscGasParameters, NativeGasParameters, LATEST_GAS_FEATURE_VERSION, + gas_feature_versions::RELEASE_V1_16, AptosGasParameters, MiscGasParameters, + NativeGasParameters, LATEST_GAS_FEATURE_VERSION, }; use aptos_native_interface::SafeNativeBuilder; use aptos_types::{ @@ -21,7 +22,7 @@ use aptos_vm_types::{ environment::{aptos_default_ty_builder, aptos_prod_ty_builder, Environment}, storage::change_set_configs::ChangeSetConfigs, }; -use move_vm_runtime::{config::VMConfig, move_vm::MoveVM}; +use move_vm_runtime::move_vm::MoveVM; use std::{ops::Deref, sync::Arc}; /// MoveVM wrapper which is used to run genesis initializations. Designed as a @@ -39,13 +40,11 @@ impl GenesisMoveVM { let features = Features::default(); let timed_features = TimedFeaturesBuilder::enable_all().build(); - // Genesis runs sessions, where there is no concept of block execution. - // Hence, delayed fields are not enabled. - let delayed_field_optimization_enabled = false; + let pseudo_meter_vector_ty_to_ty_tag_construction = true; let vm_config = aptos_prod_vm_config( &features, &timed_features, - delayed_field_optimization_enabled, + pseudo_meter_vector_ty_to_ty_tag_construction, aptos_default_ty_builder(&features), ); @@ -142,18 +141,10 @@ impl MoveVmExt { ); // TODO(George): Move gas configs to environment to avoid this clone! - let vm_config = VMConfig { - verifier_config: env.vm_config().verifier_config.clone(), - deserializer_config: env.vm_config().deserializer_config.clone(), - paranoid_type_checks: env.vm_config().paranoid_type_checks, - check_invariant_in_swap_loc: env.vm_config().check_invariant_in_swap_loc, - max_value_nest_depth: env.vm_config().max_value_nest_depth, - type_max_cost: env.vm_config().type_max_cost, - type_base_cost: env.vm_config().type_base_cost, - type_byte_cost: env.vm_config().type_byte_cost, - delayed_field_optimization_enabled: env.vm_config().delayed_field_optimization_enabled, - ty_builder, - }; + let mut vm_config = env.vm_config().clone(); + vm_config.pseudo_meter_vector_ty_to_ty_tag_construction = + gas_feature_version >= RELEASE_V1_16; + vm_config.ty_builder = ty_builder; Self { inner: WarmVmCache::get_warm_vm( diff --git a/third_party/move/move-vm/runtime/src/config.rs b/third_party/move/move-vm/runtime/src/config.rs index 98cc0d619ebc9..7bb93a5a1ffdd 100644 --- a/third_party/move/move-vm/runtime/src/config.rs +++ b/third_party/move/move-vm/runtime/src/config.rs @@ -22,6 +22,7 @@ pub struct VMConfig { pub type_max_cost: u64, pub type_base_cost: u64, pub type_byte_cost: u64, + pub pseudo_meter_vector_ty_to_ty_tag_construction: bool, pub delayed_field_optimization_enabled: bool, pub ty_builder: TypeBuilder, } @@ -37,6 +38,7 @@ impl Default for VMConfig { type_max_cost: 0, type_base_cost: 0, type_byte_cost: 0, + pseudo_meter_vector_ty_to_ty_tag_construction: true, delayed_field_optimization_enabled: false, ty_builder: TypeBuilder::Legacy, } diff --git a/third_party/move/move-vm/runtime/src/loader/mod.rs b/third_party/move/move-vm/runtime/src/loader/mod.rs index 1a4cd9c2982b3..4c849c9af4b29 100644 --- a/third_party/move/move-vm/runtime/src/loader/mod.rs +++ b/third_party/move/move-vm/runtime/src/loader/mod.rs @@ -1647,7 +1647,14 @@ impl Loader { Type::U256 => TypeTag::U256, Type::Address => TypeTag::Address, Type::Signer => TypeTag::Signer, - Type::Vector(ty) => TypeTag::Vector(Box::new(self.type_to_type_tag(ty)?)), + Type::Vector(ty) => { + let el_ty_tag = if self.vm_config.pseudo_meter_vector_ty_to_ty_tag_construction { + self.type_to_type_tag_impl(ty, gas_context)? + } else { + self.type_to_type_tag(ty)? + }; + TypeTag::Vector(Box::new(el_ty_tag)) + }, Type::Struct { idx, .. } => TypeTag::Struct(Box::new(self.struct_name_to_type_tag( *idx, &[], diff --git a/types/src/vm/configs.rs b/types/src/vm/configs.rs index 76463a1cafe10..c48be4c7e8f75 100644 --- a/types/src/vm/configs.rs +++ b/types/src/vm/configs.rs @@ -69,7 +69,7 @@ pub fn aptos_prod_verifier_config(features: &Features) -> VerifierConfig { pub fn aptos_prod_vm_config( features: &Features, timed_features: &TimedFeatures, - delayed_field_optimization_enabled: bool, + pseudo_meter_vector_ty_to_ty_tag_construction: bool, ty_builder: TypeBuilder, ) -> VMConfig { let check_invariant_in_swap_loc = @@ -98,7 +98,10 @@ pub fn aptos_prod_vm_config( type_max_cost, type_base_cost, type_byte_cost, - delayed_field_optimization_enabled, + pseudo_meter_vector_ty_to_ty_tag_construction, + // By default, do not use delayed field optimization. Instead, clients should enable it + // manually where applicable. + delayed_field_optimization_enabled: false, ty_builder, } }