aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/2.0.0/utils/SafeMath
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/2.0.0/utils/SafeMath')
-rw-r--r--packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol18
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;
}