Incorrect calculation of newCumulativeIndex
in function calcDecrease
#201
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
edited-by-warden
M-16
primary issue
Highest quality submission among a set of duplicates
🤖_70_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L652
Vulnerability details
In the contract
CDPVault.sol
, the functioncalcDecrease
calculatesnewCumulativeIndex
in line 703 whenamountToRepay < interestAccrued
withprofit
which is:https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L703
However, the
profit
constains thecumulativeQuotaInterest
, so it can not be used to calculatenewCumulativeIndex
.https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L668
For example, when the left amountToRepay can cover the
interestAccrued
, thenewCumulativeIndex
should becumulativeIndexNow
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 becumulativeQuotaInterest+interestAccrued - 1
. And the calculation ofnewCumulativeIndex
will be larger thancumulativeIndexNow
because thecumulativeQuotaInterest+interestAccrued - 1
will be larger thaninterestAccrued
which is totaly wrong, since it exceeds the limitcumulativeIndexNow
.https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L703
Impact
Position.cumulativeIndexLastUpdate will be updated with incorrect
newCumulativeIndex
.And less interest accrued will be charged from users. And the position which should be liquidated will not be liquidated due the the wrong Position.cumulativeIndexLastUpdate.
Proof of Concept
Paste this test in CDPVault.t.sol:
The poc result will be :
cumulativeIndexLastUpdate 1242341891861284810269427100
cumulativeIndexNow 1239397711761394368218295007
cumulativeIndexLastUpdate>cumulativeIndexNow
which is wrong
Tool used
Manual Review
Recommended Mitigation Steps
Use the code as below:
Assessed type
Other
The text was updated successfully, but these errors were encountered: