From 5ef661302432780dae38ac39ae294f82fb99e85a Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Tue, 10 Jul 2018 11:22:34 -0700 Subject: Add revert reasons and optimization to safeMath --- .../contracts/src/2.0.0/utils/SafeMath/SafeMath.sol | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'packages/contracts/src/2.0.0/utils/SafeMath') diff --git a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol index 4413244db..190989181 100644 --- a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol +++ b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol @@ -7,8 +7,14 @@ contract SafeMath { pure returns (uint256) { + if (a == 0) { + return 0; + } uint256 c = a * b; - assert(a == 0 || c / a == b); + require( + c / a == b, + "UINT256_OVERFLOW" + ); return c; } @@ -26,7 +32,10 @@ contract SafeMath { pure returns (uint256) { - assert(b <= a); + require( + b <= a, + "UINT256_OVERFLOW" + ); return a - b; } @@ -36,7 +45,10 @@ contract SafeMath { returns (uint256) { uint256 c = a + b; - assert(c >= a); + require( + c >= a, + "UINT256_OVERFLOW" + ); return c; } -- cgit