Bauchibred - clearBadDebt
function still does not accrue earnings from each maturity
#5
Labels
Non-Reward
This issue will not receive a payout
Bauchibred
Medium
clearBadDebt
function still does not accrue earnings from each maturitySummary
During the operation of a maturity,
Pool.accrueEarnings()
is triggered to transfer thebackupEarnings
fromunassignedEarnings
of the maturity to the floating pool, which is dripped over time. However, theclearBadDebt()
function does not triggerPool.accrueEarnings()
to collect earnings for the backup supply. This results in a loss of the remaining earnings if a maturity ends with aclearBadDebt()
call.Vulnerability Detail
In the FixedLib library, the
accrueEarnings()
function is used to collect backup earnings from a specific maturity (fixed pool) to the floating pool. These earnings are dripped from theunassignedEarnings
of the maturity over time.Pool.accrueEarnings()
is called whenever an operation of the maturity (such as deposit, withdrawal, borrowing, or repayment) occurs see https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/3eb87e3edf3bcd57c4cc1c6a73e8255f575b76de/protocol/contracts/utils/FixedLib.sol#L84-L99Now,
Market.clearBadDebt()
is a function called byAuditor.handleBadDebt()
to clear all the debt of a borrower when this borrower has no collateral. It clears all debt from each maturity that this account has borrowed from. However, it does not triggeraccrueEarnings()
for each fixed pool, seeMarket.clearBadDebt()
https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/3eb87e3edf3bcd57c4cc1c6a73e8255f575b76de/protocol/contracts/Market.sol#L637-L660An issue will occur when a maturity ends and
clearBadDebt()
is the last operation of this maturity, but theunassignedEarnings()
of that maturity have not been fully accrued. This means that although the earnings have been completely dripped because the maturity has ended, they will never be collected into the floating pool becauseclearBadDebt()
does not triggerPool.accrueEarnings()
for that maturity.Therefore, in this case, floating assets will incur a loss of earnings from that maturity, since the remaining
unassignedEarnings
of this maturity will still be greater than 0 but will never be accrued. There is no mitigation to claim it since there is no debt remaining in this maturity.See POC here
Impact
As hinted under Vulnerability Details & here, when
clearBadDebt()
is the last operation of a maturity after it ends, the remainingunassignedEarnings
in this maturity will never be accrued. Therefore, the floating pool will lose significant funds accrued from maturitiesCode Snippet
https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts/blob/3eb87e3edf3bcd57c4cc1c6a73e8255f575b76de/protocol/contracts/Market.sol#L637-L660
Tool used
Manual Review
Recommendation
Apply the fix suggested here, i.e the
clearBadDebt()
function should triggerPool.accrueEarnings()
for each maturity when clearing debt as follows:The text was updated successfully, but these errors were encountered: