Omniscia Maverick Protocol Audit
Math Code Style Findings
Math Code Style Findings
MHT-01C: Ineffectual Usage of Safe Arithmetics
| Type | Severity | Location |
|---|---|---|
| Language Specific | ![]() | Math.sol:L47, L51, L78, L154, L162 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.
Example:
70function invFloor(uint256 x) internal pure returns (uint256) {71 unchecked {72 return 1e36 / x;73 }74}75
76function invCeil(uint256 x) internal pure returns (uint256 result) {77 result = invFloor(x);78 if (mulmod(ONE, ONE, x) != 0) result = result + 1;79}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 (175f8c39b19df69134add3aa8a2a042ce3047763):
All referenced arithmetic statements have been wrapped in an unchecked code block as advised, optimizing their gas cost.
MHT-02C: Potentially Confusing Terminology
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | Math.sol:L158, L169 |
Description:
The Math::toScale and Math::fromScale functions are slightly contradictory in their terminology, as the Math::toScale function will convert an amount to its input scaleFactor from the "main" 1e18 scale while the Math::fromScale function will convert an amount to the "main" 1e18 scale from its input scaleFactor.
Example:
158function toScale(uint256 amount, uint256 scaleFactor, bool ceil) internal pure returns (uint256 z) {159 if (scaleFactor == DEFAULT_SCALE || amount == 0) {160 return amount;161 } else {162 if (!ceil) return amount / scaleFactor;163 assembly ("memory-safe") {164 z := add(div(sub(amount, 1), scaleFactor), 1)165 }166 }167}168
169function fromScale(uint256 amount, uint256 scaleFactor) internal pure returns (uint256) {170 if (scaleFactor == DEFAULT_SCALE) {171 return amount;172 } else {173 return amount * scaleFactor;174 }175}Recommendation:
As both the scale of the token and the scale of the system are "scales", we advise the functions to utilize different terminology (i.e. normalize, denormalize) that better illustrates their purpose.
As the scale of the system (1e18) represents a "one-to-many" relation between the scales of each token, the Math::fromScale function should be considered to convert from the singular 1e18 project scale to the token's respective scale.
Alleviation (175f8c39b19df69134add3aa8a2a042ce3047763):
The referenced functions have been aptly renamed to indicate the conversion path they implement (i.e. Math::ammScaleToTokenScale and Math::tokenScaleToAmmScale), illustrating their intended usage and addressing the exhibit's concerns as a result.
MHT-03C: Repetitive Value Literal
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | Math.sol:L72, L143 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
72return 1e36 / x;Recommendation:
We advise it to be set to a constant variable instead, optimizing the legibility of the codebase.
In case the constant has already been declared, we advise it to be properly re-used across the code.
Alleviation (175f8c39b19df69134add3aa8a2a042ce3047763):
The referenced value literal 1e36 has been properly relocated to a file-level constant declaration labelled ONE_SQUARED within the Constants file, optimizing the code's legibility.
