diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-07-11 02:22:34 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-07-11 03:53:47 +0800 |
commit | 5ef661302432780dae38ac39ae294f82fb99e85a (patch) | |
tree | b4d0aa44b6dd370807a0b37a5963d901f597f75f /packages/contracts/src/2.0.0 | |
parent | af7e02de2789efd3e73f60bf92b700ccec8ba520 (diff) | |
download | dexon-sol-tools-5ef661302432780dae38ac39ae294f82fb99e85a.tar.gz dexon-sol-tools-5ef661302432780dae38ac39ae294f82fb99e85a.tar.zst dexon-sol-tools-5ef661302432780dae38ac39ae294f82fb99e85a.zip |
Add revert reasons and optimization to safeMath
Diffstat (limited to 'packages/contracts/src/2.0.0')
-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; } |