-
Notifications
You must be signed in to change notification settings - Fork 279
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
Ametsuchi: fixed asset quantity overflow detection #154
Ametsuchi: fixed asset quantity overflow detection #154
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
fdf45fb
to
b42a0e7
Compare
test/framework/common_constants.hpp
Outdated
@@ -39,12 +40,19 @@ namespace common_constants { | |||
extern const std::string kSameDomainUserId; | |||
extern const std::string kAnotherDomainUserId; | |||
extern const std::string kAssetId; | |||
extern const std::string kAnotherDomainAssetId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kAnotherDomainAssetId
is unused and can be removed.
test/framework/common_constants.hpp
Outdated
|
||
// misc | ||
extern const shared_model::interface::Amount | ||
kAmountPrec1Max; // maximum amount of asset with pricision 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kAmountPrec1Max; // maximum amount of asset with pricision 1 | |
kAmountPrec1Max; // maximum amount of asset with precision 1 |
same below
AND precision >= $3 | ||
|
||
UNION | ||
SELECT 4, value < (2::decimal ^ 256) / 10::decimal ^ precision |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT 4, value < (2::decimal ^ 256) / 10::decimal ^ precision | |
SELECT 4, value < (2::decimal ^ 256) / (10::decimal ^ precision) |
* @given two users with all required permissions, one having the maximum | ||
* allowed quantity of an asset with precision 1 | ||
* @when execute a tx from another user with TransferAsset command for that | ||
* asset with the smallest possible quantity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* asset with the smallest possible quantity | |
* asset with the smallest possible quantity and then with a lower | |
* precision |
* allowed quantity of an asset with precision 1 | ||
* @when execute a tx from another user with TransferAsset command for that | ||
* asset with the smallest possible quantity | ||
* @then that transaction is not committed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @then that transaction is not committed | |
* @then the last two transactions are not committed |
* @given two users with all required permissions, one having the maximum | ||
* allowed quantity of an asset with precision 2 | ||
* @when execute a tx from another user with TransferAsset command for that | ||
* asset with the smallest possible quantity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* asset with the smallest possible quantity | |
* asset with the smallest possible quantity and then with a lower | |
* precision |
b01de70
to
1595ef4
Compare
1595ef4
to
b16c3a9
Compare
932705a
to
59b25d0
Compare
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
59b25d0
to
970f1fd
Compare
Description of the Change
Prior to this change, the maximum asset quantity was computed as
2^(256-p)
, wherep
is the asset precision. This had a weird consequence that an asset with greaterp
would have a greater significand* limit that will not fit a 256-bit integer.*) significand means
M
inN = M * e ^ p
floating point notationBenefits
Now the мантисса limit is always uint256_max, regardless the asset precision. Also the involved SQL got prettified (to my taste).
Possible Drawbacks
Usage Examples or Tests [optional]
See the
*Overflow*
tests inadd_asset_qty_test
andpostgres_executor_test
.Alternate Designs [optional]