Omniscia Alliance Block Audit
PercentageCalculator Code Style Findings
PercentageCalculator Code Style Findings
PCR-01C: Optimizational Adjustments
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | PercentageCalculator.sol:L14-L16 |
Description:
The linked div
function is meant to be utilized as a utility function by other contracts to allow percentage based calculations.
Example:
contracts/PercentageCalculator.sol
14function div(uint256 _amount, uint256 _percentage) public pure returns(uint256) {15 return _amount.mul(_percentage).div(100000);16}
Recommendation:
We advise that the function is renamed as div
should instead be reflected by a name such as percentageMul
as the calculation carried out is not solely a division.
Additionally, the div
portion of the statement within should be dropped as the division is being conducted with a literal.
Finally, the literal should be seperated by _
per 3 digits to denote the granularity it provides.
Alleviation:
The div
function was renamed to percentageCalc
and the denominator numeric literal was set to contain the _
symbol as a seperator to render the overall code segment more legible.