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

PR: decimal value shall not be greater than 18 #309

Merged
merged 3 commits into from
May 28, 2024

Conversation

unboxedtype
Copy link
Contributor

@unboxedtype unboxedtype commented May 21, 2024

What

initialize() shall panic in case the supplied decimal value is greater than 18.

Why

The Soroban token has a balance type of i128, which allows for up to 38 digits (base 10), including the decimal part. However, the current token implementation allows decimal values up to u8::MAX. This is an overly loose input validation, since providing a value of >=39 would result in a unusable token, as 10^39 is not representable in i128 and will lead to overflows. Also, having this value slightly below 38 could may cause sporadic overflows in a protocol that rely on this token, due to the limited size of the integer part of the number.

The recommended upper bound for decimal value is 18. With this, you would still have ~20 digits available for the integer part, which should be sufficient for most use-cases. Also, 18 decimals is a standard value for Ethereum tokens, so using the same value leads to a greater compatibility between platforms.

@dmkozh dmkozh enabled auto-merge (squash) May 22, 2024 17:40
auto-merge was automatically disabled May 23, 2024 07:02

Head branch was pushed to by a user without write access

@unboxedtype
Copy link
Contributor Author

I fixed the corresponding test in test.rs to reflect the latest changes.

@dmkozh dmkozh enabled auto-merge (squash) May 23, 2024 15:31
auto-merge was automatically disabled May 25, 2024 06:20

Head branch was pushed to by a user without write access

@unboxedtype
Copy link
Contributor Author

There was a failing cargo fmt target that I didn't know existed. I fixed the formatting issue.

@dmkozh dmkozh enabled auto-merge (squash) May 28, 2024 16:47
@dmkozh dmkozh merged commit fbf4860 into stellar:main May 28, 2024
110 checks passed
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.

2 participants