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.
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.