Omniscia Tangible Audit
PriceConverter Code Style Findings
PriceConverter Code Style Findings
PCR-01C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | PriceConverter.sol:L14, L16 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
13if (fromDecimal > toDecimal) {14 amount = amount / (10 ** (fromDecimal - toDecimal));15} else if (fromDecimal < toDecimal) {16 amount = amount * (10 ** (toDecimal - fromDecimal));17}
Recommendation:
Given that safe arithmetics are toggled on by default in pragma
versions of 0.8.X
, we advise the linked statement to be wrapped in an unchecked
code block thereby optimizing its execution cost.
Alleviation (2ad448279d):
An unchecked
code block has been introduced to the full code block, however, its introduction should solely apply to the subtraction of the decimal values rather than the multiplication in the else if
branch. As such, we consider this exhibit not applied as the change should be reversed or corrected.
Alleviation (1f394a00cc):
The optimization was corrected, wrapping the fromDecimal - toDecimal
or toDecimal - fromDecimal
calculation in an unchecked
code block that is guaranteed to execute safely. As such, we consider this exhibit properly addressed.