# Major insolvency risk in LiquidationLogic::executeCrossLiquidateERC721() due to not setting a maximum liquidation price

BendDAO's cross ERC721 liquidation derives NFT price from debt/collateral count with no cap, so after a price drop liquidators must overpay and skip liquidation, risking bad debt.

- Payout: Audit contest
- Severity: medium
- Program: BendDAO
- Found by: 0x73696d616f
- Disclosed: 2024-09-03
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-benddao-findings/issues/22
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AM-13
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:liquidation

**Target:** LiquidationLogic::executeCrossLiquidateERC721() / _calculateDebtAmountFromERC721Collateral()
**Root cause:** The per-NFT liquidation price is computed as debt divided by collateral token count with no upper bound, so a debt increase or NFT price crash inflates the implied price above market.
**Steps:**
1. Borrow USDT against BAYC collateral via actionCrossBorrowERC20.
2. Advance 365 days to accrue interest.
3. Drop BAYC oracle price to 60% via setAssetPrice, pushing healthFactor below 1e18.
4. Call tsPoolLens.getUserCrossLiquidateData to read actualDebtToLiquidate and actualCollateralToLiquidate.
5. Observe debtValue is 112% of collateralValue, making liquidation unprofitable.
6. Liquidator calling actionCrossLiquidateERC721 takes a loss; partial liquidation still uses the same inflated price.
**How found:** Code reading of _calculateDebtAmountFromERC721Collateral noticed the NFT price is derived by dividing debt by collateral count without a cap, then a Foundry PoC simulated an interest accrual plus 60% price drop to show debt exceeds collateral value.
**Exploitation:** No attacker profit path; the flaw is that liquidators rationally decline to liquidate underwater positions because the computed per-NFT price exceeds market, leaving bad debt to the protocol.
**Insight:** In NFT-collateral lending, check whether the liquidation price is derived from debt/collateral ratio rather than an oracle cap; if uncapped, a price crash makes liquidation unprofitable and partial liquidation won't help since the same inflated unit price applies.

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

**Foundry test proving inflated NFT liquidation price**

```
function test_POC_RepayUSDT_HasBAYC_InflatedPrice() public {
  prepareUSDT(tsDepositor1);

  uint256[] memory depTokenIds = prepareCrossBAYC(tsBorrower1);

  TestUserAccountData memory accountDataBeforeBorrow = getUserAccountData(address(tsBorrower1), tsCommonPoolId);

  // borrow some eth
  uint8[] memory borrowGroups = new uint8[](1);
  borrowGroups[0] = tsLowRateGroupId;

  uint256[] memory borrowAmounts = new uint256[](1);
  borrowAmounts[0] =
    (accountDataBeforeBorrow.availableBorrowInBase * (10 ** tsUSDT.decimals())) /
    tsPriceOracle.getAssetPrice(address(tsUSDT));

  actionCrossBorrowERC20(
    address(tsBorrower1),
    tsCommonPoolId,
    address(tsUSDT),
    borrowGroups,
    borrowAmounts,
    new bytes(0)
  );

  // make some interest
  advanceTimes(365 days);

  // drop down price and lower health factor
  uint256 baycCurPrice = tsBendNFTOracle.getAssetPrice(address(tsBAYC));
  uint256 baycNewPrice = (baycCurPrice * 60) / 100;
  tsBendNFTOracle.setAssetPrice(address(tsBAYC), baycNewPrice);

  TestUserAccountData memory accountDataAfterBorrow = getUserAccountData(address(tsBorrower1), tsCommonPoolId);
  assertLt(accountDataAfterBorrow.healthFactor, 1e18, 'ACC:healthFactor');

  (uint256 actualCollateralToLiquidate, uint256 actualDebtToLiquidate) = tsPoolLens.getUserCrossLiquidateData(
    tsCommonPoolId,
    address(tsBorrower1),
    address(tsBAYC),
    1,
    address(tsUSDT),
    0
  );

  uint256 tsBAYCprice = tsPriceOracle.getAssetPrice(address(tsBAYC));
  uint256 tsUSDTprice = tsPriceOracle.getAssetPrice(address(tsUSDT));
  assertEq(tsBAYCprice, 3822840829686);
  assertEq(tsUSDTprice, 100053000);

  uint256 collateralValue = tsBAYCprice;
  uint256 debtValue = actualDebtToLiquidate * tsUSDTprice / 1e6;
  assertEq(debtValue, 4300008062440, 'actualDebtToLiquidate');
  assertEq(debtValue * 100 / collateralValue, 112); //@audit debt is worth 112% of collateral, not worth it

  assertGt(actualDebtToLiquidate, 0, 'actualDebtToLiquidate');
  assertGt(actualCollateralToLiquidate, 0, 'actualCollateralToLiquidate');
  
  // liquidate some eth
  tsLiquidator1.approveERC20(address(tsUSDT), type(uint256).max);

  uint256[] memory liqTokenIds = new uint256[](1);
  liqTokenIds[0] = depTokenIds[0];

  actionCrossLiquidateERC721(
    address(tsLiquidator1),
    tsCommonPoolId,
    address(tsBorrower1),
    address(tsBAYC),
    liqTokenIds,
    address(tsUSDT),
    false,
    new bytes(0)
  );
}
```

