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

[token] tokendata maximum should not be changed from or to 0. #5382

Merged
merged 2 commits into from
Nov 2, 2022

Conversation

Stumble
Copy link
Contributor

@Stumble Stumble commented Oct 31, 2022

Description

Tokendata maximum should not be able to be mutated to or from 0.

Test Plan

1 unit test was added.


This change is Reviewable

@Stumble Stumble requested a review from areshand as a code owner October 31, 2022 23:30
Copy link
Contributor

@areshand areshand left a comment

Choose a reason for hiding this comment

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

Yes, thanks for the good catch

@0xchloe
Copy link
Contributor

0xchloe commented Nov 1, 2022

good catch - thanks for putting out the PR!!

@@ -773,6 +773,8 @@ module aptos_token::token {
assert_tokendata_exists(creator, token_data_id);
let all_token_data = &mut borrow_global_mut<Collections>(token_data_id.creator).token_data;
let token_data = table::borrow_mut(all_token_data, token_data_id);
// cannot change maximum from 0 and cannot change maximum to 0
assert!(token_data.maximum != 0 && maximum != 0, error::invalid_argument(EINVALID_MAXIMUM));
Copy link
Contributor

@lightmark lightmark Nov 1, 2022

Choose a reason for hiding this comment

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

IIUC, please also add an assertion before line 1072, otherwise the invariant can not be guaranteed at initialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you referring to this line?


IIUC, it is valid to have token_data.maximum = 0. The case here is to prevent mutating maximum from or to zero because when the maximum is zero, the supply is untracked. For example,
if (token_data.maximum > 0) {

Copy link
Contributor

@lightmark lightmark Nov 1, 2022

Choose a reason for hiding this comment

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

So it is allowed to have maximum = 0 at initialization and immutable since then. It seems we did the same for Collections and maximum = 0 means no supply tracking...
n00b Q: Do we have any use case for that? cc @areshand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it is allowed to have maximum = 0 at initialization and immutable since then. Nope, that's what this PR hopes to fix. The only usecase that should be allowed is : having maximum > 0 at initialization, and then mutate it to a valid (>supply) non-zero value since then.

Copy link
Contributor

Choose a reason for hiding this comment

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

talked to @areshand offline. = 0 at initialization is a hack for some special case. I'll follow up offline.

@movekevin movekevin enabled auto-merge (rebase) November 2, 2022 01:58
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

✅ Forge suite compat success on 2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> 7688da1a6149f3eae7f456ce508e7823cd41fb35

Compatibility test results for 2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> 7688da1a6149f3eae7f456ce508e7823cd41fb35 (PR)
1. Check liveness of validators at old version: 2d8b1b57553d869190f61df1aaf7f31a8fc19a7b
compatibility::simple-validator-upgrade::liveness-check : 7266 TPS, 5360 ms latency, 7500 ms p99 latency,no expired txns
2. Upgrading first Validator to new version: 7688da1a6149f3eae7f456ce508e7823cd41fb35
compatibility::simple-validator-upgrade::single-validator-upgrade : 4492 TPS, 8823 ms latency, 11500 ms p99 latency,no expired txns
3. Upgrading rest of first batch to new version: 7688da1a6149f3eae7f456ce508e7823cd41fb35
compatibility::simple-validator-upgrade::half-validator-upgrade : 4412 TPS, 9496 ms latency, 12200 ms p99 latency,no expired txns
4. upgrading second batch to new version: 7688da1a6149f3eae7f456ce508e7823cd41fb35
compatibility::simple-validator-upgrade::rest-validator-upgrade : 6657 TPS, 5841 ms latency, 9600 ms p99 latency,no expired txns
5. check swarm health
Compatibility test for 2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> 7688da1a6149f3eae7f456ce508e7823cd41fb35 passed
Test Ok

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

✅ Forge suite land_blocking success on 7688da1a6149f3eae7f456ce508e7823cd41fb35

performance benchmark with full nodes : 6639 TPS, 5961 ms latency, 10600 ms p99 latency,(!) expired 440 out of 2835640 txns
Test Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants