Skip to content
Business logic Audit finding Intermediate

leverageStrategy will revert due users interest rate accrual

The leverageStrategy function checks that a user's principal borrow amount increases by exactly the new borrow amount, but the principal also grows from accrued interest, so the check fails. As a result, the leverageStrategy function reverts almost always, blocking users from using it.

KupiaSec Follow with jokr

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-numa-audit-judging/issues/120

Found by

KupiaSec, jokr

Summary

In the CNumaToken.leverageStrategy() function, after borrowing from the market using the borrowInternalNoTransfer function, a check is performed to ensure that the user's borrow amount changes only by borrowAmount using a require statement. However, this check will fail because the user's principal borrow amount will increase by more than borrowAmount due to the interest accrued on the user's borrow position.

Root Cause

Solidity
uint accountBorrowBefore = accountBorrows[msg.sender].principal;
// Borrow but do not transfer borrowed tokens
borrowInternalNoTransfer(borrowAmount, msg.sender);
// uint accountBorrowAfter = accountBorrows[msg.sender].principal;

require(
    (accountBorrows[msg.sender].principal - accountBorrowBefore) == 
        borrowAmount,
    "borrow ko"
);

https://github.com/sherlock-audit/2024-12-numa-audit/blob/main/Numa/contracts/lending/CNumaToken.sol#L196-L204

The require statement above will always fail since the user's previous borrow amount accrues interest, causing the principal borrow amount to increase beyond borrowAmount.

Even if the global interest rate index is updated, the user's borrow position will only accrue interest when their borrow position is touched as below.

Solidity
    function borrowBalanceStoredInternal(
        address account
    ) internal view returns (uint) {
        /* Get borrowBalance and borrowIndex */
        BorrowSnapshot storage borrowSnapshot = accountBorrows[account];

        /* If borrowBalance = 0 then borrowIndex is likely also 0.
         * Rather than failing the calculation with a division by 0, we immediately return 0 in this case.
         */
        if (borrowSnapshot.principal == 0) {
            return 0;
        }

        /* Calculate new borrow balance using the interest index:
         *  recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex
         */
        uint principalTimesIndex = borrowSnapshot.principal * borrowIndex;
        return principalTimesIndex / borrowSnapshot.interestIndex;
    }

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. Suppose the user has an existing borrow amount of 100. Hence, accountBorrows[msg.sender].principal = 100.
  2. The user calls the leverageStrategy function to borrow an additional 50 from the market.
  3. During the borrowing process, interest will accrue on the existing borrow amount. For example, the principal borrow amount will increase to 150.2 (existing borrow = 100, new borrow = 50, accrued interest = 0.2).
  4. The require statement (accountBorrows[msg.sender].principal - accountBorrowBefore) == borrowAmount will then fail because the principal borrow amount includes the accrued interest, making the difference greater than borrowAmount.

Impact

leverageStrategy function will fail almost always.

PoC

No response

Mitigation

Instead of directly fetching the user's previous borrow amount from the state using accountBorrows[msg.sender].principal, use the borrowBalanceStored() function. This function accounts for accrued interest and provides the correct previous borrow balance, ensuring that the require statement works as intended.

Diff
- uint accountBorrowBefore = accountBorrows[msg.sender].principal;
+ uint accountBorrowBefore = borrowBalanceStored(msg.sender);

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

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 code compares the raw stored principal, which does not include accrued interest, against the new borrow amount, so any accrued interest makes the difference larger than expected.

Impact

The leverageStrategy function will fail almost always, preventing users from using it.

What the attacker needed

User has an existing borrow position; interest has accrued on that position

The fix

The previous borrow amount should be read using borrowBalanceStored, which includes accrued interest, instead of the raw principal.

How it was found

  1. The user has an existing borrow amount of 100, so the stored principal is 100.
  2. The user calls leverageStrategy to borrow an additional 50.
  3. Interest accrues on the existing borrow, making the principal increase to more than 150.
  4. The require statement checks that the principal difference equals the new borrow amount, but it is larger, so the transaction reverts.

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.

When someone borrows money in this lending system, the amount they owe slowly grows because of interest. The code tries to confirm that a new borrow only adds the new amount, but it forgets that interest has already made the old amount bigger. So the check fails and the borrowing feature stops working.

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.

More by KupiaSec

View all

28 more disclosed reports, best first.

More from Numa

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.