From 2cd733c622916e2210f9fc511ad54b6b0c848c8a Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 26 May 2023 16:39:43 -0500 Subject: [PATCH 01/61] Add native function create_guid --- aptos-move/aptos-vm/src/move_vm_ext/vm.rs | 6 +- aptos-move/aptos-vm/src/natives.rs | 6 +- .../doc/transaction_context.md | 24 +++++++ .../sources/transaction_context.move | 3 + aptos-move/framework/src/natives/mod.rs | 1 + .../src/natives/transaction_context.rs | 72 ++++++++++++++++--- 6 files changed, 100 insertions(+), 12 deletions(-) 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 60c7fce288a62..d345666868788 100644 --- a/aptos-move/aptos-vm/src/move_vm_ext/vm.rs +++ b/aptos-move/aptos-vm/src/move_vm_ext/vm.rs @@ -112,7 +112,11 @@ impl MoveVmExt { _ => vec![], }; - extensions.add(NativeTransactionContext::new(script_hash, self.chain_id)); + extensions.add(NativeTransactionContext::new( + txn_hash.to_vec(), + script_hash, + self.chain_id, + )); extensions.add(NativeCodeContext::default()); extensions.add(NativeStateStorageContext::new(remote)); diff --git a/aptos-move/aptos-vm/src/natives.rs b/aptos-move/aptos-vm/src/natives.rs index eb4dfef998e23..4ee79f9a027dc 100644 --- a/aptos-move/aptos-vm/src/natives.rs +++ b/aptos-move/aptos-vm/src/natives.rs @@ -91,7 +91,11 @@ pub fn configure_for_unit_test() { #[cfg(feature = "testing")] fn unit_test_extensions_hook(exts: &mut NativeContextExtensions) { exts.add(NativeCodeContext::default()); - exts.add(NativeTransactionContext::new(vec![1], ChainId::test().id())); // We use the testing environment chain ID here + exts.add(NativeTransactionContext::new( + vec![1], + vec![1], + ChainId::test().id(), + )); // We use the testing environment chain ID here exts.add(NativeAggregatorContext::new( [0; 32], &*DUMMY_RESOLVER, diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 981c01a44b618..49fdb9535fe05 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -5,6 +5,7 @@ +- [Function `create_guid`](#0x1_transaction_context_create_guid) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Specification](#@Specification_0) - [Function `get_script_hash`](#@Specification_0_get_script_hash) @@ -14,6 +15,29 @@ + + +## Function `create_guid` + +Return a globally unique identifier + + +
public fun create_guid(): address
+
+ + + +
+Implementation + + +
public native fun create_guid(): address;
+
+ + + +
+ ## Function `get_script_hash` diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 45a371148cae0..8e58ea2e8a61e 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -1,4 +1,7 @@ module aptos_framework::transaction_context { + /// Return a globally unique identifier + public native fun create_guid(): address; + /// Return the script hash of the current entry function. public native fun get_script_hash(): vector; } diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index 2089364b927ca..cd0dd8814abf5 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -227,6 +227,7 @@ impl GasParameters { }, transaction_context: transaction_context::GasParameters { get_script_hash: transaction_context::GetScriptHashGasParameters { base: 0.into() }, + create_guid: transaction_context::CreateGUIDGasParameters { base: 0.into() }, }, code: code::GasParameters { request_publish: code::RequestPublishGasParameters { diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index ca6f2d970e727..3796ba3e628c8 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -4,9 +4,10 @@ use crate::natives::helpers::{make_safe_native, SafeNativeContext, SafeNativeResult}; use aptos_types::on_chain_config::{Features, TimedFeatures}; use better_any::{Tid, TidAble}; -use move_core_types::gas_algebra::InternalGas; +use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas}; use move_vm_runtime::native_functions::NativeFunction; use move_vm_types::{loaded_data::runtime_types::Type, values::Value}; +use sha2::{Digest, Sha256}; use smallvec::{smallvec, SmallVec}; use std::{collections::VecDeque, fmt::Debug, sync::Arc}; @@ -15,6 +16,9 @@ use std::{collections::VecDeque, fmt::Debug, sync::Arc}; /// natives of this extension. #[derive(Tid)] pub struct NativeTransactionContext { + txn_hash: Vec, + /// This is the number of GUIDs (Globally unique identifiers) issued during the execution of this transaction + guid_counter: u64, script_hash: Vec, chain_id: u8, } @@ -22,8 +26,10 @@ pub struct NativeTransactionContext { impl NativeTransactionContext { /// Create a new instance of a native transaction context. This must be passed in via an /// extension into VM session functions. - pub fn new(script_hash: Vec, chain_id: u8) -> Self { + pub fn new(txn_hash: Vec, script_hash: Vec, chain_id: u8) -> Self { Self { + txn_hash, + guid_counter: 0, script_hash, chain_id, } @@ -34,6 +40,40 @@ impl NativeTransactionContext { } } +/*************************************************************************************************** + * native fun create_guid + * + * gas cost: base_cost + * + **************************************************************************************************/ +#[derive(Clone, Debug)] +pub struct CreateGUIDGasParameters { + pub base: InternalGas, +} + +fn native_create_guid( + gas_params: &CreateGUIDGasParameters, + context: &mut SafeNativeContext, + mut _ty_args: Vec, + _args: VecDeque, +) -> SafeNativeResult> { + context.charge(gas_params.base)?; + + let mut transaction_context = context + .extensions_mut() + .get_mut::(); + transaction_context.guid_counter += 1; + let mut hash_arg = Vec::new(); + hash_arg.extend(transaction_context.txn_hash.clone()); + hash_arg.extend(transaction_context.guid_counter.to_le_bytes().to_vec()); + let hash_vec = Sha256::digest(hash_arg.as_slice()).to_vec(); + Ok(smallvec![Value::address(AccountAddress::new( + hash_vec + .try_into() + .expect("Unable to convert hash vector into [u8]") + ))]) +} + /*************************************************************************************************** * native fun get_script_hash * @@ -67,6 +107,7 @@ fn native_get_script_hash( #[derive(Debug, Clone)] pub struct GasParameters { pub get_script_hash: GetScriptHashGasParameters, + pub create_guid: CreateGUIDGasParameters, } pub fn make_all( @@ -74,15 +115,26 @@ pub fn make_all( timed_features: TimedFeatures, features: Arc, ) -> impl Iterator { - let natives = [( - "get_script_hash", - make_safe_native( - gas_params.get_script_hash, - timed_features, - features, - native_get_script_hash, + let natives = [ + ( + "get_script_hash", + make_safe_native( + gas_params.get_script_hash, + timed_features.clone(), + features.clone(), + native_get_script_hash, + ), + ), + ( + "create_guid", + make_safe_native( + gas_params.create_guid, + timed_features, + features, + native_create_guid, + ), ), - )]; + ]; crate::natives::helpers::make_module_natives(natives) } From 3decce033d15e89cbed90948bbdaeba018bcc466 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 27 May 2023 11:34:08 -0500 Subject: [PATCH 02/61] Append a constant to hash_arg --- aptos-move/framework/src/natives/transaction_context.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 3796ba3e628c8..1b75bfbae79bd 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -63,7 +63,10 @@ fn native_create_guid( .extensions_mut() .get_mut::(); transaction_context.guid_counter += 1; + const OBJECT_FROM_TRANSACTION_GUID_ADDRESS_SCHEME: u8 = 0xFB; + let mut hash_arg = Vec::new(); + hash_arg.push(OBJECT_FROM_TRANSACTION_GUID_ADDRESS_SCHEME); hash_arg.extend(transaction_context.txn_hash.clone()); hash_arg.extend(transaction_context.guid_counter.to_le_bytes().to_vec()); let hash_vec = Sha256::digest(hash_arg.as_slice()).to_vec(); From c9b68ec242dba2033ccbfd873ab94ba9ea591859 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 27 May 2023 14:23:16 -0500 Subject: [PATCH 03/61] Add move test to verify uniqueness of guids --- aptos-move/e2e-move-tests/src/lib.rs | 1 + aptos-move/e2e-move-tests/src/tests/mod.rs | 1 + .../tests/transaction_context.data/Move.toml | 6 +++++ .../sources/transaction_context_test.move | 25 +++++++++++++++++ .../src/tests/transaction_context.rs | 20 ++++++++++++++ .../e2e-move-tests/src/transaction_context.rs | 27 +++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml create mode 100644 aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move create mode 100644 aptos-move/e2e-move-tests/src/tests/transaction_context.rs create mode 100644 aptos-move/e2e-move-tests/src/transaction_context.rs diff --git a/aptos-move/e2e-move-tests/src/lib.rs b/aptos-move/e2e-move-tests/src/lib.rs index be3971b7feae2..3370007b50d66 100644 --- a/aptos-move/e2e-move-tests/src/lib.rs +++ b/aptos-move/e2e-move-tests/src/lib.rs @@ -4,6 +4,7 @@ pub mod aggregator; pub mod harness; pub mod stake; +pub mod transaction_context; pub mod transaction_fee; use anyhow::bail; diff --git a/aptos-move/e2e-move-tests/src/tests/mod.rs b/aptos-move/e2e-move-tests/src/tests/mod.rs index 464c8c6ca018a..e032517363638 100644 --- a/aptos-move/e2e-move-tests/src/tests/mod.rs +++ b/aptos-move/e2e-move-tests/src/tests/mod.rs @@ -35,6 +35,7 @@ mod state_metadata; mod string_args; mod token_event_store; mod token_objects; +mod transaction_context; mod transaction_fee; mod type_too_large; mod vector_numeric_address; diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml new file mode 100644 index 0000000000000..f98dd748225f9 --- /dev/null +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml @@ -0,0 +1,6 @@ +[package] +name = "transaction_context_test" +version = "0.0.0" + +[dependencies] +AptosFramework = { local = "../../../../framework/aptos-framework" } diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move new file mode 100644 index 0000000000000..8bc8eeb7f08f3 --- /dev/null +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -0,0 +1,25 @@ +module 0x1::transaction_context_test { + use std::vector; + use aptos_framework::transaction_context::create_guid; + + /// When checking the value of aggregator fails. + const ENOT_UNIQUE: u64 = 20; + + public entry fun create_many_guids(_account: &signer, count: u64) { + let guids: vector
= vector
[]; + let i: u64 = 0; + while (i < count) { + i = i+1; + vector::push_back(&mut guids, create_guid()); + }; + i = 0; + while (i < count - 1) { + let j: u64 = i + 1; + while (j < count) { + assert!(*vector::borrow(&guids, i) != *vector::borrow(&guids, j), ENOT_UNIQUE); + j = j + 1; + }; + i = i + 1; + }; + } +} diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs new file mode 100644 index 0000000000000..820f779ac8afd --- /dev/null +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs @@ -0,0 +1,20 @@ +use crate::{ + assert_success, + tests::common, + transaction_context::{create_many_guids, initialize}, + MoveHarness, +}; +use aptos_language_e2e_tests::account::Account; + +fn setup() -> (MoveHarness, Account) { + initialize(common::test_dir_path("transaction_context.data")) +} + +#[test] +fn test_many_unique_guids() { + let (mut h, acc) = setup(); + + let txn1 = create_many_guids(&mut h, &acc, 50); + + assert_success!(h.run(txn1)); +} diff --git a/aptos-move/e2e-move-tests/src/transaction_context.rs b/aptos-move/e2e-move-tests/src/transaction_context.rs new file mode 100644 index 0000000000000..dd916112134ee --- /dev/null +++ b/aptos-move/e2e-move-tests/src/transaction_context.rs @@ -0,0 +1,27 @@ +// Copyright © Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +use crate::{assert_success, harness::MoveHarness}; +use aptos_language_e2e_tests::account::Account; +use aptos_types::{account_address::AccountAddress, transaction::SignedTransaction}; +use std::path::PathBuf; + +pub fn initialize(path: PathBuf) -> (MoveHarness, Account) { + let mut harness = MoveHarness::new(); + let account = harness.new_account_at(AccountAddress::ONE); + assert_success!(harness.publish_package(&account, &path)); + (harness, account) +} + +pub fn create_many_guids( + harness: &mut MoveHarness, + account: &Account, + count: u64, +) -> SignedTransaction { + harness.create_entry_function( + account, + str::parse("0x1::transaction_context_test::create_many_guids").unwrap(), + vec![], + vec![bcs::to_bytes(&count).unwrap()], + ) +} From 4c4ef51f6de372c743dcb38abff9894988299707 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 27 May 2023 18:37:59 -0500 Subject: [PATCH 04/61] Charging gas for create_guid method --- aptos-move/aptos-gas/src/aptos_framework.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index 478eef0ec8908..ab96430e660c2 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -164,6 +164,9 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.util.from_bytes.per_byte, "util.from_bytes.per_byte", 5 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], + // Using SHA2-256's cost + [.transaction_context.create_guid.base, "transaction_context.create_guid.base", 3000 * MUL], + [.transaction_context.create_guid.per_byte, { 4.. => "transaction_context.create_guid.per_byte" }, 50], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], From 2284e552b436f483cc7a902b786a0bffe432fdf1 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 27 May 2023 18:42:37 -0500 Subject: [PATCH 05/61] Add gas for create guid --- aptos-move/aptos-gas/src/aptos_framework.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index ab96430e660c2..5a0b5d838d3f1 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -166,7 +166,6 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost [.transaction_context.create_guid.base, "transaction_context.create_guid.base", 3000 * MUL], - [.transaction_context.create_guid.per_byte, { 4.. => "transaction_context.create_guid.per_byte" }, 50], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], From 2f0d2eb27c88ae1fc5eff66edfd539556379a9e5 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 27 May 2023 23:01:01 -0500 Subject: [PATCH 06/61] Add create_guid to object.move --- aptos-move/framework/aptos-framework/doc/object.md | 9 +++++---- aptos-move/framework/aptos-framework/sources/object.move | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 8c536b58778f6..15076bafcc6ce 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -78,8 +78,7 @@ make it so that a reference to a global object can be returned from a function. - [Function `exists_at`](#@Specification_1_exists_at) -
use 0x1::account;
-use 0x1::bcs;
+
use 0x1::bcs;
 use 0x1::create_signer;
 use 0x1::error;
 use 0x1::event;
@@ -87,6 +86,7 @@ make it so that a reference to a global object can be returned from a function.
 use 0x1::guid;
 use 0x1::hash;
 use 0x1::signer;
+use 0x1::transaction_context;
 use 0x1::vector;
 
