From 94d1b68eb6d562c8a752c000284a5c126ab2c5fb Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 15 Oct 2024 12:47:31 -0700 Subject: [PATCH] feature flag --- aptos-move/framework/move-stdlib/src/natives/vector.rs | 10 ++++++++-- .../move/move-vm/types/src/values/values_impl.rs | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/move-stdlib/src/natives/vector.rs b/aptos-move/framework/move-stdlib/src/natives/vector.rs index 06f7e4541d62ea..d53fc1c6800875 100644 --- a/aptos-move/framework/move-stdlib/src/natives/vector.rs +++ b/aptos-move/framework/move-stdlib/src/natives/vector.rs @@ -23,13 +23,15 @@ use move_vm_types::{ use smallvec::{smallvec, SmallVec}; use std::collections::VecDeque; +use super::mem::get_feature_not_available_error; + /// The generic type supplied to aggregator snapshots is not supported. pub const EINDEX_OUT_OF_BOUNDS: u64 = 0x03_0001; /*************************************************************************************************** - * native fun vector_move(from: &mut vector, removal_position: u64, length: u64, to: &mut vector, insert_position: u64) + * native fun range_move(from: &mut vector, removal_position: u64, length: u64, to: &mut vector, insert_position: u64) * - * gas cost: VECTOR_RANGE_MOVE_BASE + EINDEX_OUT_OF_BOUNDS * num_elements_to_move + * gas cost: VECTOR_RANGE_MOVE_BASE + VECTOR_RANGE_MOVE_PER_INDEX_MOVED * num_elements_to_move * **************************************************************************************************/ fn native_range_move( @@ -37,6 +39,10 @@ fn native_range_move( ty_args: Vec, mut args: VecDeque, ) -> SafeNativeResult> { + if !context.get_feature_flags().is_native_memory_operations_enabled() { + return Err(get_feature_not_available_error()); + } + context.charge(VECTOR_RANGE_MOVE_BASE)?; let map_err = |_| SafeNativeError::Abort { diff --git a/third_party/move/move-vm/types/src/values/values_impl.rs b/third_party/move/move-vm/types/src/values/values_impl.rs index eead3acf428959..a3d42830114e7b 100644 --- a/third_party/move/move-vm/types/src/values/values_impl.rs +++ b/third_party/move/move-vm/types/src/values/values_impl.rs @@ -2482,6 +2482,9 @@ impl VectorRef { ) -> PartialVMResult<()> { let from_c = self.0.container(); let to_c = to_self.0.container(); + + // potentially unnecessary as native call should've checked the types already + // (unlike other vector functions that are bytecodes) check_elem_layout(type_param, from_c)?; check_elem_layout(type_param, to_c)?;