sherlock-audit / 2024-05-beefy-cowcentrated-liquidity-manager-judging

5 stars 5 forks source link

EgisSecurity - `maxDevation` for some pools can be at most 3, which may be easily weaponized #83

Closed sherlock-admin2 closed 3 months ago

sherlock-admin2 commented 3 months ago

EgisSecurity

high

maxDevation for some pools can be at most 3, which may be easily weaponized

Summary

maxDeviation value is set so calmPeriod is checked on important actions such as deposit, withdraw and _setTicks. It protects against pool price manipulations using the current price, twap for a period and decide whether price has been manipulated by comparing it to the price deviation:

    function isCalm() public view returns (bool) { 
        int24 tick = currentTick();                
        int56 twapTick = twap();

        int56 minCalmTick = int56(SignedMath.max(twapTick - maxTickDeviation, MIN_TICK));
        int56 maxCalmTick = int56(SignedMath.min(twapTick + maxTickDeviation, MAX_TICK));

        // Calculate if tick move more than allowed from twap and revert if it did. 
        if(minCalmTick > tick  || maxCalmTick < tick) return false;
        else return true;
    }

The problem here is that if we are overprotective, a path for new vulnerabilities is uncovered. Here this is the case.

Vulnerability Detail

If we check veldrome pools and their liquidity, we see that second and third most active pools are USDC/sUSD and USDC/USDC . We assume that those pools are of interest to the protocol, because they are from the most active pools. Both has a fee of 0.01% and a tickSpacing = 1, which means that protocol can set maxTickDeviation to at most 3, because of the following lines:

    function setDeviation(int56 _maxDeviation) external onlyOwner {
        emit SetDeviation(_maxDeviation);

        // Require the deviation to be less than or equal to 4 times the tick spacing.
        if (_maxDeviation >= _tickDistance() * 4) revert InvalidInput();

        maxTickDeviation = _maxDeviation;
    }

Here we can also notice that the comment is wrong by claiming that deviation could be equal to 4 times tick spacing, when the reality is that it can be at most 3.

This is a very tight range, which can easily be moved even for stablecoin pairs without opening arbitrage oppertunities, because it is capital neglectable, but such action would cause important strategy actions to revert.

We can provide the following real values:

Manual Review

Recommendation

Make maxDeviation limit larger.

Duplicate of #58