# Revert due to underflow error, leading to lock of the liquidated NFT

BendDAO isolate liquidation subtracts accrued borrowAmount (with interest) from totalBidAmount, underflowing and locking the winning liquidator's NFT.

- Payout: Audit contest
- Severity: high
- Program: BendDAO
- Found by: Ch\_301
- Disclosed: 2024-09-03
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-07-benddao-findings/issues/27
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-04
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** IsolateLogic/VaultLogic isolate auction liquidation
**Root cause:** executeIsolateLiquidate passes vars.totalBorrowAmount (which grows with interest over the auction) to erc20TransferOutBidAmountToLiqudity, subtracting it from assetData.totalBidAmout which only holds the bid amount; when interest makes borrowAmount exceed the bid, the subtraction underflows.
**Steps:**
1. Set up isolate loan on BAYC borrowing WETH; advance 365 days to accrue interest.
2. Drop NFT price to 5000; liquidator1 bids 20561005318463975387 WETH as first bidder (wins auction).
3. advanceTimes(25 hours) so borrowAmount accrues past the bid amount.
4. Call isolateLiquidate(...) -> reverts with arithmetic underflow at `assetData.totalBidAmout -= amount`.
**How found:** Code reading of executeIsolateLiquidate: noticed totalBidAmout is only incremented by bid amount at auction time, while liquidation subtracts totalBorrowAmount which keeps accruing interest during the up-to-7-day auction, so the two diverge.
**Exploitation:** Liquidator wins auction and pays bid into escrow, but on isolateLiquidate the borrowAmount (scaledAmount * normalizedIndex, inflated by interest) exceeds totalBidAmout, so the subtraction reverts; the NFT cannot be unlocked/withdrawn by the winner.
**Insight:** In auction/liquidation accounting, check that the value subtracted at settlement is the same quantity that was added at bid time; interest-accruing debt vs fixed bid escrow is a classic underflow/lock vector.

## Proof of concept (copied exactly from the original report)

**Foundry PoC test causing underflow revert**

```
function test_POC_Should_LiquidateWETH() public {
  TestCaseLocalVars memory testVars;

  // deposit
  prepareWETH(tsDepositor1);
  uint256[] memory tokenIds = prepareIsolateBAYC(tsBorrower1);

  // borrow
  prepareBorrow(tsBorrower1, address(tsBAYC), tokenIds, address(tsWETH));

  // make some interest
  advanceTimes(365 days);

  // drop down nft price
  actionSetNftPrice(address(tsBAYC), 5000);

  //?1- first bidder wins the auction
  // auction
  tsLiquidator1.approveERC20(address(tsWETH), type(uint256).max);

  uint256[] memory bidAmounts = new uint256[](tokenIds.length);

  for (uint256 i = 0; i < tokenIds.length; i++) {
    bidAmounts[i] = 20561005318463975387;
  }

  tsLiquidator1.isolateAuction(tsCommonPoolId, address(tsBAYC), tokenIds, address(tsWETH), bidAmounts);

  //?2- wait and accumulate interest until the borrowed amount exceeds the winner's bid price
  // end the auction
  advanceTimes(25 hours);

  uint256[] memory liquidateAmounts = new uint256[](tokenIds.length);

  //?3- call `isolateLiquidate()` should revert
  // liquidate
  vm.expectRevert(stdError.arithmeticError);
  tsLiquidator1.isolateLiquidate(tsCommonPoolId, address(tsBAYC), tokenIds, address(tsWETH), liquidateAmounts, false);
}
```

