DeFiHardhat
21,000 USDC
View results
Submission Details
Severity: low
Invalid

`formatUintWith6DecimalsTo2` should return 0.00 when input length < 4

Summary

formatUintWith6DecimalsTo2 is a function to convert a uint128 number with 6 decimal to a string with 2 decimals.
while number with less than 4 digits always return 0.00, no more calculation is needed.

Vulnerability Details

any number with less than 4 digits will always return 0.00, no more calculation is needed, so the function should return 0.00 directly to avoid unnecessary calculation.

function formatUintWith6DecimalsTo2(uint128 number)
internal
pure
returns (string memory)
{
// Cast to uint256 to be compatible with toString
string memory numString = toString(uint256(number));
// If the number has fewer than 6 decimals, add trailing zeros
@> while (bytes(numString).length < 7) {
numString = string(abi.encodePacked("0", numString));
}

Impact

Redundant calculations will be performed when the input length is less than 4, which is unnecessary and will waste gas.

Tools Used

manual

Recommendation

just return 0.00 directly when the input length is less than 4, to avoid unnecessary calculations.

Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.