Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add native function create_uuid #8401

Merged
merged 71 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2cd733c
Add native function create_guid
vusirikala May 26, 2023
3decce0
Append a constant to hash_arg
vusirikala May 27, 2023
c9b68ec
Add move test to verify uniqueness of guids
vusirikala May 27, 2023
4c4ef51
Charging gas for create_guid method
vusirikala May 27, 2023
fc9b372
Merge branch 'main' into satya/create-guid
vusirikala May 27, 2023
2284e55
Add gas for create guid
vusirikala May 27, 2023
2f0d2eb
Add create_guid to object.move
vusirikala May 28, 2023
80b7cbb
Change GUID to UUID
vusirikala May 31, 2023
4d7c564
Change GUID to UUID in tests
vusirikala May 31, 2023
b79d4bc
Change GUID to UUID in tests
vusirikala May 31, 2023
631d66d
Add create_object method in object.move
vusirikala May 31, 2023
bdfaa55
Fix typo
vusirikala May 31, 2023
90f30db
Fix typo
vusirikala May 31, 2023
98ad018
Merge branch 'main' into satya/create-guid
vusirikala May 31, 2023
0a00af6
fix trigger condition for build jobs
geekflyer Jun 4, 2023
f02858f
Add native_get_txn_hash
vusirikala Jun 5, 2023
b632592
Add native_get_txn_hash
vusirikala Jun 5, 2023
1c444d4
Merge branch 'main' into satya/create-guid
vusirikala Jun 5, 2023
3a616ba
Deprecate the old create_object_from_object and create_object_from_ac…
vusirikala Jun 5, 2023
f89370c
Bumped the latest_gas_version to 10
vusirikala Jun 5, 2023
83c4a21
Bumped gas version to 10
vusirikala Jun 5, 2023
8a6ff98
Changed gas feature version to 9
vusirikala Jun 7, 2023
bf29748
Moved transaction hash hashing to authenticator.rs
vusirikala Jun 7, 2023
ee02708
Add documentation to create_uuid method
vusirikala Jun 8, 2023
638e2af
Use AuthenticationKey struct for create_uuid
vusirikala Jun 8, 2023
331e728
Remove deprecated comment
vusirikala Jun 8, 2023
ce78b04
Updatd comments in object.move
vusirikala Jun 8, 2023
575e409
Changed create_uuid to use only one hash
vusirikala Jun 9, 2023
0e7206d
Merge branch 'main' into satya/create-guid
vusirikala Jun 11, 2023
16b52a4
Add create_unique_address function
vusirikala Jun 11, 2023
f1afb1e
Add drop, store capabilities to UUID
vusirikala Jun 11, 2023
29e0b62
Merge branch 'main' into satya/create-guid
vusirikala Jun 21, 2023
5308088
Resetting the create_object_from_account function
vusirikala Jun 21, 2023
9b1591b
Add comment for create_object function
vusirikala Jun 21, 2023
0424d8b
feature gating
vusirikala Jun 21, 2023
ad6f336
deprecated tag
vusirikala Jun 22, 2023
ea7fbb6
Add transaction context spec
vusirikala Jun 22, 2023
c267a23
Add a test case in transaction_context
vusirikala Jun 22, 2023
7568b15
Updated move test case
vusirikala Jun 22, 2023
f180aa0
Merge branch 'main' into satya/create-guid
vusirikala Jun 22, 2023
23f8776
Add create_token method
vusirikala Jun 22, 2023
fb9bce1
Update test cases
vusirikala Jun 22, 2023
82fec8a
rust lint
vusirikala Jun 22, 2023
41cb9af
Changed comments
vusirikala Jun 23, 2023
4df1c1c
Remove create_token method
vusirikala Jun 23, 2023
752caae
Add feature flag for test
vusirikala Jun 23, 2023
8cdf218
fix a unit test
vusirikala Jun 23, 2023
545283d
Fix unit test
vusirikala Jun 23, 2023
2cadd2c
moved unit test to object.move
vusirikala Jun 23, 2023
aad09cc
changing uuid to auid
vusirikala Jun 24, 2023
2b40d44
Merge branch 'main' into satya/create-guid
vusirikala Jun 24, 2023
06aa5b9
rust lint
vusirikala Jun 24, 2023
584cca2
Minor changes
vusirikala Jun 25, 2023
16252d8
Change uuid to auid in tests
vusirikala Jun 25, 2023
77b2002
Change uuid to auid in tests
vusirikala Jun 25, 2023
8fc34f6
changed name to generate_unique_address
vusirikala Jun 25, 2023
6cdd260
Merge branch 'main' into satya/create-guid
vusirikala Jun 25, 2023
53e4d3d
Fixed the specs which timeout
junkil-park Jun 26, 2023
c3f1a1a
Fixed a unit test
vusirikala Jun 26, 2023
6d7b0dd
Shift test from e2e-move-tests to transaction_context.move
vusirikala Jun 26, 2023
987f88f
Add a comment in object.move
vusirikala Jun 26, 2023
29725d6
rust lint
vusirikala Jun 26, 2023
b86849f
Merge branch 'main' into satya/create-guid
vusirikala Jun 26, 2023
18b4e3b
Add create_token method in token.move (#8825)
vusirikala Jun 26, 2023
e863b87
Enable auid flag in an ambassador.move unit test
vusirikala Jun 26, 2023
b5aecf0
Changed gas cost
vusirikala Jun 26, 2023
e2e05cf
changed name from generate_unique_address to generate_auid_address
vusirikala Jun 26, 2023
1e71ba9
Merge branch 'main' into satya/create-guid
vusirikala Jun 26, 2023
03b9fea
Updated a comment
vusirikala Jun 26, 2023
b54fa0c
Feature gate get_txn_hash
vusirikala Jun 26, 2023
3f0d40d
changing names in test cases
vusirikala Jun 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 95 additions & 92 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions aptos-move/aptos-gas/src/aptos_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +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],
vusirikala marked this conversation as resolved.
Show resolved Hide resolved
[.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],

