In the LendingPool contract, both _repay and finalizeLiquidation functions incorrectly handle the return values from DebtToken's burn function, specifically interchanging amountScaled and amountBurned. This causes the wrong amount of underlying asset (crvUSD) to be transferred to the lending pool during debt repayment and liquidation processes.
The issue stems from the mishandling of return values from the DebtToken's burn function in two critical operations: debt repayment and liquidation.
Let's look at how DebtToken's burn function works:
The burn function returns four values in this order:
amount: The amount of DebtTokens (amount burned)
totalSupply: The new total supply after burning
amountScaled: The scaled amount (amount/index)
balanceIncrease: Any increase in balance due to interest
However, in the LendingPool's _repay function:
The same issue exists in finalizeLiquidation:
The issue arises because:
The return values are incorrectly mapped - amountScaled is capturing the original amount, while amountBurned is capturing the scaled amount
The asset transfer uses amountScaled (which actually contains the original amount) instead of the properly scaled amount
This leads to incorrect asset transfers during both repayment and liquidation processes
Incorrect amount of assets being transferred during debt repayments and liquidations
Protocol accounting becomes inaccurate
Liquidations may transfer wrong amounts, affecting both the protocol and users
Manual Review
Correct the parameter interchange in both _repay and finalizeLiquidation functions:
Interest IS applied through the balanceOf() mechanism. The separate balanceIncrease calculation is redundant/wrong. Users pay full debt including interest via userBalance capping.
Interest IS applied through the balanceOf() mechanism. The separate balanceIncrease calculation is redundant/wrong. Users pay full debt including interest via userBalance capping.
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.