Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Invalid

Incorrect exponentiation in openzeppelin library `Math.sol::mulDiv()`

Description:
The mulDiv() function in OpenZeppelin's Math.sol (v5.1.0) uses a bitwise XOR (^) operator instead of exponentiation (**) in the calculation of the modular inverse:

uint256 inverse = (3 * denominator) ^ 2; // Line 205

This is incorrect as the intention appears to be exponentiation (squaring) rather than bitwise XOR. The XOR operation will produce incorrect results for the inverse calculation.

Impact:

  • Incorrect calculation of modular inverse

  • Potential security implications in functions relying on this calculation

  • Could lead to incorrect results in any contract using this math utility

  • High severity as it affects core mathematical operations

Recommended Mitigation:
Replace the XOR operator (^) with the exponentiation operator (**):

uint256 inverse = (3 * denominator) ** 2;

Likelihood and Impact

  • Impact: High (mathematical correctness)

  • Likelihood: Medium (always occurs when this code path is executed)

  • Severity: HIGH

Updates

Lead Judging Commences

m3dython Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

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