The usage index returned by ReserveLibrary::calculateUsageIndex() is wrong because of incorrect usage of the WadRayMath library.
The function ReserveLibrary::calculateUsageIndex() calls ReserveLibrary::calculateCompoundedInterest() to calculate the interestFactor by using WadRayMath::rayDiv() and WadRayMath::rayMul() with values which are not scaled to RAY.
If both SECONDS_PER_YEAR and time delta are not properly scaled to RAY(1e27) this discrepancy will eventually cancel out. The issue is that it "cancels out" when calculating the exponent using rayMul(), but in the intermediate step (calculating ratePerSecond using rayDiv()) the result of division is rounded up. This rounding up happens on the incorrectly scaled intermediate result.
ratePerSecond will be rounded up at the wrong position as the WadRayMath library is supposed to work with RAY values resulting in inflated usageIndex values. Since exponent is calculated as the ratePerSecond multiplied by the timeDelta this difference will be proportional to the amount of time passed from the last update.
set up:
run npm install and add .env file if you haven't already
npm i --save-dev @nomicfoundation/hardhat-foundry - Install the hardhat-foundry plugin.
Add require("@nomicfoundation/hardhat-foundry"); to the top of your hardhat.config.js file.
Run npx hardhat init-foundry in your terminal. This will generate a foundry.toml file based on your Hardhat project’s existing configuration, and will install the forge-std library.
mkdir test/foundry
Create *.t.sol file inside /test/foundry and paste the POC inside.
In foundry.toml update test = 'test/foundry'
running test:
forge test --match-test testCalculateCompoundedInterest -vv
Manual review
Scale the SECONDS_PER_YEAR and timeDelta values that are being used in ReserveLibrary::calculateCompoundedInterest() to 1e27(RAY)
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.