sherlock-audit / 2023-06-real-wagmi-judging

3 stars 2 forks source link

0xdice91 - Loss Of Precision Due To Division Before Multiplication #178

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

0xdice91

medium

Loss Of Precision Due To Division Before Multiplication

Summary

Division before multiplication may lead to loss of precision

Vulnerability Detail

In the function _getTicksForPosition division before multiplication is used to get the value of floorTick.

    function _getTicksForPosition(
        int24 tick,
        int24 positionRange,
        int24 tickSpacingOffset,
        int24 tickSpacing
    ) private pure returns (int24 lowerTick, int24 upperTick) {
        int24 floorTick = (tick / tickSpacing) * tickSpacing;
        if (tickSpacingOffset == 0) {
// More code ....
 }

Impact

Loss of precision

Code Snippet

https://github.com/sherlock-audit/2023-06-real-wagmi/blob/main/concentrator/contracts/Multipool.sol#L259

Tool used

Manual Review

Recommendation

Recommend Using Multiplication before Division instead.

 function _getTicksForPosition(
        int24 tick,
        int24 positionRange,
        int24 tickSpacingOffset,
        int24 tickSpacing
    ) private pure returns (int24 lowerTick, int24 upperTick) {
        int24 floorTick = (tick * tickSpacing) / tickSpacing;
        if (tickSpacingOffset == 0) {
// More code...
 }

Duplicate of #82