Omniscia 0xPhase Audit

MathLib Code Style Findings

MathLib Code Style Findings

MLB-01C: Ineffectual Usage of Safe Arithmetics

TypeSeverityLocation
Language SpecificMathLib.sol:L66, L68, L86, L89

Description:

The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

lib/MathLib.sol
58function scaleAmount(
59 int256 amount,
60 uint8 fromDecimals,
61 uint8 toDecimals
62) internal pure returns (int256) {
63 if (fromDecimals == toDecimals) {
64 return amount;
65 } else if (fromDecimals < toDecimals) {
66 return amount * int256(uint256(10) ** uint256(toDecimals - fromDecimals));
67 } else {
68 return amount / int256(uint256(10) ** uint256(fromDecimals - toDecimals));
69 }
70}

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statements to be wrapped in unchecked code blocks thereby optimizing their execution cost.

Alleviation (3dd3d7bf0c2693b2f9c23bacedfa420393f7ea84):

The unchecked calculations are safely applied to the decimal deltas as advised, optimizing the code's gas cost.