Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: low
Invalid

Precision Loss in Fee Calculations in StabilityBranch.sol

Summary

The fee calculation logic uses multiplication followed by division with fixed-point arithmetic. Although supported by libraries like PRB Math, the order of operations can lead to rounding issues, particularly for very small amounts.

Vulnerability Details

The fee math is implemented as follows:

function getFees(assetsAmountOut, price) {
// Convert base fee from USD to asset amount.
let baseFee = baseFeeUsd / price;
// Calculate dynamic swap fee with rounding up.
let swapFee = divUp(assetsAmountOut * swapSettlementFeeBps, BPS_DENOMINATOR);
return { baseFee, swapFee };
}

Impact

  • Rounding Errors: In transactions with small amounts, rounding differences could lead to slight overcharging or undercharging.

  • Accumulated Inaccuracies: While minor per transaction, repeated errors could have a cumulative impact over many swaps.

Tools Used

  • Static analysis

  • Mathematical verification and simulation

  • Fuzz testing

Recommendations

  • Rounding Optimization: Review the order of arithmetic operations to minimize precision loss.

  • Edge Case Testing: Perform detailed tests on small volume swaps to understand and adjust for rounding.

  • Library Enhancements: Consider using higher precision arithmetic or specialized libraries if necessary.

Updates

Lead Judging Commences

inallhonesty 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!