The prime rate, a key factor in determining borrowing and lending rates, is updated by an admin-triggered Chainlink function. However, when the prime rate is changed, the liquidityIndex and usageIndex are updated incorrectly due to a missing state update before the new rate is applied.
This results in incorrect interest accrual calculations, affecting both borrowers and lenders, and leading to potential financial discrepancies.
The primeRate can be changed when the admin request is fulfilled by Chainlink Functions. The response is processed in _processResponse hook calling the lendingPool.setPrimeRate with the new prime rate. The ReserveLibrary.setPrimeRate is invoked, which:
directly updates the rateData.primeRate
calls updateInterestRatesAndLiquidity, which :
i. computes new borrow (currentUsageRate) and liquidity (currentLiquidityRate) rates based on the new prime rate.
ii. calls updateReserveInterests(), which updates liquidityIndex and usageIndex.
The liquidityIndex and usageIndex represent the accumulated interest for lenders and borrowers over time. These values should be updated before applying a new prime rate, ensuring that past interest accruals are calculated correctly.
However, in the current implementation, the new prime rate is applied before the indexes are updated.
Interest accrual uses timeDelta = block.timestamp - lastUpdateTimestamp.
If a prime rate update occurs after a long delay, it retroactively applies to the entire timeDelta, distorting historical interest calculations.
This disproportionately affects borrowers and lenders depending on whether the new prime rate is higher or lower.
Incorrect borrower debt accumulation:
If the prime rate increased, borrowers pay more than they should for past interest accruals.
If the prime rate decreased, borrowers pay less than they should, leading to protocol revenue loss.
Incorrect lender (LP) yield calculations
Lenders (LPs) receive incorrect yield allocations, which could distort APY calculations.
Before applying the new prime rate, update the liquidity and usage indexes first to correctly reflect historical interest accruals.
This ensures that:
Old prime rate is used to finalize past interest accruals.
New prime rate takes effect only after updating historical indexes.
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.