The swap function in SmartVaultV3 does not have sufficient slippage protection because minimumAmountOut
can be 0 in certain cases, making the swap vulnerable to MEV attacks.
Let's take a look at the code:
The function passes amountOutMinimum: minimumAmountOut
for slippage protection. Let's see how minimumAmountOut
is calculated:
The function calculates requiredCollateralValue
, which is the amount of collateral that needs to be maintained in the vault.
Then it calculates collateralValueMinusSwapValue
which is the current collateral value in the vault (euroCollateral()) minus the EUR equivalent of the _amount of the input token being swapped.
Then in the case where collateralValueMinusSwapValue
is greater than or equal to requiredCollateralValue
it returns 0 offering no slippage protection to the swap.
The swap will be subject to MEV attacks and will result in unfavorable swapping conditions leading to a loss of funds.
Manual review
You can implement a default slippage protection value that gets returned by the calculateMinimumAmountOut()
function instead of returning 0.
Or you could add a user-specified slippage parameter that gets passed to the calculateMinimumAmountOut()
function and is returned instead of returning 0.
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.