Skip to content
Business logic Audit finding Intermediate

incorrect distribution of Lend tokens to users

The cross-chain borrow handler updates the user's collateral record before distributing LEND rewards, but the reward calculation reads that same record. As a result, the protocol distributes an incorrect amount of LEND tokens to borrowers.

0xc0ffEE Follow with Kirkeelee, Kvar and 9 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-05-lend-audit-contest-judging/issues/773

Found by

0xc0ffEE, Kirkeelee, Kvar, PNS, future, ggg_ttt_hhh, hard1k, jokr, mussucal, patitonar, rudhra1749, t.aksoy

Summary

if we observe _handleBorrowCrossChainRequest function, https://github.com/sherlock-audit/2025-05-lend-audit-contest/blob/main/Lend-V2/src/LayerZero/CrossChainRouter.sol#L581-L660

Solidity
    function _handleBorrowCrossChainRequest(LZPayload memory payload, uint32 srcEid) private {
        // Accrue interest on borrowed token on destination chain
        LTokenInterface(payload.destlToken).accrueInterest();


        // Get current borrow index from destination lToken
        uint256 currentBorrowIndex = LTokenInterface(payload.destlToken).borrowIndex();


        // Important: Use the underlying token address
        address destUnderlying = lendStorage.lTokenToUnderlying(payload.destlToken);


        // Check if user has any existing borrows on this chain
        bool found = false;
        uint256 index;


        LendStorage.Borrow[] memory userCrossChainCollaterals =
            lendStorage.getCrossChainCollaterals(payload.sender, destUnderlying);


        /**
         * Filter collaterals for the given srcEid. Prevents borrowing from
         * multiple collateral sources.
         */
        for (uint256 i = 0; i < userCrossChainCollaterals.length;) {
            if (
                userCrossChainCollaterals[i].srcEid == srcEid
                    && userCrossChainCollaterals[i].srcToken == payload.srcToken
            ) {
                index = i;
                found = true;
                break;
            }
            unchecked {
                ++i;
            }
        }


        // Get existing borrow amount
        (uint256 totalBorrowed,) = lendStorage.getHypotheticalAccountLiquidityCollateral(
            payload.sender, LToken(payable(payload.destlToken)), 0, payload.amount
        );


        // Verify the collateral from source chain is sufficient for total borrowed amount
        require(payload.collateral >= totalBorrowed, "Insufficient collateral");


        // Execute the borrow on destination chain
        CoreRouter(coreRouter).borrowForCrossChain(payload.sender, payload.amount, payload.destlToken, destUnderlying);


        /**
         * @dev If existing cross-chain collateral, update it. Otherwise, add new collateral.
         */
        if (found) {
            uint256 newPrincipleWithAmount = (userCrossChainCollaterals[index].principle * currentBorrowIndex)
                / userCrossChainCollaterals[index].borrowIndex;


            userCrossChainCollaterals[index].principle = newPrincipleWithAmount + payload.amount;
            userCrossChainCollaterals[index].borrowIndex = currentBorrowIndex;


            lendStorage.updateCrossChainCollateral(
                payload.sender, destUnderlying, index, userCrossChainCollaterals[index]
            );
        } else {
            lendStorage.addCrossChainCollateral(
                payload.sender,
                destUnderlying,
                LendStorage.Borrow({
                    srcEid: srcEid,
                    destEid: currentEid,
                    principle: payload.amount,
                    borrowIndex: currentBorrowIndex,
                    borrowedlToken: payload.destlToken,
                    srcToken: payload.srcToken
                })
            );
        }


        // Track borrowed asset
        lendStorage.addUserBorrowedAsset(payload.sender, payload.destlToken);


        // Distribute LEND rewards on destination chain
        lendStorage.distributeBorrowerLend(payload.destlToken, payload.sender);


here if we observe, first it updates CrossChainCollaterals mapping then it calls lendStorage.distributeBorrowerLend which gives Lend tokens to borrower. But it should first distribute lend tokens and then it should update CrossChainCollaterals mapping.because distributeBorrowerLend function uses CrossChainCollaterals mapping to calculate total user borrowed assets, https://github.com/sherlock-audit/2025-05-lend-audit-contest/blob/main/Lend-V2/src/LayerZero/LendStorage.sol#L365-L368

Solidity
        uint256 borrowerAmount = div_(
            add_(borrowWithInterest(borrower, lToken), borrowWithInterestSame(borrower, lToken)),
            Exp({mantissa: LTokenInterface(lToken).borrowIndex()})
        );

https://github.com/sherlock-audit/2025-05-lend-audit-contest/blob/main/Lend-V2/src/LayerZero/LendStorage.sol#L478-L501

Solidity
    function borrowWithInterest(address borrower, address _lToken) public view returns (uint256) {
        address _token = lTokenToUnderlying[_lToken];
        uint256 borrowedAmount;


        Borrow[] memory borrows = crossChainBorrows[borrower][_token];
        Borrow[] memory collaterals = crossChainCollaterals[borrower][_token];


        require(borrows.length == 0 || collaterals.length == 0, "Invariant violated: both mappings populated");
        // Only one mapping should be populated:
        if (borrows.length > 0) {
            for (uint256 i = 0; i < borrows.length; i++) {
                if (borrows[i].srcEid == currentEid) {
                    borrowedAmount +=
                        (borrows[i].principle * LTokenInterface(_lToken).borrowIndex()) / borrows[i].borrowIndex;
                }
            }
        } else {
            for (uint256 i = 0; i < collaterals.length; i++) {
                // Only include a cross-chain collateral borrow if it originated locally.
                if (collaterals[i].destEid == currentEid && collaterals[i].srcEid == currentEid) {
                    borrowedAmount +=
                        (collaterals[i].principle * LTokenInterface(_lToken).borrowIndex()) / collaterals[i].borrowIndex;
                }
            }

due to this protocol will distrubute incorrect amount of lend tokens to users.

Root Cause

distributing lend tokens before updating crossChainCollateral mapping

Internal Pre-conditions

none

External Pre-conditions

none

Attack Path

none

Impact

incorrect distribution of Lend tokens to users

PoC

No response

Mitigation

first distribute Lend tokens and then update CrossChainCollateral mapping

The original report as published on Sherlock, by 0xc0ffEE. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The reward distribution function reads the cross-chain collateral mapping after it has been updated, so it uses the new borrow amount instead of the previous one.

What the attacker needed

None

The fix

The reward distribution should be called before updating the cross-chain collateral mapping.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When someone borrows across chains, the protocol gives them reward tokens called LEND. The amount of reward depends on how much they have borrowed. The code updates the borrow record first, then calculates the reward using that updated record, so the reward is wrong.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0xc0ffEE

View all

27 more disclosed reports, best first.

More from LEND

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.