// SPDX-License-Identifier: LGPL-3.0-only pragma solidity >=0.7.0 <0.9.0; /** * @title SafeMath * @notice Math operations with safety checks that revert on error (overflow/underflow) */ library SafeMath { /** * @notice Multiplies two numbers, reverts on overflow. * @param a First number * @param b Second number * @return Product of a and b */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not to be zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b); return c; } /** * @notice Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). * @param a First number * @param b Second number * @return Difference of a and b */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a); uint256 c = a - b; return c; } /** * @notice Adds two numbers, reverts on overflow. * @param a First number * @param b Second number * @return Sum of a and b */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a); return c; } /** * @notice Returns the largest of two numbers. * @param a First number * @param b Second number * @return Largest of a and b */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } }