Users can lend and borrow above allowed limitations
The daily lend and borrow increase limits were calculated incorrectly, allowing users to deposit or borrow up to 110% of the intended limit instead of 10%. An attacker could exceed the daily limits, potentially destabilising the protocol's risk controls.
JohnSmith Follow with Arz, BowTiedOriole and 8 others
Originally disclosed on Code4rena
Submitted by JohnSmith, also found by Arz, BowTiedOriole, FastChecker, shaka, Aymen0909, deepplus, KupiaSec, kennedy1030, kfx, and DanielArmstrong
Impact
Protocol design includes limitations on how much a user can deposit and borrow per day. So it is 10% of lent money or dailyLendIncreaseLimitMin/dailyDebtIncreaseLimitMin, whichever is greater. Current implementation is wrong and makes it 110% because of mistake in calculations; which means that users are able to deposit/borrow close to 110% amount of current assets.
Issue is in these calculations:
uint256 lendIncreaseLimit = _convertToAssets(totalSupply(), newLendExchangeRateX96, Math.Rounding.Up)
* (Q32 + MAX_DAILY_LEND_INCREASE_X32) / Q32;
uint256 debtIncreaseLimit = _convertToAssets(totalSupply(), newLendExchangeRateX96, Math.Rounding.Up)
* (Q32 + MAX_DAILY_DEBT_INCREASE_X32) / Q32;
Proof of Concept
For borrow I used function _setupBasicLoan() already implemented by you in your tests. Add this tests beside your other tests in test/integration/V3Vault.t.sol:
function testDepositV2() external {
vault.setLimits(0, 150000_000000, 0, 10_000000, 0);//10 usdc dailyLendIncreaseLimitMin
uint256 balance = USDC.balanceOf(WHALE_ACCOUNT);
vm.startPrank(WHALE_ACCOUNT);
USDC.approve(address(vault), type(uint256).max);
vault.deposit(10_000000 , WHALE_ACCOUNT);
skip(1 days);
for (uint i; i < 10; ++i) {
uint256 assets = vault.totalAssets();
console.log("USDC vault balance: %s", assets);
uint amount = assets + assets * 9 / 100;// 109%
vault.deposit(amount, WHALE_ACCOUNT);
skip(1 days);
}
uint256 assets = vault.totalAssets();
assertEq(assets, 15902_406811);//so in 10 days we deposited 15k usdc, despite the 10 usdc daily limitation
console.log("USDC balance: %s", assets);
}
function testBorrowV2() external {
vault.setLimits(0, 150_000000, 150_000000, 150_000000, 1_000000);// 1 usdc dailyDebtIncreaseLimitMin
skip(1 days); //so we can recalculate debtIncreaseLimit again
_setupBasicLoan(true);//borrow 8_847206 which is > 1_000000 and > 10% of USDC10_000000 in vault
}
Recommended Mitigation Steps
Fix is simple for _resetDailyLendIncreaseLimit():
uint256 lendIncreaseLimit = _convertToAssets(totalSupply(), newLendExchangeRateX96, Math.Rounding.Up)
- * (Q32 + MAX_DAILY_LEND_INCREASE_X32) / Q32;
+ * MAX_DAILY_LEND_INCREASE_X32 / Q32;
And for _resetDailyDebtIncreaseLimit():
uint256 debtIncreaseLimit = _convertToAssets(totalSupply(), newLendExchangeRateX96, Math.Rounding.Up)
- * (Q32 + MAX_DAILY_DEBT_INCREASE_X32) / Q32;
+ * MAX_DAILY_DEBT_INCREASE_X32 / Q32;
Assessed type
Math
Fixed here.
Status: Mitigation confirmed. Full details in reports from thank_you, b0g0 and ktg.
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 limit calculation added the maximum daily increase to 100% (Q32) before multiplying, instead of just using the maximum daily increase percentage.
Impact
Users could lend or borrow close to 110% of the current assets per day, bypassing the intended 10% daily limit and potentially exposing the protocol to excessive risk.
What the attacker needed
A user account with funds; ability to call deposit or borrow functions
How it was found
- Set the daily lend increase minimum to a small value (e.g., 10 USDC).
- Deposit a small amount to initialise the vault.
- Wait one day to reset the limit.
- Repeatedly deposit an amount equal to 109% of the current total assets, waiting a day between each deposit.
- Observe that after 10 days the total deposited far exceeds the intended daily limit.
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.
The protocol sets a daily cap on how much you can lend or borrow, meant to be 10% of the pool. A coding mistake made the cap 110% instead, so users could move almost the entire pool in one day. This breaks the safety limit that protects the protocol.
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.