Precision Loss From Integer Division in Stratax::calculateUnwindParams May Under/Overestimate Collateral Withdrawal
Description:
The function computes collateralToWithdraw using integer division:
Solidity division truncates, so this calculation can lose precision and systematically round down. Since this value is then adjusted by a slippage buffer:
any earlier truncation still affects the final result. With different token decimals (e.g., 6 vs 18) and price feeds with 8 decimals, rounding error can become material.
Impact:
Medium. Incorrect estimation of collateral to withdraw can lead to:
Withdrawing too little collateral → swap yields insufficient borrow token → unwind flow reverts or fails to fully repay debt.
Withdrawing too much collateral → unnecessarily reduces remaining collateral / worsens position outcomes.
Recommended Mitigation:
Use a full-precision mulDiv approach to reduce truncation and control rounding direction (often round up is safer here to ensure enough collateral is withdrawn).
This minimizes precision loss and makes unwind calculations more reliable across token decimal configurations.
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.
The contest is complete and the rewards are being distributed.