From 157b10001594b1ba41296df2a7f1c2df1eb62b6f Mon Sep 17 00:00:00 2001 From: 0xtotem <104422021+0xtotem@users.noreply.github.com> Date: Sat, 14 Jan 2023 09:48:57 +0100 Subject: [PATCH] Reduces mul execution cost Reduces from 21769 down to 21748 when a != 0 --- contracts/libraries/math/SafeMath.sol | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/contracts/libraries/math/SafeMath.sol b/contracts/libraries/math/SafeMath.sol index 7cb3abaa..474bfba8 100644 --- a/contracts/libraries/math/SafeMath.sol +++ b/contracts/libraries/math/SafeMath.sol @@ -75,15 +75,8 @@ library SafeMath { * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { - // Gas optimization: this is cheaper than requiring 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 - if (a == 0) { - return 0; - } - uint256 c = a * b; - require(c / a == b, "SafeMath: multiplication overflow"); + require(a == 0 || c / a == b, "SafeMath: multiplication overflow"); return c; }