The Standard

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

swap() function should check whether loan is `fullyCollateralised()`

Summary

Under collaterized Vault trying to make a swap() will always fail, this is why they should the swap() function should check whether the loan is fully collaterized.

Vulnerability Details

When performing a swap the amountOutMinimum is calculated based on the requiredCollateralValue - collateralValueMinusSwapValue.

https://github.com/Cyfrin/2023-12-the-standard/blob/91132936cb09ef9bf82f38ab1106346e2ad60f91/contracts/SmartVaultV3.sol#L215-L216

return collateralValueMinusSwapValue >= requiredCollateralValue ?
0 : calculator.eurToToken(getToken(_outTokenSymbol), requiredCollateralValue - collateralValueMinusSwapValue);

Which means that if a position is undercollaterized the swap cannot ever hope to be successful as the requested amountOutMinimum will exceed the market value of the amountIn.
Considering the fees from uniswap fee and the swapFees, we should expect the value of amountOutMinimum to be in EUROs lower than the amountIn value in EUROs. This is why attempting a swap() while not have the required collateral is just a waste of gas and should be avoided.

Impact

The impact is not severe as it is in the protocol design not to allow a position to go below the collaterization rate after a swap(), however if the loan is under collaterized then swaps shouldn't even be attempted, as they will always revert.

Tools Used

Manual review

Recommendations

Add a check that makes sure that no swap() are attempted whilst the position is undercollaterized.

function swap(bytes32 _inToken, bytes32 _outToken, uint256 _amount) external onlyOwner {
@> require(!undercollateralised(), "err-under-collaterized");
uint256 swapFee = _amount * ISmartVaultManagerV3(manager).swapFeeRate() / ISmartVaultManagerV3(manager).HUNDRED_PC();
address inToken = getSwapAddressFor(_inToken);
uint256 minimumAmountOut = calculateMinimumAmountOut(_inToken, _outToken, _amount);
Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

informational/invalid

Support

FAQs

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