executeIsolateLiquidate() totalBidAmout/availableLiquidity incorrect accounting
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:
- availableLiquidity += (totalBorrowAmount + totalExtraAmount)
- 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:
- availableLiquidity += (totalBorrowAmount + totalExtraAmount) = 100 + 20 = 120
- totalBidAmout -= totalBorrowAmount = 100
The correct value is:
- availableLiquidity += totalBorrowAmount = 100
- totalBidAmout -= (totalBorrowAmount - totalExtraAmount) = (100 - 20) = 80
Impact
- availableLiquidity adds extra totalExtraAmount, resulting in inaccurate borrowRate.
- 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
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.