In DebtToken.sol, _userState[user].index isn't deleted when user is making a full repayment or the position is finalized with liquidation. This could lead to unwanted balanceIncrease when the user is making a new borrow from scratch again in the future.
A user is typically minted the extra balanceIncrease of debt tokens on top of the inputted amount when making the second or subsequent borrow on an existing position via the delta of indices multiplied by the user's balance. The logic will also have _userState[onBehalfOf].inde assigned the latest index.
Likewise, when it comes to burning of the debt tokens, _userState[from].index is correctly assigned the latest index if this entails a partial repayment. However, the function logic fails to delete or reset the index when it involves a full repayment or the finalization of a liquidation:
Consequently, when the same user were to come back and start a new borrow after a long time, instead of being minted the inputted amount, an excessive amount of balanceIncrease would be added to amountToMint. This is because _userState[onBehalfOf].index != 0 and that _userState[onBehalfOf].index is significantly or much smaller than the latest index this time.
In the end, like I have reported separately, totalSupply() will also be inflated significantly prior to getting itself assigned to reserve.totalUsage.
In the end, when updateInterestRatesAndLiquidity() is invoked,
utilizationRate, and hence rateData.currentUsageRate and rateData.currentLiquidityRate are going to be correspondingly inflated more than intended.
And, finally, the frequently referenced reserve.liquidityIndex and reserve.usageIndex will be inflated more than intended too via updateReserveInterests(), causing advantaged lending at the expense of disadvantaged borrowing.
Not deleting _userState[user].index when necessary could lead to a series of cascading effects, creating systemic imbalances. Although lenders benefit from the inflated liquidity index, borrowers would be prone to liquidation due to faster rate of debt piling associated with the inflated usage index.
Manual
Consider implementing a permissioned logic that will only allow the Lending Pool to delete _userState[user].index when user.scaledDebtBalance has be reduced to zero or less than DUST_THRESHOLD.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.