ETH Price: $3,381.74 (+1.02%)

Contract

0x22af4EDBeA3De885dDa8f0a0653E6209e44e5B84
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Relay204534962024-08-04 6:48:35141 days ago1722754115IN
0x22af4EDB...9e44e5B84
0.00096726 ETH0.000116121
Relay160751322022-11-29 10:44:35755 days ago1669718675IN
0x22af4EDB...9e44e5B84
0 ETH0.0248529212.30811493
Relay160751012022-11-29 10:38:23755 days ago1669718303IN
0x22af4EDB...9e44e5B84
0.3 ETH0.010316913.56352029
Relay160750822022-11-29 10:34:35755 days ago1669718075IN
0x22af4EDB...9e44e5B84
0.7 ETH0.0100556613.12778592
Relay160742082022-11-29 7:38:59755 days ago1669707539IN
0x22af4EDB...9e44e5B84
0 ETH0.0150967312.55287907
Relay160742002022-11-29 7:37:23755 days ago1669707443IN
0x22af4EDB...9e44e5B84
1.06821331 ETH0.009786712.77645966
Relay160741752022-11-29 7:32:23755 days ago1669707143IN
0x22af4EDB...9e44e5B84
0 ETH0.012614210.7178923
Relay160730182022-11-29 3:39:23756 days ago1669693163IN
0x22af4EDB...9e44e5B84
0.17998119 ETH0.0084984711.09468987
Relay160681232022-11-28 11:15:35756 days ago1669634135IN
0x22af4EDB...9e44e5B84
0 ETH0.0141763912.41833898
Relay160681142022-11-28 11:13:47756 days ago1669634027IN
0x22af4EDB...9e44e5B84
1.13613117 ETH0.0105071513.52855216
Relay160680352022-11-28 10:57:59756 days ago1669633079IN
0x22af4EDB...9e44e5B84
0 ETH0.0138270111.39555878
Relay160680062022-11-28 10:52:11756 days ago1669632731IN
0x22af4EDB...9e44e5B84
2.92579613 ETH0.0099724213.11043997
Relay160680022022-11-28 10:51:23756 days ago1669632683IN
0x22af4EDB...9e44e5B84
6.43763191 ETH0.0107565714.04305275
Relay160677732022-11-28 10:05:35756 days ago1669629935IN
0x22af4EDB...9e44e5B84
0 ETH0.0161792214.30651363
Relay160677592022-11-28 10:02:47756 days ago1669629767IN
0x22af4EDB...9e44e5B84
0 ETH0.0349232416.1303984
Relay160656452022-11-28 2:58:59757 days ago1669604339IN
0x22af4EDB...9e44e5B84
0.00354969 ETH0.007606610
Relay160631312022-11-27 18:31:59757 days ago1669573919IN
0x22af4EDB...9e44e5B84
0.1390356 ETH0.0078375910.23223211
Relay160629962022-11-27 18:04:47757 days ago1669572287IN
0x22af4EDB...9e44e5B84
0 ETH0.0154960310.71090519
Relay160628582022-11-27 17:36:59757 days ago1669570619IN
0x22af4EDB...9e44e5B84
0 ETH0.0125162910.6763339
Relay160628532022-11-27 17:35:59757 days ago1669570559IN
0x22af4EDB...9e44e5B84
0 ETH0.0226364910.3531925
Relay160626512022-11-27 16:55:11757 days ago1669568111IN
0x22af4EDB...9e44e5B84
0 ETH0.0132228411.33493087
Relay160625962022-11-27 16:43:59757 days ago1669567439IN
0x22af4EDB...9e44e5B84
0.19732619 ETH0.0090917211.86916872
Relay160624542022-11-27 16:15:23757 days ago1669565723IN
0x22af4EDB...9e44e5B84
0 ETH0.0159676110.86612073
Relay160601372022-11-27 8:29:59757 days ago1669537799IN
0x22af4EDB...9e44e5B84
0 ETH0.013212810.72454138
Relay160595582022-11-27 6:33:59757 days ago1669530839IN
0x22af4EDB...9e44e5B84
0 ETH0.0135061910.87083127
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
204534962024-08-04 6:48:35141 days ago1722754115
0x22af4EDB...9e44e5B84
0.00096726 ETH
160751322022-11-29 10:44:35755 days ago1669718675
0x22af4EDB...9e44e5B84
2.36485658 ETH
160751322022-11-29 10:44:35755 days ago1669718675
0x22af4EDB...9e44e5B84
2.36485658 ETH
160751012022-11-29 10:38:23755 days ago1669718303
0x22af4EDB...9e44e5B84
0.3 ETH
160750822022-11-29 10:34:35755 days ago1669718075
0x22af4EDB...9e44e5B84
0.7 ETH
160742082022-11-29 7:38:59755 days ago1669707539
0x22af4EDB...9e44e5B84
1.10609712 ETH
160742082022-11-29 7:38:59755 days ago1669707539
0x22af4EDB...9e44e5B84
1.10609712 ETH
160742002022-11-29 7:37:23755 days ago1669707443
0x22af4EDB...9e44e5B84
1.06821331 ETH
160741752022-11-29 7:32:23755 days ago1669707143
0x22af4EDB...9e44e5B84
0.009975 ETH
160741752022-11-29 7:32:23755 days ago1669707143
0x22af4EDB...9e44e5B84
0.009975 ETH
160730182022-11-29 3:39:23756 days ago1669693163
0x22af4EDB...9e44e5B84
0.17998119 ETH
160681232022-11-28 11:15:35756 days ago1669634135
0x22af4EDB...9e44e5B84
1.08507765 ETH
160681232022-11-28 11:15:35756 days ago1669634135
0x22af4EDB...9e44e5B84
1.08507765 ETH
160681142022-11-28 11:13:47756 days ago1669634027
0x22af4EDB...9e44e5B84
1.13613117 ETH
160680352022-11-28 10:57:59756 days ago1669633079
0x22af4EDB...9e44e5B84
9.2490176 ETH
160680352022-11-28 10:57:59756 days ago1669633079
0x22af4EDB...9e44e5B84
9.2490176 ETH
160680062022-11-28 10:52:11756 days ago1669632731
0x22af4EDB...9e44e5B84
2.92579613 ETH
160680022022-11-28 10:51:23756 days ago1669632683
0x22af4EDB...9e44e5B84
6.43763191 ETH
160677732022-11-28 10:05:35756 days ago1669629935
0x22af4EDB...9e44e5B84
1.3965 ETH
160677732022-11-28 10:05:35756 days ago1669629935
0x22af4EDB...9e44e5B84
1.3965 ETH
160656452022-11-28 2:58:59757 days ago1669604339
0x22af4EDB...9e44e5B84
0.00354969 ETH
160631312022-11-27 18:31:59757 days ago1669573919
0x22af4EDB...9e44e5B84
0.1390356 ETH
160629962022-11-27 18:04:47757 days ago1669572287
0x22af4EDB...9e44e5B84
0.14900156 ETH
160629962022-11-27 18:04:47757 days ago1669572287
0x22af4EDB...9e44e5B84
0.14900156 ETH
160628582022-11-27 17:36:59757 days ago1669570619
0x22af4EDB...9e44e5B84
0.0951584 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
RelayAdapt

Compiler Version
v0.8.12+commit.f00d7308

Optimization Enabled:
Yes with 1600 runs

Other Settings:
default evmVersion
File 1 of 17 : Relay.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

// OpenZeppelin v4
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import { IWBase } from "./IWBase.sol";
import { RailgunLogic, Transaction, CommitmentPreimage, TokenData, TokenType } from "../../logic/RailgunLogic.sol";

/**
 * @title Relay Adapt
 * @author Railgun Contributors
 * @notice Multicall adapt contract for Railgun with relayer support
 */

