A single external protocol can DOS rebalancing process
The rebalancing process in Notional V3 would revert entirely if any single external money market call failed, preventing the protocol from moving funds out of a vulnerable or underperforming market. An attacker or external failure could thus block rebalancing, potentially leading to fund loss or missed yield.
Source: https://github.com/sherlock-audit/2023-03-notional-judging/issues/175
Found by
0xGoodess, chaduke, xiaoming90 + 0xleastwood
Summary
A failure in an external money market can DOS the entire rebalance process in Notional.
Vulnerability Detail
File: ProportionalRebalancingStrategy.sol
23: function calculateRebalance(
24: IPrimeCashHoldingsOracle oracle,
25: uint8[] calldata rebalancingTargets
26: ) external view override onlyNotional returns (RebalancingData memory rebalancingData) {
27: address[] memory holdings = oracle.holdings();
..SNIP..
40: for (uint256 i; i < holdings.length;) {
41: address holding = holdings[i];
42: uint256 targetAmount = totalValue * rebalancingTargets[i] / uint256(Constants.PERCENTAGE_DECIMALS);
43: uint256 currentAmount = values[i];
44:
45: redeemHoldings[i] = holding;
46: depositHoldings[i] = holding;
..SNIP..
61: }
62:
63: rebalancingData.redeemData = oracle.getRedemptionCalldataForRebalancing(redeemHoldings, redeemAmounts);
64: rebalancingData.depositData = oracle.getDepositCalldataForRebalancing(depositHoldings, depositAmounts);
65: }
During a rebalance, the ProportionalRebalancingStrategy will loop through all the holdings and perform a deposit or redemption against the external market of the holdings.
Assume that Notional integrates with four (4) external money markets (Aave V2, Aave V3, Compound V3, Morpho). In this case, whenever a rebalance is executed, Notional will interact with all four external money markets.
File: TreasuryAction.sol
304: function _executeDeposits(Token memory underlyingToken, DepositData[] memory deposits) private {
..SNIP..
316: for (uint256 j; j < depositData.targets.length; ++j) {
317: // This will revert if the individual call reverts.
318: GenericToken.executeLowLevelCall(
319: depositData.targets[j],
320: depositData.msgValue[j],
321: depositData.callData[j]
322: );
323: }
File: TokenHandler.sol
357: function executeMoneyMarketRedemptions(
..SNIP..
373: for (uint256 j; j < data.targets.length; j++) {
374: // This will revert if the individual call reverts.
375: GenericToken.executeLowLevelCall(data.targets[j], 0, data.callData[j]);
376: }
However, as long as one external money market reverts, the entire rebalance process will be reverted and Notional would not be able to rebalance its underlying assets.
The call to the external money market can revert due to many reasons, which include the following:
- Changes in the external protocol's interfaces (e.g. function signatures modified or functions added or removed)
- The external protocol is paused
- The external protocol has been compromised
- The external protocol suffers from an upgrade failure causing an error in the new contract code.
Impact
Notional would not be able to rebalance its underlying holding if one of the external money markets causes a revert. The probability of this issue occurring increases whenever Notional integrates with a new external money market
The key feature of Notional V3 is to allow its Treasury Manager to rebalance underlying holdings into various other money market protocols.
This makes Notional more resilient to issues in external protocols and future-proofs the protocol. If rebalancing does not work, Notional will be unable to move its fund out of a vulnerable external market, potentially draining protocol funds if this is not mitigated.
Another purpose of rebalancing is to allow Notional to allocate Notional V3’s capital to new opportunities or protocols that provide a good return. If rebalancing does not work, the protocol and its users will lose out on the gain from the investment.
On the other hand, if an external monkey market that Notional invested in is consistently underperforming or yielding negative returns, Notional will perform a rebalance to reallocate its funds to a better market. However, if rebalancing does not work, they will be stuck with a suboptimal asset allocation, and the protocol and its users will incur losses.
Code Snippet
Tool used
Manual Review
Recommendation
Consider implementing a more resilient rebalancing process that allows for failures in individual external money markets. For instance, Notional could catch reverts from individual money markets and continue the rebalancing process with the remaining markets.
Discussion
jeffywu
Fixed: https://github.com/notional-finance/contracts-v2/pull/117
0xleastwood
@0xleastwood + @xiaoming9090: The MM redemption failure has been handled in PR https://github.com/notional-finance/contracts-v2/pull/117 so that a single redemption failure/revert will not DOS the entire rebalance process. However, it was observed that a single failure/revert when depositing into MMs will still DOS the entire rebalance process. Thus, this issue is partially fixed.
jeffywu
@0xleastwood, having the contract revert during deposits on a single money market is intended here. Our reasoning is that it is always safer to hold underlying funds rather than put them on money markets and forgo the additional yield. Therefore, redemptions will always succeed as much as possible, but deposits will fail. The effect here is that the contract will always hold excess underlying if there are any money market failures, sort of like automatically going into "safe mode" if anything is reverting.
Furthermore, having deposits succeed but redemptions fail will cause issues with calculations of how much to deposit and redeem if the contract is attempting to go from one money market (which fails redemption) and another money market (where we try to deposit funds that were never redeemed). We decided the added complexity here was not worth the additional benefit.
0xleastwood
@0xleastwood, having the contract revert during deposits on a single money market is intended here. Our reasoning is that it is always safer to hold underlying funds rather than put them on money markets and forgo the additional yield. Therefore, redemptions will always succeed as much as possible, but deposits will fail. The effect here is that the contract will always hold excess underlying if there are any money market failures, sort of like automatically going into "safe mode" if anything is reverting.
Furthermore, having deposits succeed but redemptions fail will cause issues with calculations of how much to deposit and redeem if the contract is attempting to go from one money market (which fails redemption) and another money market (where we try to deposit funds that were never redeemed). We decided the added complexity here was not worth the additional benefit.
I agree that this is the correct and is the most safe approach. Consider the case where the desired portions of MMs is (AAVE, Compound, Morpho) at (30%, 30%, 40%) and it is currently at (40%, 40%, 20%). 20% would be redeemed from Morpho and 10% would be deposited into AAVE and Compound. Handling redemptions failures by skipping the deposit step makes sense to keep underlying funds available and "safe".
However, we are not actually adhering to this idea of safety where in the example provided, a Morpho MM redemption succeeds but we are unable to deposit 10% of funds into AAVE. Ultimately, we should silently handle a failed MM deposit as we are effectively keeping funds available that way.
0xleastwood
Otherwise, we are keeping the same dependency on protocols being able to DoS the rebalancing process. Priority should be made to keep funds available by allowing MMs to always redeem but preventing any single MM from DoS'ing via deposit.
0xleastwood
Circling back to this, it appears that reverts are already handled correctly. The comment on this line made it seem that this was not the case.
0xleastwood
@0xleastwood + @xiaoming9090: Verified. Fixed in https://github.com/notional-finance/contracts-v2/pull/117
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 rebalancing logic did not handle individual external call failures, so a revert in any single money market call caused the entire transaction to revert.
Impact
If one external money market reverts, Notional cannot rebalance its holdings, potentially leaving funds in a vulnerable or underperforming market and causing losses; the fix was partial, as deposit failures still revert by design.
What the attacker needed
Notional integrates with multiple money markets; One external money market call reverts
The fix
The redemption failure was fixed to skip failed markets, but deposit failures still revert intentionally as a safety measure.
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.
Notional is a DeFi protocol that spreads its funds across several external money markets to earn interest. To adjust these allocations, it runs a 'rebalance' that calls each market to deposit or withdraw. The bug was that if any one of those calls failed, the whole rebalance would fail, leaving funds stuck in a bad market.
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.