Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
Handler
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 500 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; // Internal import {IHandler} from "./interfaces/IHandler.sol"; import {BalanceManager} from "./BalanceManager.sol"; import {NocturneReentrancyGuard} from "./NocturneReentrancyGuard.sol"; import {Utils} from "./libs/Utils.sol"; import {OperationUtils} from "./libs/OperationUtils.sol"; import {Groth16} from "./libs/Groth16.sol"; import {AssetUtils} from "./libs/AssetUtils.sol"; import "./libs/Types.sol"; /// @title Handler /// @author Nocturne Labs /// @notice Handler contract for processing and executing operations. contract Handler is IHandler, BalanceManager, NocturneReentrancyGuard { using OperationLib for Operation; bytes4 public constant ERC20_APPROVE_SELECTOR = bytes4(0x095ea7b3); uint256 public constant ERC_20_APPROVE_FN_DATA_LENGTH = 4 + 32 + 32; // Set of supported contracts mapping(address => bool) public _supportedContracts; // Set of callable protocol methods (key = address | selector) // NOTE: If an upgradeable contract with malicious admins is whitelisted, the contract could be // upgraded to add a new method that has a selector clash with an already-whitelisted method. // This would allow a malicious admin to make methods not intended to be called callable. This // scenario would allow for bypassing of deposit limits if new method allows for large inflow // of funds. mapping(uint192 => bool) public _supportedContractMethods; // Gap for upgrade safety uint256[50] private __GAP; /// @notice Event emitted when a contract is given/revoked allowlist permission event ContractMethodPermissionSet( address contractAddress, bytes4 selector, bool permission ); /// @notice Event emitted when a token is given/revoked allowlist permission event ContractPermissionSet(address contractAddress, bool permission); /// @notice Initialization function /// @param subtreeUpdateVerifier Address of the subtree update verifier contract /// @param leftoverTokensHolder Address of the leftover tokens holder contract function initialize( address subtreeUpdateVerifier, address leftoverTokensHolder ) external initializer { __NocturneReentrancyGuard_init(); __BalanceManager_init(subtreeUpdateVerifier, leftoverTokensHolder); } /// @notice Only callable by the handler itself (used so handler can message call itself) modifier onlyThis() { require(msg.sender == address(this), "Only this"); _; } /// @notice Only callable by the Teller contract modifier onlyTeller() { require(msg.sender == address(_teller), "Only teller"); _; } /// @notice Pauses the contract, only callable by owner function pause() external onlyOwner { _pause(); } /// @notice Unpauses the contract, only callable by owner function unpause() external onlyOwner { _unpause(); } /// @notice Sets allowlist permission of the given contract, only callable by owner /// @param contractAddress Address of the contract to add /// @param permission Whether to enable or revoke permission /// @dev This whitelists the contract but none of its methods. This is used for checks such as /// checks that a token is supported or when checking that a spender being approved for an /// erc20 is allowed. function setContractPermission( address contractAddress, bool permission ) external onlyOwner { _supportedContracts[contractAddress] = permission; emit ContractPermissionSet(contractAddress, permission); } /// @notice Sets allowlist permission of the given contract, only callable by owner /// @param contractAddress Address of the contract to add /// @param permission Whether to enable or revoke permission function setContractMethodPermission( address contractAddress, bytes4 selector, bool permission ) external onlyOwner { uint192 addressAndSelector = _addressAndSelector( contractAddress, selector ); _supportedContractMethods[addressAndSelector] = permission; emit ContractMethodPermissionSet(contractAddress, selector, permission); } /// @notice Handles deposit call from Teller. Inserts new note commitment for deposit. /// @dev This method is only callable by the Teller contract when contract is not paused. /// @dev Function checks asset is on the allowlist to avoid unsupported tokens getting stuck. /// @param deposit Deposit to handle function handleDeposit( Deposit calldata deposit ) external override whenNotPaused onlyTeller returns (uint128 merkleIndex) { // Ensure deposit asset is supported EncodedAsset memory encodedAsset = deposit.encodedAsset; (, address assetAddr, ) = AssetUtils.decodeAsset(encodedAsset); require(_supportedContracts[assetAddr], "!supported deposit asset"); merkleIndex = _handleRefundNote( encodedAsset, deposit.depositAddr, deposit.value ); return merkleIndex; } /// @notice Handles an operation after proofs have been verified by the Teller. Checks /// joinSplits, requests proven funds from the Teller, executes op.actions, compensates /// the bundler, then handles refunds. /// @dev This method is only callable by the Teller contract when contract is not paused. /// @dev There are 3 call nested call contexts used to isolate different types of errors: /// 1. handleOperation: A revert here means the bundler failed to perform standard /// checks that are predictable (e.g. valid chainid, valid deadline, enough gas /// assets, etc). The bundler is not compensated when reverts happen here because /// the revert happens before _gatherReservedGasAssetAndPayBundler is called. /// 2. executeActions: A revert here can be due to unpredictable reasons, mainly if /// there is not enough executionGas for the actions or if after executing actions, /// there are fewer refund tokens than what was specified in trackedAssets /// minRefundValues. /// 3. _makeExternalCall: A revert here only leads to top level revert if /// op.atomicActions = true (requires all actions to succeed atomically or none at /// all). /// @param op Operation to handle /// @param perJoinSplitVerifyGas Gas usage for verifying a single joinSplit proof /// @param bundler Address of the bundler function handleOperation( Operation calldata op, uint256 perJoinSplitVerifyGas, address bundler ) external whenNotPaused onlyTeller handleOperationGuard returns (OperationResult memory opResult) { // Ensure all assets supported uint256 numTrackedAssets = op.trackedAssets.length; for (uint256 i = 0; i < numTrackedAssets; i++) { (, address assetAddr, ) = AssetUtils.decodeAsset( op.trackedAssets[i].encodedAsset ); require(_supportedContracts[assetAddr], "!supported asset"); } // Ensure all token balances of tokens to be used are zeroed out _ensureZeroedBalances(op); // Mark merkle count pre operation opResult.preOpMerkleCount = totalCount(); // Handle all joinsplits uint256 numJoinSplitAssets = _processJoinSplitsReservingFee( op, perJoinSplitVerifyGas ); // If reached this point, assets have been unwrapped and will have refunds to handle opResult.assetsUnwrapped = true; uint256 preExecutionGas = gasleft(); try this.executeActions{gas: op.executionGasLimit}(op) returns ( bool[] memory successes, bytes[] memory results, uint256 numRefundsToHandle ) { opResult.opProcessed = true; opResult.callSuccesses = successes; opResult.callResults = results; opResult.numRefunds = numRefundsToHandle; } catch (bytes memory reason) { // Indicates revert because of one of the following reasons: // 1. `executeActions` yielded fewer refund tokens than expected in // trackedAssets // 2. `executeActions` exceeded `executionGasLimit`, but in its outer call context // (i.e. while not making an external call) // 3. There was a revert when executing actions (e.g. atomic actions, unsupported // contract call, etc) // We explicitly catch cases 1 and 3 in `executeActions`, so if `executeActions` failed // silently, then it must be case 2. string memory revertMsg = OperationUtils.getRevertMsg(reason); if (bytes(revertMsg).length == 0) { opResult.failureReason = "exceeded `executionGasLimit`"; } else { opResult.failureReason = revertMsg; } // In case that action execution reverted, num refunds to handle will be number of // joinSplit assets. NOTE that this could be higher estimate than actual if joinsplits // are not organized in contiguous subarrays by user. opResult.numRefunds = numJoinSplitAssets; } // Set verification and execution gas after getting opResult opResult.verificationGas = perJoinSplitVerifyGas * op.totalNumJoinSplits(); opResult.executionGas = Utils.min( op.executionGasLimit, preExecutionGas - gasleft() ); // Gather reserved gas asset and process gas payment to bundler _gatherReservedGasAssetAndPayBundler( op, opResult, perJoinSplitVerifyGas, bundler ); _handleAllRefunds(op); // Mark new merkle count post operation opResult.postOpMerkleCount = totalCount(); return opResult; } /// @notice Executes an array of actions for an operation. /// @dev This function is only callable by the Handler itself when not paused. /// @dev This function can revert if any of the below occur (revert not within action itself): /// 1. The call runs out of gas in the outer call context (OOG) /// 2. The executed actions result in fewer refunds than expected in /// trackedAssets /// 3. An action reverts and atomicActions is set to true /// 4. A call to an unsupported protocol is attempted /// 5. An action attempts to re-enter by calling the Teller contract /// @param op Operation to execute actions for function executeActions( Operation calldata op ) external whenNotPaused onlyThis executeActionsGuard returns ( bool[] memory successes, bytes[] memory results, uint256 numRefundsToHandle ) { uint256 numActions = op.actions.length; successes = new bool[](numActions); results = new bytes[](numActions); // Execute each external call for (uint256 i = 0; i < numActions; i++) { (successes[i], results[i]) = _makeExternalCall(op.actions[i]); if (op.atomicActions && !successes[i]) { string memory revertMsg = OperationUtils.getRevertMsg( results[i] ); if (bytes(revertMsg).length == 0) { // TODO maybe say which action? revert("action silently reverted"); } else { revert(revertMsg); } } } // NOTE: if any tokens have < expected refund value, the below call will revert. This causes // executeActions to revert, undoing all state changes in this call context. The user still // ends up compensating the bundler for gas in this case. numRefundsToHandle = _ensureMinRefundValues(op); } /// @notice Makes an external call to execute a single action /// @dev Reverts if caller attempts to call unsupported contract OR if caller tries /// to re-enter by calling the Teller contract. /// @dev There is a special check on methods with the erc20.approve selector that ensures only /// whitelisted protocols can be approved as `spender` for erc20 tokens. Without this /// check, users can call erc20.approve(amount, spender) from the Handler contract to /// approve arbitrary spenders. function _makeExternalCall( Action calldata action ) internal returns (bool success, bytes memory result) { // Ensure contract exists require(action.contractAddress.code.length != 0, "!zero code"); // Block re-entrancy from teller calling self require( action.contractAddress != address(_teller), "Cannot call the Nocturne Teller" ); // Ensure contract and method to call are supported bytes4 selector = _extractFunctionSelector(action.encodedFunction); uint192 addressAndSelector = _addressAndSelector( action.contractAddress, selector ); require( _supportedContractMethods[addressAndSelector], "Cannot call non-allowed protocol method" ); // NOTE: If an allowed protocol has a selector clash with erc20.approve, then abi.decode // will yield whatever data is formatted at bytes 4:23 for spender. This will likely revert // and cause the clashing function to not be callable. If 1st argument happens to be a // whitelisted address, then the clashing function will be callable. Selector clashes, // however, are not an issue here, as this check is only meant to ensure the normal case // (erc20s with standard approve fn signature) have protection against arbitrary approvals // and is not intended to have any bearing on other non-erc20 or non-approve cases. Worst // case outcome is that small number of functions with signature clash will not be callable. if (selector == ERC20_APPROVE_SELECTOR) { require( action.encodedFunction.length == ERC_20_APPROVE_FN_DATA_LENGTH, "!approve fn length" ); (address spender, ) = abi.decode( action.encodedFunction[4:], (address, uint256) ); require(_supportedContracts[spender], "!approve spender"); } (success, result) = action.contractAddress.call(action.encodedFunction); } /// @notice Extract function selector from encoded function data /// @param encodedFunctionData Encoded function data function _extractFunctionSelector( bytes calldata encodedFunctionData ) internal pure returns (bytes4 selector) { require(encodedFunctionData.length >= 4, "!encoded fn length"); return bytes4(encodedFunctionData[:4]); } /// @notice Concat address and selector as key to contract allowlist /// @param contractAddress Address of the contract /// @param selector Selector of the function function _addressAndSelector( address contractAddress, bytes4 selector ) internal pure returns (uint192) { return (uint192(uint160(contractAddress)) << 32) | uint32(selector); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol) pragma solidity ^0.8.0; import "./OwnableUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership} and {acceptOwnership}. * * This module is used through inheritance. It will make available all functions * from parent (Ownable). */ abstract contract Ownable2StepUpgradeable is Initializable, OwnableUpgradeable { function __Ownable2Step_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable2Step_init_unchained() internal onlyInitializing { } address private _pendingOwner; event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner); /** * @dev Returns the address of the pending owner. */ function pendingOwner() public view virtual returns (address) { return _pendingOwner; } /** * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual override onlyOwner { _pendingOwner = newOwner; emit OwnershipTransferStarted(owner(), newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner. * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual override { delete _pendingOwner; super._transferOwnership(newOwner); } /** * @dev The new owner accepts the ownership transfer. */ function acceptOwnership() public virtual { address sender = _msgSender(); require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner"); _transferOwnership(sender); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://consensys.net/diligence/blog/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.8.0/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"); (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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // 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 /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch( address[] calldata accounts, uint256[] calldata ids ) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); /** * @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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/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. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ 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 { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to * 0 before setting it to a non-zero value. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @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). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // 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 cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ 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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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://consensys.net/diligence/blog/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.8.0/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"); (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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // 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 /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; // Internal import {ITeller} from "./interfaces/ITeller.sol"; import {CommitmentTreeManager} from "./CommitmentTreeManager.sol"; import {Utils} from "./libs/Utils.sol"; import {AssetUtils} from "./libs/AssetUtils.sol"; import {OperationUtils} from "./libs/OperationUtils.sol"; import "./libs/Types.sol"; /// @title BalanceManager /// @author Nocturne Labs /// @notice Module containing logic for funding the Handler contract during operation processing and /// handling refunds for any remaining assets left in the Handler after operation execution. contract BalanceManager is CommitmentTreeManager { using OperationLib for Operation; // Teller contract to send/request assets to/from ITeller public _teller; // Leftover tokens holder contract address public _leftoverTokensHolder; // Gap for upgrade safety uint256[50] private __GAP; /// @notice Internal initializer function /// @param subtreeUpdateVerifier Address of the subtree update verifier contract /// @param leftoverTokensHolder Address of the leftover tokens holder contract function __BalanceManager_init( address subtreeUpdateVerifier, address leftoverTokensHolder ) internal onlyInitializing { __CommitmentTreeManager_init(subtreeUpdateVerifier); _leftoverTokensHolder = leftoverTokensHolder; } /// @notice Set teller contract after initialization /// @dev Teller and Handler initialization depend on each other's deployments thus we cannot /// initialize the Teller and Handler in the same transaction (as we have to deploy one /// before the other). We set Teller separately after initialization to avoid /// front-running risk. /// @dev Because we require Teller address is 0x0, this method is only executable once. /// @param teller Address of the teller contract function setTeller(address teller) external onlyOwner { require(address(_teller) == address(0), "Teller already set"); _teller = ITeller(teller); } /// @notice For each public and conf joinSplit, check root and nullifier validity against /// commitment tree manager, then request joinSplit.publicSpend barring tokens for gas /// payment for pubJoinSplits (conf joinSplits are only handled in CTM, no fund /// processing since all publicSpends implicitly 0). /// @dev Before looping through pubJoinSplits, we calculate amount of gas to reserve based on /// execution gas, number of pubJoinSplits, and number of refunds. Then we loop through /// pubJoinSplits, check root and nullifier validity, and attempt to reserve as much gas /// asset. /// as possible until we have gotten as the reserve amount we originally calculated. If we /// have not reserved enough gas asset after looping through all pubJoinSplits, we revert. /// @dev We attempt to group asset transfers to handler by contiguous subarrays of pubJoinSplits /// for same asset. User can group however they like but contiguous group saves them gas /// by reducing number of teller.requestAsset calls. /// @param op Operation to process pubJoinSplits for /// @param perJoinSplitVerifyGas Gas cost of verifying a single joinSplit proof, calculated by /// teller during (batch) proof verification function _processJoinSplitsReservingFee( Operation calldata op, uint256 perJoinSplitVerifyGas ) internal returns (uint256 numJoinSplitAssets) { // process nullifiers and insert new noteCommitments for each joinSplit // will throw an error if nullifiers are invalid or tree root invalid // NOTE: we handle both public and conf joinSplits here, all code below though is // only called on public joinSplits _handleJoinSplits(op); // Get gas asset and amount to reserve EncodedAsset calldata encodedGasAsset = op.encodedGasAsset; uint256 gasAssetToReserve = op.maxGasAssetCost(perJoinSplitVerifyGas); // Loop through pubJoinSplits and gather assets, reserving gas asset as needed EncodedAsset calldata encodedAsset; uint256 numJoinSplits = op.pubJoinSplits.length; for ( uint256 subarrayStartIndex = 0; subarrayStartIndex < numJoinSplits; ) { uint8 joinSplitAssetIndex = op .pubJoinSplits[subarrayStartIndex] .assetIndex; encodedAsset = op.trackedAssets[joinSplitAssetIndex].encodedAsset; // Get largest possible subarray for current asset and sum of publicSpend uint256 subarrayEndIndex = _getHighestContiguousJoinSplitIndex( op.pubJoinSplits, subarrayStartIndex ); uint256 valueToGatherForSubarray = _sumJoinSplitPublicSpendsInclusive( op.pubJoinSplits, subarrayStartIndex, subarrayEndIndex ); if ( gasAssetToReserve > 0 && AssetUtils.eq(encodedGasAsset, encodedAsset) ) { uint256 reserveValue = Utils.min( valueToGatherForSubarray, gasAssetToReserve ); valueToGatherForSubarray -= reserveValue; gasAssetToReserve -= reserveValue; } subarrayStartIndex = subarrayEndIndex + 1; numJoinSplitAssets++; // NOTE: if joinsplits not sorted contiguously by asset, this number will be higher than the actual number of joinsplits // If value to transfer is 0, skip the transfer if (valueToGatherForSubarray > 0) { _teller.requestAsset(encodedAsset, valueToGatherForSubarray); } } require(gasAssetToReserve == 0, "Too few gas tokens"); } /// @notice Gather reserved gas assets and pay bundler calculated amount. /// @dev Bundler can be paid less than reserved amount. Reserved amount is refunded to user's /// stealth address in this case. /// @dev If the amount of gas asset remaining after bundler payout is less than the operation's /// gasAssetRefundThreshold, we just give the remaining amount to bundler. This is because /// the cost of handling refund for dust note and later proving ownership of the dust note /// will outweigh the actual value of the note. /// @param op Operation, which contains info on how much gas was reserved /// @param opResult OperationResult, which contains info on how much gas was actually spent /// @param perJoinSplitVerifyGas Gas cost of verifying a single joinSplit proof /// @param bundler Address of the bundler to pay function _gatherReservedGasAssetAndPayBundler( Operation calldata op, OperationResult memory opResult, uint256 perJoinSplitVerifyGas, address bundler ) internal { EncodedAsset calldata encodedGasAsset = op.encodedGasAsset; uint256 gasAssetReserved = op.maxGasAssetCost(perJoinSplitVerifyGas); if (gasAssetReserved > 0) { // Request reserved gasAssetReserved from teller. /// @dev This is safe because _processJoinSplitsReservingFee is /// guaranteed to have reserved gasAssetReserved since it didn't throw. _teller.requestAsset(encodedGasAsset, gasAssetReserved); uint256 bundlerPayout = OperationUtils .calculateBundlerGasAssetPayout(op, opResult); if (gasAssetReserved - bundlerPayout < op.gasAssetRefundThreshold) { bundlerPayout = gasAssetReserved; // Give all to bundler if under threshold } AssetUtils.transferAssetTo(encodedGasAsset, bundler, bundlerPayout); } } /// @notice Ensure all joinsplit and refund assets start with empty balances (0 or 1). /// @dev If any asset has a balance > 1, we transfer the excess to the leftover tokens contract /// and return the amount transferred. /// @dev This is to ensure a user cannot bypass deposit limits by sending tokens to the handler /// externally then creating an operation to claim those funds via refunds. /// @param op Operation to ensure zeroed balances for function _ensureZeroedBalances(Operation calldata op) internal { uint256 numTrackedAssets = op.trackedAssets.length; for (uint256 i = 0; i < numTrackedAssets; i++) { _transferOutstandingAssetToAndReturnAmount( op.trackedAssets[i].encodedAsset, _leftoverTokensHolder ); } } /// @notice Ensure all tracked assets have a balance >= minRefundValue and return number of /// refunds to handle. If any asset has a balance < minRefundValue, call reverts. /// @param op Operation to ensure min refund values for function _ensureMinRefundValues( Operation calldata op ) internal view returns (uint256 numRefundsToHandle) { bool gasAssetAlreadyInRefunds = false; uint256 numTrackedAssets = op.trackedAssets.length; for (uint256 i = 0; i < numTrackedAssets; i++) { uint256 refundValue = _ensureMinRefundValueForTrackedAsset( op.trackedAssets[i] ); if (refundValue > 0) { numRefundsToHandle++; if ( !gasAssetAlreadyInRefunds && AssetUtils.eq( op.trackedAssets[i].encodedAsset, op.encodedGasAsset ) ) { gasAssetAlreadyInRefunds = true; } } } // If we withheld gas asset and there is no existing refund of the same type as the gas // asset, we add an additional refund to numRefundsToHandle to reflect the potential for // additional refund of gas asset after bundler compensation. // NOTE: the only time numRefundsToHandle gets over-counted is when the bundler // takes all reserved gas asset, leaving none for refund. The max over-estimate though // is the cost of the one extra refund. if (!gasAssetAlreadyInRefunds && op.gasPrice > 0) { numRefundsToHandle++; } return numRefundsToHandle; } /// @notice Ensure tracked asset has a balance >= minRefundValue and return true if a refund /// is required. If asset has a balance < minRefundValue, call reverts. /// @param trackedAsset Tracked asset to ensure min refund value for function _ensureMinRefundValueForTrackedAsset( TrackedAsset calldata trackedAsset ) internal view returns (uint256 refundValue) { EncodedAsset calldata encodedAsset = trackedAsset.encodedAsset; uint256 currentBalance = AssetUtils.balanceOfAsset(encodedAsset); // We want to guarantee that the minRefundValue check is exact, so we account for // the token prefills gas optimization that attempts to keep balance of Handler = 1 for // erc20s (AssetType assetType, , ) = AssetUtils.decodeAsset(encodedAsset); uint256 amountToWithhold = assetType == AssetType.ERC20 ? 1 : 0; refundValue = currentBalance > amountToWithhold ? currentBalance - amountToWithhold : 0; require( refundValue >= trackedAsset.minRefundValue, "!min refund value" ); return refundValue; } /// @notice Handle all refunds for an operation, potentially sending back any leftover assets /// to the Teller and inserting new note commitments for the sent back assets. /// @dev Checks for refunds in op.trackedAssets. A refund occurs if any of the checked assets /// have outstanding balance > 0 in the Handler. If a refund occurs, the Handler will /// transfer the asset back to the Teller and insert a new /// note commitment into the commitment tree. /// @param op Operation to handle refunds for function _handleAllRefunds(Operation calldata op) internal { EncodedAsset calldata encodedAsset; uint256 numTrackedAssets = op.trackedAssets.length; for (uint256 i = 0; i < numTrackedAssets; i++) { encodedAsset = op.trackedAssets[i].encodedAsset; uint256 refundAmount = _transferOutstandingAssetToAndReturnAmount( encodedAsset, address(_teller) ); if (refundAmount > 0) { _handleRefundNote(encodedAsset, op.refundAddr, refundAmount); } } } /// @notice Refund Teller for a single asset /// @dev Checks if asset has outstanding balance in the Handler. If so, transfers the asset /// back to the Teller and returns the amount transferred. /// @dev To prevent clearing the handler's token balances to 0 each time for erc20s, we attempt /// to withold 1 token from the refund each time if the handler's current balance is 0. /// This saves gas for future users because it avoids writing to a zeroed out storage slot /// each time for the handler's balance. This single token can technically be taken by any /// user. The goal is to keep the handler's balance non-zero as often as possible to save /// on user gas. /// @param encodedAsset Encoded asset to check for refund function _transferOutstandingAssetToAndReturnAmount( EncodedAsset memory encodedAsset, address to ) internal returns (uint256) { require( to == address(_teller) || to == address(_leftoverTokensHolder), "Invalid to addr" ); uint256 currentBalance = AssetUtils.balanceOfAsset(encodedAsset); (AssetType assetType, , ) = AssetUtils.decodeAsset(encodedAsset); uint256 amountToWithhold = assetType == AssetType.ERC20 ? 1 : 0; uint256 difference = currentBalance > amountToWithhold ? currentBalance - amountToWithhold : 0; if (difference > 0) { // Token callback safe since we know leftoverTokensHandler and Teller have no receiver hooks currently AssetUtils.transferAssetTo(encodedAsset, to, difference); return difference; } return 0; } /// @notice Get highest index for contiguous subarray of joinsplits of same encodedAssetType /// @dev Used so we can take sum(subarray) make single call teller.requestAsset(asset, sum) /// instead of calling teller.requestAsset multiple times for the same asset /// @param pubJoinSplits Joinsplits /// @param startIndex Index to start searching from function _getHighestContiguousJoinSplitIndex( PublicJoinSplit[] calldata pubJoinSplits, uint256 startIndex ) private pure returns (uint256) { uint256 startAssetIndex = pubJoinSplits[startIndex].assetIndex; uint256 numJoinSplits = pubJoinSplits.length; uint256 highestIndex = startIndex; while ( highestIndex + 1 < numJoinSplits && startAssetIndex == pubJoinSplits[highestIndex + 1].assetIndex ) { highestIndex++; } return highestIndex; } /// @notice Get sum of public spends for a contiguous subarray of joinsplits /// @param pubJoinSplits op pubJoinSplits /// @param startIndex Index to start summing from /// @param endIndex Index to end summing at (inclusive) function _sumJoinSplitPublicSpendsInclusive( PublicJoinSplit[] calldata pubJoinSplits, uint256 startIndex, uint256 endIndex ) private pure returns (uint256) { uint256 sum = 0; for (uint256 i = startIndex; i <= endIndex; i++) { sum += pubJoinSplits[i].publicSpend; } return sum; } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; // External import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; // Internal import {LibOffchainMerkleTree, OffchainMerkleTree} from "./libs/OffchainMerkleTree.sol"; import {Utils} from "./libs/Utils.sol"; import {Validation} from "./libs/Validation.sol"; import {TreeUtils} from "./libs/TreeUtils.sol"; import "./libs/Types.sol"; /// @title CommitmentTreeManager /// @author Nocturne Labs /// @notice Manages the commitment tree, keeps track of past roots, and keeps track of used /// nullifiers. contract CommitmentTreeManager is Initializable, Ownable2StepUpgradeable, PausableUpgradeable { using LibOffchainMerkleTree for OffchainMerkleTree; using OperationLib for Operation; // Set of past roots of the merkle tree mapping(uint256 => bool) public _pastRoots; // Set of used nullifiers mapping(uint256 => bool) public _nullifierSet; // Offchain merkle tree struct OffchainMerkleTree internal _merkle; // Set of addressed allowed to fill subtree batches with zeros mapping(address => bool) public _subtreeBatchFillers; // Gap for upgrade safety uint256[50] private __GAP; /// @notice Event emitted when a subtree batch filler is given/revoked permission event SubtreeBatchFillerPermissionSet(address filler, bool permission); /// @notice Event emitted when a refund is processed /// @dev Refund means any outstanding assets left in the handler during execution /// or a new deposit event RefundProcessed( CompressedStealthAddress refundAddr, uint256 nonce, uint256 encodedAssetAddr, uint256 encodedAssetId, uint256 value, uint128 merkleIndex ); /// @notice Event emitted when a joinsplit is processed event JoinSplitProcessed( uint256 indexed oldNoteANullifier, uint256 indexed oldNoteBNullifier, uint128 newNoteAIndex, uint128 newNoteBIndex, uint256 newNoteACommitment, uint256 newNoteBCommitment, uint256 senderCommitment, uint256 joinSplitInfoCommitment, EncryptedNote newNoteAEncrypted, EncryptedNote newNoteBEncrypted ); /// @notice Event emitted when a subtree batch is filled with zeros event FilledBatchWithZeros(uint256 startIndex, uint256 numZeros); /// @notice Event emitted when a subtree (and subsequently the main tree's root) are updated event SubtreeUpdate(uint256 newRoot, uint256 subtreeBatchOffset); /// @notice Internal initialization function /// @param subtreeUpdateVerifier Address of the subtree update verifier contract function __CommitmentTreeManager_init( address subtreeUpdateVerifier ) internal onlyInitializing { __Ownable2Step_init(); __Pausable_init(); _merkle.initialize(subtreeUpdateVerifier); _pastRoots[TreeUtils.EMPTY_TREE_ROOT] = true; } /// @notice Require caller is permissioned batch filler modifier onlySubtreeBatchFiller() { require(_subtreeBatchFillers[msg.sender], "Only subtree batch filler"); _; } /// @notice Owner-only function, sets address permission to call `fillBatchesWithZeros` /// @param filler Address to set permission for /// @param permission Permission to set function setSubtreeBatchFillerPermission( address filler, bool permission ) external onlyOwner { _subtreeBatchFillers[filler] = permission; emit SubtreeBatchFillerPermissionSet(filler, permission); } /// @notice Inserts a batch of zero refund notes into the commitment tree /// @dev This function allows the an entity to expedite process of being able to update /// the merkle tree root. The caller of this function function fillBatchWithZeros() external onlySubtreeBatchFiller { uint256 batchLen = _merkle.getBatchLen(); require(batchLen > 0, "!zero fill empty batch"); uint256 startIndex = _merkle.getTotalCount(); uint256 numZeros = TreeUtils.BATCH_SIZE - batchLen; _merkle.fillBatchWithZeros(); emit FilledBatchWithZeros(startIndex, numZeros); } /// @notice Attempts to update the tree's root given a subtree update proof /// @param newRoot The new root of the Merkle tree after the subtree update /// @param proof The proof for the subtree update function applySubtreeUpdate( uint256 newRoot, uint256[8] calldata proof ) external whenNotPaused { require(!_pastRoots[newRoot], "newRoot already a past root"); uint256 subtreeBatchOffset = _merkle.getCount(); _merkle.applySubtreeUpdate(newRoot, proof); _pastRoots[newRoot] = true; emit SubtreeUpdate(newRoot, subtreeBatchOffset); } /// @notice Returns current root of the merkle tree function root() public view returns (uint256) { return _merkle.getRoot(); } /// @notice Returns count of the merkle tree under the current root function count() public view returns (uint128) { return _merkle.getCount(); } /// @notice Returns the count of the merkle tree including leaves that have not yet been /// included in a subtree update function totalCount() public view returns (uint128) { return _merkle.getTotalCount(); } /// @notice Inserts note into commitment tree /// @param note note to insert function _insertNote(EncodedNote memory note) internal { // ensure note can be decommitted by subtree update circuit + addrs are valid Validation.validateNote(note); _merkle.insertNote(note); } /// @notice Inserts several note commitments into the tree /// @param ncs Note commitments to insert function _insertNoteCommitments(uint256[] memory ncs) internal { _merkle.insertNoteCommitments(ncs); } /// @notice Process an op's pubJoinSplits, assuming that their proofs have already been /// verified. /// Ensures joinSplit commitment tree root is up to date, that nullifiers are not /// reused, adds the new NFs to the nullifier set, and inserts the new note NCs. /// @dev This function should be re-entry safe. Nullifiers are be marked /// used as soon as they are checked to be valid. /// @param op Operation with joinsplits function _handleJoinSplits(Operation calldata op) internal { uint256 totalNumJoinSplits = op.totalNumJoinSplits(); uint256[] memory newNoteCommitments = new uint256[]( totalNumJoinSplits * 2 ); uint128 offset = _merkle.getTotalCount(); JoinSplit calldata joinSplit; for (uint256 i = 0; i < totalNumJoinSplits; i++) { joinSplit = i < op.pubJoinSplits.length ? op.pubJoinSplits[i].joinSplit : op.confJoinSplits[i - op.pubJoinSplits.length]; // Check commitment tree root is valid require( _pastRoots[joinSplit.commitmentTreeRoot], "Tree root not past root" ); // Check both NFs are not already used and don't match require( !_nullifierSet[joinSplit.nullifierA], "Nullifier A already used" ); require( !_nullifierSet[joinSplit.nullifierB], "Nullifier B already used" ); require( joinSplit.nullifierA != joinSplit.nullifierB, "2 nfs should !equal" ); // Mark NFs used _nullifierSet[joinSplit.nullifierA] = true; _nullifierSet[joinSplit.nullifierB] = true; // Compute newNote indices in the merkle tree uint128 newNoteIndexA = offset + uint128(2 * i); uint128 newNoteIndexB = offset + uint128(2 * i + 1); // Insert new note commitments newNoteCommitments[i * 2] = joinSplit.newNoteACommitment; newNoteCommitments[i * 2 + 1] = joinSplit.newNoteBCommitment; emit JoinSplitProcessed( joinSplit.nullifierA, joinSplit.nullifierB, newNoteIndexA, newNoteIndexB, joinSplit.newNoteACommitment, joinSplit.newNoteBCommitment, joinSplit.senderCommitment, joinSplit.joinSplitInfoCommitment, joinSplit.newNoteAEncrypted, joinSplit.newNoteBEncrypted ); } _insertNoteCommitments(newNoteCommitments); } /// @notice Inserts a single refund note into the commitment tree /// @param encodedAsset Encoded asset refund note is being created for /// @param refundAddr Stealth address refund note is created to /// @param value Value of refund note for given asset function _handleRefundNote( EncodedAsset memory encodedAsset, CompressedStealthAddress calldata refundAddr, uint256 value ) internal returns (uint128 merkleIndex) { merkleIndex = _merkle.getTotalCount(); EncodedNote memory note = EncodedNote({ ownerH1: refundAddr.h1, ownerH2: refundAddr.h2, nonce: uint256(merkleIndex), encodedAssetAddr: encodedAsset.encodedAssetAddr, encodedAssetId: encodedAsset.encodedAssetId, value: value }); _insertNote(note); emit RefundProcessed( refundAddr, note.nonce, encodedAsset.encodedAssetAddr, encodedAsset.encodedAssetId, value, merkleIndex ); return merkleIndex; } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import "../libs/Types.sol"; interface IHandler { function handleOperation( Operation calldata op, uint256 perJoinSplitVerifyGas, address bundler ) external returns (OperationResult memory); function handleDeposit( Deposit calldata deposit ) external returns (uint128 merkleIndex); }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {IVerifier} from "./IVerifier.sol"; /// @title Verifier interface. /// @dev Interface of Verifier contract. interface ISubtreeUpdateVerifier is IVerifier { }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import "../libs/Types.sol"; interface ITeller { function processBundle( Bundle calldata bundle ) external returns ( uint256[] memory opDigests, OperationResult[] memory opResults ); function depositFunds( Deposit calldata deposit ) external returns (uint128 merkleIndex); function requestAsset( EncodedAsset calldata encodedAsset, uint256 value ) external; }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {Groth16} from "../libs/Groth16.sol"; /// @title interface for verifiers that support batch verification. /// @dev Interface for verifiers that support batch verification. interface IVerifier { /// @param proof: the proof to verify /// @param pis: an array of containing the public inputs for the proof function verifyProof( uint256[8] memory proof, uint256[] memory pis ) external view returns (bool); /// @param proofs: an array containing the proofs to verify /// @param pis: an array of length `NUM_PIS * numProofs` containing the PIs for each proof concatenated together function batchVerifyProofs( uint256[8][] memory proofs, uint256[][] memory pis ) external view returns (bool); }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import {Utils} from "../libs/Utils.sol"; import "../libs/Types.sol"; library AssetUtils { using SafeERC20 for IERC20; uint256 constant MASK_111 = 7; uint256 constant MASK_11 = 3; uint256 constant BITS_250_TO_252_MASK = (MASK_111 << 250); uint256 constant BOTTOM_253_MASK = (1 << 253) - 1; uint256 constant BOTTOM_160_MASK = (1 << 160) - 1; function encodeAsset( AssetType assetType, address assetAddr, uint256 id ) internal pure returns (EncodedAsset memory encodedAsset) { uint256 encodedAssetId = id & BOTTOM_253_MASK; uint256 assetTypeBits; if (assetType == AssetType.ERC20) { assetTypeBits = uint256(0); } else if (assetType == AssetType.ERC721) { assetTypeBits = uint256(1); } else if (assetType == AssetType.ERC1155) { assetTypeBits = uint256(2); } else { revert("Invalid assetType"); } uint256 encodedAssetAddr = ((id >> 3) & BITS_250_TO_252_MASK) | (assetTypeBits << 160) | (uint256(uint160(assetAddr))); return EncodedAsset({ encodedAssetAddr: encodedAssetAddr, encodedAssetId: encodedAssetId }); } function decodeAsset( EncodedAsset memory encodedAsset ) internal pure returns (AssetType assetType, address assetAddr, uint256 id) { id = ((encodedAsset.encodedAssetAddr & BITS_250_TO_252_MASK) << 3) | encodedAsset.encodedAssetId; assetAddr = address( uint160(encodedAsset.encodedAssetAddr & BOTTOM_160_MASK) ); uint256 assetTypeBits = (encodedAsset.encodedAssetAddr >> 160) & MASK_11; if (assetTypeBits == 0) { assetType = AssetType.ERC20; } else if (assetTypeBits == 1) { assetType = AssetType.ERC721; } else if (assetTypeBits == 2) { assetType = AssetType.ERC1155; } else { revert("Invalid encodedAssetAddr"); } return (assetType, assetAddr, id); } function hashEncodedAsset( EncodedAsset memory encodedAsset ) internal pure returns (bytes32) { return keccak256( abi.encodePacked( encodedAsset.encodedAssetAddr, encodedAsset.encodedAssetId ) ); } function balanceOfAsset( EncodedAsset memory encodedAsset ) internal view returns (uint256) { (AssetType assetType, address assetAddr, uint256 id) = AssetUtils .decodeAsset(encodedAsset); uint256 value = 0; if (assetType == AssetType.ERC20) { value = IERC20(assetAddr).balanceOf(address(this)); } else if (assetType == AssetType.ERC721) { // If erc721 not minted, return balance = 0 try IERC721(assetAddr).ownerOf(id) returns (address owner) { if (owner == address(this)) { value = 1; } } catch {} } else if (assetType == AssetType.ERC1155) { value = IERC1155(assetAddr).balanceOf(address(this), id); } else { revert("Invalid asset"); } return value; } /** @dev Transfer asset to receiver. Throws if unsuccssful. */ function transferAssetTo( EncodedAsset memory encodedAsset, address receiver, uint256 value ) internal { (AssetType assetType, address assetAddr, ) = decodeAsset(encodedAsset); if (assetType == AssetType.ERC20) { IERC20(assetAddr).safeTransfer(receiver, value); } else if (assetType == AssetType.ERC721) { revert("!supported"); } else if (assetType == AssetType.ERC1155) { revert("!supported"); } else { revert("Invalid asset"); } } /** @dev Transfer asset from spender. Throws if unsuccssful. */ function transferAssetFrom( EncodedAsset memory encodedAsset, address spender, uint256 value ) internal { (AssetType assetType, address assetAddr, ) = decodeAsset(encodedAsset); if (assetType == AssetType.ERC20) { IERC20(assetAddr).safeTransferFrom(spender, address(this), value); } else if (assetType == AssetType.ERC721) { revert("!supported"); } else if (assetType == AssetType.ERC1155) { revert("!supported"); } else { revert("Invalid asset"); } } /** @dev Approve asset to spender for value. Throws if unsuccssful. */ function approveAsset( EncodedAsset memory encodedAsset, address spender, uint256 value ) internal { (AssetType assetType, address assetAddr, ) = decodeAsset(encodedAsset); if (assetType == AssetType.ERC20) { // TODO: next OZ release will add SafeERC20.forceApprove IERC20(assetAddr).approve(spender, 0); IERC20(assetAddr).approve(spender, value); } else if (assetType == AssetType.ERC721) { revert("!supported"); } else if (assetType == AssetType.ERC1155) { revert("!supported"); } else { revert("Invalid asset"); } } function eq( EncodedAsset calldata assetA, EncodedAsset calldata assetB ) internal pure returns (bool) { return (assetA.encodedAssetAddr == assetB.encodedAssetAddr) && (assetA.encodedAssetId == assetB.encodedAssetId); } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {Pairing} from "./Pairing.sol"; import {Utils} from "./Utils.sol"; library Groth16 { struct VerifyingKey { Pairing.G1Point alpha1; Pairing.G2Point beta2; Pairing.G2Point gamma2; Pairing.G2Point delta2; Pairing.G1Point[] IC; } struct Proof { Pairing.G1Point A; Pairing.G2Point B; Pairing.G1Point C; } // Verifying a single Groth16 proof function verifyProof( VerifyingKey memory vk, uint256[8] memory proof8, uint256[] memory pi ) internal view returns (bool) { require(vk.IC.length == pi.length + 1, "Public input length mismatch."); Pairing.G1Point memory vk_x = vk.IC[0]; for (uint i = 0; i < pi.length; i++) { require( pi[i] < Utils.BN254_SCALAR_FIELD_MODULUS, "Malformed public input." ); vk_x = Pairing.addition( vk_x, Pairing.scalar_mul(vk.IC[i + 1], pi[i]) ); } Proof memory proof = _proof8ToStruct(proof8); return Pairing.pairingProd4( Pairing.negate(proof.A), proof.B, vk.alpha1, vk.beta2, vk_x, vk.gamma2, proof.C, vk.delta2 ); } function accumulate( Proof[] memory proofs, uint256[][] memory allPis ) internal view returns ( Pairing.G1Point[] memory proofAsandAggegateC, uint256[] memory publicInputAccumulators ) { uint256 allPisLength = allPis.length; uint256 numProofs = proofs.length; uint256 numPublicInputs = allPis[0].length; for (uint256 i = 1; i < allPisLength; i++) { require( numPublicInputs == allPis[i].length, "Public input mismatch during batch verification." ); } uint256[] memory entropy = new uint256[](numProofs); publicInputAccumulators = new uint256[](numPublicInputs + 1); // Generate entropy for each proof and accumulate each PI // seed a challenger by hashing all of the proofs and the current blockhash togethre uint256 challengerState = uint256( keccak256(abi.encode(proofs, blockhash(block.number - 1))) ); for (uint256 proofIndex = 0; proofIndex < numProofs; proofIndex++) { if (proofIndex == 0) { entropy[proofIndex] = 1; } else { challengerState = uint256( keccak256(abi.encodePacked(challengerState)) ); entropy[proofIndex] = challengerState; } require(entropy[proofIndex] != 0, "Entropy should not be zero"); // here multiplication by 1 is implied publicInputAccumulators[0] = addmod( publicInputAccumulators[0], entropy[proofIndex], Utils.BN254_SCALAR_FIELD_MODULUS ); for (uint256 i = 0; i < numPublicInputs; i++) { require( allPis[proofIndex][i] < Utils.BN254_SCALAR_FIELD_MODULUS, "Malformed public input" ); // accumulate the exponent with extra entropy mod Utils.BN254_SCALAR_FIELD_MODULUS publicInputAccumulators[i + 1] = addmod( publicInputAccumulators[i + 1], mulmod( entropy[proofIndex], allPis[proofIndex][i], Utils.BN254_SCALAR_FIELD_MODULUS ), Utils.BN254_SCALAR_FIELD_MODULUS ); } } proofAsandAggegateC = new Pairing.G1Point[](numProofs + 1); proofAsandAggegateC[0] = proofs[0].A; // raise As from each proof to entropy[i] for (uint256 proofIndex = 1; proofIndex < numProofs; proofIndex++) { uint256 s = entropy[proofIndex]; proofAsandAggegateC[proofIndex] = Pairing.scalar_mul( proofs[proofIndex].A, s ); } // MSM(proofCs, entropy) Pairing.G1Point memory msmProduct = proofs[0].C; for (uint256 proofIndex = 1; proofIndex < numProofs; proofIndex++) { uint256 s = entropy[proofIndex]; Pairing.G1Point memory term = Pairing.scalar_mul( proofs[proofIndex].C, s ); msmProduct = Pairing.addition(msmProduct, term); } proofAsandAggegateC[numProofs] = msmProduct; return (proofAsandAggegateC, publicInputAccumulators); } function batchVerifyProofs( VerifyingKey memory vk, uint256[8][] memory proof8s, uint256[][] memory allPis ) internal view returns (bool success) { uint256 proof8sLength = proof8s.length; require( allPis.length == proof8sLength, "Invalid inputs length for a batch" ); Proof[] memory proofs = new Proof[](proof8sLength); for (uint256 i = 0; i < proof8sLength; i++) { proofs[i] = _proof8ToStruct(proof8s[i]); } // strategy is to accumulate entropy separately for some proof elements // (accumulate only for G1, can't in G2) of the pairing equation, as well as input verification key, // postpone scalar multiplication as much as possible and check only one equation // by using 3 + proofs.length pairings only plus 2*proofs.length + (num_inputs+1) + 1 scalar multiplications compared to naive // 4*proofs.length pairings and proofs.length*(num_inputs+1) scalar multiplications ( Pairing.G1Point[] memory proofAsandAggegateC, uint256[] memory publicInputAccumulators ) = accumulate(proofs, allPis); Pairing.G1Point[2] memory finalVKAlphaAndX = _prepareBatch( vk, publicInputAccumulators ); Pairing.G1Point[] memory p1s = new Pairing.G1Point[](proofs.length + 3); Pairing.G2Point[] memory p2s = new Pairing.G2Point[](proofs.length + 3); // first proofs.length pairings e(ProofA, ProofB) for ( uint256 proofNumber = 0; proofNumber < proofs.length; proofNumber++ ) { p1s[proofNumber] = proofAsandAggegateC[proofNumber]; p2s[proofNumber] = proofs[proofNumber].B; } // second pairing e(-finalVKaplha, vk.beta) p1s[proofs.length] = Pairing.negate(finalVKAlphaAndX[0]); p2s[proofs.length] = vk.beta2; // third pairing e(-finalVKx, vk.gamma) p1s[proofs.length + 1] = Pairing.negate(finalVKAlphaAndX[1]); p2s[proofs.length + 1] = vk.gamma2; // fourth pairing e(-proof.C, vk.delta) p1s[proofs.length + 2] = Pairing.negate( proofAsandAggegateC[proofs.length] ); p2s[proofs.length + 2] = vk.delta2; return Pairing.pairing(p1s, p2s); } function _prepareBatch( VerifyingKey memory vk, uint256[] memory publicInputAccumulators ) internal view returns (Pairing.G1Point[2] memory finalVKAlphaAndX) { // Compute the linear combination vk_x using accumulator // Performs an MSM(vkIC, publicInputAccumulators) Pairing.G1Point memory msmProduct = Pairing.scalar_mul( vk.IC[0], publicInputAccumulators[0] ); uint256 piAccumulatorsLength = publicInputAccumulators.length; for (uint256 i = 1; i < piAccumulatorsLength; i++) { Pairing.G1Point memory product = Pairing.scalar_mul( vk.IC[i], publicInputAccumulators[i] ); msmProduct = Pairing.addition(msmProduct, product); } finalVKAlphaAndX[1] = msmProduct; // add one extra memory slot for scalar for multiplication usage Pairing.G1Point memory finalVKalpha = vk.alpha1; finalVKalpha = Pairing.scalar_mul( finalVKalpha, publicInputAccumulators[0] ); finalVKAlphaAndX[0] = finalVKalpha; return finalVKAlphaAndX; } function _proof8ToStruct( uint256[8] memory proof ) internal pure returns (Proof memory) { return Groth16.Proof( Pairing.G1Point(proof[0], proof[1]), Pairing.G2Point([proof[2], proof[3]], [proof[4], proof[5]]), Pairing.G1Point(proof[6], proof[7]) ); } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import "../interfaces/ISubtreeUpdateVerifier.sol"; import {Groth16} from "../libs/Groth16.sol"; import "../libs/Types.sol"; import {ITeller} from "../interfaces/ITeller.sol"; import {ISubtreeUpdateVerifier} from "../interfaces/ISubtreeUpdateVerifier.sol"; import {Utils} from "./Utils.sol"; import {TreeUtils} from "./TreeUtils.sol"; import {QueueLib} from "./Queue.sol"; enum InsertionType { Note, Commitment } struct OffchainMerkleTree { // number of non-zero leaves in the tree // INVARIANT: bottom `LOG2_BATCH_SIZE` bits of `count` should all be zero uint128 count; // number of leaves in the batch, plus one // when this gets to TreeUtils.BATCH_SIZE + 1, we compute accumulatorHash and push te the accumulatorQueue // we store batch size + 1 to avoid "clearing" the storage slot and save gas uint64 batchLenPlusOne; // a bitmap representing whether or not each leaf in the batch is a note or a note commitment // the bitmap is kept in big-endian order // that is, the bit corresponding to the 0th leaf in the batch is the "leftmost bit" of the bitmap, i.e. the bit with value 2^63 // and hte bit corresponding to the ith leaf in the batch is the bit with value 2^(63 - i) // 0 = note commitment, 1 = note uint64 bitmap; // root of the merkle tree uint256 root; // buffer containing uncommitted update hashes // each hash can either be the sha256 hash of a publically revealed note (e.g. in thecase of a deposit) // or the note commitment (i.e. poseidon hash computed off-chain) of a note that hasn't been revealed // when the buffer is filled, the sha256 hash of the batch is pushed to the accumulatorQueue, "accumulating" the batch of updates // ! solidity doesn't allow us to use `TreeUtils.BATCH_SIZE` here unfortunately. uint256[16] batch; // queue containing accumulator hashes of batches of updates // each accumulator commits to an update (a set of note commitments) that will be applied to the tree // via the commitSubtree() method QueueLib.Queue accumulatorQueue; ISubtreeUpdateVerifier subtreeUpdateVerifier; } library LibOffchainMerkleTree { using QueueLib for QueueLib.Queue; function initialize( OffchainMerkleTree storage self, address subtreeUpdateVerifier ) internal { // root starts as the root of the empty depth-32 tree. self.root = TreeUtils.EMPTY_TREE_ROOT; self.count = 0; self.bitmap = 0; _setBatchLen(self, 0); self.subtreeUpdateVerifier = ISubtreeUpdateVerifier( subtreeUpdateVerifier ); self.accumulatorQueue.initialize(); for (uint256 i = 0; i < TreeUtils.BATCH_SIZE; i++) { self.batch[i] = TreeUtils.ZERO_VALUE; } } function insertNote( OffchainMerkleTree storage self, EncodedNote memory note ) internal { uint256 noteHash = TreeUtils.sha256Note(note); _insertUpdate(self, noteHash, InsertionType.Note); } function insertNoteCommitments( OffchainMerkleTree storage self, uint256[] memory ncs ) internal { for (uint256 i = 0; i < ncs.length; i++) { _insertUpdate(self, ncs[i], InsertionType.Commitment); } } function applySubtreeUpdate( OffchainMerkleTree storage self, uint256 newRoot, uint256[8] memory proof ) internal { uint256[] memory pis = _calculatePublicInputs(self, newRoot); // 1) this library computes accumulatorHash on its own, // the definition of accumulatorHash prevents collisions (different batch with same hash), // and the subtree update circuit guarantees `accumulatorHash` is re-computed correctly, // so if the circuit accepts, the only possible batch the updater could be inserting is precisely // the batch we've enqueued here on-chain // 2) the subtree update circuit guarantees that the new root is computed correctly, // so due to (1), the only possible newRoot is the newRoot that results from inserting // the batch we've enqueued here on-chain require( self.subtreeUpdateVerifier.verifyProof(proof, pis), "subtree update proof invalid" ); self.accumulatorQueue.dequeue(); self.root = newRoot; self.count += uint128(TreeUtils.BATCH_SIZE); } // returns the current root of the tree function getRoot( OffchainMerkleTree storage self ) internal view returns (uint256) { return self.root; } // returns the current number of leaves in the tree function getCount( OffchainMerkleTree storage self ) internal view returns (uint128) { return self.count; } // returns the number of leaves in the tree plus the number of leaves waiting in the queue function getTotalCount( OffchainMerkleTree storage self ) internal view returns (uint128) { return self.count + uint128(getBatchLen(self)) + uint128(TreeUtils.BATCH_SIZE) * uint128(self.accumulatorQueue.length()); } function getAccumulatorHash( OffchainMerkleTree storage self ) external view returns (uint256) { return self.accumulatorQueue.peek(); } function getBatchLen( OffchainMerkleTree storage self ) internal view returns (uint64) { return self.batchLenPlusOne - 1; } function _setBatchLen( OffchainMerkleTree storage self, uint64 batchLen ) internal { self.batchLenPlusOne = batchLen + 1; } function _calculatePublicInputs( OffchainMerkleTree storage self, uint256 newRoot ) internal view returns (uint256[] memory) { uint256 accumulatorHash = self.accumulatorQueue.peek(); (uint256 hi, uint256 lo) = TreeUtils.uint256ToFieldElemLimbs( accumulatorHash ); uint256 encodedPathAndHash = TreeUtils.encodePathAndHash( self.count, hi ); uint256[] memory pis = new uint256[](4); pis[0] = self.root; pis[1] = newRoot; pis[2] = encodedPathAndHash; pis[3] = lo; return pis; } // H(updates || bitmap) // claim: it's impossible to have a collision between two different sets of updates // argument: order matters because of hash function. The only way two different sequences of note commitments // could result in the same accumulatorHash would be if the inner hashes - either note commitments or note sha256 hashes - // were the same, but the insertion kinds were mismatched. That is, there's a sha256 hash "masquerading" as a note commitment // in the batch. But this is impossible because we also include the bitmap in the hash - which this library ensures is consistent with the // order and kind of insertinos in the batch. function _computeAccumulatorHash( OffchainMerkleTree storage self ) internal view returns (uint256) { uint256 batchLen = getBatchLen(self); uint256[] memory accumulatorInputs = new uint256[]( TreeUtils.BATCH_SIZE + 1 ); for (uint256 i = 0; i < batchLen; i++) { accumulatorInputs[i] = self.batch[i]; } for (uint256 i = batchLen; i < TreeUtils.BATCH_SIZE; i++) { accumulatorInputs[i] = TreeUtils.ZERO_VALUE; } // shift over to pad input out to a multiple of 256 bits accumulatorInputs[TreeUtils.BATCH_SIZE] = uint256(self.bitmap) << 192; return uint256(TreeUtils.sha256U256ArrayBE(accumulatorInputs)); } function fillBatchWithZeros(OffchainMerkleTree storage self) internal { _accumulateAndResetBatchLen(self); } function _accumulateAndResetBatchLen( OffchainMerkleTree storage self ) internal { uint256 accumulatorHash = _computeAccumulatorHash(self); self.accumulatorQueue.enqueue(accumulatorHash); self.bitmap = 0; _setBatchLen(self, 0); } function _insertUpdate( OffchainMerkleTree storage self, uint256 update, InsertionType insertionType ) internal { uint64 batchLen = getBatchLen(self); self.batch[batchLen] = update; self.bitmap |= insertionType == InsertionType.Note ? uint64(1) << (63 - batchLen) : uint64(0); uint64 newBatchLen = batchLen + 1; _setBatchLen(self, newBatchLen); if (newBatchLen == TreeUtils.BATCH_SIZE) { _accumulateAndResetBatchLen(self); } } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {Groth16} from "../libs/Groth16.sol"; import {Utils} from "../libs/Utils.sol"; import "../libs/Types.sol"; // Helpers for extracting data / formatting operations library OperationUtils { function extractJoinSplitProofsAndPis( Operation[] calldata ops, uint256[] memory digests ) internal pure returns (uint256[8][] memory proofs, uint256[][] memory allPis) { // compute number of joinsplits in the bundle uint256 totalNumJoinSplits = 0; uint256 numOps = ops.length; for (uint256 i = 0; i < numOps; i++) { totalNumJoinSplits += (ops[i].pubJoinSplits.length + ops[i].confJoinSplits.length); } proofs = new uint256[8][](totalNumJoinSplits); allPis = new uint256[][](totalNumJoinSplits); // current index into proofs and pis uint256 totalIndex = 0; // Batch verify all the joinsplit proofs for (uint256 j = 0; j < numOps; j++) { ( uint256[8][] memory proofsForOp, uint256[][] memory pisForOp ) = extractProofsAndPisFromOperation(ops[j], digests[j]); for (uint256 i = 0; i < proofsForOp.length; i++) { proofs[totalIndex] = proofsForOp[i]; allPis[totalIndex] = pisForOp[i]; totalIndex++; } } return (proofs, allPis); } function extractProofsAndPisFromOperation( Operation calldata op, uint256 opDigest ) internal pure returns (uint256[8][] memory proofs, uint256[][] memory allPis) { uint256 numJoinSplitsForOp = OperationLib.totalNumJoinSplits(op); proofs = new uint256[8][](numJoinSplitsForOp); allPis = new uint256[][](numJoinSplitsForOp); (uint256 refundAddrH1SignBit, uint256 refundAddrH1YCoordinate) = Utils .decomposeCompressedPoint(op.refundAddr.h1); (uint256 refundAddrH2SignBit, uint256 refundAddrH2YCoordinate) = Utils .decomposeCompressedPoint(op.refundAddr.h2); for (uint256 i = 0; i < numJoinSplitsForOp; i++) { bool isPublicJoinSplit = i < op.pubJoinSplits.length; JoinSplit calldata joinSplit = isPublicJoinSplit ? op.pubJoinSplits[i].joinSplit : op.confJoinSplits[i - op.pubJoinSplits.length]; EncodedAsset memory encodedAsset = isPublicJoinSplit ? op.trackedAssets[op.pubJoinSplits[i].assetIndex].encodedAsset : EncodedAsset(0, 0); uint256 publicSpend = isPublicJoinSplit ? op.pubJoinSplits[i].publicSpend : 0; uint256 encodedAssetAddrWithSignBits = encodeEncodedAssetAddrWithSignBitsPI( encodedAsset.encodedAssetAddr, refundAddrH1SignBit, refundAddrH2SignBit ); proofs[i] = joinSplit.proof; allPis[i] = new uint256[](13); allPis[i][0] = joinSplit.newNoteACommitment; allPis[i][1] = joinSplit.newNoteBCommitment; allPis[i][2] = joinSplit.commitmentTreeRoot; allPis[i][3] = publicSpend; allPis[i][4] = joinSplit.nullifierA; allPis[i][5] = joinSplit.nullifierB; allPis[i][6] = joinSplit.senderCommitment; allPis[i][7] = joinSplit.joinSplitInfoCommitment; allPis[i][8] = opDigest; allPis[i][9] = encodedAsset.encodedAssetId; allPis[i][10] = encodedAssetAddrWithSignBits; allPis[i][11] = refundAddrH1YCoordinate; allPis[i][12] = refundAddrH2YCoordinate; } } function encodeEncodedAssetAddrWithSignBitsPI( uint256 encodedAssetAddr, uint256 h1SignBit, uint256 h2SignBit ) internal pure returns (uint256) { return encodedAssetAddr | (h1SignBit << 248) | (h2SignBit << 249); } function calculateBundlerGasAssetPayout( Operation calldata op, OperationResult memory opResult ) internal pure returns (uint256) { uint256 handleJoinSplitGas = OperationLib.totalNumJoinSplits(op) * GAS_PER_JOINSPLIT_HANDLE; uint256 refundGas = opResult.numRefunds * (GAS_PER_INSERTION_ENQUEUE + GAS_PER_INSERTION_SUBTREE_UPDATE); return op.gasPrice * (opResult.verificationGas + handleJoinSplitGas + opResult.executionGas + refundGas + GAS_PER_OPERATION_MISC); } // From https://ethereum.stackexchange.com/questions/83528 // returns empty string if no revert message function getRevertMsg( bytes memory reason ) internal pure returns (string memory) { // If the _res length is less than 68, then the transaction failed silently (without a revert message) if (reason.length < 68) { return ""; } assembly { // Slice the sighash. reason := add(reason, 0x04) } return abi.decode(reason, (string)); // All that remains is the revert string } }
// Copyright 2017 Christian Reitwiessner // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // 2019 OKIMS // ported to solidity 0.6 // fixed linter warnings // added requiere error messages // // // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.2; library Pairing { struct G1Point { uint256 X; uint256 Y; } // Encoding of field elements is: X[0] * z + X[1] struct G2Point { uint256[2] X; uint256[2] Y; } /// @return the generator of G1 function P1() internal pure returns (G1Point memory) { return G1Point(1, 2); } /// @return the generator of G2 function P2() internal pure returns (G2Point memory) { // Original code point return G2Point( [ 11559732032986387107991004021392285783925812861821192530917403151452391805634, 10857046999023057135944570762232829481370756359578518086990519993285655852781 ], [ 4082367875863433681332203403145435568316851327593401208105741076214120093531, 8495653923123431417604973247489272438418190587263600148770280649306958101930 ] ); /* // Changed by Jordi point return G2Point( [10857046999023057135944570762232829481370756359578518086990519993285655852781, 11559732032986387107991004021392285783925812861821192530917403151452391805634], [8495653923123431417604973247489272438418190587263600148770280649306958101930, 4082367875863433681332203403145435568316851327593401208105741076214120093531] ); */ } /// @return r the negation of p, i.e. p.addition(p.negate()) should be zero. function negate(G1Point memory p) internal pure returns (G1Point memory r) { // The prime q in the base field F_q for G1 uint256 q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; if (p.X == 0 && p.Y == 0) return G1Point(0, 0); return G1Point(p.X, q - (p.Y % q)); } /// @return r the sum of two points of G1 function addition( G1Point memory p1, G1Point memory p2 ) internal view returns (G1Point memory r) { uint256[4] memory input; input[0] = p1.X; input[1] = p1.Y; input[2] = p2.X; input[3] = p2.Y; bool success; // solium-disable-next-line security/no-inline-assembly assembly { success := staticcall(sub(gas(), 2000), 6, input, 0xc0, r, 0x60) // Use "invalid" to make gas estimation work switch success case 0 { invalid() } } require(success, "pairing-add-failed"); } /// @return r the product of a point on G1 and a scalar, i.e. /// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p. function scalar_mul( G1Point memory p, uint256 s ) internal view returns (G1Point memory r) { uint256[3] memory input; input[0] = p.X; input[1] = p.Y; input[2] = s; bool success; // solium-disable-next-line security/no-inline-assembly assembly { success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60) // Use "invalid" to make gas estimation work switch success case 0 { invalid() } } require(success, "pairing-mul-failed"); } /// @return the result of computing the pairing check /// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1 /// For example pairing([P1(), P1().negate()], [P2(), P2()]) should /// return true. function pairing( G1Point[] memory p1, G2Point[] memory p2 ) internal view returns (bool) { require(p1.length == p2.length, "pairing-lengths-failed"); uint256 elements = p1.length; uint256 inputSize = elements * 6; uint256[] memory input = new uint256[](inputSize); for (uint256 i = 0; i < elements; i++) { input[i * 6 + 0] = p1[i].X; input[i * 6 + 1] = p1[i].Y; input[i * 6 + 2] = p2[i].X[0]; input[i * 6 + 3] = p2[i].X[1]; input[i * 6 + 4] = p2[i].Y[0]; input[i * 6 + 5] = p2[i].Y[1]; } uint256[1] memory out; bool success; // solium-disable-next-line security/no-inline-assembly assembly { success := staticcall( sub(gas(), 2000), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20 ) // Use "invalid" to make gas estimation work switch success case 0 { invalid() } } require(success, "pairing-opcode-failed"); return out[0] != 0; } /// Convenience method for a pairing check for two pairs. function pairingProd2( G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2 ) internal view returns (bool) { G1Point[] memory p1 = new G1Point[](2); G2Point[] memory p2 = new G2Point[](2); p1[0] = a1; p1[1] = b1; p2[0] = a2; p2[1] = b2; return pairing(p1, p2); } /// Convenience method for a pairing check for three pairs. function pairingProd3( G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2, G1Point memory c1, G2Point memory c2 ) internal view returns (bool) { G1Point[] memory p1 = new G1Point[](3); G2Point[] memory p2 = new G2Point[](3); p1[0] = a1; p1[1] = b1; p1[2] = c1; p2[0] = a2; p2[1] = b2; p2[2] = c2; return pairing(p1, p2); } /// Convenience method for a pairing check for four pairs. function pairingProd4( G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2, G1Point memory c1, G2Point memory c2, G1Point memory d1, G2Point memory d2 ) internal view returns (bool) { G1Point[] memory p1 = new G1Point[](4); G2Point[] memory p2 = new G2Point[](4); p1[0] = a1; p1[1] = b1; p1[2] = c1; p1[3] = d1; p2[0] = a2; p2[1] = b2; p2[2] = c2; p2[3] = d2; return pairing(p1, p2); } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; // Derived from: https://github.com/nomad-xyz/monorepo/blob/main/packages/contracts-core/contracts/libs/Queue.sol library QueueLib { /** * @notice Queue struct * @dev Internally keeps track of the `first` and `last` elements through * indices and a mapping of indices to enqueued elements. **/ struct Queue { uint128 first; uint128 last; mapping(uint256 => uint256) queue; } /** * @notice Initializes the queue * @dev Empty state denoted by self.first > q.last. Queue initialized * with self.first = 1 and self.last = 0. **/ function initialize(Queue storage self) internal { if (self.first == 0) { self.first = 1; } } /** * @notice Enqueues a single new element * @param item New element to be enqueued * @return last Index of newly enqueued element **/ function enqueue( Queue storage self, uint256 item ) internal returns (uint128 last) { last = self.last + 1; self.last = last; if (item != uint256(0)) { // saves gas if we're queueing 0 self.queue[last] = item; } } /** * @notice Dequeues element at front of queue * @dev Removes dequeued element from storage * @return item Dequeued element **/ function dequeue(Queue storage self) internal returns (uint256 item) { uint128 last = self.last; uint128 first = self.first; require(_length(last, first) != 0, "Empty"); item = self.queue[first]; if (item != uint256(0)) { // saves gas if we're dequeuing 0 delete self.queue[first]; } self.first = first + 1; } /** * @notice Batch enqueues several elements * @param items Array of elements to be enqueued * @return last Index of last enqueued element **/ function enqueue( Queue storage self, uint256[] memory items ) internal returns (uint128 last) { last = self.last; uint256 numItems = items.length; for (uint256 i = 0; i < numItems; i += 1) { last += 1; uint256 item = items[i]; if (item != uint256(0)) { self.queue[last] = item; } } self.last = last; } /** * @notice Batch dequeues `_number` elements * @dev Reverts if `_number` > queue length * @param _number Number of elements to dequeue * @return Array of dequeued elements **/ function dequeue( Queue storage _q, uint256 _number ) internal returns (uint256[] memory) { uint128 _last = _q.last; uint128 _first = _q.first; // Cannot underflow unless state is corrupted require(_length(_last, _first) >= _number, "Insufficient"); uint256[] memory _items = new uint256[](_number); for (uint256 i = 0; i < _number; i++) { _items[i] = _q.queue[_first]; delete _q.queue[_first]; _first++; } _q.first = _first; return _items; } /** * @notice Returns true if `item` is in the queue and false if otherwise * @dev Linearly scans from self.first to self.last looking for `item` * @param item Item being searched for in queue * @return True if `item` currently exists in queue, false if otherwise **/ function contains( Queue storage self, uint256 item ) internal view returns (bool) { uint256 last = self.last; for (uint256 i = self.first; i <= last; i++) { if (self.queue[i] == item) { return true; } } return false; } /// @notice Returns last item in queue /// @dev Returns uint256(0) if queue empty function lastItem(Queue storage self) internal view returns (uint256) { return self.queue[self.last]; } /// @notice Returns element at front of queue without removing element /// @dev Reverts if queue is empty function peek(Queue storage self) internal view returns (uint256 item) { require(!isEmpty(self), "Queue is empty"); item = self.queue[self.first]; } /// @notice Returns true if queue is empty and false if otherwise function isEmpty(Queue storage self) internal view returns (bool) { return self.last < self.first; } /// @notice Returns number of elements in queue function length(Queue storage self) internal view returns (uint256) { uint128 last = self.last; uint128 first = self.first; // Cannot underflow unless state is corrupted return _length(last, first); } /// @notice Returns number of elements between `last` and `first` (used internally) function _length( uint128 last, uint128 first ) internal pure returns (uint256) { return uint256(last + 1 - first); } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {ITeller} from "../interfaces/ITeller.sol"; import "./Types.sol"; // helpers for converting to/from field elems, uint256s, and/or bytes, and hashing them library TreeUtils { uint256 public constant DEPTH = 16; uint256 public constant BATCH_SIZE = 16; uint256 public constant BATCH_SUBTREE_DEPTH = 2; // uint256(keccak256("nocturne")) % BN254_SCALAR_FIELD_MODULUS uint256 public constant ZERO_VALUE = 11826002903343228749062904299844230482823860030613873531382924534593825466831; uint256 public constant EMPTY_TREE_ROOT = 14425423529089750832921210739722026857026797579827942712639385657619324990872; // packs a field element for the `encodedPathAndHash` input to the subtree update verifier // `subtreeIdx` is the index of the subtree's leftmost element in the tree // `accumulatorHashHi` is the top 3 bits of `accumulatorHash` gotten from `uint256ToFieldElemLimbs` function encodePathAndHash( uint128 subtreeIdx, uint256 accumulatorHashHi ) internal pure returns (uint256) { require( subtreeIdx % BATCH_SIZE == 0, "subtreeIdx not multiple of BATCH_SIZE" ); // we shift by 2 * depth because the tree is quaternary uint256 encodedPathAndHash = uint256(subtreeIdx) >> (2 * BATCH_SUBTREE_DEPTH); encodedPathAndHash |= accumulatorHashHi << (2 * (DEPTH - BATCH_SUBTREE_DEPTH)); return encodedPathAndHash; } // hash array of uint256s as big-endian bytes with sha256 function sha256U256ArrayBE( uint256[] memory elems ) internal pure returns (bytes32) { return sha256(abi.encodePacked(elems)); } function sha256Note( EncodedNote memory note ) internal pure returns (uint256) { uint256[] memory elems = new uint256[](6); elems[0] = note.ownerH1; elems[1] = note.ownerH2; elems[2] = note.nonce; elems[3] = note.encodedAssetAddr; elems[4] = note.encodedAssetId; elems[5] = note.value; return uint256(sha256U256ArrayBE(elems)); } // return uint256 as two limbs - one uint256 containing the 3 hi bits, the // other containing the lower 253 bits function uint256ToFieldElemLimbs( uint256 n ) internal pure returns (uint256, uint256) { return _splitUint256ToLimbs(n, 253); } // split a uint256 into 2 limbs, one containing the high (256 - lowerBits) // bits, the other containing the lower `lowerBits` bits function _splitUint256ToLimbs( uint256 n, uint256 lowerBits ) internal pure returns (uint256, uint256) { uint256 hi = n >> lowerBits; uint256 lo = n & ((1 << lowerBits) - 1); return (hi, lo); } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; uint256 constant GAS_PER_JOINSPLIT_HANDLE = 110_000; // two 20k SSTOREs from NF insertions, ~70k for merkle tree checks + NF mapping checks + processing joinsplits not including tree insertions uint256 constant GAS_PER_INSERTION_SUBTREE_UPDATE = 25_000; // Full 16 leaf non-zero subtree update = 320k / 16 = 20k per insertion (+5k buffer) uint256 constant GAS_PER_INSERTION_ENQUEUE = 25_000; // 20k for enqueueing note commitment not including subtree update cost (+5k buffer) uint256 constant GAS_PER_OPERATION_MISC = 100_000; // remaining gas cost for operation including miscellaneous costs such as sending gas tokens to bundler, requesting assets from teller, sending tokens back for refunds, calldata, event, etc. uint256 constant ERC20_ID = 0; enum AssetType { ERC20, ERC721, ERC1155 } struct EncodedAsset { uint256 encodedAssetAddr; uint256 encodedAssetId; } struct CompressedStealthAddress { uint256 h1; uint256 h2; } struct EncryptedNote { bytes ciphertextBytes; bytes encapsulatedSecretBytes; } struct PublicJoinSplit { JoinSplit joinSplit; uint8 assetIndex; // Index in op.joinSplitAssets uint256 publicSpend; } struct JoinSplit { uint256 commitmentTreeRoot; uint256 nullifierA; uint256 nullifierB; uint256 newNoteACommitment; uint256 newNoteBCommitment; uint256 senderCommitment; uint256 joinSplitInfoCommitment; uint256[8] proof; EncryptedNote newNoteAEncrypted; EncryptedNote newNoteBEncrypted; } struct JoinSplitInfo { uint256 compressedSenderCanonAddr; uint256 compressedReceiverCanonAddr; uint256 oldMerkleIndicesWithSignBits; uint256 newNoteValueA; uint256 newNoteValueB; uint256 nonce; } struct EncodedNote { uint256 ownerH1; uint256 ownerH2; uint256 nonce; uint256 encodedAssetAddr; uint256 encodedAssetId; uint256 value; } struct DepositRequest { address spender; EncodedAsset encodedAsset; uint256 value; CompressedStealthAddress depositAddr; uint256 nonce; uint256 gasCompensation; } struct Deposit { address spender; EncodedAsset encodedAsset; uint256 value; CompressedStealthAddress depositAddr; } struct Action { address contractAddress; bytes encodedFunction; } struct TrackedAsset { EncodedAsset encodedAsset; uint256 minRefundValue; } struct Operation { PublicJoinSplit[] pubJoinSplits; JoinSplit[] confJoinSplits; CompressedStealthAddress refundAddr; TrackedAsset[] trackedAssets; Action[] actions; EncodedAsset encodedGasAsset; uint256 gasAssetRefundThreshold; uint256 executionGasLimit; uint256 gasPrice; uint256 deadline; bool atomicActions; } // An operation is processed if its joinsplitTxs are processed. // If an operation is processed, the following is guaranteeed to happen: // 1. Encoded calls are attempted (not necessarily successfully) // 2. The bundler is compensated verification and execution gas // Bundlers should only be submitting operations that can be processed. struct OperationResult { bool opProcessed; bool assetsUnwrapped; string failureReason; bool[] callSuccesses; bytes[] callResults; uint256 verificationGas; uint256 executionGas; uint256 numRefunds; uint128 preOpMerkleCount; uint128 postOpMerkleCount; } struct Bundle { Operation[] operations; } struct CanonAddrRegistryEntry { address ethAddress; uint256 compressedCanonAddr; uint256 perCanonAddrNonce; } library OperationLib { function maxGasLimit( Operation calldata self, uint256 perJoinSplitVerifyGas ) internal pure returns (uint256) { uint256 numJoinSplits = totalNumJoinSplits(self); return self.executionGasLimit + ((perJoinSplitVerifyGas + GAS_PER_JOINSPLIT_HANDLE) * numJoinSplits) + ((GAS_PER_INSERTION_SUBTREE_UPDATE + GAS_PER_INSERTION_ENQUEUE) * (self.trackedAssets.length + (numJoinSplits * 2))) + // NOTE: assume refund for every asset GAS_PER_OPERATION_MISC; } function maxGasAssetCost( Operation calldata self, uint256 perJoinSplitVerifyGas ) internal pure returns (uint256) { return self.gasPrice * maxGasLimit(self, perJoinSplitVerifyGas); } function totalNumJoinSplits( Operation calldata self ) internal pure returns (uint256) { return self.pubJoinSplits.length + self.confJoinSplits.length; } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {ITeller} from "../interfaces/ITeller.sol"; import {Groth16} from "../libs/Groth16.sol"; import {Pairing} from "../libs/Pairing.sol"; import "../libs/Types.sol"; // helpers for converting to/from field elems, uint256s, and/or bytes, and hashing them library Utils { uint256 public constant BN254_SCALAR_FIELD_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617; uint256 constant COMPRESSED_POINT_SIGN_MASK = 1 << 254; // takes a compressed point and extracts the sign bit and y coordinate // returns (sign, y) function decomposeCompressedPoint( uint256 compressedPoint ) internal pure returns (uint256 sign, uint256 y) { sign = (compressedPoint & COMPRESSED_POINT_SIGN_MASK) >> 254; y = compressedPoint & (COMPRESSED_POINT_SIGN_MASK - 1); return (sign, y); } // return the minimum of the two values function min(uint256 a, uint256 b) internal pure returns (uint256) { return (a >= b) ? b : a; } function sum(uint256[] calldata arr) internal pure returns (uint256) { uint256 total = 0; uint256 arrLength = arr.length; for (uint256 i = 0; i < arrLength; i++) { total += arr[i]; } return total; } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import "./Types.sol"; import "./Utils.sol"; import {AssetUtils} from "./AssetUtils.sol"; library Validation { uint256 constant MAX_NOTE_VALUE = (1 << 252) - 1; // value must fit in 252 bits uint256 constant ENCODED_ASSET_ADDR_MASK = ((1 << 163) - 1) | (7 << 249); uint256 constant MAX_ASSET_ID = (1 << 253) - 1; uint256 constant CURVE_A = 168700; uint256 constant CURVE_D = 168696; uint256 constant COMPRESSED_POINT_Y_MASK = ~uint256(1 << 254); function validateOperation(Operation calldata op) internal view { uint256 numPubJoinSplits = op.pubJoinSplits.length; require(numPubJoinSplits + op.confJoinSplits.length > 0, "!JoinSplits"); // Ensure public spend > 0 for public joinsplit. Ensures handler only deals // with assets that are actually unwrappable. If asset has > 0 public spend, then // circuit guarantees that note with the _revealed_ asset is included in the tree is // unwrappable. If asset has public spend = 0, circuit guarantees that the note with the // _masked_ asset is included in the tree and unwrappable, but the revealed asset for public // spend = 0 is (0,0) and is not unwrappable. for (uint256 i = 0; i < numPubJoinSplits; i++) { require(op.pubJoinSplits[i].publicSpend > 0, "0 public spend"); } // Ensure timestamp for op has not already expired require(block.timestamp <= op.deadline, "expired deadline"); // Ensure gas asset is erc20 to ensure transfers to bundler retain control flow (no // callbacks/receiver hooks) (AssetType assetType, , ) = AssetUtils.decodeAsset(op.encodedGasAsset); require(assetType == AssetType.ERC20, "!gas erc20"); } // Ensure note fields are also valid as circuit inputs function validateNote(EncodedNote memory note) internal pure { require( // nonce is a valid field element note.nonce < Utils.BN254_SCALAR_FIELD_MODULUS && // encodedAssetAddr is a valid field element note.encodedAssetAddr < Utils.BN254_SCALAR_FIELD_MODULUS && // encodedAssetAddr doesn't have any bits set outside bits 0-162 and 250-252 note.encodedAssetAddr & (~ENCODED_ASSET_ADDR_MASK) == 0 && // encodedAssetId is a 253 bit number (and therefore a valid field element) note.encodedAssetId <= MAX_ASSET_ID && // value is < the 2^252 limit (and therefore a valid field element) note.value <= MAX_NOTE_VALUE, "invalid note" ); validateCompressedBJJPoint(note.ownerH1); validateCompressedBJJPoint(note.ownerH2); } function validateCompressedBJJPoint(uint256 p) internal pure { // Clear X-sign bit. Leaves MSB untouched for the next check. uint256 y = p & COMPRESSED_POINT_Y_MASK; // Simultaneously check that the high-bit is unset and Y is a canonical field element // this works because y >= Utils.BN254_SCALAR_FIELD_MODULUS if high bit is set or y is not a valid field element require(y < Utils.BN254_SCALAR_FIELD_MODULUS, "invalid point"); } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.17; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; /// @title NocturneReentrancyGuard /// @author Nocturne Labs /// @notice Custom reentrancy guard that track stages of operation processing/execution. /// @dev Modified from OpenZeppelin ReentrancyGuard.sol contract NocturneReentrancyGuard is Initializable { // No operation entered (before Teller calls handler.handleOperation) uint256 public constant NOT_ENTERED = 1; // Once an operation is entered for processing (after Teller calls handler.handleOperation) uint256 public constant ENTERED_HANDLE_OPERATION = 2; // Once an operation is entered for execution (after Teller calls handler.executeActions) uint256 public constant ENTERED_EXECUTE_ACTIONS = 3; // Operation stage uint256 private _operationStage; // Gap for upgrade safety uint256[50] private __GAP; /// @notice Internal initializer function __NocturneReentrancyGuard_init() internal onlyInitializing { _operationStage = NOT_ENTERED; } /// @notice Requires current stage to be NOT_ENTERED. /// @dev Moves stage to ENTERED_HANDLE_OPERATION before function execution, then resets stage /// to NOT_ENTERED at end of call context. modifier handleOperationGuard() { require(_operationStage == NOT_ENTERED, "Reentry into handleOperation"); _operationStage = ENTERED_HANDLE_OPERATION; _; _operationStage = NOT_ENTERED; } /// @notice Requires current stage to be ENTERED_HANDLE_OPERATION. /// @dev Moves stage to ENTERED_EXECUTE_ACTIONS before function execution, then resets stage to /// ENTERED_HANDLE_OPERATION at end of call context. modifier executeActionsGuard() { require( _operationStage == ENTERED_HANDLE_OPERATION, "Reentry into executeActions" ); _operationStage = ENTERED_EXECUTE_ACTIONS; _; _operationStage = ENTERED_HANDLE_OPERATION; } /// @notice Returns current operation stage function reentrancyGuardStage() public view returns (uint256) { return _operationStage; } }
{ "optimizer": { "enabled": true, "runs": 500 }, "metadata": { "bytecodeHash": "none" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":false,"internalType":"bytes4","name":"selector","type":"bytes4"},{"indexed":false,"internalType":"bool","name":"permission","type":"bool"}],"name":"ContractMethodPermissionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":false,"internalType":"bool","name":"permission","type":"bool"}],"name":"ContractPermissionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"startIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"numZeros","type":"uint256"}],"name":"FilledBatchWithZeros","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldNoteANullifier","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"oldNoteBNullifier","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"newNoteAIndex","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"newNoteBIndex","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"newNoteACommitment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newNoteBCommitment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"senderCommitment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"joinSplitInfoCommitment","type":"uint256"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"indexed":false,"internalType":"struct EncryptedNote","name":"newNoteAEncrypted","type":"tuple"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"indexed":false,"internalType":"struct EncryptedNote","name":"newNoteBEncrypted","type":"tuple"}],"name":"JoinSplitProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"h1","type":"uint256"},{"internalType":"uint256","name":"h2","type":"uint256"}],"indexed":false,"internalType":"struct CompressedStealthAddress","name":"refundAddr","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"encodedAssetAddr","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"encodedAssetId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"merkleIndex","type":"uint128"}],"name":"RefundProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"filler","type":"address"},{"indexed":false,"internalType":"bool","name":"permission","type":"bool"}],"name":"SubtreeBatchFillerPermissionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newRoot","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"subtreeBatchOffset","type":"uint256"}],"name":"SubtreeUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"ENTERED_EXECUTE_ACTIONS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ENTERED_HANDLE_OPERATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ERC20_APPROVE_SELECTOR","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ERC_20_APPROVE_FN_DATA_LENGTH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NOT_ENTERED","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_leftoverTokensHolder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"_nullifierSet","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"_pastRoots","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_subtreeBatchFillers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint192","name":"","type":"uint192"}],"name":"_supportedContractMethods","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_supportedContracts","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_teller","outputs":[{"internalType":"contract ITeller","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRoot","type":"uint256"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"}],"name":"applySubtreeUpdate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"uint256","name":"commitmentTreeRoot","type":"uint256"},{"internalType":"uint256","name":"nullifierA","type":"uint256"},{"internalType":"uint256","name":"nullifierB","type":"uint256"},{"internalType":"uint256","name":"newNoteACommitment","type":"uint256"},{"internalType":"uint256","name":"newNoteBCommitment","type":"uint256"},{"internalType":"uint256","name":"senderCommitment","type":"uint256"},{"internalType":"uint256","name":"joinSplitInfoCommitment","type":"uint256"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteAEncrypted","type":"tuple"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteBEncrypted","type":"tuple"}],"internalType":"struct JoinSplit","name":"joinSplit","type":"tuple"},{"internalType":"uint8","name":"assetIndex","type":"uint8"},{"internalType":"uint256","name":"publicSpend","type":"uint256"}],"internalType":"struct PublicJoinSplit[]","name":"pubJoinSplits","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"commitmentTreeRoot","type":"uint256"},{"internalType":"uint256","name":"nullifierA","type":"uint256"},{"internalType":"uint256","name":"nullifierB","type":"uint256"},{"internalType":"uint256","name":"newNoteACommitment","type":"uint256"},{"internalType":"uint256","name":"newNoteBCommitment","type":"uint256"},{"internalType":"uint256","name":"senderCommitment","type":"uint256"},{"internalType":"uint256","name":"joinSplitInfoCommitment","type":"uint256"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteAEncrypted","type":"tuple"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteBEncrypted","type":"tuple"}],"internalType":"struct JoinSplit[]","name":"confJoinSplits","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"h1","type":"uint256"},{"internalType":"uint256","name":"h2","type":"uint256"}],"internalType":"struct CompressedStealthAddress","name":"refundAddr","type":"tuple"},{"components":[{"components":[{"internalType":"uint256","name":"encodedAssetAddr","type":"uint256"},{"internalType":"uint256","name":"encodedAssetId","type":"uint256"}],"internalType":"struct EncodedAsset","name":"encodedAsset","type":"tuple"},{"internalType":"uint256","name":"minRefundValue","type":"uint256"}],"internalType":"struct TrackedAsset[]","name":"trackedAssets","type":"tuple[]"},{"components":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"bytes","name":"encodedFunction","type":"bytes"}],"internalType":"struct Action[]","name":"actions","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"encodedAssetAddr","type":"uint256"},{"internalType":"uint256","name":"encodedAssetId","type":"uint256"}],"internalType":"struct EncodedAsset","name":"encodedGasAsset","type":"tuple"},{"internalType":"uint256","name":"gasAssetRefundThreshold","type":"uint256"},{"internalType":"uint256","name":"executionGasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"atomicActions","type":"bool"}],"internalType":"struct Operation","name":"op","type":"tuple"}],"name":"executeActions","outputs":[{"internalType":"bool[]","name":"successes","type":"bool[]"},{"internalType":"bytes[]","name":"results","type":"bytes[]"},{"internalType":"uint256","name":"numRefundsToHandle","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"fillBatchWithZeros","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"spender","type":"address"},{"components":[{"internalType":"uint256","name":"encodedAssetAddr","type":"uint256"},{"internalType":"uint256","name":"encodedAssetId","type":"uint256"}],"internalType":"struct EncodedAsset","name":"encodedAsset","type":"tuple"},{"internalType":"uint256","name":"value","type":"uint256"},{"components":[{"internalType":"uint256","name":"h1","type":"uint256"},{"internalType":"uint256","name":"h2","type":"uint256"}],"internalType":"struct CompressedStealthAddress","name":"depositAddr","type":"tuple"}],"internalType":"struct Deposit","name":"deposit","type":"tuple"}],"name":"handleDeposit","outputs":[{"internalType":"uint128","name":"merkleIndex","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"uint256","name":"commitmentTreeRoot","type":"uint256"},{"internalType":"uint256","name":"nullifierA","type":"uint256"},{"internalType":"uint256","name":"nullifierB","type":"uint256"},{"internalType":"uint256","name":"newNoteACommitment","type":"uint256"},{"internalType":"uint256","name":"newNoteBCommitment","type":"uint256"},{"internalType":"uint256","name":"senderCommitment","type":"uint256"},{"internalType":"uint256","name":"joinSplitInfoCommitment","type":"uint256"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteAEncrypted","type":"tuple"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteBEncrypted","type":"tuple"}],"internalType":"struct JoinSplit","name":"joinSplit","type":"tuple"},{"internalType":"uint8","name":"assetIndex","type":"uint8"},{"internalType":"uint256","name":"publicSpend","type":"uint256"}],"internalType":"struct PublicJoinSplit[]","name":"pubJoinSplits","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"commitmentTreeRoot","type":"uint256"},{"internalType":"uint256","name":"nullifierA","type":"uint256"},{"internalType":"uint256","name":"nullifierB","type":"uint256"},{"internalType":"uint256","name":"newNoteACommitment","type":"uint256"},{"internalType":"uint256","name":"newNoteBCommitment","type":"uint256"},{"internalType":"uint256","name":"senderCommitment","type":"uint256"},{"internalType":"uint256","name":"joinSplitInfoCommitment","type":"uint256"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteAEncrypted","type":"tuple"},{"components":[{"internalType":"bytes","name":"ciphertextBytes","type":"bytes"},{"internalType":"bytes","name":"encapsulatedSecretBytes","type":"bytes"}],"internalType":"struct EncryptedNote","name":"newNoteBEncrypted","type":"tuple"}],"internalType":"struct JoinSplit[]","name":"confJoinSplits","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"h1","type":"uint256"},{"internalType":"uint256","name":"h2","type":"uint256"}],"internalType":"struct CompressedStealthAddress","name":"refundAddr","type":"tuple"},{"components":[{"components":[{"internalType":"uint256","name":"encodedAssetAddr","type":"uint256"},{"internalType":"uint256","name":"encodedAssetId","type":"uint256"}],"internalType":"struct EncodedAsset","name":"encodedAsset","type":"tuple"},{"internalType":"uint256","name":"minRefundValue","type":"uint256"}],"internalType":"struct TrackedAsset[]","name":"trackedAssets","type":"tuple[]"},{"components":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"bytes","name":"encodedFunction","type":"bytes"}],"internalType":"struct Action[]","name":"actions","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"encodedAssetAddr","type":"uint256"},{"internalType":"uint256","name":"encodedAssetId","type":"uint256"}],"internalType":"struct EncodedAsset","name":"encodedGasAsset","type":"tuple"},{"internalType":"uint256","name":"gasAssetRefundThreshold","type":"uint256"},{"internalType":"uint256","name":"executionGasLimit","type":"uint256"},{"internalType":"uint256","name":"gasPrice","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"atomicActions","type":"bool"}],"internalType":"struct Operation","name":"op","type":"tuple"},{"internalType":"uint256","name":"perJoinSplitVerifyGas","type":"uint256"},{"internalType":"address","name":"bundler","type":"address"}],"name":"handleOperation","outputs":[{"components":[{"internalType":"bool","name":"opProcessed","type":"bool"},{"internalType":"bool","name":"assetsUnwrapped","type":"bool"},{"internalType":"string","name":"failureReason","type":"string"},{"internalType":"bool[]","name":"callSuccesses","type":"bool[]"},{"internalType":"bytes[]","name":"callResults","type":"bytes[]"},{"internalType":"uint256","name":"verificationGas","type":"uint256"},{"internalType":"uint256","name":"executionGas","type":"uint256"},{"internalType":"uint256","name":"numRefunds","type":"uint256"},{"internalType":"uint128","name":"preOpMerkleCount","type":"uint128"},{"internalType":"uint128","name":"postOpMerkleCount","type":"uint128"}],"internalType":"struct OperationResult","name":"opResult","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"subtreeUpdateVerifier","type":"address"},{"internalType":"address","name":"leftoverTokensHolder","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"reentrancyGuardStage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"root","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"bytes4","name":"selector","type":"bytes4"},{"internalType":"bool","name":"permission","type":"bool"}],"name":"setContractMethodPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"bool","name":"permission","type":"bool"}],"name":"setContractPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"filler","type":"address"},{"internalType":"bool","name":"permission","type":"bool"}],"name":"setSubtreeBatchFillerPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"teller","type":"address"}],"name":"setTeller","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalCount","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50614c66806100206000396000f3fe608060405234801561001057600080fd5b50600436106102065760003560e01c80638456cb591161011a578063b0288791116100ad578063e30c39781161007c578063e30c397814610475578063ebf0c71714610486578063f2fde38b1461048e578063fb2a29b8146104a1578063ffdc2709146104c457600080fd5b8063b028879114610424578063b2d1c4dc1461042c578063b9efcfab14610440578063d0df233f1461046257600080fd5b80638da5cb5b116100e95780638da5cb5b146103b5578063974a0565146103da578063a2b8cc30146103fd578063a74ccfd61461041157600080fd5b80638456cb591461038957806387237d581461039157806389d0fbef146103995780638a8356e6146103ac57600080fd5b8063438525e51161019d57806362d2cc6b1161016c57806362d2cc6b1461032d578063644e2cf714610351578063715018a61461037157806375157d5e1461037957806379ba50971461038157600080fd5b8063438525e5146102d2578063485cc955146102f95780634bb356551461030c5780635c975abb1461032257600080fd5b806334eafb11116101d957806334eafb111461028c5780633a53c785146102945780633f4ba83a146102b7578063404f7534146102bf57600080fd5b806306661abd1461020b57806314d6237714610230578063199b75491461024357806333ff772214610277575b600080fd5b6102136104cc565b6040516001600160801b0390911681526020015b60405180910390f35b61021361023e366004613b3e565b6104e5565b610267610251366004613b65565b61017a6020526000908152604090205460ff1681565b6040519015158152602001610227565b61028a610285366004613b65565b6105e9565b005b61021361066e565b6102676102a2366004613b82565b60c96020526000908152604090205460ff1681565b61028a61067a565b61028a6102cd366004613b9b565b61068c565b6102e063095ea7b360e01b81565b6040516001600160e01b03199091168152602001610227565b61028a610307366004613bd1565b6107aa565b610314600181565b604051908152602001610227565b60975460ff16610267565b61026761033b366004613c0a565b61017b6020526000908152604090205460ff1681565b61036461035f366004613c46565b6108d2565b6040516102279190613d85565b61028a610c92565b610314600281565b61028a610ca4565b61028a610d1e565b610314600381565b61028a6103a7366004613e7f565b610d2e565b61014754610314565b6033546001600160a01b03165b6040516001600160a01b039091168152602001610227565b6102676103e8366004613b65565b60e06020526000908152604090205460ff1681565b610114546103c2906001600160a01b031681565b61028a61041f366004613ead565b610d9b565b61028a610e43565b610113546103c2906001600160a01b031681565b61045361044e366004613efa565b610f6f565b60405161022793929190613f2e565b61028a610470366004613e7f565b61122b565b6065546001600160a01b03166103c2565b60cc54610314565b61028a61049c366004613b65565b61128f565b6102676104af366004613b82565b60ca6020526000908152604090205460ff1681565b610314604481565b60006104e060cb546001600160801b031690565b905090565b60006104ef611300565b610113546001600160a01b0316331461053d5760405162461bcd60e51b815260206004820152600b60248201526a27b7363c903a32b63632b960a91b60448201526064015b60405180910390fd5b600061055136849003840160208501613faa565b9050600061055e82611353565b506001600160a01b038116600090815261017a602052604090205490925060ff1690506105cd5760405162461bcd60e51b815260206004820152601860248201527f21737570706f72746564206465706f73697420617373657400000000000000006044820152606401610534565b6105df82856080018660600135611400565b925050505b919050565b6105f16114d7565b610113546001600160a01b03161561064b5760405162461bcd60e51b815260206004820152601260248201527f54656c6c657220616c72656164792073657400000000000000000000000000006044820152606401610534565b61011380546001600160a01b0319166001600160a01b0392909216919091179055565b60006104e060cb611531565b6106826114d7565b61068a611581565b565b610694611300565b600082815260c9602052604090205460ff16156106f35760405162461bcd60e51b815260206004820152601b60248201527f6e6577526f6f7420616c72656164792061207061737420726f6f7400000000006044820152606401610534565b600061070760cb546001600160801b031690565b6001600160801b031690506107498383600880602002604051908101604052809291908260086020028082843760009201919091525060cb93929150506115d3565b600083815260c9602052604090819020805460ff19166001179055517ffb39e09569c2d91048a9e4a7b26d1ed588ebf53019d8aaf02eb77f54f5ed9ab79061079d9085908490918252602082015260400190565b60405180910390a1505050565b600054610100900460ff16158080156107ca5750600054600160ff909116105b806107e45750303b1580156107e4575060005460ff166001145b6108565760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610534565b6000805460ff191660011790558015610879576000805461ff0019166101001790555b6108816116fd565b61088b838361172c565b80156108cd576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200161079d565b505050565b61093e60405180610140016040528060001515815260200160001515815260200160608152602001606081526020016060815260200160008152602001600081526020016000815260200160006001600160801b0316815260200160006001600160801b031681525090565b610946611300565b610113546001600160a01b0316331461098f5760405162461bcd60e51b815260206004820152600b60248201526a27b7363c903a32b63632b960a91b6044820152606401610534565b600161014754146109e25760405162461bcd60e51b815260206004820152601c60248201527f5265656e74727920696e746f2068616e646c654f7065726174696f6e000000006044820152606401610534565b60026101475560006109f76080860186613ff8565b9050905060005b81811015610ac6576000610a44610a186080890189613ff8565b84818110610a2857610a28614040565b610a3f926060909102013681900381019150613faa565b611353565b506001600160a01b038116600090815261017a602052604090205490925060ff169050610ab35760405162461bcd60e51b815260206004820152601060248201527f21737570706f72746564206173736574000000000000000000000000000000006044820152606401610534565b5080610abe8161406c565b9150506109fe565b50610ad085611780565b610ad861066e565b6001600160801b03166101008301526000610af386866117fa565b60016020850152905060005a60405163b9efcfab60e01b8152909150309063b9efcfab906101208a013590610b2c908b90600401614463565b60006040518083038160008887f193505050508015610b6d57506040513d6000823e601f3d908101601f19168201604052610b6a919081019061469f565b60015b610c09573d808015610b9b576040519150601f19603f3d011682016040523d82523d6000602084013e610ba0565b606091505b506000610bac82611a02565b90508051600003610bf357604080518082018252601c81527f65786365656465642060657865637574696f6e4761734c696d69746000000000602082015290870152610bfb565b604086018190525b505060e08401829052610c20565b600187526060870192909252608086015260e08501525b610c2987611a3c565b610c33908761476c565b60a0850152610c516101208801355a610c4c9084614783565b611a62565b60c0850152610c6287858888611a78565b610c6b87611b4a565b610c7361066e565b6001600160801b03166101208501525050506001610147559392505050565b610c9a6114d7565b61068a6000611bf6565b60655433906001600160a01b03168114610d125760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610534565b610d1b81611bf6565b50565b610d266114d7565b61068a611c0f565b610d366114d7565b6001600160a01b038216600081815261017a6020908152604091829020805460ff19168515159081179091558251938452908301527f7ea68faa530351818165a7ce70585717acbdd207ec45e501cd6a81f263a364c091015b60405180910390a15050565b610da36114d7565b77ffffffffffffffffffffffffffffffffffffffff00000000602084811b9190911660e084901c17600081815261017b8352604090819020805485151560ff19909116811790915581516001600160a01b03881681526001600160e01b0319871694810194909452838201525190917f94540635cbdcea052b9bce97a7cc558ae28970966db7477ff284bb3e0609851c919081900360600190a150505050565b33600090815260e0602052604090205460ff16610ea25760405162461bcd60e51b815260206004820152601960248201527f4f6e6c7920737562747265652062617463682066696c6c6572000000000000006044820152606401610534565b6000610eae60cb611c4c565b6001600160401b0316905060008111610f095760405162461bcd60e51b815260206004820152601660248201527f217a65726f2066696c6c20656d707479206261746368000000000000000000006044820152606401610534565b6000610f1560cb611531565b6001600160801b031690506000610f2d836010614783565b9050610f3960cb611c6d565b60408051838152602081018390527f8865c2a0c0d95d3da57d4c528ea72a2fdc92192373aabc7e147a73ecee5a56cb910161079d565b6060806000610f7c611300565b333014610fb75760405162461bcd60e51b81526020600482015260096024820152684f6e6c79207468697360b81b6044820152606401610534565b6002610147541461100a5760405162461bcd60e51b815260206004820152601b60248201527f5265656e74727920696e746f2065786563757465416374696f6e7300000000006044820152606401610534565b600361014755600061101f60a0860186614796565b90509050806001600160401b0381111561103b5761103b613f64565b604051908082528060200260200182016040528015611064578160200160208202803683370190505b509350806001600160401b0381111561107f5761107f613f64565b6040519080825280602002602001820160405280156110b257816020015b606081526020019060019003908161109d5790505b50925060005b81811015611212576110f76110d060a0880188614796565b838181106110e0576110e0614040565b90506020028101906110f291906147df565b611c76565b86838151811061110957611109614040565b6020026020010186848151811061112257611122614040565b602090810291909101019190915290151590526111476101a0870161018088016147ff565b801561116a575084818151811061116057611160614040565b6020026020010151155b1561120057600061119385838151811061118657611186614040565b6020026020010151611a02565b905080516000036111e65760405162461bcd60e51b815260206004820152601860248201527f616374696f6e2073696c656e746c7920726576657274656400000000000000006044820152606401610534565b8060405162461bcd60e51b8152600401610534919061481c565b8061120a8161406c565b9150506110b8565b5061121c85611f9b565b60026101475593959294505050565b6112336114d7565b6001600160a01b038216600081815260e06020908152604091829020805460ff19168515159081179091558251938452908301527fd5526a8e995d06d14d095efbea5d9aaf857f75a6ddc8198403003bce7ea20c079101610d8f565b6112976114d7565b606580546001600160a01b0383166001600160a01b031990911681179091556112c86033546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60975460ff161561068a5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610534565b602081015181516000916001600160a01b03821691600381811b600760fd1b169092179160a09190911c1680840361138e57600093506113f8565b8060010361139f57600193506113f8565b806002036113b057600293506113f8565b60405162461bcd60e51b815260206004820152601860248201527f496e76616c696420656e636f64656441737365744164647200000000000000006044820152606401610534565b509193909250565b600061140c60cb611531565b6040805160c08101825285358152602080870135818301526001600160801b038416928201929092528651606082015290860151608082015260a0810184905290915061145881612083565b6040808201518651602080890151845189358152828a013592810192909252938101929092526060820152608081019190915260a081018490526001600160801b03831660c08201527f7e44173b0d57b460187962e8ccda97c4f6dc0604464fc038150dca7e7b9452fe9060e00160405180910390a1505b9392505050565b6033546001600160a01b0316331461068a5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610534565b600061153f82601201612097565b61154a90601061482f565b61155383611c4c565b8354611571916001600160401b0316906001600160801b031661485a565b61157b919061485a565b92915050565b6115896120b9565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60006115df848461210b565b6014850154604051632833f41360e11b81529192506001600160a01b031690635067e826906116149085908590600401614881565b602060405180830381865afa158015611631573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165591906148f6565b6116a15760405162461bcd60e51b815260206004820152601c60248201527f73756274726565207570646174652070726f6f6620696e76616c6964000000006044820152606401610534565b6116ad846012016121fb565b5060018401839055835460109085906000906116d39084906001600160801b031661485a565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555050505050565b600054610100900460ff166117245760405162461bcd60e51b815260040161053490614913565b600161014755565b600054610100900460ff166117535760405162461bcd60e51b815260040161053490614913565b61175c826122c9565b61011480546001600160a01b0319166001600160a01b039290921691909117905550565b600061178f6080830183613ff8565b9050905060005b818110156108cd576117e76117ae6080850185613ff8565b838181106117be576117be614040565b6117d5926060909102013681900381019150613faa565b610114546001600160a01b0316612363565b50806117f28161406c565b915050611796565b600061180583612469565b60c0830160006118158585612867565b90503660006118248780614796565b9050905060005b818110156119a957600061183f8980614796565b8381811061184f5761184f614040565b9050602002810190611861919061495e565b611872906040810190602001614974565b905061188160808a018a613ff8565b8260ff1681811061189457611894614040565b606002919091019450600090506118b46118ae8b80614796565b85612882565b905060006118cc6118c58c80614796565b868561293c565b90506000871180156118e357506118e3888761299a565b156119105760006118f48289611a62565b90506119008183614783565b915061190c8189614783565b9750505b61191b82600161498f565b9350886119278161406c565b99505080156119a1576101135460405163042609d760e31b81528735600482015260208801356024820152604481018390526001600160a01b03909116906321304eb890606401600060405180830381600087803b15801561198857600080fd5b505af115801561199c573d6000803e3d6000fd5b505050505b50505061182b565b5082156119f85760405162461bcd60e51b815260206004820152601260248201527f546f6f206665772067617320746f6b656e7300000000000000000000000000006044820152606401610534565b5050505092915050565b6060604482511015611a2257505060408051602081019091526000815290565b6004820191508180602001905181019061157b91906149a2565b6000611a4b6020830183614796565b9050611a578380614796565b61157b92915061498f565b600081831015611a7257826114d0565b50919050565b60c084016000611a888685612867565b90508015611b42576101135460405163042609d760e31b81528335600482015260208401356024820152604481018390526001600160a01b03909116906321304eb890606401600060405180830381600087803b158015611ae857600080fd5b505af1158015611afc573d6000803e3d6000fd5b505050506000611b0c87876129b6565b9050610100870135611b1e8284614783565b1015611b275750805b611b40611b3936859003850185613faa565b8583612a41565b505b505050505050565b366000611b5a6080840184613ff8565b9050905060005b81811015611bf057611b766080850185613ff8565b82818110611b8657611b86614040565b60600291909101935060009050611bb7611ba536869003860186613faa565b610113546001600160a01b0316612363565b90508015611bdd57611bdb611bd136869003860186613faa565b8660400183611400565b505b5080611be88161406c565b915050611b61565b50505050565b606580546001600160a01b0319169055610d1b81612b59565b611c17611300565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586115b63390565b805460009061157b90600190600160801b90046001600160401b03166149ea565b610d1b81612bab565b60006060611c876020840184613b65565b6001600160a01b03163b600003611ccd5760405162461bcd60e51b815260206004820152600a602482015269217a65726f20636f646560b01b6044820152606401610534565b610113546001600160a01b0316611ce76020850185613b65565b6001600160a01b031603611d3d5760405162461bcd60e51b815260206004820152601f60248201527f43616e6e6f742063616c6c20746865204e6f637475726e652054656c6c6572006044820152606401610534565b6000611d54611d4f6020860186614a0a565b612be2565b90506000611d90611d686020870187613b65565b8360e01c60209190911b77ffffffffffffffffffffffffffffffffffffffff00000000161790565b6001600160c01b038116600090815261017b602052604090205490915060ff16611e0c5760405162461bcd60e51b815260206004820152602760248201527f43616e6e6f742063616c6c206e6f6e2d616c6c6f7765642070726f746f636f6c604482015266081b595d1a1bd960ca1b6064820152608401610534565b63f6a1584d60e01b6001600160e01b0319831601611f1b576044611e336020870187614a0a565b905014611e825760405162461bcd60e51b815260206004820152601260248201527f21617070726f766520666e206c656e67746800000000000000000000000000006044820152606401610534565b6000611e916020870187614a0a565b611e9f916004908290614a50565b810190611eac9190614a7a565b506001600160a01b038116600090815261017a602052604090205490915060ff16611f195760405162461bcd60e51b815260206004820152601060248201527f21617070726f7665207370656e646572000000000000000000000000000000006044820152606401610534565b505b611f286020860186613b65565b6001600160a01b0316611f3e6020870187614a0a565b604051611f4c929190614aa6565b6000604051808303816000865af19150503d8060008114611f89576040519150601f19603f3d011682016040523d82523d6000602084013e611f8e565b606091505b5090969095509350505050565b60008080611fac6080850185613ff8565b9050905060005b81811015612055576000611fe8611fcd6080880188613ff8565b84818110611fdd57611fdd614040565b905060600201612c4c565b905080156120425784611ffa8161406c565b9550508315801561203857506120386120166080880188613ff8565b8481811061202657612026614040565b9050606002016000018760c00161299a565b1561204257600193505b508061204d8161406c565b915050611fb3565b508115801561206957506000846101400135115b1561207c57826120788161406c565b9350505b5050919050565b61208c81612d23565b610d1b60cb82612e4b565b80546000906001600160801b03600160801b8204811691166105df8282612e64565b60975460ff1661068a5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610534565b6060600061211b84601201612e8c565b905060008061212983612f19565b87549193509150600090612146906001600160801b031684612f30565b60408051600480825260a08201909252919250600091906020820160808036833701905050905087600101548160008151811061218557612185614040565b60200260200101818152505086816001815181106121a5576121a5614040565b60200260200101818152505081816002815181106121c5576121c5614040565b60200260200101818152505082816003815181106121e5576121e5614040565b6020908102919091010152979650505050505050565b80546000906001600160801b03600160801b82048116911661221d8282612e64565b6000036122545760405162461bcd60e51b8152602060048201526005602482015264456d70747960d81b6044820152606401610534565b6001600160801b038116600090815260018501602052604090205492508215612293576001600160801b03811660009081526001850160205260408120555b61229e81600161485a565b84546fffffffffffffffffffffffffffffffff19166001600160801b03919091161790935550919050565b600054610100900460ff166122f05760405162461bcd60e51b815260040161053490614913565b6122f8612fdf565b61230061300e565b61230b60cb8261303d565b507f1fe48018cdbfc6b7d8bc35b49fdde4563ab7ddb7b1d917c4dd087a8a6265f59860005260c96020527f2a38d31b1a338d741911d0d0d852fa107c786f32172e830c3bae7a1f64121a6b805460ff19166001179055565b610113546000906001600160a01b03838116911614806123915750610114546001600160a01b038381169116145b6123dd5760405162461bcd60e51b815260206004820152600f60248201527f496e76616c696420746f206164647200000000000000000000000000000000006044820152606401610534565b60006123e88461310b565b905060006123f585611353565b50909150600090508082600281111561241057612410614ab6565b1461241c57600061241f565b60015b60ff169050600081841161243457600061243e565b61243e8285614783565b9050801561245c57612451878783612a41565b935061157b92505050565b5060009695505050505050565b600061247482611a3c565b9050600061248382600261476c565b6001600160401b0381111561249a5761249a613f64565b6040519080825280602002602001820160405280156124c3578160200160208202803683370190505b50905060006124d260cb611531565b90503660005b84811015612856576124ea8680614796565b9050811061253a576124ff6020870187614796565b6125098880614796565b612514915084614783565b81811061252357612523614040565b90506020028101906125359190614acc565b612570565b6125448680614796565b8281811061255457612554614040565b9050602002810190612566919061495e565b6125709080614acc565b8035600090815260c9602052604090205490925060ff166125d35760405162461bcd60e51b815260206004820152601760248201527f5472656520726f6f74206e6f74207061737420726f6f740000000000000000006044820152606401610534565b602080830135600090815260ca909152604090205460ff16156126385760405162461bcd60e51b815260206004820152601860248201527f4e756c6c6966696572204120616c7265616479207573656400000000000000006044820152606401610534565b604080830135600090815260ca602052205460ff161561269a5760405162461bcd60e51b815260206004820152601860248201527f4e756c6c6966696572204220616c7265616479207573656400000000000000006044820152606401610534565b81604001358260200135036126f15760405162461bcd60e51b815260206004820152601360248201527f32206e66732073686f756c642021657175616c000000000000000000000000006044820152606401610534565b602082810135600090815260ca90915260408082208054600160ff199182168117909255828601358452918320805490921617905561273182600261476c565b61273b908561485a565b9050600061274a83600261476c565b61275590600161498f565b61275f908661485a565b905060608401358661277285600261476c565b8151811061278257612782614040565b602090810291909101015260808401358661279e85600261476c565b6127a990600161498f565b815181106127b9576127b9614040565b602002602001018181525050836040013584602001357f26522f457c833ab2f50122cf6922e5362473d89bc731f6f8c1389a9f302550358484886060013589608001358a60a001358b60c001358c806101e0019061281791906147df565b6128256102008f018f6147df565b604051612839989796959493929190614ae3565b60405180910390a35050808061284e9061406c565b9150506124d8565b506128608361328f565b5050505050565b6000612873838361329a565b6114d09061014085013561476c565b60008084848481811061289757612897614040565b90506020028101906128a9919061495e565b6128ba906040810190602001614974565b60ff16905083835b816128ce82600161498f565b10801561291b575086866128e383600161498f565b8181106128f2576128f2614040565b9050602002810190612904919061495e565b612915906040810190602001614974565b60ff1683145b15612932578061292a8161406c565b9150506128c2565b9695505050505050565b600080835b83811161298e5786868281811061295a5761295a614040565b905060200281019061296c919061495e565b61297a90604001358361498f565b9150806129868161406c565b915050612941565b5090505b949350505050565b6000823582351480156114d05750506020918201359101351490565b6000806201adb06129c685611a3c565b6129d0919061476c565b905060006129e06161a88061498f565b8460e001516129ef919061476c565b9050620186a0818560c00151848760a00151612a0b919061498f565b612a15919061498f565b612a1f919061498f565b612a29919061498f565b612a389061014087013561476c565b95945050505050565b600080612a4d85611353565b5090925090506000826002811115612a6757612a67614ab6565b03612a8557612a806001600160a01b0382168585613320565b612860565b6001826002811115612a9957612a99614ab6565b03612ad35760405162461bcd60e51b815260206004820152600a602482015269085cdd5c1c1bdc9d195960b21b6044820152606401610534565b6002826002811115612ae757612ae7614ab6565b03612b215760405162461bcd60e51b815260206004820152600a602482015269085cdd5c1c1bdc9d195960b21b6044820152606401610534565b60405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a5908185cdcd95d609a1b6044820152606401610534565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000612bb682613387565b9050612bc560128301826134f7565b5081546001600160c01b03168255612bde826000613558565b5050565b60006004821015612c355760405162461bcd60e51b815260206004820152601260248201527f21656e636f64656420666e206c656e67746800000000000000000000000000006044820152606401610534565b612c43600460008486614a50565b6114d091614b4b565b60008181612c67612c6236849003840184613faa565b61310b565b90506000612c7d610a3f36859003850185613faa565b509091506000905080826002811115612c9857612c98614ab6565b14612ca4576000612ca7565b60015b60ff169050808311612cba576000612cc4565b612cc48184614783565b94508560400135851015612d1a5760405162461bcd60e51b815260206004820152601160248201527f216d696e20726566756e642076616c75650000000000000000000000000000006044820152606401610534565b50505050919050565b7f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018160400151108015612d7957507f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018160600151105b8015612d98575060608101516b1e3fffffffffffffffffffff60a31b16155b8015612dc857507f1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff816080015111155b8015612df857507f0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160a0015111155b612e335760405162461bcd60e51b815260206004820152600c60248201526b696e76616c6964206e6f746560a01b6044820152606401610534565b8051612e3e906135a2565b610d1b81602001516135a2565b6000612e5682613624565b90506108cd8382600061372b565b600081612e7284600161485a565b612e7c9190614b79565b6001600160801b03169392505050565b6000612eab82546001600160801b03808216600160801b909204161090565b15612ef85760405162461bcd60e51b815260206004820152600e60248201527f517565756520697320656d7074790000000000000000000000000000000000006044820152606401610534565b5080546001600160801b031660009081526001909101602052604090205490565b600080612f278360fd6137f8565b91509150915091565b6000612f4660106001600160801b038516614b99565b15612fa15760405162461bcd60e51b815260206004820152602560248201527f73756274726565496478206e6f74206d756c7469706c65206f662042415443486044820152645f53495a4560d81b6064820152608401610534565b6000612fae60028061476c565b6001600160801b038516901c9050612fc860026010614783565b612fd390600261476c565b83901b17905092915050565b600054610100900460ff166130065760405162461bcd60e51b815260040161053490614913565b61068a61381c565b600054610100900460ff166130355760405162461bcd60e51b815260040161053490614913565b61068a61384c565b7f1fe48018cdbfc6b7d8bc35b49fdde4563ab7ddb7b1d917c4dd087a8a6265f5986001830155815477ffffffffffffffff0000000000000000000000000000000016825561308c826000613558565b6014820180546001600160a01b0319166001600160a01b0383161790556130b56012830161387f565b60005b60108110156108cd577f1a2547cb123f691ef1fd5d62b27584a8a6e55b21377854db5bb4dd7e2d9ee9cf8360020182601081106130f7576130f7614040565b0155806131038161406c565b9150506130b8565b60008060008061311a85611353565b9194509250905060008084600281111561313657613136614ab6565b036131ab576040516370a0823160e01b81523060048201526001600160a01b038416906370a08231906024015b602060405180830381865afa158015613180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131a49190614bbb565b9050612a38565b60018460028111156131bf576131bf614ab6565b03613245576040516331a9108f60e11b8152600481018390526001600160a01b03841690636352211e90602401602060405180830381865afa925050508015613225575060408051601f3d908101601f1916820190925261322291810190614bd4565b60015b15612a3857306001600160a01b0382160361323f57600191505b50612a38565b600284600281111561325957613259614ab6565b03612b2157604051627eeac760e11b8152306004820152602481018390526001600160a01b0384169062fdd58e90604401613163565b610d1b60cb826138ae565b6000806132a684611a3c565b9050620186a06132b782600261476c565b6132c46080870187613ff8565b6132cf92915061498f565b6132db6161a88061498f565b6132e5919061476c565b826132f36201adb08761498f565b6132fd919061476c565b61330c9061012088013561498f565b613316919061498f565b612992919061498f565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663a9059cbb60e01b1790526108cd9084906138f1565b60008061339383611c4c565b6001600160401b0316905060006133ac6010600161498f565b6001600160401b038111156133c3576133c3613f64565b6040519080825280602002602001820160405280156133ec578160200160208202803683370190505b50905060005b828110156134405784600201816010811061340f5761340f614040565b015482828151811061342357613423614040565b6020908102919091010152806134388161406c565b9150506133f2565b50815b601081101561349c577f1a2547cb123f691ef1fd5d62b27584a8a6e55b21377854db5bb4dd7e2d9ee9cf82828151811061347f5761347f614040565b6020908102919091010152806134948161406c565b915050613443565b5083548151600160c01b90910460c01b7fffffffffffffffff0000000000000000000000000000000000000000000000001690829060109081106134e2576134e2614040565b602002602001018181525050612992816139c6565b815460009061351790600160801b90046001600160801b0316600161485a565b83546001600160801b03808316600160801b0291161784559050811561157b576001600160801b038116600090815260019390930160205260409092205590565b613563816001614bf1565b82546001600160401b0391909116600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790915550565b7fbfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81167f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018110612bde5760405162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a59081c1bda5b9d609a1b6044820152606401610534565b60408051600680825260e082019092526000918291906020820160c08036833701905050905082600001518160008151811061366257613662614040565b60200260200101818152505082602001518160018151811061368657613686614040565b6020026020010181815250508260400151816002815181106136aa576136aa614040565b6020026020010181815250508260600151816003815181106136ce576136ce614040565b6020026020010181815250508260800151816004815181106136f2576136f2614040565b6020026020010181815250508260a001518160058151811061371657613716614040565b6020026020010181815250506114d0816139c6565b600061373684611c4c565b90508284600201826001600160401b03166010811061375757613757614040565b0155600082600181111561376d5761376d614ab6565b1461377957600061379b565b61378481603f6149ea565b6001600160401b031660016001600160401b0316901b5b84546001600160c01b038116600160c01b918290046001600160401b039081169316929092170217845560006137d2826001614bf1565b90506137de8582613558565b6010816001600160401b0316036128605761286085612bab565b60008083831c8161380c600180871b614783565b91935050841690505b9250929050565b600054610100900460ff166138435760405162461bcd60e51b815260040161053490614913565b61068a33611bf6565b600054610100900460ff166138735760405162461bcd60e51b815260040161053490614913565b6097805460ff19169055565b80546001600160801b0316600003610d1b5780546fffffffffffffffffffffffffffffffff1916600117815550565b60005b81518110156108cd576138df838383815181106138d0576138d0614040565b6020026020010151600161372b565b806138e98161406c565b9150506138b1565b6000613946826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613a359092919063ffffffff16565b905080516000148061396757508080602001905181019061396791906148f6565b6108cd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610534565b60006002826040516020016139db9190614c11565b60408051601f19818403018152908290526139f591614c47565b602060405180830381855afa158015613a12573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061157b9190614bbb565b6060612992848460008585600080866001600160a01b03168587604051613a5c9190614c47565b60006040518083038185875af1925050503d8060008114613a99576040519150601f19603f3d011682016040523d82523d6000602084013e613a9e565b606091505b5091509150613aaf87838387613aba565b979650505050505050565b60608315613b29578251600003613b22576001600160a01b0385163b613b225760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610534565b5081612992565b61299283838151156111e65781518083602001fd5b600060c08284031215611a7257600080fd5b6001600160a01b0381168114610d1b57600080fd5b600060208284031215613b7757600080fd5b81356114d081613b50565b600060208284031215613b9457600080fd5b5035919050565b600080610120808486031215613bb057600080fd5b83359250848185011115613bc357600080fd5b506020830190509250929050565b60008060408385031215613be457600080fd5b8235613bef81613b50565b91506020830135613bff81613b50565b809150509250929050565b600060208284031215613c1c57600080fd5b81356001600160c01b03811681146114d057600080fd5b60006101a08284031215611a7257600080fd5b600080600060608486031215613c5b57600080fd5b83356001600160401b03811115613c7157600080fd5b613c7d86828701613c33565b935050602084013591506040840135613c9581613b50565b809150509250925092565b60005b83811015613cbb578181015183820152602001613ca3565b50506000910152565b60008151808452613cdc816020860160208601613ca0565b601f01601f19169290920160200192915050565b600081518084526020808501945080840160005b83811015613d22578151151587529582019590820190600101613d04565b509495945050505050565b600082825180855260208086019550808260051b84010181860160005b84811015613d7857601f19868403018952613d66838351613cc4565b98840198925090830190600101613d4a565b5090979650505050505050565b60208152613d9860208201835115159052565b60006020830151613dad604084018215159052565b506040830151610140806060850152613dca610160850183613cc4565b91506060850151601f1980868503016080870152613de88483613cf0565b935060808701519150808685030160a087015250613e068382613d2d565b92505060a085015160c085015260c085015160e085015260e0850151610100818187015280870151915050610120613e48818701836001600160801b03169052565b8601516001600160801b0381168387015290505b5090949350505050565b8015158114610d1b57600080fd5b80356105e481613e66565b60008060408385031215613e9257600080fd5b8235613e9d81613b50565b91506020830135613bff81613e66565b600080600060608486031215613ec257600080fd5b8335613ecd81613b50565b925060208401356001600160e01b031981168114613eea57600080fd5b91506040840135613c9581613e66565b600060208284031215613f0c57600080fd5b81356001600160401b03811115613f2257600080fd5b61299284828501613c33565b606081526000613f416060830186613cf0565b8281036020840152613f538186613d2d565b915050826040830152949350505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613fa257613fa2613f64565b604052919050565b600060408284031215613fbc57600080fd5b604051604081018181106001600160401b0382111715613fde57613fde613f64565b604052823581526020928301359281019290925250919050565b6000808335601e1984360301811261400f57600080fd5b8301803591506001600160401b0382111561402957600080fd5b602001915060608102360382131561381557600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161407e5761407e614056565b5060010190565b6000808335601e1984360301811261409c57600080fd5b83016020810192503590506001600160401b038111156140bb57600080fd5b8060051b360382131561381557600080fd5b6000823561021e198336030181126140e457600080fd5b90910192915050565b6101008183375050565b60008235603e198336030181126140e457600080fd5b6000808335601e1984360301811261412457600080fd5b83016020810192503590506001600160401b0381111561414357600080fd5b80360382131561381557600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6000614187828361410d565b60408552614199604086018284614152565b9150506141a9602084018461410d565b8583036020870152612932838284614152565b6000610220823584526020830135602085015260408301356040850152606083013560608501526080830135608085015260a083013560a085015260c083013560c085015261421160e0850160e085016140ed565b6101e0614220818501856140f7565b82828701526142318387018261417b565b92505050610200614244818501856140f7565b85830382870152612932838261417b565b803560ff811681146105e457600080fd5b81835260006020808501808196508560051b81019150846000805b888110156142ee578385038a528235605e198936030181126142a1578283fd5b880160606142af82806140cd565b8188526142be828901826141bc565b91505060ff6142ce898401614255565b168789015260409182013591909601529885019891850191600101614281565b509298975050505050505050565b81835260006020808501808196508560051b810191508460005b8781101561434857828403895261433684614331848a6140cd565b6141bc565b98850198935090840190600101614316565b5091979650505050505050565b6000808335601e1984360301811261436c57600080fd5b83016020810192503590506001600160401b0381111561438b57600080fd5b60608102360382131561381557600080fd5b81835260208301925060008160005b848110156143de57813586526020808301359087015260408281013590870152606095860195909101906001016143ac565b5093949350505050565b818352600060208085019450848460051b86018460005b87811015613d7857838303895261441682886140f7565b6040813561442381613b50565b6001600160a01b0316855261443a8288018361410d565b9250818887015261444e8287018483614152565b9b88019b9550505091850191506001016143ff565b6020815260006144738384614085565b6101a080602086015261448b6101c086018385614266565b925061449a6020870187614085565b9250601f19808786030160408801526144b48585846142fc565b94506144d06060880160408a0180358252602090810135910152565b6144dd6080890189614355565b94509150808786030160a08801526144f685858461439d565b945061450560a0890189614085565b94509150808786030160c08801525061451f8484836143e8565b93505061453c60e0860160c0880180358252602090810135910152565b61012091506101008601358286015261014082870135818701526101609250808701358387015250610180828701358187015261457a818801613e74565b925050613e5c8186018315159052565b60006001600160401b038211156145a3576145a3613f64565b5060051b60200190565b60006001600160401b038311156145c6576145c6613f64565b6145d9601f8401601f1916602001613f7a565b90508281528383830111156145ed57600080fd5b6114d0836020830184613ca0565b600082601f83011261460c57600080fd5b8151602061462161461c8361458a565b613f7a565b82815260059290921b8401810191818101908684111561464057600080fd5b8286015b848110156146945780516001600160401b038111156146635760008081fd5b8701603f810189136146755760008081fd5b6146868986830151604084016145ad565b845250918301918301614644565b509695505050505050565b6000806000606084860312156146b457600080fd5b83516001600160401b03808211156146cb57600080fd5b818601915086601f8301126146df57600080fd5b815160206146ef61461c8361458a565b82815260059290921b8401810191818101908a84111561470e57600080fd5b948201945b8386101561473557855161472681613e66565b82529482019490820190614713565b9189015191975090935050508082111561474e57600080fd5b5061475b868287016145fb565b925050604084015190509250925092565b808202811582820484141761157b5761157b614056565b8181038181111561157b5761157b614056565b6000808335601e198436030181126147ad57600080fd5b8301803591506001600160401b038211156147c757600080fd5b6020019150600581901b360382131561381557600080fd5b60008235603e198336030181126147f557600080fd5b9190910192915050565b60006020828403121561481157600080fd5b81356114d081613e66565b6020815260006114d06020830184613cc4565b6001600160801b0381811683821602808216919082811461485257614852614056565b505092915050565b6001600160801b0381811683821601908082111561487a5761487a614056565b5092915050565b60006101208281018386845b60088110156148ac57815183526020928301929091019060010161488d565b50505061010084019190915283519081905261014083019060209081860160005b828110156148e9578151855293830193908301906001016148cd565b5092979650505050505050565b60006020828403121561490857600080fd5b81516114d081613e66565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60008235605e198336030181126147f557600080fd5b60006020828403121561498657600080fd5b6114d082614255565b8082018082111561157b5761157b614056565b6000602082840312156149b457600080fd5b81516001600160401b038111156149ca57600080fd5b8201601f810184136149db57600080fd5b612992848251602084016145ad565b6001600160401b0382811682821603908082111561487a5761487a614056565b6000808335601e19843603018112614a2157600080fd5b8301803591506001600160401b03821115614a3b57600080fd5b60200191503681900382131561381557600080fd5b60008085851115614a6057600080fd5b83861115614a6d57600080fd5b5050820193919092039150565b60008060408385031215614a8d57600080fd5b8235614a9881613b50565b946020939093013593505050565b8183823760009101908152919050565b634e487b7160e01b600052602160045260246000fd5b6000823561021e198336030181126147f557600080fd5b60006101006001600160801b03808c168452808b166020850152508860408401528760608401528660808401528560a08401528060c0840152614b288184018661417b565b905082810360e0840152614b3c818561417b565b9b9a5050505050505050505050565b6001600160e01b031981358181169160048510156148525760049490940360031b84901b1690921692915050565b6001600160801b0382811682821603908082111561487a5761487a614056565b600082614bb657634e487b7160e01b600052601260045260246000fd5b500690565b600060208284031215614bcd57600080fd5b5051919050565b600060208284031215614be657600080fd5b81516114d081613b50565b6001600160401b0381811683821601908082111561487a5761487a614056565b815160009082906020808601845b83811015614c3b57815185529382019390820190600101614c1f565b50929695505050505050565b600082516147f5818460208701613ca056fea164736f6c6343000811000a
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102065760003560e01c80638456cb591161011a578063b0288791116100ad578063e30c39781161007c578063e30c397814610475578063ebf0c71714610486578063f2fde38b1461048e578063fb2a29b8146104a1578063ffdc2709146104c457600080fd5b8063b028879114610424578063b2d1c4dc1461042c578063b9efcfab14610440578063d0df233f1461046257600080fd5b80638da5cb5b116100e95780638da5cb5b146103b5578063974a0565146103da578063a2b8cc30146103fd578063a74ccfd61461041157600080fd5b80638456cb591461038957806387237d581461039157806389d0fbef146103995780638a8356e6146103ac57600080fd5b8063438525e51161019d57806362d2cc6b1161016c57806362d2cc6b1461032d578063644e2cf714610351578063715018a61461037157806375157d5e1461037957806379ba50971461038157600080fd5b8063438525e5146102d2578063485cc955146102f95780634bb356551461030c5780635c975abb1461032257600080fd5b806334eafb11116101d957806334eafb111461028c5780633a53c785146102945780633f4ba83a146102b7578063404f7534146102bf57600080fd5b806306661abd1461020b57806314d6237714610230578063199b75491461024357806333ff772214610277575b600080fd5b6102136104cc565b6040516001600160801b0390911681526020015b60405180910390f35b61021361023e366004613b3e565b6104e5565b610267610251366004613b65565b61017a6020526000908152604090205460ff1681565b6040519015158152602001610227565b61028a610285366004613b65565b6105e9565b005b61021361066e565b6102676102a2366004613b82565b60c96020526000908152604090205460ff1681565b61028a61067a565b61028a6102cd366004613b9b565b61068c565b6102e063095ea7b360e01b81565b6040516001600160e01b03199091168152602001610227565b61028a610307366004613bd1565b6107aa565b610314600181565b604051908152602001610227565b60975460ff16610267565b61026761033b366004613c0a565b61017b6020526000908152604090205460ff1681565b61036461035f366004613c46565b6108d2565b6040516102279190613d85565b61028a610c92565b610314600281565b61028a610ca4565b61028a610d1e565b610314600381565b61028a6103a7366004613e7f565b610d2e565b61014754610314565b6033546001600160a01b03165b6040516001600160a01b039091168152602001610227565b6102676103e8366004613b65565b60e06020526000908152604090205460ff1681565b610114546103c2906001600160a01b031681565b61028a61041f366004613ead565b610d9b565b61028a610e43565b610113546103c2906001600160a01b031681565b61045361044e366004613efa565b610f6f565b60405161022793929190613f2e565b61028a610470366004613e7f565b61122b565b6065546001600160a01b03166103c2565b60cc54610314565b61028a61049c366004613b65565b61128f565b6102676104af366004613b82565b60ca6020526000908152604090205460ff1681565b610314604481565b60006104e060cb546001600160801b031690565b905090565b60006104ef611300565b610113546001600160a01b0316331461053d5760405162461bcd60e51b815260206004820152600b60248201526a27b7363c903a32b63632b960a91b60448201526064015b60405180910390fd5b600061055136849003840160208501613faa565b9050600061055e82611353565b506001600160a01b038116600090815261017a602052604090205490925060ff1690506105cd5760405162461bcd60e51b815260206004820152601860248201527f21737570706f72746564206465706f73697420617373657400000000000000006044820152606401610534565b6105df82856080018660600135611400565b925050505b919050565b6105f16114d7565b610113546001600160a01b03161561064b5760405162461bcd60e51b815260206004820152601260248201527f54656c6c657220616c72656164792073657400000000000000000000000000006044820152606401610534565b61011380546001600160a01b0319166001600160a01b0392909216919091179055565b60006104e060cb611531565b6106826114d7565b61068a611581565b565b610694611300565b600082815260c9602052604090205460ff16156106f35760405162461bcd60e51b815260206004820152601b60248201527f6e6577526f6f7420616c72656164792061207061737420726f6f7400000000006044820152606401610534565b600061070760cb546001600160801b031690565b6001600160801b031690506107498383600880602002604051908101604052809291908260086020028082843760009201919091525060cb93929150506115d3565b600083815260c9602052604090819020805460ff19166001179055517ffb39e09569c2d91048a9e4a7b26d1ed588ebf53019d8aaf02eb77f54f5ed9ab79061079d9085908490918252602082015260400190565b60405180910390a1505050565b600054610100900460ff16158080156107ca5750600054600160ff909116105b806107e45750303b1580156107e4575060005460ff166001145b6108565760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610534565b6000805460ff191660011790558015610879576000805461ff0019166101001790555b6108816116fd565b61088b838361172c565b80156108cd576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200161079d565b505050565b61093e60405180610140016040528060001515815260200160001515815260200160608152602001606081526020016060815260200160008152602001600081526020016000815260200160006001600160801b0316815260200160006001600160801b031681525090565b610946611300565b610113546001600160a01b0316331461098f5760405162461bcd60e51b815260206004820152600b60248201526a27b7363c903a32b63632b960a91b6044820152606401610534565b600161014754146109e25760405162461bcd60e51b815260206004820152601c60248201527f5265656e74727920696e746f2068616e646c654f7065726174696f6e000000006044820152606401610534565b60026101475560006109f76080860186613ff8565b9050905060005b81811015610ac6576000610a44610a186080890189613ff8565b84818110610a2857610a28614040565b610a3f926060909102013681900381019150613faa565b611353565b506001600160a01b038116600090815261017a602052604090205490925060ff169050610ab35760405162461bcd60e51b815260206004820152601060248201527f21737570706f72746564206173736574000000000000000000000000000000006044820152606401610534565b5080610abe8161406c565b9150506109fe565b50610ad085611780565b610ad861066e565b6001600160801b03166101008301526000610af386866117fa565b60016020850152905060005a60405163b9efcfab60e01b8152909150309063b9efcfab906101208a013590610b2c908b90600401614463565b60006040518083038160008887f193505050508015610b6d57506040513d6000823e601f3d908101601f19168201604052610b6a919081019061469f565b60015b610c09573d808015610b9b576040519150601f19603f3d011682016040523d82523d6000602084013e610ba0565b606091505b506000610bac82611a02565b90508051600003610bf357604080518082018252601c81527f65786365656465642060657865637574696f6e4761734c696d69746000000000602082015290870152610bfb565b604086018190525b505060e08401829052610c20565b600187526060870192909252608086015260e08501525b610c2987611a3c565b610c33908761476c565b60a0850152610c516101208801355a610c4c9084614783565b611a62565b60c0850152610c6287858888611a78565b610c6b87611b4a565b610c7361066e565b6001600160801b03166101208501525050506001610147559392505050565b610c9a6114d7565b61068a6000611bf6565b60655433906001600160a01b03168114610d125760405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608401610534565b610d1b81611bf6565b50565b610d266114d7565b61068a611c0f565b610d366114d7565b6001600160a01b038216600081815261017a6020908152604091829020805460ff19168515159081179091558251938452908301527f7ea68faa530351818165a7ce70585717acbdd207ec45e501cd6a81f263a364c091015b60405180910390a15050565b610da36114d7565b77ffffffffffffffffffffffffffffffffffffffff00000000602084811b9190911660e084901c17600081815261017b8352604090819020805485151560ff19909116811790915581516001600160a01b03881681526001600160e01b0319871694810194909452838201525190917f94540635cbdcea052b9bce97a7cc558ae28970966db7477ff284bb3e0609851c919081900360600190a150505050565b33600090815260e0602052604090205460ff16610ea25760405162461bcd60e51b815260206004820152601960248201527f4f6e6c7920737562747265652062617463682066696c6c6572000000000000006044820152606401610534565b6000610eae60cb611c4c565b6001600160401b0316905060008111610f095760405162461bcd60e51b815260206004820152601660248201527f217a65726f2066696c6c20656d707479206261746368000000000000000000006044820152606401610534565b6000610f1560cb611531565b6001600160801b031690506000610f2d836010614783565b9050610f3960cb611c6d565b60408051838152602081018390527f8865c2a0c0d95d3da57d4c528ea72a2fdc92192373aabc7e147a73ecee5a56cb910161079d565b6060806000610f7c611300565b333014610fb75760405162461bcd60e51b81526020600482015260096024820152684f6e6c79207468697360b81b6044820152606401610534565b6002610147541461100a5760405162461bcd60e51b815260206004820152601b60248201527f5265656e74727920696e746f2065786563757465416374696f6e7300000000006044820152606401610534565b600361014755600061101f60a0860186614796565b90509050806001600160401b0381111561103b5761103b613f64565b604051908082528060200260200182016040528015611064578160200160208202803683370190505b509350806001600160401b0381111561107f5761107f613f64565b6040519080825280602002602001820160405280156110b257816020015b606081526020019060019003908161109d5790505b50925060005b81811015611212576110f76110d060a0880188614796565b838181106110e0576110e0614040565b90506020028101906110f291906147df565b611c76565b86838151811061110957611109614040565b6020026020010186848151811061112257611122614040565b602090810291909101019190915290151590526111476101a0870161018088016147ff565b801561116a575084818151811061116057611160614040565b6020026020010151155b1561120057600061119385838151811061118657611186614040565b6020026020010151611a02565b905080516000036111e65760405162461bcd60e51b815260206004820152601860248201527f616374696f6e2073696c656e746c7920726576657274656400000000000000006044820152606401610534565b8060405162461bcd60e51b8152600401610534919061481c565b8061120a8161406c565b9150506110b8565b5061121c85611f9b565b60026101475593959294505050565b6112336114d7565b6001600160a01b038216600081815260e06020908152604091829020805460ff19168515159081179091558251938452908301527fd5526a8e995d06d14d095efbea5d9aaf857f75a6ddc8198403003bce7ea20c079101610d8f565b6112976114d7565b606580546001600160a01b0383166001600160a01b031990911681179091556112c86033546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b60975460ff161561068a5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610534565b602081015181516000916001600160a01b03821691600381811b600760fd1b169092179160a09190911c1680840361138e57600093506113f8565b8060010361139f57600193506113f8565b806002036113b057600293506113f8565b60405162461bcd60e51b815260206004820152601860248201527f496e76616c696420656e636f64656441737365744164647200000000000000006044820152606401610534565b509193909250565b600061140c60cb611531565b6040805160c08101825285358152602080870135818301526001600160801b038416928201929092528651606082015290860151608082015260a0810184905290915061145881612083565b6040808201518651602080890151845189358152828a013592810192909252938101929092526060820152608081019190915260a081018490526001600160801b03831660c08201527f7e44173b0d57b460187962e8ccda97c4f6dc0604464fc038150dca7e7b9452fe9060e00160405180910390a1505b9392505050565b6033546001600160a01b0316331461068a5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610534565b600061153f82601201612097565b61154a90601061482f565b61155383611c4c565b8354611571916001600160401b0316906001600160801b031661485a565b61157b919061485a565b92915050565b6115896120b9565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b60006115df848461210b565b6014850154604051632833f41360e11b81529192506001600160a01b031690635067e826906116149085908590600401614881565b602060405180830381865afa158015611631573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165591906148f6565b6116a15760405162461bcd60e51b815260206004820152601c60248201527f73756274726565207570646174652070726f6f6620696e76616c6964000000006044820152606401610534565b6116ad846012016121fb565b5060018401839055835460109085906000906116d39084906001600160801b031661485a565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555050505050565b600054610100900460ff166117245760405162461bcd60e51b815260040161053490614913565b600161014755565b600054610100900460ff166117535760405162461bcd60e51b815260040161053490614913565b61175c826122c9565b61011480546001600160a01b0319166001600160a01b039290921691909117905550565b600061178f6080830183613ff8565b9050905060005b818110156108cd576117e76117ae6080850185613ff8565b838181106117be576117be614040565b6117d5926060909102013681900381019150613faa565b610114546001600160a01b0316612363565b50806117f28161406c565b915050611796565b600061180583612469565b60c0830160006118158585612867565b90503660006118248780614796565b9050905060005b818110156119a957600061183f8980614796565b8381811061184f5761184f614040565b9050602002810190611861919061495e565b611872906040810190602001614974565b905061188160808a018a613ff8565b8260ff1681811061189457611894614040565b606002919091019450600090506118b46118ae8b80614796565b85612882565b905060006118cc6118c58c80614796565b868561293c565b90506000871180156118e357506118e3888761299a565b156119105760006118f48289611a62565b90506119008183614783565b915061190c8189614783565b9750505b61191b82600161498f565b9350886119278161406c565b99505080156119a1576101135460405163042609d760e31b81528735600482015260208801356024820152604481018390526001600160a01b03909116906321304eb890606401600060405180830381600087803b15801561198857600080fd5b505af115801561199c573d6000803e3d6000fd5b505050505b50505061182b565b5082156119f85760405162461bcd60e51b815260206004820152601260248201527f546f6f206665772067617320746f6b656e7300000000000000000000000000006044820152606401610534565b5050505092915050565b6060604482511015611a2257505060408051602081019091526000815290565b6004820191508180602001905181019061157b91906149a2565b6000611a4b6020830183614796565b9050611a578380614796565b61157b92915061498f565b600081831015611a7257826114d0565b50919050565b60c084016000611a888685612867565b90508015611b42576101135460405163042609d760e31b81528335600482015260208401356024820152604481018390526001600160a01b03909116906321304eb890606401600060405180830381600087803b158015611ae857600080fd5b505af1158015611afc573d6000803e3d6000fd5b505050506000611b0c87876129b6565b9050610100870135611b1e8284614783565b1015611b275750805b611b40611b3936859003850185613faa565b8583612a41565b505b505050505050565b366000611b5a6080840184613ff8565b9050905060005b81811015611bf057611b766080850185613ff8565b82818110611b8657611b86614040565b60600291909101935060009050611bb7611ba536869003860186613faa565b610113546001600160a01b0316612363565b90508015611bdd57611bdb611bd136869003860186613faa565b8660400183611400565b505b5080611be88161406c565b915050611b61565b50505050565b606580546001600160a01b0319169055610d1b81612b59565b611c17611300565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586115b63390565b805460009061157b90600190600160801b90046001600160401b03166149ea565b610d1b81612bab565b60006060611c876020840184613b65565b6001600160a01b03163b600003611ccd5760405162461bcd60e51b815260206004820152600a602482015269217a65726f20636f646560b01b6044820152606401610534565b610113546001600160a01b0316611ce76020850185613b65565b6001600160a01b031603611d3d5760405162461bcd60e51b815260206004820152601f60248201527f43616e6e6f742063616c6c20746865204e6f637475726e652054656c6c6572006044820152606401610534565b6000611d54611d4f6020860186614a0a565b612be2565b90506000611d90611d686020870187613b65565b8360e01c60209190911b77ffffffffffffffffffffffffffffffffffffffff00000000161790565b6001600160c01b038116600090815261017b602052604090205490915060ff16611e0c5760405162461bcd60e51b815260206004820152602760248201527f43616e6e6f742063616c6c206e6f6e2d616c6c6f7765642070726f746f636f6c604482015266081b595d1a1bd960ca1b6064820152608401610534565b63f6a1584d60e01b6001600160e01b0319831601611f1b576044611e336020870187614a0a565b905014611e825760405162461bcd60e51b815260206004820152601260248201527f21617070726f766520666e206c656e67746800000000000000000000000000006044820152606401610534565b6000611e916020870187614a0a565b611e9f916004908290614a50565b810190611eac9190614a7a565b506001600160a01b038116600090815261017a602052604090205490915060ff16611f195760405162461bcd60e51b815260206004820152601060248201527f21617070726f7665207370656e646572000000000000000000000000000000006044820152606401610534565b505b611f286020860186613b65565b6001600160a01b0316611f3e6020870187614a0a565b604051611f4c929190614aa6565b6000604051808303816000865af19150503d8060008114611f89576040519150601f19603f3d011682016040523d82523d6000602084013e611f8e565b606091505b5090969095509350505050565b60008080611fac6080850185613ff8565b9050905060005b81811015612055576000611fe8611fcd6080880188613ff8565b84818110611fdd57611fdd614040565b905060600201612c4c565b905080156120425784611ffa8161406c565b9550508315801561203857506120386120166080880188613ff8565b8481811061202657612026614040565b9050606002016000018760c00161299a565b1561204257600193505b508061204d8161406c565b915050611fb3565b508115801561206957506000846101400135115b1561207c57826120788161406c565b9350505b5050919050565b61208c81612d23565b610d1b60cb82612e4b565b80546000906001600160801b03600160801b8204811691166105df8282612e64565b60975460ff1661068a5760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610534565b6060600061211b84601201612e8c565b905060008061212983612f19565b87549193509150600090612146906001600160801b031684612f30565b60408051600480825260a08201909252919250600091906020820160808036833701905050905087600101548160008151811061218557612185614040565b60200260200101818152505086816001815181106121a5576121a5614040565b60200260200101818152505081816002815181106121c5576121c5614040565b60200260200101818152505082816003815181106121e5576121e5614040565b6020908102919091010152979650505050505050565b80546000906001600160801b03600160801b82048116911661221d8282612e64565b6000036122545760405162461bcd60e51b8152602060048201526005602482015264456d70747960d81b6044820152606401610534565b6001600160801b038116600090815260018501602052604090205492508215612293576001600160801b03811660009081526001850160205260408120555b61229e81600161485a565b84546fffffffffffffffffffffffffffffffff19166001600160801b03919091161790935550919050565b600054610100900460ff166122f05760405162461bcd60e51b815260040161053490614913565b6122f8612fdf565b61230061300e565b61230b60cb8261303d565b507f1fe48018cdbfc6b7d8bc35b49fdde4563ab7ddb7b1d917c4dd087a8a6265f59860005260c96020527f2a38d31b1a338d741911d0d0d852fa107c786f32172e830c3bae7a1f64121a6b805460ff19166001179055565b610113546000906001600160a01b03838116911614806123915750610114546001600160a01b038381169116145b6123dd5760405162461bcd60e51b815260206004820152600f60248201527f496e76616c696420746f206164647200000000000000000000000000000000006044820152606401610534565b60006123e88461310b565b905060006123f585611353565b50909150600090508082600281111561241057612410614ab6565b1461241c57600061241f565b60015b60ff169050600081841161243457600061243e565b61243e8285614783565b9050801561245c57612451878783612a41565b935061157b92505050565b5060009695505050505050565b600061247482611a3c565b9050600061248382600261476c565b6001600160401b0381111561249a5761249a613f64565b6040519080825280602002602001820160405280156124c3578160200160208202803683370190505b50905060006124d260cb611531565b90503660005b84811015612856576124ea8680614796565b9050811061253a576124ff6020870187614796565b6125098880614796565b612514915084614783565b81811061252357612523614040565b90506020028101906125359190614acc565b612570565b6125448680614796565b8281811061255457612554614040565b9050602002810190612566919061495e565b6125709080614acc565b8035600090815260c9602052604090205490925060ff166125d35760405162461bcd60e51b815260206004820152601760248201527f5472656520726f6f74206e6f74207061737420726f6f740000000000000000006044820152606401610534565b602080830135600090815260ca909152604090205460ff16156126385760405162461bcd60e51b815260206004820152601860248201527f4e756c6c6966696572204120616c7265616479207573656400000000000000006044820152606401610534565b604080830135600090815260ca602052205460ff161561269a5760405162461bcd60e51b815260206004820152601860248201527f4e756c6c6966696572204220616c7265616479207573656400000000000000006044820152606401610534565b81604001358260200135036126f15760405162461bcd60e51b815260206004820152601360248201527f32206e66732073686f756c642021657175616c000000000000000000000000006044820152606401610534565b602082810135600090815260ca90915260408082208054600160ff199182168117909255828601358452918320805490921617905561273182600261476c565b61273b908561485a565b9050600061274a83600261476c565b61275590600161498f565b61275f908661485a565b905060608401358661277285600261476c565b8151811061278257612782614040565b602090810291909101015260808401358661279e85600261476c565b6127a990600161498f565b815181106127b9576127b9614040565b602002602001018181525050836040013584602001357f26522f457c833ab2f50122cf6922e5362473d89bc731f6f8c1389a9f302550358484886060013589608001358a60a001358b60c001358c806101e0019061281791906147df565b6128256102008f018f6147df565b604051612839989796959493929190614ae3565b60405180910390a35050808061284e9061406c565b9150506124d8565b506128608361328f565b5050505050565b6000612873838361329a565b6114d09061014085013561476c565b60008084848481811061289757612897614040565b90506020028101906128a9919061495e565b6128ba906040810190602001614974565b60ff16905083835b816128ce82600161498f565b10801561291b575086866128e383600161498f565b8181106128f2576128f2614040565b9050602002810190612904919061495e565b612915906040810190602001614974565b60ff1683145b15612932578061292a8161406c565b9150506128c2565b9695505050505050565b600080835b83811161298e5786868281811061295a5761295a614040565b905060200281019061296c919061495e565b61297a90604001358361498f565b9150806129868161406c565b915050612941565b5090505b949350505050565b6000823582351480156114d05750506020918201359101351490565b6000806201adb06129c685611a3c565b6129d0919061476c565b905060006129e06161a88061498f565b8460e001516129ef919061476c565b9050620186a0818560c00151848760a00151612a0b919061498f565b612a15919061498f565b612a1f919061498f565b612a29919061498f565b612a389061014087013561476c565b95945050505050565b600080612a4d85611353565b5090925090506000826002811115612a6757612a67614ab6565b03612a8557612a806001600160a01b0382168585613320565b612860565b6001826002811115612a9957612a99614ab6565b03612ad35760405162461bcd60e51b815260206004820152600a602482015269085cdd5c1c1bdc9d195960b21b6044820152606401610534565b6002826002811115612ae757612ae7614ab6565b03612b215760405162461bcd60e51b815260206004820152600a602482015269085cdd5c1c1bdc9d195960b21b6044820152606401610534565b60405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a5908185cdcd95d609a1b6044820152606401610534565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000612bb682613387565b9050612bc560128301826134f7565b5081546001600160c01b03168255612bde826000613558565b5050565b60006004821015612c355760405162461bcd60e51b815260206004820152601260248201527f21656e636f64656420666e206c656e67746800000000000000000000000000006044820152606401610534565b612c43600460008486614a50565b6114d091614b4b565b60008181612c67612c6236849003840184613faa565b61310b565b90506000612c7d610a3f36859003850185613faa565b509091506000905080826002811115612c9857612c98614ab6565b14612ca4576000612ca7565b60015b60ff169050808311612cba576000612cc4565b612cc48184614783565b94508560400135851015612d1a5760405162461bcd60e51b815260206004820152601160248201527f216d696e20726566756e642076616c75650000000000000000000000000000006044820152606401610534565b50505050919050565b7f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018160400151108015612d7957507f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018160600151105b8015612d98575060608101516b1e3fffffffffffffffffffff60a31b16155b8015612dc857507f1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff816080015111155b8015612df857507f0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160a0015111155b612e335760405162461bcd60e51b815260206004820152600c60248201526b696e76616c6964206e6f746560a01b6044820152606401610534565b8051612e3e906135a2565b610d1b81602001516135a2565b6000612e5682613624565b90506108cd8382600061372b565b600081612e7284600161485a565b612e7c9190614b79565b6001600160801b03169392505050565b6000612eab82546001600160801b03808216600160801b909204161090565b15612ef85760405162461bcd60e51b815260206004820152600e60248201527f517565756520697320656d7074790000000000000000000000000000000000006044820152606401610534565b5080546001600160801b031660009081526001909101602052604090205490565b600080612f278360fd6137f8565b91509150915091565b6000612f4660106001600160801b038516614b99565b15612fa15760405162461bcd60e51b815260206004820152602560248201527f73756274726565496478206e6f74206d756c7469706c65206f662042415443486044820152645f53495a4560d81b6064820152608401610534565b6000612fae60028061476c565b6001600160801b038516901c9050612fc860026010614783565b612fd390600261476c565b83901b17905092915050565b600054610100900460ff166130065760405162461bcd60e51b815260040161053490614913565b61068a61381c565b600054610100900460ff166130355760405162461bcd60e51b815260040161053490614913565b61068a61384c565b7f1fe48018cdbfc6b7d8bc35b49fdde4563ab7ddb7b1d917c4dd087a8a6265f5986001830155815477ffffffffffffffff0000000000000000000000000000000016825561308c826000613558565b6014820180546001600160a01b0319166001600160a01b0383161790556130b56012830161387f565b60005b60108110156108cd577f1a2547cb123f691ef1fd5d62b27584a8a6e55b21377854db5bb4dd7e2d9ee9cf8360020182601081106130f7576130f7614040565b0155806131038161406c565b9150506130b8565b60008060008061311a85611353565b9194509250905060008084600281111561313657613136614ab6565b036131ab576040516370a0823160e01b81523060048201526001600160a01b038416906370a08231906024015b602060405180830381865afa158015613180573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131a49190614bbb565b9050612a38565b60018460028111156131bf576131bf614ab6565b03613245576040516331a9108f60e11b8152600481018390526001600160a01b03841690636352211e90602401602060405180830381865afa925050508015613225575060408051601f3d908101601f1916820190925261322291810190614bd4565b60015b15612a3857306001600160a01b0382160361323f57600191505b50612a38565b600284600281111561325957613259614ab6565b03612b2157604051627eeac760e11b8152306004820152602481018390526001600160a01b0384169062fdd58e90604401613163565b610d1b60cb826138ae565b6000806132a684611a3c565b9050620186a06132b782600261476c565b6132c46080870187613ff8565b6132cf92915061498f565b6132db6161a88061498f565b6132e5919061476c565b826132f36201adb08761498f565b6132fd919061476c565b61330c9061012088013561498f565b613316919061498f565b612992919061498f565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663a9059cbb60e01b1790526108cd9084906138f1565b60008061339383611c4c565b6001600160401b0316905060006133ac6010600161498f565b6001600160401b038111156133c3576133c3613f64565b6040519080825280602002602001820160405280156133ec578160200160208202803683370190505b50905060005b828110156134405784600201816010811061340f5761340f614040565b015482828151811061342357613423614040565b6020908102919091010152806134388161406c565b9150506133f2565b50815b601081101561349c577f1a2547cb123f691ef1fd5d62b27584a8a6e55b21377854db5bb4dd7e2d9ee9cf82828151811061347f5761347f614040565b6020908102919091010152806134948161406c565b915050613443565b5083548151600160c01b90910460c01b7fffffffffffffffff0000000000000000000000000000000000000000000000001690829060109081106134e2576134e2614040565b602002602001018181525050612992816139c6565b815460009061351790600160801b90046001600160801b0316600161485a565b83546001600160801b03808316600160801b0291161784559050811561157b576001600160801b038116600090815260019390930160205260409092205590565b613563816001614bf1565b82546001600160401b0391909116600160801b027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff9091161790915550565b7fbfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81167f30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f00000018110612bde5760405162461bcd60e51b815260206004820152600d60248201526c1a5b9d985b1a59081c1bda5b9d609a1b6044820152606401610534565b60408051600680825260e082019092526000918291906020820160c08036833701905050905082600001518160008151811061366257613662614040565b60200260200101818152505082602001518160018151811061368657613686614040565b6020026020010181815250508260400151816002815181106136aa576136aa614040565b6020026020010181815250508260600151816003815181106136ce576136ce614040565b6020026020010181815250508260800151816004815181106136f2576136f2614040565b6020026020010181815250508260a001518160058151811061371657613716614040565b6020026020010181815250506114d0816139c6565b600061373684611c4c565b90508284600201826001600160401b03166010811061375757613757614040565b0155600082600181111561376d5761376d614ab6565b1461377957600061379b565b61378481603f6149ea565b6001600160401b031660016001600160401b0316901b5b84546001600160c01b038116600160c01b918290046001600160401b039081169316929092170217845560006137d2826001614bf1565b90506137de8582613558565b6010816001600160401b0316036128605761286085612bab565b60008083831c8161380c600180871b614783565b91935050841690505b9250929050565b600054610100900460ff166138435760405162461bcd60e51b815260040161053490614913565b61068a33611bf6565b600054610100900460ff166138735760405162461bcd60e51b815260040161053490614913565b6097805460ff19169055565b80546001600160801b0316600003610d1b5780546fffffffffffffffffffffffffffffffff1916600117815550565b60005b81518110156108cd576138df838383815181106138d0576138d0614040565b6020026020010151600161372b565b806138e98161406c565b9150506138b1565b6000613946826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613a359092919063ffffffff16565b905080516000148061396757508080602001905181019061396791906148f6565b6108cd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610534565b60006002826040516020016139db9190614c11565b60408051601f19818403018152908290526139f591614c47565b602060405180830381855afa158015613a12573d6000803e3d6000fd5b5050506040513d601f19601f8201168201806040525081019061157b9190614bbb565b6060612992848460008585600080866001600160a01b03168587604051613a5c9190614c47565b60006040518083038185875af1925050503d8060008114613a99576040519150601f19603f3d011682016040523d82523d6000602084013e613a9e565b606091505b5091509150613aaf87838387613aba565b979650505050505050565b60608315613b29578251600003613b22576001600160a01b0385163b613b225760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610534565b5081612992565b61299283838151156111e65781518083602001fd5b600060c08284031215611a7257600080fd5b6001600160a01b0381168114610d1b57600080fd5b600060208284031215613b7757600080fd5b81356114d081613b50565b600060208284031215613b9457600080fd5b5035919050565b600080610120808486031215613bb057600080fd5b83359250848185011115613bc357600080fd5b506020830190509250929050565b60008060408385031215613be457600080fd5b8235613bef81613b50565b91506020830135613bff81613b50565b809150509250929050565b600060208284031215613c1c57600080fd5b81356001600160c01b03811681146114d057600080fd5b60006101a08284031215611a7257600080fd5b600080600060608486031215613c5b57600080fd5b83356001600160401b03811115613c7157600080fd5b613c7d86828701613c33565b935050602084013591506040840135613c9581613b50565b809150509250925092565b60005b83811015613cbb578181015183820152602001613ca3565b50506000910152565b60008151808452613cdc816020860160208601613ca0565b601f01601f19169290920160200192915050565b600081518084526020808501945080840160005b83811015613d22578151151587529582019590820190600101613d04565b509495945050505050565b600082825180855260208086019550808260051b84010181860160005b84811015613d7857601f19868403018952613d66838351613cc4565b98840198925090830190600101613d4a565b5090979650505050505050565b60208152613d9860208201835115159052565b60006020830151613dad604084018215159052565b506040830151610140806060850152613dca610160850183613cc4565b91506060850151601f1980868503016080870152613de88483613cf0565b935060808701519150808685030160a087015250613e068382613d2d565b92505060a085015160c085015260c085015160e085015260e0850151610100818187015280870151915050610120613e48818701836001600160801b03169052565b8601516001600160801b0381168387015290505b5090949350505050565b8015158114610d1b57600080fd5b80356105e481613e66565b60008060408385031215613e9257600080fd5b8235613e9d81613b50565b91506020830135613bff81613e66565b600080600060608486031215613ec257600080fd5b8335613ecd81613b50565b925060208401356001600160e01b031981168114613eea57600080fd5b91506040840135613c9581613e66565b600060208284031215613f0c57600080fd5b81356001600160401b03811115613f2257600080fd5b61299284828501613c33565b606081526000613f416060830186613cf0565b8281036020840152613f538186613d2d565b915050826040830152949350505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613fa257613fa2613f64565b604052919050565b600060408284031215613fbc57600080fd5b604051604081018181106001600160401b0382111715613fde57613fde613f64565b604052823581526020928301359281019290925250919050565b6000808335601e1984360301811261400f57600080fd5b8301803591506001600160401b0382111561402957600080fd5b602001915060608102360382131561381557600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161407e5761407e614056565b5060010190565b6000808335601e1984360301811261409c57600080fd5b83016020810192503590506001600160401b038111156140bb57600080fd5b8060051b360382131561381557600080fd5b6000823561021e198336030181126140e457600080fd5b90910192915050565b6101008183375050565b60008235603e198336030181126140e457600080fd5b6000808335601e1984360301811261412457600080fd5b83016020810192503590506001600160401b0381111561414357600080fd5b80360382131561381557600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6000614187828361410d565b60408552614199604086018284614152565b9150506141a9602084018461410d565b8583036020870152612932838284614152565b6000610220823584526020830135602085015260408301356040850152606083013560608501526080830135608085015260a083013560a085015260c083013560c085015261421160e0850160e085016140ed565b6101e0614220818501856140f7565b82828701526142318387018261417b565b92505050610200614244818501856140f7565b85830382870152612932838261417b565b803560ff811681146105e457600080fd5b81835260006020808501808196508560051b81019150846000805b888110156142ee578385038a528235605e198936030181126142a1578283fd5b880160606142af82806140cd565b8188526142be828901826141bc565b91505060ff6142ce898401614255565b168789015260409182013591909601529885019891850191600101614281565b509298975050505050505050565b81835260006020808501808196508560051b810191508460005b8781101561434857828403895261433684614331848a6140cd565b6141bc565b98850198935090840190600101614316565b5091979650505050505050565b6000808335601e1984360301811261436c57600080fd5b83016020810192503590506001600160401b0381111561438b57600080fd5b60608102360382131561381557600080fd5b81835260208301925060008160005b848110156143de57813586526020808301359087015260408281013590870152606095860195909101906001016143ac565b5093949350505050565b818352600060208085019450848460051b86018460005b87811015613d7857838303895261441682886140f7565b6040813561442381613b50565b6001600160a01b0316855261443a8288018361410d565b9250818887015261444e8287018483614152565b9b88019b9550505091850191506001016143ff565b6020815260006144738384614085565b6101a080602086015261448b6101c086018385614266565b925061449a6020870187614085565b9250601f19808786030160408801526144b48585846142fc565b94506144d06060880160408a0180358252602090810135910152565b6144dd6080890189614355565b94509150808786030160a08801526144f685858461439d565b945061450560a0890189614085565b94509150808786030160c08801525061451f8484836143e8565b93505061453c60e0860160c0880180358252602090810135910152565b61012091506101008601358286015261014082870135818701526101609250808701358387015250610180828701358187015261457a818801613e74565b925050613e5c8186018315159052565b60006001600160401b038211156145a3576145a3613f64565b5060051b60200190565b60006001600160401b038311156145c6576145c6613f64565b6145d9601f8401601f1916602001613f7a565b90508281528383830111156145ed57600080fd5b6114d0836020830184613ca0565b600082601f83011261460c57600080fd5b8151602061462161461c8361458a565b613f7a565b82815260059290921b8401810191818101908684111561464057600080fd5b8286015b848110156146945780516001600160401b038111156146635760008081fd5b8701603f810189136146755760008081fd5b6146868986830151604084016145ad565b845250918301918301614644565b509695505050505050565b6000806000606084860312156146b457600080fd5b83516001600160401b03808211156146cb57600080fd5b818601915086601f8301126146df57600080fd5b815160206146ef61461c8361458a565b82815260059290921b8401810191818101908a84111561470e57600080fd5b948201945b8386101561473557855161472681613e66565b82529482019490820190614713565b9189015191975090935050508082111561474e57600080fd5b5061475b868287016145fb565b925050604084015190509250925092565b808202811582820484141761157b5761157b614056565b8181038181111561157b5761157b614056565b6000808335601e198436030181126147ad57600080fd5b8301803591506001600160401b038211156147c757600080fd5b6020019150600581901b360382131561381557600080fd5b60008235603e198336030181126147f557600080fd5b9190910192915050565b60006020828403121561481157600080fd5b81356114d081613e66565b6020815260006114d06020830184613cc4565b6001600160801b0381811683821602808216919082811461485257614852614056565b505092915050565b6001600160801b0381811683821601908082111561487a5761487a614056565b5092915050565b60006101208281018386845b60088110156148ac57815183526020928301929091019060010161488d565b50505061010084019190915283519081905261014083019060209081860160005b828110156148e9578151855293830193908301906001016148cd565b5092979650505050505050565b60006020828403121561490857600080fd5b81516114d081613e66565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60008235605e198336030181126147f557600080fd5b60006020828403121561498657600080fd5b6114d082614255565b8082018082111561157b5761157b614056565b6000602082840312156149b457600080fd5b81516001600160401b038111156149ca57600080fd5b8201601f810184136149db57600080fd5b612992848251602084016145ad565b6001600160401b0382811682821603908082111561487a5761487a614056565b6000808335601e19843603018112614a2157600080fd5b8301803591506001600160401b03821115614a3b57600080fd5b60200191503681900382131561381557600080fd5b60008085851115614a6057600080fd5b83861115614a6d57600080fd5b5050820193919092039150565b60008060408385031215614a8d57600080fd5b8235614a9881613b50565b946020939093013593505050565b8183823760009101908152919050565b634e487b7160e01b600052602160045260246000fd5b6000823561021e198336030181126147f557600080fd5b60006101006001600160801b03808c168452808b166020850152508860408401528760608401528660808401528560a08401528060c0840152614b288184018661417b565b905082810360e0840152614b3c818561417b565b9b9a5050505050505050505050565b6001600160e01b031981358181169160048510156148525760049490940360031b84901b1690921692915050565b6001600160801b0382811682821603908082111561487a5761487a614056565b600082614bb657634e487b7160e01b600052601260045260246000fd5b500690565b600060208284031215614bcd57600080fd5b5051919050565b600060208284031215614be657600080fd5b81516114d081613b50565b6001600160401b0381811683821601908082111561487a5761487a614056565b815160009082906020808601845b83811015614c3b57815185529382019390820190600101614c1f565b50929695505050505050565b600082516147f5818460208701613ca056fea164736f6c6343000811000a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.