contract RelayAdapt {
  using SafeERC20 for IERC20;

  // Snark bypass address, can't be address(0) as many burn prevention mechanisms will disallow transfers to 0
  // Use 0x000000000000000000000000000000000000dEaD as an alternative
  address constant public VERIFICATION_BYPASS = 0x000000000000000000000000000000000000dEaD;

  struct Call {
    address to;
    bytes data;
    uint256 value;
  }

  struct Result {
    bool success;
    string returnData;
  }

  event CallResult(Result[] callResults);

  // External contract addresses
  RailgunLogic public railgun;
  IWBase public wbase;

  /**
   * @notice only allows self calls to these contracts
   */
  modifier onlySelf() {
    require(msg.sender == address(this), "RelayAdapt: External call to onlySelf function");
    _;
  }

  /**
   * @notice Sets Railgun contract and wbase address
   */
  constructor(RailgunLogic _railgun, IWBase _wbase) {
    railgun = _railgun;
    wbase = _wbase;
  }

  /**
   * @notice Gets adapt params for Railgun batch
   * @param _transactions - Batch of Railgun transactions to execute
   * @param _additionalData - Additional data
   * @return adapt params
   */
  function getAdaptParams(
    Transaction[] calldata _transactions,
    bytes memory _additionalData
  ) public pure returns (bytes32) {
    uint256[] memory firstNullifiers = new uint256[](_transactions.length);

    for (uint256 i = 0; i < _transactions.length; i++) {
      // Only need first nullifier
      firstNullifiers[i] = _transactions[i].nullifiers[0];
    }

    return keccak256(
      abi.encode(
        firstNullifiers,
        _transactions.length,
        _additionalData
      )
    );
  }

  /**
   * @notice Executes a batch of Railgun transactions
   * @param _transactions - Batch of Railgun transactions to execute
   * @param _additionalData - Additional data
   * Should be random value if called directly
   * If called via multicall sub-call this can be extracted and submitted standalone
   * Be aware of the dangers of this before doing so!
   */
  function railgunBatch(
    Transaction[] calldata _transactions,
    bytes memory _additionalData
  ) public {
    bytes32 expectedAdaptParameters = getAdaptParams(_transactions, _additionalData);

    // Loop through each transaction and ensure adaptID parameters match
    for(uint256 i = 0; i < _transactions.length; i++) {
      require(
        _transactions[i].boundParams.adaptParams == expectedAdaptParameters
        // solhint-disable-next-line avoid-tx-origin
        || tx.origin == VERIFICATION_BYPASS,
        "GeneralAdapt: AdaptID Parameters Mismatch"
      );
    }

    // Execute railgun transactions
    railgun.transact(_transactions);
  }

  /**
   * @notice Executes a batch of Railgun deposits
   * @param _deposits - Tokens to deposit
   * @param _encryptedRandom - Encrypted random value for deposits
   * @param _npk - note public key to deposit to
   */
  function deposit(
    TokenData[] calldata _deposits,
    uint256[2] calldata _encryptedRandom,
    uint256 _npk
  ) external onlySelf {
    // Loop through each token specified for deposit and deposit our total balance
    // Due to a quirk with the USDT token contract this will fail if it's approval is
    // non-0 (https://github.com/Uniswap/interface/issues/1034), to ensure that your
    // transaction always succeeds when dealing with USDT/similar tokens make sure the last
    // call in your calls is a call to the token contract with an approval of 0
    CommitmentPreimage[] memory commitmentPreimages = new CommitmentPreimage[](_deposits.length);
    uint256 numValidTokens = 0;

    for (uint256 i = 0; i < _deposits.length; i++) {
      if (_deposits[i].tokenType == TokenType.ERC20) {
        IERC20 token = IERC20(_deposits[i].tokenAddress);

        // Fetch balance
        uint256 balance = token.balanceOf(address(this));

        if (balance > 0) {
          numValidTokens += 1;

          // Approve the balance for deposit
          token.safeApprove(
            address(railgun),
            balance
          );

          // Push to deposits arrays
          commitmentPreimages[i] = CommitmentPreimage({
            npk: _npk,
            value: uint120(balance),
            token: _deposits[i]
          });
        }
      } else if (_deposits[i].tokenType == TokenType.ERC721) {
        // ERC721 token
        revert("GeneralAdapt: ERC721 not yet supported");
      } else if (_deposits[i].tokenType == TokenType.ERC1155) {
        // ERC1155 token
        revert("GeneralAdapt: ERC1155 not yet supported");
      } else {
        // Invalid token type, revert
        revert("GeneralAdapt: Unknown token type");
      }
    }

    if (numValidTokens == 0) {
      return;
    }

    // Filter commitmentPreImages for != 0 (remove 0 balance tokens).
    CommitmentPreimage[] memory filteredCommitmentPreimages = new CommitmentPreimage[](numValidTokens);
    uint256[2][] memory filteredEncryptedRandom = new uint256[2][](numValidTokens);

    uint256 filterIndex = 0;
    for (uint256 i = 0; i < numValidTokens; i++) {
      while (commitmentPreimages[filterIndex].value == 0) {
        filterIndex += 1;
      }
      filteredCommitmentPreimages[i] = commitmentPreimages[filterIndex];
      filteredEncryptedRandom[i] = _encryptedRandom;
      filterIndex += 1;
    }

    // Deposit back to Railgun
    railgun.generateDeposit(filteredCommitmentPreimages, filteredEncryptedRandom);
  }

  /**
   * @notice Sends tokens to particular address
   * @param _tokens - tokens to send (0x0 - ERC20 is eth)
   * @param _to - ETH address to send to
   */
   function send(
    TokenData[] calldata _tokens,
    address _to
  ) external onlySelf {
    // Loop through each token specified for deposit and deposit our total balance
    // Due to a quirk with the USDT token contract this will fail if it's approval is
    // non-0 (https://github.com/Uniswap/interface/issues/1034), to ensure that your
    // transaction always succeeds when dealing with USDT/similar tokens make sure the last
    // call in your calls is a call to the token contract with an approval of 0
    for (uint256 i = 0; i < _tokens.length; i++) {
      if (_tokens[i].tokenType == TokenType.ERC20) {
        // ERC20 token
        IERC20 token = IERC20(_tokens[i].tokenAddress);

        if (address(token) == address(0x0)) {
          // Fetch ETH balance
          uint256 balance = address(this).balance;

          if (balance > 0) {
            // Send ETH
            // solhint-disable-next-line avoid-low-level-calls
            (bool sent,) = _to.call{value: balance}("");
            require(sent, "Failed to send Ether");
          }
        } else {
          // Fetch balance
          uint256 balance = token.balanceOf(address(this));

          if (balance > 0) {
            // Send all to address
            token.safeTransfer(_to, balance);
          }
        }
      } else if (_tokens[i].tokenType == TokenType.ERC721) {
        // ERC721 token
        revert("RailgunLogic: ERC721 not yet supported");
      } else if (_tokens[i].tokenType == TokenType.ERC1155) {
        // ERC1155 token
        revert("RailgunLogic: ERC1155 not yet supported");
      } else {
        // Invalid token type, revert
        revert("RailgunLogic: Unknown token type");
      }
    }
  }

  /**
   * @notice Wraps all base tokens in contract
   */
  function wrapAllBase() external onlySelf {
    // Fetch ETH balance
    uint256 balance = address(this).balance;

    // Wrap
    wbase.deposit{value: balance}();
  }

  /**
   * @notice Unwraps all wrapped base tokens in contract
   */
  function unwrapAllBase() external onlySelf {
    // Fetch ETH balance
    uint256 balance = wbase.balanceOf(address(this));

    // Unwrap
    wbase.withdraw(balance);
  }

  /**
   * @notice Executes multicall batch
   * @param _requireSuccess - Whether transaction should throw on call failure
   * @param _calls - multicall array
   */
  function multicall(
    bool _requireSuccess,
    Call[] calldata _calls
  ) internal {
    // Initialize returnData array
    Result[] memory returnData = new Result[](_calls.length);

    // Loop through each call
    for(uint256 i = 0; i < _calls.length; i++) {
      // Retrieve call
      Call calldata call = _calls[i];

      // Execute call
      // solhint-disable-next-line avoid-low-level-calls
      (bool success, bytes memory ret) = call.to.call{value: call.value, gas: gasleft()}(call.data);

      // Add call result to returnData
      returnData[i] = Result(success, string(ret));

      if (success) {
        continue;
      }

      bool isInternalCall = call.to == address(this);
      bool requireSuccess = _requireSuccess || isInternalCall;

      // If requireSuccess is true, throw on failure
      if (requireSuccess) {
        emit CallResult(returnData);
        revert(string.concat("GeneralAdapt Call Failed:", string(ret)));
      }
    }

    emit CallResult(returnData);
  }

  /**
   * @notice Convenience function to get the adapt params value for a given set of transactions
   * and calls
   * @param _transactions - Batch of Railgun transactions to execute
   * @param _random - Random value (shouldn't be reused if resubmitting the same transaction
   * through another relayer or resubmitting on failed transaction - the same nullifier:random
   * should never be reused)
   * @param _minGas - minimum amount of gas to be supplied to transaction
   * @param _requireSuccess - Whether transaction should throw on multicall failure
   * @param _calls - multicall
   */
  function getRelayAdaptParams(
    Transaction[] calldata _transactions,
    uint256 _random,
    bool _requireSuccess,
    uint256 _minGas,
    Call[] calldata _calls
  ) external pure returns (bytes32) {
    // Convenience function to get the expected adaptID parameters value for global
    bytes memory additionalData = abi.encode(
      _random,
      _requireSuccess,
      _minGas,
      _calls
    );

    // Return adapt params value
    return getAdaptParams(_transactions, additionalData);
  }

  /**
   * @notice Executes a batch of Railgun transactions followed by a multicall
   * @param _transactions - Batch of Railgun transactions to execute
   * @param _random - Random value (shouldn't be reused if resubmitting the same transaction
   * through another relayer or resubmitting on failed transaction - the same nullifier:random
   * should never be reused)
   * @param _requireSuccess - Whether transaction should throw on multicall failure
   * @param _minGas - minimum amount of gas to be supplied to transaction
   * @param _calls - multicall
   */
  function relay(
    Transaction[] calldata _transactions,
    uint256 _random,
    bool _requireSuccess,
    uint256 _minGas,
    Call[] calldata _calls
  ) external payable {
    require(gasleft() > _minGas, "Not enough gas supplied");

    if (_transactions.length > 0) {
      // Calculate additionalData parameter for adaptID parameters
      bytes memory additionalData = abi.encode(
        _random,
        _requireSuccess,
        _minGas,
        _calls
      );

      // Executes railgun batch
      railgunBatch(_transactions, additionalData);
    }

    // Execute multicalls
    multicall(_requireSuccess, _calls);

    // To execute a multicall and deposit or send the resulting tokens, encode a call to the relevant function on this
    // contract at the end of your calls array.
  }

  // Allow WBASE contract unwrapping to pay us
  // solhint-disable-next-line avoid-tx-origin no-empty-blocks
  receive() external payable {}
}

