Calculating the amountOutMinimum of swaps onchain allows MEV sandwitch attack on the swap, amountOutMinimum should be supplied as input to the function. Calculating the amountOutMinimum can be handled on the frontend.
The swap logic of the following function calculates the amountOutMinimum onchain.
CurveAdapter.sol#executeSwapExactInputSingle(....)
CurveAdapter.sol#executeSwapExactInput(...)
UniswapV2Adapter.sol#executeSwapExactInputSingle(...)
UniswapV2Adapter.sol#executeSwapExactInput(...)
UniswapV3Adapter.sol#executeSwapExactInputSingle(...)
UniswapV3Adapter.sol#executeSwapExactInput(...)
Calculating amountOutMinimum onchain is worthless because:
The MEV attacker bots will have adjusted the price of the pool by frontrunning
After the price adjustment, then calculation of amountOutMinimum is done when executing the swap
Attacker back runs the swap to sell back to the pool to make profit
So the amountOutMinimum will be calculated from the state of an already manipulated pool before in the swap transaction. That is why it is better to calculate the amountOutMinimum offchain then passed to the swap function. Calculation of `amountOutMinimum can be handled on the frontend just like it is done on swap dapps like Uniswap.
Sandwich attack by MEV bots to adjust the price in a frontrunning attack and sell back to the pool after the swap there by making profit from the adjusted price. The swap buys the loss from adjusted price.
Manual Review
Consider passing amountOutMinimum as input to the swap function. This amountOutMinimum can calculated on the frontend before sending the transaction.
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.