# Incorrect Collateral Check Logic in CoreRouter.sol#borrow()

CoreRouter.borrow() zeroes the collateral check when a user has no prior borrow index in the target market, allowing undercollateralized borrowing.

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

**Target:** CoreRouter.sol borrow() lending contract
**Root cause:** borrow() discards the correct hypothetical USD debt from getHypotheticalAccountLiquidityCollateral and instead rescales it by borrowIndex; when currentBorrow.borrowIndex is 0 (first borrow in market), borrowAmount becomes 0, making require(collateral >= 0) always pass.
**Steps:**
1. Call `borrow(_amount, _lToken)` on a market where msg.sender has no existing borrow balance (currentBorrow.borrowIndex == 0).
2. borrow() calls `getHypotheticalAccountLiquidityCollateral(msg.sender, LToken(_lToken), 0, _amount)` returning (borrowed, collateral).
3. currentBorrow.borrowIndex == 0 so borrowAmount is set to 0.
4. `require(collateral >= 0)` passes regardless of actual debt vs collateral.
5. Borrow succeeds even when borrowed > collateral, creating an undercollateralized position.
**How found:** Code review of borrow(): noticed the correct hypothetical liquidity values were computed but then discarded in favor of a borrowIndex-scaled borrowAmount, and that the ternary defaults to 0 when borrowIndex is 0.
**Exploitation:** Attacker with any collateral (or none needed for the check) performs a first-time borrow in a target market; the zero borrowIndex path nullifies the solvency check, letting them withdraw borrowed assets exceeding their collateral, leaving bad debt.
**Escalation:** Repeat across multiple markets to accumulate undercollateralized debt; if asset prices move adversely, positions cannot be liquidated fully, causing protocol bad debt.
**Insight:** When a contract computes a correct solvency value then re-derives it via a secondary formula, check the fallback branch of any ternary scaling by an index/accumulator—zero-initialized state (first interaction) often collapses the check to a no-op.