File 2 of 17 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `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);

    /**
     * @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);
}

File 3 of 17 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.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;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // 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));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    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");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 4 of 17 : IWBase.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IWBase is IERC20 {
  function deposit() external payable;
  function withdraw(uint256) external;
}

File 5 of 17 : RailgunLogic.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

// OpenZeppelin v4
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { StorageSlot } from "@openzeppelin/contracts/utils/StorageSlot.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { OwnableUpgradeable } from  "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import { SNARK_SCALAR_FIELD, TokenType, WithdrawType, TokenData, CommitmentCiphertext, CommitmentPreimage, Transaction } from "./Globals.sol";

import { Verifier } from "./Verifier.sol";
import { Commitments } from "./Commitments.sol";
import { TokenBlacklist } from "./TokenBlacklist.sol";
import { PoseidonT4 } from "./Poseidon.sol";

/**
 * @title Railgun Logic
 * @author Railgun Contributors
 * @notice Functions to interact with the railgun contract
 * @dev Wallets for Railgun will only need to interact with functions specified in this contract.
 * This contract is written to be run behind a ERC1967-like proxy. Upon deployment of proxy the _data parameter should
 * call the initializeRailgunLogic function.
 */
contract RailgunLogic is Initializable, OwnableUpgradeable, Commitments, TokenBlacklist, Verifier {
  using SafeERC20 for IERC20;

  // NOTE: The order of instantiation MUST stay the same across upgrades
  // add new variables to the bottom of the list
  // See https://docs.openzeppelin.com/learn/upgrading-smart-contracts#upgrading

  // Treasury variables
  address payable public treasury; // Treasury contract
  uint120 private constant BASIS_POINTS = 10000; // Number of basis points that equal 100%
  // % fee in 100ths of a %. 100 = 1%.
  uint120 public depositFee;
  uint120 public withdrawFee;

  // Flat fee in wei that applies to NFT transactions
  uint256 public nftFee;

  // Safety vectors
  mapping(uint256 => bool) public snarkSafetyVector;

  // Treasury events
  event TreasuryChange(address treasury);
  event FeeChange(uint256 depositFee, uint256 withdrawFee, uint256 nftFee);

  // Transaction events
  event CommitmentBatch(
    uint256 treeNumber,
    uint256 startPosition,
    uint256[] hash,
    CommitmentCiphertext[] ciphertext
  );

  event GeneratedCommitmentBatch(
    uint256 treeNumber,
    uint256 startPosition,
    CommitmentPreimage[] commitments,
    uint256[2][] encryptedRandom
  );

  event Nullifiers(uint256 treeNumber, uint256[] nullifier);

  /**
   * @notice Initialize Railgun contract
   * @dev OpenZeppelin initializer ensures this can only be called once
   * This function also calls initializers on inherited contracts
   * @param _treasury - address to send usage fees to
   * @param _depositFee - Deposit fee
   * @param _withdrawFee - Withdraw fee
   * @param _nftFee - Flat fee in wei that applies to NFT transactions
   * @param _owner - governance contract
   */
  function initializeRailgunLogic(
    address payable _treasury,
    uint120 _depositFee,
    uint120 _withdrawFee,
    uint256 _nftFee,
    address _owner
  ) external initializer {
    // Call initializers
    OwnableUpgradeable.__Ownable_init();
    Commitments.initializeCommitments();

    // Set treasury and fee
    changeTreasury(_treasury);
    changeFee(_depositFee, _withdrawFee, _nftFee);

    // Change Owner
    OwnableUpgradeable.transferOwnership(_owner);

    // Set safety vectors
    snarkSafetyVector[11991246288605609459798790887503763024866871101] = true;
    snarkSafetyVector[135932600361240492381964832893378343190771392134] = true;
    snarkSafetyVector[1165567609304106638376634163822860648671860889162] = true;
  }

  /**
   * @notice Change treasury address, only callable by owner (governance contract)
   * @dev This will change the address of the contract we're sending the fees to in the future
   * it won't transfer tokens already in the treasury
   * @param _treasury - Address of new treasury contract
   */
  function changeTreasury(address payable _treasury) public onlyOwner {
    // Do nothing if the new treasury address is same as the old
    if (treasury != _treasury) {
      // Change treasury
      treasury = _treasury;

      // Emit treasury change event
      emit TreasuryChange(_treasury);
    }
  }

  /**
   * @notice Change fee rate for future transactions
   * @param _depositFee - Deposit fee
   * @param _withdrawFee - Withdraw fee
   * @param _nftFee - Flat fee in wei that applies to NFT transactions
   */
  function changeFee(
    uint120 _depositFee,
    uint120 _withdrawFee,
    uint256 _nftFee
  ) public onlyOwner {
    if (
      _depositFee != depositFee
      || _withdrawFee != withdrawFee
      || nftFee != _nftFee
    ) {
      require(_depositFee <= BASIS_POINTS, "RailgunLogic: Deposit Fee exceeds 100%");
      require(_withdrawFee <= BASIS_POINTS, "RailgunLogic: Withdraw Fee exceeds 100%");

      // Change fee
      depositFee = _depositFee;
      withdrawFee = _withdrawFee;
      nftFee = _nftFee;

      // Emit fee change event
      emit FeeChange(_depositFee, _withdrawFee, _nftFee);
    }
  }

  /**
   * @notice Get base and fee amount
   * @param _amount - Amount to calculate for
   * @param _isInclusive - Whether the amount passed in is inclusive of the fee
   * @param _feeBP - Fee basis points
   * @return base, fee
   */
  function getFee(uint136 _amount, bool _isInclusive, uint120 _feeBP) public pure returns (uint120, uint120) {
    // Expand width of amount to uint136 to accomodate full size of (2**120-1)*BASIS_POINTS
    uint136 amountExpanded = _amount;

    // Base is the amount deposited into the railgun contract or withdrawn to the target eth address
    // for deposits and withdraws respectively
    uint136 base;
    // Fee is the amount sent to the treasury
    uint136 fee;

    if (_isInclusive) {
      base = amountExpanded - (amountExpanded * _feeBP) / BASIS_POINTS;
      fee = amountExpanded - base;
    } else {
      base = amountExpanded;
      fee = (BASIS_POINTS * base) / (BASIS_POINTS - _feeBP) - base;
    }

    return (uint120(base), uint120(fee));
  }

  /**
   * @notice Gets token field value from tokenData
   * @param _tokenData - tokenData to calculate token field from
   * @return token field
   */
  function getTokenField(TokenData memory _tokenData) public pure returns (uint256) {
    if (_tokenData.tokenType == TokenType.ERC20) {
      return uint256(uint160(_tokenData.tokenAddress));
    } else if (_tokenData.tokenType == TokenType.ERC721) {
      revert("RailgunLogic: ERC721 not yet supported");
    } else if (_tokenData.tokenType == TokenType.ERC1155) {
      revert("RailgunLogic: ERC1155 not yet supported");
    } else {
      revert("RailgunLogic: Unknown token type");
    }
  }

  /**
   * @notice Hashes a commitment
   * @param _commitmentPreimage - commitment to hash
   * @return commitment hash
   */
  function hashCommitment(CommitmentPreimage memory _commitmentPreimage) public pure returns (uint256) {
    return PoseidonT4.poseidon([
      _commitmentPreimage.npk,
      getTokenField(_commitmentPreimage.token),
      _commitmentPreimage.value
    ]);
  }

  /**
   * @notice Deposits requested amount and token, creates a commitment hash from supplied values and adds to tree
   * @param _notes - list of commitments to deposit
   */
  function generateDeposit(CommitmentPreimage[] calldata _notes, uint256[2][] calldata _encryptedRandom) external {
    // Get notes length
    uint256 notesLength = _notes.length;

    // Insertion and event arrays
    uint256[] memory insertionLeaves = new uint256[](notesLength);
    CommitmentPreimage[] memory generatedCommitments = new CommitmentPreimage[](notesLength);

    require(_notes.length == _encryptedRandom.length, "RailgunLogic: notes and encrypted random length doesn't match");

    for (uint256 notesIter = 0; notesIter < notesLength; notesIter++) {
      // Retrieve note
      CommitmentPreimage calldata note = _notes[notesIter];

      // Check deposit amount is not 0
      require(note.value > 0, "RailgunLogic: Cannot deposit 0 tokens");

      // Check if token is on the blacklist
      require(
        !TokenBlacklist.tokenBlacklist[note.token.tokenAddress],
        "RailgunLogic: Token is blacklisted"
      );

      // Check ypubkey is in snark scalar field
      require(note.npk < SNARK_SCALAR_FIELD, "RailgunLogic: npk out of range");

      // Process deposit request
      if (note.token.tokenType == TokenType.ERC20) {
        // ERC20

        // Get ERC20 interface
        IERC20 token = IERC20(address(uint160(note.token.tokenAddress)));

        // Get base and fee amounts
        (uint120 base, uint120 fee) = getFee(note.value, true, depositFee);

        // Add GeneratedCommitment to event array
        generatedCommitments[notesIter] = CommitmentPreimage({
          npk: note.npk,
          value: base,
          token: note.token
        });

        // Calculate commitment hash
        uint256 hash = hashCommitment(generatedCommitments[notesIter]);

        // Add to insertion array
        insertionLeaves[notesIter] = hash;

        // Transfer base to output address
        token.safeTransferFrom(
          address(msg.sender),
          address(this),
          base
        );

        // Transfer fee to treasury
        token.safeTransferFrom(
          address(msg.sender),
          treasury,
          fee
        );
      } else if (note.token.tokenType == TokenType.ERC721) {
        // ERC721 token
        revert("RailgunLogic: ERC721 not yet supported");
      } else if (note.token.tokenType == TokenType.ERC1155) {
        // ERC1155 token
        revert("RailgunLogic: ERC1155 not yet supported");
      } else {
        // Invalid token type, revert
        revert("RailgunLogic: Unknown token type");
      }
    }

    // Emit GeneratedCommitmentAdded events (for wallets) for the commitments
    emit GeneratedCommitmentBatch(Commitments.treeNumber, Commitments.nextLeafIndex, generatedCommitments, _encryptedRandom);

    // Push new commitments to merkle tree
    Commitments.insertLeaves(insertionLeaves);
  }

  /**
   * @notice Safety check for badly behaving code
   */
  function checkSafetyVectors() external {
    // Set safety bit
    StorageSlot.getBooleanSlot(0x8dea8703c3cf94703383ce38a9c894669dccd4ca8e65ddb43267aa0248711450).value = true;

    // Setup behaviour check
    bool result = false;

    // Execute behaviour check
    // solhint-disable-next-line no-inline-assembly
    assembly {
      mstore(0, caller())
      mstore(32, snarkSafetyVector.slot)
      let hash := keccak256(0, 64)
      result := sload(hash)
    }

    require(result, "RailgunLogic: Unsafe vectors");
  }

  /**
   * @notice Adds safety vector
   */
  function addVector(uint256 vector) external onlyOwner {
    snarkSafetyVector[vector] = true;
  }

  /**
   * @notice Removes safety vector
   */
  function removeVector(uint256 vector) external onlyOwner {
    snarkSafetyVector[vector] = false;
  }

  /**
   * @notice Execute batch of Railgun snark transactions
   * @param _transactions - Transactions to execute
   */
  function transact(
    Transaction[] calldata _transactions
  ) external {
    // Accumulate total number of insertion commitments
    uint256 insertionCommitmentCount = 0;

    // Loop through each transaction
    uint256 transactionLength = _transactions.length;
    for(uint256 transactionIter = 0; transactionIter < transactionLength; transactionIter++) {
      // Retrieve transaction
      Transaction calldata transaction = _transactions[transactionIter];

      // If adaptContract is not zero check that it matches the caller
      require(
        transaction.boundParams.adaptContract == address (0) || transaction.boundParams.adaptContract == msg.sender,
        "AdaptID doesn't match caller contract"
      );

      // Retrieve treeNumber
      uint256 treeNumber = transaction.boundParams.treeNumber;

      // Check merkle root is valid
      require(Commitments.rootHistory[treeNumber][transaction.merkleRoot], "RailgunLogic: Invalid Merkle Root");

      // Loop through each nullifier
      uint256 nullifiersLength = transaction.nullifiers.length;
      for (uint256 nullifierIter = 0; nullifierIter < nullifiersLength; nullifierIter++) {
        // Retrieve nullifier
        uint256 nullifier = transaction.nullifiers[nullifierIter];

        // Check if nullifier has been seen before
        require(!Commitments.nullifiers[treeNumber][nullifier], "RailgunLogic: Nullifier already seen");

        // Push to nullifiers
        Commitments.nullifiers[treeNumber][nullifier] = true;
      }

      // Emit nullifiers event
      emit Nullifiers(treeNumber, transaction.nullifiers);

      // Verify proof
      require(
        Verifier.verify(transaction),
        "RailgunLogic: Invalid SNARK proof"
      );

      if (transaction.boundParams.withdraw != WithdrawType.NONE) {
        // Last output is marked as withdraw, process
        // Hash the withdraw commitment preimage
        uint256 commitmentHash = hashCommitment(transaction.withdrawPreimage);

        // Make sure the commitment hash matches the withdraw transaction output
        require(
          commitmentHash == transaction.commitments[transaction.commitments.length - 1],
          "RailgunLogic: Withdraw commitment preimage is invalid"
        );

        // Fetch output address
        address output = address(uint160(transaction.withdrawPreimage.npk));

        // Check if we've been asked to override the withdraw destination
        if(transaction.overrideOutput != address(0)) {
          // Withdraw must == 2 and msg.sender must be the original recepient to change the output destination
          require(
            msg.sender == output && transaction.boundParams.withdraw == WithdrawType.REDIRECT,
            "RailgunLogic: Can't override destination address"
          );

          // Override output address
          output = transaction.overrideOutput;
        }

        // Process withdrawal request
        if (transaction.withdrawPreimage.token.tokenType == TokenType.ERC20) {
          // ERC20

          // Get ERC20 interface
          IERC20 token = IERC20(address(uint160(transaction.withdrawPreimage.token.tokenAddress)));

          // Get base and fee amounts
          (uint120 base, uint120 fee) = getFee(transaction.withdrawPreimage.value, true, withdrawFee);

          // Transfer base to output address
          token.safeTransfer(
            output,
            base
          );

          // Transfer fee to treasury
          token.safeTransfer(
            treasury,
            fee
          );
        } else if (transaction.withdrawPreimage.token.tokenType == TokenType.ERC721) {
          // ERC721 token
          revert("RailgunLogic: ERC721 not yet supported");
        } else if (transaction.withdrawPreimage.token.tokenType == TokenType.ERC1155) {
          // ERC1155 token
          revert("RailgunLogic: ERC1155 not yet supported");
        } else {
          // Invalid token type, revert
          revert("RailgunLogic: Unknown token type");
        }

        // Ensure ciphertext length matches the commitments length (minus 1 for withdrawn output)
        require(
          transaction.boundParams.commitmentCiphertext.length == transaction.commitments.length - 1,
          "RailgunLogic: Ciphertexts and commitments count mismatch"
        );

        // Increment insertion commitment count (minus 1 for withdrawn output)
        insertionCommitmentCount += transaction.commitments.length - 1;
      } else {
        // Ensure ciphertext length matches the commitments length
        require(
          transaction.boundParams.commitmentCiphertext.length == transaction.commitments.length,
          "RailgunLogic: Ciphertexts and commitments count mismatch"
        );

        // Increment insertion commitment count
        insertionCommitmentCount += transaction.commitments.length;
      }
    }

    // Create insertion array
    uint256[] memory hashes = new uint256[](insertionCommitmentCount);

    // Create ciphertext array
    CommitmentCiphertext[] memory ciphertext = new CommitmentCiphertext[](insertionCommitmentCount);

    // Track insert position
    uint256 insertPosition = 0;

    // Loop through each transaction and accumulate commitments
    for(uint256 transactionIter = 0; transactionIter < _transactions.length; transactionIter++) {
      // Retrieve transaction
      Transaction calldata transaction = _transactions[transactionIter];

      // Loop through commitments and push to array
      uint256 commitmentLength = transaction.boundParams.commitmentCiphertext.length;
      for(uint256 commitmentIter = 0; commitmentIter < commitmentLength; commitmentIter++) {
        // Push commitment hash to array
        hashes[insertPosition] = transaction.commitments[commitmentIter];

        // Push ciphertext to array
        ciphertext[insertPosition] = transaction.boundParams.commitmentCiphertext[commitmentIter];

        // Increment insert position
        insertPosition++;
      }
    }

    // Emit commitment state update
    emit CommitmentBatch(Commitments.treeNumber, Commitments.nextLeafIndex, hashes, ciphertext);

    // Push new commitments to merkle tree after event due to insertLeaves causing side effects
    Commitments.insertLeaves(hashes);
  }
}

File 6 of 17 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.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
     * ====
     *
     * [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://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 7 of 17 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly {
            r.slot := slot
        }
    }
}

File 8 of 17 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

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.
 *
 * 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 initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 9 of 17 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing 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);
    }

    /**
     * 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;
}

File 10 of 17 : Globals.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

// Constants
uint256 constant SNARK_SCALAR_FIELD = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
uint256 constant CIPHERTEXT_WORDS = 4;

enum TokenType { ERC20, ERC721, ERC1155 }

// Transaction token data
struct TokenData {
  TokenType tokenType;
  address tokenAddress;
  uint256 tokenSubID;
}

// Commitment ciphertext
struct CommitmentCiphertext {
  uint256[CIPHERTEXT_WORDS] ciphertext; // Ciphertext order: iv & tag (16 bytes each), recipient master public key (packedPoint) (uint256), packedField (uint256) {sign, random, amount}, token (uint256)
  uint256[2] ephemeralKeys; // Sender first, receipient second (packed points 32 bytes each)
  uint256[] memo;
}

enum WithdrawType { NONE, WITHDRAW, REDIRECT }

// Transaction bound parameters
struct BoundParams {
  uint16 treeNumber;
  WithdrawType withdraw;
  address adaptContract;
  bytes32 adaptParams;
  // For withdraws do not include an element in ciphertext array
  // Ciphertext array length = commitments - withdraws
  CommitmentCiphertext[] commitmentCiphertext;
}

// Transaction struct
struct Transaction {
  SnarkProof proof;
  uint256 merkleRoot;
  uint256[] nullifiers;
  uint256[] commitments;
  BoundParams boundParams;
  CommitmentPreimage withdrawPreimage;
  address overrideOutput; // Only allowed if original destination == msg.sender & boundParams.withdraw == 2
}

// Commitment hash preimage
struct CommitmentPreimage {
  uint256 npk; // Poseidon(mpk, random), mpk = Poseidon(spending public key, nullifier)
  TokenData token; // Token field
  uint120 value; // Note value
}

struct G1Point {
  uint256 x;
  uint256 y;
}

// Encoding of field elements is: X[0] * z + X[1]
struct G2Point {
  uint256[2] x;
  uint256[2] y;
}

// Verification key for SNARK
struct VerifyingKey {
  string artifactsIPFSHash;
  G1Point alpha1;
  G2Point beta2;
  G2Point gamma2;
  G2Point delta2;
  G1Point[] ic;
}

// Snark proof for transaction
struct SnarkProof {
  G1Point a;
  G2Point b;
  G1Point c;
}

File 11 of 17 : Verifier.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

// OpenZeppelin v4
import { OwnableUpgradeable } from  "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import { SnarkProof, Transaction, BoundParams, VerifyingKey, SNARK_SCALAR_FIELD } from "./Globals.sol";

import { Snark } from "./Snark.sol";

/**
 * @title Verifier
 * @author Railgun Contributors
 * @notice Verifies snark proof
 * @dev Functions in this contract statelessly verify proofs, nullifiers and adaptID should be checked in RailgunLogic.
 */
contract Verifier is OwnableUpgradeable {
  // NOTE: The order of instantiation MUST stay the same across upgrades
  // add new variables to the bottom of the list and decrement __gap
  // See https://docs.openzeppelin.com/learn/upgrading-smart-contracts#upgrading

  // Snark bypass address, can't be address(0) as many burn prevention mechanisms will disallow transfers to 0
  // Use 0x000000000000000000000000000000000000dEaD as an alternative
  address constant public SNARK_BYPASS = 0x000000000000000000000000000000000000dEaD;

  // Verifying key set event
  event VerifyingKeySet(uint256 nullifiers, uint256 commitments, VerifyingKey verifyingKey);

  // Nullifiers => Commitments => Verification Key
  mapping(uint256 => mapping(uint256 => VerifyingKey)) private verificationKeys;

  /**
   * @notice Sets verification key
   * @param _nullifiers - number of nullifiers this verification key is for
   * @param _commitments - number of commitmets out this verification key is for
   * @param _verifyingKey - verifyingKey to set
   */
  function setVerificationKey(
    uint256 _nullifiers,
    uint256 _commitments,
    VerifyingKey calldata _verifyingKey
  ) public onlyOwner {
    verificationKeys[_nullifiers][_commitments] = _verifyingKey;

    emit VerifyingKeySet(_nullifiers, _commitments, _verifyingKey);
  }

  /**
   * @notice Gets verification key
   * @param _nullifiers - number of nullifiers this verification key is for
   * @param _commitments - number of commitmets out this verification key is for
   */
  function getVerificationKey(
    uint256 _nullifiers,
    uint256 _commitments
  ) public view returns (VerifyingKey memory) {
    // Manually add getter so dynamic IC array is included in response
    return verificationKeys[_nullifiers][_commitments];
  }

  /**
   * @notice Calculates hash of transaction bound params for snark verification
   * @param _boundParams - bound parameters
   * @return bound parameters hash
   */
  function hashBoundParams(BoundParams calldata _boundParams) public pure returns (uint256) {
    return uint256(keccak256(abi.encode(
      _boundParams
    ))) % SNARK_SCALAR_FIELD;
  }

  /**
   * @notice Verifies inputs against a verification key
   * @param _verifyingKey - verifying key to verify with
   * @param _proof - proof to verify
   * @param _inputs - input to verify
   * @return proof validity
   */
  function verifyProof(
    VerifyingKey memory _verifyingKey,
    SnarkProof calldata _proof,
    uint256[] memory _inputs
  ) public view returns (bool) {
    return Snark.verify(
      _verifyingKey,
      _proof,
      _inputs
    );
  }

  /**
   * @notice Verifies a transaction
   * @param _transaction to verify
   * @return transaction validity
   */
  function verify(Transaction calldata _transaction) public view returns (bool) {
    uint256 nullifiersLength = _transaction.nullifiers.length;
    uint256 commitmentsLength = _transaction.commitments.length;

    // Retrieve verification key
    VerifyingKey memory verifyingKey = verificationKeys
      [nullifiersLength]
      [commitmentsLength];

    // Check if verifying key is set
    require(verifyingKey.alpha1.x != 0, "Verifier: Key not set");

    // Calculate inputs
    uint256[] memory inputs = new uint256[](2 + nullifiersLength + commitmentsLength);
    inputs[0] = _transaction.merkleRoot;
    
    // Hash bound parameters
    inputs[1] = hashBoundParams(_transaction.boundParams);

    // Loop through nullifiers and add to inputs
    for (uint i = 0; i < nullifiersLength; i++) {
      inputs[2 + i] = _transaction.nullifiers[i];
    }

    // Loop through commitments and add to inputs
    for (uint i = 0; i < commitmentsLength; i++) {
      inputs[2 + nullifiersLength + i] = _transaction.commitments[i];
    }
    
    // Verify snark proof
    bool validity = verifyProof(
      verifyingKey,
      _transaction.proof,
      inputs
    );

    // Always return true in gas estimation transaction
    // This is so relayer fees can be calculated without needing to compute a proof
    // solhint-disable-next-line avoid-tx-origin
    if (tx.origin == SNARK_BYPASS) {
      return true;
    } else {
      return validity;
    }
  }

  uint256[49] private __gap;
}

File 12 of 17 : Commitments.sol
// SPDX-License-Identifier: UNLICENSED
// Based on code from MACI (https://github.com/appliedzkp/maci/blob/7f36a915244a6e8f98bacfe255f8bd44193e7919/contracts/sol/IncrementalMerkleTree.sol)
pragma solidity ^0.8.0;
pragma abicoder v2;

// OpenZeppelin v4
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import { SNARK_SCALAR_FIELD } from "./Globals.sol";

import { PoseidonT3 } from "./Poseidon.sol";

/**
 * @title Commitments
 * @author Railgun Contributors
 * @notice Batch Incremental Merkle Tree for commitments
 * @dev Publically accessible functions to be put in RailgunLogic
 * Relevent external contract calls should be in those functions, not here
 */
contract Commitments is Initializable {
  // NOTE: The order of instantiation MUST stay the same across upgrades
  // add new variables to the bottom of the list and decrement the __gap
  // variable at the end of this file
  // See https://docs.openzeppelin.com/learn/upgrading-smart-contracts#upgrading

  // Commitment nullifiers (treenumber -> nullifier -> seen)
  mapping(uint256 => mapping(uint256 => bool)) public nullifiers;

  // The tree depth
  uint256 internal constant TREE_DEPTH = 16;

  // Tree zero value
  uint256 public constant ZERO_VALUE = uint256(keccak256("Railgun")) % SNARK_SCALAR_FIELD;

  // Next leaf index (number of inserted leaves in the current tree)
  uint256 internal nextLeafIndex;

  // The Merkle root
  uint256 public merkleRoot;

  // Store new tree root to quickly migrate to a new tree
  uint256 private newTreeRoot;

  // Tree number
  uint256 public treeNumber;

  // The Merkle path to the leftmost leaf upon initialisation. It *should
  // not* be modified after it has been set by the initialize function.
  // Caching these values is essential to efficient appends.
  uint256[TREE_DEPTH] public zeros;

  // Right-most elements at each level
  // Used for efficient upodates of the merkle tree
  uint256[TREE_DEPTH] private filledSubTrees;

  // Whether the contract has already seen a particular Merkle tree root
  // treeNumber -> root -> seen
  mapping(uint256 => mapping(uint256 => bool)) public rootHistory;


  /**
   * @notice Calculates initial values for Merkle Tree
   * @dev OpenZeppelin initializer ensures this can only be called once
   */
  function initializeCommitments() internal onlyInitializing {
    /*
    To initialise the Merkle tree, we need to calculate the Merkle root
    assuming that each leaf is the zero value.
    H(H(a,b), H(c,d))
      /          \
    H(a,b)     H(c,d)
    /   \       /  \
    a    b     c    d
    `zeros` and `filledSubTrees` will come in handy later when we do
    inserts or updates. e.g when we insert a value in index 1, we will
    need to look up values from those arrays to recalculate the Merkle
    root.
    */

    // Calculate zero values
    zeros[0] = ZERO_VALUE;

    // Store the current zero value for the level we just calculated it for
    uint256 currentZero = ZERO_VALUE;

    // Loop through each level
    for (uint256 i = 0; i < TREE_DEPTH; i++) {
      // Push it to zeros array
      zeros[i] = currentZero;

      // Calculate the zero value for this level
      currentZero = hashLeftRight(currentZero, currentZero);
    }

    // Set merkle root and store root to quickly retrieve later
    newTreeRoot = merkleRoot = currentZero;
    rootHistory[treeNumber][currentZero] = true;
  }

  /**
   * @notice Hash 2 uint256 values
   * @param _left - Left side of hash
   * @param _right - Right side of hash
   * @return hash result
   */
  function hashLeftRight(uint256 _left, uint256 _right) public pure returns (uint256) {
    return PoseidonT3.poseidon([
      _left,
      _right
    ]);
  }

  /**
   * @notice Calculates initial values for Merkle Tree
   * @dev Insert leaves into the current merkle tree
   * Note: this function INTENTIONALLY causes side effects to save on gas.
   * _leafHashes and _count should never be reused.
   * @param _leafHashes - array of leaf hashes to be added to the merkle tree
   */
  function insertLeaves(uint256[] memory _leafHashes) internal {
    /*
    Loop through leafHashes at each level, if the leaf is on the left (index is even)
    then hash with zeros value and update subtree on this level, if the leaf is on the
    right (index is odd) then hash with subtree value. After calculating each hash
    push to relevent spot on leafHashes array. For gas efficiency we reuse the same
    array and use the count variable to loop to the right index each time.

    Example of updating a tree of depth 4 with elements 13, 14, and 15
    [1,7,15]    {1}                    1
                                       |
    [3,7,15]    {1}          2-------------------3
                             |                   |
    [6,7,15]    {2}     4---------5         6---------7
                       / \       / \       / \       / \
    [13,14,15]  {3}  08   09   10   11   12   13   14   15
    [] = leafHashes array
    {} = count variable
    */

    // Get initial count
    uint256 count = _leafHashes.length;

    // Create new tree if current one can't contain new leaves
    // We insert all new commitment into a new tree to ensure they can be spent in the same transaction
    if ((nextLeafIndex + count) >= (2 ** TREE_DEPTH)) { newTree(); }

    // Current index is the index at each level to insert the hash
    uint256 levelInsertionIndex = nextLeafIndex;

    // Update nextLeafIndex
    nextLeafIndex += count;

    // Variables for starting point at next tree level
    uint256 nextLevelHashIndex;
    uint256 nextLevelStartIndex;

    // Loop through each level of the merkle tree and update
    for (uint256 level = 0; level < TREE_DEPTH; level++) {
      // Calculate the index to start at for the next level
      // >> is equivilent to / 2 rounded down
      nextLevelStartIndex = levelInsertionIndex >> 1;

      uint256 insertionElement = 0;

      // If we're on the right, hash and increment to get on the left
      if (levelInsertionIndex % 2 == 1) {
        // Calculate index to insert hash into leafHashes[]
        // >> is equivilent to / 2 rounded down
        nextLevelHashIndex = (levelInsertionIndex >> 1) - nextLevelStartIndex;

        // Calculate the hash for the next level
        _leafHashes[nextLevelHashIndex] = hashLeftRight(filledSubTrees[level], _leafHashes[insertionElement]);

        // Increment
        insertionElement += 1;
        levelInsertionIndex += 1;
      }

      // We'll always be on the left side now
      for (insertionElement; insertionElement < count; insertionElement += 2) {
        uint256 right;

        // Calculate right value
        if (insertionElement < count - 1) {
          right = _leafHashes[insertionElement + 1];
        } else {
          right = zeros[level];
        }

        // If we've created a new subtree at this level, update
        if (insertionElement == count - 1 || insertionElement == count - 2) {
          filledSubTrees[level] = _leafHashes[insertionElement];
        }

        // Calculate index to insert hash into leafHashes[]
        // >> is equivilent to / 2 rounded down
        nextLevelHashIndex = (levelInsertionIndex >> 1) - nextLevelStartIndex;

        // Calculate the hash for the next level
        _leafHashes[nextLevelHashIndex] = hashLeftRight(_leafHashes[insertionElement], right);

        // Increment level insertion index
        levelInsertionIndex += 2;
      }

      // Get starting levelInsertionIndex value for next level
      levelInsertionIndex = nextLevelStartIndex;

      // Get count of elements for next level
      count = nextLevelHashIndex + 1;
    }
 
    // Update the Merkle tree root
    merkleRoot = _leafHashes[0];
    rootHistory[treeNumber][merkleRoot] = true;
  }

  /**
   * @notice Creates new merkle tree
   */
  function newTree() internal {
    // Restore merkleRoot to newTreeRoot
    merkleRoot = newTreeRoot;

    // Existing values in filledSubtrees will never be used so overwriting them is unnecessary

    // Reset next leaf index to 0
    nextLeafIndex = 0;

    // Increment tree number
    treeNumber++;
  }

  uint256[10] private __gap;
}

File 13 of 17 : TokenBlacklist.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

// OpenZeppelin v4
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/**
 * @title Token Blacklist
 * @author Railgun Contributors
 * @notice Blacklist of tokens that are incompatible with the protocol
 * @dev Tokens on this blacklist can't be deposited to railgun.
 * Tokens on this blacklist will still be transferrable
 * internally (as internal transactions have a shielded token ID) and
 * withdrawable (to prevent user funds from being locked)
 * THIS WILL ALWAYS BE A NON-EXHAUSTIVE LIST, DO NOT RELY ON IT BLOCKING ALL
 * INCOMPATIBLE TOKENS
 */
contract TokenBlacklist is OwnableUpgradeable {
  // Events for offchain building of blacklist index
  event AddToBlacklist(address indexed token);
  event RemoveFromBlacklist(address indexed token);

  // NOTE: The order of instantiation MUST stay the same across upgrades
  // add new variables to the bottom of the list and decrement the __gap
  // variable at the end of this file
  // See https://docs.openzeppelin.com/learn/upgrading-smart-contracts#upgrading
  mapping(address => bool) public tokenBlacklist;

  /**
   * @notice Adds tokens to blacklist, only callable by owner (governance contract)
   * @dev This function will ignore tokens that are already in the blacklist
   * no events will be emitted in this case
   * @param _tokens - List of tokens to add to blacklist
   */
  function addToBlacklist(address[] calldata _tokens) external onlyOwner {
    // Loop through token array
    for (uint256 i = 0; i < _tokens.length; i++) {
      // Don't do anything if the token is already blacklisted
      if (!tokenBlacklist[_tokens[i]]) {
          // Set token address in blacklist map to true
        tokenBlacklist[_tokens[i]] = true;

        // Emit event for building index of blacklisted tokens offchain
        emit AddToBlacklist(_tokens[i]);
      }
    }
  }

  /**
   * @notice Removes token from blacklist, only callable by owner (governance contract)
   * @dev This function will ignore tokens that aren't in the blacklist
   * no events will be emitted in this case
   * @param _tokens - List of tokens to remove from blacklist
   */
  function removeFromBlacklist(address[] calldata _tokens) external onlyOwner {
    // Loop through token array
    for (uint256 i = 0; i < _tokens.length; i++) {
      // Don't do anything if the token isn't blacklisted
      if (tokenBlacklist[_tokens[i]]) {
        // Set token address in blacklisted map to false (default value)
        delete tokenBlacklist[_tokens[i]];

        // Emit event for building index of blacklisted tokens offchain
        emit RemoveFromBlacklist(_tokens[i]);
      }
    }
  }

  uint256[49] private __gap;
}

File 14 of 17 : Poseidon.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

/*
Functions here are stubs for the solidity compiler to generate the right interface.
The deployed library is generated bytecode from the circomlib toolchain
*/

library PoseidonT3 {
  // solhint-disable-next-line no-empty-blocks
  function poseidon(uint256[2] memory input) public pure returns (uint256) {}
}

library PoseidonT4 {
  // solhint-disable-next-line no-empty-blocks
  function poseidon(uint256[3] memory input) public pure returns (uint256) {}
}

File 15 of 17 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.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
     * ====
     *
     * [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://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 16 of 17 : ContextUpgradeable.sol
// 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;
    }

    /**
     * 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;
}

File 17 of 17 : Snark.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
pragma abicoder v2;

import { G1Point, G2Point, VerifyingKey, SnarkProof, SNARK_SCALAR_FIELD } from "./Globals.sol";

library Snark {
  uint256 private constant PRIME_Q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
  uint256 private constant PAIRING_INPUT_SIZE = 24;
  uint256 private constant PAIRING_INPUT_WIDTH = 768; // PAIRING_INPUT_SIZE * 32

  /**
   * @notice Computes the negation of point p
   * @dev The negation of p, i.e. p.plus(p.negate()) should be zero.
   * @return result
   */
  function negate(G1Point memory p) internal pure returns (G1Point memory) {
    if (p.x == 0 && p.y == 0) return G1Point(0, 0);

    // check for valid points y^2 = x^3 +3 % PRIME_Q
    uint256 rh = mulmod(p.x, p.x, PRIME_Q); //x^2
    rh = mulmod(rh, p.x, PRIME_Q); //x^3
    rh = addmod(rh, 3, PRIME_Q); //x^3 + 3
    uint256 lh = mulmod(p.y, p.y, PRIME_Q); //y^2
    require(lh == rh, "Snark: Invalid negation");

    return G1Point(p.x, PRIME_Q - (p.y % PRIME_Q));
    }

  /**
   * @notice Adds 2 G1 points
   * @return result
   */
  function add(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory) {
    // Format inputs
    uint256[4] memory input;
    input[0] = p1.x;
    input[1] = p1.y;
    input[2] = p2.x;
    input[3] = p2.y;

    // Setup output variables
    bool success;
    G1Point memory result;

    // Add points
    // solhint-disable-next-line no-inline-assembly
    assembly {
      success := staticcall(sub(gas(), 2000), 6, input, 0x80, result, 0x40)
    }

    // Check if operation succeeded
    require(success, "Snark: Add Failed");

    return result;
  }

  /**
   * @notice Scalar multiplies two G1 points p, s
   * @dev The product of a point on G1 and a scalar, i.e.
   * p == p.scalar_mul(1) and p.plus(p) == p.scalar_mul(2) for all
   * points p.
   * @return r - result
   */
  function scalarMul(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;
    
    // solhint-disable-next-line no-inline-assembly
    assembly {
      success := staticcall(sub(gas(), 2000), 7, input, 0x60, r, 0x40)
    }

    // Check multiplication succeeded
    require(success, "Snark: Scalar Multiplication Failed");
  }

  /**
   * @notice Performs pairing check on points
   * @dev 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.
   * @return if pairing check passed
   */
  function pairing(
    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) {
    uint256[PAIRING_INPUT_SIZE] memory input = [
      _a1.x,
      _a1.y,
      _a2.x[0],
      _a2.x[1],
      _a2.y[0],
      _a2.y[1],
      _b1.x,
      _b1.y,
      _b2.x[0],
      _b2.x[1],
      _b2.y[0],
      _b2.y[1],
      _c1.x,
      _c1.y,
      _c2.x[0],
      _c2.x[1],
      _c2.y[0],
      _c2.y[1],
      _d1.x,
      _d1.y,
      _d2.x[0],
      _d2.x[1],
      _d2.y[0],
      _d2.y[1]
    ];

    uint256[1] memory out;
    bool success;

    // solhint-disable-next-line no-inline-assembly
    assembly {
      success := staticcall(
        sub(gas(), 2000),
        8,
        input,
        PAIRING_INPUT_WIDTH,
        out,
        0x20
      )
    }

    // Check if operation succeeded
    require(success, "Snark: Pairing Verification Failed");

    return out[0] != 0;
  }

  /**
    * @notice Verifies snark proof against proving key
    * @param _vk - Verification Key
    * @param _proof - snark proof
    * @param _inputs - inputs
    */
  function verify(
    VerifyingKey memory _vk,
    SnarkProof memory _proof,
    uint256[] memory _inputs
  ) internal view returns (bool) {
    // Compute the linear combination vkX
    G1Point memory vkX = G1Point(0, 0);
    
    // Loop through every input
    for (uint i = 0; i < _inputs.length; i++) {
      // Make sure inputs are less than SNARK_SCALAR_FIELD
      require(_inputs[i] < SNARK_SCALAR_FIELD, "Snark: Input > SNARK_SCALAR_FIELD");

      // Add to vkX point
      vkX = add(vkX, scalarMul(_vk.ic[i + 1], _inputs[i]));
  }

    // Compute final vkX point
    vkX = add(vkX, _vk.ic[0]);

    // Verify pairing and return
    return pairing(
      negate(_proof.a),
      _proof.b,
      _vk.alpha1,
      _vk.beta2,
      vkX,
      _vk.gamma2,
      _proof.c,
      _vk.delta2
    );
  }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 1600
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract RailgunLogic","name":"_railgun","type":"address"},{"internalType":"contract IWBase","name":"_wbase","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"components":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"string","name":"returnData","type":"string"}],"indexed":false,"internalType":"struct RelayAdapt.Result[]","name":"callResults","type":"tuple[]"}],"name":"CallResult","type":"event"},{"inputs":[],"name":"VERIFICATION_BYPASS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"enum TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenSubID","type":"uint256"}],"internalType":"struct TokenData[]","name":"_deposits","type":"tuple[]"},{"internalType":"uint256[2]","name":"_encryptedRandom","type":"uint256[2]"},{"internalType":"uint256","name":"_npk","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"a","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"x","type":"uint256[2]"},{"internalType":"uint256[2]","name":"y","type":"uint256[2]"}],"internalType":"struct G2Point","name":"b","type":"tuple"},{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"c","type":"tuple"}],"internalType":"struct SnarkProof","name":"proof","type":"tuple"},{"internalType":"uint256","name":"merkleRoot","type":"uint256"},{"internalType":"uint256[]","name":"nullifiers","type":"uint256[]"},{"internalType":"uint256[]","name":"commitments","type":"uint256[]"},{"components":[{"internalType":"uint16","name":"treeNumber","type":"uint16"},{"internalType":"enum WithdrawType","name":"withdraw","type":"uint8"},{"internalType":"address","name":"adaptContract","type":"address"},{"internalType":"bytes32","name":"adaptParams","type":"bytes32"},{"components":[{"internalType":"uint256[4]","name":"ciphertext","type":"uint256[4]"},{"internalType":"uint256[2]","name":"ephemeralKeys","type":"uint256[2]"},{"internalType":"uint256[]","name":"memo","type":"uint256[]"}],"internalType":"struct CommitmentCiphertext[]","name":"commitmentCiphertext","type":"tuple[]"}],"internalType":"struct BoundParams","name":"boundParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"npk","type":"uint256"},{"components":[{"internalType":"enum TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenSubID","type":"uint256"}],"internalType":"struct TokenData","name":"token","type":"tuple"},{"internalType":"uint120","name":"value","type":"uint120"}],"internalType":"struct CommitmentPreimage","name":"withdrawPreimage","type":"tuple"},{"internalType":"address","name":"overrideOutput","type":"address"}],"internalType":"struct Transaction[]","name":"_transactions","type":"tuple[]"},{"internalType":"bytes","name":"_additionalData","type":"bytes"}],"name":"getAdaptParams","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"a","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"x","type":"uint256[2]"},{"internalType":"uint256[2]","name":"y","type":"uint256[2]"}],"internalType":"struct G2Point","name":"b","type":"tuple"},{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"c","type":"tuple"}],"internalType":"struct SnarkProof","name":"proof","type":"tuple"},{"internalType":"uint256","name":"merkleRoot","type":"uint256"},{"internalType":"uint256[]","name":"nullifiers","type":"uint256[]"},{"internalType":"uint256[]","name":"commitments","type":"uint256[]"},{"components":[{"internalType":"uint16","name":"treeNumber","type":"uint16"},{"internalType":"enum WithdrawType","name":"withdraw","type":"uint8"},{"internalType":"address","name":"adaptContract","type":"address"},{"internalType":"bytes32","name":"adaptParams","type":"bytes32"},{"components":[{"internalType":"uint256[4]","name":"ciphertext","type":"uint256[4]"},{"internalType":"uint256[2]","name":"ephemeralKeys","type":"uint256[2]"},{"internalType":"uint256[]","name":"memo","type":"uint256[]"}],"internalType":"struct CommitmentCiphertext[]","name":"commitmentCiphertext","type":"tuple[]"}],"internalType":"struct BoundParams","name":"boundParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"npk","type":"uint256"},{"components":[{"internalType":"enum TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenSubID","type":"uint256"}],"internalType":"struct TokenData","name":"token","type":"tuple"},{"internalType":"uint120","name":"value","type":"uint120"}],"internalType":"struct CommitmentPreimage","name":"withdrawPreimage","type":"tuple"},{"internalType":"address","name":"overrideOutput","type":"address"}],"internalType":"struct Transaction[]","name":"_transactions","type":"tuple[]"},{"internalType":"uint256","name":"_random","type":"uint256"},{"internalType":"bool","name":"_requireSuccess","type":"bool"},{"internalType":"uint256","name":"_minGas","type":"uint256"},{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RelayAdapt.Call[]","name":"_calls","type":"tuple[]"}],"name":"getRelayAdaptParams","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"railgun","outputs":[{"internalType":"contract RailgunLogic","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"a","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"x","type":"uint256[2]"},{"internalType":"uint256[2]","name":"y","type":"uint256[2]"}],"internalType":"struct G2Point","name":"b","type":"tuple"},{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"c","type":"tuple"}],"internalType":"struct SnarkProof","name":"proof","type":"tuple"},{"internalType":"uint256","name":"merkleRoot","type":"uint256"},{"internalType":"uint256[]","name":"nullifiers","type":"uint256[]"},{"internalType":"uint256[]","name":"commitments","type":"uint256[]"},{"components":[{"internalType":"uint16","name":"treeNumber","type":"uint16"},{"internalType":"enum WithdrawType","name":"withdraw","type":"uint8"},{"internalType":"address","name":"adaptContract","type":"address"},{"internalType":"bytes32","name":"adaptParams","type":"bytes32"},{"components":[{"internalType":"uint256[4]","name":"ciphertext","type":"uint256[4]"},{"internalType":"uint256[2]","name":"ephemeralKeys","type":"uint256[2]"},{"internalType":"uint256[]","name":"memo","type":"uint256[]"}],"internalType":"struct CommitmentCiphertext[]","name":"commitmentCiphertext","type":"tuple[]"}],"internalType":"struct BoundParams","name":"boundParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"npk","type":"uint256"},{"components":[{"internalType":"enum TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenSubID","type":"uint256"}],"internalType":"struct TokenData","name":"token","type":"tuple"},{"internalType":"uint120","name":"value","type":"uint120"}],"internalType":"struct CommitmentPreimage","name":"withdrawPreimage","type":"tuple"},{"internalType":"address","name":"overrideOutput","type":"address"}],"internalType":"struct Transaction[]","name":"_transactions","type":"tuple[]"},{"internalType":"bytes","name":"_additionalData","type":"bytes"}],"name":"railgunBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"a","type":"tuple"},{"components":[{"internalType":"uint256[2]","name":"x","type":"uint256[2]"},{"internalType":"uint256[2]","name":"y","type":"uint256[2]"}],"internalType":"struct G2Point","name":"b","type":"tuple"},{"components":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"internalType":"struct G1Point","name":"c","type":"tuple"}],"internalType":"struct SnarkProof","name":"proof","type":"tuple"},{"internalType":"uint256","name":"merkleRoot","type":"uint256"},{"internalType":"uint256[]","name":"nullifiers","type":"uint256[]"},{"internalType":"uint256[]","name":"commitments","type":"uint256[]"},{"components":[{"internalType":"uint16","name":"treeNumber","type":"uint16"},{"internalType":"enum WithdrawType","name":"withdraw","type":"uint8"},{"internalType":"address","name":"adaptContract","type":"address"},{"internalType":"bytes32","name":"adaptParams","type":"bytes32"},{"components":[{"internalType":"uint256[4]","name":"ciphertext","type":"uint256[4]"},{"internalType":"uint256[2]","name":"ephemeralKeys","type":"uint256[2]"},{"internalType":"uint256[]","name":"memo","type":"uint256[]"}],"internalType":"struct CommitmentCiphertext[]","name":"commitmentCiphertext","type":"tuple[]"}],"internalType":"struct BoundParams","name":"boundParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"npk","type":"uint256"},{"components":[{"internalType":"enum TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenSubID","type":"uint256"}],"internalType":"struct TokenData","name":"token","type":"tuple"},{"internalType":"uint120","name":"value","type":"uint120"}],"internalType":"struct CommitmentPreimage","name":"withdrawPreimage","type":"tuple"},{"internalType":"address","name":"overrideOutput","type":"address"}],"internalType":"struct Transaction[]","name":"_transactions","type":"tuple[]"},{"internalType":"uint256","name":"_random","type":"uint256"},{"internalType":"bool","name":"_requireSuccess","type":"bool"},{"internalType":"uint256","name":"_minGas","type":"uint256"},{"components":[{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct RelayAdapt.Call[]","name":"_calls","type":"tuple[]"}],"name":"relay","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"enum TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenSubID","type":"uint256"}],"internalType":"struct TokenData[]","name":"_tokens","type":"tuple[]"},{"internalType":"address","name":"_to","type":"address"}],"name":"send","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unwrapAllBase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"wbase","outputs":[{"internalType":"contract IWBase","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wrapAllBase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b50604051620026783803806200267883398101604081905262000034916200007f565b600080546001600160a01b039384166001600160a01b03199182161790915560018054929093169116179055620000be565b6001600160a01b03811681146200007c57600080fd5b50565b600080604083850312156200009357600080fd5b8251620000a08162000066565b6020840151909250620000b38162000066565b809150509250929050565b6125aa80620000ce6000396000f3fe6080604052600436106100c05760003560e01c80638182b67f11610074578063aa6a9c441161004e578063aa6a9c44146101e2578063b29e021e14610202578063f62f3e9b1461021757600080fd5b80638182b67f1461018c57806396abc9ed146101ac5780639ce6b76c146101cc57600080fd5b8063494f40a4116100a5578063494f40a41461012b5780634d2a938f1461015957806358543a9d1461016c57600080fd5b806305c7671a146100cc5780634013074d146100ee57600080fd5b366100c757005b600080fd5b3480156100d857600080fd5b506100ec6100e7366004611946565b61022c565b005b3480156100fa57600080fd5b5060005461010e906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561013757600080fd5b5061014b6101463660046119ff565b610867565b604051908152602001610122565b6100ec6101673660046119ff565b6108ac565b34801561017857600080fd5b5061014b610187366004611ade565b61094e565b34801561019857600080fd5b506100ec6101a7366004611ade565b610a52565b3480156101b857600080fd5b506100ec6101c7366004611bb6565b610bb9565b3480156101d857600080fd5b5061010e61dead81565b3480156101ee57600080fd5b5060015461010e906001600160a01b031681565b34801561020e57600080fd5b506100ec610fa0565b34801561022357600080fd5b506100ec6110ee565b3330146102975760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b60648201526084015b60405180910390fd5b60008367ffffffffffffffff8111156102b2576102b2611a97565b6040519080825280602002602001820160405280156102eb57816020015b6102d8611898565b8152602001906001900390816102d05790505b5090506000805b8581101561063557600087878381811061030e5761030e611c20565b6103249260206060909202019081019150611c43565b600281111561033557610335611c0a565b141561047d57600087878381811061034f5761034f611c20565b90506060020160200160208101906103679190611c60565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156103b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103d59190611c7b565b90508015610476576103e8600185611caa565b600054909450610405906001600160a01b038481169116836111d1565b60405180606001604052808781526020018a8a8681811061042857610428611c20565b90506060020180360381019061043e9190611cc2565b8152602001826effffffffffffffffffffffffffffff1681525085848151811061046a5761046a611c20565b60200260200101819052505b5050610623565b600187878381811061049157610491611c20565b6104a79260206060909202019081019150611c43565b60028111156104b8576104b8611c0a565b141561052c5760405162461bcd60e51b815260206004820152602660248201527f47656e6572616c41646170743a20455243373231206e6f74207965742073757060448201527f706f727465640000000000000000000000000000000000000000000000000000606482015260840161028e565b600287878381811061054057610540611c20565b6105569260206060909202019081019150611c43565b600281111561056757610567611c0a565b14156105db5760405162461bcd60e51b815260206004820152602760248201527f47656e6572616c41646170743a2045524331313535206e6f742079657420737560448201527f70706f7274656400000000000000000000000000000000000000000000000000606482015260840161028e565b60405162461bcd60e51b815260206004820181905260248201527f47656e6572616c41646170743a20556e6b6e6f776e20746f6b656e2074797065604482015260640161028e565b8061062d81611d2c565b9150506102f2565b5080610642575050610861565b60008167ffffffffffffffff81111561065d5761065d611a97565b60405190808252806020026020018201604052801561069657816020015b610683611898565b81526020019060019003908161067b5790505b50905060008267ffffffffffffffff8111156106b4576106b4611a97565b6040519080825280602002602001820160405280156106ed57816020015b6106da6118dc565b8152602001906001900390816106d25790505b5090506000805b848110156107dd575b85828151811061070f5761070f611c20565b6020026020010151604001516effffffffffffffffffffffffffffff16600014156107465761073f600183611caa565b91506106fd565b85828151811061075857610758611c20565b602002602001015184828151811061077257610772611c20565b60209081029190910101526040805180820182529089906002908390839080828437600092019190915250508451859150839081106107b3576107b3611c20565b60209081029190910101526107c9600183611caa565b9150806107d581611d2c565b9150506106f4565b506000546040517fae9c2c8f0000000000000000000000000000000000000000000000000000000081526001600160a01b039091169063ae9c2c8f906108299086908690600401611dc6565b600060405180830381600087803b15801561084357600080fd5b505af1158015610857573d6000803e3d6000fd5b5050505050505050505b50505050565b6000808686868686604051602001610883959493929190611e5d565b604051602081830303815290604052905061089f89898361094e565b9998505050505050505050565b825a116108fb5760405162461bcd60e51b815260206004820152601760248201527f4e6f7420656e6f7567682067617320737570706c696564000000000000000000604482015260640161028e565b851561093a576000858585858560405160200161091c959493929190611e5d565b6040516020818303038152906040529050610938888883610a52565b505b610945848383611384565b50505050505050565b6000808367ffffffffffffffff81111561096a5761096a611a97565b604051908082528060200260200182016040528015610993578160200160208202803683370190505b50905060005b84811015610a1b578585828181106109b3576109b3611c20565b90506020028101906109c59190611f64565b6109d490610120810190611f85565b60008181106109e5576109e5611c20565b905060200201358282815181106109fe576109fe611c20565b602090810291909101015280610a1381611d2c565b915050610999565b50604051610a3190829086908690602001612027565b604051602081830303815290604052805190602001209150505b9392505050565b6000610a5f84848461094e565b905060005b83811015610b355781858583818110610a7f57610a7f611c20565b9050602002810190610a919190611f64565b610aa09061016081019061207a565b606001351480610ab157503261dead145b610b235760405162461bcd60e51b815260206004820152602960248201527f47656e6572616c41646170743a204164617074494420506172616d657465727360448201527f204d69736d617463680000000000000000000000000000000000000000000000606482015260840161028e565b80610b2d81611d2c565b915050610a64565b506000546040517f4489999c0000000000000000000000000000000000000000000000000000000081526001600160a01b0390911690634489999c90610b8190879087906004016122c9565b600060405180830381600087803b158015610b9b57600080fd5b505af1158015610baf573d6000803e3d6000fd5b5050505050505050565b333014610c1f5760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b606482015260840161028e565b60005b82811015610861576000848483818110610c3e57610c3e611c20565b610c549260206060909202019081019150611c43565b6002811115610c6557610c65611c0a565b1415610de8576000848483818110610c7f57610c7f611c20565b9050606002016020016020810190610c979190611c60565b90506001600160a01b038116610d5957478015610d53576000846001600160a01b03168260405160006040518083038185875af1925050503d8060008114610cfb576040519150601f19603f3d011682016040523d82523d6000602084013e610d00565b606091505b5050905080610d515760405162461bcd60e51b815260206004820152601460248201527f4661696c656420746f2073656e64204574686572000000000000000000000000604482015260640161028e565b505b50610de2565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610da0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc49190611c7b565b90508015610de057610de06001600160a01b03831685836115d2565b505b50610f8e565b6001848483818110610dfc57610dfc611c20565b610e129260206060909202019081019150611c43565b6002811115610e2357610e23611c0a565b1415610e975760405162461bcd60e51b815260206004820152602660248201527f5261696c67756e4c6f6769633a20455243373231206e6f74207965742073757060448201527f706f727465640000000000000000000000000000000000000000000000000000606482015260840161028e565b6002848483818110610eab57610eab611c20565b610ec19260206060909202019081019150611c43565b6002811115610ed257610ed2611c0a565b1415610f465760405162461bcd60e51b815260206004820152602760248201527f5261696c67756e4c6f6769633a2045524331313535206e6f742079657420737560448201527f70706f7274656400000000000000000000000000000000000000000000000000606482015260840161028e565b60405162461bcd60e51b815260206004820181905260248201527f5261696c67756e4c6f6769633a20556e6b6e6f776e20746f6b656e2074797065604482015260640161028e565b80610f9881611d2c565b915050610c22565b3330146110065760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b606482015260840161028e565b6001546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa15801561104f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110739190611c7b565b6001546040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018390529192506001600160a01b031690632e1a7d4d90602401600060405180830381600087803b1580156110d357600080fd5b505af11580156110e7573d6000803e3d6000fd5b5050505050565b3330146111545760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b606482015260840161028e565b600154604080517fd0e30db0000000000000000000000000000000000000000000000000000000008152905147926001600160a01b03169163d0e30db091849160048082019260009290919082900301818588803b1580156111b557600080fd5b505af11580156111c9573d6000803e3d6000fd5b505050505050565b80158061126457506040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561123e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112629190611c7b565b155b6112d65760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e636500000000000000000000606482015260840161028e565b6040516001600160a01b03831660248201526044810182905261137f9084907f095ea7b300000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915261161b565b505050565b60008167ffffffffffffffff81111561139f5761139f611a97565b6040519080825280602002602001820160405280156113e557816020015b6040805180820190915260008152606060208201528152602001906001900390816113bd5790505b50905060005b82811015611594573684848381811061140657611406611c20565b90506020028101906114189190612418565b905060008061142a6020840184611c60565b6001600160a01b031683604001355a90611447602087018761242e565b604051611455929190612475565b600060405180830381858888f193505050503d8060008114611493576040519150601f19603f3d011682016040523d82523d6000602084013e611498565b606091505b509150915060405180604001604052808315158152602001828152508585815181106114c6576114c6611c20565b602002602001018190525081156114df57505050611582565b6000306114ef6020860186611c60565b6001600160a01b0316149050600089806115065750815b9050801561157c577f12dedbded7484b2dfc73a6e1ba20c48221bce1959057eab9b438542d79bf15a38760405161153d9190612485565b60405180910390a18260405160200161155691906124ed565b60408051601f198184030181529082905262461bcd60e51b825261028e91600401612532565b50505050505b8061158c81611d2c565b9150506113eb565b507f12dedbded7484b2dfc73a6e1ba20c48221bce1959057eab9b438542d79bf15a3816040516115c49190612485565b60405180910390a150505050565b6040516001600160a01b03831660248201526044810182905261137f9084907fa9059cbb000000000000000000000000000000000000000000000000000000009060640161131b565b6000611670826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166117009092919063ffffffff16565b80519091501561137f578080602001905181019061168e9190612545565b61137f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161028e565b606061170f8484600085611717565b949350505050565b60608247101561178f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161028e565b6001600160a01b0385163b6117e65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161028e565b600080866001600160a01b031685876040516118029190612562565b60006040518083038185875af1925050503d806000811461183f576040519150601f19603f3d011682016040523d82523d6000602084013e611844565b606091505b509150915061185482828661185f565b979650505050505050565b6060831561186e575081610a4b565b82511561187e5782518084602001fd5b8160405162461bcd60e51b815260040161028e9190612532565b6040518060600160405280600081526020016118cf6040805160608101909152806000815260006020820181905260409091015290565b8152600060209091015290565b60405180604001604052806002906020820280368337509192915050565b60008083601f84011261190c57600080fd5b50813567ffffffffffffffff81111561192457600080fd5b60208301915083602060608302850101111561193f57600080fd5b9250929050565b6000806000806080858703121561195c57600080fd5b843567ffffffffffffffff81111561197357600080fd5b61197f878288016118fa565b909550935050606085018681111561199657600080fd5b9396929550505060209290920191903590565b60008083601f8401126119bb57600080fd5b50813567ffffffffffffffff8111156119d357600080fd5b6020830191508360208260051b850101111561193f57600080fd5b80151581146119fc57600080fd5b50565b600080600080600080600060a0888a031215611a1a57600080fd5b873567ffffffffffffffff80821115611a3257600080fd5b611a3e8b838c016119a9565b909950975060208a0135965060408a01359150611a5a826119ee565b9094506060890135935060808901359080821115611a7757600080fd5b50611a848a828b016119a9565b989b979a50959850939692959293505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611ad657611ad6611a97565b604052919050565b600080600060408486031215611af357600080fd5b833567ffffffffffffffff80821115611b0b57600080fd5b611b17878388016119a9565b9095509350602091508582013581811115611b3157600080fd5b8601601f81018813611b4257600080fd5b803582811115611b5457611b54611a97565b611b66601f8201601f19168501611aad565b92508083528884828401011115611b7c57600080fd5b80848301858501376000848285010152505080925050509250925092565b80356001600160a01b0381168114611bb157600080fd5b919050565b600080600060408486031215611bcb57600080fd5b833567ffffffffffffffff811115611be257600080fd5b611bee868287016118fa565b9094509250611c01905060208501611b9a565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600381106119fc57600080fd5b600060208284031215611c5557600080fd5b8135610a4b81611c36565b600060208284031215611c7257600080fd5b610a4b82611b9a565b600060208284031215611c8d57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115611cbd57611cbd611c94565b500190565b600060608284031215611cd457600080fd5b6040516060810181811067ffffffffffffffff82111715611cf757611cf7611a97565b6040528235611d0581611c36565b8152611d1360208401611b9a565b6020820152604083013560408201528091505092915050565b6000600019821415611d4057611d40611c94565b5060010190565b600381106119fc57634e487b7160e01b600052602160045260246000fd5b60008151808452602080850194508084016000805b84811015611dba57825188835b6002811015611da457825182529186019190860190600101611d87565b5050506040979097019691830191600101611d7a565b50959695505050505050565b6040808252835182820181905260009190606090818501906020808901865b83811015611e4957815180518652838101518051611e0281611d47565b87860152808501516001600160a01b031689880152880151878701528701516effffffffffffffffffffffffffffff16608086015260a09094019390820190600101611de5565b505086830390870152506118548187611d65565b6000608080830188845260208815158186015260408881870152606084818801528388855260a08801905060a08960051b89010194508960005b8a811015611f5157898703609f190183528135368d9003605e19018112611ebd57600080fd5b8c016001600160a01b03611ed082611b9a565b16885286810135601e19823603018112611ee957600080fd5b8101803567ffffffffffffffff811115611f0257600080fd5b803603831315611f1157600080fd5b86898b015280878b0152808983018c8c013760008a82018c015291870135878a015250601f01601f19169096018701959185019190850190600101611e97565b50949d9c50505050505050505050505050565b6000823561023e19833603018112611f7b57600080fd5b9190910192915050565b6000808335601e19843603018112611f9c57600080fd5b83018035915067ffffffffffffffff821115611fb757600080fd5b6020019150600581901b360382131561193f57600080fd5b60005b83811015611fea578181015183820152602001611fd2565b838111156108615750506000910152565b60008151808452612013816020860160208601611fcf565b601f01601f19169290920160200192915050565b606080825284519082018190526000906020906080840190828801845b8281101561206057815184529284019290840190600101612044565b505050858285015283810360408501526118548186611ffb565b60008235609e19833603018112611f7b57600080fd5b6000808335601e198436030181126120a757600080fd5b830160208101925035905067ffffffffffffffff8111156120c757600080fd5b8060051b360383131561193f57600080fd5b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561210b57600080fd5b8260051b8083602087013760009401602001938452509192915050565b60008235609e1983360301811261213e57600080fd5b90910192915050565b600060a08301823561ffff811680821461216057600080fd5b85525060208381013561217281611c36565b61217b81611d47565b8582015260406001600160a01b03612194868301611b9a565b16818701526060850135606087015260806121b181870187612090565b60a0898401529485905260c094858901600582901b8a0187018360005b84811015612245578c830360bf1901845281353687900360de190181126121f457600080fd5b860160e088828637888501600081528a8a84018237508b85016000815261221d8d840184612090565b935082825261222f83880185836120d9565b978d019796505050928a019250506001016121ce565b50909b9a5050505050505050505050565b80358252602081013561226881611c36565b61227181611d47565b60208301526001600160a01b0361228a60408301611b9a565b1660408301526060810135606083015260808101356effffffffffffffffffffffffffffff81168082146122bd57600080fd5b80608085015250505050565b60208082528181018390526000906040808401600586901b8501820187855b8881101561240a57878303603f190184528135368b900361023e1901811261230f57600080fd5b8a0180358452602080820135908501526102408687830188870137608080860160008152888285018237505060c0828101359086015260e08083013590860152610100808301359086015261012061236981840184612090565b838389015261237b84890182846120d9565b935050505061014061238f81840184612090565b878403838901526123a18482846120d9565b93505050506101606123b581840184612128565b868303828801526123c68382612147565b925050506101806123db818701828501612256565b506102206123ea818401611b9a565b6001600160a01b03169501949094525092850192908501906001016122e8565b509098975050505050505050565b60008235605e19833603018112611f7b57600080fd5b6000808335601e1984360301811261244557600080fd5b83018035915067ffffffffffffffff82111561246057600080fd5b60200191503681900382131561193f57600080fd5b8183823760009101908152919050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b8381101561240a57888303603f1901855281518051151584528701518784018790526124da87850182611ffb565b95880195935050908601906001016124ac565b7f47656e6572616c41646170742043616c6c204661696c65643a00000000000000815260008251612525816019850160208701611fcf565b9190910160190192915050565b602081526000610a4b6020830184611ffb565b60006020828403121561255757600080fd5b8151610a4b816119ee565b60008251611f7b818460208701611fcf56fea26469706673582212205ce9f863cea1e2422d997ac86ae33a4cb5faeb34bfcb5330ff2fb699fff266de64736f6c634300080c0033000000000000000000000000fa7093cdd9ee6932b4eb2c9e1cde7ce00b1fa4b9000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

Deployed Bytecode

0x6080604052600436106100c05760003560e01c80638182b67f11610074578063aa6a9c441161004e578063aa6a9c44146101e2578063b29e021e14610202578063f62f3e9b1461021757600080fd5b80638182b67f1461018c57806396abc9ed146101ac5780639ce6b76c146101cc57600080fd5b8063494f40a4116100a5578063494f40a41461012b5780634d2a938f1461015957806358543a9d1461016c57600080fd5b806305c7671a146100cc5780634013074d146100ee57600080fd5b366100c757005b600080fd5b3480156100d857600080fd5b506100ec6100e7366004611946565b61022c565b005b3480156100fa57600080fd5b5060005461010e906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561013757600080fd5b5061014b6101463660046119ff565b610867565b604051908152602001610122565b6100ec6101673660046119ff565b6108ac565b34801561017857600080fd5b5061014b610187366004611ade565b61094e565b34801561019857600080fd5b506100ec6101a7366004611ade565b610a52565b3480156101b857600080fd5b506100ec6101c7366004611bb6565b610bb9565b3480156101d857600080fd5b5061010e61dead81565b3480156101ee57600080fd5b5060015461010e906001600160a01b031681565b34801561020e57600080fd5b506100ec610fa0565b34801561022357600080fd5b506100ec6110ee565b3330146102975760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b60648201526084015b60405180910390fd5b60008367ffffffffffffffff8111156102b2576102b2611a97565b6040519080825280602002602001820160405280156102eb57816020015b6102d8611898565b8152602001906001900390816102d05790505b5090506000805b8581101561063557600087878381811061030e5761030e611c20565b6103249260206060909202019081019150611c43565b600281111561033557610335611c0a565b141561047d57600087878381811061034f5761034f611c20565b90506060020160200160208101906103679190611c60565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156103b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103d59190611c7b565b90508015610476576103e8600185611caa565b600054909450610405906001600160a01b038481169116836111d1565b60405180606001604052808781526020018a8a8681811061042857610428611c20565b90506060020180360381019061043e9190611cc2565b8152602001826effffffffffffffffffffffffffffff1681525085848151811061046a5761046a611c20565b60200260200101819052505b5050610623565b600187878381811061049157610491611c20565b6104a79260206060909202019081019150611c43565b60028111156104b8576104b8611c0a565b141561052c5760405162461bcd60e51b815260206004820152602660248201527f47656e6572616c41646170743a20455243373231206e6f74207965742073757060448201527f706f727465640000000000000000000000000000000000000000000000000000606482015260840161028e565b600287878381811061054057610540611c20565b6105569260206060909202019081019150611c43565b600281111561056757610567611c0a565b14156105db5760405162461bcd60e51b815260206004820152602760248201527f47656e6572616c41646170743a2045524331313535206e6f742079657420737560448201527f70706f7274656400000000000000000000000000000000000000000000000000606482015260840161028e565b60405162461bcd60e51b815260206004820181905260248201527f47656e6572616c41646170743a20556e6b6e6f776e20746f6b656e2074797065604482015260640161028e565b8061062d81611d2c565b9150506102f2565b5080610642575050610861565b60008167ffffffffffffffff81111561065d5761065d611a97565b60405190808252806020026020018201604052801561069657816020015b610683611898565b81526020019060019003908161067b5790505b50905060008267ffffffffffffffff8111156106b4576106b4611a97565b6040519080825280602002602001820160405280156106ed57816020015b6106da6118dc565b8152602001906001900390816106d25790505b5090506000805b848110156107dd575b85828151811061070f5761070f611c20565b6020026020010151604001516effffffffffffffffffffffffffffff16600014156107465761073f600183611caa565b91506106fd565b85828151811061075857610758611c20565b602002602001015184828151811061077257610772611c20565b60209081029190910101526040805180820182529089906002908390839080828437600092019190915250508451859150839081106107b3576107b3611c20565b60209081029190910101526107c9600183611caa565b9150806107d581611d2c565b9150506106f4565b506000546040517fae9c2c8f0000000000000000000000000000000000000000000000000000000081526001600160a01b039091169063ae9c2c8f906108299086908690600401611dc6565b600060405180830381600087803b15801561084357600080fd5b505af1158015610857573d6000803e3d6000fd5b5050505050505050505b50505050565b6000808686868686604051602001610883959493929190611e5d565b604051602081830303815290604052905061089f89898361094e565b9998505050505050505050565b825a116108fb5760405162461bcd60e51b815260206004820152601760248201527f4e6f7420656e6f7567682067617320737570706c696564000000000000000000604482015260640161028e565b851561093a576000858585858560405160200161091c959493929190611e5d565b6040516020818303038152906040529050610938888883610a52565b505b610945848383611384565b50505050505050565b6000808367ffffffffffffffff81111561096a5761096a611a97565b604051908082528060200260200182016040528015610993578160200160208202803683370190505b50905060005b84811015610a1b578585828181106109b3576109b3611c20565b90506020028101906109c59190611f64565b6109d490610120810190611f85565b60008181106109e5576109e5611c20565b905060200201358282815181106109fe576109fe611c20565b602090810291909101015280610a1381611d2c565b915050610999565b50604051610a3190829086908690602001612027565b604051602081830303815290604052805190602001209150505b9392505050565b6000610a5f84848461094e565b905060005b83811015610b355781858583818110610a7f57610a7f611c20565b9050602002810190610a919190611f64565b610aa09061016081019061207a565b606001351480610ab157503261dead145b610b235760405162461bcd60e51b815260206004820152602960248201527f47656e6572616c41646170743a204164617074494420506172616d657465727360448201527f204d69736d617463680000000000000000000000000000000000000000000000606482015260840161028e565b80610b2d81611d2c565b915050610a64565b506000546040517f4489999c0000000000000000000000000000000000000000000000000000000081526001600160a01b0390911690634489999c90610b8190879087906004016122c9565b600060405180830381600087803b158015610b9b57600080fd5b505af1158015610baf573d6000803e3d6000fd5b5050505050505050565b333014610c1f5760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b606482015260840161028e565b60005b82811015610861576000848483818110610c3e57610c3e611c20565b610c549260206060909202019081019150611c43565b6002811115610c6557610c65611c0a565b1415610de8576000848483818110610c7f57610c7f611c20565b9050606002016020016020810190610c979190611c60565b90506001600160a01b038116610d5957478015610d53576000846001600160a01b03168260405160006040518083038185875af1925050503d8060008114610cfb576040519150601f19603f3d011682016040523d82523d6000602084013e610d00565b606091505b5050905080610d515760405162461bcd60e51b815260206004820152601460248201527f4661696c656420746f2073656e64204574686572000000000000000000000000604482015260640161028e565b505b50610de2565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa158015610da0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc49190611c7b565b90508015610de057610de06001600160a01b03831685836115d2565b505b50610f8e565b6001848483818110610dfc57610dfc611c20565b610e129260206060909202019081019150611c43565b6002811115610e2357610e23611c0a565b1415610e975760405162461bcd60e51b815260206004820152602660248201527f5261696c67756e4c6f6769633a20455243373231206e6f74207965742073757060448201527f706f727465640000000000000000000000000000000000000000000000000000606482015260840161028e565b6002848483818110610eab57610eab611c20565b610ec19260206060909202019081019150611c43565b6002811115610ed257610ed2611c0a565b1415610f465760405162461bcd60e51b815260206004820152602760248201527f5261696c67756e4c6f6769633a2045524331313535206e6f742079657420737560448201527f70706f7274656400000000000000000000000000000000000000000000000000606482015260840161028e565b60405162461bcd60e51b815260206004820181905260248201527f5261696c67756e4c6f6769633a20556e6b6e6f776e20746f6b656e2074797065604482015260640161028e565b80610f9881611d2c565b915050610c22565b3330146110065760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b606482015260840161028e565b6001546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa15801561104f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110739190611c7b565b6001546040517f2e1a7d4d000000000000000000000000000000000000000000000000000000008152600481018390529192506001600160a01b031690632e1a7d4d90602401600060405180830381600087803b1580156110d357600080fd5b505af11580156110e7573d6000803e3d6000fd5b5050505050565b3330146111545760405162461bcd60e51b815260206004820152602e60248201527f52656c617941646170743a2045787465726e616c2063616c6c20746f206f6e6c60448201526d3ca9b2b63310333ab731ba34b7b760911b606482015260840161028e565b600154604080517fd0e30db0000000000000000000000000000000000000000000000000000000008152905147926001600160a01b03169163d0e30db091849160048082019260009290919082900301818588803b1580156111b557600080fd5b505af11580156111c9573d6000803e3d6000fd5b505050505050565b80158061126457506040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561123e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112629190611c7b565b155b6112d65760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e636500000000000000000000606482015260840161028e565b6040516001600160a01b03831660248201526044810182905261137f9084907f095ea7b300000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915261161b565b505050565b60008167ffffffffffffffff81111561139f5761139f611a97565b6040519080825280602002602001820160405280156113e557816020015b6040805180820190915260008152606060208201528152602001906001900390816113bd5790505b50905060005b82811015611594573684848381811061140657611406611c20565b90506020028101906114189190612418565b905060008061142a6020840184611c60565b6001600160a01b031683604001355a90611447602087018761242e565b604051611455929190612475565b600060405180830381858888f193505050503d8060008114611493576040519150601f19603f3d011682016040523d82523d6000602084013e611498565b606091505b509150915060405180604001604052808315158152602001828152508585815181106114c6576114c6611c20565b602002602001018190525081156114df57505050611582565b6000306114ef6020860186611c60565b6001600160a01b0316149050600089806115065750815b9050801561157c577f12dedbded7484b2dfc73a6e1ba20c48221bce1959057eab9b438542d79bf15a38760405161153d9190612485565b60405180910390a18260405160200161155691906124ed565b60408051601f198184030181529082905262461bcd60e51b825261028e91600401612532565b50505050505b8061158c81611d2c565b9150506113eb565b507f12dedbded7484b2dfc73a6e1ba20c48221bce1959057eab9b438542d79bf15a3816040516115c49190612485565b60405180910390a150505050565b6040516001600160a01b03831660248201526044810182905261137f9084907fa9059cbb000000000000000000000000000000000000000000000000000000009060640161131b565b6000611670826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166117009092919063ffffffff16565b80519091501561137f578080602001905181019061168e9190612545565b61137f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161028e565b606061170f8484600085611717565b949350505050565b60608247101561178f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161028e565b6001600160a01b0385163b6117e65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161028e565b600080866001600160a01b031685876040516118029190612562565b60006040518083038185875af1925050503d806000811461183f576040519150601f19603f3d011682016040523d82523d6000602084013e611844565b606091505b509150915061185482828661185f565b979650505050505050565b6060831561186e575081610a4b565b82511561187e5782518084602001fd5b8160405162461bcd60e51b815260040161028e9190612532565b6040518060600160405280600081526020016118cf6040805160608101909152806000815260006020820181905260409091015290565b8152600060209091015290565b60405180604001604052806002906020820280368337509192915050565b60008083601f84011261190c57600080fd5b50813567ffffffffffffffff81111561192457600080fd5b60208301915083602060608302850101111561193f57600080fd5b9250929050565b6000806000806080858703121561195c57600080fd5b843567ffffffffffffffff81111561197357600080fd5b61197f878288016118fa565b909550935050606085018681111561199657600080fd5b9396929550505060209290920191903590565b60008083601f8401126119bb57600080fd5b50813567ffffffffffffffff8111156119d357600080fd5b6020830191508360208260051b850101111561193f57600080fd5b80151581146119fc57600080fd5b50565b600080600080600080600060a0888a031215611a1a57600080fd5b873567ffffffffffffffff80821115611a3257600080fd5b611a3e8b838c016119a9565b909950975060208a0135965060408a01359150611a5a826119ee565b9094506060890135935060808901359080821115611a7757600080fd5b50611a848a828b016119a9565b989b979a50959850939692959293505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611ad657611ad6611a97565b604052919050565b600080600060408486031215611af357600080fd5b833567ffffffffffffffff80821115611b0b57600080fd5b611b17878388016119a9565b9095509350602091508582013581811115611b3157600080fd5b8601601f81018813611b4257600080fd5b803582811115611b5457611b54611a97565b611b66601f8201601f19168501611aad565b92508083528884828401011115611b7c57600080fd5b80848301858501376000848285010152505080925050509250925092565b80356001600160a01b0381168114611bb157600080fd5b919050565b600080600060408486031215611bcb57600080fd5b833567ffffffffffffffff811115611be257600080fd5b611bee868287016118fa565b9094509250611c01905060208501611b9a565b90509250925092565b634e487b7160e01b600052602160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600381106119fc57600080fd5b600060208284031215611c5557600080fd5b8135610a4b81611c36565b600060208284031215611c7257600080fd5b610a4b82611b9a565b600060208284031215611c8d57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115611cbd57611cbd611c94565b500190565b600060608284031215611cd457600080fd5b6040516060810181811067ffffffffffffffff82111715611cf757611cf7611a97565b6040528235611d0581611c36565b8152611d1360208401611b9a565b6020820152604083013560408201528091505092915050565b6000600019821415611d4057611d40611c94565b5060010190565b600381106119fc57634e487b7160e01b600052602160045260246000fd5b60008151808452602080850194508084016000805b84811015611dba57825188835b6002811015611da457825182529186019190860190600101611d87565b5050506040979097019691830191600101611d7a565b50959695505050505050565b6040808252835182820181905260009190606090818501906020808901865b83811015611e4957815180518652838101518051611e0281611d47565b87860152808501516001600160a01b031689880152880151878701528701516effffffffffffffffffffffffffffff16608086015260a09094019390820190600101611de5565b505086830390870152506118548187611d65565b6000608080830188845260208815158186015260408881870152606084818801528388855260a08801905060a08960051b89010194508960005b8a811015611f5157898703609f190183528135368d9003605e19018112611ebd57600080fd5b8c016001600160a01b03611ed082611b9a565b16885286810135601e19823603018112611ee957600080fd5b8101803567ffffffffffffffff811115611f0257600080fd5b803603831315611f1157600080fd5b86898b015280878b0152808983018c8c013760008a82018c015291870135878a015250601f01601f19169096018701959185019190850190600101611e97565b50949d9c50505050505050505050505050565b6000823561023e19833603018112611f7b57600080fd5b9190910192915050565b6000808335601e19843603018112611f9c57600080fd5b83018035915067ffffffffffffffff821115611fb757600080fd5b6020019150600581901b360382131561193f57600080fd5b60005b83811015611fea578181015183820152602001611fd2565b838111156108615750506000910152565b60008151808452612013816020860160208601611fcf565b601f01601f19169290920160200192915050565b606080825284519082018190526000906020906080840190828801845b8281101561206057815184529284019290840190600101612044565b505050858285015283810360408501526118548186611ffb565b60008235609e19833603018112611f7b57600080fd5b6000808335601e198436030181126120a757600080fd5b830160208101925035905067ffffffffffffffff8111156120c757600080fd5b8060051b360383131561193f57600080fd5b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561210b57600080fd5b8260051b8083602087013760009401602001938452509192915050565b60008235609e1983360301811261213e57600080fd5b90910192915050565b600060a08301823561ffff811680821461216057600080fd5b85525060208381013561217281611c36565b61217b81611d47565b8582015260406001600160a01b03612194868301611b9a565b16818701526060850135606087015260806121b181870187612090565b60a0898401529485905260c094858901600582901b8a0187018360005b84811015612245578c830360bf1901845281353687900360de190181126121f457600080fd5b860160e088828637888501600081528a8a84018237508b85016000815261221d8d840184612090565b935082825261222f83880185836120d9565b978d019796505050928a019250506001016121ce565b50909b9a5050505050505050505050565b80358252602081013561226881611c36565b61227181611d47565b60208301526001600160a01b0361228a60408301611b9a565b1660408301526060810135606083015260808101356effffffffffffffffffffffffffffff81168082146122bd57600080fd5b80608085015250505050565b60208082528181018390526000906040808401600586901b8501820187855b8881101561240a57878303603f190184528135368b900361023e1901811261230f57600080fd5b8a0180358452602080820135908501526102408687830188870137608080860160008152888285018237505060c0828101359086015260e08083013590860152610100808301359086015261012061236981840184612090565b838389015261237b84890182846120d9565b935050505061014061238f81840184612090565b878403838901526123a18482846120d9565b93505050506101606123b581840184612128565b868303828801526123c68382612147565b925050506101806123db818701828501612256565b506102206123ea818401611b9a565b6001600160a01b03169501949094525092850192908501906001016122e8565b509098975050505050505050565b60008235605e19833603018112611f7b57600080fd5b6000808335601e1984360301811261244557600080fd5b83018035915067ffffffffffffffff82111561246057600080fd5b60200191503681900382131561193f57600080fd5b8183823760009101908152919050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b8381101561240a57888303603f1901855281518051151584528701518784018790526124da87850182611ffb565b95880195935050908601906001016124ac565b7f47656e6572616c41646170742043616c6c204661696c65643a00000000000000815260008251612525816019850160208701611fcf565b9190910160190192915050565b602081526000610a4b6020830184611ffb565b60006020828403121561255757600080fd5b8151610a4b816119ee565b60008251611f7b818460208701611fcf56fea26469706673582212205ce9f863cea1e2422d997ac86ae33a4cb5faeb34bfcb5330ff2fb699fff266de64736f6c634300080c0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000fa7093cdd9ee6932b4eb2c9e1cde7ce00b1fa4b9000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

-----Decoded View---------------
Arg [0] : _railgun (address): 0xFA7093CDD9EE6932B4eb2c9e1cde7CE00B1FA4b9
Arg [1] : _wbase (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000fa7093cdd9ee6932b4eb2c9e1cde7ce00b1fa4b9
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

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.