# isolateRepay() lack of check onBehalf == nftOwner

isolateRepay() lets any caller pass an arbitrary onBehalf, decrementing another user's scaled borrow so their loan underflows on liquidation.

- 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/44
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-benddao%3AH-02
- Tags: area:web3 domain:web3 impact:dos impact:integrity kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:accounting-error vuln:business-logic

**Target:** isolateRepay / isolateRedeem in BendDAO lending pool
**Root cause:** validateIsolateRepayBasic only checks onBehalf != address(0), not that onBehalf equals the NFT owner, so userScaledIsolateBorrow[onBehalf] can be decremented for an unrelated account.
**Steps:**
1. Alice depositERC721(NFT_1); Bob depositERC721(NFT_2).
2. Alice isolateBorrow(NFT_1, 100) -> userScaledIsolateBorrow[alice]=100, loanData[NFT_1].scaledAmount=100.
3. Bob isolateBorrow(NFT_2, 100) -> userScaledIsolateBorrow[bob]=100, loanData[NFT_2].scaledAmount=100.
4. Alice calls `isolateRepay(NFT_1, amounts=[1], onBehalf=bob)` -> userScaledIsolateBorrow[bob]=99.
5. On isolateLiquidate(NFT_2): userScaledIsolateBorrow[bob] -= loanData[NFT_2].scaledAmount (99-100) underflows, reverting liquidation.
**How found:** Code review of validateIsolateRepayBasic: noticed only a non-zero check on onBehalf, then traced how userScaledIsolateBorrow[onBehalf] is decremented and how liquidation subtracts loanData.scaledAmount, producing an underflow.
**Exploitation:** Attacker repays a tiny amount on their own NFT while setting onBehalf to a victim, decrementing the victim's scaled borrow balance. The victim's later repay or liquidation then underflows and reverts, blocking repayment/liquidation.
**Insight:** In lending protocols, any function taking an onBehalf/beneficiary parameter must bind it to the actual position owner; trace every write to per-user scaled-debt accounting and check whether a mismatched beneficiary can desync user balance vs per-loan scaledAmount.

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

**Attack sequence: repay NFT_1 on behalf of Bob**

```
5. Alice malicious repay, isolateRepay(NFT\_1,amounts = 1, onBehalf = bob)
   - userScaledIsolateBorrow\[bob] = 99
6. When NFT\_2 be liquidated, isolateLiquidate(NFT\_2)
   - userScaledIsolateBorrow\[bob] = loanData\[NFT\_2].scaledAmount = 99 - 100 =====> underflow.
```

