Stratax Contracts

First Flight #57
Beginner FriendlyDeFi
100 EXP
Submission Details
Impact: medium
Likelihood: medium

Precision Loss Risk Due to Integer Division in collateralToWithdraw

Author Revealed upon completion

Precision Loss Risk Due to Integer Division in collateralToWithdraw

Description:
The calculation:

uint256 collateralToWithdraw = (...) / (...);

uses Solidity integer division, which truncates values and can introduce precision loss.

Impact:
May under- or overestimate collateral withdrawal, potentially:

  • Causing insufficient swap output → transaction revert

  • Withdrawing excess collateral → suboptimal financial outcome

Recommended Mitigation:
Use full-precision multiplication/division via Math.mulDiv:

+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
+ uint256 collateralToWithdraw = Math.mulDiv(
+ _amount * debtTokenPrice * LTV_PRECISION,
+ 10 ** IERC20(unwindParams.collateralToken).decimals(),
+ collateralTokenPrice * (10 ** IERC20(_asset).decimals()) * liqThreshold,
+ Math.Rounding.Ceil
+ );

Support

FAQs

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

Give us feedback!