Rebalance will be delayed due to revert
A rebalancing transaction reverts if any currency becomes healthy between the bot's check and execution, preventing other unhealthy currencies from being rebalanced. This can delay rebalancing, leaving excess liquidity lent out and potentially causing withdrawal or liquidation issues due to insufficient liquidity.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-12-notional-update-5-judging/issues/44
Found by
xiaoming90
Summary
The rebalancing of unhealthy currencies will be delayed due to a revert, resulting in an excess of liquidity being lent out in the external market. This might affect the liquidity of the protocol, potentially resulting in withdrawal or liquidation having issues executed due to insufficient liquidity.
Vulnerability Detail
Assume that Notional supports 5 currencies ($A, B, C, D, E$), and the Gelato bot is configured to call the checkRebalance function every 30 minutes.
Assume that the current market condition is volatile. Thus, the inflow and outflow of assets to Notional, utilization rate, and available liquidity at AAVE change frequently. As a result, the target amount that should be externally lent out also changes frequently since the computation of this value relies on the spot market information.
At T1, when the Gelato bot calls the checkRebalance() view function, it returns that currencies $A$, $B$, and $C$ are unhealthy and need to be rebalanced.
Shortly after receiving the execution payload from the checkRebalance(), the bot submits the rebalancing TX to the mempool for execution at T2.
When the rebalancing TX is executed at T3, one of the currencies (Currency $A$) becomes healthy. As a result, the require check at Line 326 will revert and the entire rebalancing transaction will be cancelled. Thus, currencies $B$ and $C$ that are still unhealthy at this point will not be rebalanced.
If this issue occurs frequently or repeatedly over a period of time, the rebalancing of unhealthy currencies will be delayed.
File: TreasuryAction.sol
315: function _rebalanceCurrency(uint16 currencyId, bool useCooldownCheck) private {
316: RebalancingContextStorage memory context = LibStorage.getRebalancingContext()[currencyId];
317: // Accrues interest up to the current block before any rebalancing is executed
318: IPrimeCashHoldingsOracle oracle = PrimeCashExchangeRate.getPrimeCashHoldingsOracle(currencyId);
319: PrimeRate memory pr = PrimeRateLib.buildPrimeRateStateful(currencyId);
320:
321: bool hasCooldownPassed = _hasCooldownPassed(context);
322: (bool isExternalLendingUnhealthy, OracleData memory oracleData, uint256 targetAmount) =
323: _isExternalLendingUnhealthy(currencyId, oracle, pr);
324:
325: // Cooldown check is bypassed when the owner updates the rebalancing targets
326: if (useCooldownCheck) require(hasCooldownPassed || isExternalLendingUnhealthy);
Impact
The rebalancing of unhealthy currencies will be delayed, resulting in an excess of liquidity being lent out to the external market. This might affect the liquidity of the protocol, potentially resulting in withdrawal or liquidation having issues executed due to insufficient liquidity.
Code Snippet
Tool used
Manual Review
Recommendation
If one of the currencies becomes healthy when the rebalance TX is executed, consider skipping this currency and move on to execute the rebalance on the rest of the currencies that are still unhealthy.
function _rebalanceCurrency(uint16 currencyId, bool useCooldownCheck) private {
RebalancingContextStorage memory context = LibStorage.getRebalancingContext()[currencyId];
// Accrues interest up to the current block before any rebalancing is executed
IPrimeCashHoldingsOracle oracle = PrimeCashExchangeRate.getPrimeCashHoldingsOracle(currencyId);
PrimeRate memory pr = PrimeRateLib.buildPrimeRateStateful(currencyId);
bool hasCooldownPassed = _hasCooldownPassed(context);
(bool isExternalLendingUnhealthy, OracleData memory oracleData, uint256 targetAmount) =
_isExternalLendingUnhealthy(currencyId, oracle, pr);
// Cooldown check is bypassed when the owner updates the rebalancing targets
- if (useCooldownCheck) require(hasCooldownPassed || isExternalLendingUnhealthy);
+ if (useCooldownCheck && !hasCooldownPassed && !isExternalLendingUnhealthy) return;
Discussion
sherlock-admin2
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid because { valid medium findings due to the occurrence}
sherlock-admin
The protocol team fixed this issue in PR/commit https://github.com/notional-finance/contracts-v3/pull/32.
sherlock-admin
The Lead Senior Watson signed-off on the fix.
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 function uses a require statement that reverts the entire transaction if any currency is no longer unhealthy, instead of skipping that currency and continuing with the others.
Impact
The rebalancing of unhealthy currencies could be delayed, leading to excess liquidity lent out and potentially causing withdrawal or liquidation issues due to insufficient liquidity.
What the attacker needed
Gelato bot configured to call checkRebalance; Volatile market conditions; Currency becomes healthy between check and execution
The fix
The issue was fixed by changing the require to a return statement so that a healthy currency is skipped and the rest of the rebalancing continues.
How it was found
- The Gelato bot calls checkRebalance and identifies currencies A, B, and C as unhealthy.
- The bot submits a rebalancing transaction to the mempool.
- Before execution, currency A becomes healthy.
- When the transaction executes, the require check for currency A fails and the entire transaction reverts, so currencies B and C are not rebalanced.
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.
A bot regularly checks which currencies need rebalancing and then sends a transaction to fix them. If one currency becomes healthy in the short time between the check and the transaction, the whole transaction fails, so other currencies that still need fixing are not rebalanced. This can leave too much money lent out and cause problems when users try to withdraw.
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.