Wrong calculation of solvency in `fillCloseRequest` prevents the position from being closed even if the user is solvent after position closure
The solvency check in `fillCloseRequest` requires both parties to be solvent at both the market price and the provided close price, causing the transaction to revert even when the close price would make both parties solvent. This prevents position closure and can lead to unfair liquidation and loss of funds for partyA.
panprog Follow with xiaoming90
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-08-symmetrical-judging/issues/9
Found by
panprog, xiaoming90
This is an issue 184 from previous contest, developers fixed it only partially (request to close), but fill close request remains the same.
If partyA has requested to close position, and partyB has called fillCloseRequest, the transaction will revert even though partyA is solvent after closure in the following scenario:
- partyA is not solvent if the position is closed at the current market price
closePriceprovided by the partyB is better than market price- partyA is solvent if the position is closed at the
closePriceprovided by partyB
This is unfair for partyA and can lead to liquidation and loss of funds for partyA, even though it could have had the position closed correctly to make it solvent.
Vulnerability Detail
isSolventAfterClosePosition verifies that both partyA and partyB are solvent at the market price, then verifies that both partyA and partyB are solvent at the closePrice. However, if both parties are solvent at closePrice - this should be sufficient, as it's the most fair way for both parties - let the position close if both parties are solvent after it. But the requirement to be solvent both at market and close price prevents the transaction from being completed successfully.
Impact
PartyA can be liquidated and lose funds instead of correct closure of the position due to failed position closure transaction.
Code Snippet
isSolventAfterClosePosition requires enough balance both at the market and close price:
https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/libraries/LibSolvency.sol#L101-L133
Tool used
Manual Review
Recommendation
Require both parties to only be solvent at closePrice when the position is closed, there is no point in reverting if the position closure can make both parties solvent, even though one of it is not solvent before that.
Discussion
MoonKnightDev
Fixed Code PR: https://github.com/SYMM-IO/symmio-core/pull/32
xiaoming9090
Verified. Fixed in PR 32
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The solvency check requires solvency at both the market price and the close price, instead of only at the close price.
Impact
PartyA can be liquidated and lose funds instead of having the position closed correctly.
What the attacker needed
PartyA requests to close position; partyB calls fillCloseRequest; partyA insolvent at market price; closePrice better than market price
The fix
The solvency check should require both parties to be solvent only at the close price, not at both market and close price.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a smart contract for closing financial positions, a function checks if both parties have enough funds. It incorrectly requires them to be solvent at two different prices, so even if the deal price would make everyone solvent, the closure fails. This can force a user into liquidation and lose money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.