Incorrect _amountOutMinimum
calculation cause vault loss fund when swap tokens.
UniswapSwap#swapExactTokensForTokens and TraderJoeSwap#swapExactTokensForTokens is used as swap tokens by GMXCompound#compound, vi call: GMXCompound#compound -> GMXManager.swapExactTokensForTokens -> GMXWorker.swapTokensForExactTokens -> swapRouter.swapTokensForExactTokens
, before actually swap, swapRouter calculate _amountOutMinimum
as below:
However, the _amountOutMinimum
is not correct because different token has different decimal.
Image such condition: keeper want to compound with 1800 usdc
, sp.tokenA = USDC, sp.tokenB = WETH
, slippage = 1%
, so the expected swap result is 0.99 WETH
.
Following poc show the calculation result:
Results:
Obviously, It's much smaller than expected result, so those swap txs can be sandwiched by MEV.
Protocol may loss fund when swap tokens.
vscode, Manual Review
Change uint256 _valueIn = sp.amountIn * oracle.consultIn18Decimals(sp.tokenIn) / SAFE_MULTIPLIER;
inside swapRouter#swapExactTokensForTokens
to uint256 _valueIn = sp.amountIn * oracle.consultIn18Decimals(sp.tokenIn) / 10 ** IERC20Metadata(sp.tokenIn).decimals()
.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.