sherlock-audit / 2023-04-unitasprotocol-judging

4 stars 3 forks source link

okolicodes - No Slippage Parameter where the `Minimum of tokens` to get after a `swap` is done is set to `zero` by default, `swaps` are prone to `sandwich attacks`. #131

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

okolicodes

high

No Slippage Parameter where the Minimum of tokens to get after a swap is done is set to zero by default, swaps are prone to sandwich attacks.

Line with Bug

Summary

The amount of EMCs(eg USD1, USD91) minted and received by a user when swapping with their collateral/USD/(other EMCs), can be decreased to an unlimited extent by manipulating the reserves of the pool leading to the user getting fewer EMCs(eg USD1, USD91) than requested.

Vulnerability Detail

This issue is in the Unitas.sol contract at the swap function.

      function swap(address tokenIn, address tokenOut, AmountType amountType, uint256 amount)
        external
        whenNotPaused
        nonReentrant
        returns (uint256 amountIn, uint256 amountOut)
    {

There is no parameter that allows a user to set the minimum amount of EMCs they should get after swapping their collateral for EMCs, and in a situation like this the slippage is set to zero by default meaning the user can get as low as zero amount of EMCs for any amount of collateral/Tokens, which will lead to loss of funds. POC Here a user is expected send collateral/Tokens to the pool and the equivalent amount of EMCs are minted and to be sent to the user. However, the user can’t specify the minimum amount of EMCs that they would accept. A frontrunner/MEV can then manipulate the reserves of the pool via FLASHLOANS in order to make the reserves appear more valuable than it really is so the user receives EMCs that are worth much less than what collateral is worth.

Impact

Users who trying to swaps the funds for EMCs, are left unprotected from slippage attacks as they could get as low as zero amount of EMCs when the swap with their tokens. leading to loss of funds due to MEV/FlashLoan attacks

Code Snippet

Manual Review

Recommendation

Add an argument for the minimum amount of tokens to get after a swap for an equivalent collateral/Tokens to enable the users secure themselves against such attacks.

Duplicate of #88