From 4e1a8c29bd904b8dce47a8a7c83cf80d67fc6693 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 23 Oct 2020 16:52:22 +0200 Subject: [PATCH] Fixed wad functions in WadRayMath --- contracts/libraries/math/WadRayMath.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contracts/libraries/math/WadRayMath.sol b/contracts/libraries/math/WadRayMath.sol index 696a0e09..a1a8d8f4 100644 --- a/contracts/libraries/math/WadRayMath.sol +++ b/contracts/libraries/math/WadRayMath.sol @@ -60,7 +60,7 @@ library WadRayMath { uint256 result = a * b + halfWAD; - require((result - halfWAD) / a == b, Errors.MULTIPLICATION_OVERFLOW); + require(result >= halfWAD && (result - halfWAD) / a == b, Errors.MULTIPLICATION_OVERFLOW); return result / WAD; } @@ -76,13 +76,9 @@ library WadRayMath { uint256 halfB = b / 2; - uint256 result = a * WAD; + uint256 result = a * WAD + halfB; - require(result / WAD == a, Errors.MULTIPLICATION_OVERFLOW); - - result += halfB; - - require(result >= halfB, Errors.ADDITION_OVERFLOW); + require(result >= halfB && (result - halfB) / WAD == a, Errors.MULTIPLICATION_OVERFLOW); return result / b; }