Skip to content
Business logic Audit finding Intermediate

executeIsolateLiquidate() totalBidAmout/availableLiquidity incorrect accounting

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen, also found by oakcobalt (1, 2) and SpicyMeatball (1, 2)

Code reference: IsolateLogic.sol#L499

When executeIsolateLiquidate() is executed, it will account totalBidAmout/availableLiquidity.

The main accounting code is as follows:

    function executeIsolateLiquidate(InputTypes.ExecuteIsolateLiquidateParams memory params) internal {
...

        InterestLogic.updateInterestRates(poolData, debtAssetData, vars.totalBorrowAmount, 0);

        if (vars.totalExtraAmount > 0) {
            // transfer underlying asset from caller to pool
@>          VaultLogic.erc20TransferInLiquidity(debtAssetData, params.msgSender, vars.totalExtraAmount);
        }

        // bid already in pool and now repay the borrow but need to increase liquidity
@>      VaultLogic.erc20TransferOutBidAmountToLiqudity(debtAssetData, vars.totalBorrowAmount);

        // transfer erc721 to winning bidder
        if (params.supplyAsCollateral) {
            VaultLogic.erc721TransferIsolateSupplyOnLiquidate(
                nftAssetData,
                vars.winningBidder,
                params.nftTokenIds,
                true
            );
        } else {
            VaultLogic.erc721DecreaseIsolateSupplyOnLiquidate(nftAssetData, params.nftTokenIds);

            VaultLogic.erc721TransferOutLiquidity(nftAssetData, vars.winningBidder, params.nftTokenIds);
        }

function erc20TransferInLiquidity(DataTypes.AssetData storage assetData, address from, uint256 amount) internal {
        address asset = assetData.underlyingAsset;
        uint256 poolSizeBefore = IERC20Upgradeable(asset).balanceOf(address(this));

@>      assetData.availableLiquidity += amount;

        IERC20Upgradeable(asset).safeTransferFrom(from, address(this), amount);

        uint256 poolSizeAfter = IERC20Upgradeable(asset).balanceOf(address(this));
        require(poolSizeAfter == (poolSizeBefore + amount), Errors.INVALID_TRANSFER_AMOUNT);
    }

    function erc20TransferOutBidAmountToLiqudity(DataTypes.AssetData storage assetData, uint amount) internal {
        require(assetData.totalBidAmout >= amount, Errors.ASSET_INSUFFICIENT_BIDAMOUNT);
@>      assetData.totalBidAmout -= amount;

@>      assetData.availableLiquidity += amount;
    }

We know from the above code that the current formula is as follows:

  1. availableLiquidity += (totalBorrowAmount + totalExtraAmount)
  2. totalBidAmout -= totalBorrowAmount

Both of these accounting errors. TotalExtraAmount is calculated twice.totalBorrowAmount already contains totalExtraAmount.

Example: Suppose: total Borrow Amount = 100 , Actual Bid Amout = 80 So: total Extra Amount = 20

but in the current algorithm:

  1. availableLiquidity += (totalBorrowAmount + totalExtraAmount) = 100 + 20 = 120
  2. totalBidAmout -= totalBorrowAmount = 100

The correct value is:

  1. availableLiquidity += totalBorrowAmount = 100
  2. totalBidAmout -= (totalBorrowAmount - totalExtraAmount) = (100 - 20) = 80

Impact

  1. availableLiquidity adds extra totalExtraAmount, resulting in inaccurate borrowRate.
  2. totalBidAmout underflow, which makes it impossible to liquidate.

Recommended Mitigation

    function executeIsolateLiquidate(InputTypes.ExecuteIsolateLiquidateParams memory params) internal {
...

        InterestLogic.updateInterestRates(poolData, debtAssetData, vars.totalBorrowAmount, 0);

        if (vars.totalExtraAmount > 0) {
            // transfer underlying asset from caller to pool
            VaultLogic.erc20TransferInLiquidity(debtAssetData, params.msgSender, vars.totalExtraAmount);
        }

        // bid already in pool and now repay the borrow but need to increase liquidity
-       VaultLogic.erc20TransferOutBidAmountToLiqudity(debtAssetData, vars.totalBorrowAmount);
+       VaultLogic.erc20TransferOutBidAmountToLiqudity(debtAssetData, vars.totalBorrowAmount - vars.totalExtraAmount );

thorseldon (BendDAO) confirmed and commented:

Fixed in commit 18a4b84


The original report as published on Code4rena, by bin2chen. 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.

What is known

A high-severity business logic bug in BendDAO Invitational. Code4rena made it public on 22 January 2025. Found in the 2024-12-benddao-invitational audit contest (finding H-01).

About Business logic

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 bin2chen

View all

139 more disclosed reports, best first.

More from BendDAO Invitational

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.