# currentLoanOwner can manipulate loanInfo when any lenders try to buyout

Reentrancy via ERC777 loan asset lets currentLoanOwner re-enter lend() during buyout payout, overwriting loanInfo with zero interest and long duration.

- Payout: Audit contest
- Severity: high
- Program: Backed Protocol
- Credited: rayn
- Disclosed: 2022-04-21
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2022-04-backed-findings/issues/88
- Library page: https://bugbountylibrary.com/r/c4%3A2022-04-backed%3AH-02
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:chained vuln:business-logic vuln:reentrancy

**Target:** NFTLoanFacilitator.lend() buyout path
**Root cause:** lend() transfers accumulatedInterest+previousLoanAmount to currentLoanOwner via safeTransfer before finalizing state; an ERC777 loan asset invokes tokensReceived hook, allowing reentrant lend() that rewrites loanInfo.
**Steps:**
1. Attacker calls `lend()` on a loan using an ERC777 loanAssetContractAddress, becoming currentLoanOwner.
2. Victim lender calls `lend()` to buyout the attacker's loan.
3. lend() executes `ERC20(loanAssetContractAddress).safeTransfer(accumulatedInterest+previousLoanAmount, currentLoanOwner)`.
4. ERC777 transfer triggers `_callTokensReceived` on attacker, who re-enters `lend()` with same loanId, interestRate=0, same amount, long durationSeconds, sendLendTicketTo=attacker.
5. loanInfo now holds manipulated bad terms; victim receives lend ticket but cannot reset terms since improvement requires better terms.
**How found:** Researcher read lend() flow and noticed safeTransfer to currentLoanOwner occurs before state finalization; recognized ERC777 tokensReceived hook enables reentrancy into lend() to rewrite loanInfo.
**Exploitation:** Attacker pre-positions as currentLoanOwner with an ERC777 loan asset; on victim buyout, the payout transfer re-enters lend() to overwrite loan terms to zero interest and long duration, locking victim into unfavorable terms.
**Insight:** When a buyout/refinance function pays the incumbent owner via safeTransfer, check whether the loan asset can be a hook-bearing token (ERC777) and whether re-entering the same entrypoint can overwrite terms the new lender cannot later improve.
