Fix utilization rate computation
The utilization rate calculation in a smart contract can return a value greater than 1 when reserves exceed cash, because the formula does not handle that case. This could lead to incorrect interest rate calculations.
SaeedAlipoor01988 Follow with lanrebayode77
Originally disclosed on Code4rena
Submitted by SaeedAlipoor01988, also found by lanrebayode77.
The BaseJumpRateModelV2.sol#L131.utilizationRate() function can return a value above 1 and not between [0, BASE].
Proof of Concept
In the BaseJumpRateModelV2.sol#L131.utilizationRate() function, cash and borrows and reserves values get used to calculate the utilization rate between [0, 1e18]. Reserves are currently unused but it will be used in the future.
*/
function utilizationRate(
uint256 cash,
uint256 borrows,
uint256 reserves
) public pure returns (uint256) {
// Utilization rate is 0 when there are no borrows
if (borrows == 0) {
return 0;
}
return (borrows * BASE) / (cash + borrows - reserves);
}
If the borrow value is 0, then the function will return 0, but in this function, the scenario where the value of reserves exceeds cash is not handled. The system does not guarantee that reserves never exceed cash. The reserves grow automatically over time, so it might be difficult to avoid this entirely.
If reserves > cash (and borrows + cash - reserves > 0), the formula for utilizationRate above gives a utilization rate above 1.
Recommended Mitigation Steps
Make the utilization rate computation return 1 if reserves > cash.
Assessed type
Math
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The function does not handle the case where reserves exceed cash, so the denominator can become smaller than borrows, producing a utilization rate above 1.
Impact
The utilization rate could exceed 1, leading to incorrect interest rate calculations, though the text does not specify the exact consequence.
What the attacker needed
Reserves exceed cash
The fix
The utilization rate computation should return 1 if reserves > cash.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract calculates how much of the available money is borrowed, called the utilization rate. The formula divides total borrows by the cash plus borrows minus reserves. If reserves become larger than cash, the denominator becomes smaller than expected, so the result can be bigger than 1, which is not a valid percentage. This could make interest rates wrong.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.