Sablier

Sablier
DeFiFoundry
53,440 USDC
View results
Submission Details
Severity: low
Invalid

calculatePixelWidth can be optimized.

Summary

calculatePixelWidth can be optimized as bytes(text).length can be very large and we have only one "It is further assumed that there is no other semicolon in text".

Vulnerability Details

function calculatePixelWidth(string memory text, bool largeFont) internal pure returns (uint256 width) {
    uint256 length = bytes(text).length;
    if (length == 0) {
        return 0;
    }

    unchecked {
        uint256 charWidth = largeFont ? 16 : 13;
        uint256 semicolonIndex;
        for (uint256 i = 0; i < length; ++i) {
            if (bytes(text)[i] == ";") {
                semicolonIndex = i;
            }
            width += charWidth;
        }

        // Account for escaped characters (such as &#8805;).
  @>>      width -= charWidth * semicolonIndex;
    }
}

Impact

code is optimized as we are not going through the whole array.

Tools Used

Recommendations

function calculatePixelWidth(string memory text, bool largeFont) internal pure returns (uint256 width) {
    uint256 length = bytes(text).length;
    if (length == 0) {
        return 0;
    }

    unchecked {
        uint256 charWidth = largeFont ? 16 : 13;
        uint256 semicolonIndex;
        for (uint256 i = 0; i < length; ++i) {
            if (bytes(text)[i] == ";") {
                semicolonIndex = i;
                 break;

            }
           
        }

        // Account for escaped characters (such as &#8805;).
         width =(length-i)*charWidth;
    }
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Info/Gas/Invalid as per Docs

https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity

Support

FAQs

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