Verified contractPartialUNLICENSED
Wintermute
Address0x0000006daea1723962647b7e189d311d757fb793
- Balance
0.406 ETH
- Transactions
1,002,169
- Compiler
solc 0.7.3
- Same code
Only this contract
Details
- Compiler
- solc 0.7.3+commit.9bfce1f6
- Language
- solidity
- Optimization
- Yes, 999,999 runs
- License
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 11,789,893
- Creation transaction
- 0x706b0a5061…aa0b816893
5 files
- Wintermute.solmain12.09 KB
- Address.sol6.83 KB
- IERC20.sol2.7 KB
- SafeERC20.sol3.42 KB
- SafeMath.sol5.21 KB
Wintermute.sol
// Rebuilt by the imd.fun swarm
// ◇ IMD · an onchain AI agent workforce · $IMD 0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7
// Seat #1202 · explorer.imd.fun/goals/a05f7d2f-c42e-423e-bb75-fb80ed455626
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.7.3;
pragma experimental ABIEncoderV2;
import "SafeERC20.sol";
import "Address.sol";
interface IChi {
function mint(uint256 value) external;
function freeUpTo(uint256 value) external returns (uint256);
}
/// @notice Reconstruction of the historical Wintermute executor at
/// 0x0000006daea1723962647b7e189d311d757fb793.
/// @dev Names beginning f_ are selector preimages, rather than recovered names.
contract Wintermute {
using SafeERC20 for IERC20;
using Address for address;
uint256 private status;
uint256 private constant ENTERED = 2;
uint256 private constant NOT_ENTERED = 1;
// 0xa6dd0c50: allowed external call targets.
mapping(address => bool) public f_00006c1ecf3d;
mapping(address => bool) private executors;
mapping(address => bool) private drainers;
mapping(address => bool) private approvers;
mapping(address => bool) private signers;
// Signedness also determines the compiler-generated packed encoder.
int256 private nonce = 0;
// Constructor-only storage aliases for three recovered initialization slots.
// These gaps are never accessed. They place each bool at its exact mapping
// slot while its original address key remains unknown; no address is invented.
// Unaccessed padding does not allocate or initialize EVM storage.
uint256[0xa58aa94b3d53f6aad5c57046deb54c8ff159706bb16ef9657b9194f90bc02af0] private constructorGap0;
bool private initialFlag_a58aa94b;
uint256[0x164a52d1d256e341456b5cca1e925e253a4cbcca703c85ab122e36f94d3de839] private constructorGap1;
bool private initialFlag_bbd4fc1d;
uint256[0x2e717e82674c14ec7c958dbff5b3a80bfaf3b76e75e62754a6c6124b34ed6221] private constructorGap2;
bool private initialFlag_ea467a9f;
IChi public constant CHI = IChi(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c);
address payable private constant RECIPIENT = 0x0000f079e68BbCC79AB9600ace786B0a4dB1c83c;
// Anonymous declarations preserve recovered topic hashes without inventing
// a name for an event whose original signature has not been recovered.
event CallFailure(uint256 indexed topic, address indexed target, uint256 indexed value, bytes data, bytes result) anonymous;
event ApprovalFailure(uint256 indexed topic, address indexed spender, address indexed token, uint256 indexed value) anonymous;
constructor() {
status = NOT_ENTERED;
approvers[0x0000160CE56b16f258803CB1c2a3c8CE3Af046E7] = true;
approvers[0x0000235f60518B324e36e2bC3806A7C521083c65] = true;
approvers[0x000083Fed471A799250a2E4D9Fc3955d50D229A9] = true;
executors[0x000002Cba8DfB0a86A47a415592835E17fac080a] = true;
executors[0x00007d83668899A2aF7b5b03efd2351585843dE9] = true;
executors[0x0000495194Ec698FCF89ccF8aBB445dAf01Db497] = true;
executors[0x0000A0756737268a633cd9296F1B154cf74430b6] = true;
executors[0x00006196242a1D328fe4B636995e796cb6c7a2Ac] = true;
executors[0x000000C3cfD83E7F9D856bED82231e8a00a1b07F] = true;
executors[0x000000b11f0013D97124fD89d21940E46aaB852d] = true;
executors[0x000000A23C3512d4AAB1129564b7E4e1Ff571287] = true;
executors[0x000000a2e1b612C53D39b789b0fFAB18D6c12870] = true;
executors[0x0000007eeE50167CCef12745e19967667ff16E55] = true;
drainers[0x000089D643EDa1f3E45a945017E5eb1D09F9b2b2] = true;
initialFlag_bbd4fc1d = true;
initialFlag_a58aa94b = true;
initialFlag_ea467a9f = true;
signers[0x00000768676582CBA32fC98aF30fDFB6e945f9a3] = true;
signers[0x00000061A91c563D5c00463baE844edaf75Ad639] = true;
signers[0x00000067f1cc21FEbD04b5E5d7bC035D8e3F2b32] = true;
signers[0x000000e47588F5136A4657d3eCC992595A58415c] = true;
}
modifier onlyExecutor() { require(executors[msg.sender], "2"); _; }
modifier onlyDrainer() { require(drainers[msg.sender], "2"); _; }
modifier onlyTarget(address target) { require(f_00006c1ecf3d[target], "2"); _; }
modifier onlyTargets(address[] memory targets) {
for (uint256 i = 0; i < targets.length; i++) require(f_00006c1ecf3d[targets[i]], "2");
_;
}
modifier nonReentrant() {
require(status != ENTERED, "8");
status = ENTERED;
_;
status = NOT_ENTERED;
}
modifier refundChi() {
uint256 gasStart = gasleft();
_;
uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length;
CHI.freeUpTo((gasSpent + 14154) / 41947);
}
fallback() external payable {}
function isValidSignature(bytes32 hash, bytes memory signature) public view returns (bytes32) {
address signer;
if (signature.length == 87 || signature.length == 88) signer = recoverWithFee(hash, signature);
else signer = recover(hash, signature);
require(signers[signer], "2");
return 0xb067138131d606f18b51e6ee32605a2acac5aad86d6a80011ed9cb2bab20c1c7;
}
// 0x178979ae: execute one call, logging a failed subcall.
function f_00016097e403(address target, uint256 value, bytes memory data) public onlyExecutor onlyTarget(target) nonReentrant {
callOptional(target, value, data);
}
// 0x29411510: execute a batch, logging failed subcalls.
function f_0001b455b67a(address[] memory targets, uint256[] memory values, bytes[] memory data) public onlyExecutor onlyTargets(targets) nonReentrant {
require(targets.length == values.length && values.length == data.length, "1");
for (uint256 i = 0; i < targets.length; i++) callOptional(targets[i], values[i], data[i]);
}
// 0x3e004d44: update approvals with a CHI refund.
function f_000087b79a91(address[] memory spenders, address[] memory tokens, uint256[] memory values, uint8 v1, bytes32 r1, bytes32 s1, uint8 v2, bytes32 r2, bytes32 s2) public refundChi {
f_000223acc3dc(spenders, tokens, values, v1, r1, s1, v2, r2, s2);
}
function drain(IERC20[] memory tokens, uint256[] memory values) public onlyDrainer {
require(tokens.length == values.length, "1");
for (uint256 i = 0; i < tokens.length; i++) tokens[i].safeTransfer(RECIPIENT, values[i]);
}
function mintChi(uint256 value) public { CHI.mint(value); }
// 0x729df14c: execute a batch, reverting on a failed subcall.
function f_0000bfc8d87a(address[] memory targets, uint256[] memory values, bytes[] memory data) public onlyExecutor onlyTargets(targets) nonReentrant {
require(targets.length == values.length && values.length == data.length, "1");
for (uint256 i = 0; i < targets.length; i++) callStrict(targets[i], values[i], data[i]);
}
// 0x847a771a: execute one call with a CHI refund.
function f_0000eeb2fb5b(address target, uint256 value, bytes memory data) public refundChi { f_00016097e403(target, value, data); }
// 0xad0b5105: authorize approvals using two distinct approver signatures.
function f_000223acc3dc(address[] memory spenders, address[] memory tokens, uint256[] memory values, uint8 v1, bytes32 r1, bytes32 s1, uint8 v2, bytes32 r2, bytes32 s2) public {
authorizeApproval(spenders, tokens, values, v1, r1, s1, v2, r2, s2);
nonce++;
for (uint256 i = 0; i < spenders.length; i++) {
IERC20 token = IERC20(tokens[i]);
token.safeApprove(spenders[i], values[i]);
if (token.allowance(address(this), spenders[i]) > values[i]) {
f_00006c1ecf3d[spenders[i]] = false;
emit ApprovalFailure(0x8d0bc26ce8e6410cc86e097ebb7f172dbde6300bd4091008c29002bd4f7dfb10, spenders[i], tokens[i], values[i]);
} else if (values[i] == 0) f_00006c1ecf3d[spenders[i]] = false;
else f_00006c1ecf3d[spenders[i]] = true;
}
}
// 0xc217d070: execute a strict batch with a CHI refund.
function f_000066f388c5(address[] memory targets, uint256[] memory values, bytes[] memory data) public refundChi { f_0000bfc8d87a(targets, values, data); }
// 0xc36f210b: hash the nonce and approval arrays.
function f_00006f7e99da(address[] memory spenders, address[] memory tokens, uint256[] memory values) public view returns (bytes32) {
checkApprovalArrays(spenders, tokens, values);
bytes32 result = keccak256(abi.encodePacked(nonce, spenders, tokens, values));
return result;
}
function drainETH(uint256 value) public onlyDrainer { RECIPIENT.call{value:value}(""); }
// 0xdff69b6c: execute an optional batch with a CHI refund.
function f_00004fb7badf(address[] memory targets, uint256[] memory values, bytes[] memory data) public refundChi { f_0001b455b67a(targets, values, data); }
function drainETH() public onlyDrainer { RECIPIENT.call{value:address(this).balance}(""); }
function recoverWithFee(bytes32 hash, bytes memory signature) internal pure returns (address) {
uint8 v;
bytes32 r;
bytes32 s;
address wallet;
bytes2 fee;
v = uint8(signature[0]);
assembly {
r := mload(add(signature, 33))
s := mload(add(signature, 65))
wallet := and(mload(add(signature, 85)), 0xffffffffffffffffffffffffffffffffffffffff)
fee := and(mload(add(signature, 117)), 0xffff000000000000000000000000000000000000000000000000000000000000)
}
uint16 feeFactor = uint16(fee);
require(feeFactor < 10000, "FEE_FACTOR_MORE_THEN_10000");
return ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n54", hash, wallet, feeFactor)), v, r, s);
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
uint8 v;
bytes32 r;
bytes32 s;
v = uint8(signature[0]);
assembly {
r := mload(add(signature, 33))
s := mload(add(signature, 65))
}
return ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)), v, r, s);
}
function callOptional(address target, uint256 value, bytes memory data) internal {
require(value <= address(this).balance, "3");
(bool success, bytes memory result) = target.call{value:value}(data);
if (!success) emit CallFailure(0x335a31c96b94b80f0be06ac8580999f098962ec15c75c6cf3c48df0628ce2531, target, value, data, result);
}
function callStrict(address target, uint256 value, bytes memory data) internal {
require(value <= address(this).balance, "3");
(bool success, bytes memory result) = target.call{value:value}(data);
if (!success) {
emit CallFailure(0x335a31c96b94b80f0be06ac8580999f098962ec15c75c6cf3c48df0628ce2531, target, value, data, result);
revert("TRADE_FAILED");
}
}
function authorizeApproval(address[] memory spenders, address[] memory tokens, uint256[] memory values, uint8 v1, bytes32 r1, bytes32 s1, uint8 v2, bytes32 r2, bytes32 s2) internal view {
bytes32 hash = f_00006f7e99da(spenders, tokens, values);
bytes32 message = keccak256(abi.encodePacked(bytes1(0x19), bytes1(0x00), address(this), hash));
address signer1 = ecrecover(message, v1, r1, s1);
address signer2 = ecrecover(message, v2, r2, s2);
checkApprovers(signer1, signer2);
}
function checkApprovalArrays(address[] memory spenders, address[] memory tokens, uint256[] memory values) internal view {
require(spenders.length == tokens.length && tokens.length == values.length, "1");
for (uint256 i = 0; i < spenders.length; i++) require(spenders[i].isContract(), "7");
}
function checkApprovers(address first, address second) internal view {
require(first != second, "4");
require(approvers[first], "5");
require(approvers[second], "6");
}
}
Address.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
/**
* @dev Collection of functions related to the address type
*/
// OpenZeppelin 3.3-style call helpers with the legacy extcodehash contract test
// and the revert-data expression recovered from this deployment.
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
revert(add(32, returndata), mload(returndata))
}
} else {
revert(errorMessage);
}
}
}
}
IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
SafeERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "SafeMath.sol";
import "Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
// Historical variant: safeApprove has no allowance-reset precondition.
// The deployed executor calls this optional-return approval primitive directly.
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
SafeMath.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @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;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 999999,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.