When a user single-side deposit into a pool, slippage protection is invalid
When a user makes a single-sided deposit into a pool, the contract performs a swap with belief_price set to None, which disables the intended slippage protection. An attacker could exploit this to cause the user to receive fewer LP tokens than expected due to price movements before the transaction is executed.
oakcobalt Follow with Egis_Security
Originally disclosed on Code4rena
Submitted by oakcobalt, also found by Egis_Security
When a user single-side deposit into a pool, a swap is performed first before liquidity provision.
The vulnerability is belief_price is always set to NONE which causes slippage protection to be invalid in some cases.
//contracts/pool-manager/src/liquidity/commands.rs
pub fn provide_liquidity(
...
) -> Result<Response, ContractError> {
...
let is_single_asset_provision = deposits.len() == 1usize;
if is_single_asset_provision {
...
Ok(Response::default()
.add_submessage(SubMsg::reply_on_success(
wasm_execute(
env.contract.address.into_string(),
&ExecuteMsg::Swap {
ask_asset_denom,
|> belief_price: None,
max_spread,
receiver: None,
pool_identifier,
},
vec![swap_half],
)?,
SINGLE_SIDE_LIQUIDITY_PROVISION_REPLY_ID,
))
.add_attributes(vec![("action", "single_side_liquidity_provision")]))
} else {
/contracts/pool-manager/src/liquidity/commands.rs#L164
Proof of Concept
During a swap (perform_swap::assert_max_spread), belief_price and max_spread are both user input and can be combined for slippage protection.
belief_price: what a user believes the spot price before swap should be.max_spread: how much the price moved during swap.
/// If `belief_price` and `max_spread` both are given,
/// we compute new spread else we just use pool network
/// spread to check `max_spread`
pub fn assert_max_spread(
belief_price: Option<Decimal>,
max_spread: Option<Decimal>,
offer_amount: Uint128,
return_amount: Uint128,
spread_amount: Uint128,
) -> StdResult<()> {
let max_spread: Decimal256 = max_spread
.unwrap_or(Decimal::from_str(DEFAULT_SLIPPAGE)?)
.min(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?)
.into();
if let Some(belief_price) = belief_price {
let expected_return = Decimal::from_ratio(offer_amount, Uint128::one())
.checked_mul(
belief_price
.inv()
.ok_or_else(|| StdError::generic_err("Belief price can't be zero"))?,
)?
.to_uint_floor();
let spread_amount = expected_return.saturating_sub(return_amount);
if return_amount < expected_return
&& Decimal256::from_ratio(spread_amount, expected_return) > max_spread
{
return Err(StdError::generic_err("Spread limit exceeded"));
}
|> } else if Decimal256::from_ratio(spread_amount, return_amount + spread_amount) > max_spread {
return Err(StdError::generic_err("Spread limit exceeded"));
}
Ok(())
}
/contracts/pool-manager/src/swap/perform_swap.rs#L166
belief_price is especially important in constant product swap case where the pool spot price can shift wildly between tx submission and tx execution.
Even in stableswap pool, belief_price is also important because pool spot price can still shift away from the ideal 1:1 price in the case where amp is set to a low value (e.g., less than 2000000) or assets are more imbalanced.
When belief_price is set to NONE, max_spread’s implementation between constant product swap and stable swap become inconsistent. Both constant product pool and stableswap pool’s slippage protection can be invalid.
- Constant product swap (
belief_price= none)spread_amount=offer_amount * (ask_pool / offer_pool) - return_amount;
Note: ask_pool/offer_pool is the current spot price of the pool, which is not foreseeable by the user.
Check: spread_amount/(spread_amount + return_amount) ≤ max_spread
- stableswap (
belief_price= none)spread_amount=offer_amount - return_amount; (with decimal aligned).
Note: spread_amount is based on a fixed 1:1 price. However, when assets are imbalanced or amp is low, the deltaX:deltaY will differ from 1:1.
We see in both cases, swap slippage protection is voided because it’s not able to account for the pool price slipping before tx execution.
Recommended mitigation steps
Consider revising provide_liquidity to allow user to pass a belief_price for single-sided swap flow.
jvr0x (MANTRA) confirmed and commented:
Valid, probably low.
When I, as a user, am providing liquidity to a pool, why would I care about the underlying swap that is happening behind the scenes? I don’t think it would make sense to put “conditions” (slippage) on that swap. What I care about is the result of providing liquidity and the shares minted to me, which are validated using
slippage_tolerance.As a result, I believe
slippage_toleranceis more than enough as slippage protection, even when providing single-side liquidity. I believe this could be a low-severity issue.
carrotsmuggler (warden) commented:
The issue states that slippage is not set, which is incorrect since
max_spreadis used. The issue then saysmax_spreadis not good for stableswap and constant products.
max_spreadnot being good is already covered in F-37, so this is not a new path and is basically just triggering a flaw reported in another issue.The
max_spreadimplementation on constant product pool does work. It calculatesask_pool/offer_pool, the current spot price of the pool, which is a measure of the amount of price change the user expects. The submitter says that “Both constant product pool and stableswap pool’s slippage protection can be invalid.”, but does not prove that statement beyond what is already reported in F-37.Furthermore, the issue here shows that
belief_priceis being ignored andmax_spreadis being used instead.
The
max_spreadimplementation on constant product pool does work. It calculatesask_pool/offer_pool…
max_spreaddeals withspread_amount/(return_amount + spread_amount). it uses the spot price (ask_pool/offer_pool) when belief_price is not provided.the current spot price of the pool, which is a measure of the amount of price change the user expects.
This is not entirely correct. The user cannot measure the price change based on spot price without the
belief_price, which is the vulnerable case this report deals with.
max_spreadnot being good is already covered in F-37, so this is not a new path and is basically just triggering a flaw reported in another issue.Not true. F-37 only deals with stableswap case, and it has to do with a comparison logic specific in the stableswap branch. It doesn’t consider constant product pool.
The point here is not that there is no slippage check for
provide_liquidity, it’s that whenbelief_priceis none when single side depositing, existing slippage calculation is invalid.For a constant product pool:
- When
belief_priceis none, user cannot control how much ask tokens to transfer out, which means the user cannot control the asset ratio (ask_token/ask_pool, oroffer_token/offer_pool) which determines actual minted LPs.max_spreaddoesn’t prevent slippage withoutbelief_price. It doesn’t care how much price moved before the swap.slippage_toleranceis intended to work when no swaps, i.e., user deposits pool reserve ratio → deposit ratio is fixed by user. It only cares about input deposits ratio’s deviation from the pool reserve ratio. (ask_token/offer_tokenvsask_pool/offer_pool).However, because of (1), both deposit ratio and pool reserve ratio are moving targets, resulting in invalid slippage_tolerance’s comparison.
Example:
- User provides 10000 DAI to a constant product pool with 20% slippage for simplicity.
- Pool’s total lp: 316
Case1: Pool’s spot price before swap: 5000 DAI, 20 WETH
swap: → 5000 DAI, 10 WETH
two-sided
provide_liquidity:
- pool reserve: 10000 DAI, 10 WETH
- deposit[0]/deposit[1] = 500
- pool[0]/pool[1] = 1000
- pool[0]/pool[1] > deposit[0]/ (deposit[1] * 80%) → slippage check fails.
- Theoretical Lp mints: 158
Case2: Pool’s spot price before swap: 20000 DAI, 5 WETH
swap: → 5000 DAI, 1 WETH
two-sided
provide_liquidity:
- pool reserve: 25000 DAI, 4 WETH
- deposit[0]/deposit[1] = 5000
- pool[0]/pool[1]= 6250
- (deposit[0]/deposit[1])* 80% ≤ pool[0]/pool[1] ≤ deposit[0]/ (deposit[1] * 80%) → slippage check pass.
- Lp mints: 63
As seen, Case2’s slippage check passed; however, actual minted share is much lower compared to Case1.
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
The provide_liquidity function hardcodes belief_price to None when performing the internal swap for single-sided deposits, so the slippage check relies only on max_spread, which does not account for price changes before the swap.
Impact
Users making single-sided deposits could receive fewer LP tokens than expected because the swap lacks effective slippage protection, though the severity is debated and may be low.
What the attacker needed
User makes a single-sided deposit; price moves before transaction execution
The fix
The provide_liquidity function should be revised to allow the user to pass a belief_price for the single-sided swap flow.
How it was found
- User calls provide_liquidity with a single asset deposit.
- Contract performs a swap with belief_price set to None.
- Slippage protection relies only on max_spread, which does not prevent price slippage before execution.
- User may receive fewer LP tokens than expected due to price movement.
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 you add money to a trading pool, the system sometimes swaps your deposit first. To protect you from bad prices, the system can check the price before and after the swap. Here, that check is turned off, so you might get fewer pool shares than you should if the price moves.
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.