UniV2Adapter#getExecutionData doesn't properly handle native ETH swaps
The Uniswap V2 adapter in Notional's leveraged vaults builds swap calldata using only token-to-token router functions, which cannot handle native ETH, and it does not set the spender and target fields that would let the trade executor wrap ETH automatically. As a result, any Uniswap V2 trade involving native ETH would fail.
Source: https://github.com/sherlock-audit/2022-09-notional-judging/issues/33
Found by
Chom, 0x52
Summary
UniV2Adapter#getExecutionData doesn't properly account for native ETH trades which makes them impossible. Neither method selected supports direct ETH trades, and sender/target are not set correctly for TradingUtils_executeTrade to automatically convert
Vulnerability Detail
spender = address(Deployments.UNIV2_ROUTER);
target = address(Deployments.UNIV2_ROUTER);
// msgValue is always zero for uniswap
if (
tradeType == TradeType.EXACT_IN_SINGLE ||
tradeType == TradeType.EXACT_IN_BATCH
) {
executionCallData = abi.encodeWithSelector(
IUniV2Router2.swapExactTokensForTokens.selector,
trade.amount,
trade.limit,
data.path,
from,
trade.deadline
);
} else if (
tradeType == TradeType.EXACT_OUT_SINGLE ||
tradeType == TradeType.EXACT_OUT_BATCH
) {
executionCallData = abi.encodeWithSelector(
IUniV2Router2.swapTokensForExactTokens.selector,
trade.amount,
trade.limit,
data.path,
from,
trade.deadline
);
}
UniV2Adapter#getExecutionData either returns the swapTokensForExactTokens or swapExactTokensForTokens, neither of with support native ETH. It also doesn't set spender and target like UniV3Adapter, so _executeTrade won't automatically convert it to a WETH call. The result is that all Uniswap V2 calls made with native ETH will fail. Given that Notional operates in native ETH rather than WETH, this is an important feature that currently does not function.
Impact
Uniswap V2 calls won't support native ETH
Code Snippet
Tool used
Manual Review
Recommendation
There are two possible solutions:
- Change the way that target and sender are set to match the implementation in UniV3Adapter
- Modify the return data to return the correct selector for each case (swapExactETHForTokens, swapTokensForExactETH, etc.)
Given that the infrastructure for Uniswap V3 already exists in TradingUtils_executeTrade the first option would be the easiest, and would give the same results considering it's basically the same as what the router is doing internally anyways.
Discussion
jeffywu
@weitianjie2000
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 adapter only encodes token-to-token router selectors and leaves spender and target unset, so the executor never converts native ETH to WETH before swapping.
Impact
Uniswap V2 trades using native ETH would fail, which matters because Notional operates in native ETH rather than WETH.
What the attacker needed
Native ETH trade via Uniswap V2 adapter
The fix
It should be fixed by setting target and sender the same way UniV3Adapter does, or by returning the correct ETH-specific router selectors.
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 smart contract adapter is a small piece of code that lets a larger system talk to another service, here the Uniswap V2 exchange. This adapter only knew how to swap one token for another token, not how to swap the network's own currency (ETH), so those trades simply broke. The fix is to either use the ETH-specific swap functions or set things up so ETH is converted to its token form (WETH) first.
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.