SSSwap

First Flight #41
Beginner FriendlyRust
100 EXP
View results
Submission Details
Severity: high
Valid

Insufficient Validation in Liquidity Provision

Description: In the liquidity_operations::provide_liquidity function, only the amount of token A is specified, and token B amount is calculated based on the current ratio. This can lead to unexpected slippage if the pool ratio changes between transaction submission and execution.

Impact: Users might provide more token B than expected, leading to financial losses.

Recommended Mitigation: Add a maximum token B parameter to the provide_liquidity function to protect users from unexpected price movements:

pub fn provide_liquidity(context: Context<ModifyLiquidity>,
amount_a: u64,
max_amount_b: u64
) -> Result<()> {
let amount_b = calculate_token_b_provision_with_a_given(
&mut context.accounts.vault_a,
&mut context.accounts.vault_b,
amount_a
)?;
require!(amount_b <= max_amount_b, AmmError::Slippage);
// Rest of the function
// ...
}
Updates

Lead Judging Commences

0xtimefliez Lead Judge
17 days ago
0xtimefliez Lead Judge 14 days ago
Submission Judgement Published
Validated
Assigned finding tags:

Liquidity Provision Lacks Slippage Protection

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.