Users can lose up to 100% of their funds when removing liquidity #97
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-93
🤖_16_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2024-02-hydradx/blob/main/HydraDX-node/pallets/omnipool/src/lib.rs#L745-L753
https://github.com/code-423n4/2024-02-hydradx/blob/main/HydraDX-node/pallets/omnipool/src/lib.rs#L759-L764
https://github.com/code-423n4/2024-02-hydradx/blob/main/HydraDX-node/math/src/omnipool/math.rs#L288-L307
Vulnerability details
Impact
There is no slippage protection when removing liquidity. An attacker can manipulate the spot price of an asset to increase the withdrawal fees (up to 100%) for other users before they withdraw their funds.
This will result in a partial or total loss of funds, depending on how much the spot price is increased in comparison to the oracle price.
Proof of Concept
When removing liquidity, there are some checks to ensure that the price delta between the oracle and the spot price falls within 1%. This also normally serves as a "slippage" protection, as the transaction will fail when these prices differ too much.
However, when trading is disabled for an asset (i.e.
safe_withdrawal = true
), the price difference check is skipped:Nevertheless, the
withdrawal_fee
will be calculated using the delta between oracle price and spot price:This is the function that will calculate the withdrawal fee:
Which is the price delta % between spot and oracle price, capped between
min_fee
and100%
.Let's assume that an attacker frontruns the transaction to manipulate the spot price (even if difficult, this is possible on substrate).
If the new spot price is at least twice the amount of the oracle price, the withdrawal fee for the victim will be 100% of their liquidity, leading to a total loss of funds.
Afterward, the liquidity received by the user will be calculated as
delta_reserve
:Finally, the user receives zero funds for their shares:
Recommended Mitigation Steps
Consider implementing some slippage protection when removing liquidity.
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: