Skip to content
Smart contracts Audit finding Advanced

utilization for _getInterestRate() does not factor in interest

The utilization figure used to set the interest rate is computed before accrued interest is added to the total borrow amount, so the new interest rate is based on a stale, understated utilization. This can produce incorrect interest rates and may let utilization appear to exceed the maximum target threshold.

ItsNio Follow with ItsNio and SaeedAlipoor01988

Originally disclosed on Code4rena

Submitted by ItsNio, also found by ItsNio and SaeedAlipoor01988

The calculation for utilization in _getInterestRate() does not factor in the accrued interest. This leads to _accrueInfo.interestPerSecond being under-represented, and leading to incorrect interest rate calculation and potentially endangering conditions such as utilization > maximumTargetUtilization on line 124.

Proof of Concept

The calculation for utilization in the _getInterestRate() function for SGLCommon.sol occurs on lines 61-64 as a portion of the fullAssetAmount (which is also problematic) and the _totalBorrow.elastic. However, _totalBorrow.elastic is accrued by interest on line 99. This accrued amount is not factored into the calculation for utilization, which will be used to update the new interest rate, as purposed by the comment on line 111.

Recommended Mitigation Steps

Factor in the interest accrual into the utilization calculation:

...
        // Accrue interest
        extraAmount =
            (uint256(_totalBorrow.elastic) *
                _accrueInfo.interestPerSecond *
                elapsedTime) /
            1e18;
        _totalBorrow.elastic += uint128(extraAmount);

    +    uint256 fullAssetAmount = yieldBox.toAmount(
    +        assetId,
    +        _totalAsset.elastic,
    +        false
    +    ) + _totalBorrow.elastic;
        //@audit utilization factors in accrual
    +    utilization = fullAssetAmount == 0
    +   ? 0
    +        : (uint256(_totalBorrow.elastic) * UTILIZATION_PRECISION) /
    +        fullAssetAmount;
...

0xRektora (Tapioca) confirmed


The original report as published on Code4rena, by ItsNio. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the utilization is calculated from the borrow total before the accrued interest is added to it, so the rate update uses a stale value.

Impact

Interest rates could be calculated incorrectly and utilization could appear to exceed the maximum target threshold, though the text does not show a concrete loss.

What the attacker needed

None

The fix

The utilization calculation should be moved after interest accrual so it includes the accrued amount.

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 lending contract sets its interest rate based on how much of the pool is borrowed (utilization). Before recalculating the rate, it adds newly earned interest to the amount owed, but it then works out utilization using the old figure, so the rate is set from out-of-date numbers. The result is that borrowers may be charged the wrong rate.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by ItsNio

View all

2 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.