Lender DoS if all asset is borrowed or realized
The lending pool's interest realization function lacks a zero check, so when all assets are borrowed and realized interest is zero, it still attempts to distribute rewards, causing a revert with InsufficientReward. This can be exploited to block time-sensitive operations like repayments and liquidations.
Bigsam Follow with Drynooo, farismaulana and 4 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-07-cap-judging/issues/150
Found by
Bigsam, Drynooo, farismaulana, frndz0ne, lanrebayode77, magiccentaur, montecristo
Summary
If all asset is borrowed (or already realized to restaker interests), realizedInterest is 0. Thus, there is no rewards to distribute to restakers. However, BorrowLogic is missing zero check, thus it will try to distribute rewards anway, which will revert due to InsufficientReward error from Symbiotic DefaultStakerRewards contract.
Root Cause
When debt is repaid, restakers' interests will be realized.
File: cap-contracts/contracts/lendingPool/libraries/BorrowLogic.sol
201: function realizeRestakerInterest(ILender.LenderStorage storage $, address _agent, address _asset)
202: public
203: returns (uint256 realizedInterest)
204: {
205: ILender.ReserveData storage reserve = $.reservesData[_asset];
206: uint256 unrealizedInterest;
207: (realizedInterest, unrealizedInterest) = maxRestakerRealization($, _agent, _asset);
208: reserve.lastRealizationTime[_agent] = block.timestamp;
209:
210: if (realizedInterest == 0 && unrealizedInterest == 0) return 0;
211:
212: reserve.debt += realizedInterest;
213: reserve.unrealizedInterest[_agent] += unrealizedInterest;
214: reserve.totalUnrealizedInterest += unrealizedInterest;
215:
216: IDebtToken(reserve.debtToken).mint(_agent, realizedInterest + unrealizedInterest);
217: IVault(reserve.vault).borrow(_asset, realizedInterest, $.delegation);
218:@> IDelegation($.delegation).distributeRewards(_agent, _asset);
219: emit RealizeInterest(_asset, realizedInterest, $.delegation);
In L207, realizedInterest equals to 0 if all asset is borrowed.
So in L217, lender contract will borrow 0 asset from cUSD contract.
In 218, delegation distributes rewards but it doesn't hold any reward. Thus, transaction will revert with InsufficientReward error due to this check.
Internal Pre-conditions
- All asset is borrowed
External Pre-conditions
n/a
Attack Path
n/a
Impact
Lender contract will suffer from DoS, as restaker rewards are realized prior to all major features (borrow, repay, liquidation etc).
Although DoS can be easily mitigated by minting 1 wei of cUSD (thus, depositing affected asset), this vulnerability can be exploited to brick certain time-sensitive operations.
For example:
- One agent can brick other agent from repaying, or brick liquidations (which is very time-sensitive).
- If vault does not have enough balance to cover the current restaker reward, an attacker can frontrun incoming operations (borrow, repay, liquidation) by
Lender::realizeRestakerInterestto drain vault balance and brick the operation.
Additional Note
This bug also affects repayment on paused asset. As realizedInterest is set to 0 for paused asset:
File: cap-contracts/contracts/lendingPool/libraries/BorrowLogic.sol
262: if (reserve.paused) {
263: unrealizedInterest = realization;
264:@> realization = 0;
But paused asset repayment is blocked by another bug which I'll describe in another report.
PoC
pragma solidity ^0.8.28;
import { IOracle } from "../contracts/interfaces/IOracle.sol";
import { IVaultAdapter } from "../contracts/interfaces/IVaultAdapter.sol";
import { VaultAdapter } from "../contracts/oracle/libraries/VaultAdapter.sol";
import { TestDeployer } from "./deploy/TestDeployer.sol";
import { console } from "forge-std/console.sol";
contract POC is TestDeployer {
VaultAdapter adapter;
address user_agent;
function setUp() public {
_deployCapTestEnvironment();
_initTestVaultLiquidity(usdVault);
_initSymbioticVaultsLiquidity(env);
user_agent = _getRandomAgent();
vm.startPrank(env.symbiotic.users.vault_admin);
_symbioticVaultDelegateToAgent(symbioticWethVault, env.symbiotic.networkAdapter, user_agent, 100e18);
vm.stopPrank();
}
function test_submissionValidity() public {
_setAssetOraclePrice(address(weth), 2000e8);
vm.startPrank(user_agent);
// borrows all USDC
lender.borrow(address(usdc), 12000e6, user_agent);
_timeTravel(90 days);
usdc.approve(address(lender), 5000e6);
// repay is DoSed
vm.expectRevert(abi.encodeWithSignature("InsufficientReward()"));
lender.repay(address(usdc), 5000e6, user_agent);
vm.stopPrank();
}
}
Mitigation
diff --git a/cap-contracts/contracts/lendingPool/libraries/BorrowLogic.sol b/cap-contracts/contracts/lendingPool/libraries/BorrowLogic.sol
index 3c2b60a..e36f043 100644
--- a/cap-contracts/contracts/lendingPool/libraries/BorrowLogic.sol
+++ b/cap-contracts/contracts/lendingPool/libraries/BorrowLogic.sol
@@ -214,8 +214,10 @@ library BorrowLogic {
reserve.totalUnrealizedInterest += unrealizedInterest;
IDebtToken(reserve.debtToken).mint(_agent, realizedInterest + unrealizedInterest);
- IVault(reserve.vault).borrow(_asset, realizedInterest, $.delegation);
- IDelegation($.delegation).distributeRewards(_agent, _asset);
+ if (realizedInterest > 0) {
+ IVault(reserve.vault).borrow(_asset, realizedInterest, $.delegation);
+ IDelegation($.delegation).distributeRewards(_agent, _asset);
+ }
emit RealizeInterest(_asset, realizedInterest, $.delegation);
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/cap-labs-dev/cap-contracts/pull/189
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
Likely the function realizeRestakerInterest does not check if realizedInterest is zero before calling distributeRewards, which reverts when there are no rewards to distribute.
Impact
The lender contract suffers a denial of service, blocking repayments and liquidations, though it can be mitigated by depositing a tiny amount of the asset.
What the attacker needed
All assets in the lending pool are borrowed
The fix
The protocol team fixed this issue by adding a check to only borrow and distribute rewards when realizedInterest is greater than zero.
How it was found
- Borrow all available USDC from the lending pool.
- Wait for interest to accrue over time.
- Attempt to repay part of the loan.
- The transaction reverts with InsufficientReward 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.
When all the money in a lending pool is borrowed, the pool still tries to pay out rewards to people who staked their tokens, but it has nothing to give. This causes the transaction to fail with an error. An attacker can use this to stop important actions like repaying a loan or liquidating a risky position.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.