From eb38c059d81ecf9296ef7526233ed962aba070eb Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Fri, 24 Feb 2023 19:34:03 +0100 Subject: [PATCH] Add comment on unchecked arithmetic (division by zero) in `Math.sol` (#4050) Co-authored-by: Francisco --- contracts/utils/math/Math.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/utils/math/Math.sol b/contracts/utils/math/Math.sol index 8400d0669..f8e7ca0a9 100644 --- a/contracts/utils/math/Math.sol +++ b/contracts/utils/math/Math.sol @@ -67,6 +67,9 @@ library Math { // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { + // Solidity will revert if denominator == 0, unlike the div opcode on its own. + // The surrounding unchecked block does not change this fact. + // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; }