# `CoreRouter.sol`’s `repayBorrowInternal` incorrectly updates `same chain` borrow balances on `cross chain` repayments

Cross-chain repay in CoreRouter.repayBorrowInternal also wipes the borrower's same-chain borrowBalance, erasing legitimate debt and causing lender fund loss.

- Payout: Audit contest
- Severity: high
- Program: Lend Audit Contest
- Found by: 0xbakeng
- Disclosed: 2025-05-22
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-05-lend-audit-contest-judging/issues/782
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-lend-audit-contest%3AH-16
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** CoreRouter.sol repayBorrowInternal (LayerZero cross-chain lending)
**Root cause:** The 'Update same-chain borrow balances' block executes unconditionally, even when _isSameChain == false, so a cross-chain repayment deletes or reduces the same-chain borrowBalance for the same lToken.
**Steps:**
1. Alice opens a same-chain borrow on Chain B via CoreRouter.borrow(_isSameChain=true).
2. Alice separately opens a cross-chain borrow collateralized on Chain A via CrossChainRouter.borrowCrossChain(), delivered to Chain B.
3. Alice (or liquidator) calls CoreRouter.repayBorrow(_isSameChain=false) repaying exactly the cross-chain debt.
4. repayBorrowInternal computes borrowedAmount from borrowWithInterest() and calls LErc20Interface(_lToken).repayBorrow().
5. The unconditional same-chain block runs: repayAmountFinal == borrowedAmount triggers lendStorage.removeBorrowBalance(borrower,_lToken) and removeUserBorrowedAsset, deleting the same-chain debt.
6. Alice's same-chain loan is erased while tokens are still owed; lenders lose funds.
**How found:** Code reading of repayBorrowInternal: noticed the same-chain balance update block lacked an _isSameChain guard despite borrowedAmount being sourced differently per branch.
**Exploitation:** Borrower takes both a same-chain and cross-chain loan of the same lToken, then repays only the cross-chain debt; the same-chain borrow record is deleted, leaving unbacked debt that lenders absorb.
**Insight:** In dual-path repay/borrow functions keyed by a same-chain vs cross-chain flag, verify every storage mutation is gated on that flag; shared cleanup blocks silently corrupt the other debt ledger.

