Open github-actions[bot] opened 1 year ago
The caller can specify the target price using the sqrtPriceLimitX96
parameter to the rebalanceLite
function. This offers slippage protection.
Escalate for 10 USDC
I suggest the judge and the sponsor read this issue carefully again.
The key problem is that the Perp protocol can partially fill the position, especially when the sqrtPriceLimitX96
is specified.
(This is related to how Uniswap works, check here)
So it is possible that the order is not placed to the full amount and the remaining amount should be returned to the user.
I admit that my explanation sounded vague because I mentioned slippage.
I mean, the protocol should return the remaining value or allow the user to explicitly specify the minimum output amount.
Please check the screenshot of the chat I had with the Perp team.
They confirmed it is possible that the order is not filled to the full amount when the sqrtPriceLimitX96
is specified.
Escalate for 10 USDC
I suggest the judge and the sponsor read this issue carefully again. The key problem is that the Perp protocol can partially fill the position, especially when the
sqrtPriceLimitX96
is specified. (This is related to how Uniswap works, check here) So it is possible that the order is not placed to the full amount and the remaining amount should be returned to the user. I admit that my explanation sounded vague because I mentioned slippage. I mean, the protocol should return the remaining value or allow the user to explicitly specify the minimum output amount. Please check the screenshot of the chat I had with the Perp team. They confirmed it is possible that the order is not filled to the full amount when thesqrtPriceLimitX96
is specified.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
With the updated comments I agree there is a valid issue here. If the requested amount is not filled completely in the Perp order, we should only transfer from the user the amount returned from the _placePerpOrder()
call.
Escalation accepted.
As pointed out in the Escalation that there is the possibility of partial order fills when sqrtPriceLimitX96 is specified.
Escalation accepted.
As pointed out in the Escalation that there is the possibility of partial order fills when sqrtPriceLimitX96 is specified.
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
Fixed here by removing sqrtPriceLimitX96
in swap when rebalancing
https://github.com/UXDProtocol/uxd-evm/pull/24
hansfriese
medium
rebalanceLite
should provide a slippage protectionSummary
Users can lose funds while rebalancing.
Vulnerability Detail
The protocol provides two kinds of rebalancing functions -
rebalance()
andrebalanceLite()
. While the functionrebalance()
is protected from an unintended slippage because the caller can specifyamountOutMinimum
,rebalanceLite()
does not have this protection. This makes the user vulnerable to unintended slippage due to various scenarios.Especially, according to the communication with the PERP dev team, it is possible for the Perp's ClearingHouse to fill the position partially when the price limit is specified (
sqrtPriceLimitX96
). It is also commented in the Perp contract comments here.So it is possible that the order is not placed to the full amount. As we can see in the #L626~#L628, the UXD protocol grabs the quote token of
amount
and deposits to the Perp's vault. And the unused amount will remain in the Perp vault while this is supposed to be returned to the user who called this rebalance function.Impact
Users can lose funds while lite rebalancing.
Code Snippet
https://github.com/sherlock-audit/2023-01-uxd/blob/main/contracts/integrations/perp/PerpDepository.sol#L597
Tool used
Manual Review
Recommendation
Add a protection parameter to the function
rebalanceLite()
so that the user can specify the minimum out amount.