Omniscia Mantissa Finance Audit
MasterMantis Code Style Findings
MasterMantis Code Style Findings
MMS-01C: Inefficient Square Root Implementation
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | MasterMantis.sol:L448-L459 |
Description:
The referenced implementation of a square root is inefficient as it relies on an early primitive implementation that has since been outdated.
Example:
448function sqrt(uint256 y) internal pure returns (uint256 z) {449 if (y > 3) {450 z = y;451 uint256 x = y / 2 + 1;452 while (x < z) {453 z = x;454 x = (y / x + x) / 2;455 }456 } else if (y != 0) {457 z = 1;458 }459}Recommendation:
We advise an updated and efficient implementation to be utilized, such as the Math::sqrt implementation of OpenZeppelin.
Alleviation (418ee413ad8e26f7eea383764c19953ff31b2bf3):
The Mantissa Finance evaluated this exhibit and given that it has no security implications opted not to apply it to avoid updating the on-chain contracts and / or introducing significant complexity to existing deployments. As such, we consider this exhibit acknowledged.
MMS-02C: Inefficient Update of Pools
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | MasterMantis.sol:L297, L318, L371 |
Description:
The referenced MasterMantis::updatePool operations are inefficient if the MasterMantis::gaugeUpdate function executed and updated the gauges and pools.
Example:
296gaugeUpdate();297updatePool(_pid);Recommendation:
We advise the MasterMantis::gaugeUpdate function to yield a bool value that is true when a pool update was also performed, permitting the referenced invocations to be skipped if the gauge updated all pools.
Alleviation (418ee413ad8e26f7eea383764c19953ff31b2bf3):
The Mantissa Finance team evaluated this exhibit and assessed that the MasterMantis::gaugeUpdate function is expected to be invoked only 2 times per month. As such, they wish to retain the current logic in place as the gas cost benefit would occur rarely.
MMS-03C: Loop Iterator Optimizations
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | MasterMantis.sol:L169, L191, L202, L216, L269, L369, L390, L413, L421, L438 |
Description:
The linked for loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X).
Example:
169for (uint256 i = 0; i < poolSize; i++) {Recommendation:
We advise the increment / decrement operations to be performed in an unchecked code block as the last statement within each for loop to optimize their execution cost.
Alleviation (418ee413ad):
All iterators were correctly updated, however, the sixth loop referenced (L381 in the latest codebase) contains a continue statement that does not properly increment the iterator before being executed. As such, this edge case would cause an infinite loop to occur consuming all the gas of the caller.
We advise the iterator increment statement to be performed before the continue statement as well for the optimization to be properly applied.
Alleviation (5482fabf5b):
The continue statement is now properly preceded by an increment of the i iterator, preventing the loop from never terminating and fully applying the recommended optimization properly.
MMS-04C: Repetitive Value Literal
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | MasterMantis.sol:L132, L205 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
132require(_gaugeAssetWeight + _gaugeVoteWeight == 100, "Incorrect sum");Recommendation:
We advise it to be set to a constant variable instead optimizing the legibility of the codebase.
Alleviation (418ee413ad8e26f7eea383764c19953ff31b2bf3):
The Mantissa Finance team stated that the repetition occurs solely twice and as such they deem it inconsequential and wish to acknowledge it.
