The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: medium
Invalid

Swapping of tokens have very high slippage in swap()

Summary

While swapping of token in SmartVault::swap, user can receive less token than expected because minimumAmountOut is set very low, if user have minted euros and collateralValueMinusSwapValue is less than requiredCollateralValue

Vulnerability Details

Swapping of token takes minimumAmountOut, This is calculated in calculateMinimumAmountOut() which is calculating minimumAmountOut based on requiredCollateralValue & collateralValueMinusSwapValue. if collateralValueMinusSwapValue is less than requiredCollateralValue then minimumAmountOut is calculator.eurToToken(getToken(_outTokenSymbol), requiredCollateralValue - collateralValueMinusSwapValue)

function calculateMinimumAmountOut(bytes32 _inTokenSymbol, bytes32 _outTokenSymbol, uint256 _amount) private view returns (uint256) {
ISmartVaultManagerV3 _manager = ISmartVaultManagerV3(manager);
uint256 requiredCollateralValue = minted * _manager.collateralRate() / _manager.HUNDRED_PC();
uint256 collateralValueMinusSwapValue = euroCollateral() - calculator.tokenToEur(getToken(_inTokenSymbol), _amount);
@> return collateralValueMinusSwapValue >= requiredCollateralValue ?
0 : calculator.eurToToken(getToken(_outTokenSymbol), requiredCollateralValue - collateralValueMinusSwapValue);
}

Now this is an issue because if user have high collateral but minted less token and wanted to swap for a large amount, then in that case minimumAmountOut is very low as compare to amount that is being swapped for

// Here is the POC

  1. Bob deposited 6000 euro worth of collateral

  2. MaxMintable will be 5000 euros at 120% collateral rate

  3. Bob minted 2000 euros and wanted to swap for his 5000 euro worth of collateral

  4. minimumAmountOut will be only 1400 euro worth of collateral as collateralValueMinusSwapValue = 1000( 6000-5000 ) is less than requiredCollateralValue = 2400(2000*120/100). So minimumAmountOut is calculated based on calculator.eurToToken(getToken(_outTokenSymbol), requiredCollateralValue - collateralValueMinusSwapValue)

  5. Now, this 1400 is very less than as compared to 5000(which is being swapped for) ie 72% less and this is just an example as this number can go up&down depending upon no. of minted euros and amount of collateral being swapped for

Impact

Users will receive less amount than expected

Tools Used

Manual Review

Recommendations

Take consideration of amount of token being swapped for while calculating minimumAmountOut

Updates

Lead Judging Commences

hrishibhat Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

Slippage-issue

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

Slippage-issue

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.