No safe_withdrawal option in withdraw_protocol_liquidity function in omnipool can be abused by frontrunners to cause losses to the admin when removing liquidity
The withdraw_protocol_liquidity function lacks the safe_withdrawal price check present in remove_liquidity, so an attacker can frontrun the admin's withdrawal and manipulate the spot price to cause slippage losses. The report claims these losses can be much higher than the 2% limit enforced elsewhere.
carrotsmuggler Follow with QiuhaoLi
Originally disclosed on Code4rena
Submitted by carrotsmuggler, also found by QiuhaoLi
The sacrifice_position function can be used by any liquidity provider to hand over their liquidity position to the protocol. The protocol can then choose to remove this liquidity via the withdraw_protocol_liquidity function. This is similar to the remove_liquidity function, but with one key difference. The remove_liquidity function has a safe_withdrawal option, where if trading is ongoing, the price difference is limited to 1% via the ensure_price function. This is not present in the withdraw_protocol_liquidity function.
// remove_liquidity
if !safe_withdrawal {
T::PriceBarrier::ensure_price(
&who,
T::HubAssetId::get(),
asset_id,
EmaPrice::new(asset_state.hub_reserve, asset_state.reserve),
)
.map_err(|_| Error::<T>::PriceDifferenceTooHigh)?;
}
Thus when the admin decides to call withdraw_protocol_liquidity to remove the liquidity, they can be frontrun to eat slippage loss. The admin has to pass in a price parameter, and if the frontrunner manipulates the spot price to be different from the price passed in, the admin will eat losses. A deeper dive and simulation of losses has been done in another issue titled No slippage check in remove_liquidity function in omnipool can lead to slippage losses during liquidity withdrawal where the losses are limited to 2% due to the ensure_price check. However, the losses here can be much higher due to the lack of this check altogether.
Since higher losses can be possible, this is a high severity issue.
Proof of Concept
The ensure_price check is missing from the withdraw_protocol_liquidity function.
Tools Used
Substrate
Recommended Mitigation Steps
Add a safe_withdrawal parameter, or add a minimum_out parameter to limit slippage losses.
Assessed type
MEV
enthusiastmartin (HydraDX) confirmed, but disagreed with severity and commented:
This action is usually performed when trading is paused, it is not permissionless call.
Definitely not high risk, not even medium.
Lambda (judge) decreased severity to Medium and commented:
Medium is more appropriate for missing slippage protection, even if the potential slippage can be larger here. According to the sponsor, the function will usually not be used when trading is enabled. However, this is not enforced, so the issue itself is still valid.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the withdraw_protocol_liquidity function omits the safe_withdrawal price barrier check that remove_liquidity uses to limit slippage.
Impact
An attacker could frontrun the admin's withdrawal and cause slippage losses that may be higher than the 2% limit enforced in remove_liquidity, though the sponsor says the function is usually called when trading is paused.
What the attacker needed
Admin calls withdraw_protocol_liquidity; attacker can frontrun the transaction
The fix
Add a safe_withdrawal parameter or a minimum_out parameter to limit slippage losses.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When someone removes money from a trading pool, the price can change between when they decide to withdraw and when the transaction actually happens. A frontrunner is someone who sees a pending transaction and places their own trade first to profit from the price change. This report says one withdrawal function does not check that the price is close to what the admin expected, so a frontrunner can make the admin lose more money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.