Excess funds withdrawn from the money market
The contract withdraws the full requested amount from the money market even when it already holds part of the balance, causing excess funds to be pulled and sit idle. An attacker could exploit this to drain invested funds, causing griefing and loss of interest for the protocol.
Source: https://github.com/sherlock-audit/2023-03-notional-judging/issues/193
Found by
bin2chen, chaduke, iglyx, mstpr-brainbot, xiaoming90 + 0xleastwood
Summary
Excessive amounts of assets are being withdrawn from the money market.
Vulnerability Detail
File: TokenHandler.sol
256: function _redeemMoneyMarketIfRequired(
257: uint16 currencyId,
258: Token memory underlying,
259: uint256 withdrawAmountExternal
260: ) private {
261: // If there is sufficient balance of the underlying to withdraw from the contract
262: // immediately, just return.
263: mapping(address => uint256) storage store = LibStorage.getStoredTokenBalances();
264: uint256 currentBalance = store[underlying.tokenAddress];
265: if (withdrawAmountExternal <= currentBalance) return;
266:
267: IPrimeCashHoldingsOracle oracle = PrimeCashExchangeRate.getPrimeCashHoldingsOracle(currencyId);
268: // Redemption data returns an array of contract calls to make from the Notional proxy (which
269: // is holding all of the money market tokens).
270: (RedeemData[] memory data) = oracle.getRedemptionCalldata(withdrawAmountExternal);
271:
272: // This is the total expected underlying that we should redeem after all redemption calls
273: // are executed.
274: uint256 totalUnderlyingRedeemed = executeMoneyMarketRedemptions(underlying, data);
275:
276: // Ensure that we have sufficient funds before we exit
277: require(withdrawAmountExternal <= currentBalance.add(totalUnderlyingRedeemed)); // dev: insufficient redeem
278: }
If the currentBalance is 999,900 USDC and the withdrawAmountExternal is 1,000,000 USDC, then there is insufficient balance in the contract, and additional funds need to be withdrawn from the money market (e.g. Compound).
Since the contract already has 999,900 USDC, only an additional 100 USDC needs to be withdrawn from the money market to fulfill the withdrawal request of 1,000,000 USDC
However, instead of withdrawing 100 USDC from the money market, Notional withdraw 1,000,000 USDC from the market as per the oracle.getRedemptionCalldata(withdrawAmountExternal) function. As a result, an excess of 990,000 USDC is being withdrawn from the money market
Impact
This led to an excessive amount of assets idling in Notional and not generating any returns or interest in the money market, which led to a loss of assets for the users as they would receive a lower interest rate than expected and incur opportunity loss.
Attackers could potentially abuse this to pull the funds Notional invested in the money market leading to griefing and loss of returns/interest for the protocol.
Code Snippet
Tool used
Manual Review
Recommendation
Consider withdrawing only the shortfall amount from the money market.
- (RedeemData[] memory data) = oracle.getRedemptionCalldata(withdrawAmountExternal);
+ (RedeemData[] memory data) = oracle.getRedemptionCalldata(withdrawAmountExternal - currentBalance);
Discussion
jeffywu
Valid Issue
jeffywu
Fixed: https://github.com/notional-finance/contracts-v2/pull/125
xiaoming9090
@0xleastwood + @xiaoming9090 : Verified. Fixed in PR https://github.com/notional-finance/contracts-v2/pull/125.
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 code passes the full withdrawal amount to the redemption function instead of subtracting the contract's existing balance.
Impact
Excess assets sit idle in Notional, reducing interest for users, and an attacker could potentially pull invested funds to cause griefing and loss of returns.
What the attacker needed
Ability to trigger a withdrawal
The fix
The issue was fixed by withdrawing only the shortfall amount from the money market.
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 ask to take out money, the system should only take the missing amount from the external savings pool. Here it took the whole amount from the pool even though some cash was already on hand, leaving too much cash idle and earning no interest. This could be abused to pull out funds that were meant to be invested.
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.