Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

stopthecap - Incorrect calculation of the slippage when reducing positions . #14

Closed
sherlock-admin opened this issue Jul 5, 2023 · 10 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jul 5, 2023

stopthecap

high

Incorrect calculation of the slippage when reducing positions .

Summary

Incorrect calculation of the slippage when reducing positions .

Vulnerability Detail

When reducing a position. Unstoppablecalculates the slippage (min_amount_out) for you if 0 was specified.
The calculation is wrong because when reducing position you are not swapping the whole position amount, that would be done in the close_position function. In the reduce_position function, you have to specify, as a trader, the amount that you want to reduce your position by _reduce_by_amount.

The error relies in the following lines:
https://github.com/sherlock-audit/2023-06-unstoppable/blob/94a68e49971bc6942c75da76720f7170d46c0150/unstoppable-dex-audit/contracts/margin-dex/Vault.vy#L307-L311

    if min_amount_out == 0: 
        min_amount_out = self._market_order_min_amount_out(
            position.position_token, position.debt_token, position.position_amount
        )

The slippage is being calculated with the entire position.position_amount instead of the actual _reduce_by_amount amount. This will cause a wrong slippage to be calculated, getting either a wrong amount back from the swap, or swaps not being able to take place because the slippage amount was to high.

Impact

A wrong slippage will cause users to get an incorrect amount funds back from the swap, or if it is too high, transactions will fail

Code Snippet

https://github.com/sherlock-audit/2023-06-unstoppable/blob/94a68e49971bc6942c75da76720f7170d46c0150/unstoppable-dex-audit/contracts/margin-dex/Vault.vy#L307-L311

Tool used

Manual Review

Recommendation

Change the position.position_amount variable for _reduce_by_amount

    if min_amount_out == 0: 
        min_amount_out = self._market_order_min_amount_out(
            position.position_token, position.debt_token, _reduce_by_amount
        )

Duplicate of #120

@github-actions github-actions bot added the Excluded Excluded by the judge without consulting the protocol or the senior label Jul 10, 2023
@141345
Copy link
Collaborator

141345 commented Jul 14, 2023

Duplicate of #120

@141345 141345 added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label and removed Excluded Excluded by the judge without consulting the protocol or the senior labels Jul 14, 2023
@141345 141345 marked this as a duplicate of #120 Jul 14, 2023
@sherlock-admin2 sherlock-admin2 added the Reward A payout will be made for this issue label Jul 19, 2023
@0xffff11
Copy link
Collaborator

Escalate

This should be a high together with issue #120

@sherlock-admin2
Copy link

Escalate

This should be a high together with issue #120

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin sherlock-admin added the Escalated This issue contains a pending escalation label Jul 19, 2023
@twicek
Copy link

twicek commented Jul 20, 2023

Escalate for 10 USDC
Severity should be medium because it will only prevent position reduction in the worst case since min_amount_out will be higher than expected leading for the swap to revert. There is no loss of funds, in the worst case it reverts.

@sherlock-admin2
Copy link

Escalate for 10 USDC
Severity should be medium because it will only prevent position reduction in the worst case since min_amount_out will be higher than expected leading for the swap to revert. There is no loss of funds, in the worst case it reverts.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@141345
Copy link
Collaborator

141345 commented Jul 23, 2023

Recommendation:
keep the original judging.

Escalate

This should be a high together with issue #120

Loss is limited, no material loss of fund, medium is appropriate

@141345
Copy link
Collaborator

141345 commented Jul 23, 2023

Escalate for 10 USDC Severity should be medium because it will only prevent position reduction in the worst case since min_amount_out will be higher than expected leading for the swap to revert. There is no loss of funds, in the worst case it reverts.

same as above

@0xffff11
Copy link
Collaborator

Agree with @twicek . After reviewing I believe medium is the correct severity. Thanks

@hrishibhat
Copy link
Contributor

hrishibhat commented Aug 1, 2023

Result:
Medium
Duplicate of #120

@sherlock-admin2
Copy link

sherlock-admin2 commented Aug 1, 2023

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin sherlock-admin removed the Escalated This issue contains a pending escalation label Aug 1, 2023
@sherlock-admin2 sherlock-admin2 added the Escalation Resolved This issue's escalations have been approved/rejected label Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Escalation Resolved This issue's escalations have been approved/rejected Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

6 participants