SSSwap

First Flight #41
Beginner FriendlyRust
100 EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

Missing Zero Amount Validation in Provide Liquidity

Summary

The provide_liquidity function lacks validation to prevent users from providing zero amounts, which can lead to failed transactions, wasted gas, and potential edge case exploits.

Vulnerability Details

The function accepts amount_a as input but does not validate that it is greater than zero before proceeding with calculations and token transfers. While the calculate_token_b_provision_with_a_given function will eventually fail if the calculated amount_b is zero, the primary input amount_a is never validated upfront.

pub fn provide_liquidity(context: Context<ModifyLiquidity>, amount_a: u64) -> Result<()> {
// Missing: require!(amount_a > 0, AmmError::NoZeroAmount);
let amount_b = calculate_token_b_provision_with_a_given(
&mut context.accounts.vault_a,
&mut context.accounts.vault_b,
amount_a // Zero value can be passed here
)?;
// ... rest of the function
}

Impact

  • Gas Waste: Users can call the function with amount_a = 0, causing unnecessary computation and gas consumption before eventual failure

  • Poor User Experience: Late validation leads to confusing error messages deep in the execution flow

  • Potential Edge Cases: Zero amounts combined with rounding errors could lead to unexpected behavior in LP token minting calculations

  • Inconsistent Validation: Other functions like initialize_pool properly validate against zero amounts, creating inconsistent behavior

Recommended Mitigation

Add explicit zero amount validation at the beginning of the function:

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

This ensures consistent validation patterns across all liquidity operations and provides clear, early feedback to users.

Updates

Lead Judging Commences

0xtimefliez Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Too generic

Support

FAQs

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

Give us feedback!