The SmartVaultV3.swap
function lacks slippage protection, making it vulnerable to sandwich attacks, potentially leading to the loss of swapped locked collateral tokens.
In some cases the SmartVaultV3.swap()
function uses amountOutMinimum
and sqrtPriceLimitX96
set to 0, enabling MEV or sandwich attacks.
From Uniswap's documentation:
amountOutMinimum
is advised to be non-zero in production to safeguard against price manipulation.
sqrtPriceLimitX96
being zero deactivates this parameter. In production, it should be set to manage price impact and facilitate other price-related mechanisms.
The SmartVaultV3.swap()
function, callable by the vault owner, internally calls calculateMinimumAmountOut to calculate amountOutMinimum
based on collateral value and swap token value. If the locked collateral tokens' value - the swapped token value exceeds requiredCollateralValue, the function returns 0. For example, this can happen when the ETH price bumps. This lack of slippage protection is critical, particularly when the value of tokens like ETH rises sharply.
A potential attack involves using a flash loan to manipulate the WETH/USDC pool on Uniswap, allowing the attacker to drain all USDC from the SmartVaultV3 contract. This method can also target other ERC-20 tokens in the contract.
For instance, to drain all USDC, consider the following proof-of-concept:
The attacker borrows a flash loan in USDC and buys WETH from Uniswap's WETH/USDC pool.
The attacker executes the SmartVaultV3.swap
function with USDC.
The SmartVaultV3.swap
will use all the locked USDC to buy WETH at a very high price.
The attacker then sells the previously obtained WETH for USDC in the same pool and repays the flash loan.
The attacker takes all the locked USDC as profit.
Place this test in the smartVault.js
file and execute it by POC: slippage, amountOutMinimum = 0
Furthermore, the deadline
parameter is set to block.timestamp
, allowing token swaps at any block number without an expiration deadline.
Another concern is the constant pool fee
of 3000 (0.3%). This inflexibility could lead to liquidity shifts and higher MEV attack risks due to lower liquidity tiers.
This vulnerability, particularly during a significant price increase of locked collateral tokens, allows an attacker to deplete the SmartVaultV3
of various cryptocurrencies. It's considered a high-risk issue due to specific required conditions but can lead to substantial financial losses.
Additionally, without an expiration deadline, miners or validators could manipulate transactions for their benefit, increasing the risk of fund loss due to slippage.
Manual Review
To mitigate this vulnerability, it's advised not to use 0 as amountOutMinimum
during swaps.
Given that the swap
function is restricted to the vault owner, they should be able to set parameters like amountOutMinimum
, sqrtPriceLimitX96
, deadline
, and fee
to enhance security and control slippage.
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.