43 lines
1.2 KiB
Solidity
43 lines
1.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity 0.6.12;
|
|
|
|
/**
|
|
* @dev Wrappers over Solidity's arithmetic operations with added overflow
|
|
* checks.
|
|
*
|
|
* note that this is a stripped down version of open zeppelin's safemath
|
|
* https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol
|
|
*/
|
|
|
|
contract SafeMath {
|
|
|
|
/**
|
|
* @dev Returns the subtraction of two unsigned integers, reverting on
|
|
* overflow (when the result is negative).
|
|
*
|
|
* Counterpart to Solidity's `-` operator.
|
|
*
|
|
* Requirements:
|
|
* - Subtraction cannot overflow.
|
|
*/
|
|
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
|
|
return _sub(a, b, "SafeMath: subtraction overflow");
|
|
}
|
|
|
|
/**
|
|
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
|
|
* overflow (when the result is negative).
|
|
*
|
|
* Counterpart to Solidity's `-` operator.
|
|
*
|
|
* Requirements:
|
|
* - Subtraction cannot overflow.
|
|
*/
|
|
function _sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
|
|
require(b <= a, errorMessage);
|
|
uint256 c = a - b;
|
|
|
|
return c;
|
|
}
|
|
} |