sherlock-audit / 2024-06-symmetrical-update-2-judging

0 stars 0 forks source link

unix515 - `Force Close Minimum Signature Period` might be skipped when `closePrice` is different than `sig.averagePrice`. #18

Closed sherlock-admin4 closed 1 week ago

sherlock-admin4 commented 2 weeks ago

unix515

Medium

Force Close Minimum Signature Period might be skipped when closePrice is different than sig.averagePrice.

Summary

Vulnerability Detail

  1. For about PartyA's forceClosePosition,

  2. On PartyAFacetImpl#forceClosePosition(),

    • maLayout.forceCloseMinSigPeriod (the minimum signature period required for force closing of positions) is checked only when closePrice is equal to sig.averagePrice.
    • It means the minimum signature period might be not elapsed when closePrice is different thansig.averagePrice.
function forceClosePosition(
    uint256 quoteId,
    HighLowPriceSig memory sig
) internal returns (
    uint256 closePrice, 
    bool isPartyBLiquidated, 
    int256 upnlPartyB, 
    uint256 partyBAllocatedBalance
) {
    ...
    if (closePrice == sig.averagePrice) //<---------- @audit
        require(
            sig.endTime - sig.startTime >= maLayout.forceCloseMinSigPeriod, 
            "PartyAFacet: Invalid signature period"
        );
    }
    ...
}
  1. But for about forceCloseMinSigPeriod,
    • It is an independent mechanism how closePrice is determined.
    • It focuses on the integrity of the state and ensuring both parties agree on the final state before closing.

Impact

Force Close Minimum Signature Period might be not elapsed when closePrice is different than sig.averagePrice and It happens protocol violation.

Code Snippet

https://github.com/sherlock-audit/2024-06-symmetrical-update-2/blob/main/protocol-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L243

Tool used

Manual Review

Recommendation

Please update PartyAFacetImpl#forceClosePosition() as follows.

    function forceClosePosition(
        uint256 quoteId,
        HighLowPriceSig memory sig
    ) internal returns (
        uint256 closePrice, 
        bool isPartyBLiquidated, 
        int256 upnlPartyB, 
        uint256 partyBAllocatedBalance
    ) {
        ...
--      if (closePrice == sig.averagePrice)
            require(
                sig.endTime - sig.startTime >= maLayout.forceCloseMinSigPeriod, 
                "PartyAFacet: Invalid signature period"
            );
--      }
        ...
    }
sherlock-admin4 commented 1 week ago

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

Hash01011122 commented:

Invalid