EgisSecurity - Under certain circumstances bad debt will cause first depositor to lose funds #319
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A Medium severity issue.
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
EgisSecurity
Medium
Under certain circumstances bad debt will cause first depositor to lose funds
Summary
The protocol handles bad debt through
PositionManager::liquidateBadDebt()
The function is used to handle bad debt if it occurs for a specific
position
.Let's examine
pool.rebalanceBadDebt
:Wen ca see that
totalBorrowShares, totalBorrowAssets and totalDepositAssets
decremented by their respective values (shares and assets).When bad debt occurs and is liquidated, it's basically written off the protocol and the losses are socialized between all the depositors of that pool.
There is 1 problem with this, if a
position
has borrowed the entire assets of thepool
and is liquidated due to bad debt. This is realistic if the pool is unpopular for some reason (niche token, high fees, etc...). Note that this can also occur when all positions incur bad debt and their debt gets socialized, but it's a rarer for this to happen.The problem will be the fact that
totalDepositAssets
will equal 0. When it's 0, when a user deposits into the pool, his shares are minted 1:1 to the assets he is providing, which is a problem, because there are other shares in the pool at this time, the shares of the depositors that got socialized the bad debt.Example:
totalDepositAssets == totalBorrowAssets
.totalDepositAssets = 150
andtotalBorrowAssets = 150
.liquidateBadDebt
.rebalanceBadDebt
is called bothtotalDepositAssets
andtotalBorrowAssets
equal 0.totalDepositAssets = 0
, buttotalDepositShares = 100
.Root Cause
Allowing for 100% utilization of assets.
Note that only 1 of the 3 bellow have to happen in order for the issue to occur.
Internal pre-conditions
Optional:
External pre-conditions
Optional:
Attack Path
None
Impact
Loss of funds
PoC
None
Mitigation
Don't allow for pools to reach 100% utilization.
The text was updated successfully, but these errors were encountered: