Omniscia Olympus DAO Audit

SafeMath Code Style Findings

SafeMath Code Style Findings

SMH-01C: Inefficient Implementation

TypeSeverityLocation
Gas OptimizationInformationalSafeMath.sol:L115-L127

Description:

The sqqrt implementation does not efficiently calculate the root of the provided argument as it wraps operations unnecessarily (i.e. divisions with non-zero value literals).

Example:

contracts/libraries/SafeMath.sol
115// Only used in the BondingCalculator.sol
116function sqrrt(uint256 a) internal pure returns (uint c) {
117 if (a > 3) {
118 c = a;
119 uint b = add( div( a, 2), 1 );
120 while (b < c) {
121 c = b;
122 b = div( add( div( a, b ), b), 2 );
123 }
124 } else if (a != 0) {
125 c = 1;
126 }
127}

Recommendation:

We advise a more efficient square root algorithm to be implemented instead, such as the optimized Babylonian method by Uniswap.

Alleviation:

The Olympus DAO team considered this exhibit but opted not to apply any remediation for it.