Skip to content
Business logic Audit finding Intermediate

Inconsistent Use of `lastCumulativeRate` in `depositTokens()` and `withdraw()` Functions in `Borrowings` Contract

The depositTokens() and withdraw() functions in the Borrowings contract use the stored lastCumulativeRate before updating it via calculateCumulativeRate(), so the first transaction after a time gap uses an outdated interest rate. This can cause incorrect interest calculations and discrepancies in normalized deposit amounts and borrower debt.

0x37 Follow with 0x73696d616f, 0xAadi and 13 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/961

Found by

0x37, 0x73696d616f, 0xAadi, Cybrid, EgisSecurity, John44, LZ_security, OrangeSantra, Pablo, RampageAudit, Ruhum, almurhasan, gss1, pashap9990, super_jack, t.aksoy

Summary

The depositTokens() and withdraw() functions in the Borrowing contract exhibit inconsistent use of the lastCumulativeRate. This inconsistency arises because the lastCumulativeRate is used in calculations before it is updated, leading to potential inaccuracies in interest calculations among multiple transactions.

Root Cause

In both depositTokens() and withdraw() functions, lastCumulativeRate is passed to BorrowLib.deposit() and BorrowLib.withdraw() respectively, before calling calculateCumulativeRate() to update it.

Solidity
        totalNormalizedAmount = BorrowLib.deposit(
            BorrowLibDeposit_Params(
                LTV,
                APR,
@>              lastCumulativeRate,
                totalNormalizedAmount,
                exchangeRate,
                ethPrice,
                lastEthprice
            ),
            depositParam,
            Interfaces(treasury, globalVariables, usda, abond, cds, options),
            assetAddress
        );

        //Call calculateCumulativeRate() to get currentCumulativeRate
@>      calculateCumulativeRate();
        lastEventTime = uint128(block.timestamp);

https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/Core_logic/borrowing.sol#L241C1-L254C11

Solidity
        BorrowWithdraw_Result memory result = BorrowLib.withdraw(
            depositDetail,
            BorrowWithdraw_Params(
                toAddress,
                index,
                ethPrice,
                exchangeRate,
                withdrawTime,
                lastCumulativeRate,
                totalNormalizedAmount,
                bondRatio,
                collateralRemainingInWithdraw,
                collateralValueRemainingInWithdraw
            ),
            Interfaces(treasury, globalVariables, usda, abond, cds, options)
        );
.
.
        lastEventTime = uint128(block.timestamp);}

        // Call calculateCumulativeRate function to get the interest
@>      calculateCumulativeRate();

https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/Core_logic/borrowing.sol#L649C1-L664C11

And the lastCumulativeRate is used to calculate normalizedAmount and borrowerDebt

Solidity
        // Calculate normalizedAmount
        uint256 normalizedAmount = calculateNormAmount(tokensToMint, libParams.lastCumulativeRate);

https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/lib/BorrowLib.sol#L749C1-L750C100

Solidity
            // Calculate th borrower's debt
            uint256 borrowerDebt = calculateDebtAmount(depositDetail.normalizedAmount, params.lastCumulativeRate);

https://github.com/sherlock-audit/2024-11-autonomint/blob/main/Blockchain/Blockchian/contracts/lib/BorrowLib.sol#L824C1-L825C115

This results in using an outdated cumulative rate for the first transaction, while subsequent transactions use the updated rate, causing discrepancies.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. Allow a significant time gap since the last transaction to accumulate interest.
  2. Execute two simultaneous transactions (e.g., deposits or withdrawals).
  3. Observe that the first transaction uses an outdated lastCumulativeRate, while the second uses the updated rate.

Impact

The first transaction uses an outdated cumulative rate, while subsequent transactions use the updated cumulative rate, leading to incorrect interest calculations. This discrepancy causes inconsistencies in the normalized deposit amount and borrower debt, potentially affecting the protocol's financial accuracy .

PoC

No response

Mitigation

Ensure that calculateCumulativeRate() is called at the beginning of both the depositTokens() and withdraw() functions to update lastCumulativeRate before it is used in any calculations. This ensures that all transactions use the most current cumulative rate.

The original report as published on Sherlock, by 0x37. 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

Likely the functions call BorrowLib.deposit() and BorrowLib.withdraw() with the stored lastCumulativeRate before calling calculateCumulativeRate() to refresh it.

Impact

The first transaction uses an outdated cumulative rate, potentially causing incorrect interest calculations and inconsistencies in normalized deposit amounts and borrower debt.

What the attacker needed

A significant time gap since last transaction; two simultaneous transactions

The fix

calculateCumulativeRate() should be called at the beginning of both depositTokens() and withdraw() to update lastCumulativeRate before it is used.

How it was found

  1. Allow a significant time gap since the last transaction to accumulate interest.
  2. Execute two simultaneous transactions (e.g., deposits or withdrawals).
  3. Observe that the first transaction uses an outdated lastCumulativeRate, while the second uses the updated rate.

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.

In a lending protocol, interest builds up over time and is tracked by a cumulative rate. The contract updates this rate only after using it, so the first action after a pause uses old interest data, which can make the numbers slightly 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.

More by 0x37

View all

79 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

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.