User may not be able to borrow even if they provide sufficient collaterals
When a user supplies collateral, the protocol does not add the corresponding market to the user's account, so the collateral is not counted when they later try to borrow. As a result, a user with sufficient collateral cannot borrow and the transaction reverts.
Source: https://github.com/sherlock-audit/2025-05-lend-audit-contest-judging/issues/456
Found by
h2134
Summary
User may not be able to borrow even if they provide sufficient collaterals.
Root Cause
When a user borrows tokens, LToken is called to borrow the tokens from LToken contract.
// Enter the Compound market
enterMarkets(_lToken);
// Borrow tokens
@> require(LErc20Interface(_lToken).borrow(_amount) == 0, "Borrow failed");
Under the hood, borrowAllowed() in Lendtroller is called by LToken to check if the borrow is allowed.
/* Fail if borrow not allowed */
uint256 allowed = lendtroller.borrowAllowed(address(this), borrower, borrowAmount);
if (allowed != 0) {
revert BorrowLendtrollerRejection(allowed);
}
In Lendtroller::borrowAllowed(), it checks if CoreRouter provides sufficient collaterals to LToken by looping through each asset CoreRouter is in.
(Error err,, uint256 shortfall) =
getHypotheticalAccountLiquidityInternal(borrower, LToken(lToken), 0, borrowAmount);
if (err != Error.NO_ERROR) {
return uint256(err);
}
// For each asset the account is in
LToken[] memory assets = accountAssets[account];
for (uint256 i = 0; i < assets.length; i++) {
The problem is that when the user supplies collaterals, enterMarkets() is not called, leading to the collateral asset is not in accountAssets in Lendtroller, as a result, when CoreRouter borrows on behalf of the user, Lendtroller::borrowAllowed() would return error and the transaction will eventually fail.
Internal Pre-conditions
NA
External Pre-conditions
NA
Attack Path
NA
Impact
User cannot borrow tokens even if they provides sufficient collaterals.
PoC
Please run forge test --mt testPOC_CannotBorrowWithSufficientCollaterals.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "forge-std/Test.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ILayerZeroEndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import {Lend} from "../src/Governance/Lend.sol";
import {Lendtroller, LendtrollerInterface} from "../src/Lendtroller.sol";
import {LErc20Immutable, LToken} from "../src/LErc20Immutable.sol";
import {SimplePriceOracle} from "../src/SimplePriceOracle.sol";
import {WhitePaperInterestRateModel, InterestRateModel} from "../src/WhitePaperInterestRateModel.sol";
import {LendtrollerErrorReporter, TokenErrorReporter} from "../src/ErrorReporter.sol";
import {LendStorage} from "../src/LayerZero/LendStorage.sol";
import {CoreRouter} from "../src/LayerZero/CoreRouter.sol";
import {CrossChainRouter, Origin} from "../src/LayerZero/CrossChainRouter.sol";
contract POC is Test {
using SafeERC20 for IERC20;
uint32 constant chainAEid = 30101; // Ethereum
uint32 constant chainBEid = 30184; // Base
address owner;
address mockDestLToken;
address mockPeer;
IERC20 btc;
IERC20 dai;
IERC20 weth;
LErc20Immutable lTokenBTC;
LErc20Immutable lTokenDAI;
LErc20Immutable lTokenWETH;
Lend lend;
ILayerZeroEndpointV2 endpoint;
Lendtroller lendtroller;
SimplePriceOracle priceOracle;
WhitePaperInterestRateModel interestRateModel;
LendStorage lendStorage;
CoreRouter coreRouter;
CrossChainRouter crossChainRouter;
function setUp() public {
vm.createSelectFork("https://eth.drpc.org");
owner = makeAddr("Owner");
mockDestLToken = makeAddr("MockDestLToken");
mockPeer = makeAddr("ChainBPeer");
endpoint = ILayerZeroEndpointV2(0x1a44076050125825900e736c501f859c50fE728c);
btc = IERC20(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599);
dai = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
vm.startPrank(owner);
// Deploy Lendtroller
lendtroller = new Lendtroller();
// Deploy Lend
lend = new Lend(address(lendtroller));
// Deploy PriceOracle
priceOracle = new SimplePriceOracle();
// Deploy InterestRateModel
interestRateModel = new WhitePaperInterestRateModel(0.1e18, 0.05e18);
// Deploy lTokens
lTokenBTC = new LErc20Immutable(
address(btc),
lendtroller,
interestRateModel,
1e8, // 1:1
"Lending BTC",
"lBTC",
18,
payable(owner)
);
lTokenDAI = new LErc20Immutable(
address(dai),
lendtroller,
interestRateModel,
1e18, // 1:1
"Lending DAI",
"lDAI",
18,
payable(owner)
);
lTokenWETH = new LErc20Immutable(
address(weth),
lendtroller,
interestRateModel,
1e18, // 1:1
"Lending WETH",
"lWETH",
18,
payable(owner)
);
// Deploy LendStorage
lendStorage = new LendStorage(
address(lendtroller),
address(priceOracle),
chainAEid
);
// Deploy CoreRouter
coreRouter = new CoreRouter(
address(lendStorage),
address(priceOracle),
address(lendtroller)
);
// Deploy CrossChainRouter
crossChainRouter = new CrossChainRouter(
address(endpoint),
owner,
address(lendStorage),
address(priceOracle),
address(lendtroller),
payable(address(coreRouter)),
chainAEid
);
// Configurations
{
priceOracle.setUnderlyingPrice(lTokenBTC, 100000e18);
priceOracle.setUnderlyingPrice(lTokenDAI, 1e18);
priceOracle.setUnderlyingPrice(lTokenWETH, 2500e18);
lendtroller._setPriceOracle(priceOracle);
lendtroller.setLendStorage(address(lendStorage));
lendtroller._supportMarket(lTokenBTC);
lendtroller._supportMarket(lTokenDAI);
lendtroller._supportMarket(lTokenWETH);
lendtroller.setLendToken(address(lend));
lendtroller._setCollateralFactor(lTokenBTC, 0.9e18);
lendtroller._setCollateralFactor(lTokenDAI, 0.9e18);
lendtroller._setCollateralFactor(lTokenWETH, 0.9e18);
LToken[] memory lTokens = new LToken[](3);
lTokens[0] = lTokenBTC;
lTokens[1] = lTokenDAI;
lTokens[2] = lTokenWETH;
uint256[] memory supplySpeeds = new uint256[](3);
supplySpeeds[0] = 1e18;
supplySpeeds[1] = 1e18;
supplySpeeds[2] = 1e18;
uint256[] memory borrowSpeeds = new uint256[](3);
borrowSpeeds[0] = 2e18;
borrowSpeeds[1] = 2e18;
borrowSpeeds[2] = 2e18;
lendtroller._setLendSpeeds(lTokens, supplySpeeds, borrowSpeeds);
lendStorage.addSupportedTokens(address(btc), address(lTokenBTC));
lendStorage.addSupportedTokens(address(dai), address(lTokenDAI));
lendStorage.addSupportedTokens(address(weth), address(lTokenWETH));
lendStorage.addUnderlyingToDestlToken(address(btc), address(mockDestLToken), chainBEid);
lendStorage.addUnderlyingToDestlToken(address(dai), address(mockDestLToken), chainBEid);
lendStorage.addUnderlyingToDestlToken(address(weth), address(mockDestLToken), chainBEid);
lendStorage.setAuthorizedContract(address(coreRouter), true);
lendStorage.setAuthorizedContract(address(crossChainRouter), true);
crossChainRouter.setPeer(chainBEid, bytes32(uint256(uint160(mockPeer))));
coreRouter.setCrossChainRouter(address(crossChainRouter));
deal(address(crossChainRouter), 1 ether);
}
vm.stopPrank();
{
vm.label(address(btc), "BTC");
vm.label(address(dai), "DAI");
vm.label(address(weth), "WETH");
vm.label(address(lTokenBTC), "lToken BTC");
vm.label(address(lTokenDAI), "lToken DAI");
vm.label(address(lTokenWETH), "lToken WETH");
vm.label(address(endpoint), "Endpoint");
vm.label(address(lendtroller), "Lendtroller");
vm.label(address(lend), "Lend");
vm.label(address(priceOracle), "PriceOracle");
vm.label(address(lendStorage), "LendStorage");
vm.label(address(coreRouter), "CoreRouter");
vm.label(address(crossChainRouter), "CrossChainRouter");
}
}
function testPOC_CannotBorrowWithSufficientCollaterals() public {
address alice = makeAddr("Alice");
deal(address(weth), alice, 1e18);
// Alice supplies 1 WETH
{
vm.startPrank(alice);
weth.safeApprove(address(coreRouter), 1e18);
coreRouter.supply(1e18, address(weth));
vm.stopPrank();
}
address bob = makeAddr("Bob");
deal(address(dai), bob, 3000e18);
// Bob supplies 3000 DAI
{
vm.startPrank(bob);
dai.safeApprove(address(coreRouter), 3000e18);
coreRouter.supply(3000e18, address(dai));
vm.stopPrank();
}
// Bob borrows 1 WETH but then transaction will revert
vm.prank(bob);
vm.expectRevert(abi.encodeWithSelector(TokenErrorReporter.BorrowLendtrollerRejection.selector, LendtrollerErrorReporter.Error.INSUFFICIENT_LIQUIDITY));
coreRouter.borrow(1e18, address(weth));
}
}
Mitigation
Enter market when user supplies.
function supply(uint256 _amount, address _token) external {
address _lToken = lendStorage.underlyingTolToken(_token);
...
+ // Enter the Compound market
+ enterMarkets(_lToken);
// Mint lTokens
require(LErc20Interface(_lToken).mint(_amount) == 0, "Mint failed");
...
emit SupplySuccess(msg.sender, _lToken, _amount, mintTokens);
}
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 supply function does not call enterMarkets, so the collateral market is not added to the user's account and is ignored during borrow checks.
Impact
A user cannot borrow tokens even if they provide sufficient collateral; the borrow transaction reverts.
What the attacker needed
User supplies collateral; User attempts to borrow
The fix
The supply function should call enterMarkets for the supplied lToken so the collateral is recorded.
How it was found
- Alice supplies 1 WETH as collateral.
- Bob supplies 3000 DAI as collateral.
- Bob tries to borrow 1 WETH.
- The borrow transaction reverts with an insufficient liquidity error.
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.
In a lending protocol, you deposit assets as collateral so you can borrow other assets. The protocol must record which markets you have entered to count your collateral. Here, the deposit step forgot to record the market, so the system thought the user had no collateral and blocked the borrow.
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.