User unable to migrate under certain edge case
During migration, the router always sets the repayment amount to the maximum value, which is then converted to zero shares and zero assets when the user has no debt. This causes the Morpho repay call to revert, blocking migration for users with only collateral.
Bigsam Follow with Ledger_Patrol, Ragnarok and 11 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-06-notional-exponent-judging/issues/674
Found by
Bigsam, Ledger_Patrol, Ragnarok, Riceee, X0sauce, aman, coffiasd, dan__vinci, dhank, h2134, hard1k, shiazinho, theweb3mechanic, xiaoming90
Summary
Root Cause
Internal Pre-conditions
External Pre-conditions
Attack Path
During migration, the assetToRepay parameter of the _exitWithRepay function is always set to type(uint256).max, as shown in Line 237 below.
File: AbstractLendingRouter.sol
221: /// @dev Enters a position or migrates shares from a previous lending router
222: function _enterOrMigrate(
223: address onBehalf,
224: address vault,
225: address asset,
226: uint256 assetAmount,
227: bytes memory depositData,
228: address migrateFrom
229: ) internal returns (uint256 sharesReceived) {
230: if (migrateFrom != address(0)) {
231: // Allow the previous lending router to repay the debt from assets held here.
232: ERC20(asset).checkApprove(migrateFrom, assetAmount);
233: sharesReceived = ILendingRouter(migrateFrom).balanceOfCollateral(onBehalf, vault);
234:
235: // Must migrate the entire position
236: ILendingRouter(migrateFrom).exitPosition(
237: onBehalf, vault, address(this), sharesReceived, type(uint256).max, bytes("")
238: );
239: } else {
Assume that Bob has supplied collateral, but no debt, and he wants to migrate from the previous lending router to a new lending router.
Since assetToRepay is set to type(uint256).max, the assetToRepay will be overwritten to zero (0) in Line 193 below. In addition, since Bob does not have any debt, which means that he has no borrow shares, the MORPHO.position(morphoId(m), onBehalf).borrowShares at Line 192 below will return zero (0). In this case, sharesToRepay will be zero (0)
File: MorphoLendingRouter.sol
177: function _exitWithRepay(
178: address onBehalf,
179: address vault,
180: address asset,
181: address receiver,
182: uint256 sharesToRedeem,
183: uint256 assetToRepay,
184: bytes calldata redeemData
185: ) internal override {
186: MarketParams memory m = marketParams(vault, asset);
187:
188: uint256 sharesToRepay;
189: if (assetToRepay == type(uint256).max) {
190: // If assetToRepay is uint256.max then get the morpho borrow shares amount to
191: // get a full exit.
192: sharesToRepay = MORPHO.position(morphoId(m), onBehalf).borrowShares;
193: assetToRepay = 0;
194: }
195:
196: bytes memory repayData = abi.encode(
197: onBehalf, vault, asset, receiver, sharesToRedeem, redeemData, _isMigrate(receiver)
198: );
199:
200: // Will trigger a callback to onMorphoRepay
201: MORPHO.repay(m, assetToRepay, sharesToRepay, onBehalf, repayData);
202: }
Note that both assetToRepay and sharesToRepay are zero (0). At Line 201 above, the Morpho.repay() function will be executed with the following parameter values:
MORPHO.repay(m, assetToRepay, sharesToRepay, onBehalf, repayData);
MORPHO.repay(m, 0, 0, onBehalf, repayData);
When inspecting Morpho's Morpho.repay() function, the repay function will revert at Line 278 due to the UtilsLib.exactlyOneZero(assets, shares) check because assets and shares cannot be both zero at the same time.
File: Morpho.sol
269: function repay(
270: MarketParams memory marketParams,
271: uint256 assets, // @audit-info if migrate, assets = assetToRepay = 0
272: uint256 shares, // @audit-info if migrate, shares = MORPHO.position(morphoId(m), onBehalf).borrowShares;
273: address onBehalf,
274: bytes calldata data
275: ) external returns (uint256, uint256) {
276: Id id = marketParams.id();
277: require(market[id].lastUpdate != 0, ErrorsLib.MARKET_NOT_CREATED);
278: require(UtilsLib.exactlyOneZero(assets, shares), ErrorsLib.INCONSISTENT_INPUT);
279: require(onBehalf != address(0), ErrorsLib.ZERO_ADDRESS);
File: UtilsLib.sol
11: library UtilsLib {
12: /// @dev Returns true if there is exactly one zero among `x` and `y`.
13: function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) {
14: assembly {
15: z := xor(iszero(x), iszero(y))
16: }
17: }
Impact
Medium. Migration function is a core functionality in the protocol. This report shows that the migration will be DOS or not work under certain edge case.
PoC
No response
Mitigation
Skip the repayment if debt is zero, and proceed with the migration.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/notional-finance/notional-v4/pull/9
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 migration logic unconditionally sets the repayment amount to the maximum, which becomes zero when there is no debt, and the underlying repay function rejects zero amounts.
Impact
Migration is a core function and will fail (denial of service) for users who have collateral but no debt, preventing them from moving their position.
What the attacker needed
User has collateral but no debt; user initiates migration
The fix
The protocol team fixed this issue by skipping the repayment when debt is zero and proceeding with the migration.
How it was found
- Bob supplies collateral but has no debt.
- Bob initiates a migration from the old lending router to a new one.
- The migration calls exitPosition with assetToRepay set to type(uint256).max.
- The exit function converts this to zero shares and zero assets because Bob has no debt.
- The Morpho repay function is called with both assets and shares as zero.
- Morpho's repay reverts due to the exactlyOneZero check, causing the migration to fail.
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 you move a loan position from one contract to another, the old contract must repay any debt. Here, the code always tries to repay the maximum possible amount, but if you have no debt, it ends up trying to repay zero. The lending system refuses to process a repayment of zero, so the whole migration fails.
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.