SmartVaultV3.swap has bad slippage protection which can lead to loss of user's funds.
Using SmartVaultV3.swap
function user can swap one collateral token for another.
calculateMinimumAmountOut
function is responsible to calculate slippage amount.
https://github.com/Cyfrin/2023-12-the-standard/blob/main/contracts/SmartVaultV3.sol#L206-L212
The main logic of this function is next: after the swap, vault should have not less than requiredCollateralValue
, which is amount to collateralize minted
tokens. So in case if even without swap amount contract has enough collateral, then function doesn't care about slippage and set it to 0. Otherwise it set it to the amount that is needed to reach collateralization.
Such approach is not good and allows sandwhich attacks against such swap. Result of this will be collateral loss for the vault's owner.
Swap is not protected against sandwhich attack
VsCode
Allow user to provide slippage for the swap. And then validate it to still be fully collateralized.
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.