Skip to content
Business logic Audit finding Intermediate

An attacker can manipulate `omniChainData.cdsPoolValue` by breaking protocol

The depositTokens function fails to update lastEthprice after a deposit, so each call recalculates profit and loss using a stale price. An attacker can repeatedly call depositTokens to inflate or deflate cdsPoolValue, potentially allowing borrowing when the protocol is undercollateralised or blocking borrowing and CDS withdrawals.

0x37 Follow with 0x73696d616f, 0xAristos and 12 others

Originally disclosed on Sherlock

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

Found by

0x37, 0x73696d616f, 0xAristos, CL001, Pablo, RampageAudit, almurhasan, gss1, newspacexyz, nuthan2x, onthehunt, super_jack, theweb3mechanic, tjonair, volodya

Summary

Missing update of lastEthprice in borrowing.sol#depositTokens() will cause manipulation of omniChainData.cdsPoolValue as an attaker replays borrowing.sol#depositTokens() by breaking protocol.

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

Root Cause

  • In borrowing.sol#depositTokens(), lastEthprice is not updated.
Solidity
    function depositTokens(
        BorrowDepositParams memory depositParam
    ) external payable nonReentrant whenNotPaused(IMultiSign.Functions(0)) {
        // Assign options for lz contract, here the gas is hardcoded as 400000, we got this through testing by iteration
        bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(400000, 0);
        // calculting fee
        MessagingFee memory fee = globalVariables.quote(
            IGlobalVariables.FunctionToDo(1),
            depositParam.assetName,
            _options,
            false
        );
        // Get the exchange rate for a collateral and eth price
        (uint128 exchangeRate, uint128 ethPrice) = getUSDValue(assetAddress[depositParam.assetName]);

        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);

        // Calling Omnichain send function
        globalVariables.send{value: fee.nativeFee}(
            IGlobalVariables.FunctionToDo(1),
            depositParam.assetName,
            fee,
            _options,
            msg.sender
        );
    }
  • In BorrowLib.sol:661, omniChainData is updated with new cdsPoolValue.
Solidity
    (ratio, omniChainData) = calculateRatio(
        params.depositingAmount,
        uint128(libParams.ethPrice),
        libParams.lastEthprice,
        omniChainData.totalNoOfDepositIndices,
        omniChainData.totalVolumeOfBorrowersAmountinWei,
        omniChainData.totalCdsDepositedAmount - omniChainData.downsideProtected,
        omniChainData
    );
    // Check whether the cds have enough funds to give downside prottection to borrower
    if (ratio < (2 * RATIO_PRECISION)) revert IBorrowing.Borrow_NotEnoughFundInCDS();
  • In BorrowLib.sol#calculateRatio(), cdsPoolValue is updated by difference between lastEthprice and currentEthprice.
