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

3 stars 2 forks source link

0xpinky - `_getTicksForPosition` will not determine the valid lower and upper tick when `tickSpacingOffset > 0` #183

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

0xpinky

medium

_getTicksForPosition will not determine the valid lower and upper tick when tickSpacingOffset > 0

Summary

_getTicksForPosition will return the incorrect the lower and upper tick values when calling from _initializeStrategy

Vulnerability Detail

_initializeStrategy is called to initialize the strategies by traversing the strategy in a loop.

It would call the _getTicksForPosition to get the lower as well as upper ticks.

when look at the function _getTicksForPosition, below logic is used to decide the lower and upper tick value.

    } else if (tickSpacingOffset > 0) {
        lowerTick = floorTick + tickSpacing * tickSpacingOffset;
        upperTick = lowerTick + positionRange;
    } else {

But it is incorrect, upperTick is marked as lowerTick and vise versa.

Impact

Valid ticks are marked as invalid and reverted in the Line296

This _initializeStrategy would be calling in deposit(first time), rebalanceAll

So, rebalancing would be reverted due to this.

Code Snippet

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

Tool used

Manual Review

Recommendation

Update the below portion the codes as shown below

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

    } else if (tickSpacingOffset > 0) {
        upperTick = floorTick + tickSpacing * tickSpacingOffset;
        lowerTick = lowerTick + positionRange;
    } else {