-
Notifications
You must be signed in to change notification settings - Fork 1
Emmanuel - Exiting the market as a trader results in a deficit in collateral balance. #66
Comments
2 comment(s) were left on this issue during the judging contest. 141345 commented:
panprog commented:
|
A user cannot fully withdraw their collateral in the same update where they set their position to 0 as this will put them below the minimum maintenance requirement. They will need to wait to withdraw collateral until after the position change has settled, at which time position fees will be properly deducted. |
Escalate Deducting of keeper fees separately from liquidationFee is a problem because in case liquidatorFee causes position's balance to be 0, deducting the fees during next settlement will result in deficit |
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. |
Escalate There is no problem as it's expected behavior. Liquidation fee alone can also put account into deficit, it's not like fees are something that is the only way to put account into deficit. Moreover, even if account is not liquidated, its collateral can become negative just due to price movement. |
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. |
If a position is in a deficit, it implies that other users will be forced to cover the debt accrued by the account. Additionally, keep in mind that a user can self-liquidate. They can open multiple positions with different accounts and subsequently liquidate them, resulting in several accounts carrying a negative collateral balance (this debt will be paid by other users). |
Account deficit by itself is an expected protocol functionality: collateral is intentionally signed and can be negative. So this if by design. This report states the following issues:
Since both issues stated in the report are invalid, the report itself should be invalid. Stated impacts are
While accounts in deficit might be a problem for the other users, this report doesn't talk about it specifically, only in relation to fees which might have to be paid by the other users (which is incorrect as explained above). And the issue stated is fees, not the account deficit by itself.
This is not described in the report at all: self-liquidation is not an easy operation to do and an issue by itself. Even when user can self-liquidate, minMaintenance collateral >= minLiquidationFee restriction (when setting market risk parameters) ensures that the user account is not in deficit even if intentionally self-liquidated. |
The core issue this report is pointing out is that deducting of keeper fees during next settlement could lead to a deficit in collateral balance.
This scenario has been correctly invalidated by the judges and sponsor
This issue also explains that users pay So there can be a scenario where a trader uses a contract(or many contracts) to open positions, and when it gets liquidated, the balance becomes negative(due to delayed fee deduction), and the trader abandons the account. |
The problem is not about keeper fees separated from liquidationFee. The focus is deficit here. But liquidation itself can create deficit as well, as panprog points out. Most protocols face profit and loss, limited deficit should not be vulnerability. Keeper fee combined with liquidationFee could be future design consideration. Low severity seems more appropriate. |
Yes. Liquidation causing a deficit is also a problem, and has been reported here.
Please note that this loss will be paid by some other unlucky users(specifically, the last set of users to withdraw their collateral).
Other users will be forced to pay this created debt, and this is the main reason why I believe this is an issue->loss of funds of other users |
If the attacker intentionally create deficits, multiple positions need to be opened, the cost of the attack is quite high. Seems there is no profit for the attacker. |
Even if the malicious user does not profit, they lose nothing as well, while causing some other users to lose. Additionally, the malicious user can profit if, due to PnL, their collateral balance falls below the minLiquidationFee. In this case, they will gain minLiquidationFee - collateralBalance. Then, deducting positionFees in the next settlement will create a greater deficit. |
Emmanuel
medium
Exiting the market as a trader results in a deficit in collateral balance.
Summary
It is expected that a trader that closes all his position and withdraws all his collateral will have a collateral balance of 0, but this is not so due to the delayed settlement of position fees
Vulnerability Detail
When a user updates his positions, the position fees and keeper fees does not get deducted immediately, rather it gets deducted during the next settlement.
If a trader decides to exit a market by closing all his positions and withdrawing all his collateral, the fees will be deducted during the next settlement, so his collateral balance becomes negative.
If trader does not enter the market again(very possible if trader is a contract controlled by an EOA), collateral balance of that account remains negative, so the assumption that account MUST pay back during the next settlement holds false.
When the fees get withdrawn by protocol, other users' collateral pay for the fees that the malicious trader ought to have paid.
Similarly, during liquidations, fees are deducted from the liquidated account's collateral balance during the next settlement, instead of it to be deducted from the liquidationFee that liquidator will receive. This is unfair to the liquidated account because now, they are paying liquidationFee+keeperFee+positionFee, instead of them to pay just liquidationFee.
Impact
Code Snippet
https://github.com/sherlock-audit/2023-07-perennial/blob/main/perennial-v2/packages/perennial/contracts/Market.sol#L345
https://github.com/sherlock-audit/2023-07-perennial/blob/main/perennial-v2/packages/perennial/contracts/Market.sol#L440
https://github.com/sherlock-audit/2023-07-perennial/blob/main/perennial-v2/packages/perennial/contracts/types/Local.sol#L72
Tool used
Manual Review
Recommendation
When updating position, users should only be able to withdraw up to collateralBalance-(newOrder.fee+newOrder.keeper), so that when fees get debited during next settlement, collateralBalance will be 0 and not negative.
Also, during liquidation, liquidator should receive liquidatioFee-(newOrder.fee+newOrder.keeper)
The text was updated successfully, but these errors were encountered: