# erc721DecreaseIsolateSupplyOnLiquidate() missing clear lockerAddr

Liquidation path fails to clear lockerAddr on NFT token data, permanently locking the NFT when later deposited in cross mode.

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

**Target:** BVault ERC721 isolate supply accounting
**Root cause:** erc721DecreaseIsolateSupplyOnLiquidate() resets owner and supplyMode but not lockerAddr, leaving a stale poolManager lock on the token record.
**Steps:**
1. Call isolateLiquidate(supplyAsCollateral=false) so erc721DecreaseIsolateSupplyOnLiquidate() runs, leaving tokenData.lockerAddr = poolManager
2. Alice calls BVault.depositERC721(NFT_1, SUPPLY_MODE_CROSS); deposit does not check lockerAddr
3. tokenData now owner=Alice, supplyMode=CROSS, lockerAddr=poolManager
4. Alice calls withdrawERC721(); validateWithdrawERC721() reverts with ASSET_ALREADY_LOCKED_IN_USE because lockerAddr != address(0)
**How found:** Code review of the liquidation supply-decrement path, noticing owner/supplyMode were cleared but lockerAddr was not, then tracing deposit and withdraw validation to confirm the lock persists.
**Exploitation:** After a liquidation leaves a stale lockerAddr, the NFT owner re-deposits in cross mode; the withdraw validation requires lockerAddr==0, so the NFT is permanently stuck and other isolate methods are blocked.
**Insight:** When a struct is reset on one lifecycle path, diff every field against sibling reset functions (erc721DecreaseIsolateSupply has the same bug) and check which downstream validators read the un-cleared field.

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

**erc721DecreaseIsolateSupplyOnLiquidate missing lockerAddr clear**

```
function erc721DecreaseIsolateSupplyOnLiquidate(
    DataTypes.AssetData storage assetData,
    uint256[] memory tokenIds
  ) internal {
    for (uint256 i = 0; i < tokenIds.length; i++) {
      DataTypes.ERC721TokenData storage tokenData = assetData.erc721TokenData[tokenIds[i]];
      require(tokenData.supplyMode == Constants.SUPPLY_MODE_ISOLATE, Errors.INVALID_SUPPLY_MODE);

      assetData.userScaledIsolateSupply[tokenData.owner] -= 1;

      tokenData.owner = address(0);
      tokenData.supplyMode = 0;
@>  //missing tokenData.lockerAddr = address(0);
    }

    assetData.totalScaledIsolateSupply -= tokenIds.length;
  }
```

**validateWithdrawERC721 lockerAddr check**

```
function validateWithdrawERC721(
...
    for (uint256 i = 0; i < inputParams.tokenIds.length; i++) {
      DataTypes.ERC721TokenData storage tokenData = VaultLogic.erc721GetTokenData(assetData, inputParams.tokenIds[i]);
      require(tokenData.owner == inputParams.onBehalf, Errors.INVALID_CALLER);
      require(tokenData.supplyMode == inputParams.supplyMode, Errors.INVALID_SUPPLY_MODE);

@>    require(tokenData.lockerAddr == address(0), Errors.ASSET_ALREADY_LOCKED_IN_USE);
    }
  }
```

