Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

pallet-asset: Fix transfer of a large amount of an asset #11241

Merged
merged 6 commits into from
Apr 25, 2022

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Apr 19, 2022

Before this pr transferring a large amount of an asset would check that transferring the asset would
not overflow the supply of the asset. However, it doesn't make sense to check for asset supply
overflow when we just transfer from one account to another account and don't increase the supply in
any way. It also required to extend the can_deposit method of fungible and fungibles with a
mint parameter. If this parameter is set to true, it means we want to mint the amount of an
asset before transferring it into an account. For can_withdraw we don't need to add an extra
parameter, because withdrawing should never be able to underflow the supply. If that would happen,
it would mean that somewhere the supply wasn't increased while increasing the balance of an account.

Before this pr transferring a large amount of an asset would check that transferring the asset would
not overflow the supply of the asset. However, it doesn't make sense to check for asset supply
overflow when we just transfer from one account to another account and don't increase the supply in
any way. It also required to extend the `can_deposit` method of `fungible` and `fungibles` with a
`mint` parameter. If this parameter is set to `true`, it means we want to mint the amount of an
asset before transferring it into an account. For `can_withdraw` we don't need to add an extra
parameter, because withdrawing should never be able to underflow the supply. If that would happen,
it would mean that somewhere the supply wasn't increased while increasing the balance of an account.
@bkchr bkchr added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Apr 19, 2022
@bkchr bkchr requested a review from gavofyork April 19, 2022 21:16
frame/assets/src/functions.rs Outdated Show resolved Hide resolved
frame/assets/src/functions.rs Outdated Show resolved Hide resolved
frame/assets/src/functions.rs Outdated Show resolved Hide resolved
@bkchr bkchr requested a review from shawntabrizi April 20, 2022 13:28
@shawntabrizi
Copy link
Member

fortunately, all of this complexity can probably be re-written and removed once transactional storage by default is implemented

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
@bkchr
Copy link
Member Author

bkchr commented Apr 20, 2022

fortunately, all of this complexity can probably be re-written and removed once transactional storage by default is implemented

Yep :)

@bkchr bkchr merged commit d79a2af into master Apr 25, 2022
@bkchr bkchr deleted the bkchr-pallet-asset-large-transfer branch April 25, 2022 18:12
godcodehunter pushed a commit to sensoriumxr/substrate that referenced this pull request Jun 22, 2022
…11241)

* pallet-asset: Fix transfer of a large amount of an asset

Before this pr transferring a large amount of an asset would check that transferring the asset would
not overflow the supply of the asset. However, it doesn't make sense to check for asset supply
overflow when we just transfer from one account to another account and don't increase the supply in
any way. It also required to extend the `can_deposit` method of `fungible` and `fungibles` with a
`mint` parameter. If this parameter is set to `true`, it means we want to mint the amount of an
asset before transferring it into an account. For `can_withdraw` we don't need to add an extra
parameter, because withdrawing should never be able to underflow the supply. If that would happen,
it would mean that somewhere the supply wasn't increased while increasing the balance of an account.

* Update frame/assets/src/functions.rs

* Update frame/assets/src/functions.rs

* Update frame/assets/src/functions.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* FMT

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
DaviRain-Su pushed a commit to octopus-network/substrate that referenced this pull request Aug 23, 2022
…11241)

* pallet-asset: Fix transfer of a large amount of an asset

Before this pr transferring a large amount of an asset would check that transferring the asset would
not overflow the supply of the asset. However, it doesn't make sense to check for asset supply
overflow when we just transfer from one account to another account and don't increase the supply in
any way. It also required to extend the `can_deposit` method of `fungible` and `fungibles` with a
`mint` parameter. If this parameter is set to `true`, it means we want to mint the amount of an
asset before transferring it into an account. For `can_withdraw` we don't need to add an extra
parameter, because withdrawing should never be able to underflow the supply. If that would happen,
it would mean that somewhere the supply wasn't increased while increasing the balance of an account.

* Update frame/assets/src/functions.rs

* Update frame/assets/src/functions.rs

* Update frame/assets/src/functions.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* FMT

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…11241)

* pallet-asset: Fix transfer of a large amount of an asset

Before this pr transferring a large amount of an asset would check that transferring the asset would
not overflow the supply of the asset. However, it doesn't make sense to check for asset supply
overflow when we just transfer from one account to another account and don't increase the supply in
any way. It also required to extend the `can_deposit` method of `fungible` and `fungibles` with a
`mint` parameter. If this parameter is set to `true`, it means we want to mint the amount of an
asset before transferring it into an account. For `can_withdraw` we don't need to add an extra
parameter, because withdrawing should never be able to underflow the supply. If that would happen,
it would mean that somewhere the supply wasn't increased while increasing the balance of an account.

* Update frame/assets/src/functions.rs

* Update frame/assets/src/functions.rs

* Update frame/assets/src/functions.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* FMT

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants