This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
panprog - Position value can fall below minimum acceptable quote value when partially closing positions requested to be closed in full #12
Labels
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
panprog
medium
Position value can fall below minimum acceptable quote value when partially closing positions requested to be closed in full
Summary
This is issue 248 from previous audit contest, which was fixed incorrectly.
When PartyA requests to close LIMIT position in full, but partyB closes it partially, the remaining open quote can be below
minAcceptableQuoteValue
, breaking important protocol invariant, which can cause different problems, such as not enough incentive to liquidate dust positions.Vulnerability Detail
In
LibQuote.closeQuote
there is a requirement to have the remaining quote value to not be less thanminAcceptableQuoteValue
:Notice the condition when this require happens:
LibQuote.quoteOpenAmount(quote)
is remaining open amountquote.quantityToClose
is requested amount to closeThis means that this check is ignored if partyA has requested to close amount equal to full remaining quote value, but enforced when it's not (even if closing fully). For example, a quote with opened amount = 100 is requested to be closed in full (amount = 100): this check is ignored. But PartyB can fill the request partially, for example fill 99 out of 100, and the remainder (1) is not checked to confirm to
minAcceptableQuoteValue
.The following execution paths are possible if PartyA has open position size = 100 and
minAcceptableQuoteValue
= 5:requestToClosePosition(99)
-> revertrequestToClosePosition(100)
->fillCloseRequest(99)
-> pass (remaining quote = 1)Impact
There can be multiple reasons why the protocol enforces
minAcceptableQuoteValue
, one of them might be the efficiency of the liquidation mechanism: when quote value is too small (and liquidation value too small too), liquidators will not have enough incentive to liquidate these positions in case they become insolvent. Both partyA and partyB might also not have enough incentive to close or respond to request to close such small positions, possibly resulting in a loss of funds and greater market risk for either user.Proof of Concept
Add this to any test, for example to
ClosePosition.behavior.ts
.Console execution result:
Code Snippet
Notice the condition to perform the
minAcceptableQuoteValue
check:https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/libraries/LibQuote.sol#L155-L158
Tool used
Manual Review
Recommendation
The condition should be to ignore the
minAcceptableQuoteValue
if request is filled in full (filledAmount == quantityToClose):The text was updated successfully, but these errors were encountered: