diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-07-11 05:01:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-11 05:01:13 +0800 |
commit | b9627e14d0b30eb50e9169fb7002f942fa089347 (patch) | |
tree | f2dcd41f80deaddfcb7341e959cc94c10389f34b /packages/contracts | |
parent | 56a96d36a1f994f36c9331931a9b9cb201891678 (diff) | |
parent | e60630fa73b7c1aa93fa87161a1c959d41ca7b33 (diff) | |
download | dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.tar dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.tar.gz dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.tar.bz2 dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.tar.lz dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.tar.xz dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.tar.zst dexon-sol-tools-b9627e14d0b30eb50e9169fb7002f942fa089347.zip |
Merge pull request #848 from 0xProject/feature/contracts/safeMath
Add revert reasons and optimization to safeMath
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol | 18 |
1 files changed, 15 insertions, 3 deletions
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; } |