Solidity
    function calculateRatio(
        uint256 amount,
        uint128 currentEthPrice,
        uint128 lastEthprice,
        uint256 noOfDeposits,
        uint256 totalCollateralInETH,
        uint256 latestTotalCDSPool,
        IGlobalVariables.OmniChainData memory previousData
    ) public pure returns (uint64, IGlobalVariables.OmniChainData memory) {
        uint256 netPLCdsPool;

        // Calculate net P/L of CDS Pool
        // if the current eth price is high
        if (currentEthPrice > lastEthprice) {
            // profit, multiply the price difference with total collateral
@>          netPLCdsPool = (((currentEthPrice - lastEthprice) * totalCollateralInETH) / USDA_PRECISION) / 100;
        } else {
            // loss, multiply the price difference with total collateral
@>          netPLCdsPool = (((lastEthprice - currentEthPrice) * totalCollateralInETH) / USDA_PRECISION) / 100;
        }

        uint256 currentVaultValue;
        uint256 currentCDSPoolValue;

        // Check it is the first deposit
        if (noOfDeposits == 0) {
            // Calculate the ethVault value
            previousData.vaultValue = amount * currentEthPrice;
            // Set the currentEthVaultValue to lastEthVaultValue for next deposit
            currentVaultValue = previousData.vaultValue;

            // Get the total amount in CDS
            // lastTotalCDSPool = cds.totalCdsDepositedAmount();
            previousData.totalCDSPool = latestTotalCDSPool;

            // BAsed on the eth prices, add or sub, profit and loss respectively
            if (currentEthPrice >= lastEthprice) {
@>              currentCDSPoolValue = previousData.totalCDSPool + netPLCdsPool;
            } else {
@>              currentCDSPoolValue = previousData.totalCDSPool - netPLCdsPool;
            }

            // Set the currentCDSPoolValue to lastCDSPoolValue for next deposit
@>          previousData.cdsPoolValue = currentCDSPoolValue;
@>          currentCDSPoolValue = currentCDSPoolValue * USDA_PRECISION;
        } else {
            // find current vault value by adding current depositing amount
            currentVaultValue = previousData.vaultValue + (amount * currentEthPrice);
            previousData.vaultValue = currentVaultValue;

            // BAsed on the eth prices, add or sub, profit and loss respectively
            if (currentEthPrice >= lastEthprice) {
                previousData.cdsPoolValue += netPLCdsPool;
            } else {
                previousData.cdsPoolValue -= netPLCdsPool;
            }
@>          previousData.totalCDSPool = latestTotalCDSPool;
@>          currentCDSPoolValue = previousData.cdsPoolValue * USDA_PRECISION;
        }

        // Calculate ratio by dividing currentEthVaultValue by currentCDSPoolValue,
        // since it may return in decimals we multiply it by 1e6
@>      uint64 ratio = uint64((currentCDSPoolValue * CUMULATIVE_PRECISION) / currentVaultValue);
        return (ratio, previousData);
    }

Internal pre-conditions

No response

External pre-conditions

  • Eth price changed a little from borrowing.sol#lastEthprice.

Attack Path

  • We say that current ratio is bigger than 2 * RATIO_PRECISION.
  • An attaker continues to replay borrowing.sol#depositTokens.
  • Then, omniChainData.cdsPoolValue continues to be increased or decreased.

Impact

  • In case of increasing, cdsPoolValue can be much bigger than normal. Then, borrowing is allowed even if protocol is really under water.
  • In case of decreasing, cdsPoolValue can be decreased so that ratio is small enough to touch (2 * RATIO_PRECISION). Then, borrowing can be DOSed even if cds have enough funds. And withdrawal from CDS can be DOSed.

PoC

No response

Mitigation

borrowing.sol#depositTokens() function has to be modified as follows.

Solidity
    function depositTokens(
        BorrowDepositParams memory depositParam
    ) external payable nonReentrant whenNotPaused(IMultiSign.Functions(0)) {
        // Assign options for lz contract, here the gas is hardcoded as 400000, we got this through testing by iteration
        bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(400000, 0);
        // calculting fee
        MessagingFee memory fee = globalVariables.quote(
            IGlobalVariables.FunctionToDo(1),
            depositParam.assetName,
            _options,
            false
        );
        // Get the exchange rate for a collateral and eth price
        (uint128 exchangeRate, uint128 ethPrice) = getUSDValue(assetAddress[depositParam.assetName]);

        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);
++      lastEthprice = ethPrice;

        // Calling Omnichain send function
        globalVariables.send{value: fee.nativeFee}(
            IGlobalVariables.FunctionToDo(1),
            depositParam.assetName,
            fee,
            _options,
            msg.sender
        );
    }

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 depositTokens function does not update the stored lastEthprice after using it, so repeated deposits keep applying profit and loss from the same stale price.

Impact

If cdsPoolValue is inflated, borrowing may be allowed even when the protocol is under water; if deflated, borrowing and CDS withdrawals can be blocked.

What the attacker needed

Eth price differs slightly from lastEthprice; Current ratio above 2 * RATIO_PRECISION

The fix

The depositTokens function should update lastEthprice to the current ethPrice after the deposit logic runs.

How it was found

  1. Ensure the current ratio is above the minimum threshold.
  2. Repeatedly call the depositTokens function.
  3. Observe that cdsPoolValue keeps increasing or decreasing with each call.

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 keeps track of the last Ethereum price it used to calculate profit and loss. When someone deposits, the contract should update that saved price, but it does not. Because the old price stays, anyone can call the deposit function over and over to make the contract's internal accounting drift, which can wrongly allow or block borrowing.

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.