@@ -845,8 +845,9 @@ Create a new object from a GUID generated by an account.
public fun create_object_from_account(creator: &signer): ConstructorRef {
-    let guid = account::create_guid(creator);
-    create_object_from_guid(signer::address_of(creator), guid)
+    let guid_creation_num = INIT_GUID_CREATION_NUM;
+    let object_guid = guid::create(aptos_framework::transaction_context::create_guid(), &mut guid_creation_num);
+    create_object_from_guid(signer::address_of(creator), object_guid)
 }
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 9f61e3b6bfbe1..287dfcd999ad9 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -21,7 +21,6 @@ module aptos_framework::object { use std::signer; use std::vector; - use aptos_framework::account; use aptos_framework::create_signer::create_signer; use aptos_framework::event; use aptos_framework::from_bcs; @@ -212,8 +211,9 @@ module aptos_framework::object { /// Create a new object from a GUID generated by an account. public fun create_object_from_account(creator: &signer): ConstructorRef { - let guid = account::create_guid(creator); - create_object_from_guid(signer::address_of(creator), guid) + let guid_creation_num = INIT_GUID_CREATION_NUM; + let object_guid = guid::create(aptos_framework::transaction_context::create_guid(), &mut guid_creation_num); + create_object_from_guid(signer::address_of(creator), object_guid) } /// Create a new object from a GUID generated by an object. From 80b7cbbd6a9e6528ed55ded49abb963507f08112 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 31 May 2023 10:06:02 -0500 Subject: [PATCH 07/61] Change GUID to UUID --- aptos-move/aptos-gas/src/aptos_framework.rs | 2 +- .../framework/aptos-framework/doc/object.md | 2 +- .../doc/transaction_context.md | 12 ++++---- .../aptos-framework/sources/object.move | 2 +- .../sources/transaction_context.move | 4 +-- aptos-move/framework/src/natives/mod.rs | 2 +- .../src/natives/transaction_context.rs | 30 +++++++++---------- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index 5a0b5d838d3f1..ac8b2f93a777a 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -165,7 +165,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost - [.transaction_context.create_guid.base, "transaction_context.create_guid.base", 3000 * MUL], + [.transaction_context.create_uuid.base, "transaction_context.create_uuid.base", 3000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 15076bafcc6ce..5e065cbdb2ffa 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -846,7 +846,7 @@ Create a new object from a GUID generated by an account.
public fun create_object_from_account(creator: &signer): ConstructorRef {
     let guid_creation_num = INIT_GUID_CREATION_NUM;
-    let object_guid = guid::create(aptos_framework::transaction_context::create_guid(), &mut guid_creation_num);
+    let object_guid = guid::create(aptos_framework::transaction_context::create_uuid(), &mut guid_creation_num);
     create_object_from_guid(signer::address_of(creator), object_guid)
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 49fdb9535fe05..f97cf31f8ff54 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -5,7 +5,7 @@ -- [Function `create_guid`](#0x1_transaction_context_create_guid) +- [Function `create_uuid`](#0x1_transaction_context_create_uuid) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Specification](#@Specification_0) - [Function `get_script_hash`](#@Specification_0_get_script_hash) @@ -15,14 +15,14 @@ - + -## Function `create_guid` +## Function `create_uuid` -Return a globally unique identifier +Return a universally unique identifier -
public fun create_guid(): address
+
public fun create_uuid(): address
 
@@ -31,7 +31,7 @@ Return a globally unique identifier Implementation -
public native fun create_guid(): address;
+
public native fun create_uuid(): address;
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 287dfcd999ad9..d5909030f8e8b 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -212,7 +212,7 @@ module aptos_framework::object { /// Create a new object from a GUID generated by an account. public fun create_object_from_account(creator: &signer): ConstructorRef { let guid_creation_num = INIT_GUID_CREATION_NUM; - let object_guid = guid::create(aptos_framework::transaction_context::create_guid(), &mut guid_creation_num); + let object_guid = guid::create(aptos_framework::transaction_context::create_uuid(), &mut guid_creation_num); create_object_from_guid(signer::address_of(creator), object_guid) } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 8e58ea2e8a61e..ce3eb83c84211 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -1,6 +1,6 @@ module aptos_framework::transaction_context { - /// Return a globally unique identifier - public native fun create_guid(): address; + /// Return a universally unique identifier + public native fun create_uuid(): address; /// Return the script hash of the current entry function. public native fun get_script_hash(): vector; diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index cd0dd8814abf5..d4f60a23ec8e0 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -227,7 +227,7 @@ impl GasParameters { }, transaction_context: transaction_context::GasParameters { get_script_hash: transaction_context::GetScriptHashGasParameters { base: 0.into() }, - create_guid: transaction_context::CreateGUIDGasParameters { base: 0.into() }, + create_uuid: transaction_context::CreateUUIDGasParameters { base: 0.into() }, }, code: code::GasParameters { request_publish: code::RequestPublishGasParameters { diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 1b75bfbae79bd..8d023068e08e5 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -17,8 +17,8 @@ use std::{collections::VecDeque, fmt::Debug, sync::Arc}; #[derive(Tid)] pub struct NativeTransactionContext { txn_hash: Vec, - /// This is the number of GUIDs (Globally unique identifiers) issued during the execution of this transaction - guid_counter: u64, + /// This is the number of UUIDs (Universally unique identifiers) issued during the execution of this transaction + uuid_counter: u64, script_hash: Vec, chain_id: u8, } @@ -29,7 +29,7 @@ impl NativeTransactionContext { pub fn new(txn_hash: Vec, script_hash: Vec, chain_id: u8) -> Self { Self { txn_hash, - guid_counter: 0, + uuid_counter: 0, script_hash, chain_id, } @@ -41,18 +41,18 @@ impl NativeTransactionContext { } /*************************************************************************************************** - * native fun create_guid + * native fun create_uuid * * gas cost: base_cost * **************************************************************************************************/ #[derive(Clone, Debug)] -pub struct CreateGUIDGasParameters { +pub struct CreateUUIDGasParameters { pub base: InternalGas, } -fn native_create_guid( - gas_params: &CreateGUIDGasParameters, +fn native_create_uuid( + gas_params: &CreateUUIDGasParameters, context: &mut SafeNativeContext, mut _ty_args: Vec, _args: VecDeque, @@ -62,13 +62,13 @@ fn native_create_guid( let mut transaction_context = context .extensions_mut() .get_mut::(); - transaction_context.guid_counter += 1; - const OBJECT_FROM_TRANSACTION_GUID_ADDRESS_SCHEME: u8 = 0xFB; + transaction_context.uuid_counter += 1; + const OBJECT_FROM_TRANSACTION_UUID_ADDRESS_SCHEME: u8 = 0xFB; let mut hash_arg = Vec::new(); - hash_arg.push(OBJECT_FROM_TRANSACTION_GUID_ADDRESS_SCHEME); + hash_arg.push(OBJECT_FROM_TRANSACTION_UUID_ADDRESS_SCHEME); hash_arg.extend(transaction_context.txn_hash.clone()); - hash_arg.extend(transaction_context.guid_counter.to_le_bytes().to_vec()); + hash_arg.extend(transaction_context.uuid_counter.to_le_bytes().to_vec()); let hash_vec = Sha256::digest(hash_arg.as_slice()).to_vec(); Ok(smallvec![Value::address(AccountAddress::new( hash_vec @@ -110,7 +110,7 @@ fn native_get_script_hash( #[derive(Debug, Clone)] pub struct GasParameters { pub get_script_hash: GetScriptHashGasParameters, - pub create_guid: CreateGUIDGasParameters, + pub create_uuid: CreateUUIDGasParameters, } pub fn make_all( @@ -129,12 +129,12 @@ pub fn make_all( ), ), ( - "create_guid", + "create_uuid", make_safe_native( - gas_params.create_guid, + gas_params.create_uuid, timed_features, features, - native_create_guid, + native_create_uuid, ), ), ]; From 4d7c56495abad86d9420b5cb4ffa3d5ca18304c7 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 31 May 2023 10:12:59 -0500 Subject: [PATCH 08/61] Change GUID to UUID in tests --- .../sources/transaction_context_test.move | 10 +++++----- .../e2e-move-tests/src/tests/transaction_context.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index 8bc8eeb7f08f3..e8d65a66b9313 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -1,22 +1,22 @@ module 0x1::transaction_context_test { use std::vector; - use aptos_framework::transaction_context::create_guid; + use aptos_framework::transaction_context::create_uuid; /// When checking the value of aggregator fails. const ENOT_UNIQUE: u64 = 20; - public entry fun create_many_guids(_account: &signer, count: u64) { - let guids: vector
= vector
[]; + public entry fun create_many_uuids(_account: &signer, count: u64) { + let uuids: vector
= vector
[]; let i: u64 = 0; while (i < count) { i = i+1; - vector::push_back(&mut guids, create_guid()); + vector::push_back(&mut uuids, create_uuid()); }; i = 0; while (i < count - 1) { let j: u64 = i + 1; while (j < count) { - assert!(*vector::borrow(&guids, i) != *vector::borrow(&guids, j), ENOT_UNIQUE); + assert!(*vector::borrow(&uuids, i) != *vector::borrow(&uuids, j), ENOT_UNIQUE); j = j + 1; }; i = i + 1; diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs index 820f779ac8afd..cb86774d97863 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs @@ -1,7 +1,7 @@ use crate::{ assert_success, tests::common, - transaction_context::{create_many_guids, initialize}, + transaction_context::{create_many_uuids, initialize}, MoveHarness, }; use aptos_language_e2e_tests::account::Account; @@ -11,10 +11,10 @@ fn setup() -> (MoveHarness, Account) { } #[test] -fn test_many_unique_guids() { +fn test_many_unique_uuids() { let (mut h, acc) = setup(); - let txn1 = create_many_guids(&mut h, &acc, 50); + let txn1 = create_many_uuids(&mut h, &acc, 50); assert_success!(h.run(txn1)); } From b79d4bcbe876b214b2f9482bbfc77394923fe078 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 31 May 2023 10:14:54 -0500 Subject: [PATCH 09/61] Change GUID to UUID in tests --- aptos-move/e2e-move-tests/src/transaction_context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/transaction_context.rs b/aptos-move/e2e-move-tests/src/transaction_context.rs index dd916112134ee..961d4daa95dec 100644 --- a/aptos-move/e2e-move-tests/src/transaction_context.rs +++ b/aptos-move/e2e-move-tests/src/transaction_context.rs @@ -13,14 +13,14 @@ pub fn initialize(path: PathBuf) -> (MoveHarness, Account) { (harness, account) } -pub fn create_many_guids( +pub fn create_many_uuids( harness: &mut MoveHarness, account: &Account, count: u64, ) -> SignedTransaction { harness.create_entry_function( account, - str::parse("0x1::transaction_context_test::create_many_guids").unwrap(), + str::parse("0x1::transaction_context_test::create_many_uuids").unwrap(), vec![], vec![bcs::to_bytes(&count).unwrap()], ) From 631d66d363c0db7482c60f6d5a8f6e08109464a1 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 31 May 2023 10:20:05 -0500 Subject: [PATCH 10/61] Add create_object method in object.move --- .../framework/aptos-framework/sources/object.move | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index d5909030f8e8b..f26e2f6a42fcc 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -209,11 +209,16 @@ module aptos_framework::object { create_object_internal(creator_address, obj_addr, false) } + /// Create a new object by generating a random UUID based on transaction hash + public fun create_object(creator: &signer): ConstructorRef { + let uuid = aptos_framework::transaction_context::create_uuid(); + create_object_internal(signer::address_of(creator), uuid, true) + } + /// Create a new object from a GUID generated by an account. public fun create_object_from_account(creator: &signer): ConstructorRef { - let guid_creation_num = INIT_GUID_CREATION_NUM; - let object_guid = guid::create(aptos_framework::transaction_context::create_uuid(), &mut guid_creation_num); - create_object_from_guid(signer::address_of(creator), object_guid) + let guid = account::create_guid(); + create_object_from_guid(signer::address_of(creator), guid) } /// Create a new object from a GUID generated by an object. From bdfaa5576a203670a124052ed27ab0f6ee5c72a8 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 31 May 2023 10:20:57 -0500 Subject: [PATCH 11/61] Fix typo --- aptos-move/framework/aptos-framework/sources/object.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index f26e2f6a42fcc..f7e39d55eb68e 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -217,7 +217,7 @@ module aptos_framework::object { /// Create a new object from a GUID generated by an account. public fun create_object_from_account(creator: &signer): ConstructorRef { - let guid = account::create_guid(); + let guid = account::create_guid(creator); create_object_from_guid(signer::address_of(creator), guid) } From 90f30db1972cf487a0452f6a379198e597472ca7 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 31 May 2023 10:21:36 -0500 Subject: [PATCH 12/61] Fix typo --- aptos-move/framework/aptos-framework/sources/object.move | 1 + 1 file changed, 1 insertion(+) diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index f7e39d55eb68e..062e6ed736795 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -21,6 +21,7 @@ module aptos_framework::object { use std::signer; use std::vector; + use aptos_framework::account; use aptos_framework::create_signer::create_signer; use aptos_framework::event; use aptos_framework::from_bcs; From 0a00af6ded4e80e5755cf306cfc24c9b8ad7982f Mon Sep 17 00:00:00 2001 From: geekflyer Date: Sat, 3 Jun 2023 17:55:42 -0700 Subject: [PATCH 13/61] fix trigger condition for build jobs --- .github/workflows/docker-build-test.yaml | 93 +++++++++++------------- 1 file changed, 43 insertions(+), 50 deletions(-) diff --git a/.github/workflows/docker-build-test.yaml b/.github/workflows/docker-build-test.yaml index 80f7ab8d936d9..bbcf9f388e16b 100644 --- a/.github/workflows/docker-build-test.yaml +++ b/.github/workflows/docker-build-test.yaml @@ -171,43 +171,8 @@ jobs: FEATURES: consensus-only-perf-test BUILD_ADDL_TESTING_IMAGES: true - rust-images-all: - needs: - [ - determine-docker-build-metadata, - rust-images, - rust-images-indexer, - rust-images-failpoints, - rust-images-performance, - rust-images-consensus-only-perf-test, - ] - if: always() # this ensures that the job will run even if the previous jobs were skipped - runs-on: ubuntu-latest - steps: - - name: fail if rust-images job failed - if: ${{ needs.rust-images.result == 'failure' }} - run: exit 1 - - name: fail if rust-images-indexer job failed - if: ${{ needs.rust-images-indexer.result == 'failure' }} - run: exit 1 - - name: fail if rust-images-failpoints job failed - if: ${{ needs.rust-images-failpoints.result == 'failure' }} - run: exit 1 - - name: fail if rust-images-performance job failed - if: ${{ needs.rust-images-performance.result == 'failure' }} - run: exit 1 - - name: fail if rust-images-consensus-only-perf-test job failed - if: ${{ needs.rust-images-consensus-only-perf-test.result == 'failure' }} - run: exit 1 - outputs: - rustImagesResult: ${{ needs.rust-images.result }} - rustImagesIndexerResult: ${{ needs.rust-images-indexer.result }} - rustImagesFailpointsResult: ${{ needs.rust-images-failpoints.result }} - rustImagesPerformanceResult: ${{ needs.rust-images-performance.result }} - rustImagesConsensusOnlyPerfTestResult: ${{ needs.rust-images-consensus-only-perf-test.result }} - sdk-release: - needs: [rust-images, determine-docker-build-metadata] # runs with the default release docker build variant "rust-images" + needs: [permission-check, rust-images, determine-docker-build-metadata] # runs with the default release docker build variant "rust-images" if: | (github.event_name == 'push' && github.ref_name != 'main') || github.event_name == 'workflow_dispatch' || @@ -220,7 +185,7 @@ jobs: GIT_SHA: ${{ needs.determine-docker-build-metadata.outputs.gitSha }} cli-e2e-tests: - needs: [rust-images, determine-docker-build-metadata] # runs with the default release docker build variant "rust-images" + needs: [permission-check, rust-images, determine-docker-build-metadata] # runs with the default release docker build variant "rust-images" if: | !contains(github.event.pull_request.labels.*.name, 'CICD:skip-sdk-integration-test') && ( github.event_name == 'push' || @@ -235,7 +200,7 @@ jobs: GIT_SHA: ${{ needs.determine-docker-build-metadata.outputs.gitSha }} indexer-grpc-e2e-tests: - needs: [rust-images, determine-docker-build-metadata] # runs with the default release docker build variant "rust-images" + needs: [permission-check, rust-images, determine-docker-build-metadata] # runs with the default release docker build variant "rust-images" if: | (github.event_name == 'push' && github.ref_name != 'main') || github.event_name == 'workflow_dispatch' || @@ -248,9 +213,16 @@ jobs: GIT_SHA: ${{ needs.determine-docker-build-metadata.outputs.gitSha }} forge-e2e-test: - needs: [rust-images-all, determine-docker-build-metadata] - if: | # always() ensures that the job will run even if some of the previous docker variant build jobs were skipped https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions - always() && needs.rust-images-all.result == 'success' && ( + needs: + - permission-check + - determine-docker-build-metadata + - rust-images + - rust-images-indexer + - rust-images-failpoints + - rust-images-performance + - rust-images-consensus-only-perf-test + if: | + !failure() && !cancelled() && needs.permission-check.result == 'success' && ( (github.event_name == 'push' && github.ref_name != 'main') || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'CICD:run-e2e-tests') || @@ -272,9 +244,16 @@ jobs: # Run e2e compat test against testnet branch forge-compat-test: - needs: [rust-images-all, determine-docker-build-metadata] - if: | # always() ensures that the job will run even if some of the previous docker variant build jobs were skipped https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions - always() && needs.rust-images-all.result == 'success' && ( + needs: + - permission-check + - determine-docker-build-metadata + - rust-images + - rust-images-indexer + - rust-images-failpoints + - rust-images-performance + - rust-images-consensus-only-perf-test + if: | + !failure() && !cancelled() && needs.permission-check.result == 'success' && ( (github.event_name == 'push' && github.ref_name != 'main') || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'CICD:run-e2e-tests') || @@ -293,9 +272,16 @@ jobs: # Run forge framework upgradability test forge-framework-upgrade-test: - needs: [rust-images-all, determine-docker-build-metadata] - if: | # always() ensures that the job will run even if some of the previous docker variant build jobs were skipped https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions - always() && needs.rust-images-all.result == 'success' && ( + needs: + - permission-check + - determine-docker-build-metadata + - rust-images + - rust-images-indexer + - rust-images-failpoints + - rust-images-performance + - rust-images-consensus-only-perf-test + if: | + !failure() && !cancelled() && needs.permission-check.result == 'success' && ( (github.event_name == 'push' && github.ref_name != 'main') || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'CICD:run-e2e-tests') || @@ -313,9 +299,16 @@ jobs: FORGE_NAMESPACE: forge-framework-upgrade-${{ needs.determine-docker-build-metadata.outputs.targetCacheId }} forge-consensus-only-perf-test: - needs: [rust-images-all, determine-docker-build-metadata] - if: | # always() ensures that the job will run even if some of the previous docker variant build jobs were skipped https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions - always() && needs.rust-images-all.result == 'success' && + needs: + - permission-check + - determine-docker-build-metadata + - rust-images + - rust-images-indexer + - rust-images-failpoints + - rust-images-performance + - rust-images-consensus-only-perf-test + if: | + !failure() && !cancelled() && needs.permission-check.result == 'success' && contains(github.event.pull_request.labels.*.name, 'CICD:run-consensus-only-perf-test') uses: aptos-labs/aptos-core/.github/workflows/workflow-run-forge.yaml@main secrets: inherit From f02858f7e5c4a1cd786930ab3c51cdbeb74adcb9 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 5 Jun 2023 10:42:52 -0500 Subject: [PATCH 14/61] Add native_get_txn_hash --- aptos-move/aptos-gas/src/aptos_framework.rs | 1 + .../framework/aptos-framework/doc/object.md | 35 ++++++++++++++-- aptos-move/framework/src/natives/mod.rs | 1 + .../src/natives/transaction_context.rs | 42 ++++++++++++++++++- 4 files changed, 74 insertions(+), 5 deletions(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index ac8b2f93a777a..02bc5c49f9804 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -163,6 +163,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.util.from_bytes.base, "util.from_bytes.base", 300 * MUL], [.util.from_bytes.per_byte, "util.from_bytes.per_byte", 5 * MUL], + [.transaction_context.get_txn_hash.base, "transaction_context.get_txn_hash.base", 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost [.transaction_context.create_uuid.base, "transaction_context.create_uuid.base", 3000 * MUL], diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index b67c699a1d16f..ad63f5b4a92c6 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -42,6 +42,7 @@ make it so that a reference to a global object can be returned from a function. - [Function `convert`](#0x1_object_convert) - [Function `create_named_object`](#0x1_object_create_named_object) - [Function `create_user_derived_object`](#0x1_object_create_user_derived_object) +- [Function `create_object`](#0x1_object_create_object) - [Function `create_object_from_account`](#0x1_object_create_object_from_account) - [Function `create_object_from_object`](#0x1_object_create_object_from_object) - [Function `create_object_from_guid`](#0x1_object_create_object_from_guid) @@ -78,7 +79,8 @@ make it so that a reference to a global object can be returned from a function. - [Function `exists_at`](#@Specification_1_exists_at) -
use 0x1::bcs;
+
use 0x1::account;
+use 0x1::bcs;
 use 0x1::create_signer;
 use 0x1::error;
 use 0x1::event;
@@ -826,6 +828,32 @@ Derivde objects, similar to named objects, cannot be deleted.
 
 
 
+
+
+
+
+## Function `create_object`
+
+Create a new object by generating a random UUID based on transaction hash
+
+
+
public fun create_object(creator: &signer): object::ConstructorRef
+
+ + + +
+Implementation + + +
public fun create_object(creator: &signer): ConstructorRef {
+    let uuid = aptos_framework::transaction_context::create_uuid();
+    create_object_internal(signer::address_of(creator), uuid, true)
+}
+
+ + +
@@ -845,9 +873,8 @@ Create a new object from a GUID generated by an account.
public fun create_object_from_account(creator: &signer): ConstructorRef {
-    let guid_creation_num = INIT_GUID_CREATION_NUM;
-    let object_guid = guid::create(aptos_framework::transaction_context::create_uuid(), &mut guid_creation_num);
-    create_object_from_guid(signer::address_of(creator), object_guid)
+    let guid = account::create_guid(creator);
+    create_object_from_guid(signer::address_of(creator), guid)
 }
 
diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index d4f60a23ec8e0..57ba1077ac27a 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -226,6 +226,7 @@ impl GasParameters { }, }, transaction_context: transaction_context::GasParameters { + get_txn_hash: transaction_context::GetTxnHashGasParameters { base: 0.into() }, get_script_hash: transaction_context::GetScriptHashGasParameters { base: 0.into() }, create_uuid: transaction_context::CreateUUIDGasParameters { base: 0.into() }, }, diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 8d023068e08e5..aa0e9996e65f4 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -40,6 +40,36 @@ impl NativeTransactionContext { } } +/*************************************************************************************************** + * native fun get_txn_hash + * + * gas cost: base_cost + * + **************************************************************************************************/ +#[derive(Clone, Debug)] +pub struct GetTxnHashGasParameters { + pub base: InternalGas, +} + +fn native_get_txn_hash( + gas_params: &GetTxnHashGasParameters, + context: &mut SafeNativeContext, + mut _ty_args: Vec, + _args: VecDeque, +) -> SafeNativeResult> { + context.charge(gas_params.base)?; + + let transaction_context = context.extensions().get::(); + + Ok(smallvec![Value::address(AccountAddress::new( + transaction_context + .txn_hash + .clone() + .try_into() + .expect("Unable to convert transaction hash to address") + ))]) +} + /*************************************************************************************************** * native fun create_uuid * @@ -109,6 +139,7 @@ fn native_get_script_hash( **************************************************************************************************/ #[derive(Debug, Clone)] pub struct GasParameters { + pub get_txn_hash: GetTxnHashGasParameters, pub get_script_hash: GetScriptHashGasParameters, pub create_uuid: CreateUUIDGasParameters, } @@ -132,9 +163,18 @@ pub fn make_all( "create_uuid", make_safe_native( gas_params.create_uuid, + timed_features.clone(), + features.clone(), + native_create_uuid, + ), + ), + ( + "get_txn_hash", + make_safe_native( + gas_params.get_txn_hash, timed_features, features, - native_create_uuid, + native_get_txn_hash, ), ), ]; From b63259278fb2288c40900b789d279ba305d3b63c Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 5 Jun 2023 10:48:10 -0500 Subject: [PATCH 15/61] Add native_get_txn_hash --- .../doc/transaction_context.md | 24 +++++++++++++++++++ .../sources/transaction_context.move | 3 +++ .../src/natives/transaction_context.rs | 10 +++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index f97cf31f8ff54..b65ae91c81eca 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -5,6 +5,7 @@ +- [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) - [Function `create_uuid`](#0x1_transaction_context_create_uuid) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Specification](#@Specification_0) @@ -15,6 +16,29 @@ + + +## Function `get_txn_hash` + +Return the transaction hash of the current transaction + + +
public fun get_txn_hash(): vector<u8>
+
+ + + +
+Implementation + + +
public native fun get_txn_hash(): vector<u8>;
+
+ + + +
+ ## Function `create_uuid` diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index ce3eb83c84211..3a4fad287e717 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -1,4 +1,7 @@ module aptos_framework::transaction_context { + /// Return the transaction hash of the current transaction + public native fun get_txn_hash(): vector; + /// Return a universally unique identifier public native fun create_uuid(): address; diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index aa0e9996e65f4..edc6a81f043cd 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -61,13 +61,9 @@ fn native_get_txn_hash( let transaction_context = context.extensions().get::(); - Ok(smallvec![Value::address(AccountAddress::new( - transaction_context - .txn_hash - .clone() - .try_into() - .expect("Unable to convert transaction hash to address") - ))]) + Ok(smallvec![Value::vector_u8( + transaction_context.txn_hash.clone() + )]) } /*************************************************************************************************** From 3a616ba3525c94553c636f7bd3a06e4a850d71b5 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 5 Jun 2023 14:05:52 -0500 Subject: [PATCH 16/61] Deprecate the old create_object_from_object and create_object_from_account --- .../framework/aptos-framework/doc/object.md | 49 +++++-------------- .../aptos-framework/sources/object.move | 26 ++++------ 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index ad63f5b4a92c6..cb5efd7a7f2c3 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -45,7 +45,6 @@ make it so that a reference to a global object can be returned from a function. - [Function `create_object`](#0x1_object_create_object) - [Function `create_object_from_account`](#0x1_object_create_object_from_account) - [Function `create_object_from_object`](#0x1_object_create_object_from_object) -- [Function `create_object_from_guid`](#0x1_object_create_object_from_guid) - [Function `create_object_internal`](#0x1_object_create_object_internal) - [Function `generate_delete_ref`](#0x1_object_generate_delete_ref) - [Function `generate_extend_ref`](#0x1_object_generate_extend_ref) @@ -79,8 +78,7 @@ make it so that a reference to a global object can be returned from a function. - [Function `exists_at`](#@Specification_1_exists_at) -
use 0x1::account;
-use 0x1::bcs;
+
use 0x1::bcs;
 use 0x1::create_signer;
 use 0x1::error;
 use 0x1::event;
@@ -834,7 +832,9 @@ Derivde objects, similar to named objects, cannot be deleted.
 
 ## Function `create_object`
 
-Create a new object by generating a random UUID based on transaction hash
+Create a new object by generating a random UUID based on transaction hash.
+The created object is deletable as we can guarantee the same UUID can
+never be regenerated with future txs.
 
 
 
public fun create_object(creator: &signer): object::ConstructorRef
@@ -860,7 +860,8 @@ Create a new object by generating a random UUID based on transaction hash
 
 ## Function `create_object_from_account`
 
-Create a new object from a GUID generated by an account.
+Deprectated.
+Create a new object by generating a random UUID based on transaction hash.
 
 
 
public fun create_object_from_account(creator: &signer): object::ConstructorRef
@@ -873,8 +874,7 @@ Create a new object from a GUID generated by an account.
 
 
 
public fun create_object_from_account(creator: &signer): ConstructorRef {
-    let guid = account::create_guid(creator);
-    create_object_from_guid(signer::address_of(creator), guid)
+    create_object(creator)
 }
 
@@ -886,7 +886,8 @@ Create a new object from a GUID generated by an account. ## Function `create_object_from_object` -Create a new object from a GUID generated by an object. +Deprectated. +Create a new object by generating a random UUID based on transaction hash.
public fun create_object_from_object(creator: &signer): object::ConstructorRef
@@ -898,36 +899,8 @@ Create a new object from a GUID generated by an object.
 Implementation
 
 
-
public fun create_object_from_object(creator: &signer): ConstructorRef acquires ObjectCore {
-    let guid = create_guid(creator);
-    create_object_from_guid(signer::address_of(creator), guid)
-}
-
- - - - - - - -## Function `create_object_from_guid` - - - -
fun create_object_from_guid(creator_address: address, guid: guid::GUID): object::ConstructorRef
-
- - - -
-Implementation - - -
fun create_object_from_guid(creator_address: address, guid: guid::GUID): ConstructorRef {
-    let bytes = bcs::to_bytes(&guid);
-    vector::push_back(&mut bytes, OBJECT_FROM_GUID_ADDRESS_SCHEME);
-    let obj_addr = from_bcs::to_address(hash::sha3_256(bytes));
-    create_object_internal(creator_address, obj_addr, true)
+
public fun create_object_from_object(creator: &signer): ConstructorRef {
+    create_object(creator)
 }
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 2bcf50ae332c0..7255e3e872cdb 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -21,7 +21,6 @@ module aptos_framework::object { use std::signer; use std::vector; - use aptos_framework::account; use aptos_framework::create_signer::create_signer; use aptos_framework::event; use aptos_framework::from_bcs; @@ -210,29 +209,24 @@ module aptos_framework::object { create_object_internal(creator_address, obj_addr, false) } - /// Create a new object by generating a random UUID based on transaction hash + /// Create a new object by generating a random UUID based on transaction hash. + /// The created object is deletable as we can guarantee the same UUID can + /// never be regenerated with future txs. public fun create_object(creator: &signer): ConstructorRef { let uuid = aptos_framework::transaction_context::create_uuid(); create_object_internal(signer::address_of(creator), uuid, true) } - /// Create a new object from a GUID generated by an account. + /// Deprectated. + /// Create a new object by generating a random UUID based on transaction hash. public fun create_object_from_account(creator: &signer): ConstructorRef { - let guid = account::create_guid(creator); - create_object_from_guid(signer::address_of(creator), guid) + create_object(creator) } - /// Create a new object from a GUID generated by an object. - public fun create_object_from_object(creator: &signer): ConstructorRef acquires ObjectCore { - let guid = create_guid(creator); - create_object_from_guid(signer::address_of(creator), guid) - } - - fun create_object_from_guid(creator_address: address, guid: guid::GUID): ConstructorRef { - let bytes = bcs::to_bytes(&guid); - vector::push_back(&mut bytes, OBJECT_FROM_GUID_ADDRESS_SCHEME); - let obj_addr = from_bcs::to_address(hash::sha3_256(bytes)); - create_object_internal(creator_address, obj_addr, true) + /// Deprectated. + /// Create a new object by generating a random UUID based on transaction hash. + public fun create_object_from_object(creator: &signer): ConstructorRef { + create_object(creator) } fun create_object_internal( From f89370c96f1a683872f7110b87ddd69600c527d5 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 5 Jun 2023 14:24:28 -0500 Subject: [PATCH 17/61] Bumped the latest_gas_version to 10 --- aptos-move/aptos-gas/src/gas_meter.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aptos-move/aptos-gas/src/gas_meter.rs b/aptos-move/aptos-gas/src/gas_meter.rs index 4b249d34ab338..3edd4bb817941 100644 --- a/aptos-move/aptos-gas/src/gas_meter.rs +++ b/aptos-move/aptos-gas/src/gas_meter.rs @@ -33,6 +33,8 @@ use move_vm_types::{ use std::collections::BTreeMap; // Change log: +// - V10 +// - Added create_uuid and get_txn_hash native functions // - V8 // - Added BLS12-381 operations. // - V7 @@ -59,7 +61,7 @@ use std::collections::BTreeMap; // global operations. // - V1 // - TBA -pub const LATEST_GAS_FEATURE_VERSION: u64 = 8; +pub const LATEST_GAS_FEATURE_VERSION: u64 = 10; pub(crate) const EXECUTION_GAS_MULTIPLIER: u64 = 20; From 83c4a218bae5abdd2d2cb7e74b922c7b224313ca Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 5 Jun 2023 14:40:23 -0500 Subject: [PATCH 18/61] Bumped gas version to 10 --- aptos-move/aptos-gas/src/aptos_framework.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index 02bc5c49f9804..e7a986be353c4 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -163,10 +163,10 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.util.from_bytes.base, "util.from_bytes.base", 300 * MUL], [.util.from_bytes.per_byte, "util.from_bytes.per_byte", 5 * MUL], - [.transaction_context.get_txn_hash.base, "transaction_context.get_txn_hash.base", 200 * MUL], + [.transaction_context.get_txn_hash.base, { 10.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost - [.transaction_context.create_uuid.base, "transaction_context.create_uuid.base", 3000 * MUL], + [.transaction_context.create_uuid.base, { 10.. => "transaction_context.create_uuid.base" }, 3000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], From 8a6ff98201e75896cd5b8b6e5762e69011d13514 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 7 Jun 2023 15:58:56 -0500 Subject: [PATCH 19/61] Changed gas feature version to 9 --- aptos-move/aptos-gas/src/aptos_framework.rs | 4 ++-- aptos-move/aptos-gas/src/gas_meter.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index e7a986be353c4..d6d3beeb4dbb7 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -163,10 +163,10 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.util.from_bytes.base, "util.from_bytes.base", 300 * MUL], [.util.from_bytes.per_byte, "util.from_bytes.per_byte", 5 * MUL], - [.transaction_context.get_txn_hash.base, { 10.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], + [.transaction_context.get_txn_hash.base, { 9.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost - [.transaction_context.create_uuid.base, { 10.. => "transaction_context.create_uuid.base" }, 3000 * MUL], + [.transaction_context.create_uuid.base, { 9.. => "transaction_context.create_uuid.base" }, 3000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], diff --git a/aptos-move/aptos-gas/src/gas_meter.rs b/aptos-move/aptos-gas/src/gas_meter.rs index 3edd4bb817941..efdbeadbcd0d2 100644 --- a/aptos-move/aptos-gas/src/gas_meter.rs +++ b/aptos-move/aptos-gas/src/gas_meter.rs @@ -33,7 +33,7 @@ use move_vm_types::{ use std::collections::BTreeMap; // Change log: -// - V10 +// - V9 // - Added create_uuid and get_txn_hash native functions // - V8 // - Added BLS12-381 operations. @@ -61,7 +61,7 @@ use std::collections::BTreeMap; // global operations. // - V1 // - TBA -pub const LATEST_GAS_FEATURE_VERSION: u64 = 10; +pub const LATEST_GAS_FEATURE_VERSION: u64 = 9; pub(crate) const EXECUTION_GAS_MULTIPLIER: u64 = 20; From bf2974854b0b5fe8136016b4c2f8f59dd8a9932b Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 7 Jun 2023 16:58:09 -0500 Subject: [PATCH 20/61] Moved transaction hash hashing to authenticator.rs --- Cargo.lock | 1 + .../src/natives/transaction_context.rs | 17 +++++++++-------- types/Cargo.toml | 1 + types/src/transaction/authenticator.rs | 18 +++++++++++++++++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7490cd4237e7..0bf9ab8c6467e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3288,6 +3288,7 @@ dependencies = [ "serde_bytes", "serde_json", "serde_yaml 0.8.26", + "sha2 0.9.9", "thiserror", "tiny-keccak", ] diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index edc6a81f043cd..f5090ef04d6dd 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -2,12 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 use crate::natives::helpers::{make_safe_native, SafeNativeContext, SafeNativeResult}; -use aptos_types::on_chain_config::{Features, TimedFeatures}; +use aptos_types::{ + on_chain_config::{Features, TimedFeatures}, + transaction::authenticator::{AuthenticationKeyPreimage, TransactionDerivedUUID}, +}; use better_any::{Tid, TidAble}; use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas}; use move_vm_runtime::native_functions::NativeFunction; use move_vm_types::{loaded_data::runtime_types::Type, values::Value}; -use sha2::{Digest, Sha256}; use smallvec::{smallvec, SmallVec}; use std::{collections::VecDeque, fmt::Debug, sync::Arc}; @@ -89,15 +91,14 @@ fn native_create_uuid( .extensions_mut() .get_mut::(); transaction_context.uuid_counter += 1; - const OBJECT_FROM_TRANSACTION_UUID_ADDRESS_SCHEME: u8 = 0xFB; - let mut hash_arg = Vec::new(); - hash_arg.push(OBJECT_FROM_TRANSACTION_UUID_ADDRESS_SCHEME); - hash_arg.extend(transaction_context.txn_hash.clone()); - hash_arg.extend(transaction_context.uuid_counter.to_le_bytes().to_vec()); - let hash_vec = Sha256::digest(hash_arg.as_slice()).to_vec(); + let hash_vec = AuthenticationKeyPreimage::uuid(TransactionDerivedUUID { + txn_hash: transaction_context.txn_hash.clone(), + uuid_counter: transaction_context.uuid_counter, + }); Ok(smallvec![Value::address(AccountAddress::new( hash_vec + .into_vec() .try_into() .expect("Unable to convert hash vector into [u8]") ))]) diff --git a/types/Cargo.toml b/types/Cargo.toml index 35ca764d3b1cf..abe24e4e615b9 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -35,6 +35,7 @@ serde = { workspace = true } serde_bytes = { workspace = true } serde_json = { workspace = true } serde_yaml = { workspace = true } +sha2 = { workspace = true } thiserror = { workspace = true } tiny-keccak = { workspace = true } diff --git a/types/src/transaction/authenticator.rs b/types/src/transaction/authenticator.rs index b65343501eeb7..7cee42f9257c4 100644 --- a/types/src/transaction/authenticator.rs +++ b/types/src/transaction/authenticator.rs @@ -14,11 +14,12 @@ use aptos_crypto::{ traits::Signature, CryptoMaterialError, HashValue, ValidCryptoMaterial, ValidCryptoMaterialStringExt, }; -use aptos_crypto_derive::{CryptoHasher, DeserializeKey, SerializeKey}; +use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher, DeserializeKey, SerializeKey}; #[cfg(any(test, feature = "fuzzing"))] use proptest_derive::Arbitrary; use rand::{rngs::OsRng, Rng}; use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; use std::{convert::TryFrom, fmt, str::FromStr}; use thiserror::Error; @@ -246,6 +247,7 @@ pub enum Scheme { /// resources accounts. This application serves to domain separate hashes. Without such /// separation, an adversary could create (and get a signer for) a these accounts /// when a their address matches matches an existing address of a MultiEd25519 wallet. + DeriveUuid = 251, DeriveObjectAddressFromObject = 252, DeriveObjectAddressFromGuid = 253, DeriveObjectAddressFromSeed = 254, @@ -257,6 +259,7 @@ impl fmt::Display for Scheme { let display = match self { Scheme::Ed25519 => "Ed25519", Scheme::MultiEd25519 => "MultiEd25519", + Scheme::DeriveUuid => "DeriveUuid", Scheme::DeriveObjectAddressFromObject => "DeriveObjectAddressFromObject", Scheme::DeriveObjectAddressFromGuid => "DeriveObjectAddressFromGuid", Scheme::DeriveObjectAddressFromSeed => "DeriveObjectAddressFromSeed", @@ -441,6 +444,12 @@ impl ValidCryptoMaterial for AuthenticationKey { } } +#[derive(Serialize, Deserialize, CryptoHasher, BCSCryptoHash)] +pub struct TransactionDerivedUUID { + pub txn_hash: Vec, + pub uuid_counter: u64, +} + /// A value that can be hashed to produce an authentication key pub struct AuthenticationKeyPreimage(Vec); @@ -461,6 +470,13 @@ impl AuthenticationKeyPreimage { Self::new(public_key.to_bytes(), Scheme::MultiEd25519) } + pub fn uuid(transaction_derived_uuid: TransactionDerivedUUID) -> AuthenticationKeyPreimage { + let mut hash_arg = Vec::new(); + hash_arg.push(Scheme::DeriveUuid as u8); + hash_arg.extend(transaction_derived_uuid.hash().to_vec()); + Self(Sha256::digest(hash_arg.as_slice()).to_vec()) + } + /// Construct a vector from this authentication key pub fn into_vec(self) -> Vec { self.0 From ee027082493f07cbce5b879dea1e76fd33989e84 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 8 Jun 2023 11:42:08 -0500 Subject: [PATCH 21/61] Add documentation to create_uuid method --- .../aptos-framework/sources/transaction_context.move | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 3a4fad287e717..ebf43665601b0 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -2,7 +2,11 @@ module aptos_framework::transaction_context { /// Return the transaction hash of the current transaction public native fun get_txn_hash(): vector; - /// Return a universally unique identifier + /// Return a universally unique identifier generated by hashing + /// the transaction hash of this transaction and a sequence number + /// specific to this transaction. This function can be called any + /// number of times inside a single transaction. Each such call increments + /// the sequence number and generates a new UUID public native fun create_uuid(): address; /// Return the script hash of the current entry function. From 638e2afe5b3cd840b08067dae2ce5a0edde3afc0 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 8 Jun 2023 17:21:12 -0500 Subject: [PATCH 22/61] Use AuthenticationKey struct for create_uuid --- .../aptos-framework/doc/transaction_context.md | 6 +++++- .../framework/src/natives/transaction_context.rs | 16 ++++++++++------ types/src/transaction/authenticator.rs | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index b65ae91c81eca..d9ee8df2a5821 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -43,7 +43,11 @@ Return the transaction hash of the current transaction ## Function `create_uuid` -Return a universally unique identifier +Return a universally unique identifier generated by hashing +the transaction hash of this transaction and a sequence number +specific to this transaction. This function can be called any +number of times inside a single transaction. Each such call increments +the sequence number and generates a new UUID
public fun create_uuid(): address
diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs
index f5090ef04d6dd..0a4e34b48818b 100644
--- a/aptos-move/framework/src/natives/transaction_context.rs
+++ b/aptos-move/framework/src/natives/transaction_context.rs
@@ -4,7 +4,9 @@
 use crate::natives::helpers::{make_safe_native, SafeNativeContext, SafeNativeResult};
 use aptos_types::{
     on_chain_config::{Features, TimedFeatures},
-    transaction::authenticator::{AuthenticationKeyPreimage, TransactionDerivedUUID},
+    transaction::authenticator::{
+        AuthenticationKey, AuthenticationKeyPreimage, TransactionDerivedUUID,
+    },
 };
 use better_any::{Tid, TidAble};
 use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas};
@@ -92,13 +94,15 @@ fn native_create_uuid(
         .get_mut::();
     transaction_context.uuid_counter += 1;
 
-    let hash_vec = AuthenticationKeyPreimage::uuid(TransactionDerivedUUID {
-        txn_hash: transaction_context.txn_hash.clone(),
-        uuid_counter: transaction_context.uuid_counter,
-    });
+    let hash_vec = AuthenticationKey::from_preimage(&AuthenticationKeyPreimage::uuid(
+        TransactionDerivedUUID {
+            txn_hash: transaction_context.txn_hash.clone(),
+            uuid_counter: transaction_context.uuid_counter,
+        },
+    ));
     Ok(smallvec![Value::address(AccountAddress::new(
         hash_vec
-            .into_vec()
+            .to_vec()
             .try_into()
             .expect("Unable to convert hash vector into [u8]")
     ))])
diff --git a/types/src/transaction/authenticator.rs b/types/src/transaction/authenticator.rs
index 7cee42f9257c4..e1d307a59ca47 100644
--- a/types/src/transaction/authenticator.rs
+++ b/types/src/transaction/authenticator.rs
@@ -19,7 +19,6 @@ use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher, DeserializeKey, Serialize
 use proptest_derive::Arbitrary;
 use rand::{rngs::OsRng, Rng};
 use serde::{Deserialize, Serialize};
-use sha2::{Digest, Sha256};
 use std::{convert::TryFrom, fmt, str::FromStr};
 use thiserror::Error;
 
@@ -470,11 +469,12 @@ impl AuthenticationKeyPreimage {
         Self::new(public_key.to_bytes(), Scheme::MultiEd25519)
     }
 
+    /// Construct a preimage from a transaction-derived UUID as (txn_hash || uuid_scheme_id)
     pub fn uuid(transaction_derived_uuid: TransactionDerivedUUID) -> AuthenticationKeyPreimage {
         let mut hash_arg = Vec::new();
-        hash_arg.push(Scheme::DeriveUuid as u8);
         hash_arg.extend(transaction_derived_uuid.hash().to_vec());
-        Self(Sha256::digest(hash_arg.as_slice()).to_vec())
+        hash_arg.push(Scheme::DeriveUuid as u8);
+        Self(hash_arg)
     }
 
     /// Construct a vector from this authentication key

From 331e728476ea49b9c1e3400b94255e486ff4e67d Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Thu, 8 Jun 2023 17:23:51 -0500
Subject: [PATCH 23/61] Remove deprecated comment

---
 aptos-move/framework/aptos-framework/sources/object.move | 2 --
 1 file changed, 2 deletions(-)

diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move
index 7255e3e872cdb..ed42952fc7d3d 100644
--- a/aptos-move/framework/aptos-framework/sources/object.move
+++ b/aptos-move/framework/aptos-framework/sources/object.move
@@ -217,13 +217,11 @@ module aptos_framework::object {
         create_object_internal(signer::address_of(creator), uuid, true)
     }
 
-    /// Deprectated. 
     /// Create a new object by generating a random UUID based on transaction hash.
     public fun create_object_from_account(creator: &signer): ConstructorRef {
         create_object(creator)
     }
 
-    /// Deprectated. 
     /// Create a new object by generating a random UUID based on transaction hash.
     public fun create_object_from_object(creator: &signer): ConstructorRef {
         create_object(creator)

From ce78b043cae987f3e5abb7cc42a2fad0b965c314 Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Thu, 8 Jun 2023 17:28:37 -0500
Subject: [PATCH 24/61] Updatd comments in object.move

---
 aptos-move/framework/aptos-framework/doc/object.md       | 5 +----
 aptos-move/framework/aptos-framework/sources/object.move | 3 +--
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md
index cb5efd7a7f2c3..d5773671f59df 100644
--- a/aptos-move/framework/aptos-framework/doc/object.md
+++ b/aptos-move/framework/aptos-framework/doc/object.md
@@ -225,8 +225,7 @@ This is a one time ability given to the creator to configure the object as neces
 can_delete: bool
 
 
- Set to true so long as deleting the object is possible. For example, the object was - created via create_object_from_guid. + Set to true so long as deleting the object is possible.
@@ -860,7 +859,6 @@ never be regenerated with future txs. ## Function `create_object_from_account` -Deprectated. Create a new object by generating a random UUID based on transaction hash. @@ -886,7 +884,6 @@ Create a new object by generating a random UUID based on transaction hash. ## Function `create_object_from_object` -Deprectated. Create a new object by generating a random UUID based on transaction hash. diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index ed42952fc7d3d..d932a3b1e460d 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -107,8 +107,7 @@ module aptos_framework::object { /// This is a one time ability given to the creator to configure the object as necessary struct ConstructorRef has drop { self: address, - /// Set to true so long as deleting the object is possible. For example, the object was - /// created via create_object_from_guid. + /// Set to true so long as deleting the object is possible. can_delete: bool, } From 575e4099c01ee1852c5388cfcc23265dc875cc16 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 9 Jun 2023 12:27:27 -0500 Subject: [PATCH 25/61] Changed create_uuid to use only one hash --- .../framework/src/natives/transaction_context.rs | 10 +++------- types/src/transaction/authenticator.rs | 13 ++++--------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 0a4e34b48818b..746cdf9c1da0c 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -4,9 +4,7 @@ use crate::natives::helpers::{make_safe_native, SafeNativeContext, SafeNativeResult}; use aptos_types::{ on_chain_config::{Features, TimedFeatures}, - transaction::authenticator::{ - AuthenticationKey, AuthenticationKeyPreimage, TransactionDerivedUUID, - }, + transaction::authenticator::{AuthenticationKey, AuthenticationKeyPreimage}, }; use better_any::{Tid, TidAble}; use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas}; @@ -95,10 +93,8 @@ fn native_create_uuid( transaction_context.uuid_counter += 1; let hash_vec = AuthenticationKey::from_preimage(&AuthenticationKeyPreimage::uuid( - TransactionDerivedUUID { - txn_hash: transaction_context.txn_hash.clone(), - uuid_counter: transaction_context.uuid_counter, - }, + transaction_context.txn_hash.clone(), + transaction_context.uuid_counter, )); Ok(smallvec![Value::address(AccountAddress::new( hash_vec diff --git a/types/src/transaction/authenticator.rs b/types/src/transaction/authenticator.rs index e1d307a59ca47..6b0af07a142e8 100644 --- a/types/src/transaction/authenticator.rs +++ b/types/src/transaction/authenticator.rs @@ -14,7 +14,7 @@ use aptos_crypto::{ traits::Signature, CryptoMaterialError, HashValue, ValidCryptoMaterial, ValidCryptoMaterialStringExt, }; -use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher, DeserializeKey, SerializeKey}; +use aptos_crypto_derive::{CryptoHasher, DeserializeKey, SerializeKey}; #[cfg(any(test, feature = "fuzzing"))] use proptest_derive::Arbitrary; use rand::{rngs::OsRng, Rng}; @@ -443,12 +443,6 @@ impl ValidCryptoMaterial for AuthenticationKey { } } -#[derive(Serialize, Deserialize, CryptoHasher, BCSCryptoHash)] -pub struct TransactionDerivedUUID { - pub txn_hash: Vec, - pub uuid_counter: u64, -} - /// A value that can be hashed to produce an authentication key pub struct AuthenticationKeyPreimage(Vec); @@ -470,9 +464,10 @@ impl AuthenticationKeyPreimage { } /// Construct a preimage from a transaction-derived UUID as (txn_hash || uuid_scheme_id) - pub fn uuid(transaction_derived_uuid: TransactionDerivedUUID) -> AuthenticationKeyPreimage { + pub fn uuid(txn_hash: Vec, uuid_counter: u64) -> AuthenticationKeyPreimage { let mut hash_arg = Vec::new(); - hash_arg.extend(transaction_derived_uuid.hash().to_vec()); + hash_arg.extend(txn_hash); + hash_arg.extend(uuid_counter.to_le_bytes().to_vec()); hash_arg.push(Scheme::DeriveUuid as u8); Self(hash_arg) } From 16b52a4aae9ef2613d295966e133c80208a43583 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 10 Jun 2023 23:30:15 -0500 Subject: [PATCH 26/61] Add create_unique_address function --- aptos-move/aptos-gas/src/aptos_framework.rs | 2 +- .../framework/aptos-framework/doc/object.md | 2 +- .../doc/transaction_context.md | 75 +++++++++++++++++-- .../aptos-framework/sources/object.move | 2 +- .../sources/transaction_context.move | 23 +++++- aptos-move/framework/src/natives/mod.rs | 4 +- .../src/natives/transaction_context.rs | 12 +-- 7 files changed, 98 insertions(+), 22 deletions(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index d6d3beeb4dbb7..b89a5e7a37a2b 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -166,7 +166,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.transaction_context.get_txn_hash.base, { 9.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost - [.transaction_context.create_uuid.base, { 9.. => "transaction_context.create_uuid.base" }, 3000 * MUL], + [.transaction_context.create_unique_address.base, { 9.. => "transaction_context.create_unique_address.base" }, 3000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index d5773671f59df..a70c8f107d77b 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -846,7 +846,7 @@ never be regenerated with future txs.
public fun create_object(creator: &signer): ConstructorRef {
-    let uuid = aptos_framework::transaction_context::create_uuid();
+    let uuid = aptos_framework::transaction_context::create_unique_address();
     create_object_internal(signer::address_of(creator), uuid, true)
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index d9ee8df2a5821..c57c2aac1ae2b 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -5,9 +5,11 @@ +- [Struct `UUID`](#0x1_transaction_context_UUID) - [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) -- [Function `create_uuid`](#0x1_transaction_context_create_uuid) +- [Function `create_unique_address`](#0x1_transaction_context_create_unique_address) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) +- [Function `create_uuid`](#0x1_transaction_context_create_uuid) - [Specification](#@Specification_0) - [Function `get_script_hash`](#@Specification_0_get_script_hash) @@ -16,6 +18,35 @@ + + +## Struct `UUID` + +A wrapper denoting universally unique identifer (UUID) +for storing an address + + +
struct UUID
+
+ + + +
+Fields + + +
+
+unique_address: address +
+
+ +
+
+ + +
+ ## Function `get_txn_hash` @@ -39,18 +70,18 @@ Return the transaction hash of the current transaction
- + -## Function `create_uuid` +## Function `create_unique_address` -Return a universally unique identifier generated by hashing -the transaction hash of this transaction and a sequence number +Return a universally unique identifier (of type address) generated +by hashing the transaction hash of this transaction and a sequence number specific to this transaction. This function can be called any number of times inside a single transaction. Each such call increments -the sequence number and generates a new UUID +the sequence number and generates a new unique address -
public fun create_uuid(): address
+
public fun create_unique_address(): address
 
@@ -59,7 +90,7 @@ the sequence number and generates a new UUID Implementation -
public native fun create_uuid(): address;
+
public native fun create_unique_address(): address;
 
@@ -87,6 +118,34 @@ Return the script hash of the current entry function. + + + + +## Function `create_uuid` + +This method runs create_unique_address native function and returns +the generated unique address wrapped in the UUID class. + + +
public fun create_uuid(): transaction_context::UUID
+
+ + + +
+Implementation + + +
public fun create_uuid(): UUID {
+    return UUID {
+        unique_address: create_unique_address()
+    }
+}
+
+ + +
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index d932a3b1e460d..0013152e6aa31 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -212,7 +212,7 @@ module aptos_framework::object { /// The created object is deletable as we can guarantee the same UUID can /// never be regenerated with future txs. public fun create_object(creator: &signer): ConstructorRef { - let uuid = aptos_framework::transaction_context::create_uuid(); + let uuid = aptos_framework::transaction_context::create_unique_address(); create_object_internal(signer::address_of(creator), uuid, true) } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index ebf43665601b0..08c8e0a494f6e 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -1,14 +1,29 @@ module aptos_framework::transaction_context { + + /// A wrapper denoting universally unique identifer (UUID) + /// for storing an address + struct UUID { + unique_address: address + } + /// Return the transaction hash of the current transaction public native fun get_txn_hash(): vector; - /// Return a universally unique identifier generated by hashing - /// the transaction hash of this transaction and a sequence number + /// Return a universally unique identifier (of type address) generated + /// by hashing the transaction hash of this transaction and a sequence number /// specific to this transaction. This function can be called any /// number of times inside a single transaction. Each such call increments - /// the sequence number and generates a new UUID - public native fun create_uuid(): address; + /// the sequence number and generates a new unique address + public native fun create_unique_address(): address; /// Return the script hash of the current entry function. public native fun get_script_hash(): vector; + + /// This method runs `create_unique_address` native function and returns + /// the generated unique address wrapped in the UUID class. + public fun create_uuid(): UUID { + return UUID { + unique_address: create_unique_address() + } + } } diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index 57ba1077ac27a..6f2b88a1536b4 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -228,7 +228,9 @@ impl GasParameters { transaction_context: transaction_context::GasParameters { get_txn_hash: transaction_context::GetTxnHashGasParameters { base: 0.into() }, get_script_hash: transaction_context::GetScriptHashGasParameters { base: 0.into() }, - create_uuid: transaction_context::CreateUUIDGasParameters { base: 0.into() }, + create_unique_address: transaction_context::CreateUniqueAddressGasParameters { + base: 0.into(), + }, }, code: code::GasParameters { request_publish: code::RequestPublishGasParameters { diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 746cdf9c1da0c..6d5e08901edcc 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -75,12 +75,12 @@ fn native_get_txn_hash( * **************************************************************************************************/ #[derive(Clone, Debug)] -pub struct CreateUUIDGasParameters { +pub struct CreateUniqueAddressGasParameters { pub base: InternalGas, } -fn native_create_uuid( - gas_params: &CreateUUIDGasParameters, +fn native_create_unique_address( + gas_params: &CreateUniqueAddressGasParameters, context: &mut SafeNativeContext, mut _ty_args: Vec, _args: VecDeque, @@ -138,7 +138,7 @@ fn native_get_script_hash( pub struct GasParameters { pub get_txn_hash: GetTxnHashGasParameters, pub get_script_hash: GetScriptHashGasParameters, - pub create_uuid: CreateUUIDGasParameters, + pub create_unique_address: CreateUniqueAddressGasParameters, } pub fn make_all( @@ -159,10 +159,10 @@ pub fn make_all( ( "create_uuid", make_safe_native( - gas_params.create_uuid, + gas_params.create_unique_address, timed_features.clone(), features.clone(), - native_create_uuid, + native_create_unique_address, ), ), ( From f1afb1e3b52ef39ba9dc3bc47efd754c7a5a4c1f Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 10 Jun 2023 23:42:42 -0500 Subject: [PATCH 27/61] Add drop, store capabilities to UUID --- .../framework/aptos-framework/sources/transaction_context.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 08c8e0a494f6e..b9bb9fb42ea12 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -2,7 +2,7 @@ module aptos_framework::transaction_context { /// A wrapper denoting universally unique identifer (UUID) /// for storing an address - struct UUID { + struct UUID has drop, store { unique_address: address } From 5308088a500b83b30a3c491c36d5af5e55e2e1ef Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 21 Jun 2023 12:15:08 -0500 Subject: [PATCH 28/61] Resetting the create_object_from_account function --- Cargo.lock | 186 +++++++++--------- .../framework/aptos-framework/doc/object.md | 51 ++++- .../doc/transaction_context.md | 2 +- .../aptos-framework/sources/object.move | 26 ++- 4 files changed, 156 insertions(+), 109 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b7f03fa5c2c4..cc29975c4b04d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,15 +101,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aho-corasick" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" -dependencies = [ - "memchr", -] - [[package]] name = "aliasable" version = "0.1.3" @@ -4404,6 +4395,16 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "buf_redux" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" +dependencies = [ + "memchr", + "safemem", +] + [[package]] name = "bumpalo" version = "3.11.0" @@ -4944,7 +4945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e4b6aa369f41f5faa04bb80c9b1f4216ea81646ed6124d76ba5c49a7aafd9cd" dependencies = [ "cookie", - "idna 0.2.3", + "idna", "log", "publicsuffix", "serde 1.0.149", @@ -6079,10 +6080,11 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ + "matches", "percent-encoding", ] @@ -6094,9 +6096,9 @@ checksum = "85dcb89d2b10c5f6133de2efd8c11959ce9dbb46a2f7a4cab208c4eeda6ce1ab" [[package]] name = "fs_extra" -version = "1.3.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" +checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" [[package]] name = "funty" @@ -6411,7 +6413,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" dependencies = [ - "aho-corasick 0.7.18", + "aho-corasick", "bstr", "fnv", "log", @@ -6733,9 +6735,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "httpmock" -version = "0.6.7" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b56b6265f15908780cbee987912c1e98dbca675361f748291605a8a3a1df09" +checksum = "c159c4fc205e6c1a9b325cb7ec135d13b5f47188ce175dabb76ec847f331d9bd" dependencies = [ "assert-json-diff", "async-object-pool", @@ -6865,16 +6867,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "ignore" version = "0.4.18" @@ -7395,7 +7387,7 @@ dependencies = [ "petgraph 0.6.2", "pico-args", "regex", - "regex-syntax 0.6.27", + "regex-syntax", "string_cache", "term", "tiny-keccak", @@ -7565,12 +7557,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "libm" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" - [[package]] name = "libnghttp2-sys" version = "0.1.7+1.45.0" @@ -8932,9 +8918,9 @@ dependencies = [ [[package]] name = "multer" -version = "2.1.0" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01acbdc23469fd8fe07ab135923371d5f5a422fbf9c522158677c8eb15bc51c2" +checksum = "a30ba6d97eb198c5e8a35d67d5779d6680cca35652a60ee90fc23dc431d4fde8" dependencies = [ "bytes", "encoding_rs", @@ -8949,6 +8935,24 @@ dependencies = [ "version_check", ] +[[package]] +name = "multipart" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00dec633863867f29cb39df64a397cdf4a6354708ddd7759f70c7fb51c5f9182" +dependencies = [ + "buf_redux", + "httparse", + "log", + "mime", + "mime_guess", + "quick-error 1.2.3", + "rand 0.8.5", + "safemem", + "tempfile", + "twoway", +] + [[package]] name = "named-lock" version = "0.2.0" @@ -9183,7 +9187,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -9538,9 +9541,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pest" @@ -10104,22 +10107,22 @@ dependencies = [ [[package]] name = "proptest" -version = "1.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" +checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5" dependencies = [ "bit-set", "bitflags 1.3.2", "byteorder", "lazy_static 1.4.0", "num-traits 0.2.15", + "quick-error 2.0.1", "rand 0.8.5", "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax 0.6.27", + "regex-syntax", "rusty-fork", "tempfile", - "unarray", ] [[package]] @@ -10194,7 +10197,7 @@ version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aeeedb0b429dc462f30ad27ef3de97058b060016f47790c066757be38ef792b4" dependencies = [ - "idna 0.2.3", + "idna", "psl-types", ] @@ -10229,6 +10232,12 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + [[package]] name = "quick-xml" version = "0.22.0" @@ -10521,13 +10530,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ - "aho-corasick 1.0.2", + "aho-corasick", "memchr", - "regex-syntax 0.7.2", + "regex-syntax", ] [[package]] @@ -10536,7 +10545,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax 0.6.27", + "regex-syntax", ] [[package]] @@ -10545,12 +10554,6 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" -[[package]] -name = "regex-syntax" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" - [[package]] name = "remove_dir_all" version = "0.5.3" @@ -10882,7 +10885,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", - "quick-error", + "quick-error 1.2.3", "tempfile", "wait-timeout", ] @@ -10893,6 +10896,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + [[package]] name = "same-file" version = "1.0.6" @@ -11248,17 +11257,6 @@ dependencies = [ "digest 0.10.5", ] -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.5", -] - [[package]] name = "sha1_smol" version = "1.0.0" @@ -12058,9 +12056,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.26.0" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -12074,7 +12072,7 @@ dependencies = [ "socket2", "tokio-macros", "tracing", - "windows-sys 0.45.0", + "winapi 0.3.9", ] [[package]] @@ -12167,9 +12165,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.18.0" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +checksum = "f714dd15bead90401d77e04243611caec13726c2408afd5b31901dfcdcb3b181" dependencies = [ "futures-util", "log", @@ -12523,9 +12521,9 @@ dependencies = [ [[package]] name = "tungstenite" -version = "0.18.0" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" +checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" dependencies = [ "base64 0.13.0", "byteorder", @@ -12534,12 +12532,21 @@ dependencies = [ "httparse", "log", "rand 0.8.5", - "sha1", + "sha-1", "thiserror", "url", "utf-8", ] +[[package]] +name = "twoway" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" +dependencies = [ + "memchr", +] + [[package]] name = "typed-arena" version = "2.0.2" @@ -12592,12 +12599,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "unarray" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" - [[package]] name = "uncased" version = "0.9.7" @@ -12668,9 +12669,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" @@ -12689,9 +12690,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" dependencies = [ "tinyvec", ] @@ -12761,12 +12762,13 @@ dependencies = [ [[package]] name = "url" -version = "2.4.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", - "idna 0.4.0", + "idna", + "matches", "percent-encoding", "serde 1.0.149", ] @@ -12885,9 +12887,9 @@ dependencies = [ [[package]] name = "warp" -version = "0.3.5" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba431ef570df1287f7f8b07e376491ad54f84d26ac473489427231e1718e1f69" +checksum = "ed7b8be92646fc3d18b06147664ebc5f48d222686cb11a8755e561a735aacc6d" dependencies = [ "bytes", "futures-channel", @@ -12898,10 +12900,10 @@ dependencies = [ "log", "mime", "mime_guess", - "multer", + "multipart", "percent-encoding", "pin-project", - "rustls-pemfile 1.0.1", + "rustls-pemfile 0.2.1", "scoped-tls", "serde 1.0.149", "serde_json", diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 29a48f4dcac7f..d4f278b03a804 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -45,6 +45,7 @@ make it so that a reference to a global object can be returned from a function. - [Function `create_object`](#0x1_object_create_object) - [Function `create_object_from_account`](#0x1_object_create_object_from_account) - [Function `create_object_from_object`](#0x1_object_create_object_from_object) +- [Function `create_object_from_guid`](#0x1_object_create_object_from_guid) - [Function `create_object_internal`](#0x1_object_create_object_internal) - [Function `generate_delete_ref`](#0x1_object_generate_delete_ref) - [Function `generate_extend_ref`](#0x1_object_generate_extend_ref) @@ -78,7 +79,8 @@ make it so that a reference to a global object can be returned from a function. - [Function `exists_at`](#@Specification_1_exists_at) -
use 0x1::bcs;
+
use 0x1::account;
+use 0x1::bcs;
 use 0x1::create_signer;
 use 0x1::error;
 use 0x1::event;
@@ -838,7 +840,7 @@ The created object is deletable as we can guarantee the same UUID can
 never be regenerated with future txs.
 
 
-
public fun create_object(creator: &signer): object::ConstructorRef
+
public fun create_object(creator_address: address): object::ConstructorRef
 
@@ -847,9 +849,9 @@ never be regenerated with future txs. Implementation -
public fun create_object(creator: &signer): ConstructorRef {
+
public fun create_object(creator_address: address): ConstructorRef {
     let uuid = aptos_framework::transaction_context::create_unique_address();
-    create_object_internal(signer::address_of(creator), uuid, true)
+    create_object_internal(creator_address, uuid, true)
 }
 
@@ -861,7 +863,8 @@ never be regenerated with future txs. ## Function `create_object_from_account` -Create a new object by generating a random UUID based on transaction hash. +Deprecated. Use create_object instead. +Create a new object from a GUID generated by an account.
public fun create_object_from_account(creator: &signer): object::ConstructorRef
@@ -874,7 +877,8 @@ Create a new object by generating a random UUID based on transaction hash.
 
 
 
public fun create_object_from_account(creator: &signer): ConstructorRef {
-    create_object(creator)
+    let guid = account::create_guid(creator);
+    create_object_from_guid(signer::address_of(creator), guid)
 }
 
@@ -886,7 +890,8 @@ Create a new object by generating a random UUID based on transaction hash. ## Function `create_object_from_object` -Create a new object by generating a random UUID based on transaction hash. +Deprecated. Use create_object instead. +Create a new object from a GUID generated by an object.
public fun create_object_from_object(creator: &signer): object::ConstructorRef
@@ -898,8 +903,36 @@ Create a new object by generating a random UUID based on transaction hash.
 Implementation
 
 
-
public fun create_object_from_object(creator: &signer): ConstructorRef {
-    create_object(creator)
+
public fun create_object_from_object(creator: &signer): ConstructorRef acquires ObjectCore {
+    let guid = create_guid(creator);
+    create_object_from_guid(signer::address_of(creator), guid)
+}
+
+ + + + + + + +## Function `create_object_from_guid` + + + +
fun create_object_from_guid(creator_address: address, guid: guid::GUID): object::ConstructorRef
+
+ + + +
+Implementation + + +
fun create_object_from_guid(creator_address: address, guid: guid::GUID): ConstructorRef {
+    let bytes = bcs::to_bytes(&guid);
+    vector::push_back(&mut bytes, OBJECT_FROM_GUID_ADDRESS_SCHEME);
+    let obj_addr = from_bcs::to_address(hash::sha3_256(bytes));
+    create_object_internal(creator_address, obj_addr, true)
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index c57c2aac1ae2b..3f3d37af99495 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -26,7 +26,7 @@ A wrapper denoting universally unique identifer (UUID) for storing an address -
struct UUID
+
struct UUID has drop, store
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 0013152e6aa31..735c747fbbc46 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -21,6 +21,7 @@ module aptos_framework::object { use std::signer; use std::vector; + use aptos_framework::account; use aptos_framework::create_signer::create_signer; use aptos_framework::event; use aptos_framework::from_bcs; @@ -211,19 +212,30 @@ module aptos_framework::object { /// Create a new object by generating a random UUID based on transaction hash. /// The created object is deletable as we can guarantee the same UUID can /// never be regenerated with future txs. - public fun create_object(creator: &signer): ConstructorRef { + public fun create_object(creator_address: address): ConstructorRef { let uuid = aptos_framework::transaction_context::create_unique_address(); - create_object_internal(signer::address_of(creator), uuid, true) + create_object_internal(creator_address, uuid, true) } - /// Create a new object by generating a random UUID based on transaction hash. + /// Deprecated. Use `create_object` instead. + /// Create a new object from a GUID generated by an account. public fun create_object_from_account(creator: &signer): ConstructorRef { - create_object(creator) + let guid = account::create_guid(creator); + create_object_from_guid(signer::address_of(creator), guid) } - /// Create a new object by generating a random UUID based on transaction hash. - public fun create_object_from_object(creator: &signer): ConstructorRef { - create_object(creator) + /// Deprecated. Use `create_object` instead. + /// Create a new object from a GUID generated by an object. + public fun create_object_from_object(creator: &signer): ConstructorRef acquires ObjectCore { + let guid = create_guid(creator); + create_object_from_guid(signer::address_of(creator), guid) + } + + fun create_object_from_guid(creator_address: address, guid: guid::GUID): ConstructorRef { + let bytes = bcs::to_bytes(&guid); + vector::push_back(&mut bytes, OBJECT_FROM_GUID_ADDRESS_SCHEME); + let obj_addr = from_bcs::to_address(hash::sha3_256(bytes)); + create_object_internal(creator_address, obj_addr, true) } fun create_object_internal( From 9b1591b0e83107867907ea2a5b8092f7bd57c26d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 21 Jun 2023 12:22:27 -0500 Subject: [PATCH 29/61] Add comment for create_object function --- aptos-move/framework/aptos-framework/doc/object.md | 1 + aptos-move/framework/aptos-framework/sources/object.move | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index d4f278b03a804..6cb8b2fe82fe7 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -836,6 +836,7 @@ Derivde objects, similar to named objects, cannot be deleted. ## Function `create_object` Create a new object by generating a random UUID based on transaction hash. +The UUID is computed sha3_256([transaction hash | uuid counter | 0xFB]). The created object is deletable as we can guarantee the same UUID can never be regenerated with future txs. diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 735c747fbbc46..05450e1bbb704 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -210,7 +210,8 @@ module aptos_framework::object { } /// Create a new object by generating a random UUID based on transaction hash. - /// The created object is deletable as we can guarantee the same UUID can + /// The UUID is computed sha3_256([transaction hash | uuid counter | 0xFB]). + /// The created object is deletable as we can guarantee the same UUID can /// never be regenerated with future txs. public fun create_object(creator_address: address): ConstructorRef { let uuid = aptos_framework::transaction_context::create_unique_address(); From 0424d8b5ae0b38f020e9c6796fa11ccdfee7413d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Wed, 21 Jun 2023 12:53:37 -0500 Subject: [PATCH 30/61] feature gating --- .../framework/aptos-framework/doc/object.md | 2 +- .../doc/transaction_context.md | 61 ++++++++++++++++--- .../aptos-framework/sources/object.move | 2 +- .../sources/transaction_context.move | 16 ++++- .../framework/move-stdlib/doc/features.md | 59 ++++++++++++++++++ .../move-stdlib/sources/configs/features.move | 10 +++ 6 files changed, 140 insertions(+), 10 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 6cb8b2fe82fe7..c8fcec41748e3 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -851,7 +851,7 @@ never be regenerated with future txs.
public fun create_object(creator_address: address): ConstructorRef {
-    let uuid = aptos_framework::transaction_context::create_unique_address();
+    let uuid = aptos_framework::transaction_context::create_unique_addr();
     create_object_internal(creator_address, uuid, true)
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 3f3d37af99495..35c64dc864e00 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -6,15 +6,18 @@ - [Struct `UUID`](#0x1_transaction_context_UUID) +- [Constants](#@Constants_0) - [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) - [Function `create_unique_address`](#0x1_transaction_context_create_unique_address) +- [Function `create_unique_addr`](#0x1_transaction_context_create_unique_addr) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Function `create_uuid`](#0x1_transaction_context_create_uuid) -- [Specification](#@Specification_0) - - [Function `get_script_hash`](#@Specification_0_get_script_hash) +- [Specification](#@Specification_1) + - [Function `get_script_hash`](#@Specification_1_get_script_hash) -
+
use 0x1::features;
+
@@ -47,6 +50,21 @@ for storing an address
+ + +## Constants + + + + +UUID feature is not supported. + + +
const EUUID_NOT_SUPPORTED: u64 = 3;
+
+ + + ## Function `get_txn_hash` @@ -81,7 +99,32 @@ number of times inside a single transaction. Each such call increments the sequence number and generates a new unique address -
public fun create_unique_address(): address
+
fun create_unique_address(): address
+
+ + + +
+Implementation + + +
native fun create_unique_address(): address;
+
+ + + +
+ + + +## Function `create_unique_addr` + +Return a universally unique identifier. Internally calls +the private function create_unique_address. This function is +created for to feature gate the create_unique_address function. + + +
public fun create_unique_addr(): address
 
@@ -90,7 +133,10 @@ the sequence number and generates a new unique address Implementation -
public native fun create_unique_address(): address;
+
public fun create_unique_addr(): address {
+    assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED);
+    create_unique_address()
+}
 
@@ -138,6 +184,7 @@ the generated unique address wrapped in the UUID class.
public fun create_uuid(): UUID {
+    assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED);
     return UUID {
         unique_address: create_unique_address()
     }
@@ -148,12 +195,12 @@ the generated unique address wrapped in the UUID class.
 
 
 
-
+
 
 ## Specification
 
 
-
+
 
 ### Function `get_script_hash`
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move
index 05450e1bbb704..30c0ba294435a 100644
--- a/aptos-move/framework/aptos-framework/sources/object.move
+++ b/aptos-move/framework/aptos-framework/sources/object.move
@@ -214,7 +214,7 @@ module aptos_framework::object {
     /// The created object is deletable as we can guarantee the same UUID can
     /// never be regenerated with future txs.
     public fun create_object(creator_address: address): ConstructorRef {
-        let uuid = aptos_framework::transaction_context::create_unique_address();
+        let uuid = aptos_framework::transaction_context::create_unique_addr();
         create_object_internal(creator_address, uuid, true)
     }
 
diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move
index b9bb9fb42ea12..94f6ed3d6d902 100644
--- a/aptos-move/framework/aptos-framework/sources/transaction_context.move
+++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move
@@ -1,5 +1,10 @@
 module aptos_framework::transaction_context {
 
+    use std::features;
+
+    /// UUID feature is not supported.
+    const EUUID_NOT_SUPPORTED: u64 = 3;
+
     /// A wrapper denoting universally unique identifer (UUID)
     /// for storing an address
     struct UUID has drop, store {
@@ -14,14 +19,23 @@ module aptos_framework::transaction_context {
     /// specific to this transaction. This function can be called any
     /// number of times inside a single transaction. Each such call increments
     /// the sequence number and generates a new unique address
-    public native fun create_unique_address(): address;
+    native fun create_unique_address(): address;
 
+    /// Return a universally unique identifier. Internally calls
+    /// the private function `create_unique_address`. This function is
+    /// created for to feature gate the `create_unique_address` function.
+    public fun create_unique_addr(): address {
+        assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED);
+        create_unique_address()
+    }
+ 
     /// Return the script hash of the current entry function.
     public native fun get_script_hash(): vector;
 
     /// This method runs `create_unique_address` native function and returns 
     /// the generated unique address wrapped in the UUID class.
     public fun create_uuid(): UUID {
+        assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED);
         return UUID {
             unique_address: create_unique_address()
         }
diff --git a/aptos-move/framework/move-stdlib/doc/features.md b/aptos-move/framework/move-stdlib/doc/features.md
index 38c5f5a667623..f0570c2bd2142 100644
--- a/aptos-move/framework/move-stdlib/doc/features.md
+++ b/aptos-move/framework/move-stdlib/doc/features.md
@@ -61,6 +61,8 @@ return true.
 -  [Function `partial_governance_voting_enabled`](#0x1_features_partial_governance_voting_enabled)
 -  [Function `get_delegation_pool_partial_governance_voting`](#0x1_features_get_delegation_pool_partial_governance_voting)
 -  [Function `delegation_pool_partial_governance_voting_enabled`](#0x1_features_delegation_pool_partial_governance_voting_enabled)
+-  [Function `get_uuids`](#0x1_features_get_uuids)
+-  [Function `uuids_enabled`](#0x1_features_uuids_enabled)
 -  [Function `change_feature_flags`](#0x1_features_change_feature_flags)
 -  [Function `is_enabled`](#0x1_features_is_enabled)
 -  [Function `set`](#0x1_features_set)
@@ -330,6 +332,17 @@ Lifetime: permanent
 
 
 
+
+
+Whether enable MOVE functions to call create_uuid method to create UUIDs.
+Lifetime: transient
+
+
+
const UNIVERSALLY_UNIQUE_IDENTIFIERS: u64 = 22;
+
+ + + Whether to allow the use of binary format version v6. @@ -1031,6 +1044,52 @@ Lifetime: transient + + + + +## Function `get_uuids` + + + +
public fun get_uuids(): u64
+
+ + + +
+Implementation + + +
public fun get_uuids(): u64 { UNIVERSALLY_UNIQUE_IDENTIFIERS }
+
+ + + +
+ + + +## Function `uuids_enabled` + + + +
public fun uuids_enabled(): bool
+
+ + + +
+Implementation + + +
public fun uuids_enabled(): bool acquires Features {
+    is_enabled(UNIVERSALLY_UNIQUE_IDENTIFIERS)
+}
+
+ + +
diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index 21a18f27b3847..871e8aa3a68d6 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -194,6 +194,16 @@ module std::features { is_enabled(DELEGATION_POOL_PARTIAL_GOVERNANCE_VOTING) } + + /// Whether enable MOVE functions to call create_uuid method to create UUIDs. + /// Lifetime: transient + const UNIVERSALLY_UNIQUE_IDENTIFIERS: u64 = 22; + public fun get_uuids(): u64 { UNIVERSALLY_UNIQUE_IDENTIFIERS } + public fun uuids_enabled(): bool acquires Features { + is_enabled(UNIVERSALLY_UNIQUE_IDENTIFIERS) + } + + // ============================================================================================ // Feature Flag Implementation From ad6f336428284dbbe6b7ebe01635b0a40545e5c4 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 12:30:10 -0500 Subject: [PATCH 31/61] deprecated tag --- .../framework/aptos-framework/doc/object.md | 16 +++++++++------- .../aptos-framework/sources/object.move | 14 ++++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index c8fcec41748e3..dfd0d04f3b567 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -841,7 +841,7 @@ The created object is deletable as we can guarantee the same UUID can never be regenerated with future txs. -
public fun create_object(creator_address: address): object::ConstructorRef
+
public fun create_object(owner_address: address): object::ConstructorRef
 
@@ -850,9 +850,9 @@ never be regenerated with future txs. Implementation -
public fun create_object(creator_address: address): ConstructorRef {
+
public fun create_object(owner_address: address): ConstructorRef {
     let uuid = aptos_framework::transaction_context::create_unique_addr();
-    create_object_internal(creator_address, uuid, true)
+    create_object_internal(owner_address, uuid, true)
 }
 
@@ -864,11 +864,12 @@ never be regenerated with future txs. ## Function `create_object_from_account` -Deprecated. Use create_object instead. +Use create_object instead. Create a new object from a GUID generated by an account. -
public fun create_object_from_account(creator: &signer): object::ConstructorRef
+
#[deprecated]
+public fun create_object_from_account(creator: &signer): object::ConstructorRef
 
@@ -891,11 +892,12 @@ Create a new object from a GUID generated by an account. ## Function `create_object_from_object` -Deprecated. Use create_object instead. +Use create_object instead. Create a new object from a GUID generated by an object. -
public fun create_object_from_object(creator: &signer): object::ConstructorRef
+
#[deprecated]
+public fun create_object_from_object(creator: &signer): object::ConstructorRef
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 30c0ba294435a..f9c8c7386a76a 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -51,6 +51,10 @@ module aptos_framework::object { /// nesting, but any checks such as transfer will only be evaluated this deep. const MAXIMUM_OBJECT_NESTING: u8 = 8; + /// transaction_context::create_unique_address uses this for domain separation within it's native implementation + #[test_only] + const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; + /// Scheme identifier used to generate an object's address `obj_addr` as derived from another object. /// The object's address is generated as: /// ``` @@ -213,19 +217,21 @@ module aptos_framework::object { /// The UUID is computed sha3_256([transaction hash | uuid counter | 0xFB]). /// The created object is deletable as we can guarantee the same UUID can /// never be regenerated with future txs. - public fun create_object(creator_address: address): ConstructorRef { + public fun create_object(owner_address: address): ConstructorRef { let uuid = aptos_framework::transaction_context::create_unique_addr(); - create_object_internal(creator_address, uuid, true) + create_object_internal(owner_address, uuid, true) } - /// Deprecated. Use `create_object` instead. + #[deprecated] + /// Use `create_object` instead. /// Create a new object from a GUID generated by an account. public fun create_object_from_account(creator: &signer): ConstructorRef { let guid = account::create_guid(creator); create_object_from_guid(signer::address_of(creator), guid) } - /// Deprecated. Use `create_object` instead. + #[deprecated] + /// Use `create_object` instead. /// Create a new object from a GUID generated by an object. public fun create_object_from_object(creator: &signer): ConstructorRef acquires ObjectCore { let guid = create_guid(creator); From ea7fbb6881e63eaa9b26bd9661425d74e31f48f3 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 15:45:01 -0500 Subject: [PATCH 32/61] Add transaction context spec --- .../doc/transaction_context.md | 45 +++++++++++++++++++ .../sources/transaction_context.spec.move | 12 ++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 35c64dc864e00..89415db0bd88d 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -13,6 +13,8 @@ - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Function `create_uuid`](#0x1_transaction_context_create_uuid) - [Specification](#@Specification_1) + - [Function `get_txn_hash`](#@Specification_1_get_txn_hash) + - [Function `create_unique_address`](#@Specification_1_create_unique_address) - [Function `get_script_hash`](#@Specification_1_get_script_hash) @@ -200,6 +202,49 @@ the generated unique address wrapped in the UUID class. ## Specification + + +### Function `get_txn_hash` + + +
public fun get_txn_hash(): vector<u8>
+
+ + + + +
pragma opaque;
+aborts_if false;
+ensures result == spec_get_txn_hash();
+
+ + + + + + + +
fun spec_get_txn_hash(): vector<u8>;
+
+ + + + + +### Function `create_unique_address` + + +
fun create_unique_address(): address
+
+ + + + +
pragma opaque;
+
+ + + ### Function `get_script_hash` diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move index 0b1c59ee1a897..c0610ba4971f7 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move @@ -4,6 +4,14 @@ spec aptos_framework::transaction_context { aborts_if false; ensures result == spec_get_script_hash(); } - spec fun spec_get_script_hash(): vector; -} + spec get_txn_hash(): vector { + pragma opaque; + aborts_if false; + ensures result == spec_get_txn_hash(); + } + spec fun spec_get_txn_hash(): vector; + spec create_unique_address(): address { + pragma opaque; + } +} \ No newline at end of file From c267a234dd7834c61121ddd24c5332998e22911d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 16:01:01 -0500 Subject: [PATCH 33/61] Add a test case in transaction_context --- aptos-move/framework/aptos-framework/doc/object.md | 2 +- .../framework/aptos-framework/sources/object.move | 7 ++----- .../sources/transaction_context.move | 13 +++++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index dfd0d04f3b567..7b7160533487b 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -851,7 +851,7 @@ never be regenerated with future txs.
public fun create_object(owner_address: address): ConstructorRef {
-    let uuid = aptos_framework::transaction_context::create_unique_addr();
+    let uuid = transaction_context::create_unique_addr();
     create_object_internal(owner_address, uuid, true)
 }
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index f9c8c7386a76a..7415bc3a38e09 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -22,6 +22,7 @@ module aptos_framework::object { use std::vector; use aptos_framework::account; + use aptos_framework::transaction_context; use aptos_framework::create_signer::create_signer; use aptos_framework::event; use aptos_framework::from_bcs; @@ -51,10 +52,6 @@ module aptos_framework::object { /// nesting, but any checks such as transfer will only be evaluated this deep. const MAXIMUM_OBJECT_NESTING: u8 = 8; - /// transaction_context::create_unique_address uses this for domain separation within it's native implementation - #[test_only] - const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; - /// Scheme identifier used to generate an object's address `obj_addr` as derived from another object. /// The object's address is generated as: /// ``` @@ -218,7 +215,7 @@ module aptos_framework::object { /// The created object is deletable as we can guarantee the same UUID can /// never be regenerated with future txs. public fun create_object(owner_address: address): ConstructorRef { - let uuid = aptos_framework::transaction_context::create_unique_addr(); + let uuid = transaction_context::create_unique_addr(); create_object_internal(owner_address, uuid, true) } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 94f6ed3d6d902..db7d585de46f6 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -2,6 +2,10 @@ module aptos_framework::transaction_context { use std::features; + /// create_unique_address uses this for domain separation within it's native implementation + #[test_only] + const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; + /// UUID feature is not supported. const EUUID_NOT_SUPPORTED: u64 = 3; @@ -40,4 +44,13 @@ module aptos_framework::transaction_context { unique_address: create_unique_address() } } + + #[test] + fun test_correct_uuid() { + let uuid1 = create_unique_addr(); + let bytes = bcs::to_bytes(&guid::create(get_txn_hash(), 1)); + vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); + let uuid2 = from_bcs::to_address(hash::sha3_256(bytes)); + assert!(uuid1 == uuid2, 0); + } } From 7568b153663eecdcc98697f160a82d3f5c806dc0 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 16:14:14 -0500 Subject: [PATCH 34/61] Updated move test case --- .../sources/transaction_context_test.move | 4 ++-- .../framework/aptos-framework/doc/transaction_context.md | 4 +++- .../aptos-framework/sources/transaction_context.move | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index e8d65a66b9313..6bef42a0cf949 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -1,6 +1,6 @@ module 0x1::transaction_context_test { use std::vector; - use aptos_framework::transaction_context::create_uuid; + use aptos_framework::transaction_context::create_unique_address; /// When checking the value of aggregator fails. const ENOT_UNIQUE: u64 = 20; @@ -10,7 +10,7 @@ module 0x1::transaction_context_test { let i: u64 = 0; while (i < count) { i = i+1; - vector::push_back(&mut uuids, create_uuid()); + vector::push_back(&mut uuids, create_unique_address()); }; i = 0; while (i < count - 1) { diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 89415db0bd88d..7fe5235f56a40 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -98,7 +98,9 @@ Return a universally unique identifier (of type address) generated by hashing the transaction hash of this transaction and a sequence number specific to this transaction. This function can be called any number of times inside a single transaction. Each such call increments -the sequence number and generates a new unique address +the sequence number and generates a new unique address. +Uses Scheme in types/src/transaction/authenticator.rs for domain separation +from other ways of generating unique addresses.
fun create_unique_address(): address
diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move
index db7d585de46f6..714d3664aba61 100644
--- a/aptos-move/framework/aptos-framework/sources/transaction_context.move
+++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move
@@ -2,7 +2,7 @@ module aptos_framework::transaction_context {
 
     use std::features;
 
-    /// create_unique_address uses this for domain separation within it's native implementation
+    /// create_unique_address uses this for domain separation within its native implementation
     #[test_only]
     const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB;
 
@@ -22,7 +22,9 @@ module aptos_framework::transaction_context {
     /// by hashing the transaction hash of this transaction and a sequence number 
     /// specific to this transaction. This function can be called any
     /// number of times inside a single transaction. Each such call increments
-    /// the sequence number and generates a new unique address
+    /// the sequence number and generates a new unique address.
+    /// Uses Scheme in types/src/transaction/authenticator.rs for domain separation
+    /// from other ways of generating unique addresses.
     native fun create_unique_address(): address;
 
     /// Return a universally unique identifier. Internally calls

From 23f8776b685a246d580a1c475f3df34f07447f7d Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Thu, 22 Jun 2023 16:35:07 -0500
Subject: [PATCH 35/61] Add create_token method

---
 .../aptos-token-objects/doc/aptos_token.md    |  2 +-
 .../aptos-token-objects/doc/token.md          | 37 +++++++++++++++++++
 .../sources/aptos_token.move                  |  2 +-
 .../aptos-token-objects/sources/token.move    | 17 +++++++++
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
index 54c8cc83e58fc..5e8740af0c8f6 100644
--- a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
+++ b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
@@ -471,7 +471,7 @@ With an existing collection, directly mint a soul bound token into the recipient
     property_types: vector<String>,
     property_values: vector<vector<u8>>,
 ): ConstructorRef acquires AptosCollection {
-    let constructor_ref = token::create_from_account(
+    let constructor_ref = token::create_token(
         creator,
         collection,
         description,
diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md
index 0b23237681a04..7783f5da977ce 100644
--- a/aptos-move/framework/aptos-token-objects/doc/token.md
+++ b/aptos-move/framework/aptos-token-objects/doc/token.md
@@ -16,6 +16,7 @@ token are:
 -  [Struct `MutationEvent`](#0x4_token_MutationEvent)
 -  [Constants](#@Constants_0)
 -  [Function `create_common`](#0x4_token_create_common)
+-  [Function `create_token`](#0x4_token_create_token)
 -  [Function `create_named_token`](#0x4_token_create_named_token)
 -  [Function `create_from_account`](#0x4_token_create_from_account)
 -  [Function `create_token_address`](#0x4_token_create_token_address)
@@ -361,6 +362,42 @@ The token name is over the maximum length
 
 
 
+
+
+
+
+## Function `create_token`
+
+Creates a new token object with a unique address and returns the ConstructorRef
+for additional specialization.
+
+
+
public fun create_token(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
+
+ + + +
+Implementation + + +
public fun create_token(
+    creator: &signer,
+    collection_name: String,
+    description: String,
+    name: String,
+    royalty: Option<Royalty>,
+    uri: String,
+): ConstructorRef {
+    let creator_address = signer::address_of(creator);
+    let constructor_ref = object::create_object(creator_address);
+    create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri);
+    constructor_ref
+}
+
+ + +
diff --git a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move index 17c77fa3fe3b4..894414c90e34e 100644 --- a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move +++ b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move @@ -199,7 +199,7 @@ module aptos_token_objects::aptos_token { property_types: vector, property_values: vector>, ): ConstructorRef acquires AptosCollection { - let constructor_ref = token::create_from_account( + let constructor_ref = token::create_token( creator, collection, description, diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index 2867bc18c2822..2064d920cc44b 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -106,6 +106,23 @@ module aptos_token_objects::token { }; } + + /// Creates a new token object with a unique address and returns the ConstructorRef + /// for additional specialization. + public fun create_token( + creator: &signer, + collection_name: String, + description: String, + name: String, + royalty: Option, + uri: String, + ): ConstructorRef { + let creator_address = signer::address_of(creator); + let constructor_ref = object::create_object(creator_address); + create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri); + constructor_ref + } + /// Creates a new token object from a token name and returns the ConstructorRef for /// additional specialization. public fun create_named_token( From fb9bce15f578cc9df26361d92a739d031c6fa2c0 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 18:01:10 -0500 Subject: [PATCH 36/61] Update test cases --- .../sources/transaction_context_test.move | 4 ++-- .../aptos-framework/sources/transaction_context.move | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index 6bef42a0cf949..dbee5c7f2da2b 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -1,6 +1,6 @@ module 0x1::transaction_context_test { use std::vector; - use aptos_framework::transaction_context::create_unique_address; + use aptos_framework::transaction_context::create_unique_addr; /// When checking the value of aggregator fails. const ENOT_UNIQUE: u64 = 20; @@ -10,7 +10,7 @@ module 0x1::transaction_context_test { let i: u64 = 0; while (i < count) { i = i+1; - vector::push_back(&mut uuids, create_unique_address()); + vector::push_back(&mut uuids, create_unique_addr()); }; i = 0; while (i < count - 1) { diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 714d3664aba61..f4a9b375ea9f6 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -50,9 +50,9 @@ module aptos_framework::transaction_context { #[test] fun test_correct_uuid() { let uuid1 = create_unique_addr(); - let bytes = bcs::to_bytes(&guid::create(get_txn_hash(), 1)); + let bytes = std::bcs::to_bytes(&aptos_framework::guid::create(get_txn_hash(), 1)); vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); - let uuid2 = from_bcs::to_address(hash::sha3_256(bytes)); + let uuid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); assert!(uuid1 == uuid2, 0); } } From 82fec8ad00be28d54f975ad0a26782b95880c748 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 18:04:29 -0500 Subject: [PATCH 37/61] rust lint --- .../sources/transaction_context_test.move | 2 +- aptos-move/e2e-move-tests/src/tests/transaction_context.rs | 2 ++ aptos-move/framework/aptos-framework/sources/object.move | 2 +- .../aptos-framework/sources/transaction_context.move | 6 +++--- .../aptos-framework/sources/transaction_context.spec.move | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index dbee5c7f2da2b..5fc33423b8e97 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -1,7 +1,7 @@ module 0x1::transaction_context_test { use std::vector; use aptos_framework::transaction_context::create_unique_addr; - + /// When checking the value of aggregator fails. const ENOT_UNIQUE: u64 = 20; diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs index cb86774d97863..a72ee5ffd519d 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs @@ -1,3 +1,5 @@ +// Copyright © Aptos Foundation + use crate::{ assert_success, tests::common, diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 7415bc3a38e09..184584f9638cd 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -109,7 +109,7 @@ module aptos_framework::object { /// This is a one time ability given to the creator to configure the object as necessary struct ConstructorRef has drop { self: address, - /// Set to true so long as deleting the object is possible. + /// Set to true so long as deleting the object is possible. can_delete: bool, } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index f4a9b375ea9f6..eed46a6a28f99 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -19,7 +19,7 @@ module aptos_framework::transaction_context { public native fun get_txn_hash(): vector; /// Return a universally unique identifier (of type address) generated - /// by hashing the transaction hash of this transaction and a sequence number + /// by hashing the transaction hash of this transaction and a sequence number /// specific to this transaction. This function can be called any /// number of times inside a single transaction. Each such call increments /// the sequence number and generates a new unique address. @@ -34,11 +34,11 @@ module aptos_framework::transaction_context { assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED); create_unique_address() } - + /// Return the script hash of the current entry function. public native fun get_script_hash(): vector; - /// This method runs `create_unique_address` native function and returns + /// This method runs `create_unique_address` native function and returns /// the generated unique address wrapped in the UUID class. public fun create_uuid(): UUID { assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED); diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move index c0610ba4971f7..9929bf7fc6310 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move @@ -14,4 +14,4 @@ spec aptos_framework::transaction_context { spec create_unique_address(): address { pragma opaque; } -} \ No newline at end of file +} From 41cb9afe9555928db97db7c9845aacf5acba6743 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 22:22:33 -0500 Subject: [PATCH 38/61] Changed comments --- .../framework/aptos-framework/sources/transaction_context.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index eed46a6a28f99..9c35b6a116068 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -2,8 +2,8 @@ module aptos_framework::transaction_context { use std::features; - /// create_unique_address uses this for domain separation within its native implementation #[test_only] + /// create_unique_address uses this for domain separation within its native implementation const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; /// UUID feature is not supported. From 4df1c1c06d425b04e29aaf67ba43551c7f8f22be Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 22:29:51 -0500 Subject: [PATCH 39/61] Remove create_token method --- .../aptos-token-objects/doc/aptos_token.md | 2 +- .../aptos-token-objects/doc/token.md | 37 ------------------- .../sources/aptos_token.move | 2 +- .../aptos-token-objects/sources/token.move | 17 --------- 4 files changed, 2 insertions(+), 56 deletions(-) diff --git a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md index 5e8740af0c8f6..54c8cc83e58fc 100644 --- a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md +++ b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md @@ -471,7 +471,7 @@ With an existing collection, directly mint a soul bound token into the recipient property_types: vector<String>, property_values: vector<vector<u8>>, ): ConstructorRef acquires AptosCollection { - let constructor_ref = token::create_token( + let constructor_ref = token::create_from_account( creator, collection, description, diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md index 7783f5da977ce..0b23237681a04 100644 --- a/aptos-move/framework/aptos-token-objects/doc/token.md +++ b/aptos-move/framework/aptos-token-objects/doc/token.md @@ -16,7 +16,6 @@ token are: - [Struct `MutationEvent`](#0x4_token_MutationEvent) - [Constants](#@Constants_0) - [Function `create_common`](#0x4_token_create_common) -- [Function `create_token`](#0x4_token_create_token) - [Function `create_named_token`](#0x4_token_create_named_token) - [Function `create_from_account`](#0x4_token_create_from_account) - [Function `create_token_address`](#0x4_token_create_token_address) @@ -362,42 +361,6 @@ The token name is over the maximum length - - - - -## Function `create_token` - -Creates a new token object with a unique address and returns the ConstructorRef -for additional specialization. - - -
public fun create_token(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
-
- - - -
-Implementation - - -
public fun create_token(
-    creator: &signer,
-    collection_name: String,
-    description: String,
-    name: String,
-    royalty: Option<Royalty>,
-    uri: String,
-): ConstructorRef {
-    let creator_address = signer::address_of(creator);
-    let constructor_ref = object::create_object(creator_address);
-    create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri);
-    constructor_ref
-}
-
- - -
diff --git a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move index 894414c90e34e..17c77fa3fe3b4 100644 --- a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move +++ b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move @@ -199,7 +199,7 @@ module aptos_token_objects::aptos_token { property_types: vector, property_values: vector>, ): ConstructorRef acquires AptosCollection { - let constructor_ref = token::create_token( + let constructor_ref = token::create_from_account( creator, collection, description, diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index 2064d920cc44b..2867bc18c2822 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -106,23 +106,6 @@ module aptos_token_objects::token { }; } - - /// Creates a new token object with a unique address and returns the ConstructorRef - /// for additional specialization. - public fun create_token( - creator: &signer, - collection_name: String, - description: String, - name: String, - royalty: Option, - uri: String, - ): ConstructorRef { - let creator_address = signer::address_of(creator); - let constructor_ref = object::create_object(creator_address); - create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri); - constructor_ref - } - /// Creates a new token object from a token name and returns the ConstructorRef for /// additional specialization. public fun create_named_token( From 752caaec950ce3c7a42cc4955864a306177efa6e Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Thu, 22 Jun 2023 23:33:05 -0500 Subject: [PATCH 40/61] Add feature flag for test --- .../sources/transaction_context_test.move | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index 5fc33423b8e97..d353213e210b3 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -1,25 +1,28 @@ module 0x1::transaction_context_test { use std::vector; use aptos_framework::transaction_context::create_unique_addr; + use std::features; /// When checking the value of aggregator fails. const ENOT_UNIQUE: u64 = 20; public entry fun create_many_uuids(_account: &signer, count: u64) { - let uuids: vector
= vector
[]; - let i: u64 = 0; - while (i < count) { - i = i+1; - vector::push_back(&mut uuids, create_unique_addr()); - }; - i = 0; - while (i < count - 1) { - let j: u64 = i + 1; - while (j < count) { - assert!(*vector::borrow(&uuids, i) != *vector::borrow(&uuids, j), ENOT_UNIQUE); - j = j + 1; + if (features::uuids_enabled()) { + let uuids: vector
= vector
[]; + let i: u64 = 0; + while (i < count) { + i = i+1; + vector::push_back(&mut uuids, create_unique_addr()); }; - i = i + 1; - }; + i = 0; + while (i < count - 1) { + let j: u64 = i + 1; + while (j < count) { + assert!(*vector::borrow(&uuids, i) != *vector::borrow(&uuids, j), ENOT_UNIQUE); + j = j + 1; + }; + i = i + 1; + }; + } } } From 8cdf218a555cd8d709ddbea90f1b5ced1e3fb43d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 23 Jun 2023 11:40:28 -0500 Subject: [PATCH 41/61] fix a unit test --- .../aptos-framework/sources/transaction_context.move | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 9c35b6a116068..b78237922fc6d 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -49,9 +49,9 @@ module aptos_framework::transaction_context { #[test] fun test_correct_uuid() { - let uuid1 = create_unique_addr(); + let uuid1 = create_unique_address(); let bytes = std::bcs::to_bytes(&aptos_framework::guid::create(get_txn_hash(), 1)); - vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); + std::vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); let uuid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); assert!(uuid1 == uuid2, 0); } From 545283d6bc801269e4a61826700967bc585caed1 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 23 Jun 2023 12:39:43 -0500 Subject: [PATCH 42/61] Fix unit test --- .../framework/aptos-framework/sources/transaction_context.move | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index b78237922fc6d..115a00e98456b 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -50,7 +50,8 @@ module aptos_framework::transaction_context { #[test] fun test_correct_uuid() { let uuid1 = create_unique_address(); - let bytes = std::bcs::to_bytes(&aptos_framework::guid::create(get_txn_hash(), 1)); + let creation_num = 1; + let bytes = std::bcs::to_bytes(&aptos_framework::guid::create(get_txn_hash(), &mut creation_num)); std::vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); let uuid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); assert!(uuid1 == uuid2, 0); From 2cadd2cf5ab0088966a54056b6f556b6ce6e7941 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 23 Jun 2023 14:22:18 -0500 Subject: [PATCH 43/61] moved unit test to object.move --- .../doc/transaction_context.md | 25 +++++++++++++++++++ .../aptos-framework/sources/object.move | 17 +++++++++++++ .../sources/transaction_context.move | 14 ++--------- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 7fe5235f56a40..2f214ac2f7ba2 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -12,6 +12,7 @@ - [Function `create_unique_addr`](#0x1_transaction_context_create_unique_addr) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Function `create_uuid`](#0x1_transaction_context_create_uuid) +- [Function `get_unique_address`](#0x1_transaction_context_get_unique_address) - [Specification](#@Specification_1) - [Function `get_txn_hash`](#@Specification_1_get_txn_hash) - [Function `create_unique_address`](#@Specification_1_create_unique_address) @@ -197,6 +198,30 @@ the generated unique address wrapped in the UUID class. + + + + +## Function `get_unique_address` + + + +
public fun get_unique_address(uuid: transaction_context::UUID): address
+
+ + + +
+Implementation + + +
public fun get_unique_address(uuid: UUID): address {
+    uuid.unique_address
+}
+
+ + +
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 184584f9638cd..26c92c883e670 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -48,6 +48,10 @@ module aptos_framework::object { /// Explicitly separate the GUID space between Object and Account to prevent accidental overlap. const INIT_GUID_CREATION_NUM: u64 = 0x4000000000000; + #[test_only] + /// create_unique_address uses this for domain separation within its native implementation + const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; + /// Maximum nesting from one object to another. That is objects can technically have infinte /// nesting, but any checks such as transfer will only be evaluated this deep. const MAXIMUM_OBJECT_NESTING: u8 = 8; @@ -663,4 +667,17 @@ module aptos_framework::object { assert!(owner(hero) == @0x456, 0); transfer_with_ref(linear_transfer_ref_bad, @0x789); } + + #[test] + fun test_correct_uuid() { + if (std::features::uuids_enabled()) { + let uuid1 = aptos_framework::transaction_context::create_unique_addr(); + let bytes = aptos_framework::transaction_context::get_txn_hash(); + std::vector::push_back(&mut bytes, 0); + std::vector::push_back(&mut bytes, 1); + std::vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); + let uuid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); + assert!(uuid1 == uuid2, 0); + } + } } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 115a00e98456b..8dea944ad8c81 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -2,10 +2,6 @@ module aptos_framework::transaction_context { use std::features; - #[test_only] - /// create_unique_address uses this for domain separation within its native implementation - const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; - /// UUID feature is not supported. const EUUID_NOT_SUPPORTED: u64 = 3; @@ -47,13 +43,7 @@ module aptos_framework::transaction_context { } } - #[test] - fun test_correct_uuid() { - let uuid1 = create_unique_address(); - let creation_num = 1; - let bytes = std::bcs::to_bytes(&aptos_framework::guid::create(get_txn_hash(), &mut creation_num)); - std::vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); - let uuid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); - assert!(uuid1 == uuid2, 0); + public fun get_unique_address(uuid: UUID): address { + uuid.unique_address } } From aad09cc3cc8ce5874dc64468e38cecf039fd2138 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 23 Jun 2023 19:27:22 -0500 Subject: [PATCH 44/61] changing uuid to auid --- .../doc/transaction_context.md | 58 +++++++++---------- .../sources/transaction_context.move | 22 +++---- .../framework/move-stdlib/doc/features.md | 44 +++++++------- .../move-stdlib/sources/configs/features.move | 10 ++-- 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 2f214ac2f7ba2..9e79473e61f3b 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -5,13 +5,13 @@ -- [Struct `UUID`](#0x1_transaction_context_UUID) +- [Struct `AUID`](#0x1_transaction_context_AUID) - [Constants](#@Constants_0) - [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) - [Function `create_unique_address`](#0x1_transaction_context_create_unique_address) - [Function `create_unique_addr`](#0x1_transaction_context_create_unique_addr) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) -- [Function `create_uuid`](#0x1_transaction_context_create_uuid) +- [Function `create_auid`](#0x1_transaction_context_create_auid) - [Function `get_unique_address`](#0x1_transaction_context_get_unique_address) - [Specification](#@Specification_1) - [Function `get_txn_hash`](#@Specification_1_get_txn_hash) @@ -24,15 +24,15 @@ - + -## Struct `UUID` +## Struct `AUID` -A wrapper denoting universally unique identifer (UUID) +A wrapper denoting aptos unique identifer (AUID) for storing an address -
struct UUID has drop, store
+
struct AUID has drop, store
 
@@ -58,12 +58,12 @@ for storing an address ## Constants - + -UUID feature is not supported. +AUID feature is not supported. -
const EUUID_NOT_SUPPORTED: u64 = 3;
+
const EAUID_NOT_SUPPORTED: u64 = 3;
 
@@ -139,7 +139,7 @@ created for to feature gate the create_unique_address function.
public fun create_unique_addr(): address {
-    assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED);
+    assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
     create_unique_address()
 }
 
@@ -171,15 +171,15 @@ Return the script hash of the current entry function. - + -## Function `create_uuid` +## Function `create_auid` This method runs create_unique_address native function and returns -the generated unique address wrapped in the UUID class. +the generated unique address wrapped in the AUID class. -
public fun create_uuid(): transaction_context::UUID
+
public fun create_auid(): transaction_context::AUID
 
@@ -188,9 +188,9 @@ the generated unique address wrapped in the UUID class. Implementation -
public fun create_uuid(): UUID {
-    assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED);
-    return UUID {
+
public fun create_auid(): AUID {
+    assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
+    return AUID {
         unique_address: create_unique_address()
     }
 }
@@ -206,7 +206,7 @@ the generated unique address wrapped in the UUID class.
 
 
 
-
public fun get_unique_address(uuid: transaction_context::UUID): address
+
public fun get_unique_address(auid: transaction_context::AUID): address
 
@@ -215,8 +215,8 @@ the generated unique address wrapped in the UUID class. Implementation -
public fun get_unique_address(uuid: UUID): address {
-    uuid.unique_address
+
public fun get_unique_address(auid: AUID): address {
+    auid.unique_address
 }
 
@@ -229,29 +229,29 @@ the generated unique address wrapped in the UUID class. ## Specification - -### Function `get_txn_hash` + -
public fun get_txn_hash(): vector<u8>
+
fun spec_get_txn_hash(): vector<u8>;
 
+ -
pragma opaque;
-aborts_if false;
-ensures result == spec_get_txn_hash();
-
+### Function `get_txn_hash` +
public fun get_txn_hash(): vector<u8>
+
- -
fun spec_get_txn_hash(): vector<u8>;
+
pragma opaque;
+aborts_if false;
+ensures result == spec_get_txn_hash();
 
diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 8dea944ad8c81..4b539171f8757 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -2,12 +2,12 @@ module aptos_framework::transaction_context { use std::features; - /// UUID feature is not supported. - const EUUID_NOT_SUPPORTED: u64 = 3; + /// AUID feature is not supported. + const EAUID_NOT_SUPPORTED: u64 = 3; - /// A wrapper denoting universally unique identifer (UUID) + /// A wrapper denoting aptos unique identifer (AUID) /// for storing an address - struct UUID has drop, store { + struct AUID has drop, store { unique_address: address } @@ -27,7 +27,7 @@ module aptos_framework::transaction_context { /// the private function `create_unique_address`. This function is /// created for to feature gate the `create_unique_address` function. public fun create_unique_addr(): address { - assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED); + assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); create_unique_address() } @@ -35,15 +35,15 @@ module aptos_framework::transaction_context { public native fun get_script_hash(): vector; /// This method runs `create_unique_address` native function and returns - /// the generated unique address wrapped in the UUID class. - public fun create_uuid(): UUID { - assert!(features::uuids_enabled(), EUUID_NOT_SUPPORTED); - return UUID { + /// the generated unique address wrapped in the AUID class. + public fun create_auid(): AUID { + assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); + return AUID { unique_address: create_unique_address() } } - public fun get_unique_address(uuid: UUID): address { - uuid.unique_address + public fun get_unique_address(auid: AUID): address { + auid.unique_address } } diff --git a/aptos-move/framework/move-stdlib/doc/features.md b/aptos-move/framework/move-stdlib/doc/features.md index f0570c2bd2142..d02fd3a95d7fd 100644 --- a/aptos-move/framework/move-stdlib/doc/features.md +++ b/aptos-move/framework/move-stdlib/doc/features.md @@ -61,8 +61,8 @@ return true. - [Function `partial_governance_voting_enabled`](#0x1_features_partial_governance_voting_enabled) - [Function `get_delegation_pool_partial_governance_voting`](#0x1_features_get_delegation_pool_partial_governance_voting) - [Function `delegation_pool_partial_governance_voting_enabled`](#0x1_features_delegation_pool_partial_governance_voting_enabled) -- [Function `get_uuids`](#0x1_features_get_uuids) -- [Function `uuids_enabled`](#0x1_features_uuids_enabled) +- [Function `get_auids`](#0x1_features_get_auids) +- [Function `auids_enabled`](#0x1_features_auids_enabled) - [Function `change_feature_flags`](#0x1_features_change_feature_flags) - [Function `is_enabled`](#0x1_features_is_enabled) - [Function `set`](#0x1_features_set) @@ -128,6 +128,17 @@ Lifetime: transient + + +Whether enable MOVE functions to call create_auid method to create AUIDs. +Lifetime: transient + + +
const APTOS_UNIQUE_IDENTIFIERS: u64 = 22;
+
+ + + Whether the new BLAKE2B-256 hash function native is enabled. @@ -332,17 +343,6 @@ Lifetime: permanent - - -Whether enable MOVE functions to call create_uuid method to create UUIDs. -Lifetime: transient - - -
const UNIVERSALLY_UNIQUE_IDENTIFIERS: u64 = 22;
-
- - - Whether to allow the use of binary format version v6. @@ -1046,13 +1046,13 @@ Lifetime: transient - + -## Function `get_uuids` +## Function `get_auids` -
public fun get_uuids(): u64
+
public fun get_auids(): u64
 
@@ -1061,20 +1061,20 @@ Lifetime: transient Implementation -
public fun get_uuids(): u64 { UNIVERSALLY_UNIQUE_IDENTIFIERS }
+
public fun get_auids(): u64 { APTOS_UNIQUE_IDENTIFIERS }
 
- + -## Function `uuids_enabled` +## Function `auids_enabled` -
public fun uuids_enabled(): bool
+
public fun auids_enabled(): bool
 
@@ -1083,8 +1083,8 @@ Lifetime: transient Implementation -
public fun uuids_enabled(): bool acquires Features {
-    is_enabled(UNIVERSALLY_UNIQUE_IDENTIFIERS)
+
public fun auids_enabled(): bool acquires Features {
+    is_enabled(APTOS_UNIQUE_IDENTIFIERS)
 }
 
diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index 871e8aa3a68d6..b9db3e04839f8 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -195,12 +195,12 @@ module std::features { } - /// Whether enable MOVE functions to call create_uuid method to create UUIDs. + /// Whether enable MOVE functions to call create_auid method to create AUIDs. /// Lifetime: transient - const UNIVERSALLY_UNIQUE_IDENTIFIERS: u64 = 22; - public fun get_uuids(): u64 { UNIVERSALLY_UNIQUE_IDENTIFIERS } - public fun uuids_enabled(): bool acquires Features { - is_enabled(UNIVERSALLY_UNIQUE_IDENTIFIERS) + const APTOS_UNIQUE_IDENTIFIERS: u64 = 22; + public fun get_auids(): u64 { APTOS_UNIQUE_IDENTIFIERS } + public fun auids_enabled(): bool acquires Features { + is_enabled(APTOS_UNIQUE_IDENTIFIERS) } From 06aa5b94c478e7ddb0396345704110887e421e74 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Fri, 23 Jun 2023 19:39:31 -0500 Subject: [PATCH 45/61] rust lint --- .../framework/move-stdlib/doc/features.md | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/aptos-move/framework/move-stdlib/doc/features.md b/aptos-move/framework/move-stdlib/doc/features.md index ca2179921a90d..a237205951252 100644 --- a/aptos-move/framework/move-stdlib/doc/features.md +++ b/aptos-move/framework/move-stdlib/doc/features.md @@ -135,7 +135,7 @@ Whether enable MOVE functions to call create_auid method to create AUIDs. Lifetime: transient -
const APTOS_UNIQUE_IDENTIFIERS: u64 = 22;
+
const APTOS_UNIQUE_IDENTIFIERS: u64 = 23;
 
@@ -1058,21 +1058,37 @@ Lifetime: transient - + -## Function `get_auids` +## Function `gas_payer_enabled` -
public fun get_auids(): u64
+
public fun gas_payer_enabled(): bool
+
- -## Function `gas_payer_enabled` +
+Implementation -
public fun gas_payer_enabled(): bool
+
public fun gas_payer_enabled(): bool acquires Features {
+    is_enabled(GAS_PAYER_ENABLED)
+}
+
+ + + +
+ + + +## Function `get_auids` + + + +
public fun get_auids(): u64
 
@@ -1105,8 +1121,6 @@ Lifetime: transient
public fun auids_enabled(): bool acquires Features {
     is_enabled(APTOS_UNIQUE_IDENTIFIERS)
-
public fun gas_payer_enabled(): bool acquires Features {
-    is_enabled(GAS_PAYER_ENABLED)
 }
 
From 584cca2436ba2f802085412377ad469360c09c65 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 24 Jun 2023 22:50:06 -0500 Subject: [PATCH 46/61] Minor changes --- Cargo.lock | 1 - .../sources/transaction_context_test.move | 2 +- .../framework/aptos-framework/doc/object.md | 10 +++++++ .../doc/transaction_context.md | 26 +++++++++---------- .../aptos-framework/sources/object.move | 3 +-- .../sources/transaction_context.move | 6 ++--- .../move-stdlib/sources/configs/features.move | 2 +- types/Cargo.toml | 1 - 8 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7dde5dc754b5f..3b3d919cb2082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3400,7 +3400,6 @@ dependencies = [ "serde_bytes", "serde_json", "serde_yaml 0.8.26", - "sha2 0.9.9", "thiserror", "tiny-keccak", ] diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index d353213e210b3..9b7d8d63a7418 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -7,7 +7,7 @@ module 0x1::transaction_context_test { const ENOT_UNIQUE: u64 = 20; public entry fun create_many_uuids(_account: &signer, count: u64) { - if (features::uuids_enabled()) { + if (features::auids_enabled()) { let uuids: vector
= vector
[]; let i: u64 = 0; while (i < count) { diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 7b7160533487b..78e0634c45a53 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -428,6 +428,16 @@ Emitted whenever the object's owner field is changed. ## Constants + + +create_unique_address uses this for domain separation within its native implementation + + +
const DERIVE_UUID_ADDRESS_SCHEME: u8 = 251;
+
+ + + The object does not allow for deletion diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 9e79473e61f3b..3081ceacaf910 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -32,7 +32,7 @@ A wrapper denoting aptos unique identifer (AUID) for storing an address -
struct AUID has drop, store
+
struct AUID has copy, drop, store
 
@@ -63,7 +63,7 @@ for storing an address AUID feature is not supported. -
const EAUID_NOT_SUPPORTED: u64 = 3;
+
const EAUID_NOT_SUPPORTED: u64 = 1;
 
@@ -206,7 +206,7 @@ the generated unique address wrapped in the AUID class. -
public fun get_unique_address(auid: transaction_context::AUID): address
+
public fun get_unique_address(auid: &transaction_context::AUID): address
 
@@ -215,7 +215,7 @@ the generated unique address wrapped in the AUID class. Implementation -
public fun get_unique_address(auid: AUID): address {
+
public fun get_unique_address(auid: &AUID): address {
     auid.unique_address
 }
 
@@ -229,15 +229,6 @@ the generated unique address wrapped in the AUID class. ## Specification - - - - -
fun spec_get_txn_hash(): vector<u8>;
-
- - - ### Function `get_txn_hash` @@ -256,6 +247,15 @@ the generated unique address wrapped in the AUID class. + + + + +
fun spec_get_txn_hash(): vector<u8>;
+
+ + + ### Function `create_unique_address` diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 26c92c883e670..63ba10e7a2086 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -48,7 +48,6 @@ module aptos_framework::object { /// Explicitly separate the GUID space between Object and Account to prevent accidental overlap. const INIT_GUID_CREATION_NUM: u64 = 0x4000000000000; - #[test_only] /// create_unique_address uses this for domain separation within its native implementation const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; @@ -670,7 +669,7 @@ module aptos_framework::object { #[test] fun test_correct_uuid() { - if (std::features::uuids_enabled()) { + if (std::features::auids_enabled()) { let uuid1 = aptos_framework::transaction_context::create_unique_addr(); let bytes = aptos_framework::transaction_context::get_txn_hash(); std::vector::push_back(&mut bytes, 0); diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 4b539171f8757..2f7e9ac39cecc 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -3,11 +3,11 @@ module aptos_framework::transaction_context { use std::features; /// AUID feature is not supported. - const EAUID_NOT_SUPPORTED: u64 = 3; + const EAUID_NOT_SUPPORTED: u64 = 1; /// A wrapper denoting aptos unique identifer (AUID) /// for storing an address - struct AUID has drop, store { + struct AUID has copy, drop, store { unique_address: address } @@ -43,7 +43,7 @@ module aptos_framework::transaction_context { } } - public fun get_unique_address(auid: AUID): address { + public fun get_unique_address(auid: &AUID): address { auid.unique_address } } diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index e8fb6ef90aa1c..9f64c9ee8be45 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -200,7 +200,7 @@ module std::features { public fun gas_payer_enabled(): bool acquires Features { is_enabled(GAS_PAYER_ENABLED) } - + /// Whether enable MOVE functions to call create_auid method to create AUIDs. /// Lifetime: transient const APTOS_UNIQUE_IDENTIFIERS: u64 = 23; diff --git a/types/Cargo.toml b/types/Cargo.toml index b4fdc195fc992..fb27effe6cddf 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -36,7 +36,6 @@ serde = { workspace = true } serde_bytes = { workspace = true } serde_json = { workspace = true } serde_yaml = { workspace = true } -sha2 = { workspace = true } thiserror = { workspace = true } tiny-keccak = { workspace = true } From 16252d8533f31296291ff7545852ac6f8f02d7c8 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 24 Jun 2023 23:02:23 -0500 Subject: [PATCH 47/61] Change uuid to auid in tests --- .../sources/transaction_context_test.move | 8 ++++---- .../e2e-move-tests/src/tests/transaction_context.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index 9b7d8d63a7418..cfb47989c12c5 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -6,19 +6,19 @@ module 0x1::transaction_context_test { /// When checking the value of aggregator fails. const ENOT_UNIQUE: u64 = 20; - public entry fun create_many_uuids(_account: &signer, count: u64) { + public entry fun create_many_auids(_account: &signer, count: u64) { if (features::auids_enabled()) { - let uuids: vector
= vector
[]; + let auids: vector
= vector
[]; let i: u64 = 0; while (i < count) { i = i+1; - vector::push_back(&mut uuids, create_unique_addr()); + vector::push_back(&mut auids, create_unique_addr()); }; i = 0; while (i < count - 1) { let j: u64 = i + 1; while (j < count) { - assert!(*vector::borrow(&uuids, i) != *vector::borrow(&uuids, j), ENOT_UNIQUE); + assert!(*vector::borrow(&auids, i) != *vector::borrow(&auids, j), ENOT_UNIQUE); j = j + 1; }; i = i + 1; diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs index a72ee5ffd519d..69763dd37a54b 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs @@ -3,7 +3,7 @@ use crate::{ assert_success, tests::common, - transaction_context::{create_many_uuids, initialize}, + transaction_context::{create_many_auids, initialize}, MoveHarness, }; use aptos_language_e2e_tests::account::Account; @@ -13,10 +13,10 @@ fn setup() -> (MoveHarness, Account) { } #[test] -fn test_many_unique_uuids() { +fn test_many_unique_auids() { let (mut h, acc) = setup(); - let txn1 = create_many_uuids(&mut h, &acc, 50); + let txn1 = create_many_auids(&mut h, &acc, 50); assert_success!(h.run(txn1)); } From 77b200205def7114b58dfe22ad899cfe7b30550d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sat, 24 Jun 2023 23:04:34 -0500 Subject: [PATCH 48/61] Change uuid to auid in tests --- aptos-move/e2e-move-tests/src/transaction_context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aptos-move/e2e-move-tests/src/transaction_context.rs b/aptos-move/e2e-move-tests/src/transaction_context.rs index 961d4daa95dec..71463bd11e096 100644 --- a/aptos-move/e2e-move-tests/src/transaction_context.rs +++ b/aptos-move/e2e-move-tests/src/transaction_context.rs @@ -13,14 +13,14 @@ pub fn initialize(path: PathBuf) -> (MoveHarness, Account) { (harness, account) } -pub fn create_many_uuids( +pub fn create_many_auids( harness: &mut MoveHarness, account: &Account, count: u64, ) -> SignedTransaction { harness.create_entry_function( account, - str::parse("0x1::transaction_context_test::create_many_uuids").unwrap(), + str::parse("0x1::transaction_context_test::create_many_auids").unwrap(), vec![], vec![bcs::to_bytes(&count).unwrap()], ) From 8fc34f6bbc6fb90392b0765906b5a2b874d2af7d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Sun, 25 Jun 2023 18:18:25 -0500 Subject: [PATCH 49/61] changed name to generate_unique_address --- aptos-move/aptos-gas/src/aptos_framework.rs | 2 +- aptos-move/aptos-gas/src/gas_meter.rs | 2 +- .../sources/transaction_context_test.move | 4 +- .../framework/aptos-framework/doc/object.md | 16 ++--- .../doc/transaction_context.md | 68 +++++++++---------- .../aptos-framework/sources/object.move | 24 +++---- .../sources/transaction_context.move | 18 ++--- .../sources/transaction_context.spec.move | 2 +- aptos-move/framework/src/natives/mod.rs | 2 +- .../src/natives/transaction_context.rs | 28 ++++---- types/src/transaction/authenticator.rs | 12 ++-- 11 files changed, 89 insertions(+), 89 deletions(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index b89a5e7a37a2b..fc7c5e06c0b54 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -166,7 +166,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.transaction_context.get_txn_hash.base, { 9.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost - [.transaction_context.create_unique_address.base, { 9.. => "transaction_context.create_unique_address.base" }, 3000 * MUL], + [.transaction_context.generate_unique_address.base, { 9.. => "transaction_context.generate_unique_address.base" }, 3000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], diff --git a/aptos-move/aptos-gas/src/gas_meter.rs b/aptos-move/aptos-gas/src/gas_meter.rs index aedad57fe3e1a..aab25de0a642e 100644 --- a/aptos-move/aptos-gas/src/gas_meter.rs +++ b/aptos-move/aptos-gas/src/gas_meter.rs @@ -36,7 +36,7 @@ use std::collections::BTreeMap; // - V10 // - Storage gas charges (excluding "storage fees") stop respecting the storage gas curves // - V9 -// - Added create_uuid and get_txn_hash native functions +// - Added generate_unique_address_internal and get_txn_hash native functions // - Accurate tracking of the cost of loading resource groups // - V8 // - Added BLS12-381 operations. diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move index cfb47989c12c5..d428b7d7dffca 100644 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move +++ b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move @@ -1,6 +1,6 @@ module 0x1::transaction_context_test { use std::vector; - use aptos_framework::transaction_context::create_unique_addr; + use aptos_framework::transaction_context::generate_unique_address; use std::features; /// When checking the value of aggregator fails. @@ -12,7 +12,7 @@ module 0x1::transaction_context_test { let i: u64 = 0; while (i < count) { i = i+1; - vector::push_back(&mut auids, create_unique_addr()); + vector::push_back(&mut auids, generate_unique_address()); }; i = 0; while (i < count - 1) { diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 78e0634c45a53..c2ee437feb7c0 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -428,12 +428,12 @@ Emitted whenever the object's owner field is changed. ## Constants - + -create_unique_address uses this for domain separation within its native implementation +generate_unique_address uses this for domain separation within its native implementation -
const DERIVE_UUID_ADDRESS_SCHEME: u8 = 251;
+
const DERIVE_AUID_ADDRESS_SCHEME: u8 = 251;
 
@@ -845,9 +845,9 @@ Derivde objects, similar to named objects, cannot be deleted. ## Function `create_object` -Create a new object by generating a random UUID based on transaction hash. -The UUID is computed sha3_256([transaction hash | uuid counter | 0xFB]). -The created object is deletable as we can guarantee the same UUID can +Create a new object by generating a random unique address based on transaction hash. +The unique address is computed sha3_256([transaction hash | auid counter | 0xFB]). +The created object is deletable as we can guarantee the same unique address can never be regenerated with future txs. @@ -861,8 +861,8 @@ never be regenerated with future txs.
public fun create_object(owner_address: address): ConstructorRef {
-    let uuid = transaction_context::create_unique_addr();
-    create_object_internal(owner_address, uuid, true)
+    let unique_address = transaction_context::generate_unique_address();
+    create_object_internal(owner_address, unique_address, true)
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index 3081ceacaf910..a5c0f3a1bcbf1 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -8,14 +8,14 @@ - [Struct `AUID`](#0x1_transaction_context_AUID) - [Constants](#@Constants_0) - [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) -- [Function `create_unique_address`](#0x1_transaction_context_create_unique_address) -- [Function `create_unique_addr`](#0x1_transaction_context_create_unique_addr) +- [Function `generate_unique_address_internal`](#0x1_transaction_context_generate_unique_address_internal) +- [Function `generate_unique_address`](#0x1_transaction_context_generate_unique_address) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) -- [Function `create_auid`](#0x1_transaction_context_create_auid) +- [Function `generate_auid`](#0x1_transaction_context_generate_auid) - [Function `get_unique_address`](#0x1_transaction_context_get_unique_address) - [Specification](#@Specification_1) - [Function `get_txn_hash`](#@Specification_1_get_txn_hash) - - [Function `create_unique_address`](#@Specification_1_create_unique_address) + - [Function `generate_unique_address_internal`](#@Specification_1_generate_unique_address_internal) - [Function `get_script_hash`](#@Specification_1_get_script_hash) @@ -32,7 +32,7 @@ A wrapper denoting aptos unique identifer (AUID) for storing an address -
struct AUID has copy, drop, store
+
struct AUID has drop, store
 
@@ -91,9 +91,9 @@ Return the transaction hash of the current transaction - + -## Function `create_unique_address` +## Function `generate_unique_address_internal` Return a universally unique identifier (of type address) generated by hashing the transaction hash of this transaction and a sequence number @@ -104,7 +104,7 @@ Uses Scheme in types/src/transaction/authenticator.rs for domain separation from other ways of generating unique addresses. -
fun create_unique_address(): address
+
fun generate_unique_address_internal(): address
 
@@ -113,23 +113,23 @@ from other ways of generating unique addresses. Implementation -
native fun create_unique_address(): address;
+
native fun generate_unique_address_internal(): address;
 
- + -## Function `create_unique_addr` +## Function `generate_unique_address` Return a universally unique identifier. Internally calls -the private function create_unique_address. This function is -created for to feature gate the create_unique_address function. +the private function generate_unique_address_internal. This function is +created for to feature gate the generate_unique_address_internal function. -
public fun create_unique_addr(): address
+
public fun generate_unique_address(): address
 
@@ -138,9 +138,9 @@ created for to feature gate the create_unique_address function. Implementation -
public fun create_unique_addr(): address {
+
public fun generate_unique_address(): address {
     assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
-    create_unique_address()
+    generate_unique_address_internal()
 }
 
@@ -171,15 +171,15 @@ Return the script hash of the current entry function. - + -## Function `create_auid` +## Function `generate_auid` -This method runs create_unique_address native function and returns +This method runs generate_unique_address_internal native function and returns the generated unique address wrapped in the AUID class. -
public fun create_auid(): transaction_context::AUID
+
public fun generate_auid(): transaction_context::AUID
 
@@ -188,10 +188,10 @@ the generated unique address wrapped in the AUID class. Implementation -
public fun create_auid(): AUID {
+
public fun generate_auid(): AUID {
     assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
     return AUID {
-        unique_address: create_unique_address()
+        unique_address: generate_unique_address_internal()
     }
 }
 
@@ -229,39 +229,39 @@ the generated unique address wrapped in the AUID class. ## Specification - -### Function `get_txn_hash` + -
public fun get_txn_hash(): vector<u8>
+
fun spec_get_txn_hash(): vector<u8>;
 
+ -
pragma opaque;
-aborts_if false;
-ensures result == spec_get_txn_hash();
-
+### Function `get_txn_hash` +
public fun get_txn_hash(): vector<u8>
+
- -
fun spec_get_txn_hash(): vector<u8>;
+
pragma opaque;
+aborts_if false;
+ensures result == spec_get_txn_hash();
 
- + -### Function `create_unique_address` +### Function `generate_unique_address_internal` -
fun create_unique_address(): address
+
fun generate_unique_address_internal(): address
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 63ba10e7a2086..bfa247b736ae4 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -48,8 +48,8 @@ module aptos_framework::object { /// Explicitly separate the GUID space between Object and Account to prevent accidental overlap. const INIT_GUID_CREATION_NUM: u64 = 0x4000000000000; - /// create_unique_address uses this for domain separation within its native implementation - const DERIVE_UUID_ADDRESS_SCHEME: u8 = 0xFB; + /// generate_unique_address uses this for domain separation within its native implementation + const DERIVE_AUID_ADDRESS_SCHEME: u8 = 0xFB; /// Maximum nesting from one object to another. That is objects can technically have infinte /// nesting, but any checks such as transfer will only be evaluated this deep. @@ -213,13 +213,13 @@ module aptos_framework::object { create_object_internal(creator_address, obj_addr, false) } - /// Create a new object by generating a random UUID based on transaction hash. - /// The UUID is computed sha3_256([transaction hash | uuid counter | 0xFB]). - /// The created object is deletable as we can guarantee the same UUID can + /// Create a new object by generating a random unique address based on transaction hash. + /// The unique address is computed sha3_256([transaction hash | auid counter | 0xFB]). + /// The created object is deletable as we can guarantee the same unique address can /// never be regenerated with future txs. public fun create_object(owner_address: address): ConstructorRef { - let uuid = transaction_context::create_unique_addr(); - create_object_internal(owner_address, uuid, true) + let unique_address = transaction_context::generate_unique_address(); + create_object_internal(owner_address, unique_address, true) } #[deprecated] @@ -668,15 +668,15 @@ module aptos_framework::object { } #[test] - fun test_correct_uuid() { + fun test_correct_auid() { if (std::features::auids_enabled()) { - let uuid1 = aptos_framework::transaction_context::create_unique_addr(); + let auid1 = aptos_framework::transaction_context::generate_unique_address(); let bytes = aptos_framework::transaction_context::get_txn_hash(); std::vector::push_back(&mut bytes, 0); std::vector::push_back(&mut bytes, 1); - std::vector::push_back(&mut bytes, DERIVE_UUID_ADDRESS_SCHEME); - let uuid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); - assert!(uuid1 == uuid2, 0); + std::vector::push_back(&mut bytes, DERIVE_AUID_ADDRESS_SCHEME); + let auid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes)); + assert!(auid1 == auid2, 0); } } } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 2f7e9ac39cecc..8a8a3e24f8c91 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -7,7 +7,7 @@ module aptos_framework::transaction_context { /// A wrapper denoting aptos unique identifer (AUID) /// for storing an address - struct AUID has copy, drop, store { + struct AUID has drop, store { unique_address: address } @@ -21,25 +21,25 @@ module aptos_framework::transaction_context { /// the sequence number and generates a new unique address. /// Uses Scheme in types/src/transaction/authenticator.rs for domain separation /// from other ways of generating unique addresses. - native fun create_unique_address(): address; + native fun generate_unique_address_internal(): address; /// Return a universally unique identifier. Internally calls - /// the private function `create_unique_address`. This function is - /// created for to feature gate the `create_unique_address` function. - public fun create_unique_addr(): address { + /// the private function `generate_unique_address_internal`. This function is + /// created for to feature gate the `generate_unique_address_internal` function. + public fun generate_unique_address(): address { assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); - create_unique_address() + generate_unique_address_internal() } /// Return the script hash of the current entry function. public native fun get_script_hash(): vector; - /// This method runs `create_unique_address` native function and returns + /// This method runs `generate_unique_address_internal` native function and returns /// the generated unique address wrapped in the AUID class. - public fun create_auid(): AUID { + public fun generate_auid(): AUID { assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); return AUID { - unique_address: create_unique_address() + unique_address: generate_unique_address_internal() } } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move index 9929bf7fc6310..822acc17b7e66 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move @@ -11,7 +11,7 @@ spec aptos_framework::transaction_context { ensures result == spec_get_txn_hash(); } spec fun spec_get_txn_hash(): vector; - spec create_unique_address(): address { + spec generate_unique_address_internal(): address { pragma opaque; } } diff --git a/aptos-move/framework/src/natives/mod.rs b/aptos-move/framework/src/natives/mod.rs index 6f2b88a1536b4..177b1c0416870 100644 --- a/aptos-move/framework/src/natives/mod.rs +++ b/aptos-move/framework/src/natives/mod.rs @@ -228,7 +228,7 @@ impl GasParameters { transaction_context: transaction_context::GasParameters { get_txn_hash: transaction_context::GetTxnHashGasParameters { base: 0.into() }, get_script_hash: transaction_context::GetScriptHashGasParameters { base: 0.into() }, - create_unique_address: transaction_context::CreateUniqueAddressGasParameters { + generate_unique_address: transaction_context::GenerateUniqueAddressGasParameters { base: 0.into(), }, }, diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 6d5e08901edcc..f2423ca825de5 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -19,8 +19,8 @@ use std::{collections::VecDeque, fmt::Debug, sync::Arc}; #[derive(Tid)] pub struct NativeTransactionContext { txn_hash: Vec, - /// This is the number of UUIDs (Universally unique identifiers) issued during the execution of this transaction - uuid_counter: u64, + /// This is the number of AUIDs (Aptos unique identifiers) issued during the execution of this transaction + auid_counter: u64, script_hash: Vec, chain_id: u8, } @@ -31,7 +31,7 @@ impl NativeTransactionContext { pub fn new(txn_hash: Vec, script_hash: Vec, chain_id: u8) -> Self { Self { txn_hash, - uuid_counter: 0, + auid_counter: 0, script_hash, chain_id, } @@ -69,18 +69,18 @@ fn native_get_txn_hash( } /*************************************************************************************************** - * native fun create_uuid + * native fun generate_unique_address * * gas cost: base_cost * **************************************************************************************************/ #[derive(Clone, Debug)] -pub struct CreateUniqueAddressGasParameters { +pub struct GenerateUniqueAddressGasParameters { pub base: InternalGas, } -fn native_create_unique_address( - gas_params: &CreateUniqueAddressGasParameters, +fn native_generate_unique_address( + gas_params: &GenerateUniqueAddressGasParameters, context: &mut SafeNativeContext, mut _ty_args: Vec, _args: VecDeque, @@ -90,11 +90,11 @@ fn native_create_unique_address( let mut transaction_context = context .extensions_mut() .get_mut::(); - transaction_context.uuid_counter += 1; + transaction_context.auid_counter += 1; - let hash_vec = AuthenticationKey::from_preimage(&AuthenticationKeyPreimage::uuid( + let hash_vec = AuthenticationKey::from_preimage(&AuthenticationKeyPreimage::auid( transaction_context.txn_hash.clone(), - transaction_context.uuid_counter, + transaction_context.auid_counter, )); Ok(smallvec![Value::address(AccountAddress::new( hash_vec @@ -138,7 +138,7 @@ fn native_get_script_hash( pub struct GasParameters { pub get_txn_hash: GetTxnHashGasParameters, pub get_script_hash: GetScriptHashGasParameters, - pub create_unique_address: CreateUniqueAddressGasParameters, + pub generate_unique_address: GenerateUniqueAddressGasParameters, } pub fn make_all( @@ -157,12 +157,12 @@ pub fn make_all( ), ), ( - "create_uuid", + "generate_unique_address_internal", make_safe_native( - gas_params.create_unique_address, + gas_params.generate_unique_address, timed_features.clone(), features.clone(), - native_create_unique_address, + native_generate_unique_address, ), ), ( diff --git a/types/src/transaction/authenticator.rs b/types/src/transaction/authenticator.rs index 6b0af07a142e8..82203a9fe1ded 100644 --- a/types/src/transaction/authenticator.rs +++ b/types/src/transaction/authenticator.rs @@ -246,7 +246,7 @@ pub enum Scheme { /// resources accounts. This application serves to domain separate hashes. Without such /// separation, an adversary could create (and get a signer for) a these accounts /// when a their address matches matches an existing address of a MultiEd25519 wallet. - DeriveUuid = 251, + DeriveAuid = 251, DeriveObjectAddressFromObject = 252, DeriveObjectAddressFromGuid = 253, DeriveObjectAddressFromSeed = 254, @@ -258,7 +258,7 @@ impl fmt::Display for Scheme { let display = match self { Scheme::Ed25519 => "Ed25519", Scheme::MultiEd25519 => "MultiEd25519", - Scheme::DeriveUuid => "DeriveUuid", + Scheme::DeriveAuid => "DeriveAuid", Scheme::DeriveObjectAddressFromObject => "DeriveObjectAddressFromObject", Scheme::DeriveObjectAddressFromGuid => "DeriveObjectAddressFromGuid", Scheme::DeriveObjectAddressFromSeed => "DeriveObjectAddressFromSeed", @@ -463,12 +463,12 @@ impl AuthenticationKeyPreimage { Self::new(public_key.to_bytes(), Scheme::MultiEd25519) } - /// Construct a preimage from a transaction-derived UUID as (txn_hash || uuid_scheme_id) - pub fn uuid(txn_hash: Vec, uuid_counter: u64) -> AuthenticationKeyPreimage { + /// Construct a preimage from a transaction-derived AUID as (txn_hash || auid_scheme_id) + pub fn auid(txn_hash: Vec, auid_counter: u64) -> AuthenticationKeyPreimage { let mut hash_arg = Vec::new(); hash_arg.extend(txn_hash); - hash_arg.extend(uuid_counter.to_le_bytes().to_vec()); - hash_arg.push(Scheme::DeriveUuid as u8); + hash_arg.extend(auid_counter.to_le_bytes().to_vec()); + hash_arg.push(Scheme::DeriveAuid as u8); Self(hash_arg) } From 53e4d3d5fe86075213d8196a08b880b4ba33c76f Mon Sep 17 00:00:00 2001 From: Junkil Park Date: Mon, 26 Jun 2023 07:21:57 -0700 Subject: [PATCH 50/61] Fixed the specs which timeout --- aptos-move/framework/aptos-framework/doc/staking_config.md | 3 ++- .../framework/aptos-framework/doc/transaction_validation.md | 3 ++- .../aptos-framework/sources/configs/staking_config.spec.move | 1 + .../aptos-framework/sources/transaction_validation.spec.move | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/staking_config.md b/aptos-move/framework/aptos-framework/doc/staking_config.md index 92e77e132bfdf..d0f21450963a2 100644 --- a/aptos-move/framework/aptos-framework/doc/staking_config.md +++ b/aptos-move/framework/aptos-framework/doc/staking_config.md @@ -1191,7 +1191,8 @@ StakingRewardsConfig does not exist under the aptos_framework before creating it -
aborts_if !exists<StakingRewardsConfig>(@aptos_framework);
+
pragma verify_duration_estimate = 120;
+aborts_if !exists<StakingRewardsConfig>(@aptos_framework);
 aborts_if !features::spec_periodical_reward_rate_decrease_enabled();
 include StakingRewardsConfigRequirement;
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_validation.md b/aptos-move/framework/aptos-framework/doc/transaction_validation.md index 44896c2d6c0ac..c9eb48546eebc 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_validation.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_validation.md @@ -698,7 +698,8 @@ Aborts if length of public key hashed vector not equal the number of singers. -
let gas_payer = if (txn_sequence_number < GAS_PAYER_FLAG_BIT) {
+
pragma verify_duration_estimate = 120;
+let gas_payer = if (txn_sequence_number < GAS_PAYER_FLAG_BIT) {
     signer::address_of(sender)
 } else {
     secondary_signer_addresses[len(secondary_signer_addresses) - 1]
diff --git a/aptos-move/framework/aptos-framework/sources/configs/staking_config.spec.move b/aptos-move/framework/aptos-framework/sources/configs/staking_config.spec.move
index f87769d4a89a9..1de8d344a2670 100644
--- a/aptos-move/framework/aptos-framework/sources/configs/staking_config.spec.move
+++ b/aptos-move/framework/aptos-framework/sources/configs/staking_config.spec.move
@@ -83,6 +83,7 @@ spec aptos_framework::staking_config {
     }
 
     spec calculate_and_save_latest_epoch_rewards_rate(): FixedPoint64 {
+        pragma verify_duration_estimate = 120;
         aborts_if !exists(@aptos_framework);
         aborts_if !features::spec_periodical_reward_rate_decrease_enabled();
         include StakingRewardsConfigRequirement;
diff --git a/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move b/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move
index b997af5fad0f4..a125f1d344b12 100644
--- a/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move
+++ b/aptos-move/framework/aptos-framework/sources/transaction_validation.spec.move
@@ -110,6 +110,7 @@ spec aptos_framework::transaction_validation {
         txn_expiration_time: u64,
         chain_id: u8,
     ) {
+        pragma verify_duration_estimate = 120;
         let gas_payer = if (txn_sequence_number < GAS_PAYER_FLAG_BIT) {
             signer::address_of(sender)
         } else {

From c3f1a1af0014c426c34af255f7666f6468b208ae Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Mon, 26 Jun 2023 10:48:15 -0700
Subject: [PATCH 51/61] Fixed a unit test

---
 .../aptos-framework/sources/object.move       | 30 ++++++++++++-------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move
index bfa247b736ae4..2e991c3d6fd26 100644
--- a/aptos-move/framework/aptos-framework/sources/object.move
+++ b/aptos-move/framework/aptos-framework/sources/object.move
@@ -667,16 +667,24 @@ module aptos_framework::object {
         transfer_with_ref(linear_transfer_ref_bad, @0x789);
     }
 
-    #[test]
-    fun test_correct_auid() {
-        if (std::features::auids_enabled()) {
-            let auid1 = aptos_framework::transaction_context::generate_unique_address();
-            let bytes = aptos_framework::transaction_context::get_txn_hash();
-            std::vector::push_back(&mut bytes, 0);
-            std::vector::push_back(&mut bytes, 1);
-            std::vector::push_back(&mut bytes, DERIVE_AUID_ADDRESS_SCHEME);
-            let auid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes));
-            assert!(auid1 == auid2, 0);
-        }
+    #[test(fx = @std)]
+    fun test_correct_auid(fx: signer) {
+        use std::features;
+        let feature = features::get_auids();
+        features::change_feature_flags(&fx, vector[feature], vector[]);
+
+        let auid1 = aptos_framework::transaction_context::generate_unique_address();
+        let bytes = aptos_framework::transaction_context::get_txn_hash();
+        std::vector::push_back(&mut bytes, 1);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, 0);
+        std::vector::push_back(&mut bytes, DERIVE_AUID_ADDRESS_SCHEME);
+        let auid2 = aptos_framework::from_bcs::to_address(std::hash::sha3_256(bytes));
+        assert!(auid1 == auid2, 0);
     }
 }

From 6d7b0ddd5ddb272202e5e9e3a84caec6015a30b0 Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Mon, 26 Jun 2023 11:16:28 -0700
Subject: [PATCH 52/61] Shift test from e2e-move-tests to
 transaction_context.move

---
 aptos-move/aptos-gas/src/aptos_framework.rs   |  4 +--
 aptos-move/aptos-gas/src/gas_meter.rs         |  2 +-
 aptos-move/e2e-move-tests/src/lib.rs          |  1 -
 aptos-move/e2e-move-tests/src/tests/mod.rs    |  1 -
 .../tests/transaction_context.data/Move.toml  |  6 ----
 .../sources/transaction_context_test.move     | 28 -------------------
 .../src/tests/transaction_context.rs          | 22 ---------------
 .../e2e-move-tests/src/transaction_context.rs | 27 ------------------
 .../framework/aptos-framework/doc/object.md   |  2 +-
 .../doc/transaction_context.md                | 10 +++----
 .../aptos-framework/sources/object.move       |  2 +-
 .../sources/transaction_context.move          | 28 ++++++++++++++++++-
 12 files changed, 37 insertions(+), 96 deletions(-)
 delete mode 100644 aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml
 delete mode 100644 aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move
 delete mode 100644 aptos-move/e2e-move-tests/src/tests/transaction_context.rs
 delete mode 100644 aptos-move/e2e-move-tests/src/transaction_context.rs

diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs
index fc7c5e06c0b54..c00c56df6bd90 100644
--- a/aptos-move/aptos-gas/src/aptos_framework.rs
+++ b/aptos-move/aptos-gas/src/aptos_framework.rs
@@ -163,10 +163,10 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo
     [.util.from_bytes.base, "util.from_bytes.base", 300 * MUL],
     [.util.from_bytes.per_byte, "util.from_bytes.per_byte", 5 * MUL],
 
-    [.transaction_context.get_txn_hash.base, { 9.. => "transaction_context.get_txn_hash.base" }, 200 * MUL],
+    [.transaction_context.get_txn_hash.base, { 10.. => "transaction_context.get_txn_hash.base" }, 200 * MUL],
     [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL],
     // Using SHA2-256's cost
-    [.transaction_context.generate_unique_address.base, { 9.. => "transaction_context.generate_unique_address.base" }, 3000 * MUL],
+    [.transaction_context.generate_unique_address.base, { 10.. => "transaction_context.generate_unique_address.base" }, 3000 * MUL],
 
     [.code.request_publish.base, "code.request_publish.base", 500 * MUL],
     [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL],
diff --git a/aptos-move/aptos-gas/src/gas_meter.rs b/aptos-move/aptos-gas/src/gas_meter.rs
index aab25de0a642e..f2e4f5dc031cf 100644
--- a/aptos-move/aptos-gas/src/gas_meter.rs
+++ b/aptos-move/aptos-gas/src/gas_meter.rs
@@ -34,9 +34,9 @@ use std::collections::BTreeMap;
 
 // Change log:
 // - V10
+//   - Added generate_unique_address_internal and get_txn_hash native functions
 //   - Storage gas charges (excluding "storage fees") stop respecting the storage gas curves
 // - V9
-//   - Added generate_unique_address_internal and get_txn_hash native functions
 //   - Accurate tracking of the cost of loading resource groups
 // - V8
 //   - Added BLS12-381 operations.
diff --git a/aptos-move/e2e-move-tests/src/lib.rs b/aptos-move/e2e-move-tests/src/lib.rs
index 078955742c2df..6b7b3f6688eb3 100644
--- a/aptos-move/e2e-move-tests/src/lib.rs
+++ b/aptos-move/e2e-move-tests/src/lib.rs
@@ -5,7 +5,6 @@ pub mod aggregator;
 pub mod aptos_governance;
 pub mod harness;
 pub mod stake;
-pub mod transaction_context;
 pub mod transaction_fee;
 
 use anyhow::bail;
diff --git a/aptos-move/e2e-move-tests/src/tests/mod.rs b/aptos-move/e2e-move-tests/src/tests/mod.rs
index 4c53bcc23309a..d48beaa0bcfc7 100644
--- a/aptos-move/e2e-move-tests/src/tests/mod.rs
+++ b/aptos-move/e2e-move-tests/src/tests/mod.rs
@@ -35,7 +35,6 @@ mod state_metadata;
 mod string_args;
 mod token_event_store;
 mod token_objects;
-mod transaction_context;
 mod transaction_fee;
 mod type_too_large;
 mod vector_numeric_address;
diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml
deleted file mode 100644
index f98dd748225f9..0000000000000
--- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/Move.toml
+++ /dev/null
@@ -1,6 +0,0 @@
-[package]
-name = "transaction_context_test"
-version = "0.0.0"
-
-[dependencies]
-AptosFramework = { local = "../../../../framework/aptos-framework" }
diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move b/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move
deleted file mode 100644
index d428b7d7dffca..0000000000000
--- a/aptos-move/e2e-move-tests/src/tests/transaction_context.data/sources/transaction_context_test.move
+++ /dev/null
@@ -1,28 +0,0 @@
-module 0x1::transaction_context_test {
-    use std::vector;
-    use aptos_framework::transaction_context::generate_unique_address;
-    use std::features;
-
-    /// When checking the value of aggregator fails.
-    const ENOT_UNIQUE: u64 = 20;
-
-    public entry fun create_many_auids(_account: &signer, count: u64) {
-        if (features::auids_enabled()) {
-            let auids: vector
= vector
[]; - let i: u64 = 0; - while (i < count) { - i = i+1; - vector::push_back(&mut auids, generate_unique_address()); - }; - i = 0; - while (i < count - 1) { - let j: u64 = i + 1; - while (j < count) { - assert!(*vector::borrow(&auids, i) != *vector::borrow(&auids, j), ENOT_UNIQUE); - j = j + 1; - }; - i = i + 1; - }; - } - } -} diff --git a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs b/aptos-move/e2e-move-tests/src/tests/transaction_context.rs deleted file mode 100644 index 69763dd37a54b..0000000000000 --- a/aptos-move/e2e-move-tests/src/tests/transaction_context.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright © Aptos Foundation - -use crate::{ - assert_success, - tests::common, - transaction_context::{create_many_auids, initialize}, - MoveHarness, -}; -use aptos_language_e2e_tests::account::Account; - -fn setup() -> (MoveHarness, Account) { - initialize(common::test_dir_path("transaction_context.data")) -} - -#[test] -fn test_many_unique_auids() { - let (mut h, acc) = setup(); - - let txn1 = create_many_auids(&mut h, &acc, 50); - - assert_success!(h.run(txn1)); -} diff --git a/aptos-move/e2e-move-tests/src/transaction_context.rs b/aptos-move/e2e-move-tests/src/transaction_context.rs deleted file mode 100644 index 71463bd11e096..0000000000000 --- a/aptos-move/e2e-move-tests/src/transaction_context.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright © Aptos Foundation -// SPDX-License-Identifier: Apache-2.0 - -use crate::{assert_success, harness::MoveHarness}; -use aptos_language_e2e_tests::account::Account; -use aptos_types::{account_address::AccountAddress, transaction::SignedTransaction}; -use std::path::PathBuf; - -pub fn initialize(path: PathBuf) -> (MoveHarness, Account) { - let mut harness = MoveHarness::new(); - let account = harness.new_account_at(AccountAddress::ONE); - assert_success!(harness.publish_package(&account, &path)); - (harness, account) -} - -pub fn create_many_auids( - harness: &mut MoveHarness, - account: &Account, - count: u64, -) -> SignedTransaction { - harness.create_entry_function( - account, - str::parse("0x1::transaction_context_test::create_many_auids").unwrap(), - vec![], - vec![bcs::to_bytes(&count).unwrap()], - ) -} diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index c2ee437feb7c0..2e35d144f1f78 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -229,7 +229,7 @@ This is a one time ability given to the creator to configure the object as neces can_delete: bool
- Set to true so long as deleting the object is possible. + True if the object can be deleted. Named objects are not deletable.
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index a5c0f3a1bcbf1..f6151eb586bf6 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -12,7 +12,7 @@ - [Function `generate_unique_address`](#0x1_transaction_context_generate_unique_address) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Function `generate_auid`](#0x1_transaction_context_generate_auid) -- [Function `get_unique_address`](#0x1_transaction_context_get_unique_address) +- [Function `auid_address`](#0x1_transaction_context_auid_address) - [Specification](#@Specification_1) - [Function `get_txn_hash`](#@Specification_1_get_txn_hash) - [Function `generate_unique_address_internal`](#@Specification_1_generate_unique_address_internal) @@ -200,13 +200,13 @@ the generated unique address wrapped in the AUID class. - + -## Function `get_unique_address` +## Function `auid_address` -
public fun get_unique_address(auid: &transaction_context::AUID): address
+
public fun auid_address(auid: &transaction_context::AUID): address
 
@@ -215,7 +215,7 @@ the generated unique address wrapped in the AUID class. Implementation -
public fun get_unique_address(auid: &AUID): address {
+
public fun auid_address(auid: &AUID): address {
     auid.unique_address
 }
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 2e991c3d6fd26..e01f25f3af9b0 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -112,7 +112,7 @@ module aptos_framework::object { /// This is a one time ability given to the creator to configure the object as necessary struct ConstructorRef has drop { self: address, - /// Set to true so long as deleting the object is possible. + /// True if the object can be deleted. Named objects are not deletable. can_delete: bool, } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 8a8a3e24f8c91..5a8ed2f8e8565 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -43,7 +43,33 @@ module aptos_framework::transaction_context { } } - public fun get_unique_address(auid: &AUID): address { + public fun auid_address(auid: &AUID): address { auid.unique_address } + + #[test(fx = @std)] + fun test_auid_uniquess(fx: signer) { + use std::features; + use std::vector; + + let feature = features::get_auids(); + features::change_feature_flags(&fx, vector[feature], vector[]); + + let auids: vector
= vector
[]; + let i: u64 = 0; + let count: u64 = 50; + while (i < count) { + i = i + 1; + vector::push_back(&mut auids, generate_unique_address()); + }; + i = 0; + while (i < count - 1) { + let j: u64 = i + 1; + while (j < count) { + assert!(*vector::borrow(&auids, i) != *vector::borrow(&auids, j), 0); + j = j + 1; + }; + i = i + 1; + }; + } } From 987f88f1cad71f41da72a08d84cb0e508154e2f4 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 11:24:22 -0700 Subject: [PATCH 53/61] Add a comment in object.move --- aptos-move/framework/aptos-framework/sources/object.move | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index e01f25f3af9b0..5d7352788247e 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -225,6 +225,10 @@ module aptos_framework::object { #[deprecated] /// Use `create_object` instead. /// Create a new object from a GUID generated by an account. + /// As the GUID creation internally increments a counter, two transactions that executes + /// `create_object_from_account` function for the same creator run sequentially. + /// Therefore, using `create_object` method for creating objects is preferrable as it + /// doesn't have the same bottlenecks. public fun create_object_from_account(creator: &signer): ConstructorRef { let guid = account::create_guid(creator); create_object_from_guid(signer::address_of(creator), guid) @@ -233,6 +237,10 @@ module aptos_framework::object { #[deprecated] /// Use `create_object` instead. /// Create a new object from a GUID generated by an object. + /// As the GUID creation internally increments a counter, two transactions that executes + /// `create_object_from_object` function for the same creator run sequentially. + /// Therefore, using `create_object` method for creating objects is preferrable as it + /// doesn't have the same bottlenecks. public fun create_object_from_object(creator: &signer): ConstructorRef acquires ObjectCore { let guid = create_guid(creator); create_object_from_guid(signer::address_of(creator), guid) From 29725d61905c2ffc157806f2563ab761b7abab25 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 11:46:11 -0700 Subject: [PATCH 54/61] rust lint --- aptos-move/framework/aptos-framework/doc/object.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index 2e35d144f1f78..f8aa4dacee218 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -876,6 +876,10 @@ never be regenerated with future txs. Use create_object instead. Create a new object from a GUID generated by an account. +As the GUID creation internally increments a counter, two transactions that executes +create_object_from_account function for the same creator run sequentially. +Therefore, using create_object method for creating objects is preferrable as it +doesn't have the same bottlenecks.
#[deprecated]
@@ -904,6 +908,10 @@ Create a new object from a GUID generated by an account.
 
 Use create_object instead.
 Create a new object from a GUID generated by an object.
+As the GUID creation internally increments a counter, two transactions that executes
+create_object_from_object function for the same creator run sequentially.
+Therefore, using create_object method for creating objects is preferrable as it
+doesn't have the same bottlenecks.
 
 
 
#[deprecated]

From 18b4e3b7b62cb18cddc13d8fcbf2a81109b4a808 Mon Sep 17 00:00:00 2001
From: Satya Vusirikala 
Date: Mon, 26 Jun 2023 13:47:52 -0500
Subject: [PATCH 55/61] Add create_token method in token.move (#8825)

* Add create_token method in token.move

* add deprecated flag to create_token_from_account

* Add test case and rename to create

* Add feature flag condition in test case

* enabled feature flag in the unit test

* Enabling auid feature flag in ambassador unit tests
---
 .../aptos-token-objects/doc/aptos_token.md    | 28 +++++++----
 .../aptos-token-objects/doc/token.md          | 40 +++++++++++++++-
 .../sources/aptos_token.move                  | 28 +++++++----
 .../aptos-token-objects/sources/token.move    | 48 ++++++++++++++++++-
 .../ambassador/sources/ambassador.move        | 11 +++--
 5 files changed, 134 insertions(+), 21 deletions(-)

diff --git a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
index 54c8cc83e58fc..8414f43ddfb13 100644
--- a/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
+++ b/aptos-move/framework/aptos-token-objects/doc/aptos_token.md
@@ -58,6 +58,7 @@ The key features are:
 
 
 
use 0x1::error;
+use 0x1::features;
 use 0x1::object;
 use 0x1::option;
 use 0x1::signer;
@@ -471,14 +472,25 @@ With an existing collection, directly mint a soul bound token into the recipient
     property_types: vector<String>,
     property_values: vector<vector<u8>>,
 ): ConstructorRef acquires AptosCollection {
-    let constructor_ref = token::create_from_account(
-        creator,
-        collection,
-        description,
-        name,
-        option::none(),
-        uri,
-    );
+    let constructor_ref = if (features::auids_enabled()) {
+        token::create(
+            creator,
+            collection,
+            description,
+            name,
+            option::none(),
+            uri,
+        )
+    } else {
+        token::create_from_account(
+            creator,
+            collection,
+            description,
+            name,
+            option::none(),
+            uri,
+        )
+    };
 
     let object_signer = object::generate_signer(&constructor_ref);
 
diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md
index 0b23237681a04..391ae97000cbd 100644
--- a/aptos-move/framework/aptos-token-objects/doc/token.md
+++ b/aptos-move/framework/aptos-token-objects/doc/token.md
@@ -16,6 +16,7 @@ token are:
 -  [Struct `MutationEvent`](#0x4_token_MutationEvent)
 -  [Constants](#@Constants_0)
 -  [Function `create_common`](#0x4_token_create_common)
+-  [Function `create`](#0x4_token_create)
 -  [Function `create_named_token`](#0x4_token_create_named_token)
 -  [Function `create_from_account`](#0x4_token_create_from_account)
 -  [Function `create_token_address`](#0x4_token_create_token_address)
@@ -361,6 +362,42 @@ The token name is over the maximum length
 
 
 
+
+
+
+
+## Function `create`
+
+Creates a new token object with a unique address and returns the ConstructorRef
+for additional specialization.
+
+
+
public fun create(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
+
+ + + +
+Implementation + + +
public fun create(
+    creator: &signer,
+    collection_name: String,
+    description: String,
+    name: String,
+    royalty: Option<Royalty>,
+    uri: String,
+): ConstructorRef {
+    let creator_address = signer::address_of(creator);
+    let constructor_ref = object::create_object(creator_address);
+    create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri);
+    constructor_ref
+}
+
+ + +
@@ -409,7 +446,8 @@ Creates a new token object from an account GUID and returns the ConstructorRef f additional specialization. -
public fun create_from_account(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
+
#[deprecated]
+public fun create_from_account(creator: &signer, collection_name: string::String, description: string::String, name: string::String, royalty: option::Option<royalty::Royalty>, uri: string::String): object::ConstructorRef
 
diff --git a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move index 17c77fa3fe3b4..f20cd7b600025 100644 --- a/aptos-move/framework/aptos-token-objects/sources/aptos_token.move +++ b/aptos-move/framework/aptos-token-objects/sources/aptos_token.move @@ -8,6 +8,7 @@ /// * Metadata property type module aptos_token_objects::aptos_token { use std::error; + use std::features; use std::option::{Self, Option}; use std::string::String; use std::signer; @@ -199,14 +200,25 @@ module aptos_token_objects::aptos_token { property_types: vector, property_values: vector>, ): ConstructorRef acquires AptosCollection { - let constructor_ref = token::create_from_account( - creator, - collection, - description, - name, - option::none(), - uri, - ); + let constructor_ref = if (features::auids_enabled()) { + token::create( + creator, + collection, + description, + name, + option::none(), + uri, + ) + } else { + token::create_from_account( + creator, + collection, + description, + name, + option::none(), + uri, + ) + }; let object_signer = object::generate_signer(&constructor_ref); diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index 2867bc18c2822..06e9bdfe529f4 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -106,6 +106,22 @@ module aptos_token_objects::token { }; } + /// Creates a new token object with a unique address and returns the ConstructorRef + /// for additional specialization. + public fun create( + creator: &signer, + collection_name: String, + description: String, + name: String, + royalty: Option, + uri: String, + ): ConstructorRef { + let creator_address = signer::address_of(creator); + let constructor_ref = object::create_object(creator_address); + create_common(&constructor_ref, creator_address, collection_name, description, name, royalty, uri); + constructor_ref + } + /// Creates a new token object from a token name and returns the ConstructorRef for /// additional specialization. public fun create_named_token( @@ -124,6 +140,7 @@ module aptos_token_objects::token { constructor_ref } + #[deprecated] /// Creates a new token object from an account GUID and returns the ConstructorRef for /// additional specialization. public fun create_from_account( @@ -514,7 +531,7 @@ module aptos_token_objects::token { } #[test(creator = @0x123)] - fun test_burn_and_delete(creator: &signer) acquires Token { + fun test_create_from_account_burn_and_delete(creator: &signer) acquires Token { use aptos_framework::account; let collection_name = string::utf8(b"collection name"); @@ -538,6 +555,35 @@ module aptos_token_objects::token { assert!(!object::is_object(token_addr), 2); } + #[test(creator = @0x123,fx = @std)] + fun test_create_burn_and_delete(creator: &signer, fx: signer) acquires Token { + use aptos_framework::account; + use std::features; + + let feature = features::get_auids(); + features::change_feature_flags(&fx, vector[feature], vector[]); + + let collection_name = string::utf8(b"collection name"); + let token_name = string::utf8(b"token name"); + + create_collection_helper(creator, collection_name, 1); + account::create_account_for_test(signer::address_of(creator)); + let constructor_ref = create( + creator, + collection_name, + string::utf8(b"token description"), + token_name, + option::none(), + string::utf8(b"token uri"), + ); + let burn_ref = generate_burn_ref(&constructor_ref); + let token_addr = object::address_from_constructor_ref(&constructor_ref); + assert!(exists(token_addr), 0); + burn(burn_ref); + assert!(!exists(token_addr), 1); + assert!(!object::is_object(token_addr), 2); + } + #[test_only] fun create_collection_helper(creator: &signer, collection_name: String, max_supply: u64) { collection::create_fixed_collection( diff --git a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move index d60102db45134..d540995aecc9f 100644 --- a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move +++ b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move @@ -152,7 +152,7 @@ module token_objects::ambassador { // is used to generate the refs of the token. let uri = base_uri; string::append(&mut uri, string::utf8(RANK_BRONZE)); - let constructor_ref = token::create_named_token( + let constructor_ref = token::create( creator, collection, description, @@ -283,8 +283,13 @@ module token_objects::ambassador { ); } - #[test(creator = @0x123, user1 = @0x456)] - fun test_mint_burn(creator: &signer, user1: &signer) acquires AmbassadorToken, AmbassadorLevel { + #[test(creator = @0x123, user1 = @0x456, fx = @std)] + fun test_mint_burn(creator: &signer, user1: &signer, fx: signer) acquires AmbassadorToken, AmbassadorLevel { + use std::features; + + let feature = features::get_auids(); + features::change_feature_flags(&fx, vector[feature], vector[]); + // ------------------------------------------ // Creator creates the Ambassador Collection. // ------------------------------------------ From e863b872cc0e20c6fd7cc5ac5ea79b06c17735b5 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 13:10:42 -0700 Subject: [PATCH 56/61] Enable auid flag in an ambassador.move unit test --- .../token_objects/ambassador/sources/ambassador.move | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move index d540995aecc9f..d60102db45134 100644 --- a/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move +++ b/aptos-move/move-examples/token_objects/ambassador/sources/ambassador.move @@ -152,7 +152,7 @@ module token_objects::ambassador { // is used to generate the refs of the token. let uri = base_uri; string::append(&mut uri, string::utf8(RANK_BRONZE)); - let constructor_ref = token::create( + let constructor_ref = token::create_named_token( creator, collection, description, @@ -283,13 +283,8 @@ module token_objects::ambassador { ); } - #[test(creator = @0x123, user1 = @0x456, fx = @std)] - fun test_mint_burn(creator: &signer, user1: &signer, fx: signer) acquires AmbassadorToken, AmbassadorLevel { - use std::features; - - let feature = features::get_auids(); - features::change_feature_flags(&fx, vector[feature], vector[]); - + #[test(creator = @0x123, user1 = @0x456)] + fun test_mint_burn(creator: &signer, user1: &signer) acquires AmbassadorToken, AmbassadorLevel { // ------------------------------------------ // Creator creates the Ambassador Collection. // ------------------------------------------ From b5aecf035176a06248a5879f24582839f4a666e5 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 14:30:58 -0700 Subject: [PATCH 57/61] Changed gas cost --- aptos-move/aptos-gas/src/aptos_framework.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index c00c56df6bd90..5a55428560ee7 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -166,7 +166,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.transaction_context.get_txn_hash.base, { 10.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], // Using SHA2-256's cost - [.transaction_context.generate_unique_address.base, { 10.. => "transaction_context.generate_unique_address.base" }, 3000 * MUL], + [.transaction_context.generate_unique_address.base, { 10.. => "transaction_context.generate_unique_address.base" }, 4000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], [.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL], From e2e05cf5dd885e18768c07cc0b7fc7fe8df48622 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 14:44:38 -0700 Subject: [PATCH 58/61] changed name from generate_unique_address to generate_auid_address --- aptos-move/aptos-gas/src/gas_meter.rs | 2 +- .../framework/aptos-framework/doc/object.md | 2 +- .../doc/transaction_context.md | 38 +++++++++---------- .../aptos-framework/sources/object.move | 8 ++-- .../sources/transaction_context.move | 18 ++++----- .../sources/transaction_context.spec.move | 2 +- .../src/natives/transaction_context.rs | 2 +- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/aptos-move/aptos-gas/src/gas_meter.rs b/aptos-move/aptos-gas/src/gas_meter.rs index f2e4f5dc031cf..f49754cf551b5 100644 --- a/aptos-move/aptos-gas/src/gas_meter.rs +++ b/aptos-move/aptos-gas/src/gas_meter.rs @@ -34,7 +34,7 @@ use std::collections::BTreeMap; // Change log: // - V10 -// - Added generate_unique_address_internal and get_txn_hash native functions +// - Added generate_unique_address and get_txn_hash native functions // - Storage gas charges (excluding "storage fees") stop respecting the storage gas curves // - V9 // - Accurate tracking of the cost of loading resource groups diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index f8aa4dacee218..ec9e34f94b1bd 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -861,7 +861,7 @@ never be regenerated with future txs.
public fun create_object(owner_address: address): ConstructorRef {
-    let unique_address = transaction_context::generate_unique_address();
+    let unique_address = transaction_context::generate_auid_address();
     create_object_internal(owner_address, unique_address, true)
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index f6151eb586bf6..bdf13c62b8a28 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -8,14 +8,14 @@ - [Struct `AUID`](#0x1_transaction_context_AUID) - [Constants](#@Constants_0) - [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) -- [Function `generate_unique_address_internal`](#0x1_transaction_context_generate_unique_address_internal) - [Function `generate_unique_address`](#0x1_transaction_context_generate_unique_address) +- [Function `generate_auid_address`](#0x1_transaction_context_generate_auid_address) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) - [Function `generate_auid`](#0x1_transaction_context_generate_auid) - [Function `auid_address`](#0x1_transaction_context_auid_address) - [Specification](#@Specification_1) - [Function `get_txn_hash`](#@Specification_1_get_txn_hash) - - [Function `generate_unique_address_internal`](#@Specification_1_generate_unique_address_internal) + - [Function `generate_unique_address`](#@Specification_1_generate_unique_address) - [Function `get_script_hash`](#@Specification_1_get_script_hash) @@ -91,9 +91,9 @@ Return the transaction hash of the current transaction - + -## Function `generate_unique_address_internal` +## Function `generate_unique_address` Return a universally unique identifier (of type address) generated by hashing the transaction hash of this transaction and a sequence number @@ -104,7 +104,7 @@ Uses Scheme in types/src/transaction/authenticator.rs for domain separation from other ways of generating unique addresses. -
fun generate_unique_address_internal(): address
+
fun generate_unique_address(): address
 
@@ -113,23 +113,23 @@ from other ways of generating unique addresses. Implementation -
native fun generate_unique_address_internal(): address;
+
native fun generate_unique_address(): address;
 
- + -## Function `generate_unique_address` +## Function `generate_auid_address` -Return a universally unique identifier. Internally calls -the private function generate_unique_address_internal. This function is -created for to feature gate the generate_unique_address_internal function. +Return a aptos unique identifier. Internally calls +the private function generate_unique_address. This function is +created for to feature gate the generate_unique_address function. -
public fun generate_unique_address(): address
+
public fun generate_auid_address(): address
 
@@ -138,9 +138,9 @@ created for to feature gate the generate_unique_address_internal fu Implementation -
public fun generate_unique_address(): address {
+
public fun generate_auid_address(): address {
     assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
-    generate_unique_address_internal()
+    generate_unique_address()
 }
 
@@ -175,7 +175,7 @@ Return the script hash of the current entry function. ## Function `generate_auid` -This method runs generate_unique_address_internal native function and returns +This method runs generate_unique_address native function and returns the generated unique address wrapped in the AUID class. @@ -191,7 +191,7 @@ the generated unique address wrapped in the AUID class.
public fun generate_auid(): AUID {
     assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
     return AUID {
-        unique_address: generate_unique_address_internal()
+        unique_address: generate_unique_address()
     }
 }
 
@@ -256,12 +256,12 @@ the generated unique address wrapped in the AUID class. - + -### Function `generate_unique_address_internal` +### Function `generate_unique_address` -
fun generate_unique_address_internal(): address
+
fun generate_unique_address(): address
 
diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 5d7352788247e..9285af29f194c 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -48,13 +48,13 @@ module aptos_framework::object { /// Explicitly separate the GUID space between Object and Account to prevent accidental overlap. const INIT_GUID_CREATION_NUM: u64 = 0x4000000000000; - /// generate_unique_address uses this for domain separation within its native implementation - const DERIVE_AUID_ADDRESS_SCHEME: u8 = 0xFB; - /// Maximum nesting from one object to another. That is objects can technically have infinte /// nesting, but any checks such as transfer will only be evaluated this deep. const MAXIMUM_OBJECT_NESTING: u8 = 8; + /// generate_unique_address uses this for domain separation within its native implementation + const DERIVE_AUID_ADDRESS_SCHEME: u8 = 0xFB; + /// Scheme identifier used to generate an object's address `obj_addr` as derived from another object. /// The object's address is generated as: /// ``` @@ -218,7 +218,7 @@ module aptos_framework::object { /// The created object is deletable as we can guarantee the same unique address can /// never be regenerated with future txs. public fun create_object(owner_address: address): ConstructorRef { - let unique_address = transaction_context::generate_unique_address(); + let unique_address = transaction_context::generate_auid_address(); create_object_internal(owner_address, unique_address, true) } diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 5a8ed2f8e8565..82a03d6844a91 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -21,25 +21,25 @@ module aptos_framework::transaction_context { /// the sequence number and generates a new unique address. /// Uses Scheme in types/src/transaction/authenticator.rs for domain separation /// from other ways of generating unique addresses. - native fun generate_unique_address_internal(): address; + native fun generate_unique_address(): address; - /// Return a universally unique identifier. Internally calls - /// the private function `generate_unique_address_internal`. This function is - /// created for to feature gate the `generate_unique_address_internal` function. - public fun generate_unique_address(): address { + /// Return a aptos unique identifier. Internally calls + /// the private function `generate_unique_address`. This function is + /// created for to feature gate the `generate_unique_address` function. + public fun generate_auid_address(): address { assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); - generate_unique_address_internal() + generate_unique_address() } /// Return the script hash of the current entry function. public native fun get_script_hash(): vector; - /// This method runs `generate_unique_address_internal` native function and returns + /// This method runs `generate_unique_address` native function and returns /// the generated unique address wrapped in the AUID class. public fun generate_auid(): AUID { assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); return AUID { - unique_address: generate_unique_address_internal() + unique_address: generate_unique_address() } } @@ -60,7 +60,7 @@ module aptos_framework::transaction_context { let count: u64 = 50; while (i < count) { i = i + 1; - vector::push_back(&mut auids, generate_unique_address()); + vector::push_back(&mut auids, generate_auid_address()); }; i = 0; while (i < count - 1) { diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move index 822acc17b7e66..5d520bf261e59 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.spec.move @@ -11,7 +11,7 @@ spec aptos_framework::transaction_context { ensures result == spec_get_txn_hash(); } spec fun spec_get_txn_hash(): vector; - spec generate_unique_address_internal(): address { + spec generate_unique_address(): address { pragma opaque; } } diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index f2423ca825de5..44afefa15e33d 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -157,7 +157,7 @@ pub fn make_all( ), ), ( - "generate_unique_address_internal", + "generate_unique_address", make_safe_native( gas_params.generate_unique_address, timed_features.clone(), From 03b9fea2a51236f82a98bbba067e6609a1d5552d Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 14:47:28 -0700 Subject: [PATCH 59/61] Updated a comment --- aptos-move/aptos-gas/src/aptos_framework.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aptos-move/aptos-gas/src/aptos_framework.rs b/aptos-move/aptos-gas/src/aptos_framework.rs index 5a55428560ee7..550f4e490d1ef 100644 --- a/aptos-move/aptos-gas/src/aptos_framework.rs +++ b/aptos-move/aptos-gas/src/aptos_framework.rs @@ -165,7 +165,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo [.transaction_context.get_txn_hash.base, { 10.. => "transaction_context.get_txn_hash.base" }, 200 * MUL], [.transaction_context.get_script_hash.base, "transaction_context.get_script_hash.base", 200 * MUL], - // Using SHA2-256's cost + // Based on SHA3-256's cost [.transaction_context.generate_unique_address.base, { 10.. => "transaction_context.generate_unique_address.base" }, 4000 * MUL], [.code.request_publish.base, "code.request_publish.base", 500 * MUL], From b54fa0cf6d0c2db34b4aae02ec10bf48c56dd90c Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 14:59:18 -0700 Subject: [PATCH 60/61] Feature gate get_txn_hash --- .../doc/transaction_context.md | 37 +++++++++++++++++-- .../sources/transaction_context.move | 12 +++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/transaction_context.md b/aptos-move/framework/aptos-framework/doc/transaction_context.md index bdf13c62b8a28..791e456e810d3 100644 --- a/aptos-move/framework/aptos-framework/doc/transaction_context.md +++ b/aptos-move/framework/aptos-framework/doc/transaction_context.md @@ -8,6 +8,7 @@ - [Struct `AUID`](#0x1_transaction_context_AUID) - [Constants](#@Constants_0) - [Function `get_txn_hash`](#0x1_transaction_context_get_txn_hash) +- [Function `get_transaction_hash`](#0x1_transaction_context_get_transaction_hash) - [Function `generate_unique_address`](#0x1_transaction_context_generate_unique_address) - [Function `generate_auid_address`](#0x1_transaction_context_generate_auid_address) - [Function `get_script_hash`](#0x1_transaction_context_get_script_hash) @@ -72,10 +73,10 @@ AUID feature is not supported. ## Function `get_txn_hash` -Return the transaction hash of the current transaction +Return the transaction hash of the current transaction. -
public fun get_txn_hash(): vector<u8>
+
fun get_txn_hash(): vector<u8>
 
@@ -84,7 +85,35 @@ Return the transaction hash of the current transaction Implementation -
public native fun get_txn_hash(): vector<u8>;
+
native fun get_txn_hash(): vector<u8>;
+
+ + + + + + + +## Function `get_transaction_hash` + +Return the transaction hash of the current transaction. +Internally calls the private function get_txn_hash. +This function is created for to feature gate the get_txn_hash function. + + +
public fun get_transaction_hash(): vector<u8>
+
+ + + +
+Implementation + + +
public fun get_transaction_hash(): vector<u8> {
+    assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED);
+    get_txn_hash()
+}
 
@@ -243,7 +272,7 @@ the generated unique address wrapped in the AUID class. ### Function `get_txn_hash` -
public fun get_txn_hash(): vector<u8>
+
fun get_txn_hash(): vector<u8>
 
diff --git a/aptos-move/framework/aptos-framework/sources/transaction_context.move b/aptos-move/framework/aptos-framework/sources/transaction_context.move index 82a03d6844a91..b515ed1e1f2fd 100644 --- a/aptos-move/framework/aptos-framework/sources/transaction_context.move +++ b/aptos-move/framework/aptos-framework/sources/transaction_context.move @@ -11,8 +11,16 @@ module aptos_framework::transaction_context { unique_address: address } - /// Return the transaction hash of the current transaction - public native fun get_txn_hash(): vector; + /// Return the transaction hash of the current transaction. + native fun get_txn_hash(): vector; + + /// Return the transaction hash of the current transaction. + /// Internally calls the private function `get_txn_hash`. + /// This function is created for to feature gate the `get_txn_hash` function. + public fun get_transaction_hash(): vector { + assert!(features::auids_enabled(), EAUID_NOT_SUPPORTED); + get_txn_hash() + } /// Return a universally unique identifier (of type address) generated /// by hashing the transaction hash of this transaction and a sequence number From 3f0d40dd34459ceb4aa9dbf88678635752755672 Mon Sep 17 00:00:00 2001 From: Satya Vusirikala Date: Mon, 26 Jun 2023 15:39:21 -0700 Subject: [PATCH 61/61] changing names in test cases --- aptos-move/framework/aptos-framework/sources/object.move | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 9285af29f194c..e8473d1ced55b 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -681,8 +681,8 @@ module aptos_framework::object { let feature = features::get_auids(); features::change_feature_flags(&fx, vector[feature], vector[]); - let auid1 = aptos_framework::transaction_context::generate_unique_address(); - let bytes = aptos_framework::transaction_context::get_txn_hash(); + let auid1 = aptos_framework::transaction_context::generate_auid_address(); + let bytes = aptos_framework::transaction_context::get_transaction_hash(); std::vector::push_back(&mut bytes, 1); std::vector::push_back(&mut bytes, 0); std::vector::push_back(&mut bytes, 0);