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 65 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
186 changes: 94 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, { 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],

[.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 @@ -34,6 +34,7 @@ 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
// - Accurate tracking of the cost of loading resource groups
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
60 changes: 56 additions & 4 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.
True if the object can be deleted. Named objects are not deletable.
</dd>
</dl>

Expand Down Expand Up @@ -427,6 +428,16 @@ Emitted whenever the object's owner field is changed.
## Constants


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

generate_unique_address uses this for domain separation within its native implementation


<pre><code><b>const</b> <a href="object.md#0x1_object_DERIVE_AUID_ADDRESS_SCHEME">DERIVE_AUID_ADDRESS_SCHEME</a>: u8 = 251;
</code></pre>



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

The object does not allow for deletion
Expand Down Expand Up @@ -828,16 +839,51 @@ 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 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.


<pre><code><b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object">create_object</a>(owner_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>(owner_address: <b>address</b>): <a href="object.md#0x1_object_ConstructorRef">ConstructorRef</a> {
<b>let</b> unique_address = <a href="transaction_context.md#0x1_transaction_context_generate_unique_address">transaction_context::generate_unique_address</a>();
<a href="object.md#0x1_object_create_object_internal">create_object_internal</a>(owner_address, unique_address, <b>true</b>)
}
</code></pre>



</details>

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

## Function `create_object_from_account`

Use <code>create_object</code> instead.
Create a new object from a GUID generated by an account.
As the GUID creation internally increments a counter, two transactions that executes
<code>create_object_from_account</code> function for the same creator run sequentially.
Therefore, using <code>create_object</code> method for creating objects is preferrable as it
doesn't have the same bottlenecks.


<pre><code><b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object_from_account">create_object_from_account</a>(creator: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>): <a href="object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object_from_account">create_object_from_account</a>(creator: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>): <a href="object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
</code></pre>


Expand All @@ -860,10 +906,16 @@ Create a new object from a GUID generated by an account.

## Function `create_object_from_object`

Use <code>create_object</code> instead.
Create a new object from a GUID generated by an object.
As the GUID creation internally increments a counter, two transactions that executes
<code>create_object_from_object</code> function for the same creator run sequentially.
Therefore, using <code>create_object</code> method for creating objects is preferrable as it
doesn't have the same bottlenecks.


<pre><code><b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object_from_object">create_object_from_object</a>(creator: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>): <a href="object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
<pre><code>#[deprecated]
<b>public</b> <b>fun</b> <a href="object.md#0x1_object_create_object_from_object">create_object_from_object</a>(creator: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>): <a href="object.md#0x1_object_ConstructorRef">object::ConstructorRef</a>
</code></pre>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,8 @@ StakingRewardsConfig does not exist under the aptos_framework before creating it



<pre><code><b>aborts_if</b> !<b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">StakingRewardsConfig</a>&gt;(@aptos_framework);
<pre><code><b>pragma</b> verify_duration_estimate = 120;
<b>aborts_if</b> !<b>exists</b>&lt;<a href="staking_config.md#0x1_staking_config_StakingRewardsConfig">StakingRewardsConfig</a>&gt;(@aptos_framework);
<b>aborts_if</b> !<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_periodical_reward_rate_decrease_enabled">features::spec_periodical_reward_rate_decrease_enabled</a>();
<b>include</b> <a href="staking_config.md#0x1_staking_config_StakingRewardsConfigRequirement">StakingRewardsConfigRequirement</a>;
</code></pre>
Expand Down
Loading