`TradingUtils::_executeTrade` will leak ETH to WETH
When selling ETH through Uniswap in an exact-out trade, the code deposits the full limit amount as WETH but only part is used, and the excess is not recovered. This causes the reported amountSold to be wrong and may lock ETH in the contract.
Source: https://github.com/sherlock-audit/2022-09-notional-judging/issues/98
Found by
lemonmon
Summary
If sellToken is ETH, and using Uniswap for the dex, and it is exact out trade, too much is deposited to the WETH and does not withdraw the excess amount. It will give wrong amountSold value as well as accounting error.
Vulnerability Detail
trade.sellToken is ETH and using Uniswap as dex, WETH should be used instead of ETH as Uniswap does not support ETH. There for TradingUtils wraps the ETH to WETH before trading.
If the trade would be exact out, the amount trade.limit will be deposited to WETH instead of the trade.amount. However, because it is exact out, not all ETH deposited will be traded. In the current implementation, there is no logic to recover the excess deposit.
As the TradingUtils::_executeInternal, which uses the TradingUtils::_executeTrade will calculate the amountSold based on the balance of ETH, it will return the trade.limit as the amountSold, thus resulting in accounting error.
Note: in the current implementation, the trade using Uniswap with ETH as sellToken would not even work, because the WETH is not properly approved (issue 2). This issue assumes that the issue is resolved.
Impact
amountSold will reflect not the amount really sold, rather the trade.limit. It is unclear whether the excess amount of ETH, which is deposited for WETH can be recovered.
Code Snippet
Tool used
Manual Review
Recommendation
In the _executeTrade, if the sellToken is ETH and it is exact out trade, recover excess deposit.
Discussion
jeffywu
@Evert0x I don't think this is a duplicate of #110
weitianjie2000
legit issue, will be fixed
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 code deposits the full trade.limit as WETH for exact-out trades but lacks logic to recover the unused excess.
Impact
The amountSold value is incorrect and the excess ETH deposited as WETH may not be recoverable.
What the attacker needed
SellToken is ETH; Uniswap is used as the DEX; trade is exact out
The fix
The code should be fixed to recover the excess deposit when selling ETH in an exact-out trade.
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.
In a trade where you ask for a specific amount of output (exact out), the code wraps more ETH into WETH than needed. The extra WETH is not returned, so the trade reports the wrong amount sold and the extra ETH may be stuck.
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.