haircutPremia
will not cover protocol losses using liquidatee long premiums
#534
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
grade-b
primary issue
Highest quality submission among a set of duplicates
Q-09
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_242_group
AI based duplicate group recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Lines of code
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/libraries/PanopticMath.sol#L768-L858
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/CollateralTracker.sol#L1043-L1080
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/PanopticPool.sol#L1122-L1131
Vulnerability details
Issue Description
When the user positions are getting liquidated the
PanopticPool::liquidate
function will invoke under the hood thePanopticMath::haircutPremia
function which will use the liquidatee's owed long premium to cover any eventual protocol losses.The issue that it's present in the
PanopticPool::haircutPremia
function is that when trying to exercice the haircut amounts it will mint new collaterals shares to the liquidatee instead of burning them from his existing balance and this is due to the fact that the calculated haircut amountshaircut0
andhaircut1
passed toCollateralTracker::exercise
are both positive values.To understand this, let's first look at the function code snippet below:
As it can be seen, the function will calculates the values of both
haircut0
andhaircut1
which represents the portion of long premium owed by the liquidatee that must be haircut to cover the protocol losses (this means that this portion of owed long premium will not be given to the seller but instead returned to the collateral pool for PLP).If we look at the code above, we can notice the following:
longPremium
is a positive number as is calculated using this formula:We know that for long options
premiasByLeg
is negative and so by usingsub
(applying -)longPremium
we'll be the sum of- premiasByLeg
which we'll be positive.collateralDelta0
&collateralDelta1
are both positive numbers (either equal to 0 or above it) which can be deducted from their definition:If
collateralRemaining
is negative then we'll get a positive number after applying (-) and if its above 0 then the min will return 0.Knowing this two facts we can concluded that no matter which if statement block is run in the
haircutPremia
function to calculatehaircut0
andhaircut1
, both their values will be positive as they are the combination (equal or sum) of positive values: (collateralDelta0
orcollateralDelta1
), (protocolLoss0
orprotocolLoss1
) andlongPremium
(and this is quiet evident in the last else block).As we explained above, to get the owed premium from the liquidatee collaterals, the
CollateralTracker::exercise
function is called. This function's logic implies that if the providedrealizedPremia
(represented byhaircut0
andhaircut1
here) value is positive, then we must mint new collateral shares to the user, and ifrealizedPremia
is negative, then we should burn from his balance instead, as shown below:So because both
haircut0
andhaircut1
are positive and they represent the realized premiarealizedPremia
provided toCollateralTracker::exercise
function, this later will mint new collateral shares to the liquidatee instead of burning them from his balance (realizedPremium > 0 ==> tokenToPay=-realizedPremium < 0
).This issue means that whenever the
haircutPremia
function is called in a liquidation call, if there are some protocol losses the function will not haircut from the liquidatee collateral shares balance and will mint him new collateral shares instead, this will result in a protocol loss and will impact all the PLP and other users that deposited collaterals into the collateral tracker which will experience a direct fund loss due to this issue.Impact
During liquidations, the
PanopticMath::haircutPremia
function will not remove the long premiums from liquidatee collateral shares to cover protocol losses and will instead mint him new collateral shares, resulting in a loss of funds for the protocol and the PLP.Tools Used
Manual review, VS Code
Recommended Mitigation
When calling
CollateralTracker::exercise
inPanopticMath::haircutPremia
, the providedrealizedPremia
parameter value should be negative to remove collateral shares from the liquidatee balance as follows:Assessed type
Context
The text was updated successfully, but these errors were encountered: