Arithmetic and fee calculation issues in the StabilityBranch
contract arise from potential division by zero, precision loss during conversions, and rounding errors. These vulnerabilities can lead to unintended behavior, including reverts, inaccurate fee computations, and exploitation by attackers to repeatedly extract minor financial advantages.
In the getAmountOfAssetOut
function, usdAmountInX18
is divided by indexPriceX18
. If indexPriceX18
equals zero, the operation reverts, causing potential disruptions in swap functionality.
Similar risks are present in getFeesForAssetsAmountOut
and getFeesForUsdTokenAmountIn
, where division operations may involve variables that could unexpectedly equal zero.
Precision Loss and Rounding Errors:
Conversions between different precisions (e.g., 18-decimal USD tokens and asset tokens with varying decimal places) can introduce rounding errors.
Attackers could exploit these rounding errors by repeatedly executing small transactions designed to manipulate rounding outcomes in their favor.
Cascading Effects on Fees:
Incorrect fee calculations due to precision loss or division errors might lead to either overcharging or undercharging users. Overcharged fees might harm user trust, while undercharged fees could result in financial losses for the protocol.
Division by zero errors could render critical functions (e.g., initiateSwap
, fulfillSwap
) unusable, causing a DoS (Denial of Service) scenario.
Financial Losses:
Exploitation of rounding errors or precision loss could enable attackers to drain protocol funds incrementally, resulting in long-term financial damage.
Reputation Damage:
Incorrect fee calculations or transaction failures could erode user trust in the platform, affecting adoption and usage.
Manual Review
Add checks to ensure indexPriceX18
and similar variables are non-zero before performing division. For example:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.