safe_withdrawal does not correctly protect against frontrunning #16
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
duplicate-22
🤖_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#L743-L753
Vulnerability details
Bug Description
The HydraDx Protocol's Omnipool functionality is designed to safeguard users against front-running attacks during liquidity withdrawals. It employs a check against price deviations exceeding 1% from the oracle-provided average price. This mechanism is intended to revert transactions if such deviations occur, potentially due to front-running. However, the introduction of a
safe_withdrawal
boolean parameter compromises this protection under certain conditions. Thesafe_withdrawal
flag is set to true when the authority disables market trading, based on the assumption that front-running is not possible without active trading.The flaw arises if an attacker identifies transactions aimed at withdrawing liquidity alongside an authority's decision to suspend trading. By front-running these transactions and manipulating the price before trading is halted, the attacker can exploit the
safe_withdrawal
condition. This allows the withdrawal to proceed without doing the 1% deviation check, leading to potential greater losses.This mechanism is predicated on the notion that disabling trading removed the possibility of front-running. Nonetheless, this overlooks the brief window wherein transactions are visible but unexecuted, allowing an attacker to manipulate prices prior to the trading halt.
Impact
This oversight reverses the intended effect of the
safe_withdrawal
mechanism. Far from offering protection against front-running, it facilitates more severe exploitation by attackers during the interim between the detection of liquidity withdrawal transactions and the enforcement of trading restrictions.Proof of Concept
Consider a scenario where an attacker observes a pending liquidity withdrawal transaction together with an authority call to disable trading. The attacker can front-run both transactions to significantly alter the market price before the trading halt is enacted. Once trading is suspended and the
safe_withdrawal
flag is engaged, the original withdrawal transaction proceeds without the protective price deviation check.To run the test it needs to be added to the
omnipool/src/tests/remove_liquidity.rs
file.Tools Used
Manual Review
Recommended Mitigation Steps
To address this vulnerability, it's advisable to eliminate the
safe_withdrawal
flag, ensuring continuous protection against price manipulation and front-running, regardless of trading status. This adjustment will maintain the integrity of the liquidity withdrawal process, safeguarding users from potential exploitation.Assessed type
MEV
The text was updated successfully, but these errors were encountered: