-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a huge loss of funds for all the users who try to remove liquidity after swapping got disabled at manipulated price . #22
Comments
Seems to have too many hand wavy hypotheticals |
0xRobocop marked the issue as insufficient quality report |
Intended behaviour / design that this check is not performed in this state which can only be set by the |
OpenCoreCH changed the severity to QA (Quality Assurance) |
Hi @OpenCoreCH
|
This previously downgraded issue has been upgraded by OpenCoreCH |
This issue, #135, and #174 all deal with the withdrawal fees for safe withdrawals. #135 does so from a different perspective (and suggests a different solution), but the underlying issue is still the same. The issue demonstrates that there can be edge cases where a very high fee is charged, I am therefore upgrading it to a medium. |
OpenCoreCH marked the issue as primary issue |
OpenCoreCH marked the issue as selected for report |
enthusiastmartin (sponsor) disputed |
enthusiastmartin (sponsor) acknowledged |
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/omnipool/src/lib.rs#L1330-L1360
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/omnipool/src/lib.rs#L743
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/omnipool/src/lib.rs#L759-L764
Vulnerability details
Impact
this vulnerability will lead to huge loss of funds for liquidity providers that want to withdraw their liquidity if the safe withdrawal is enabled .
Proof of Concept
Normal Scenario of manipulating price and disabling removing or adding liquidity
If the price of certain asset got manipulated , there is an ensure function exist in the
remove_liquidity()
here andadd_liquidity()
here , so the function should revert in case of the price of an asset got manipulated .This
ensure_price()
function checks that the difference between spot price and oracle price is not too high , so it has critical role to prevent the profitability from this manipulation .There is also another security parameter which is the Tradability state which can prevent removing or adding liquidity .
And there is
withdrawal_fee
which is used to make manipulating price not profitable , and it can prevent the attacker from getting any of assets if the price difference is too high .Important assumption
the assumption is that the withdrawal can be done safely without checking the price difference because the swapping of this asset got disabled so the price is stable .
as shown here
Edge case
Due to the fact that there is not limitation on setting tradability states to any asset except the
hub_asset
, the tradability state can be set to prevent swapping on asset at manipulated price , by make the tradability state only contains remove and add liquidity flags , when the difference between spot price and the oracle price is too high .In such case the
remove_liquidity()
function will not revert with price error because the functionensure-price()
will not work , but it will pass and thewithdrawal_fee
will be equal to 1 .So 100% of the liquidity to be removed will be taken from the user as fees and will be distributed on the other liquidity providers .
how this vulnerability can be applied :
the normal Scenario here is that the remove_liquidity function should revert instead of taking all user assets as
withdrawal_fee
the code that calculate the withdrawal fee is
the delta assets that send to the user will be zero in case that withdrawal_fee is 1
Tools Used
vs code and manual review
Recommended Mitigation Steps
this vulnerability can be mitigated by only one step :
https://github.com/code-423n4/2024-02-hydradx/blob/603187123a20e0cb8a7ea85c6a6d718429caad8d/HydraDX-node/pallets/omnipool/src/lib.rs#L1330-L1361
consider modifying
set_asset_tradable_state()
function to ensure that if the state is set to preventing swapping , then ensure the priceAssessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: