sherlock-audit / 2023-10-real-wagmi-judging

16 stars 14 forks source link

newt - Users cannot swap token1 for token0 #74

Closed sherlock-admin2 closed 11 months ago

sherlock-admin2 commented 11 months ago

newt

medium

Users cannot swap token1 for token0

Summary

The function only helps pay for amount0delta(token0) swaps. It does not help a user pay or rather find the change in token1 balance resulting from the swap.

Vulnerability Detail

The function reverts if the amount entered is smaller or equals to 0 for amount0Delta and amount1Delta L247. The probelm is when in order to make payments(swap) for amount1Delta(token1) the amount for amount0Delta must be smaller than 0 in the below code snippet

Impact

A user can only swap for token0 and not token1

Code Snippet

    uint256 amountToPay = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
    _pay(tokenIn, address(this), msg.sender, amountToPay);

https://github.com/sherlock-audit/2023-10-real-wagmi/blob/main/wagmi-leverage/contracts/abstract/ApproveSwapAndPay.sol#L242C1-L258C6

Tool used

Manual Review

Recommendation

Include && in the if statement for amount1delta

sherlock-admin2 commented 11 months ago

1 comment(s) were left on this issue during the judging contest.

tsvetanovv commented:

Invalid. Тhe function works as it should