Liquidating pending quotes doesn't return trading fee to party A
When a pending quote is liquidated, the trading fee paid by party A is not returned or used to cover the liquidation, but instead kept by the fee collector. An attacker could exploit this to cause party A to lose funds that should be returned or used to offset debts.
AkshaySrivastav Follow with Ruhum, mstpr-brainbot and 5 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/71
Found by
AkshaySrivastav, Ruhum, mstpr-brainbot, nobody2018, panprog, rvierdiiev, simon135, sinarette
Summary
When a user is liquidated, the trading fees of the pending quotes aren't returned.
Vulnerability Detail
When a pending/locked quote is canceled, the trading fee is sent back to party A, e.g.
- https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L136
- https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/PartyA/PartyAFacetImpl.sol#L227
But, when a pending quote is liquidated, the trading fee is not used for the liquidation. Instead, the fee collector keeps the funds:
function liquidatePendingPositionsPartyA(address partyA) internal {
QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
require(
MAStorage.layout().liquidationStatus[partyA],
"LiquidationFacet: PartyA is solvent"
);
for (uint256 index = 0; index < quoteLayout.partyAPendingQuotes[partyA].length; index++) {
Quote storage quote = quoteLayout.quotes[
quoteLayout.partyAPendingQuotes[partyA][index]
];
if (
(quote.quoteStatus == QuoteStatus.LOCKED ||
quote.quoteStatus == QuoteStatus.CANCEL_PENDING) &&
quoteLayout.partyBPendingQuotes[quote.partyB][partyA].length > 0
) {
delete quoteLayout.partyBPendingQuotes[quote.partyB][partyA];
AccountStorage
.layout()
.partyBPendingLockedBalances[quote.partyB][partyA].makeZero();
}
quote.quoteStatus = QuoteStatus.LIQUIDATED;
quote.modifyTimestamp = block.timestamp;
}
AccountStorage.layout().pendingLockedBalances[partyA].makeZero();
delete quoteLayout.partyAPendingQuotes[partyA];
}
function liquidatePartyB(
address partyB,
address partyA,
SingleUpnlSig memory upnlSig
) internal {
// ...
uint256[] storage pendingQuotes = quoteLayout.partyAPendingQuotes[partyA];
for (uint256 index = 0; index < pendingQuotes.length; ) {
Quote storage quote = quoteLayout.quotes[pendingQuotes[index]];
if (
quote.partyB == partyB &&
(quote.quoteStatus == QuoteStatus.LOCKED ||
quote.quoteStatus == QuoteStatus.CANCEL_PENDING)
) {
accountLayout.pendingLockedBalances[partyA].subQuote(quote);
pendingQuotes[index] = pendingQuotes[pendingQuotes.length - 1];
pendingQuotes.pop();
quote.quoteStatus = QuoteStatus.LIQUIDATED;
quote.modifyTimestamp = block.timestamp;
} else {
index++;
}
}
These funds should be used to cover the liquidation. Since no trade has been executed, the fee collector shouldn't earn anything.
Impact
Liquidation doesn't use paid trading fees to cover outstanding balances. Instead, the funds are kept by the fee collector.
Code Snippet
https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/liquidation/LiquidationFacetImpl.sol#L105-L120 https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/liquidation/LiquidationFacetImpl.sol#L277-L293
Tool used
Manual Review
Recommendation
return the funds to party A. If party A is being liquidated, use the funds to cover the liquidation. Otherwise, party A keeps the funds.
Discussion
MoonKnightDev
Fixed code PR link:
https://github.com/SYMM-IO/symmio-core/pull/8
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
Likely the liquidation functions do not handle the trading fee for pending quotes, leaving it in the fee collector's balance instead of returning it to party A or using it for liquidation.
Impact
Liquidation does not use paid trading fees to cover outstanding balances; instead, the funds are kept by the fee collector, causing a loss to the liquidated party.
What the attacker needed
Party A has pending quotes with trading fees; party A is liquidated
The fix
The funds should be returned to party A; if party A is being liquidated, the funds should be used to cover the liquidation.
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 this system, users pay a trading fee when they create a quote. If the quote is cancelled before execution, the fee is normally refunded. However, when a user is liquidated (forced to close positions due to insufficient funds), the fee for pending quotes is not refunded or used to pay off debts; it goes to the fee collector. This means the liquidated user loses money that should have been returned or used to reduce their debt.
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.