When setting a new prime rate it calculates the liquidity and usage indexes using a delta of time that belongs to the old prime rate.
When the oracle sets a new prime rate in LendingPool.sol#setPrimeRate
it calls the ReserveLibrary.setPrimeRate
function that actually sets the new prime and then in ReserveLibrary#updateInterestRatesAndLiquidity
calculates using the new prime the rateData.currentUsageRate
and the rateData.currentLiquidityRate
fields what will be used in the ReserveLibrary#updateReserveInterests
function to calculate the new liquidity and usage indexes but the problem is that the indexes use a delta of time between the last update and the current block, check the following code: uint256 timeDelta = block.timestamp - uint256(reserve.lastUpdateTimestamp);
The delta of time is really important here because the problem is that is doing the updating of indexes with the new prime rate but the delta of time belongs to the previous old prime rate, that is because it should call reserve#updateReserveInterests
before setting the new prime rate, but it is not doing it.
The incorrect calculation of the liquidity and usage index will impact almost every important function of the lending pool,
Operation | Reason |
---|---|
Borrow | Mixed usageIndex |
Repay | Mixed usageIndex |
Liquidation | Mixed Both usageIndex and liquidationIndex |
Deposit | Mixed liquidityIndex |
Withdraw | Mixed liquidityIndex |
withdrawNFT | Mixed usageIndex |
VS Code
In order to calculate properly the indexes first calculate using the old prime and then set the new one, so the delta of time will be fresh:
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.