From c90dafdb2f450e4d3aa16b1a7cff8e3cad2b882e Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Thu, 9 May 2024 11:13:36 -0700 Subject: [PATCH] fix metadata (#13236) --- .../e2e-move-tests/src/tests/metadata.rs | 31 +++++++------ .../doc/primary_fungible_store.md | 44 +------------------ aptos-move/framework/src/module_metadata.rs | 11 +++-- 3 files changed, 27 insertions(+), 59 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/metadata.rs b/aptos-move/e2e-move-tests/src/tests/metadata.rs index 82541efd8b899..7c499fe762bcd 100644 --- a/aptos-move/e2e-move-tests/src/tests/metadata.rs +++ b/aptos-move/e2e-move-tests/src/tests/metadata.rs @@ -18,8 +18,10 @@ use aptos_types::{ }; use move_binary_format::CompiledModule; use move_core_types::{ - account_address::AccountAddress, language_storage::CORE_CODE_ADDRESS, metadata::Metadata, - vm_status::StatusCode, + account_address::AccountAddress, + language_storage::CORE_CODE_ADDRESS, + metadata::Metadata, + vm_status::{StatusCode, StatusCode::CONSTRAINT_NOT_SATISFIED}, }; use move_model::metadata::{CompilationMetadata, CompilerVersion, COMPILATION_METADATA_KEY}; use std::collections::BTreeMap; @@ -275,13 +277,13 @@ fn test_compilation_metadata() { test_compilation_metadata_internal(true, true, enable_check), StatusCode::UNSTABLE_BYTECODE_REJECTED ); - // publish compiler v2 code to test + // publish compiler v1 code to mainnet assert_success!(test_compilation_metadata_internal( true, false, enable_check )); - // publish compiler v1 code to mainnet + // publish compiler v2 code to test assert_success!(test_compilation_metadata_internal( false, true, @@ -296,20 +298,23 @@ fn test_compilation_metadata() { enable_check = false; // publish compiler v2 code to mainnet - // success because the feature flag is disabled - assert_success!(test_compilation_metadata_internal(true, true, enable_check)); - // publish compiler v2 code to test - assert_success!(test_compilation_metadata_internal( - true, - false, - enable_check - )); + // failed because the metadata cannot be recognized + assert_vm_status!( + test_compilation_metadata_internal(true, true, enable_check), + CONSTRAINT_NOT_SATISFIED + ); // publish compiler v1 code to mainnet assert_success!(test_compilation_metadata_internal( - false, true, + false, enable_check )); + // publish compiler v2 code to test + // failed because the metadata cannot be recognized + assert_vm_status!( + test_compilation_metadata_internal(false, true, enable_check), + CONSTRAINT_NOT_SATISFIED + ); // publish compiler v1 code to test assert_success!(test_compilation_metadata_internal( false, diff --git a/aptos-move/framework/aptos-framework/doc/primary_fungible_store.md b/aptos-move/framework/aptos-framework/doc/primary_fungible_store.md index a604a900d34c5..bb0b71f937afc 100644 --- a/aptos-move/framework/aptos-framework/doc/primary_fungible_store.md +++ b/aptos-move/framework/aptos-framework/doc/primary_fungible_store.md @@ -486,49 +486,7 @@ Transfer amount of fungible asset from sender's primary store to re // Check if the sender store object has been burnt or not. If so, unburn it first. may_be_unburn(sender, sender_store); let recipient_store = ensure_primary_store_exists(recipient, metadata); - dispatchable_fungible_asset::transfer(sender, sender_store, recipient_store, amount); -} - - - - - - - - -## Function `transfer_assert_minimum_deposit` - -Transfer amount of fungible asset from sender's primary store to receiver's primary store. -Use the minimum deposit assertion api to make sure receipient will receive a minimum amount of fund. - - -
public entry fun transfer_assert_minimum_deposit<T: key>(sender: &signer, metadata: object::Object<T>, recipient: address, amount: u64, expected: u64)
-
- - - -
-Implementation - - -
public entry fun transfer_assert_minimum_deposit<T: key>(
-    sender: &signer,
-    metadata: Object<T>,
-    recipient: address,
-    amount: u64,
-    expected: u64,
-) acquires DeriveRefPod {
-    let sender_store = ensure_primary_store_exists(signer::address_of(sender), metadata);
-    // Check if the sender store object has been burnt or not. If so, unburn it first.
-    may_be_unburn(sender, sender_store);
-    let recipient_store = ensure_primary_store_exists(recipient, metadata);
-    dispatchable_fungible_asset::transfer_assert_minimum_deposit(
-        sender,
-        sender_store,
-        recipient_store,
-        amount,
-        expected
-    );
+    fungible_asset::transfer(sender, sender_store, recipient_store, amount);
 }
 
diff --git a/aptos-move/framework/src/module_metadata.rs b/aptos-move/framework/src/module_metadata.rs index 832b16008a492..1be6ad0eb7d34 100644 --- a/aptos-move/framework/src/module_metadata.rs +++ b/aptos-move/framework/src/module_metadata.rs @@ -224,7 +224,10 @@ pub fn get_vm_metadata_v0( } /// Check if the metadata has unknown key/data types -pub fn check_metadata_format(module: &CompiledModule) -> Result<(), MalformedError> { +pub fn check_metadata_format( + module: &CompiledModule, + features: &Features, +) -> Result<(), MalformedError> { let mut exist = false; let mut compilation_key_exist = false; for data in module.metadata.iter() { @@ -241,7 +244,9 @@ pub fn check_metadata_format(module: &CompiledModule) -> Result<(), MalformedErr bcs::from_bytes::(&data.value) .map_err(|e| MalformedError::DeserializedError(data.key.clone(), e))?; } - } else if data.key == *COMPILATION_METADATA_KEY { + } else if features.is_enabled(FeatureFlag::REJECT_UNSTABLE_BYTECODE) + && data.key == *COMPILATION_METADATA_KEY + { if compilation_key_exist { return Err(MalformedError::DuplicateKey); } @@ -450,7 +455,7 @@ pub fn verify_module_metadata( } if features.are_resource_groups_enabled() { - check_metadata_format(module)?; + check_metadata_format(module, features)?; } let metadata = if let Some(metadata) = get_metadata_from_compiled_module(module) { metadata