Submitted by hearmen, also found by boraichodrunkenmaster, emerald7017, chaduke, 0xBugSlayer, thisvishalsingh, joaovwfreire, 0xpiken, Chinmay, hash, and pkqs90
In the contract CDPVault.sol, the function calcDecrease calculates newCumulativeIndex in line 703 when amountToRepay < interestAccrued with profit which is:
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L703
However, the profit contains the cumulativeQuotaInterest, so it can not be used to calculate newCumulativeIndex.
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L668
For example, when the left amountToRepay can cover the interestAccrued, the newCumulativeIndex should be cumulativeIndexNow as in line 692, because: interestAccrued == (debt * cumulativeIndexNow) / cumulativeIndexLastUpdate - debt.
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L692
However, when the left amountToRepay = interestAccrued - 1, and profit will be cumulativeQuotaInterest+interestAccrued - 1. The calculation of newCumulativeIndex will be larger than cumulativeIndexNow because the cumulativeQuotaInterest+interestAccrued - 1 will be larger than interestAccrued which is totally wrong, since it exceeds the limit
cumulativeIndexNow.
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L703
Position.cumulativeIndexLastUpdate will be updated with incorrect newCumulativeIndex and less interest accrued will be charged from users. The position which should be liquidated will not be liquidated due the the wrong Position.cumulativeIndexLastUpdate.
Paste this test in CDPVault.t.sol:
The poc result will be:
 which is wrong.
Use the code as below:
Other
0xtj24 (LoopFi) confirmed and commented:
