sherlock-audit / 2023-12-flatmoney-judging

11 stars 9 forks source link

GoSlang - Funding fees accumulate when contracts are paused can lead to protocol insolvency #72

Closed sherlock-admin2 closed 8 months ago

sherlock-admin2 commented 8 months ago

GoSlang

high

Funding fees accumulate when contracts are paused can lead to protocol insolvency

Summary

The team has the ability to pause the user iteration with the following functions

announceStableDeposit, announceStableWithdraw, announceLeverageOpen, announceLeverageAdjust, announceLeverageClose, executeOpen, executeAdjust, executeClose, liquidate, liquidate, executeDeposit and executeWithdraw

Vulnerability Detail

When the market is paused funding fees which are based on time will keep accumulating this is a problem since it will slowly eat away at the ones paying, leading them to lose funds without being able to do anything about it, a larger issue arise once combined with the fact that liquidations cant take place when a market is paused, since this would enable for positions to go in the negative if there is a price drop combined if an unboned amount of funding fees which if left unchecked for long enough can lead to protocol insolvency once the market is unpaused.

Impact

Liquidations are paused when while funding fees keep accumulating leading to protocol insolvency

Code Snippet

    function settleFundingFees() public returns (int256 _fundingFees) {
        (int256 fundingChangeSinceRecomputed, int256 unrecordedFunding) = _getUnrecordedFunding();

        cumulativeFundingRate = PerpMath._nextFundingEntry(unrecordedFunding, cumulativeFundingRate);

        lastRecomputedFundingRate += fundingChangeSinceRecomputed;
        lastRecomputedFundingTimestamp = (block.timestamp).toUint64();

        _fundingFees = PerpMath._accruedFundingTotalByLongs(_globalPositions, unrecordedFunding);

        _globalPositions.marginDepositedTotal = (int256(_globalPositions.marginDepositedTotal) > _fundingFees)
            ? uint256(int256(_globalPositions.marginDepositedTotal) + _fundingFees)
            : 0;

        _updateStableCollateralTotal(-_fundingFees);
    }

Tool used

Manual Review

Recommendation

Allow liquidations to take place doing a paused.

sherlock-admin commented 8 months ago

1 comment(s) were left on this issue during the judging contest.

takarez commented:

invalid

nevillehuang commented 8 months ago

Invalid based on the following sherlock rules. Additionally, this could possibly be mitigated by admins via an adjust ment of maxFundingVelocity to 0 here

5.3 An admin action can break certain assumptions about the functioning of the code. Example: Pausing a collateral causes some users to be unfairly liquidated or any other action causing loss of funds. This is not considered a valid issue.