SSSwap

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

Fee Calculation Issue: Loss of LP Fees Due to Integer Division

Root + Impact

https://github.com/CodeHawks-Contests/2025-05-ssswap/blob/27a2ef878023b0111ec4acc33503d99ae1ae36fa/programs/amm/src/instructions/swap_operations.rs#L143

https://github.com/CodeHawks-Contests/2025-05-ssswap/blob/27a2ef878023b0111ec4acc33503d99ae1ae36fa/programs/amm/src/instructions/swap_operations.rs#L211-L214

Description

  • Normal behavior: Every trade should pay 0.3% of the output token as fees to the LPs, regardless of the trade size.

  • Problem: Due to integer truncation in fee calculation, very small trades may pay 0 fees, leading to cumulative fee loss and potential abuse.

let lp_fees = (amount_out as u128 * 3).div_floor(&1000) as u64; // @> Precision loss in small trades

Risk

Likelihood:

  • This will occur whenever a trade is small enough that amount_out * 3 / 1000 < 1.

  • Common in arbitrage scenarios or bots executing small swaps frequently.

Impact:

  • LPs will receive less than expected or even zero fees.

  • Smart bots can exploit this to avoid paying fees, gaining unfair profits.

  • The protocol’s economic balance is broken, leading to potential reputational damage.

Proof of Concept

// Simulated swap:
amount_out = 5;
lp_fees = (5 * 3) / 1000 = 0
// 0.3% fee not collected => free trade

Recommended Mitigation

Set minimum fee of 1 (if any output, charge at least 1 fee)

let raw_fee = (amount_out as u128 * 3).div_floor(&1000) as u64;
let lp_fees = if raw_fee == 0 && amount_out > 0 { 1 } else { raw_fee };
Updates

Lead Judging Commences

0xtimefliez Lead Judge 15 days ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

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