Petite Porcelain Scorpion
Medium
The missing check in setBorrowingRateConfig
will cause an unexpected nonzero interest rate at zero utilization for borrowers as an admin can set utilizationA
to 0
In calculateBorrowingRate
there is no validation to ensure the borrowing rate is 0 when utilizationRate is also 0
If the Admin
sets utilizationA
to 0, when he is configuring the borrowing rate, if we have utilizationRate
of 0 and utilizationA
is 0 (as set by the admin), we will return borrowingRateA
when it should be 0.
- Admin sets
utilizationA
to 0 in the borrowing rate configuration. - Reserve utilization is 0%.
No external conditions are required since this vulnerability is due solely to an internal misconfiguration.
- Admin calls
setBorrowingRateConfig
withutilizationA
set to 0. - The system initializes the reserve with a nonzero
borrowingRateA
. - When utilization is 0, the
calculateBorrowingRate
function returnsborrowingRateA
instead of 0, causing unexpected interest accrual.
The borrowers suffer unexpected interest charges even when no funds are borrowed, which may lead to increased costs and user dissatisfaction.
function test_calculateBorrowingRate_returns_borrowingRateA_when_utilizationRate_is_0() public {
// Set up the interest rate configuration with utilizationA = 0.
// This misconfiguration should cause the function to return borrowingRateA even at 0% utilization.
configStorage = DataTypes.InterestRateConfig({
borrowingRateA: 0.05e27,
utilizationA: 0,
borrowingRateB: 0.1e27,
utilizationB: 0.5e27,
maxBorrowingRate: 0.2e27
});
uint256 utilizationRate = 0;
uint256 result = InterestRateUtils.calculateBorrowingRate(configStorage, utilizationRate);
// Expected behavior: at 0% utilization, the borrowing rate should be 0.
// Actual behavior: returns borrowingRateA (0.05e27) because utilizationA is 0.
assertEq(result, configStorage.borrowingRateA);
}
Add a validation check in setBorrowingRateConfig
to ensure that utilizationA
is greater than 0. Alternatively, modify calculateBorrowingRate
to return 0 when the utilization rate is 0, regardless of configuration.