-
Notifications
You must be signed in to change notification settings - Fork 4
shaka - Wrong calculation of solvency after request to close and after close position #184
Comments
The line that is checking whether the available balance is less than zero or not and reverts, is assessing the user's status if the position were to close right now. If it doesn't meet these conditions and doesn't pass, it implies that the user is already insolvent. |
Escalate. Even if the user is not solvent at the beginning of the close process, I cannot find any reason for not allowing a user to close a position if the outcome is that they are not insolvent anymore and both parties receive what they are due, in the same way as a user may increase their collateral to recover solvency. |
You've created a valid escalation! To remove the escalation from consideration: Delete your comment. You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final. |
I agree with @shaka0x that this is a valid issue, even though very unlikely, but still possible, and it's more fair to let partyB close position with a price more favorable to partyA than requested, if it leads to solvent accounts after closure (even if partyA is insolvent at the current price). On the other hand, I also understand the other point of view: if the user is already insolvent at the current price, he can be denied all position actions which will also be fair (as he's insolvent - he should be liquidated and no other actions allowed). Ultimately I think this is a design choice, so it's up to developers to decide what is the expected behavior. |
The system is designed to verify the user's solvency after a request to close, but I agree that this step may be unnecessary. It might be sufficient to check solvency solely within the fillCloseRequest() function. |
The report is not about user being insolvent at the time of request to close, it's about user being insolvent at market price, but solvent at the requested price (during request to close) or at the closePrice (during fill close request). During request (long position):
During fillCloseRequest:
|
Fixed code PR link: |
Result: |
Escalations have been resolved successfully! Escalation status:
|
shaka
medium
Wrong calculation of solvency after request to close and after close position
Summary
isSolventAfterClosePosition
andisSolventAfterRequestToClosePosition
do not account for the extra profit that the user would get from closing the position.Vulnerability Detail
When a party A creates a request for closing a position, the
isSolventAfterRequestToClosePosition
function is called to check if the user is solvent after the request. In the same way, when someone tries to close a position, theisSolventAfterClosePosition
function is called to check if both party A and party B are solvent after closing the position.Both functions calculate the available balance for party A and party B, and revert if it is lower than zero. After that, the function accounts for the the extra loss that the user would get as a result of the difference between
closePrice
andupnlSig.price
, and checks if the user is solvent after that.The problem is that the function does not account for the opposite case, that is the case where the user would get an extra profit as a result of the difference between
closePrice
andupnlSig.price
. This means that the user would not be able to close the position, even if at the end of the transaction they would be solvent.Proof of Concept
There is an open position with:
Party B calls
fillCloseRequest
with:In
isSolventAfterClosePosition
the following is calculated:And it reverts on:
However, the extra profit for
closedPrice - upnlSig.price = 120 - 110 = 10
is not accounted for in thepartyAAvailableBalance
calculation, that should bepartyAAvailableBalance = - 5 + 10 = 5
. Party A would be solvent after closing the position, but the transaction reverts.Impact
In a situation where the difference between the closed price and the current price will make the user solvent, users will not be able to close their positions, even if at the end of the transaction they would be solvent.
Code Snippet
https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/libraries/LibSolvency.sol#L109-L152
https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/libraries/LibSolvency.sol#L166-L184
Tool used
Manual Review
Recommendation
Add the extra profit to the
partyAAvailableBalance
calculation.The text was updated successfully, but these errors were encountered: