-
Notifications
You must be signed in to change notification settings - Fork 0
stopthecap - Incorrect calculation of the slippage when reducing positions . #14
Comments
Duplicate of #120 |
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. |
Escalate for 10 USDC |
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. |
Recommendation:
Loss is limited, no material loss of fund, medium is appropriate |
same as above |
Agree with @twicek . After reviewing I believe medium is the correct severity. Thanks |
Result: |
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.
Unstoppable
calculates theslippage (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 thereduce_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
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
Duplicate of #120
The text was updated successfully, but these errors were encountered: