`liquidatePositionsPartyA` limits partyB loss to partyB allocated balance, which can lead to inflated partyB balance and loss of funds for protocol users
The liquidation function limits partyB's loss to its current allocated balance, so if partyB has both a profitable and a losing position, liquidating the losing position first can zero out the balance and then the profitable position adds its full profit, inflating partyB's balance. This can make the protocol owe more than it holds, potentially causing a bank run.
Source: https://github.com/sherlock-audit/2023-08-symmetrical-judging/issues/6
Found by
bitsurfer, panprog
If partyB has positions both in a high profit and in a high loss, so that total upnl is much smaller than individual positions upnl, then partyB can deallocate most (or even all) of its funds. During partyA liquidation, liquidatePositionsPartyA limits partyB loss to the current allocated balance of partyB. In this case there is a big difference of the final results depending on order of position liquidations:
- If the 1st position is in a profit, then the profit is first applied to balanceB, and then position in loss correctly subtracts from it (there is enough partyB balance to fully cover position in loss).
- If the 1st position is in a loss, then balance (which is smaller than position loss) is simply reduced to 0, but then the 2nd position (which is in a profit) is added in full, leading to inflated final balance of partyB.
If such liquidation happens (intentional or not), partyB will have much more funds than it should at the expense of the other users: protocol will owe users more funds than it has, which can lead to bank run and the last users being unable to withdraw.
Vulnerability Detail
Example Scenario:
Position 1: upnl = -960, cva+lf = 10, mm=10 Position 2: upnl = +1000, cva+lf = 10, mm=10 Total cva+lf = 20, total mm=20 PartyB has allocated balance = 0 (available = 0 + 1000 - 960 = 40 >= 20 - not liquidatable) Party A is liquidated:
- Position 1 is liquidated.
amount = 960
amountToDeduct = 0 (because partyB allocated balance = 0)
partyB allocatedBalance remains 0
2. Position 2 is liquidated.
amount = 1000
partyB allocatedBalance increases by 1000 (is set to 1000)
The result: PartyB should have a balance of less than 60 (upnl+cva), but it has 1000 instead!
Impact
In some situations during partyA liquidations, PartyB balance is increased significantly while no funds enter the protocol, meaning protocol debt to users increases and is greater than protocol funds. This can cause a bank run, since the last users to withdraw will be unable to do so.
Code Snippet
amountToDeduct is calculated as minimum between partyB loss and partyB balance. This amount is deducted from current partyB allocated balance.
https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/facets/liquidation/LiquidationFacetImpl.sol#L163-L166
Tool used
Manual Review
Recommendation
Calculate total (signed) pnl for positions for each partyB before applying it: amountToDeduct should be for all positions combined for a particular partyB instead of separate positions.
Discussion
MoonKnightDev
Fixed Code PR: https://github.com/SYMM-IO/symmio-core/pull/36
xiaoming9090
Verified. Fixed in PR 36
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 logic calculates the loss deduction per position using the current allocated balance, rather than netting all positions' profit and loss for that partyB before applying the deduction.
Impact
PartyB's balance can be significantly increased without new funds entering the protocol, making the protocol owe more than it holds and potentially causing a bank run where the last users cannot withdraw.
What the attacker needed
PartyB has both a losing and a profitable position; partyB's allocated balance is low or zero; partyA is liquidated
The fix
The fix should calculate the total signed profit and loss for all positions of a partyB before applying any deduction, so that the loss is not capped per position.
How it was found
- PartyB has two positions: one with a loss and one with a profit, and its allocated balance is zero.
- PartyA is liquidated, and the losing position is liquidated first.
- The loss is capped at the current balance (zero), so the balance remains zero.
- The profitable position is then liquidated, and its full profit is added to partyB's balance, inflating it.
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, partyB provides funds and can have multiple positions. When partyA is liquidated, partyB's losses are capped at its current balance. If partyB has one losing and one winning position, the order of liquidation matters: if the losing one is processed first, the balance goes to zero, and then the winning one adds full profit, leaving partyB with more money than it should have. This extra money comes from other users' funds, so the protocol may not have enough to pay everyone.
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.