# Outdated Exchange Rate Utilization

CoreRouter.supply uses stale exchangeRateStored ignoring pending interest, so suppliers receive more lTokens than minted, diluting other users.

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

**Target:** CoreRouter.supply / LToken exchange rate
**Root cause:** supply() reads exchangeRateStored() before mint, which excludes accrued-but-unrealized interest, so the computed mintTokens exceeds what the lToken mint actually produced.
**Steps:**
1. Note LToken.exchangeRateStored() returns (cash+borrows-reserves)/totalSupply without accruing pending interest.
2. Call CoreRouter.supply(_amount, _token) while lToken has pending interest.
3. exchangeRateBefore = exchangeRateStored() is stale (lower than exchangeRateCurrent).
4. mint(_amount) mints fewer lTokens than _amount*1e18/exchangeRateBefore.
5. Contract records inflated mintTokens via updateTotalInvestment, exceeding actual minted supply.
6. Attacker supplies large amount, withdraws small amount, then withdraws all remaining lToken to extract value.
**How found:** Code review of CoreRouter.supply comparing exchangeRateStored vs exchangeRateCurrent in LToken; noticed stored rate omits accrueInterest, so pre-mint snapshot understates rate.
**Exploitation:** Attacker supplies a large underlying amount when pending interest makes exchangeRateCurrent > exchangeRateStored, causing totalInvestment to be credited more lTokens than minted; then redeems in steps to realize the discrepancy against other users' share of the pool.
**Insight:** In Compound-style lending forks, any accounting that snapshots exchangeRateStored before a mint/redeem must use exchangeRateCurrent (which accrues) or the pending-interest delta is misattributed to the caller.

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

**Supply function using exchangeRateStored before mint**

```
function supply(uint256 _amount, address _token) external {
        address _lToken = lendStorage.underlyingTolToken(_token);

        require(_lToken != address(0), "Unsupported Token");

        require(_amount > 0, "Zero supply amount");

        // Transfer tokens from the user to the contract
        IERC20(_token).safeTransferFrom(msg.sender, address(this), _amount);

        _approveToken(_token, _lToken, _amount);

        // Get exchange rate before mint
74:     uint256 exchangeRateBefore = LTokenInterface(_lToken).exchangeRateStored();

        // Mint lTokens
        require(LErc20Interface(_lToken).mint(_amount) == 0, "Mint failed");

        // Calculate actual minted tokens using exchangeRate from before mint
        uint256 mintTokens = (_amount * 1e18) / exchangeRateBefore;

        lendStorage.addUserSuppliedAsset(msg.sender, _lToken);

        lendStorage.distributeSupplierLend(_lToken, msg.sender);

        // Update total investment using calculated mintTokens
        lendStorage.updateTotalInvestment(
            msg.sender, _lToken, lendStorage.totalInvestment(msg.sender, _lToken) + mintTokens
        );

        emit SupplySuccess(msg.sender, _lToken, _amount, mintTokens);
    }
```

**exchangeRateStoredInternal ignores pending interest**

```
function exchangeRateStoredInternal() internal view virtual returns (uint256) {
        uint256 _totalSupply = totalSupply;
        if (_totalSupply == 0) {
            /*
             * If there are no tokens minted:
             *  exchangeRate = initialExchangeRate
             */
            return initialExchangeRateMantissa;
        } else {
            /*
             * Otherwise:
             *  exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
             */
            uint256 totalCash = getCashPrior();
            uint256 cashPlusBorrowsMinusReserves = totalCash + totalBorrows - totalReserves;
            uint256 exchangeRate = cashPlusBorrowsMinusReserves * expScale / _totalSupply;

            return exchangeRate;
        }
    }
```