[.code.request_publish.base, "code.request_publish.base", 500 * MUL],
[.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL],
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-gas/src/gas_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +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
// - Accurate tracking of the cost of loading resource groups
// - V8
// - Added BLS12-381 operations.
Expand Down
6 changes: 5 additions & 1 deletion aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,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));

Expand Down
6 changes: 5 additions & 1 deletion aptos-move/aptos-vm/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions aptos-move/e2e-move-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod aggregator;
pub mod aptos_governance;
pub mod harness;
pub mod stake;
pub mod transaction_context;
pub mod transaction_fee;

use anyhow::bail;
Expand Down
1 change: 1 addition & 0 deletions aptos-move/e2e-move-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "transaction_context_test"
version = "0.0.0"

[dependencies]
AptosFramework = { local = "../../../../framework/aptos-framework" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module 0x1::transaction_context_test {
use std::vector;
use aptos_framework::transaction_context::create_uuid;

/// 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<address> = vector<address>[];
let i: u64 = 0;
while (i < count) {
i = i+1;
vector::push_back(&mut uuids, create_uuid());
};
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;
};
}
}
20 changes: 20 additions & 0 deletions aptos-move/e2e-move-tests/src/tests/transaction_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::{
assert_success,
tests::common,
transaction_context::{create_many_uuids, initialize},
MoveHarness,
};
use aptos_language_e2e_tests::account::Account;

fn setup() -> (MoveHarness, Account) {
initialize(common::test_dir_path("transaction_context.data"))
}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test where an object is created and check that you can fetch resources there?

Copy link
Contributor Author

@vusirikala vusirikala Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working on it. Not entirely sure how to interact with objects. Do you have any references to sample code somewhere on how to interact with objects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the same /resources API to fetch resources at an object address. As for how to get the object address, this would be a good exercise for you to understand how people would be able to get the created addresses from the newly introduced functions.

fn test_many_unique_uuids() {
let (mut h, acc) = setup();

let txn1 = create_many_uuids(&mut h, &acc, 50);

assert_success!(h.run(txn1));
}
27 changes: 27 additions & 0 deletions aptos-move/e2e-move-tests/src/transaction_context.rs
Original file line number Diff line number Diff line change
@@ -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_uuids(
harness: &mut MoveHarness,
account: &Account,
count: u64,
) -> SignedTransaction {
harness.create_entry_function(
account,
str::parse("0x1::transaction_context_test::create_many_uuids").unwrap(),
vec![],
vec![bcs::to_bytes(&count).unwrap()],
)
}
36 changes: 34 additions & 2 deletions aptos-move/framework/aptos-framework/doc/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -87,6 +88,7 @@ make it so that a reference to a global object can be returned from a function.
<b>use</b> <a href="guid.md#0x1_guid">0x1::guid</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">0x1::hash</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">0x1::signer</a>;
<b>use</b> <a href="transaction_context.md#0x1_transaction_context">0x1::transaction_context</a>;
<b>use</b> <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">0x1::vector</a>;
</code></pre>

Expand Down Expand Up @@ -227,8 +229,7 @@ This is a one time ability given to the creator to configure the object as neces
<code>can_delete: bool</code>
</dt>
<dd>
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.
</dd>
</dl>

Expand Down Expand Up @@ -828,12 +829,42 @@ Derivde objects, similar to named objects, cannot be deleted.



</details>

<a name="0x1_object_create_object"></a>

## 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.


<pre><code><b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object">create_object</a>(creator_address: <b>address</b>): <a href="object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object">create_object</a>(creator_address: <b>address</b>): <a href="object.md#0x1_object_ConstructorRef">ConstructorRef</a> {
<b>let</b> uuid = aptos_framework::transaction_context::create_unique_addr();
<a href="object.md#0x1_object_create_object_internal">create_object_internal</a>(creator_address, uuid, <b>true</b>)
}
</code></pre>



</details>

<a name="0x1_object_create_object_from_account"></a>

## Function `create_object_from_account`

Deprecated. Use <code>create_object</code> instead.
Create a new object from a GUID generated by an account.


Expand All @@ -860,6 +891,7 @@ Create a new object from a GUID generated by an account.

## Function `create_object_from_object`

Deprecated. Use <code>create_object</code> instead.
Create a new object from a GUID generated by an object.


Expand Down
Loading