# Pine Protocol: flash loan repays NFT loan, vault balance unchanged

Pine Protocol's NFT lending pool allowed repaying a loan with flash-loaned WETH from an old pool, then repaying the flash loan by transferring WETH directly to the vault, leaving the vault balance unchanged while clearing the debt.

- Payout: Real-world hack
- Severity: high
- Program: PineProtocol
- Analysis by: DeFiHackLabs
- Disclosed: 2023-12-22
- Write-up quality: 7/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-12/PineProtocol_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20231222-pineprotocol
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:high technique:chained vuln:business-logic vuln:flash-loan

**Target:** ERC721 lending pool contract
**Root cause:** The repay function credited the loan based on the amount passed, but the flash loan repayment logic allowed the attacker to transfer WETH directly to the vault without updating the loan state, effectively repaying the loan with the protocol's own funds.
**Steps:**
1. Take a flash loan of WETH from the old lending pool (ERC721LendingPool02Old) equal to the vault's WETH balance.
2. In the flash loan callback, approve the new lending pool (ERC721LendingPool02New) to spend WETH.
3. Call `repay(collateralTokenId, _amount, address(0))` on the new pool, passing the flash-loaned amount to clear the loan.
4. Send additional 0.3 WETH to the attack contract to cover the flash loan fee.
5. Transfer `_amount - WETH.balanceOf(pineGnosisSafe)` WETH directly to the vault (pineGnosisSafe), repaying the flash loan without the vault balance changing.
**Exploitation:** Attacker flash-loaned WETH from the old pool, used it to repay a loan in the new pool, then repaid the flash loan by transferring WETH directly to the vault, leaving the vault's WETH balance unchanged while the attacker's loan was cleared, netting ~90k USD.
**Insight:** When a protocol has multiple lending pools or versions, check if flash loans from one can be used to manipulate state in another, especially if repayment logic doesn't verify the source of funds or update internal accounting correctly.
