Inconsistent in the liquidation fee leads to unfairness in liquidation process
The force close liquidation mechanism gives PartyA access to the liquidatee's reserve vault funds, increasing the liquidatee's allocated balance and reducing the computed available balance deficit. This results in a higher liquidation fee for PartyA compared to normal liquidators, creating unfairness in the liquidation process.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-09-symmio-v0-8-4-update-contest-judging/issues/52
The protocol has acknowledged this issue.
Found by
xiaoming90
Summary
Reserve vault results in unfairness in the liquidation process. PartyA using force close mechanism to liquidate a position will receive more liquidation fees compared to normal liquidators as they have access to the funds in the reserve vault.
This creates unfairness to the protocol's liquidation process and to the existing liquidators, as they will receive lesser liquidation fees than Alice (PartyA). Without a fair and effective liquidation process, the protocol's solvent will be at risk, as bad positions will not be liquidated in a timely manner, and some liquidators might not want to participate in the process due to unfairness in the system.
Root Cause
- Inconsistent in the liquidation fee given to PartyA and liquidators as PartyA performs liquidation via force close mechanism has access to funds in liquidatee's reserve vault, while normal liquidators do not.
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
Assume that PartyB's reserve vault has 1000 USD. During force closing, if PartyB's account is underwater, even with the additional support from its reserve vault, PartyB's account will be liquidated, as per Lines 127-138 below.
In Lines 128 and 129, the protocol transfers all the existing funds (1000 USD) from PartyB's reserve vault to PartyB's allocated balance. Thus, before the liquidation process is executed at Line 137 below, the PartyB's allocated balance will increase by 1000 USD.
File: ForceActionsFacetImpl.sol
051: function forceClosePosition(
..SNIP..
112: require(partyAAvailableBalance >= 0, "PartyAFacet: PartyA will be insolvent");
113: if (partyBAvailableBalance >= 0) {
..SNIP..
118: } else if (partyBAvailableBalance + int256(reserveAmount) >= 0) {
..SNIP..
127: } else { // @audit-info Code block for liquidating position
128: accountLayout.reserveVault[quote.partyB] = 0;
129: accountLayout.partyBAllocatedBalances[quote.partyB][quote.partyA] += reserveAmount;
130: emit SharedEvents.BalanceChangePartyB(quote.partyB, quote.partyA, reserveAmount, SharedEvents.BalanceChangeType.REALIZED_PNL_IN);
131: int256 diff = (int256(quote.quantityToClose) * (int256(closePrice) - int256(sig.currentPrice))) / 1e18;
132: if (quote.positionType == PositionType.LONG) {
133: diff = diff * -1;
134: }
135: isPartyBLiquidated = true;
136: upnlPartyB = sig.upnlPartyB + diff;
137: LibLiquidation.liquidatePartyB(quote.partyB, quote.partyA, upnlPartyB, block.timestamp);
138: }
As a result, when the LibLiquidation.liquidatePartyB is executed at Line 137 above, the computed availableBalance will be 1000 USD smaller when the liquidation process is triggered via the forceClosePosition function compared to the standard liquidation process that is triggered via LiquidationFacet.liquidatePartyB by the liquidators, as shown below. This can be proven via the formula within partyBAvailableBalanceForLiquidation function.
**Normal scenario without access to reserve vault's funds**
availableBalance = partyBAllocatedBalances - lockedValue + PnL
availableBalance = 1000 - 100 - 2000 = -1100
**Force close with access the reserve vault's funds => partyBAllocatedBalances will 1000 USDC higher (1000 => 2000)**
availableBalance = partyBAllocatedBalances - lockedValue + PnL
availableBalance = 2000 - 100 - 2000 = -100
Assume Alice is entitled to execute the force close function against PartyB, while Bob is a normal liquidator that can only liquidate PartyB via the standard LiquidationFacet.liquidatePartyB function.
When Alice triggers the liquidation process, the availableBalance will be -100 instead of -1000. Thus, when computing the liquidation fee that the liquidator is entitled to at Line 39 below, the computed liquidation fee (remainingLf) will be higher. This means that if Alice triggered the liquidation process, she would receive more liquidation fees compared to Bob because she has access to funds within PartyB's reserve vault. In this case, Alice is the liquidator and will receive the liquidation fee.
As a result, this creates unfairness within the system and to the existing liquidators as they (e.g., Bob) will receive lesser liquidation fees compared to Alice.
File: LibLiquidation.sol
23: function liquidatePartyB(address partyB, address partyA, int256 upnlPartyB, uint256 timestamp) internal {
24: AccountStorage.Layout storage accountLayout = AccountStorage.layout();
25: MAStorage.Layout storage maLayout = MAStorage.layout();
26: QuoteStorage.Layout storage quoteLayout = QuoteStorage.layout();
27:
28: // Calculate available balance for liquidation
29: int256 availableBalance = LibAccount.partyBAvailableBalanceForLiquidation(upnlPartyB, partyB, partyA);
30:
31: // Ensure Party B is insolvent
32: require(availableBalance < 0, "LiquidationFacet: partyB is solvent");
..SNIP..
37: // Determine liquidator share and remaining locked funds
38: if (uint256(-availableBalance) < accountLayout.partyBLockedBalances[partyB][partyA].lf) {
39: remainingLf = accountLayout.partyBLockedBalances[partyB][partyA].lf - uint256(-availableBalance);
40: liquidatorShare = (remainingLf * maLayout.liquidatorShare) / 1e18;
41:
42: maLayout.partyBPositionLiquidatorsShare[partyB][partyA] =
43: (remainingLf - liquidatorShare) /
44: quoteLayout.partyBPositionsCount[partyB][partyA];
45: } else {
46: maLayout.partyBPositionLiquidatorsShare[partyB][partyA] = 0;
47: }
Impact
This creates unfairness to the protocol's liquidation process and to the existing liquidators, as they will receive lesser liquidation fees than Alice. Without a fair and effective liquidation process, the protocol's solvent will be at risk, as bad positions will not be liquidated in a timely manner, and some liquidators might not want to participate in the process due to unfairness in the system.
PoC
No response
Mitigation
The liquidation process for Alice and existing liquidators should be consistent to ensure fairness. In the above case, consider either of the following solutions:
- Do not take into consideration the reserve vault's funds during liquidation within the
forceClosePositionfunction; OR - Take into consideration the reserve vault's funds within the
LiquidationFacet.liquidatePartyBfor consistency.
Discussion
MoonKnightDev
Normal liquidators can also call the settleAndForceClose functions.
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 force close function transfers the liquidatee's reserve vault funds into their allocated balance before liquidation, which reduces the available balance deficit and thus increases the liquidation fee compared to the standard liquidation path that does not include reserve vault funds.
Impact
This creates unfairness in the liquidation process, as normal liquidators receive lesser fees, potentially discouraging participation and risking the protocol's solvency.
What the attacker needed
PartyB has funds in reserve vault; PartyB is underwater; PartyA can call forceClosePosition
The fix
The liquidation process should be made consistent by either not considering the reserve vault's funds during force close liquidation or including them in the standard liquidation path.
How it was found
- Assume PartyB's reserve vault has 1000 USD and PartyB's account is underwater.
- Alice (PartyA) calls forceClosePosition on PartyB.
- The function transfers all reserve vault funds to PartyB's allocated balance.
- The liquidation function is called with the increased allocated balance, resulting in a smaller deficit.
- The liquidation fee is computed based on the smaller deficit, giving Alice a higher fee than a normal liquidator would receive.
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 protocol, when a trader's position is liquidated, the liquidator gets a fee. The report says that if the trader themselves (PartyA) triggers the liquidation via a special 'force close' function, they can access the failing trader's reserve vault, which makes the failing trader's balance look better and thus the liquidation fee larger. Normal liquidators cannot access that reserve vault, so they get a smaller fee, which is unfair.
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.