QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

Redundant logic in QuantAMMMathGuard._pow()

Summary

Redundant logic in QuantAMMMathGuard._pow()

Vulnerability Details

QuantAMMMathGuard._pow() checks whether _x and _y params are 0 to return one value or another. However, the first if containd redundant logic and it can be simplified in order to save gas when executing the function and make the code more legible, this is possible because in boolean logic : ```a || (a && b) = a```.

Take into account that _pow() function is called with a 'for' loop, which makes that calling this function multiple times could lead to an excessive waste of gas.

Impact

Low impact, it prevents a potential waste of gas.

Tools Used

Manual review

Recommendations

Simplify the first 'if' condition:

/// @notice Raises SD59x18 number x to an arbitrary SD59x18 number y
/// @dev Calculates (2^(log2(x)))^y == x^y == 2^(log2(x) * y)
/// @param _x Base
/// @param _y Exponent
/// @return result x^y
function _pow(int256 _x, int256 _y) internal pure returns (int256 result) {
- if (_y == 0 || (_x == 0 && _y == 0)) {
+ if (_y == 0) {
return 1 * 1e18;
}
if (_x == 0) {
return 0;
}
//Noticed effect of this reorg- 2^(log2(x) * y) - the variable multiplied by exp2() can be a large negative and lib can return 0
return _y.mul(_x.log2()).exp2();
}
Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas / Admin is trusted / Pool creation is trusted / User mistake / Suppositions

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!