Token
Confidential Wrapped ETHER (eETH)
ERC-20
Overview
Max Total Supply
0.5778 eETH
Holders
25,230
Market
Onchain Market Cap
-
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
0.5 eETHLoading...
Loading
Loading...
Loading
Loading...
Loading
| # | Exchange | Pair | Price | 24H Volume | % Volume |
|---|
Contract Source Code Verified (Exact Match)
Contract Name:
ConfidentialETH
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import { IERC20, IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { FHERC20 } from "./FHERC20.sol";
import { IWETH } from "./interfaces/IWETH.sol";
import { euint128, FHE } from "@fhenixprotocol/cofhe-contracts/FHE.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { ConfidentialClaim } from "./ConfidentialClaim.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract ConfidentialETH is FHERC20, Ownable, ConfidentialClaim {
using EnumerableSet for EnumerableSet.UintSet;
using SafeERC20 for IERC20;
using SafeERC20 for IWETH;
IWETH public wETH;
constructor(
IWETH wETH_
) Ownable(msg.sender) FHERC20("Confidential Wrapped ETHER", "eETH", IERC20Metadata(address(wETH_)).decimals()) {
wETH = wETH_;
}
/**
* @dev Returns the address of the erc20 ERC-20 token that is being encrypted wrapped.
*/
function erc20() public view returns (IERC20) {
return wETH;
}
receive() external payable {}
fallback() external payable {}
event EncryptedWETH(address indexed from, address indexed to, uint128 value);
event EncryptedETH(address indexed from, address indexed to, uint256 value);
event DecryptedETH(address indexed from, address indexed to, uint128 value);
event ClaimedDecryptedETH(address indexed from, address indexed to, uint128 value);
/**
* @dev The ETH transfer failed.
*/
error ETHTransferFailed();
/**
* @dev The recipient is the zero address.
*/
error InvalidRecipient();
function encryptWETH(address to, uint128 value) public {
if (to == address(0)) to = msg.sender;
wETH.safeTransferFrom(msg.sender, address(this), value);
wETH.withdraw(value);
_mint(to, value);
emit EncryptedWETH(msg.sender, to, value);
}
function encryptETH(address to) public payable {
if (to == address(0)) to = msg.sender;
_mint(to, SafeCast.toUint128(msg.value));
emit EncryptedETH(msg.sender, to, msg.value);
}
function decrypt(address to, uint128 value) public {
if (to == address(0)) to = msg.sender;
euint128 burned = _burn(msg.sender, value);
FHE.decrypt(burned);
_createClaim(to, value, burned);
emit DecryptedETH(msg.sender, to, value);
}
/**
* @notice Claim a decrypted amount of ETH
* @param ctHash The ctHash of the burned amount
*/
function claimDecrypted(uint256 ctHash) public {
Claim memory claim = _handleClaim(ctHash);
// Send the ETH to the recipient
(bool sent, ) = claim.to.call{ value: claim.decryptedAmount }("");
if (!sent) revert ETHTransferFailed();
emit ClaimedDecryptedETH(msg.sender, claim.to, claim.decryptedAmount);
}
/**
* @notice Claim all decrypted amounts of ETH
*/
function claimAllDecrypted() public {
Claim[] memory claims = _handleClaimAll();
for (uint256 i = 0; i < claims.length; i++) {
(bool sent, ) = claims[i].to.call{ value: claims[i].decryptedAmount }("");
if (!sent) revert ETHTransferFailed();
emit ClaimedDecryptedETH(msg.sender, claims[i].to, claims[i].decryptedAmount);
}
}
}// SPDX-License-Identifier: BSD-3-Clause-Clear
// solhint-disable one-contract-per-file
pragma solidity >=0.8.19 <0.9.0;
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {FunctionId, ITaskManager, Utils, EncryptedInput, InEbool, InEuint8, InEuint16, InEuint32, InEuint64, InEuint128, InEuint256, InEaddress} from "./ICofhe.sol";
type ebool is uint256;
type euint8 is uint256;
type euint16 is uint256;
type euint32 is uint256;
type euint64 is uint256;
type euint128 is uint256;
type euint256 is uint256;
type eaddress is uint256;
// ================================
// \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/
// TODO : CHANGE ME AFTER DEPLOYING
// /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
// ================================
//solhint-disable const-name-snakecase
address constant TASK_MANAGER_ADDRESS = 0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9;
library Common {
error InvalidHexCharacter(bytes1 char);
error SecurityZoneOutOfBounds(int32 value);
// Default value for temp hash calculation in unary operations
string private constant DEFAULT_VALUE = "0";
function convertInt32ToUint256(int32 value) internal pure returns (uint256) {
if (value < 0) {
revert SecurityZoneOutOfBounds(value);
}
return uint256(uint32(value));
}
function isInitialized(uint256 hash) internal pure returns (bool) {
return hash != 0;
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(ebool v) internal pure returns (bool) {
return isInitialized(ebool.unwrap(v));
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(euint8 v) internal pure returns (bool) {
return isInitialized(euint8.unwrap(v));
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(euint16 v) internal pure returns (bool) {
return isInitialized(euint16.unwrap(v));
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(euint32 v) internal pure returns (bool) {
return isInitialized(euint32.unwrap(v));
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(euint64 v) internal pure returns (bool) {
return isInitialized(euint64.unwrap(v));
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(euint128 v) internal pure returns (bool) {
return isInitialized(euint128.unwrap(v));
}
// Return true if the encrypted integer is initialized and false otherwise.
function isInitialized(euint256 v) internal pure returns (bool) {
return isInitialized(euint256.unwrap(v));
}
function isInitialized(eaddress v) internal pure returns (bool) {
return isInitialized(eaddress.unwrap(v));
}
function createUint256Inputs(uint256 input1) internal pure returns (uint256[] memory) {
uint256[] memory inputs = new uint256[](1);
inputs[0] = input1;
return inputs;
}
function createUint256Inputs(uint256 input1, uint256 input2) internal pure returns (uint256[] memory) {
uint256[] memory inputs = new uint256[](2);
inputs[0] = input1;
inputs[1] = input2;
return inputs;
}
function createUint256Inputs(uint256 input1, uint256 input2, uint256 input3) internal pure returns (uint256[] memory) {
uint256[] memory inputs = new uint256[](3);
inputs[0] = input1;
inputs[1] = input2;
inputs[2] = input3;
return inputs;
}
}
library Impl {
function trivialEncrypt(uint256 value, uint8 toType, int32 securityZone) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(toType, FunctionId.trivialEncrypt, new uint256[](0), Common.createUint256Inputs(value, toType, Common.convertInt32ToUint256(securityZone)));
}
function cast(uint256 key, uint8 toType) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(toType, FunctionId.cast, Common.createUint256Inputs(key), Common.createUint256Inputs(toType));
}
function select(uint8 returnType, ebool control, uint256 ifTrue, uint256 ifFalse) internal returns (uint256 result) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(returnType,
FunctionId.select,
Common.createUint256Inputs(ebool.unwrap(control), ifTrue, ifFalse),
new uint256[](0));
}
function mathOp(uint8 returnType, uint256 lhs, uint256 rhs, FunctionId functionId) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(returnType, functionId, Common.createUint256Inputs(lhs, rhs), new uint256[](0));
}
function decrypt(uint256 input) internal returns (uint256) {
ITaskManager(TASK_MANAGER_ADDRESS).createDecryptTask(input, msg.sender);
return input;
}
function getDecryptResult(uint256 input) internal view returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).getDecryptResult(input);
}
function getDecryptResultSafe(uint256 input) internal view returns (uint256 result, bool decrypted) {
return ITaskManager(TASK_MANAGER_ADDRESS).getDecryptResultSafe(input);
}
function not(uint8 returnType, uint256 input) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(returnType, FunctionId.not, Common.createUint256Inputs(input), new uint256[](0));
}
function square(uint8 returnType, uint256 input) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(returnType, FunctionId.square, Common.createUint256Inputs(input), new uint256[](0));
}
function verifyInput(EncryptedInput memory input) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).verifyInput(input, msg.sender);
}
/// @notice Generates a random value of a given type with the given seed, for the provided securityZone
/// @dev Calls the desired function
/// @param uintType the type of the random value to generate
/// @param seed the seed to use to create a random value from
/// @param securityZone the security zone to use for the random value
function random(uint8 uintType, uint64 seed, int32 securityZone) internal returns (uint256) {
return ITaskManager(TASK_MANAGER_ADDRESS).createTask(uintType, FunctionId.random, new uint256[](0), Common.createUint256Inputs(seed, Common.convertInt32ToUint256(securityZone)));
}
/// @notice Generates a random value of a given type with the given seed
/// @dev Calls the desired function
/// @param uintType the type of the random value to generate
/// @param seed the seed to use to create a random value from
function random(uint8 uintType, uint32 seed) internal returns (uint256) {
return random(uintType, seed, 0);
}
/// @notice Generates a random value of a given type
/// @dev Calls the desired function
/// @param uintType the type of the random value to generate
function random(uint8 uintType) internal returns (uint256) {
return random(uintType, 0, 0);
}
}
library FHE {
error InvalidEncryptedInput(uint8 got, uint8 expected);
/// @notice Perform the addition operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted addition
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the addition result
function add(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.add));
}
/// @notice Perform the addition operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted addition
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the addition result
function add(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.add));
}
/// @notice Perform the addition operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted addition
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the addition result
function add(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.add));
}
/// @notice Perform the addition operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted addition
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the addition result
function add(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.add));
}
/// @notice Perform the addition operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted addition
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the addition result
function add(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.add));
}
/// @notice Perform the addition operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted addition
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the addition result
function add(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.add));
}
/// @notice Perform the less than or equal to operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type ebool containing the comparison result
function lte(euint8 lhs, euint8 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.lte));
}
/// @notice Perform the less than or equal to operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type ebool containing the comparison result
function lte(euint16 lhs, euint16 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.lte));
}
/// @notice Perform the less than or equal to operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type ebool containing the comparison result
function lte(euint32 lhs, euint32 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.lte));
}
/// @notice Perform the less than or equal to operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type ebool containing the comparison result
function lte(euint64 lhs, euint64 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.lte));
}
/// @notice Perform the less than or equal to operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type ebool containing the comparison result
function lte(euint128 lhs, euint128 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.lte));
}
/// @notice Perform the less than or equal to operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type ebool containing the comparison result
function lte(euint256 lhs, euint256 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.lte));
}
/// @notice Perform the subtraction operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted subtraction
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the subtraction result
function sub(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.sub));
}
/// @notice Perform the subtraction operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted subtraction
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the subtraction result
function sub(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.sub));
}
/// @notice Perform the subtraction operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted subtraction
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the subtraction result
function sub(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.sub));
}
/// @notice Perform the subtraction operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted subtraction
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the subtraction result
function sub(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.sub));
}
/// @notice Perform the subtraction operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted subtraction
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the subtraction result
function sub(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.sub));
}
/// @notice Perform the subtraction operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted subtraction
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the subtraction result
function sub(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.sub));
}
/// @notice Perform the multiplication operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted multiplication
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the multiplication result
function mul(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.mul));
}
/// @notice Perform the multiplication operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted multiplication
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the multiplication result
function mul(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.mul));
}
/// @notice Perform the multiplication operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted multiplication
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the multiplication result
function mul(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.mul));
}
/// @notice Perform the multiplication operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted multiplication
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the multiplication result
function mul(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.mul));
}
/// @notice Perform the multiplication operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted multiplication
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the multiplication result
function mul(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.mul));
}
/// @notice Perform the multiplication operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted multiplication
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the multiplication result
function mul(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.mul));
}
/// @notice Perform the less than operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type ebool containing the comparison result
function lt(euint8 lhs, euint8 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.lt));
}
/// @notice Perform the less than operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type ebool containing the comparison result
function lt(euint16 lhs, euint16 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.lt));
}
/// @notice Perform the less than operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type ebool containing the comparison result
function lt(euint32 lhs, euint32 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.lt));
}
/// @notice Perform the less than operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type ebool containing the comparison result
function lt(euint64 lhs, euint64 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.lt));
}
/// @notice Perform the less than operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type ebool containing the comparison result
function lt(euint128 lhs, euint128 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.lt));
}
/// @notice Perform the less than operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type ebool containing the comparison result
function lt(euint256 lhs, euint256 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.lt));
}
/// @notice Perform the division operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted division
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the division result
function div(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.div));
}
/// @notice Perform the division operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted division
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the division result
function div(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.div));
}
/// @notice Perform the division operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted division
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the division result
function div(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.div));
}
/// @notice Perform the division operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted division
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the division result
function div(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.div));
}
/// @notice Perform the division operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted division
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the division result
function div(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.div));
}
/// @notice Perform the division operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted division
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the division result
function div(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.div));
}
/// @notice Perform the greater than operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type ebool containing the comparison result
function gt(euint8 lhs, euint8 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.gt));
}
/// @notice Perform the greater than operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type ebool containing the comparison result
function gt(euint16 lhs, euint16 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.gt));
}
/// @notice Perform the greater than operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type ebool containing the comparison result
function gt(euint32 lhs, euint32 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.gt));
}
/// @notice Perform the greater than operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type ebool containing the comparison result
function gt(euint64 lhs, euint64 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.gt));
}
/// @notice Perform the greater than operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type ebool containing the comparison result
function gt(euint128 lhs, euint128 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.gt));
}
/// @notice Perform the greater than operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type ebool containing the comparison result
function gt(euint256 lhs, euint256 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.gt));
}
/// @notice Perform the greater than or equal to operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type ebool containing the comparison result
function gte(euint8 lhs, euint8 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.gte));
}
/// @notice Perform the greater than or equal to operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type ebool containing the comparison result
function gte(euint16 lhs, euint16 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.gte));
}
/// @notice Perform the greater than or equal to operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type ebool containing the comparison result
function gte(euint32 lhs, euint32 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.gte));
}
/// @notice Perform the greater than or equal to operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type ebool containing the comparison result
function gte(euint64 lhs, euint64 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.gte));
}
/// @notice Perform the greater than or equal to operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type ebool containing the comparison result
function gte(euint128 lhs, euint128 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.gte));
}
/// @notice Perform the greater than or equal to operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted comparison
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type ebool containing the comparison result
function gte(euint256 lhs, euint256 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.gte));
}
/// @notice Perform the remainder operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted remainder calculation
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the remainder result
function rem(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.rem));
}
/// @notice Perform the remainder operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted remainder calculation
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the remainder result
function rem(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.rem));
}
/// @notice Perform the remainder operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted remainder calculation
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the remainder result
function rem(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.rem));
}
/// @notice Perform the remainder operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted remainder calculation
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the remainder result
function rem(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.rem));
}
/// @notice Perform the remainder operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted remainder calculation
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the remainder result
function rem(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.rem));
}
/// @notice Perform the remainder operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted remainder calculation
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the remainder result
function rem(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.rem));
}
/// @notice Perform the bitwise AND operation on two parameters of type ebool
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return result of type ebool containing the AND result
function and(ebool lhs, ebool rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEbool(true);
}
if (!Common.isInitialized(rhs)) {
rhs = asEbool(true);
}
return ebool.wrap(Impl.mathOp(Utils.EBOOL_TFHE, ebool.unwrap(lhs), ebool.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise AND operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the AND result
function and(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise AND operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the AND result
function and(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise AND operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the AND result
function and(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise AND operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the AND result
function and(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise AND operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the AND result
function and(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise AND operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted bitwise AND
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the AND result
function and(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.and));
}
/// @notice Perform the bitwise OR operation on two parameters of type ebool
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return result of type ebool containing the OR result
function or(ebool lhs, ebool rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEbool(true);
}
if (!Common.isInitialized(rhs)) {
rhs = asEbool(true);
}
return ebool.wrap(Impl.mathOp(Utils.EBOOL_TFHE, ebool.unwrap(lhs), ebool.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise OR operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the OR result
function or(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise OR operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the OR result
function or(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise OR operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the OR result
function or(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise OR operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the OR result
function or(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise OR operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the OR result
function or(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise OR operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted bitwise OR
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the OR result
function or(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.or));
}
/// @notice Perform the bitwise XOR operation on two parameters of type ebool
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return result of type ebool containing the XOR result
function xor(ebool lhs, ebool rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEbool(true);
}
if (!Common.isInitialized(rhs)) {
rhs = asEbool(true);
}
return ebool.wrap(Impl.mathOp(Utils.EBOOL_TFHE, ebool.unwrap(lhs), ebool.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the bitwise XOR operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the XOR result
function xor(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the bitwise XOR operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the XOR result
function xor(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the bitwise XOR operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the XOR result
function xor(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the bitwise XOR operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the XOR result
function xor(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the bitwise XOR operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the XOR result
function xor(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the bitwise XOR operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted bitwise XOR
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the XOR result
function xor(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.xor));
}
/// @notice Perform the equality operation on two parameters of type ebool
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return result of type ebool containing the equality result
function eq(ebool lhs, ebool rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEbool(true);
}
if (!Common.isInitialized(rhs)) {
rhs = asEbool(true);
}
return ebool.wrap(Impl.mathOp(Utils.EBOOL_TFHE, ebool.unwrap(lhs), ebool.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type ebool containing the equality result
function eq(euint8 lhs, euint8 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type ebool containing the equality result
function eq(euint16 lhs, euint16 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type ebool containing the equality result
function eq(euint32 lhs, euint32 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type ebool containing the equality result
function eq(euint64 lhs, euint64 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type ebool containing the equality result
function eq(euint128 lhs, euint128 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type ebool containing the equality result
function eq(euint256 lhs, euint256 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the equality operation on two parameters of type eaddress
/// @dev Verifies that inputs are initialized, performs encrypted equality check
/// @param lhs input of type eaddress
/// @param rhs second input of type eaddress
/// @return result of type ebool containing the equality result
function eq(eaddress lhs, eaddress rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEaddress(address(0));
}
if (!Common.isInitialized(rhs)) {
rhs = asEaddress(address(0));
}
return ebool.wrap(Impl.mathOp(Utils.EADDRESS_TFHE, eaddress.unwrap(lhs), eaddress.unwrap(rhs), FunctionId.eq));
}
/// @notice Perform the inequality operation on two parameters of type ebool
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return result of type ebool containing the inequality result
function ne(ebool lhs, ebool rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEbool(true);
}
if (!Common.isInitialized(rhs)) {
rhs = asEbool(true);
}
return ebool.wrap(Impl.mathOp(Utils.EBOOL_TFHE, ebool.unwrap(lhs), ebool.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type ebool containing the inequality result
function ne(euint8 lhs, euint8 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type ebool containing the inequality result
function ne(euint16 lhs, euint16 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type ebool containing the inequality result
function ne(euint32 lhs, euint32 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type ebool containing the inequality result
function ne(euint64 lhs, euint64 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type ebool containing the inequality result
function ne(euint128 lhs, euint128 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type ebool containing the inequality result
function ne(euint256 lhs, euint256 rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return ebool.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the inequality operation on two parameters of type eaddress
/// @dev Verifies that inputs are initialized, performs encrypted inequality check
/// @param lhs input of type eaddress
/// @param rhs second input of type eaddress
/// @return result of type ebool containing the inequality result
function ne(eaddress lhs, eaddress rhs) internal returns (ebool) {
if (!Common.isInitialized(lhs)) {
lhs = asEaddress(address(0));
}
if (!Common.isInitialized(rhs)) {
rhs = asEaddress(address(0));
}
return ebool.wrap(Impl.mathOp(Utils.EADDRESS_TFHE, eaddress.unwrap(lhs), eaddress.unwrap(rhs), FunctionId.ne));
}
/// @notice Perform the minimum operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted minimum comparison
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the minimum value
function min(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.min));
}
/// @notice Perform the minimum operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted minimum comparison
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the minimum value
function min(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.min));
}
/// @notice Perform the minimum operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted minimum comparison
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the minimum value
function min(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.min));
}
/// @notice Perform the minimum operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted minimum comparison
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the minimum value
function min(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.min));
}
/// @notice Perform the minimum operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted minimum comparison
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the minimum value
function min(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.min));
}
/// @notice Perform the minimum operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted minimum comparison
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the minimum value
function min(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.min));
}
/// @notice Perform the maximum operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted maximum calculation
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the maximum result
function max(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.max));
}
/// @notice Perform the maximum operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted maximum calculation
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the maximum result
function max(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.max));
}
/// @notice Perform the maximum operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted maximum calculation
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the maximum result
function max(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.max));
}
/// @notice Perform the maximum operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted maximum comparison
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the maximum value
function max(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.max));
}
/// @notice Perform the maximum operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted maximum comparison
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the maximum value
function max(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.max));
}
/// @notice Perform the maximum operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted maximum comparison
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the maximum value
function max(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.max));
}
/// @notice Perform the shift left operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted left shift
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the left shift result
function shl(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.shl));
}
/// @notice Perform the shift left operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted left shift
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the left shift result
function shl(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.shl));
}
/// @notice Perform the shift left operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted left shift
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the left shift result
function shl(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.shl));
}
/// @notice Perform the shift left operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted left shift
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the left shift result
function shl(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.shl));
}
/// @notice Perform the shift left operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted left shift
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the left shift result
function shl(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.shl));
}
/// @notice Perform the shift left operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted left shift
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the left shift result
function shl(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.shl));
}
/// @notice Perform the shift right operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted right shift
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the right shift result
function shr(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.shr));
}
/// @notice Perform the shift right operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted right shift
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the right shift result
function shr(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.shr));
}
/// @notice Perform the shift right operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted right shift
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the right shift result
function shr(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.shr));
}
/// @notice Perform the shift right operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted right shift
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the right shift result
function shr(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.shr));
}
/// @notice Perform the shift right operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted right shift
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the right shift result
function shr(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.shr));
}
/// @notice Perform the shift right operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted right shift
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the right shift result
function shr(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.shr));
}
/// @notice Perform the rol operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted left rotation
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the left rotation result
function rol(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.rol));
}
/// @notice Perform the rotate left operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted left rotation
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the left rotation result
function rol(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.rol));
}
/// @notice Perform the rotate left operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted left rotation
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the left rotation result
function rol(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.rol));
}
/// @notice Perform the rotate left operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted left rotation
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the left rotation result
function rol(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.rol));
}
/// @notice Perform the rotate left operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted left rotation
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the left rotation result
function rol(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.rol));
}
/// @notice Perform the rotate left operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted left rotation
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the left rotation result
function rol(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.rol));
}
/// @notice Perform the rotate right operation on two parameters of type euint8
/// @dev Verifies that inputs are initialized, performs encrypted right rotation
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return result of type euint8 containing the right rotation result
function ror(euint8 lhs, euint8 rhs) internal returns (euint8) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint8(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint8(0);
}
return euint8.wrap(Impl.mathOp(Utils.EUINT8_TFHE, euint8.unwrap(lhs), euint8.unwrap(rhs), FunctionId.ror));
}
/// @notice Perform the rotate right operation on two parameters of type euint16
/// @dev Verifies that inputs are initialized, performs encrypted right rotation
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return result of type euint16 containing the right rotation result
function ror(euint16 lhs, euint16 rhs) internal returns (euint16) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint16(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint16(0);
}
return euint16.wrap(Impl.mathOp(Utils.EUINT16_TFHE, euint16.unwrap(lhs), euint16.unwrap(rhs), FunctionId.ror));
}
/// @notice Perform the rotate right operation on two parameters of type euint32
/// @dev Verifies that inputs are initialized, performs encrypted right rotation
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return result of type euint32 containing the right rotation result
function ror(euint32 lhs, euint32 rhs) internal returns (euint32) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint32(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint32(0);
}
return euint32.wrap(Impl.mathOp(Utils.EUINT32_TFHE, euint32.unwrap(lhs), euint32.unwrap(rhs), FunctionId.ror));
}
/// @notice Perform the rotate right operation on two parameters of type euint64
/// @dev Verifies that inputs are initialized, performs encrypted right rotation
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return result of type euint64 containing the right rotation result
function ror(euint64 lhs, euint64 rhs) internal returns (euint64) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint64(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint64(0);
}
return euint64.wrap(Impl.mathOp(Utils.EUINT64_TFHE, euint64.unwrap(lhs), euint64.unwrap(rhs), FunctionId.ror));
}
/// @notice Perform the rotate right operation on two parameters of type euint128
/// @dev Verifies that inputs are initialized, performs encrypted right rotation
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return result of type euint128 containing the right rotation result
function ror(euint128 lhs, euint128 rhs) internal returns (euint128) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint128(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint128(0);
}
return euint128.wrap(Impl.mathOp(Utils.EUINT128_TFHE, euint128.unwrap(lhs), euint128.unwrap(rhs), FunctionId.ror));
}
/// @notice Perform the rotate right operation on two parameters of type euint256
/// @dev Verifies that inputs are initialized, performs encrypted right rotation
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return result of type euint256 containing the right rotation result
function ror(euint256 lhs, euint256 rhs) internal returns (euint256) {
if (!Common.isInitialized(lhs)) {
lhs = asEuint256(0);
}
if (!Common.isInitialized(rhs)) {
rhs = asEuint256(0);
}
return euint256.wrap(Impl.mathOp(Utils.EUINT256_TFHE, euint256.unwrap(lhs), euint256.unwrap(rhs), FunctionId.ror));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(ebool input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
ebool.wrap(Impl.decrypt(ebool.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(euint8 input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEuint8(0);
}
euint8.wrap(Impl.decrypt(euint8.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(euint16 input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEuint16(0);
}
euint16.wrap(Impl.decrypt(euint16.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(euint32 input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEuint32(0);
}
euint32.wrap(Impl.decrypt(euint32.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(euint64 input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEuint64(0);
}
euint64.wrap(Impl.decrypt(euint64.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(euint128 input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEuint128(0);
}
euint128.wrap(Impl.decrypt(euint128.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(euint256 input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEuint256(0);
}
euint256.wrap(Impl.decrypt(euint256.unwrap(input1)));
}
/// @notice Performs the async decrypt operation on a ciphertext
/// @dev The decrypted output should be asynchronously handled by the IAsyncFHEReceiver implementation
/// @param input1 the input ciphertext
function decrypt(eaddress input1) internal {
if (!Common.isInitialized(input1)) {
input1 = asEaddress(address(0));
}
Impl.decrypt(eaddress.unwrap(input1));
}
/// @notice Gets the decrypted value from a previously decrypted ebool ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The ebool ciphertext to get the decrypted value from
/// @return The decrypted boolean value
function getDecryptResult(ebool input1) internal view returns (bool) {
uint256 result = Impl.getDecryptResult(ebool.unwrap(input1));
return result != 0;
}
/// @notice Gets the decrypted value from a previously decrypted euint8 ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The euint8 ciphertext to get the decrypted value from
/// @return The decrypted uint8 value
function getDecryptResult(euint8 input1) internal view returns (uint8) {
return uint8(Impl.getDecryptResult(euint8.unwrap(input1)));
}
/// @notice Gets the decrypted value from a previously decrypted euint16 ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The euint16 ciphertext to get the decrypted value from
/// @return The decrypted uint16 value
function getDecryptResult(euint16 input1) internal view returns (uint16) {
return uint16(Impl.getDecryptResult(euint16.unwrap(input1)));
}
/// @notice Gets the decrypted value from a previously decrypted euint32 ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The euint32 ciphertext to get the decrypted value from
/// @return The decrypted uint32 value
function getDecryptResult(euint32 input1) internal view returns (uint32) {
return uint32(Impl.getDecryptResult(euint32.unwrap(input1)));
}
/// @notice Gets the decrypted value from a previously decrypted euint64 ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The euint64 ciphertext to get the decrypted value from
/// @return The decrypted uint64 value
function getDecryptResult(euint64 input1) internal view returns (uint64) {
return uint64(Impl.getDecryptResult(euint64.unwrap(input1)));
}
/// @notice Gets the decrypted value from a previously decrypted euint128 ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The euint128 ciphertext to get the decrypted value from
/// @return The decrypted uint128 value
function getDecryptResult(euint128 input1) internal view returns (uint128) {
return uint128(Impl.getDecryptResult(euint128.unwrap(input1)));
}
/// @notice Gets the decrypted value from a previously decrypted euint256 ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The euint256 ciphertext to get the decrypted value from
/// @return The decrypted uint256 value
function getDecryptResult(euint256 input1) internal view returns (uint256) {
return uint256(Impl.getDecryptResult(euint256.unwrap(input1)));
}
/// @notice Gets the decrypted value from a previously decrypted eaddress ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The eaddress ciphertext to get the decrypted value from
/// @return The decrypted address value
function getDecryptResult(eaddress input1) internal view returns (address) {
return address(uint160(Impl.getDecryptResult(eaddress.unwrap(input1))));
}
/// @notice Gets the decrypted value from a previously decrypted raw ciphertext
/// @dev This function will revert if the ciphertext is not yet decrypted. Use getDecryptResultSafe for a non-reverting version.
/// @param input1 The raw ciphertext to get the decrypted value from
/// @return The decrypted uint256 value
function getDecryptResult(uint256 input1) internal view returns (uint256) {
return Impl.getDecryptResult(input1);
}
/// @notice Safely gets the decrypted value from an ebool ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The ebool ciphertext to get the decrypted value from
/// @return result The decrypted boolean value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(ebool input1) internal view returns (bool result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(ebool.unwrap(input1));
return (_result != 0, _decrypted);
}
/// @notice Safely gets the decrypted value from a euint8 ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The euint8 ciphertext to get the decrypted value from
/// @return result The decrypted uint8 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(euint8 input1) internal view returns (uint8 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(euint8.unwrap(input1));
return (uint8(_result), _decrypted);
}
/// @notice Safely gets the decrypted value from a euint16 ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The euint16 ciphertext to get the decrypted value from
/// @return result The decrypted uint16 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(euint16 input1) internal view returns (uint16 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(euint16.unwrap(input1));
return (uint16(_result), _decrypted);
}
/// @notice Safely gets the decrypted value from a euint32 ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The euint32 ciphertext to get the decrypted value from
/// @return result The decrypted uint32 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(euint32 input1) internal view returns (uint32 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(euint32.unwrap(input1));
return (uint32(_result), _decrypted);
}
/// @notice Safely gets the decrypted value from a euint64 ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The euint64 ciphertext to get the decrypted value from
/// @return result The decrypted uint64 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(euint64 input1) internal view returns (uint64 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(euint64.unwrap(input1));
return (uint64(_result), _decrypted);
}
/// @notice Safely gets the decrypted value from a euint128 ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The euint128 ciphertext to get the decrypted value from
/// @return result The decrypted uint128 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(euint128 input1) internal view returns (uint128 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(euint128.unwrap(input1));
return (uint128(_result), _decrypted);
}
/// @notice Safely gets the decrypted value from a euint256 ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The euint256 ciphertext to get the decrypted value from
/// @return result The decrypted uint256 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(euint256 input1) internal view returns (uint256 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(euint256.unwrap(input1));
return (uint256(_result), _decrypted);
}
/// @notice Safely gets the decrypted value from an eaddress ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The eaddress ciphertext to get the decrypted value from
/// @return result The decrypted address value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(eaddress input1) internal view returns (address result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(eaddress.unwrap(input1));
return (address(uint160(_result)), _decrypted);
}
/// @notice Safely gets the decrypted value from a raw ciphertext
/// @dev Returns the decrypted value and a flag indicating whether the decryption has finished
/// @param input1 The raw ciphertext to get the decrypted value from
/// @return result The decrypted uint256 value
/// @return decrypted Flag indicating if the value was successfully decrypted
function getDecryptResultSafe(uint256 input1) internal view returns (uint256 result, bool decrypted) {
(uint256 _result, bool _decrypted) = Impl.getDecryptResultSafe(input1);
return (_result, _decrypted);
}
/// @notice Performs a multiplexer operation between two ebool values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type ebool
/// @param input3 Second choice of type ebool
/// @return result of type ebool containing the selected value
function select(ebool input1, ebool input2, ebool input3) internal returns (ebool) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEbool(false);
}
if (!Common.isInitialized(input3)) {
input3 = asEbool(false);
}
return ebool.wrap(Impl.select(Utils.EBOOL_TFHE, input1, ebool.unwrap(input2), ebool.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two euint8 values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type euint8
/// @param input3 Second choice of type euint8
/// @return result of type euint8 containing the selected value
function select(ebool input1, euint8 input2, euint8 input3) internal returns (euint8) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEuint8(0);
}
if (!Common.isInitialized(input3)) {
input3 = asEuint8(0);
}
return euint8.wrap(Impl.select(Utils.EUINT8_TFHE, input1, euint8.unwrap(input2), euint8.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two euint16 values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type euint16
/// @param input3 Second choice of type euint16
/// @return result of type euint16 containing the selected value
function select(ebool input1, euint16 input2, euint16 input3) internal returns (euint16) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEuint16(0);
}
if (!Common.isInitialized(input3)) {
input3 = asEuint16(0);
}
return euint16.wrap(Impl.select(Utils.EUINT16_TFHE, input1, euint16.unwrap(input2), euint16.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two euint32 values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type euint32
/// @param input3 Second choice of type euint32
/// @return result of type euint32 containing the selected value
function select(ebool input1, euint32 input2, euint32 input3) internal returns (euint32) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEuint32(0);
}
if (!Common.isInitialized(input3)) {
input3 = asEuint32(0);
}
return euint32.wrap(Impl.select(Utils.EUINT32_TFHE, input1, euint32.unwrap(input2), euint32.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two euint64 values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type euint64
/// @param input3 Second choice of type euint64
/// @return result of type euint64 containing the selected value
function select(ebool input1, euint64 input2, euint64 input3) internal returns (euint64) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEuint64(0);
}
if (!Common.isInitialized(input3)) {
input3 = asEuint64(0);
}
return euint64.wrap(Impl.select(Utils.EUINT64_TFHE, input1, euint64.unwrap(input2), euint64.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two euint128 values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type euint128
/// @param input3 Second choice of type euint128
/// @return result of type euint128 containing the selected value
function select(ebool input1, euint128 input2, euint128 input3) internal returns (euint128) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEuint128(0);
}
if (!Common.isInitialized(input3)) {
input3 = asEuint128(0);
}
return euint128.wrap(Impl.select(Utils.EUINT128_TFHE, input1, euint128.unwrap(input2), euint128.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two euint256 values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type euint256
/// @param input3 Second choice of type euint256
/// @return result of type euint256 containing the selected value
function select(ebool input1, euint256 input2, euint256 input3) internal returns (euint256) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEuint256(0);
}
if (!Common.isInitialized(input3)) {
input3 = asEuint256(0);
}
return euint256.wrap(Impl.select(Utils.EUINT256_TFHE, input1, euint256.unwrap(input2), euint256.unwrap(input3)));
}
/// @notice Performs a multiplexer operation between two eaddress values based on a selector
/// @dev If input1 is true, returns input2, otherwise returns input3. All inputs are initialized to defaults if not set.
/// @param input1 The selector of type ebool
/// @param input2 First choice of type eaddress
/// @param input3 Second choice of type eaddress
/// @return result of type eaddress containing the selected value
function select(ebool input1, eaddress input2, eaddress input3) internal returns (eaddress) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
if (!Common.isInitialized(input2)) {
input2 = asEaddress(address(0));
}
if (!Common.isInitialized(input3)) {
input3 = asEaddress(address(0));
}
return eaddress.wrap(Impl.select(Utils.EADDRESS_TFHE, input1, eaddress.unwrap(input2), eaddress.unwrap(input3)));
}
/// @notice Performs the not operation on a ciphertext
/// @dev Verifies that the input value matches a valid ciphertext.
/// @param input1 the input ciphertext
function not(ebool input1) internal returns (ebool) {
if (!Common.isInitialized(input1)) {
input1 = asEbool(false);
}
return ebool.wrap(Impl.not(Utils.EBOOL_TFHE, ebool.unwrap(input1)));
}
/// @notice Performs the not operation on a ciphertext
/// @dev Verifies that the input value matches a valid ciphertext.
/// @param input1 the input ciphertext
function not(euint8 input1) internal returns (euint8) {
if (!Common.isInitialized(input1)) {
input1 = asEuint8(0);
}
return euint8.wrap(Impl.not(Utils.EUINT8_TFHE, euint8.unwrap(input1)));
}
/// @notice Performs the not operation on a ciphertext
/// @dev Verifies that the input value matches a valid ciphertext.
/// @param input1 the input ciphertext
function not(euint16 input1) internal returns (euint16) {
if (!Common.isInitialized(input1)) {
input1 = asEuint16(0);
}
return euint16.wrap(Impl.not(Utils.EUINT16_TFHE, euint16.unwrap(input1)));
}
/// @notice Performs the not operation on a ciphertext
/// @dev Verifies that the input value matches a valid ciphertext.
/// @param input1 the input ciphertext
function not(euint32 input1) internal returns (euint32) {
if (!Common.isInitialized(input1)) {
input1 = asEuint32(0);
}
return euint32.wrap(Impl.not(Utils.EUINT32_TFHE, euint32.unwrap(input1)));
}
/// @notice Performs the bitwise NOT operation on an encrypted 64-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// The operation inverts all bits of the input value.
/// @param input1 The input ciphertext to negate
/// @return An euint64 containing the bitwise NOT of the input
function not(euint64 input1) internal returns (euint64) {
if (!Common.isInitialized(input1)) {
input1 = asEuint64(0);
}
return euint64.wrap(Impl.not(Utils.EUINT64_TFHE, euint64.unwrap(input1)));
}
/// @notice Performs the bitwise NOT operation on an encrypted 128-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// The operation inverts all bits of the input value.
/// @param input1 The input ciphertext to negate
/// @return An euint128 containing the bitwise NOT of the input
function not(euint128 input1) internal returns (euint128) {
if (!Common.isInitialized(input1)) {
input1 = asEuint128(0);
}
return euint128.wrap(Impl.not(Utils.EUINT128_TFHE, euint128.unwrap(input1)));
}
/// @notice Performs the bitwise NOT operation on an encrypted 256-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// The operation inverts all bits of the input value.
/// @param input1 The input ciphertext to negate
/// @return An euint256 containing the bitwise NOT of the input
function not(euint256 input1) internal returns (euint256) {
if (!Common.isInitialized(input1)) {
input1 = asEuint256(0);
}
return euint256.wrap(Impl.not(Utils.EUINT256_TFHE, euint256.unwrap(input1)));
}
/// @notice Performs the square operation on an encrypted 8-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// Note: The result may overflow if input * input exceeds 8 bits.
/// @param input1 The input ciphertext to square
/// @return An euint8 containing the square of the input
function square(euint8 input1) internal returns (euint8) {
if (!Common.isInitialized(input1)) {
input1 = asEuint8(0);
}
return euint8.wrap(Impl.square(Utils.EUINT8_TFHE, euint8.unwrap(input1)));
}
/// @notice Performs the square operation on an encrypted 16-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// Note: The result may overflow if input * input exceeds 16 bits.
/// @param input1 The input ciphertext to square
/// @return An euint16 containing the square of the input
function square(euint16 input1) internal returns (euint16) {
if (!Common.isInitialized(input1)) {
input1 = asEuint16(0);
}
return euint16.wrap(Impl.square(Utils.EUINT16_TFHE, euint16.unwrap(input1)));
}
/// @notice Performs the square operation on an encrypted 32-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// Note: The result may overflow if input * input exceeds 32 bits.
/// @param input1 The input ciphertext to square
/// @return An euint32 containing the square of the input
function square(euint32 input1) internal returns (euint32) {
if (!Common.isInitialized(input1)) {
input1 = asEuint32(0);
}
return euint32.wrap(Impl.square(Utils.EUINT32_TFHE, euint32.unwrap(input1)));
}
/// @notice Performs the square operation on an encrypted 64-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// Note: The result may overflow if input * input exceeds 64 bits.
/// @param input1 The input ciphertext to square
/// @return An euint64 containing the square of the input
function square(euint64 input1) internal returns (euint64) {
if (!Common.isInitialized(input1)) {
input1 = asEuint64(0);
}
return euint64.wrap(Impl.square(Utils.EUINT64_TFHE, euint64.unwrap(input1)));
}
/// @notice Performs the square operation on an encrypted 128-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// Note: The result may overflow if input * input exceeds 128 bits.
/// @param input1 The input ciphertext to square
/// @return An euint128 containing the square of the input
function square(euint128 input1) internal returns (euint128) {
if (!Common.isInitialized(input1)) {
input1 = asEuint128(0);
}
return euint128.wrap(Impl.square(Utils.EUINT128_TFHE, euint128.unwrap(input1)));
}
/// @notice Performs the square operation on an encrypted 256-bit unsigned integer
/// @dev Verifies that the input is initialized, defaulting to 0 if not.
/// Note: The result may overflow if input * input exceeds 256 bits.
/// @param input1 The input ciphertext to square
/// @return An euint256 containing the square of the input
function square(euint256 input1) internal returns (euint256) {
if (!Common.isInitialized(input1)) {
input1 = asEuint256(0);
}
return euint256.wrap(Impl.square(Utils.EUINT256_TFHE, euint256.unwrap(input1)));
}
/// @notice Generates a random value of a euint8 type for provided securityZone
/// @dev Generates a cryptographically secure random 8-bit unsigned integer in encrypted form.
/// The generated value is fully encrypted and cannot be predicted by any party.
/// @param securityZone The security zone identifier to use for random value generation.
/// @return A randomly generated encrypted 8-bit unsigned integer (euint8)
function randomEuint8(int32 securityZone) internal returns (euint8) {
return euint8.wrap(Impl.random(Utils.EUINT8_TFHE, 0, securityZone));
}
/// @notice Generates a random value of a euint8 type
/// @dev Generates a cryptographically secure random 8-bit unsigned integer in encrypted form
/// using the default security zone (0). The generated value is fully encrypted and
/// cannot be predicted by any party.
/// @return A randomly generated encrypted 8-bit unsigned integer (euint8)
function randomEuint8() internal returns (euint8) {
return randomEuint8(0);
}
/// @notice Generates a random value of a euint16 type for provided securityZone
/// @dev Generates a cryptographically secure random 16-bit unsigned integer in encrypted form.
/// The generated value is fully encrypted and cannot be predicted by any party.
/// @param securityZone The security zone identifier to use for random value generation.
/// @return A randomly generated encrypted 16-bit unsigned integer (euint16)
function randomEuint16(int32 securityZone) internal returns (euint16) {
return euint16.wrap(Impl.random(Utils.EUINT16_TFHE, 0, securityZone));
}
/// @notice Generates a random value of a euint16 type
/// @dev Generates a cryptographically secure random 16-bit unsigned integer in encrypted form
/// using the default security zone (0). The generated value is fully encrypted and
/// cannot be predicted by any party.
/// @return A randomly generated encrypted 16-bit unsigned integer (euint16)
function randomEuint16() internal returns (euint16) {
return randomEuint16(0);
}
/// @notice Generates a random value of a euint32 type for provided securityZone
/// @dev Generates a cryptographically secure random 32-bit unsigned integer in encrypted form.
/// The generated value is fully encrypted and cannot be predicted by any party.
/// @param securityZone The security zone identifier to use for random value generation.
/// @return A randomly generated encrypted 32-bit unsigned integer (euint32)
function randomEuint32(int32 securityZone) internal returns (euint32) {
return euint32.wrap(Impl.random(Utils.EUINT32_TFHE, 0, securityZone));
}
/// @notice Generates a random value of a euint32 type
/// @dev Generates a cryptographically secure random 32-bit unsigned integer in encrypted form
/// using the default security zone (0). The generated value is fully encrypted and
/// cannot be predicted by any party.
/// @return A randomly generated encrypted 32-bit unsigned integer (euint32)
function randomEuint32() internal returns (euint32) {
return randomEuint32(0);
}
/// @notice Generates a random value of a euint64 type for provided securityZone
/// @dev Generates a cryptographically secure random 64-bit unsigned integer in encrypted form.
/// The generated value is fully encrypted and cannot be predicted by any party.
/// @param securityZone The security zone identifier to use for random value generation.
/// @return A randomly generated encrypted 64-bit unsigned integer (euint64)
function randomEuint64(int32 securityZone) internal returns (euint64) {
return euint64.wrap(Impl.random(Utils.EUINT64_TFHE, 0, securityZone));
}
/// @notice Generates a random value of a euint64 type
/// @dev Generates a cryptographically secure random 64-bit unsigned integer in encrypted form
/// using the default security zone (0). The generated value is fully encrypted and
/// cannot be predicted by any party.
/// @return A randomly generated encrypted 64-bit unsigned integer (euint64)
function randomEuint64() internal returns (euint64) {
return randomEuint64(0);
}
/// @notice Generates a random value of a euint128 type for provided securityZone
/// @dev Generates a cryptographically secure random 128-bit unsigned integer in encrypted form.
/// The generated value is fully encrypted and cannot be predicted by any party.
/// @param securityZone The security zone identifier to use for random value generation.
/// @return A randomly generated encrypted 128-bit unsigned integer (euint128)
function randomEuint128(int32 securityZone) internal returns (euint128) {
return euint128.wrap(Impl.random(Utils.EUINT128_TFHE, 0, securityZone));
}
/// @notice Generates a random value of a euint128 type
/// @dev Generates a cryptographically secure random 128-bit unsigned integer in encrypted form
/// using the default security zone (0). The generated value is fully encrypted and
/// cannot be predicted by any party.
/// @return A randomly generated encrypted 128-bit unsigned integer (euint128)
function randomEuint128() internal returns (euint128) {
return randomEuint128(0);
}
/// @notice Generates a random value of a euint256 type for provided securityZone
/// @dev Generates a cryptographically secure random 256-bit unsigned integer in encrypted form.
/// The generated value is fully encrypted and cannot be predicted by any party.
/// @param securityZone The security zone identifier to use for random value generation.
/// @return A randomly generated encrypted 256-bit unsigned integer (euint256)
function randomEuint256(int32 securityZone) internal returns (euint256) {
return euint256.wrap(Impl.random(Utils.EUINT256_TFHE, 0, securityZone));
}
/// @notice Generates a random value of a euint256 type
/// @dev Generates a cryptographically secure random 256-bit unsigned integer in encrypted form
/// using the default security zone (0). The generated value is fully encrypted and
/// cannot be predicted by any party.
/// @return A randomly generated encrypted 256-bit unsigned integer (euint256)
function randomEuint256() internal returns (euint256) {
return randomEuint256(0);
}
/// @notice Verifies and converts an inEbool input to an ebool encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An ebool containing the verified encrypted value
function asEbool(InEbool memory value) internal returns (ebool) {
uint8 expectedUtype = Utils.EBOOL_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return ebool.wrap(Impl.verifyInput(Utils.inputFromEbool(value)));
}
/// @notice Verifies and converts an InEuint8 input to an euint8 encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An euint8 containing the verified encrypted value
function asEuint8(InEuint8 memory value) internal returns (euint8) {
uint8 expectedUtype = Utils.EUINT8_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return euint8.wrap(Impl.verifyInput(Utils.inputFromEuint8(value)));
}
/// @notice Verifies and converts an InEuint16 input to an euint16 encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An euint16 containing the verified encrypted value
function asEuint16(InEuint16 memory value) internal returns (euint16) {
uint8 expectedUtype = Utils.EUINT16_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return euint16.wrap(Impl.verifyInput(Utils.inputFromEuint16(value)));
}
/// @notice Verifies and converts an InEuint32 input to an euint32 encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An euint32 containing the verified encrypted value
function asEuint32(InEuint32 memory value) internal returns (euint32) {
uint8 expectedUtype = Utils.EUINT32_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return euint32.wrap(Impl.verifyInput(Utils.inputFromEuint32(value)));
}
/// @notice Verifies and converts an InEuint64 input to an euint64 encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An euint64 containing the verified encrypted value
function asEuint64(InEuint64 memory value) internal returns (euint64) {
uint8 expectedUtype = Utils.EUINT64_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return euint64.wrap(Impl.verifyInput(Utils.inputFromEuint64(value)));
}
/// @notice Verifies and converts an InEuint128 input to an euint128 encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An euint128 containing the verified encrypted value
function asEuint128(InEuint128 memory value) internal returns (euint128) {
uint8 expectedUtype = Utils.EUINT128_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return euint128.wrap(Impl.verifyInput(Utils.inputFromEuint128(value)));
}
/// @notice Verifies and converts an InEuint256 input to an euint256 encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An euint256 containing the verified encrypted value
function asEuint256(InEuint256 memory value) internal returns (euint256) {
uint8 expectedUtype = Utils.EUINT256_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return euint256.wrap(Impl.verifyInput(Utils.inputFromEuint256(value)));
}
/// @notice Verifies and converts an InEaddress input to an eaddress encrypted type
/// @dev Verifies the input signature and security parameters before converting to the encrypted type
/// @param value The input value containing hash, type, security zone and signature
/// @return An eaddress containing the verified encrypted value
function asEaddress(InEaddress memory value) internal returns (eaddress) {
uint8 expectedUtype = Utils.EADDRESS_TFHE;
if (value.utype != expectedUtype) {
revert InvalidEncryptedInput(value.utype, expectedUtype);
}
return eaddress.wrap(Impl.verifyInput(Utils.inputFromEaddress(value)));
}
// ********** TYPE CASTING ************* //
/// @notice Converts a ebool to an euint8
function asEuint8(ebool value) internal returns (euint8) {
return euint8.wrap(Impl.cast(ebool.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a ebool to an euint16
function asEuint16(ebool value) internal returns (euint16) {
return euint16.wrap(Impl.cast(ebool.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a ebool to an euint32
function asEuint32(ebool value) internal returns (euint32) {
return euint32.wrap(Impl.cast(ebool.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a ebool to an euint64
function asEuint64(ebool value) internal returns (euint64) {
return euint64.wrap(Impl.cast(ebool.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a ebool to an euint128
function asEuint128(ebool value) internal returns (euint128) {
return euint128.wrap(Impl.cast(ebool.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a ebool to an euint256
function asEuint256(ebool value) internal returns (euint256) {
return euint256.wrap(Impl.cast(ebool.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a euint8 to an ebool
function asEbool(euint8 value) internal returns (ebool) {
return ne(value, asEuint8(0));
}
/// @notice Converts a euint8 to an euint16
function asEuint16(euint8 value) internal returns (euint16) {
return euint16.wrap(Impl.cast(euint8.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a euint8 to an euint32
function asEuint32(euint8 value) internal returns (euint32) {
return euint32.wrap(Impl.cast(euint8.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a euint8 to an euint64
function asEuint64(euint8 value) internal returns (euint64) {
return euint64.wrap(Impl.cast(euint8.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a euint8 to an euint128
function asEuint128(euint8 value) internal returns (euint128) {
return euint128.wrap(Impl.cast(euint8.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a euint8 to an euint256
function asEuint256(euint8 value) internal returns (euint256) {
return euint256.wrap(Impl.cast(euint8.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a euint16 to an ebool
function asEbool(euint16 value) internal returns (ebool) {
return ne(value, asEuint16(0));
}
/// @notice Converts a euint16 to an euint8
function asEuint8(euint16 value) internal returns (euint8) {
return euint8.wrap(Impl.cast(euint16.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a euint16 to an euint32
function asEuint32(euint16 value) internal returns (euint32) {
return euint32.wrap(Impl.cast(euint16.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a euint16 to an euint64
function asEuint64(euint16 value) internal returns (euint64) {
return euint64.wrap(Impl.cast(euint16.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a euint16 to an euint128
function asEuint128(euint16 value) internal returns (euint128) {
return euint128.wrap(Impl.cast(euint16.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a euint16 to an euint256
function asEuint256(euint16 value) internal returns (euint256) {
return euint256.wrap(Impl.cast(euint16.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a euint32 to an ebool
function asEbool(euint32 value) internal returns (ebool) {
return ne(value, asEuint32(0));
}
/// @notice Converts a euint32 to an euint8
function asEuint8(euint32 value) internal returns (euint8) {
return euint8.wrap(Impl.cast(euint32.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a euint32 to an euint16
function asEuint16(euint32 value) internal returns (euint16) {
return euint16.wrap(Impl.cast(euint32.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a euint32 to an euint64
function asEuint64(euint32 value) internal returns (euint64) {
return euint64.wrap(Impl.cast(euint32.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a euint32 to an euint128
function asEuint128(euint32 value) internal returns (euint128) {
return euint128.wrap(Impl.cast(euint32.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a euint32 to an euint256
function asEuint256(euint32 value) internal returns (euint256) {
return euint256.wrap(Impl.cast(euint32.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a euint64 to an ebool
function asEbool(euint64 value) internal returns (ebool) {
return ne(value, asEuint64(0));
}
/// @notice Converts a euint64 to an euint8
function asEuint8(euint64 value) internal returns (euint8) {
return euint8.wrap(Impl.cast(euint64.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a euint64 to an euint16
function asEuint16(euint64 value) internal returns (euint16) {
return euint16.wrap(Impl.cast(euint64.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a euint64 to an euint32
function asEuint32(euint64 value) internal returns (euint32) {
return euint32.wrap(Impl.cast(euint64.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a euint64 to an euint128
function asEuint128(euint64 value) internal returns (euint128) {
return euint128.wrap(Impl.cast(euint64.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a euint64 to an euint256
function asEuint256(euint64 value) internal returns (euint256) {
return euint256.wrap(Impl.cast(euint64.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a euint128 to an ebool
function asEbool(euint128 value) internal returns (ebool) {
return ne(value, asEuint128(0));
}
/// @notice Converts a euint128 to an euint8
function asEuint8(euint128 value) internal returns (euint8) {
return euint8.wrap(Impl.cast(euint128.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a euint128 to an euint16
function asEuint16(euint128 value) internal returns (euint16) {
return euint16.wrap(Impl.cast(euint128.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a euint128 to an euint32
function asEuint32(euint128 value) internal returns (euint32) {
return euint32.wrap(Impl.cast(euint128.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a euint128 to an euint64
function asEuint64(euint128 value) internal returns (euint64) {
return euint64.wrap(Impl.cast(euint128.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a euint128 to an euint256
function asEuint256(euint128 value) internal returns (euint256) {
return euint256.wrap(Impl.cast(euint128.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a euint256 to an ebool
function asEbool(euint256 value) internal returns (ebool) {
return ne(value, asEuint256(0));
}
/// @notice Converts a euint256 to an euint8
function asEuint8(euint256 value) internal returns (euint8) {
return euint8.wrap(Impl.cast(euint256.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a euint256 to an euint16
function asEuint16(euint256 value) internal returns (euint16) {
return euint16.wrap(Impl.cast(euint256.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a euint256 to an euint32
function asEuint32(euint256 value) internal returns (euint32) {
return euint32.wrap(Impl.cast(euint256.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a euint256 to an euint64
function asEuint64(euint256 value) internal returns (euint64) {
return euint64.wrap(Impl.cast(euint256.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a euint256 to an euint128
function asEuint128(euint256 value) internal returns (euint128) {
return euint128.wrap(Impl.cast(euint256.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a euint256 to an eaddress
function asEaddress(euint256 value) internal returns (eaddress) {
return eaddress.wrap(Impl.cast(euint256.unwrap(value), Utils.EADDRESS_TFHE));
}
/// @notice Converts a eaddress to an ebool
function asEbool(eaddress value) internal returns (ebool) {
return ne(value, asEaddress(address(0)));
}
/// @notice Converts a eaddress to an euint8
function asEuint8(eaddress value) internal returns (euint8) {
return euint8.wrap(Impl.cast(eaddress.unwrap(value), Utils.EUINT8_TFHE));
}
/// @notice Converts a eaddress to an euint16
function asEuint16(eaddress value) internal returns (euint16) {
return euint16.wrap(Impl.cast(eaddress.unwrap(value), Utils.EUINT16_TFHE));
}
/// @notice Converts a eaddress to an euint32
function asEuint32(eaddress value) internal returns (euint32) {
return euint32.wrap(Impl.cast(eaddress.unwrap(value), Utils.EUINT32_TFHE));
}
/// @notice Converts a eaddress to an euint64
function asEuint64(eaddress value) internal returns (euint64) {
return euint64.wrap(Impl.cast(eaddress.unwrap(value), Utils.EUINT64_TFHE));
}
/// @notice Converts a eaddress to an euint128
function asEuint128(eaddress value) internal returns (euint128) {
return euint128.wrap(Impl.cast(eaddress.unwrap(value), Utils.EUINT128_TFHE));
}
/// @notice Converts a eaddress to an euint256
function asEuint256(eaddress value) internal returns (euint256) {
return euint256.wrap(Impl.cast(eaddress.unwrap(value), Utils.EUINT256_TFHE));
}
/// @notice Converts a plaintext boolean value to a ciphertext ebool
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
/// @return A ciphertext representation of the input
function asEbool(bool value) internal returns (ebool) {
return asEbool(value, 0);
}
/// @notice Converts a plaintext boolean value to a ciphertext ebool, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
/// @return A ciphertext representation of the input
function asEbool(bool value, int32 securityZone) internal returns (ebool) {
uint256 sVal = 0;
if (value) {
sVal = 1;
}
uint256 ct = Impl.trivialEncrypt(sVal, Utils.EBOOL_TFHE, securityZone);
return ebool.wrap(ct);
}
/// @notice Converts a uint256 to an euint8
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint8(uint256 value) internal returns (euint8) {
return asEuint8(value, 0);
}
/// @notice Converts a uint256 to an euint8, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint8(uint256 value, int32 securityZone) internal returns (euint8) {
uint256 ct = Impl.trivialEncrypt(value, Utils.EUINT8_TFHE, securityZone);
return euint8.wrap(ct);
}
/// @notice Converts a uint256 to an euint16
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint16(uint256 value) internal returns (euint16) {
return asEuint16(value, 0);
}
/// @notice Converts a uint256 to an euint16, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint16(uint256 value, int32 securityZone) internal returns (euint16) {
uint256 ct = Impl.trivialEncrypt(value, Utils.EUINT16_TFHE, securityZone);
return euint16.wrap(ct);
}
/// @notice Converts a uint256 to an euint32
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint32(uint256 value) internal returns (euint32) {
return asEuint32(value, 0);
}
/// @notice Converts a uint256 to an euint32, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint32(uint256 value, int32 securityZone) internal returns (euint32) {
uint256 ct = Impl.trivialEncrypt(value, Utils.EUINT32_TFHE, securityZone);
return euint32.wrap(ct);
}
/// @notice Converts a uint256 to an euint64
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint64(uint256 value) internal returns (euint64) {
return asEuint64(value, 0);
}
/// @notice Converts a uint256 to an euint64, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint64(uint256 value, int32 securityZone) internal returns (euint64) {
uint256 ct = Impl.trivialEncrypt(value, Utils.EUINT64_TFHE, securityZone);
return euint64.wrap(ct);
}
/// @notice Converts a uint256 to an euint128
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint128(uint256 value) internal returns (euint128) {
return asEuint128(value, 0);
}
/// @notice Converts a uint256 to an euint128, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint128(uint256 value, int32 securityZone) internal returns (euint128) {
uint256 ct = Impl.trivialEncrypt(value, Utils.EUINT128_TFHE, securityZone);
return euint128.wrap(ct);
}
/// @notice Converts a uint256 to an euint256
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint256(uint256 value) internal returns (euint256) {
return asEuint256(value, 0);
}
/// @notice Converts a uint256 to an euint256, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
function asEuint256(uint256 value, int32 securityZone) internal returns (euint256) {
uint256 ct = Impl.trivialEncrypt(value, Utils.EUINT256_TFHE, securityZone);
return euint256.wrap(ct);
}
/// @notice Converts a address to an eaddress
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
/// Allows for a better user experience when working with eaddresses
function asEaddress(address value) internal returns (eaddress) {
return asEaddress(value, 0);
}
/// @notice Converts a address to an eaddress, specifying security zone
/// @dev Privacy: The input value is public, therefore the resulting ciphertext should be considered public until involved in an fhe operation
/// Allows for a better user experience when working with eaddresses
function asEaddress(address value, int32 securityZone) internal returns (eaddress) {
uint256 ct = Impl.trivialEncrypt(uint256(uint160(value)), Utils.EADDRESS_TFHE, securityZone);
return eaddress.wrap(ct);
}
/// @notice Grants permission to an account to operate on the encrypted boolean value
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted boolean value to grant access to
/// @param account The address being granted permission
function allow(ebool ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(ebool.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted 8-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted uint8 value to grant access to
/// @param account The address being granted permission
function allow(euint8 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint8.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted 16-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted uint16 value to grant access to
/// @param account The address being granted permission
function allow(euint16 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint16.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted 32-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted uint32 value to grant access to
/// @param account The address being granted permission
function allow(euint32 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint32.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted 64-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted uint64 value to grant access to
/// @param account The address being granted permission
function allow(euint64 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint64.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted 128-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted uint128 value to grant access to
/// @param account The address being granted permission
function allow(euint128 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint128.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted 256-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted uint256 value to grant access to
/// @param account The address being granted permission
function allow(euint256 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint256.unwrap(ctHash), account);
}
/// @notice Grants permission to an account to operate on the encrypted address
/// @dev Allows the specified account to access the ciphertext
/// @param ctHash The encrypted address value to grant access to
/// @param account The address being granted permission
function allow(eaddress ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(eaddress.unwrap(ctHash), account);
}
/// @notice Grants global permission to operate on the encrypted boolean value
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted boolean value to grant global access to
function allowGlobal(ebool ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(ebool.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted 8-bit unsigned integer
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted uint8 value to grant global access to
function allowGlobal(euint8 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(euint8.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted 16-bit unsigned integer
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted uint16 value to grant global access to
function allowGlobal(euint16 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(euint16.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted 32-bit unsigned integer
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted uint32 value to grant global access to
function allowGlobal(euint32 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(euint32.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted 64-bit unsigned integer
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted uint64 value to grant global access to
function allowGlobal(euint64 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(euint64.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted 128-bit unsigned integer
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted uint128 value to grant global access to
function allowGlobal(euint128 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(euint128.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted 256-bit unsigned integer
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted uint256 value to grant global access to
function allowGlobal(euint256 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(euint256.unwrap(ctHash));
}
/// @notice Grants global permission to operate on the encrypted address
/// @dev Allows all accounts to access the ciphertext
/// @param ctHash The encrypted address value to grant global access to
function allowGlobal(eaddress ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowGlobal(eaddress.unwrap(ctHash));
}
/// @notice Checks if an account has permission to operate on the encrypted boolean value
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted boolean value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(ebool ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(ebool.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted 8-bit unsigned integer
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted uint8 value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(euint8 ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(euint8.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted 16-bit unsigned integer
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted uint16 value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(euint16 ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(euint16.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted 32-bit unsigned integer
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted uint32 value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(euint32 ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(euint32.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted 64-bit unsigned integer
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted uint64 value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(euint64 ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(euint64.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted 128-bit unsigned integer
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted uint128 value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(euint128 ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(euint128.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted 256-bit unsigned integer
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted uint256 value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(euint256 ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(euint256.unwrap(ctHash), account);
}
/// @notice Checks if an account has permission to operate on the encrypted address
/// @dev Returns whether the specified account can access the ciphertext
/// @param ctHash The encrypted address value to check access for
/// @param account The address to check permissions for
/// @return True if the account has permission, false otherwise
function isAllowed(eaddress ctHash, address account) internal returns (bool) {
return ITaskManager(TASK_MANAGER_ADDRESS).isAllowed(eaddress.unwrap(ctHash), account);
}
/// @notice Grants permission to the current contract to operate on the encrypted boolean value
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted boolean value to grant access to
function allowThis(ebool ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(ebool.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted 8-bit unsigned integer
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted uint8 value to grant access to
function allowThis(euint8 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint8.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted 16-bit unsigned integer
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted uint16 value to grant access to
function allowThis(euint16 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint16.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted 32-bit unsigned integer
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted uint32 value to grant access to
function allowThis(euint32 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint32.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted 64-bit unsigned integer
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted uint64 value to grant access to
function allowThis(euint64 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint64.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted 128-bit unsigned integer
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted uint128 value to grant access to
function allowThis(euint128 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint128.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted 256-bit unsigned integer
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted uint256 value to grant access to
function allowThis(euint256 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint256.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the current contract to operate on the encrypted address
/// @dev Allows this contract to access the ciphertext
/// @param ctHash The encrypted address value to grant access to
function allowThis(eaddress ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(eaddress.unwrap(ctHash), address(this));
}
/// @notice Grants permission to the message sender to operate on the encrypted boolean value
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted boolean value to grant access to
function allowSender(ebool ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(ebool.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted 8-bit unsigned integer
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted uint8 value to grant access to
function allowSender(euint8 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint8.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted 16-bit unsigned integer
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted uint16 value to grant access to
function allowSender(euint16 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint16.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted 32-bit unsigned integer
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted uint32 value to grant access to
function allowSender(euint32 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint32.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted 64-bit unsigned integer
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted uint64 value to grant access to
function allowSender(euint64 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint64.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted 128-bit unsigned integer
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted uint128 value to grant access to
function allowSender(euint128 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint128.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted 256-bit unsigned integer
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted uint256 value to grant access to
function allowSender(euint256 ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(euint256.unwrap(ctHash), msg.sender);
}
/// @notice Grants permission to the message sender to operate on the encrypted address
/// @dev Allows the transaction sender to access the ciphertext
/// @param ctHash The encrypted address value to grant access to
function allowSender(eaddress ctHash) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allow(eaddress.unwrap(ctHash), msg.sender);
}
/// @notice Grants temporary permission to an account to operate on the encrypted boolean value
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted boolean value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(ebool ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(ebool.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted 8-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted uint8 value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(euint8 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(euint8.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted 16-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted uint16 value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(euint16 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(euint16.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted 32-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted uint32 value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(euint32 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(euint32.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted 64-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted uint64 value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(euint64 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(euint64.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted 128-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted uint128 value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(euint128 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(euint128.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted 256-bit unsigned integer
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted uint256 value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(euint256 ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(euint256.unwrap(ctHash), account);
}
/// @notice Grants temporary permission to an account to operate on the encrypted address
/// @dev Allows the specified account to access the ciphertext for the current transaction only
/// @param ctHash The encrypted address value to grant temporary access to
/// @param account The address being granted temporary permission
function allowTransient(eaddress ctHash, address account) internal {
ITaskManager(TASK_MANAGER_ADDRESS).allowTransient(eaddress.unwrap(ctHash), account);
}
}
// ********** BINDING DEFS ************* //
using BindingsEbool for ebool global;
library BindingsEbool {
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return the result of the eq
function eq(ebool lhs, ebool rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return the result of the ne
function ne(ebool lhs, ebool rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
/// @notice Performs the not operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type ebool
/// @return the result of the not
function not(ebool lhs) internal returns (ebool) {
return FHE.not(lhs);
}
/// @notice Performs the and operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return the result of the and
function and(ebool lhs, ebool rhs) internal returns (ebool) {
return FHE.and(lhs, rhs);
}
/// @notice Performs the or operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return the result of the or
function or(ebool lhs, ebool rhs) internal returns (ebool) {
return FHE.or(lhs, rhs);
}
/// @notice Performs the xor operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type ebool
/// @param rhs second input of type ebool
/// @return the result of the xor
function xor(ebool lhs, ebool rhs) internal returns (ebool) {
return FHE.xor(lhs, rhs);
}
function toU8(ebool value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU16(ebool value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU32(ebool value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU64(ebool value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU128(ebool value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toU256(ebool value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(ebool value) internal {
FHE.decrypt(value);
}
function allow(ebool ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(ebool ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(ebool ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(ebool ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(ebool ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(ebool ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEuint8 for euint8 global;
library BindingsEuint8 {
/// @notice Performs the add operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the add
function add(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.add(lhs, rhs);
}
/// @notice Performs the mul operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the mul
function mul(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.mul(lhs, rhs);
}
/// @notice Performs the div operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the div
function div(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.div(lhs, rhs);
}
/// @notice Performs the sub operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the sub
function sub(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.sub(lhs, rhs);
}
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the eq
function eq(euint8 lhs, euint8 rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the ne
function ne(euint8 lhs, euint8 rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
/// @notice Performs the not operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @return the result of the not
function not(euint8 lhs) internal returns (euint8) {
return FHE.not(lhs);
}
/// @notice Performs the and operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the and
function and(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.and(lhs, rhs);
}
/// @notice Performs the or operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the or
function or(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.or(lhs, rhs);
}
/// @notice Performs the xor operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the xor
function xor(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.xor(lhs, rhs);
}
/// @notice Performs the gt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the gt
function gt(euint8 lhs, euint8 rhs) internal returns (ebool) {
return FHE.gt(lhs, rhs);
}
/// @notice Performs the gte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the gte
function gte(euint8 lhs, euint8 rhs) internal returns (ebool) {
return FHE.gte(lhs, rhs);
}
/// @notice Performs the lt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the lt
function lt(euint8 lhs, euint8 rhs) internal returns (ebool) {
return FHE.lt(lhs, rhs);
}
/// @notice Performs the lte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the lte
function lte(euint8 lhs, euint8 rhs) internal returns (ebool) {
return FHE.lte(lhs, rhs);
}
/// @notice Performs the rem operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the rem
function rem(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.rem(lhs, rhs);
}
/// @notice Performs the max operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the max
function max(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.max(lhs, rhs);
}
/// @notice Performs the min operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the min
function min(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.min(lhs, rhs);
}
/// @notice Performs the shl operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the shl
function shl(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.shl(lhs, rhs);
}
/// @notice Performs the shr operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the shr
function shr(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.shr(lhs, rhs);
}
/// @notice Performs the rol operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the rol
function rol(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.rol(lhs, rhs);
}
/// @notice Performs the ror operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @param rhs second input of type euint8
/// @return the result of the ror
function ror(euint8 lhs, euint8 rhs) internal returns (euint8) {
return FHE.ror(lhs, rhs);
}
/// @notice Performs the square operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint8
/// @return the result of the square
function square(euint8 lhs) internal returns (euint8) {
return FHE.square(lhs);
}
function toBool(euint8 value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU16(euint8 value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU32(euint8 value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU64(euint8 value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU128(euint8 value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toU256(euint8 value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(euint8 value) internal {
FHE.decrypt(value);
}
function allow(euint8 ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(euint8 ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(euint8 ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(euint8 ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(euint8 ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(euint8 ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEuint16 for euint16 global;
library BindingsEuint16 {
/// @notice Performs the add operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the add
function add(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.add(lhs, rhs);
}
/// @notice Performs the mul operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the mul
function mul(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.mul(lhs, rhs);
}
/// @notice Performs the div operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the div
function div(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.div(lhs, rhs);
}
/// @notice Performs the sub operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the sub
function sub(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.sub(lhs, rhs);
}
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the eq
function eq(euint16 lhs, euint16 rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the ne
function ne(euint16 lhs, euint16 rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
/// @notice Performs the not operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @return the result of the not
function not(euint16 lhs) internal returns (euint16) {
return FHE.not(lhs);
}
/// @notice Performs the and operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the and
function and(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.and(lhs, rhs);
}
/// @notice Performs the or operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the or
function or(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.or(lhs, rhs);
}
/// @notice Performs the xor operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the xor
function xor(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.xor(lhs, rhs);
}
/// @notice Performs the gt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the gt
function gt(euint16 lhs, euint16 rhs) internal returns (ebool) {
return FHE.gt(lhs, rhs);
}
/// @notice Performs the gte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the gte
function gte(euint16 lhs, euint16 rhs) internal returns (ebool) {
return FHE.gte(lhs, rhs);
}
/// @notice Performs the lt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the lt
function lt(euint16 lhs, euint16 rhs) internal returns (ebool) {
return FHE.lt(lhs, rhs);
}
/// @notice Performs the lte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the lte
function lte(euint16 lhs, euint16 rhs) internal returns (ebool) {
return FHE.lte(lhs, rhs);
}
/// @notice Performs the rem operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the rem
function rem(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.rem(lhs, rhs);
}
/// @notice Performs the max operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the max
function max(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.max(lhs, rhs);
}
/// @notice Performs the min operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the min
function min(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.min(lhs, rhs);
}
/// @notice Performs the shl operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the shl
function shl(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.shl(lhs, rhs);
}
/// @notice Performs the shr operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the shr
function shr(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.shr(lhs, rhs);
}
/// @notice Performs the rol operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the rol
function rol(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.rol(lhs, rhs);
}
/// @notice Performs the ror operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @param rhs second input of type euint16
/// @return the result of the ror
function ror(euint16 lhs, euint16 rhs) internal returns (euint16) {
return FHE.ror(lhs, rhs);
}
/// @notice Performs the square operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint16
/// @return the result of the square
function square(euint16 lhs) internal returns (euint16) {
return FHE.square(lhs);
}
function toBool(euint16 value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU8(euint16 value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU32(euint16 value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU64(euint16 value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU128(euint16 value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toU256(euint16 value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(euint16 value) internal {
FHE.decrypt(value);
}
function allow(euint16 ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(euint16 ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(euint16 ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(euint16 ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(euint16 ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(euint16 ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEuint32 for euint32 global;
library BindingsEuint32 {
/// @notice Performs the add operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the add
function add(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.add(lhs, rhs);
}
/// @notice Performs the mul operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the mul
function mul(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.mul(lhs, rhs);
}
/// @notice Performs the div operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the div
function div(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.div(lhs, rhs);
}
/// @notice Performs the sub operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the sub
function sub(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.sub(lhs, rhs);
}
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the eq
function eq(euint32 lhs, euint32 rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the ne
function ne(euint32 lhs, euint32 rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
/// @notice Performs the not operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @return the result of the not
function not(euint32 lhs) internal returns (euint32) {
return FHE.not(lhs);
}
/// @notice Performs the and operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the and
function and(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.and(lhs, rhs);
}
/// @notice Performs the or operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the or
function or(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.or(lhs, rhs);
}
/// @notice Performs the xor operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the xor
function xor(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.xor(lhs, rhs);
}
/// @notice Performs the gt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the gt
function gt(euint32 lhs, euint32 rhs) internal returns (ebool) {
return FHE.gt(lhs, rhs);
}
/// @notice Performs the gte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the gte
function gte(euint32 lhs, euint32 rhs) internal returns (ebool) {
return FHE.gte(lhs, rhs);
}
/// @notice Performs the lt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the lt
function lt(euint32 lhs, euint32 rhs) internal returns (ebool) {
return FHE.lt(lhs, rhs);
}
/// @notice Performs the lte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the lte
function lte(euint32 lhs, euint32 rhs) internal returns (ebool) {
return FHE.lte(lhs, rhs);
}
/// @notice Performs the rem operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the rem
function rem(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.rem(lhs, rhs);
}
/// @notice Performs the max operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the max
function max(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.max(lhs, rhs);
}
/// @notice Performs the min operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the min
function min(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.min(lhs, rhs);
}
/// @notice Performs the shl operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the shl
function shl(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.shl(lhs, rhs);
}
/// @notice Performs the shr operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the shr
function shr(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.shr(lhs, rhs);
}
/// @notice Performs the rol operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the rol
function rol(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.rol(lhs, rhs);
}
/// @notice Performs the ror operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @param rhs second input of type euint32
/// @return the result of the ror
function ror(euint32 lhs, euint32 rhs) internal returns (euint32) {
return FHE.ror(lhs, rhs);
}
/// @notice Performs the square operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint32
/// @return the result of the square
function square(euint32 lhs) internal returns (euint32) {
return FHE.square(lhs);
}
function toBool(euint32 value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU8(euint32 value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU16(euint32 value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU64(euint32 value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU128(euint32 value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toU256(euint32 value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(euint32 value) internal {
FHE.decrypt(value);
}
function allow(euint32 ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(euint32 ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(euint32 ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(euint32 ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(euint32 ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(euint32 ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEuint64 for euint64 global;
library BindingsEuint64 {
/// @notice Performs the add operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the add
function add(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.add(lhs, rhs);
}
/// @notice Performs the mul operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the mul
function mul(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.mul(lhs, rhs);
}
/// @notice Performs the sub operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the sub
function sub(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.sub(lhs, rhs);
}
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the eq
function eq(euint64 lhs, euint64 rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the ne
function ne(euint64 lhs, euint64 rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
/// @notice Performs the not operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @return the result of the not
function not(euint64 lhs) internal returns (euint64) {
return FHE.not(lhs);
}
/// @notice Performs the and operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the and
function and(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.and(lhs, rhs);
}
/// @notice Performs the or operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the or
function or(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.or(lhs, rhs);
}
/// @notice Performs the xor operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the xor
function xor(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.xor(lhs, rhs);
}
/// @notice Performs the gt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the gt
function gt(euint64 lhs, euint64 rhs) internal returns (ebool) {
return FHE.gt(lhs, rhs);
}
/// @notice Performs the gte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the gte
function gte(euint64 lhs, euint64 rhs) internal returns (ebool) {
return FHE.gte(lhs, rhs);
}
/// @notice Performs the lt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the lt
function lt(euint64 lhs, euint64 rhs) internal returns (ebool) {
return FHE.lt(lhs, rhs);
}
/// @notice Performs the lte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the lte
function lte(euint64 lhs, euint64 rhs) internal returns (ebool) {
return FHE.lte(lhs, rhs);
}
/// @notice Performs the max operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the max
function max(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.max(lhs, rhs);
}
/// @notice Performs the min operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the min
function min(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.min(lhs, rhs);
}
/// @notice Performs the shl operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the shl
function shl(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.shl(lhs, rhs);
}
/// @notice Performs the shr operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the shr
function shr(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.shr(lhs, rhs);
}
/// @notice Performs the rol operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the rol
function rol(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.rol(lhs, rhs);
}
/// @notice Performs the ror operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @param rhs second input of type euint64
/// @return the result of the ror
function ror(euint64 lhs, euint64 rhs) internal returns (euint64) {
return FHE.ror(lhs, rhs);
}
/// @notice Performs the square operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint64
/// @return the result of the square
function square(euint64 lhs) internal returns (euint64) {
return FHE.square(lhs);
}
function toBool(euint64 value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU8(euint64 value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU16(euint64 value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU32(euint64 value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU128(euint64 value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toU256(euint64 value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(euint64 value) internal {
FHE.decrypt(value);
}
function allow(euint64 ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(euint64 ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(euint64 ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(euint64 ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(euint64 ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(euint64 ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEuint128 for euint128 global;
library BindingsEuint128 {
/// @notice Performs the add operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the add
function add(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.add(lhs, rhs);
}
/// @notice Performs the sub operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the sub
function sub(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.sub(lhs, rhs);
}
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the eq
function eq(euint128 lhs, euint128 rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the ne
function ne(euint128 lhs, euint128 rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
/// @notice Performs the not operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @return the result of the not
function not(euint128 lhs) internal returns (euint128) {
return FHE.not(lhs);
}
/// @notice Performs the and operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the and
function and(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.and(lhs, rhs);
}
/// @notice Performs the or operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the or
function or(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.or(lhs, rhs);
}
/// @notice Performs the xor operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the xor
function xor(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.xor(lhs, rhs);
}
/// @notice Performs the gt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the gt
function gt(euint128 lhs, euint128 rhs) internal returns (ebool) {
return FHE.gt(lhs, rhs);
}
/// @notice Performs the gte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the gte
function gte(euint128 lhs, euint128 rhs) internal returns (ebool) {
return FHE.gte(lhs, rhs);
}
/// @notice Performs the lt operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the lt
function lt(euint128 lhs, euint128 rhs) internal returns (ebool) {
return FHE.lt(lhs, rhs);
}
/// @notice Performs the lte operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the lte
function lte(euint128 lhs, euint128 rhs) internal returns (ebool) {
return FHE.lte(lhs, rhs);
}
/// @notice Performs the max operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the max
function max(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.max(lhs, rhs);
}
/// @notice Performs the min operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the min
function min(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.min(lhs, rhs);
}
/// @notice Performs the shl operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the shl
function shl(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.shl(lhs, rhs);
}
/// @notice Performs the shr operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the shr
function shr(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.shr(lhs, rhs);
}
/// @notice Performs the rol operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the rol
function rol(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.rol(lhs, rhs);
}
/// @notice Performs the ror operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint128
/// @param rhs second input of type euint128
/// @return the result of the ror
function ror(euint128 lhs, euint128 rhs) internal returns (euint128) {
return FHE.ror(lhs, rhs);
}
function toBool(euint128 value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU8(euint128 value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU16(euint128 value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU32(euint128 value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU64(euint128 value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU256(euint128 value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(euint128 value) internal {
FHE.decrypt(value);
}
function allow(euint128 ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(euint128 ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(euint128 ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(euint128 ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(euint128 ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(euint128 ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEuint256 for euint256 global;
library BindingsEuint256 {
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return the result of the eq
function eq(euint256 lhs, euint256 rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type euint256
/// @param rhs second input of type euint256
/// @return the result of the ne
function ne(euint256 lhs, euint256 rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
function toBool(euint256 value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU8(euint256 value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU16(euint256 value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU32(euint256 value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU64(euint256 value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU128(euint256 value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toEaddress(euint256 value) internal returns (eaddress) {
return FHE.asEaddress(value);
}
function decrypt(euint256 value) internal {
FHE.decrypt(value);
}
function allow(euint256 ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(euint256 ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(euint256 ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(euint256 ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(euint256 ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(euint256 ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}
using BindingsEaddress for eaddress global;
library BindingsEaddress {
/// @notice Performs the eq operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type eaddress
/// @param rhs second input of type eaddress
/// @return the result of the eq
function eq(eaddress lhs, eaddress rhs) internal returns (ebool) {
return FHE.eq(lhs, rhs);
}
/// @notice Performs the ne operation
/// @dev Pure in this function is marked as a hack/workaround - note that this function is NOT pure as fetches of ciphertexts require state access
/// @param lhs input of type eaddress
/// @param rhs second input of type eaddress
/// @return the result of the ne
function ne(eaddress lhs, eaddress rhs) internal returns (ebool) {
return FHE.ne(lhs, rhs);
}
function toBool(eaddress value) internal returns (ebool) {
return FHE.asEbool(value);
}
function toU8(eaddress value) internal returns (euint8) {
return FHE.asEuint8(value);
}
function toU16(eaddress value) internal returns (euint16) {
return FHE.asEuint16(value);
}
function toU32(eaddress value) internal returns (euint32) {
return FHE.asEuint32(value);
}
function toU64(eaddress value) internal returns (euint64) {
return FHE.asEuint64(value);
}
function toU128(eaddress value) internal returns (euint128) {
return FHE.asEuint128(value);
}
function toU256(eaddress value) internal returns (euint256) {
return FHE.asEuint256(value);
}
function decrypt(eaddress value) internal {
FHE.decrypt(value);
}
function allow(eaddress ctHash, address account) internal {
FHE.allow(ctHash, account);
}
function isAllowed(eaddress ctHash, address account) internal returns (bool) {
return FHE.isAllowed(ctHash, account);
}
function allowThis(eaddress ctHash) internal {
FHE.allowThis(ctHash);
}
function allowGlobal(eaddress ctHash) internal {
FHE.allowGlobal(ctHash);
}
function allowSender(eaddress ctHash) internal {
FHE.allowSender(ctHash);
}
function allowTransient(eaddress ctHash, address account) internal {
FHE.allowTransient(ctHash, account);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;
struct EncryptedInput {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEbool {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEuint8 {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEuint16 {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEuint32 {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEuint64 {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEuint128 {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEuint256 {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
struct InEaddress {
uint256 ctHash;
uint8 securityZone;
uint8 utype;
bytes signature;
}
// Order is set as in fheos/precompiles/types/types.go
enum FunctionId {
_0, // 0 - GetNetworkKey
_1, // 1 - Verify
cast, // 2
sealoutput, // 3
select, // 4 - select
_5, // 5 - req
decrypt, // 6
sub, // 7
add, // 8
xor, // 9
and, // 10
or, // 11
not, // 12
div, // 13
rem, // 14
mul, // 15
shl, // 16
shr, // 17
gte, // 18
lte, // 19
lt, // 20
gt, // 21
min, // 22
max, // 23
eq, // 24
ne, // 25
trivialEncrypt, // 26
random, // 27
rol, // 28
ror, // 29
square, // 30
_31 // 31
}
interface ITaskManager {
function createTask(uint8 returnType, FunctionId funcId, uint256[] memory encryptedInputs, uint256[] memory extraInputs) external returns (uint256);
function createDecryptTask(uint256 ctHash, address requestor) external;
function verifyInput(EncryptedInput memory input, address sender) external returns (uint256);
function allow(uint256 ctHash, address account) external;
function isAllowed(uint256 ctHash, address account) external returns (bool);
function allowGlobal(uint256 ctHash) external;
function allowTransient(uint256 ctHash, address account) external;
function getDecryptResultSafe(uint256 ctHash) external view returns (uint256, bool);
function getDecryptResult(uint256 ctHash) external view returns (uint256);
}
library Utils {
// Values used to communicate types to the runtime.
// Must match values defined in warp-drive protobufs for everything to
uint8 internal constant EUINT8_TFHE = 2;
uint8 internal constant EUINT16_TFHE = 3;
uint8 internal constant EUINT32_TFHE = 4;
uint8 internal constant EUINT64_TFHE = 5;
uint8 internal constant EUINT128_TFHE = 6;
uint8 internal constant EUINT256_TFHE = 8;
uint8 internal constant EADDRESS_TFHE = 7;
uint8 internal constant EBOOL_TFHE = 0;
function functionIdToString(FunctionId _functionId) internal pure returns (string memory) {
if (_functionId == FunctionId.cast) return "cast";
if (_functionId == FunctionId.sealoutput) return "sealOutput";
if (_functionId == FunctionId.select) return "select";
if (_functionId == FunctionId.decrypt) return "decrypt";
if (_functionId == FunctionId.sub) return "sub";
if (_functionId == FunctionId.add) return "add";
if (_functionId == FunctionId.xor) return "xor";
if (_functionId == FunctionId.and) return "and";
if (_functionId == FunctionId.or) return "or";
if (_functionId == FunctionId.not) return "not";
if (_functionId == FunctionId.div) return "div";
if (_functionId == FunctionId.rem) return "rem";
if (_functionId == FunctionId.mul) return "mul";
if (_functionId == FunctionId.shl) return "shl";
if (_functionId == FunctionId.shr) return "shr";
if (_functionId == FunctionId.gte) return "gte";
if (_functionId == FunctionId.lte) return "lte";
if (_functionId == FunctionId.lt) return "lt";
if (_functionId == FunctionId.gt) return "gt";
if (_functionId == FunctionId.min) return "min";
if (_functionId == FunctionId.max) return "max";
if (_functionId == FunctionId.eq) return "eq";
if (_functionId == FunctionId.ne) return "ne";
if (_functionId == FunctionId.trivialEncrypt) return "trivialEncrypt";
if (_functionId == FunctionId.random) return "random";
if (_functionId == FunctionId.rol) return "rol";
if (_functionId == FunctionId.ror) return "ror";
if (_functionId == FunctionId.square) return "square";
return "";
}
function inputFromEbool(InEbool memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EBOOL_TFHE,
signature: input.signature
});
}
function inputFromEuint8(InEuint8 memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EUINT8_TFHE,
signature: input.signature
});
}
function inputFromEuint16(InEuint16 memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EUINT16_TFHE,
signature: input.signature
});
}
function inputFromEuint32(InEuint32 memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EUINT32_TFHE,
signature: input.signature
});
}
function inputFromEuint64(InEuint64 memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EUINT64_TFHE,
signature: input.signature
});
}
function inputFromEuint128(InEuint128 memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EUINT128_TFHE,
signature: input.signature
});
}
function inputFromEuint256(InEuint256 memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EUINT256_TFHE,
signature: input.signature
});
}
function inputFromEaddress(InEaddress memory input) internal pure returns (EncryptedInput memory) {
return EncryptedInput({
ctHash: input.ctHash,
securityZone: input.securityZone,
utype: EADDRESS_TFHE,
signature: input.signature
});
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.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.
*
* The initial owner is set to the address provided by the deployer. 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 Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_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);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.20;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Arrays.sol)
// This file was procedurally generated from scripts/generate/templates/Arrays.js.
pragma solidity ^0.8.20;
import {Comparators} from "./Comparators.sol";
import {SlotDerivation} from "./SlotDerivation.sol";
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using SlotDerivation for bytes32;
using StorageSlot for bytes32;
/**
* @dev Sort an array of uint256 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
uint256[] memory array,
function(uint256, uint256) pure returns (bool) comp
) internal pure returns (uint256[] memory) {
_quickSort(_begin(array), _end(array), comp);
return array;
}
/**
* @dev Variant of {sort} that sorts an array of uint256 in increasing order.
*/
function sort(uint256[] memory array) internal pure returns (uint256[] memory) {
sort(array, Comparators.lt);
return array;
}
/**
* @dev Sort an array of address (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
address[] memory array,
function(address, address) pure returns (bool) comp
) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of address in increasing order.
*/
function sort(address[] memory array) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Sort an array of bytes32 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
bytes32[] memory array,
function(bytes32, bytes32) pure returns (bool) comp
) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
*/
function sort(bytes32[] memory array) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Performs a quick sort of a segment of memory. The segment sorted starts at `begin` (inclusive), and stops
* at end (exclusive). Sorting follows the `comp` comparator.
*
* Invariant: `begin <= end`. This is the case when initially called by {sort} and is preserved in subcalls.
*
* IMPORTANT: Memory locations between `begin` and `end` are not validated/zeroed. This function should
* be used only if the limits are within a memory array.
*/
function _quickSort(uint256 begin, uint256 end, function(uint256, uint256) pure returns (bool) comp) private pure {
unchecked {
if (end - begin < 0x40) return;
// Use first element as pivot
uint256 pivot = _mload(begin);
// Position where the pivot should be at the end of the loop
uint256 pos = begin;
for (uint256 it = begin + 0x20; it < end; it += 0x20) {
if (comp(_mload(it), pivot)) {
// If the value stored at the iterator's position comes before the pivot, we increment the
// position of the pivot and move the value there.
pos += 0x20;
_swap(pos, it);
}
}
_swap(begin, pos); // Swap pivot into place
_quickSort(begin, pos, comp); // Sort the left side of the pivot
_quickSort(pos + 0x20, end, comp); // Sort the right side of the pivot
}
}
/**
* @dev Pointer to the memory location of the first element of `array`.
*/
function _begin(uint256[] memory array) private pure returns (uint256 ptr) {
assembly ("memory-safe") {
ptr := add(array, 0x20)
}
}
/**
* @dev Pointer to the memory location of the first memory word (32bytes) after `array`. This is the memory word
* that comes just after the last element of the array.
*/
function _end(uint256[] memory array) private pure returns (uint256 ptr) {
unchecked {
return _begin(array) + array.length * 0x20;
}
}
/**
* @dev Load memory word (as a uint256) at location `ptr`.
*/
function _mload(uint256 ptr) private pure returns (uint256 value) {
assembly {
value := mload(ptr)
}
}
/**
* @dev Swaps the elements memory location `ptr1` and `ptr2`.
*/
function _swap(uint256 ptr1, uint256 ptr2) private pure {
assembly {
let value1 := mload(ptr1)
let value2 := mload(ptr2)
mstore(ptr1, value2)
mstore(ptr2, value1)
}
}
/// @dev Helper: low level cast address memory array to uint256 memory array
function _castToUint256Array(address[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 memory array to uint256 memory array
function _castToUint256Array(bytes32[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast address comp function to uint256 comp function
function _castToUint256Comp(
function(address, address) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 comp function to uint256 comp function
function _castToUint256Comp(
function(bytes32, bytes32) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* NOTE: The `array` is expected to be sorted in ascending order, and to
* contain no repeated elements.
*
* IMPORTANT: Deprecated. This implementation behaves as {lowerBound} but lacks
* support for repeated elements in the array. The {lowerBound} function should
* be used instead.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value greater or equal than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/lower_bound[lower_bound].
*/
function lowerBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value strictly greater than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/upper_bound[upper_bound].
*/
function upperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Same as {lowerBound}, but with an array in memory.
*/
function lowerBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Same as {upperBound}, but with an array in memory.
*/
function upperBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes32[] memory arr, uint256 pos) internal pure returns (bytes32 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(address[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(uint256[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Comparators.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to compare values.
*
* _Available since v5.1._
*/
library Comparators {
function lt(uint256 a, uint256 b) internal pure returns (bool) {
return a < b;
}
function gt(uint256 a, uint256 b) internal pure returns (bool) {
return a > b;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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 Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(
bytes32 hash,
bytes memory signature
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly ("memory-safe") {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address recovered, RecoverError err, bytes32 errArg) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.20;
import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.
*
* The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
* encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
* does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
* produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
// slither-disable-next-line constable-states
string private _nameFallback;
// slither-disable-next-line constable-states
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @inheritdoc IERC5267
*/
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: By default this function reads _name which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view returns (string memory) {
return _name.toStringWithFallback(_nameFallback);
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: By default this function reads _version which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view returns (string memory) {
return _version.toStringWithFallback(_versionFallback);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Variant of {toDataWithIntendedValidatorHash-address-bytes} optimized for cases where `data` is a bytes32.
*/
function toDataWithIntendedValidatorHash(
address validator,
bytes32 messageHash
) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
mstore(0x00, hex"19_00")
mstore(0x02, shl(96, validator))
mstore(0x16, messageHash)
digest := keccak256(0x00, 0x36)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides tracking nonces for addresses. Nonces will only increment.
*/
abstract contract Nonces {
/**
* @dev The nonce used for an `account` is not the expected current nonce.
*/
error InvalidAccountNonce(address account, uint256 currentNonce);
mapping(address account => uint256) private _nonces;
/**
* @dev Returns the next unused nonce for an address.
*/
function nonces(address owner) public view virtual returns (uint256) {
return _nonces[owner];
}
/**
* @dev Consumes a nonce.
*
* Returns the current value and increments nonce.
*/
function _useNonce(address owner) internal virtual returns (uint256) {
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
// decremented or reset. This guarantees that the nonce never overflows.
unchecked {
// It is important to do x++ and not ++x here.
return _nonces[owner]++;
}
}
/**
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
*/
function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
uint256 current = _useNonce(owner);
if (nonce != current) {
revert InvalidAccountNonce(owner, current);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
assembly ("memory-safe") {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {toShortStringWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using
* {toShortStringWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/SlotDerivation.sol)
// This file was procedurally generated from scripts/generate/templates/SlotDerivation.js.
pragma solidity ^0.8.20;
/**
* @dev Library for computing storage (and transient storage) locations from namespaces and deriving slots
* corresponding to standard patterns. The derivation method for array and mapping matches the storage layout used by
* the solidity language / compiler.
*
* See https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays[Solidity docs for mappings and dynamic arrays.].
*
* Example usage:
* ```solidity
* contract Example {
* // Add the library methods
* using StorageSlot for bytes32;
* using SlotDerivation for bytes32;
*
* // Declare a namespace
* string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
*
* function setValueInNamespace(uint256 key, address newValue) internal {
* _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
* }
*
* function getValueInNamespace(uint256 key) internal view returns (address) {
* return _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value;
* }
* }
* ```
*
* TIP: Consider using this library along with {StorageSlot}.
*
* NOTE: This library provides a way to manipulate storage locations in a non-standard way. Tooling for checking
* upgrade safety will ignore the slots accessed through this library.
*
* _Available since v5.1._
*/
library SlotDerivation {
/**
* @dev Derive an ERC-7201 slot from a string (namespace).
*/
function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
assembly ("memory-safe") {
mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
slot := and(keccak256(0x00, 0x20), not(0xff))
}
}
/**
* @dev Add an offset to a slot to get the n-th element of a structure or an array.
*/
function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result) {
unchecked {
return bytes32(uint256(slot) + pos);
}
}
/**
* @dev Derive the location of the first element in an array from the slot where the length is stored.
*/
function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, slot)
result := keccak256(0x00, 0x20)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, address key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, and(key, shr(96, not(0))))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bool key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, iszero(iszero(key)))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes32 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, uint256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, int256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, string memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @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 ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
uint256 private constant SPECIAL_CHARS_LOOKUP =
(1 << 0x08) | // backspace
(1 << 0x09) | // tab
(1 << 0x0a) | // newline
(1 << 0x0c) | // form feed
(1 << 0x0d) | // carriage return
(1 << 0x22) | // double quote
(1 << 0x5c); // backslash
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress-string} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress-string-uint256-uint256} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
*
* WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
*
* NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
* RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
* characters that are not in this range, but other tooling may provide different results.
*/
function escapeJSON(string memory input) internal pure returns (string memory) {
bytes memory buffer = bytes(input);
bytes memory output = new bytes(2 * buffer.length); // worst case scenario
uint256 outputLength = 0;
for (uint256 i; i < buffer.length; ++i) {
bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
output[outputLength++] = "\\";
if (char == 0x08) output[outputLength++] = "b";
else if (char == 0x09) output[outputLength++] = "t";
else if (char == 0x0a) output[outputLength++] = "n";
else if (char == 0x0c) output[outputLength++] = "f";
else if (char == 0x0d) output[outputLength++] = "r";
else if (char == 0x5c) output[outputLength++] = "\\";
else if (char == 0x22) {
// solhint-disable-next-line quotes
output[outputLength++] = '"';
}
} else {
output[outputLength++] = char;
}
}
// write the actual length and deallocate unused memory
assembly ("memory-safe") {
mstore(output, outputLength)
mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
}
return string(output);
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(buffer, add(0x20, offset)))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
import {Arrays} from "../Arrays.sol";
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
* - Set can be cleared (all elements removed) in O(n).
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function _clear(Set storage set) private {
uint256 len = _length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(Bytes32Set storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.25;
import { IERC20, IERC20Metadata, ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IFHERC20, FHERC20 } from "./FHERC20.sol";
import { euint128, FHE } from "@fhenixprotocol/cofhe-contracts/FHE.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
abstract contract ConfidentialClaim {
using EnumerableSet for EnumerableSet.UintSet;
struct Claim {
uint256 ctHash;
uint128 requestedAmount;
uint128 decryptedAmount;
bool decrypted;
address to;
bool claimed;
}
mapping(uint256 ctHash => Claim) private _claims;
mapping(address => EnumerableSet.UintSet) private _userClaims;
error ClaimNotFound();
error AlreadyClaimed();
function _createClaim(address to, uint128 value, euint128 claimable) internal {
_claims[euint128.unwrap(claimable)] = Claim({
ctHash: euint128.unwrap(claimable),
requestedAmount: value,
decryptedAmount: 0,
decrypted: false,
to: to,
claimed: false
});
_userClaims[to].add(euint128.unwrap(claimable));
}
function _handleClaim(uint256 ctHash) internal returns (Claim memory claim) {
claim = _claims[ctHash];
// Check that the claimable amount exists and has not been claimed yet
if (claim.to == address(0)) revert ClaimNotFound();
if (claim.claimed) revert AlreadyClaimed();
// Get the decrypted amount (reverts if the amount is not decrypted yet)
uint128 amount = SafeCast.toUint128(FHE.getDecryptResult(ctHash));
// Update the claim
claim.decryptedAmount = amount;
claim.decrypted = true;
claim.claimed = true;
// Update the claim in storage
_claims[ctHash] = claim;
// Remove the claimable amount from the user's claimable set
_userClaims[claim.to].remove(ctHash);
}
function _handleClaimAll() internal returns (Claim[] memory claims) {
claims = new Claim[](_userClaims[msg.sender].length());
uint256[] memory ctHashes = _userClaims[msg.sender].values();
for (uint256 i = 0; i < ctHashes.length; i++) {
claims[i] = _handleClaim(ctHashes[i]);
}
}
function getClaim(uint256 ctHash) public view returns (Claim memory) {
Claim memory _claim = _claims[ctHash];
(uint256 amount, bool decrypted) = FHE.getDecryptResultSafe(ctHash);
_claim.decryptedAmount = SafeCast.toUint128(amount);
_claim.decrypted = decrypted;
return _claim;
}
function getUserClaims(address user) public view returns (Claim[] memory) {
uint256[] memory ctHashes = _userClaims[user].values();
Claim[] memory userClaims = new Claim[](ctHashes.length);
for (uint256 i = 0; i < ctHashes.length; i++) {
userClaims[i] = _claims[ctHashes[i]];
(uint256 amount, bool decrypted) = FHE.getDecryptResultSafe(ctHashes[i]);
userClaims[i].decryptedAmount = SafeCast.toUint128(amount);
userClaims[i].decrypted = decrypted;
}
return userClaims;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.25;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { Nonces } from "@openzeppelin/contracts/utils/Nonces.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { IFHERC20 } from "./interfaces/IFHERC20.sol";
import { IFHERC20Errors } from "./interfaces/IFHERC20Errors.sol";
import { FHE, euint128, InEuint128, Utils } from "@fhenixprotocol/cofhe-contracts/FHE.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*
* Note: This FHERC20 does not include FHE operations, and is intended to decouple the
* frontend work from the active CoFHE (FHE Coprocessor) work during development and auditing.
*/
abstract contract FHERC20 is IFHERC20, IFHERC20Errors, Context, EIP712, Nonces {
// NOTE: `indicatedBalances` are intended to indicate movement and change
// of an encrypted FHERC20 balance, without exposing any encrypted data.
//
// !! WARNING !! These indicated balances MUST NOT be used in any FHERC20 logic, only
// the encrypted balance should be used.
//
// `indicatedBalance` is implemented to make FHERC20s maximally backwards
// compatible with existing ERC20 expectations.
//
// `indicatedBalance` is internally represented by a number between 0 and 99999.
// When viewed in a wallet, it is transformed into a decimal value with 4 digits
// of precision (0.0000 to 0.9999). These same increments are used as the
// value in any emitted events. If the user has not interacted with this FHERC20
// their indicated amount will be 0. Their first interaction will set the amount to
// the midpoint (0.5000), and each subsequent interaction will shift that value by
// the increment (0.0001). This gives room for up to 5000 interactions in either
// direction, which is sufficient for >99.99% of user use cases.
//
// These `indicatedBalance` changes will show up in:
// - transactions and block scanners (0xAAA -> 0xBBB - 0.0001 eETH)
// - wallets and portfolios (eETH - 0.5538)
//
// `indicatedBalance` is included in the FHERC20 standard as a stop-gap
// to indicate change when the real encrypted change is not yet implemented
// in infrastructure like wallets and etherscans.
mapping(address account => uint16) internal _indicatedBalances;
mapping(address account => euint128) private _encBalances;
uint16 internal _indicatedTotalSupply;
euint128 private _encTotalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
uint256 private _indicatorTick;
// EIP712 Permit
bytes32 private constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value_hash,uint256 nonce,uint256 deadline)");
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_, uint8 decimals_) EIP712(name_, "1") {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
_indicatorTick = decimals_ <= 4 ? 1 : 10 ** (decimals_ - 4);
}
/**
* @dev Returns true if the token is a FHERC20.
*/
function isFherc20() public view virtual returns (bool) {
return true;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*
* Returns the indicated total supply.
*/
function totalSupply() public view virtual returns (uint256) {
return _indicatedTotalSupply * _indicatorTick;
}
/**
* @dev Returns the encrypted total supply.
*/
function encTotalSupply() public view virtual returns (euint128) {
return _encTotalSupply;
}
/**
* @dev Returns an flag indicating that the public balances returned by
* `balanceOf` is an indication of the underlying encrypted balance.
* The value returned is between 0.0000 and 0.9999, and
* acts as a counter of tokens transfers and changes.
*
* Receiving tokens increments this indicator by +0.0001.
* Sending tokens decrements the indicator by -0.0001.
*/
function balanceOfIsIndicator() public view virtual returns (bool) {
return true;
}
/**
* @dev Returns the true size of the indicator tick
*/
function indicatorTick() public view returns (uint256) {
return _indicatorTick;
}
/**
* @dev Returns an indicator of the underlying encrypted balance.
* The value returned is [0](no interaction) / [0.0001 - 0.9999](indicated)
* Indicator acts as a counter of tokens transfers and changes.
*
* Receiving tokens increments this indicator by +0.0001.
* Sending tokens decrements the indicator by -0.0001.
*
* Returned in the decimal expectation of the token.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _indicatedBalances[account] * _indicatorTick;
}
/**
* @dev See {IERC20-balanceOf}.
*
* Returns the euint128 representing the account's true balance (encrypted)
*/
function encBalanceOf(address account) public view virtual returns (euint128) {
return _encBalances[account];
}
/**
* @dev See {IERC20-transfer}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20
*/
function transfer(address, uint256) public pure returns (bool) {
revert FHERC20IncompatibleFunction();
}
/**
* @dev See {IERC20-transfer}.
*
* Intended to be used as a EOA call with an encrypted input `InEuint128 inValue`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
* - `inValue` must be a `InEuint128` to preserve confidentiality.
*/
function encTransfer(address to, InEuint128 memory inValue) public virtual returns (euint128 transferred) {
return encTransfer(to, FHE.asEuint128(inValue));
}
/**
* @dev See {IERC20-transfer}.
*
* Intended to be used as part of a contract call.
* Ensure that `value` is allowed to be used by using `FHE.allow` with this contracts address.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
* - `value` must be a `euint128` to preserve confidentiality.
*/
function encTransfer(address to, euint128 value) public virtual returns (euint128 transferred) {
address owner = _msgSender();
transferred = _transfer(owner, to, value);
}
/**
* @dev See {IERC20-allowance}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20.
* Allowances have been removed from FHERC20s to prevent encrypted balance leakage.
* Allowances have been replaced with an EIP712 permit for each `encTransferFrom`.
*/
function allowance(address, address) external pure returns (uint256) {
revert FHERC20IncompatibleFunction();
}
/**
* @dev See {IERC20-approve}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20.
* Allowances have been removed from FHERC20s to prevent encrypted balance leakage.
* Allowances have been replaced with an EIP712 permit for each `encTransferFrom`.
*/
function approve(address, uint256) external pure returns (bool) {
revert FHERC20IncompatibleFunction();
}
/**
* @dev See {IERC20-transferFrom}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20
*/
function transferFrom(address, address, uint256) public pure returns (bool) {
revert FHERC20IncompatibleFunction();
}
/**
* @dev See {IERC20-transferFrom}.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function encTransferFrom(
address from,
address to,
InEuint128 memory inValue,
FHERC20_EIP712_Permit calldata permit
) public virtual returns (euint128 transferred) {
if (block.timestamp > permit.deadline) revert ERC2612ExpiredSignature(permit.deadline);
if (from != permit.owner) revert FHERC20EncTransferFromOwnerMismatch(from, permit.owner);
if (msg.sender != permit.spender) revert FHERC20EncTransferFromSpenderMismatch(msg.sender, permit.spender);
if (inValue.ctHash != permit.value_hash)
revert FHERC20EncTransferFromValueHashMismatch(inValue.ctHash, permit.value_hash);
bytes32 structHash = keccak256(
abi.encode(
PERMIT_TYPEHASH,
permit.owner,
permit.spender,
permit.value_hash,
_useNonce(permit.owner),
permit.deadline
)
);
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, permit.v, permit.r, permit.s);
if (signer != permit.owner) {
revert ERC2612InvalidSigner(signer, permit.owner);
}
euint128 value = FHE.asEuint128(inValue);
transferred = _transfer(from, to, value);
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, euint128 value) internal returns (euint128 transferred) {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
transferred = _update(from, to, value);
}
/*
* @dev Increments a user's balance indicator by 0.0001
*/
function _incrementIndicator(uint16 current) internal pure returns (uint16) {
if (current == 0 || current == 9999) return 5001;
return current + 1;
}
/*
* @dev Decrements a user's balance indicator by 0.0001
*/
function _decrementIndicator(uint16 value) internal pure returns (uint16) {
if (value == 0 || value == 1) return 4999;
return value - 1;
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event and an {EncTransfer} event which includes the encrypted value.
*/
function _update(address from, address to, euint128 value) internal virtual returns (euint128 transferred) {
// If `value` is greater than the user's encBalance, it is replaced with 0
// The transaction will succeed, but the amount transferred may be 0
// Both `from` and `to` will have their `encBalance` updated in either case to preserve confidentiality
//
// NOTE: If the function is `_mint`, `from` is the zero address, and does not have an `encBalance` to
// compare against, so this check is skipped.
if (from != address(0)) {
transferred = FHE.select(value.lte(_encBalances[from]), value, FHE.asEuint128(0));
} else {
transferred = value;
}
if (from == address(0)) {
_indicatedTotalSupply = _incrementIndicator(_indicatedTotalSupply);
_encTotalSupply = FHE.add(_encTotalSupply, transferred);
} else {
_encBalances[from] = FHE.sub(_encBalances[from], transferred);
_indicatedBalances[from] = _decrementIndicator(_indicatedBalances[from]);
}
if (to == address(0)) {
_indicatedTotalSupply = _decrementIndicator(_indicatedTotalSupply);
_encTotalSupply = FHE.sub(_encTotalSupply, transferred);
} else {
_encBalances[to] = FHE.add(_encBalances[to], transferred);
_indicatedBalances[to] = _incrementIndicator(_indicatedBalances[to]);
}
// Update CoFHE Access Control List (ACL) to allow decrypting / sealing of the new balances
if (euint128.unwrap(_encBalances[from]) != 0) {
FHE.allowThis(_encBalances[from]);
FHE.allow(_encBalances[from], from);
FHE.allow(transferred, from);
}
if (euint128.unwrap(_encBalances[to]) != 0) {
FHE.allowThis(_encBalances[to]);
FHE.allow(_encBalances[to], to);
FHE.allow(transferred, to);
}
// Allow the caller to decrypt the transferred amount
FHE.allow(transferred, msg.sender);
// Allow the total supply to be decrypted by anyone
FHE.allowGlobal(_encTotalSupply);
emit Transfer(from, to, _indicatorTick);
emit EncTransfer(from, to, euint128.unwrap(transferred));
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint128 value) internal returns (euint128 transferred) {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
transferred = _update(address(0), account, FHE.asEuint128(value));
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint128 value) internal returns (euint128 transferred) {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
transferred = _update(account, address(0), FHE.asEuint128(value));
}
// EIP712 Permit
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) public view override(IFHERC20, Nonces) returns (uint256) {
return super.nonces(owner);
}
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
return _domainSeparatorV4();
}
// FHERC20
function resetIndicatedBalance() external {
_indicatedBalances[msg.sender] = 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.25;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { euint128, InEuint128 } from "@fhenixprotocol/cofhe-contracts/FHE.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*
* Note: This FHERC20 does not include FHE operations, and is intended to decouple the
* frontend work from the active CoFHE (FHE Coprocessor) work during development and auditing.
*/
interface IFHERC20 is IERC20, IERC20Metadata {
/**
* @dev EIP712 Permit reusable struct
*/
struct FHERC20_EIP712_Permit {
address owner;
address spender;
uint256 value_hash;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}
/**
* @dev Emitted when `value_hash` encrypted tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event EncTransfer(address indexed from, address indexed to, uint256 value_hash);
/**
* @dev Returns true if the token is a FHERC20.
*/
function isFherc20() external view returns (bool);
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() external view returns (uint8);
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns an flag indicating that the external balances returned by
* `balanceOf` is an indication of the underlying encrypted balance.
* The value returned is between 0.0000 and 0.9999, and
* acts as a counter of tokens transfers and changes.
*
* Receiving tokens increments this indicator by +0.0001.
* Sending tokens decrements the indicator by -0.0001.
*/
function balanceOfIsIndicator() external view returns (bool);
/**
* @dev Returns the true size of the indicator tick
*/
function indicatorTick() external view returns (uint256);
/**
* @dev Returns an indicator of the underlying encrypted balance.
* The value returned is [0](no interaction) / [0.0001 - 0.9999](indicated)
* Indicator acts as a counter of tokens transfers and changes.
*
* Receiving tokens increments this indicator by +0.0001.
* Sending tokens decrements the indicator by -0.0001.
*
* Returned in the decimal expectation of the token.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev See {IERC20-balanceOf}.
*
* Returns the euint128 representing the account's true balance (encrypted)
*/
function encBalanceOf(address account) external view returns (euint128);
/**
* @dev See {IERC20-transfer}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20
*/
function transfer(address, uint256) external pure returns (bool);
/**
* @dev See {IERC20-transfer}.
*
* Intended to be used as a EOA call with an encrypted input `InEuint128 inValue`.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
* - `inValue` must be a `InEuint128` to preserve confidentiality.
*/
function encTransfer(address to, InEuint128 memory inValue) external returns (euint128 transferred);
/**
* @dev See {IERC20-transfer}.
*
* Intended to be used as part of a contract call.
* Ensure that `value` is allowed to be used by using `FHE.allow` with this contracts address.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
* - `value` must be a `euint128` to preserve confidentiality.
*/
function encTransfer(address to, euint128 value) external returns (euint128 transferred);
/**
* @dev See {IERC20-allowance}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20.
* Allowances have been removed from FHERC20s to prevent encrypted balance leakage.
* Allowances have been replaced with an EIP712 permit for each `encTransferFrom`.
*/
function allowance(address, address) external pure returns (uint256);
/**
* @dev See {IERC20-approve}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20.
* Allowances have been removed from FHERC20s to prevent encrypted balance leakage.
* Allowances have been replaced with an EIP712 permit for each `encTransferFrom`.
*/
function approve(address, uint256) external pure returns (bool);
/**
* @dev See {IERC20-transferFrom}.
* Always reverts to prevent FHERC20 from being unintentionally treated as an ERC20
*/
function transferFrom(address, address, uint256) external pure returns (bool);
/**
* @dev See {IERC20-transferFrom}.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function encTransferFrom(
address from,
address to,
InEuint128 memory inValue,
FHERC20_EIP712_Permit calldata permit
) external returns (euint128 transferred);
// EIP712 Permit
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.25;
import { IERC20Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
/**
* @dev Standard FHERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IFHERC20Errors is IERC20Errors {
/**
* @dev Indicates an incompatible function being called.
* Prevents unintentional treatment of an FHERC20 as a cleartext ERC20
*/
error FHERC20IncompatibleFunction();
/**
* @dev encTransferFrom `from` and `permit.owner` don't match
* @param from encTransferFrom param.
* @param permitOwner token owner included in FHERC20_EIP712_Permit struct.
*/
error FHERC20EncTransferFromOwnerMismatch(address from, address permitOwner);
/**
* @dev encTransferFrom `to` and `permit.spender` don't match
* @param to encTransferFrom param.
* @param permitSpender token receiver included in FHERC20_EIP712_Permit struct.
*/
error FHERC20EncTransferFromSpenderMismatch(address to, address permitSpender);
/**
* @dev encTransferFrom `value` greater than `permit.value_hash` dont match (permit doesn't match InEuint128)
* @param inValueHash encTransferFrom param inValue.ctHash.
* @param permitValueHash token amount hash included in FHERC20_EIP712_Permit struct.
*/
error FHERC20EncTransferFromValueHashMismatch(uint256 inValueHash, uint256 permitValueHash);
/**
* @dev Permit deadline has expired.
* @param deadline Expired deadline of the FHERC20_EIP712_Permit.
*/
error ERC2612ExpiredSignature(uint256 deadline);
/**
* @dev Mismatched signature.
* @param signer ECDSA recovered signer of the FHERC20_EIP712_Permit.
* @param owner Owner passed in as part of the FHERC20_EIP712_Permit struct.
*/
error ERC2612InvalidSigner(address signer, address owner);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.25;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface IWETH is IERC20 {
function withdraw(uint256 amount) external;
function deposit() external payable;
}{
"evmVersion": "cancun",
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {}
}Contract ABI
API[{"inputs":[{"internalType":"contract IWETH","name":"wETH_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyClaimed","type":"error"},{"inputs":[],"name":"ClaimNotFound","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"ERC2612ExpiredSignature","type":"error"},{"inputs":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC2612InvalidSigner","type":"error"},{"inputs":[],"name":"ETHTransferFailed","type":"error"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"permitOwner","type":"address"}],"name":"FHERC20EncTransferFromOwnerMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"permitSpender","type":"address"}],"name":"FHERC20EncTransferFromSpenderMismatch","type":"error"},{"inputs":[{"internalType":"uint256","name":"inValueHash","type":"uint256"},{"internalType":"uint256","name":"permitValueHash","type":"uint256"}],"name":"FHERC20EncTransferFromValueHashMismatch","type":"error"},{"inputs":[],"name":"FHERC20IncompatibleFunction","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"currentNonce","type":"uint256"}],"name":"InvalidAccountNonce","type":"error"},{"inputs":[{"internalType":"uint8","name":"got","type":"uint8"},{"internalType":"uint8","name":"expected","type":"uint8"}],"name":"InvalidEncryptedInput","type":"error"},{"inputs":[],"name":"InvalidRecipient","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"int32","name":"value","type":"int32"}],"name":"SecurityZoneOutOfBounds","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint128","name":"value","type":"uint128"}],"name":"ClaimedDecryptedETH","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint128","name":"value","type":"uint128"}],"name":"DecryptedETH","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value_hash","type":"uint256"}],"name":"EncTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"EncryptedETH","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint128","name":"value","type":"uint128"}],"name":"EncryptedWETH","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceOfIsIndicator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimAllDecrypted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ctHash","type":"uint256"}],"name":"claimDecrypted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint128","name":"value","type":"uint128"}],"name":"decrypt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"encBalanceOf","outputs":[{"internalType":"euint128","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"encTotalSupply","outputs":[{"internalType":"euint128","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"uint256","name":"ctHash","type":"uint256"},{"internalType":"uint8","name":"securityZone","type":"uint8"},{"internalType":"uint8","name":"utype","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct InEuint128","name":"inValue","type":"tuple"}],"name":"encTransfer","outputs":[{"internalType":"euint128","name":"transferred","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"euint128","name":"value","type":"uint256"}],"name":"encTransfer","outputs":[{"internalType":"euint128","name":"transferred","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"uint256","name":"ctHash","type":"uint256"},{"internalType":"uint8","name":"securityZone","type":"uint8"},{"internalType":"uint8","name":"utype","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct InEuint128","name":"inValue","type":"tuple"},{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value_hash","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct IFHERC20.FHERC20_EIP712_Permit","name":"permit","type":"tuple"}],"name":"encTransferFrom","outputs":[{"internalType":"euint128","name":"transferred","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"encryptETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint128","name":"value","type":"uint128"}],"name":"encryptWETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"erc20","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"ctHash","type":"uint256"}],"name":"getClaim","outputs":[{"components":[{"internalType":"uint256","name":"ctHash","type":"uint256"},{"internalType":"uint128","name":"requestedAmount","type":"uint128"},{"internalType":"uint128","name":"decryptedAmount","type":"uint128"},{"internalType":"bool","name":"decrypted","type":"bool"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bool","name":"claimed","type":"bool"}],"internalType":"struct ConfidentialClaim.Claim","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserClaims","outputs":[{"components":[{"internalType":"uint256","name":"ctHash","type":"uint256"},{"internalType":"uint128","name":"requestedAmount","type":"uint128"},{"internalType":"uint128","name":"decryptedAmount","type":"uint128"},{"internalType":"bool","name":"decrypted","type":"bool"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bool","name":"claimed","type":"bool"}],"internalType":"struct ConfidentialClaim.Claim[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"indicatorTick","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isFherc20","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resetIndicatedBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"wETH","outputs":[{"internalType":"contract IWETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
610160604052348015610010575f80fd5b506040516135e63803806135e683398101604081905261002f91610320565b336040518060400160405280601a81526020017f436f6e666964656e7469616c2057726170706564204554484552000000000000815250604051806040016040528060048152602001630ca8aa8960e31b815250836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100bf573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e3919061034d565b6040805180820190915260018152603160f81b60208201528390610107825f610260565b61012052610116816001610260565b61014052815160208084019190912060e052815190820120610100524660a0526101a260e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b60805250503060c05260076101b78482610405565b5060086101c48382610405565b506009805460ff191660ff8316908117909155600410156101fa576101ea6004826104d8565b6101f590600a6105d1565b6101fd565b60015b600a555050506001600160a01b03811661023157604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b61023a81610292565b50600e80546001600160a01b0319166001600160a01b0392909216919091179055610637565b5f60208351101561027b57610274836102e3565b905061028c565b816102868482610405565b5060ff90505b92915050565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f80829050601f8151111561030d578260405163305a27a960e01b815260040161022891906105df565b805161031882610614565b179392505050565b5f60208284031215610330575f80fd5b81516001600160a01b0381168114610346575f80fd5b9392505050565b5f6020828403121561035d575f80fd5b815160ff81168114610346575f80fd5b634e487b7160e01b5f52604160045260245ffd5b600181811c9082168061039557607f821691505b6020821081036103b357634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561040057805f5260205f20601f840160051c810160208510156103de5750805b601f840160051c820191505b818110156103fd575f81556001016103ea565b50505b505050565b81516001600160401b0381111561041e5761041e61036d565b6104328161042c8454610381565b846103b9565b602080601f831160018114610465575f841561044e5750858301515b5f19600386901b1c1916600185901b1785556104bc565b5f85815260208120601f198616915b8281101561049357888601518255948401946001909101908401610474565b50858210156104b057878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b634e487b7160e01b5f52601160045260245ffd5b60ff828116828216039081111561028c5761028c6104c4565b600181815b8085111561052b57815f1904821115610511576105116104c4565b8085161561051e57918102915b93841c93908002906104f6565b509250929050565b5f826105415750600161028c565b8161054d57505f61028c565b8160018114610563576002811461056d57610589565b600191505061028c565b60ff84111561057e5761057e6104c4565b50506001821b61028c565b5060208310610133831016604e8410600b84101617156105ac575081810a61028c565b6105b683836104f1565b805f19048211156105c9576105c96104c4565b029392505050565b5f61034660ff841683610533565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b805160208083015191908110156103b3575f1960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051612f5e6106885f395f61146101525f61143501525f6112be01525f61129601525f6111f101525f61121b01525f6112450152612f5e5ff3fe6080604052600436106101d9575f3560e01c806384b0196e11610100578063b4b2019011610099578063dfc4d7c71161006b578063dfc4d7c7146104ff578063e985fb4614610533578063f242862114610552578063f2fde38b14610571578063f9f89c9b1461059057005b8063b4b201901461047f578063bab20208146104a7578063c34ea859146104c6578063dd62ed3e146104e557005b8063a415f269116100d2578063a415f269146102c0578063a64d572814610441578063a9059cbb1461020c578063aa3502921461046057005b806384b0196e146103d55780638da5cb5b146103fc57806395d89b41146104195780639a04a3121461042d57005b8063490690f311610172578063785e9e8611610144578063785e9e86146103465780637b525a0e146103775780637bcb4a641461038a5780637ecebe00146103b657005b8063490690f3146102d35780635aef2447146102e757806370a0823114610313578063715018a61461033257005b80632e81ef79116101ab5780632e81ef7914610277578063313ce5671461028b5780633644e515146102ac578063365ac002146102c057005b806306fdde03146101e2578063095ea7b31461020c57806318160ddd1461023b57806323b872dd1461025d57005b366101e057005b005b3480156101ed575f80fd5b506101f66105af565b60405161020391906128b9565b60405180910390f35b348015610217575f80fd5b5061022b6102263660046128e6565b61063f565b6040519015158152602001610203565b348015610246575f80fd5b5061024f610659565b604051908152602001610203565b348015610268575f80fd5b5061022b61022636600461290e565b348015610282575f80fd5b506101e0610673565b348015610296575f80fd5b5060095460405160ff9091168152602001610203565b3480156102b7575f80fd5b5061024f6107dd565b3480156102cb575f80fd5b50600161022b565b3480156102de575f80fd5b50600a5461024f565b3480156102f2575f80fd5b50610306610301366004612947565b6107e6565b60405161020391906129b3565b34801561031e575f80fd5b5061024f61032d3660046129c1565b610899565b34801561033d575f80fd5b506101e06108c9565b348015610351575f80fd5b50600e546001600160a01b03165b6040516001600160a01b039091168152602001610203565b6101e06103853660046129c1565b6108dc565b348015610395575f80fd5b506103a96103a43660046129c1565b610943565b60405161020391906129da565b3480156103c1575f80fd5b5061024f6103d03660046129c1565b610b22565b3480156103e0575f80fd5b506103e9610b3f565b6040516102039796959493929190612a55565b348015610407575f80fd5b50600b546001600160a01b031661035f565b348015610424575f80fd5b506101f6610b81565b348015610438575f80fd5b5060065461024f565b34801561044c575f80fd5b506101e061045b366004612ac4565b610b90565b34801561046b575f80fd5b5061024f61047a366004612c47565b610c7c565b34801561048a575f80fd5b506101e0335f908152600360205260409020805461ffff19169055565b3480156104b2575f80fd5b5061024f6104c13660046128e6565b610c91565b3480156104d1575f80fd5b506101e06104e0366004612947565b610ca6565b3480156104f0575f80fd5b5061024f610226366004612c92565b34801561050a575f80fd5b5061024f6105193660046129c1565b6001600160a01b03165f9081526004602052604090205490565b34801561053e575f80fd5b5061024f61054d366004612cc3565b610d9a565b34801561055d575f80fd5b50600e5461035f906001600160a01b031681565b34801561057c575f80fd5b506101e061058b3660046129c1565b61104f565b34801561059b575f80fd5b506101e06105aa366004612ac4565b61108c565b6060600780546105be90612d38565b80601f01602080910402602001604051908101604052809291908181526020018280546105ea90612d38565b80156106355780601f1061060c57610100808354040283529160200191610635565b820191905f5260205f20905b81548152906001019060200180831161061857829003601f168201915b5050505050905090565b5f60405163d411f9a960e01b815260040160405180910390fd5b600a546005545f9161066e9161ffff16612d84565b905090565b5f61067c611105565b90505f5b81518110156107d9575f82828151811061069c5761069c612d9b565b6020026020010151608001516001600160a01b03168383815181106106c3576106c3612d9b565b6020026020010151604001516001600160801b03166040515f6040518083038185875af1925050503d805f8114610715576040519150601f19603f3d011682016040523d82523d5f602084013e61071a565b606091505b505090508061073c5760405163b12d13eb60e01b815260040160405180910390fd5b82828151811061074e5761074e612d9b565b6020026020010151608001516001600160a01b0316336001600160a01b03167f4dad872852846b196bc1d02bfc8b3ce902adb76a418e89ac44a43f2c6769be7b8585815181106107a0576107a0612d9b565b6020026020010151604001516040516107c891906001600160801b0391909116815260200190565b60405180910390a350600101610680565b5050565b5f61066e6111e5565b6107ee612857565b5f828152600c60209081526040808320815160c0810183528154815260018201546001600160801b0380821695830195909552600160801b9004909316918301919091526002015460ff808216151560608401526001600160a01b036101008304166080840152600160a81b90910416151560a082015290806108708561130e565b9150915061087d82611327565b6001600160801b03166040840152151560608301525092915050565b600a546001600160a01b0382165f9081526003602052604081205490916108c39161ffff16612d84565b92915050565b6108d161135e565b6108da5f61138b565b565b6001600160a01b0381166108ed5750335b6108ff816108fa34611327565b6113dc565b506040513481526001600160a01b0382169033907f1e44a64c60b655bab6b04784fe476fb93a2a2f3199e4783ecf83a34f22606bef9060200160405180910390a350565b6001600160a01b0381165f908152600d602052604081206060919061096790611422565b90505f815167ffffffffffffffff81111561098457610984612b04565b6040519080825280602002602001820160405280156109bd57816020015b6109aa612857565b8152602001906001900390816109a25790505b5090505f5b8251811015610b1a57600c5f8483815181106109e0576109e0612d9b565b60209081029190910181015182528181019290925260409081015f20815160c0810183528154815260018201546001600160801b0380821695830195909552600160801b9004909316918301919091526002015460ff808216151560608401526001600160a01b036101008304166080840152600160a81b90910416151560a08201528251839083908110610a7757610a77612d9b565b60200260200101819052505f80610aa6858481518110610a9957610a99612d9b565b602002602001015161130e565b91509150610ab382611327565b848481518110610ac557610ac5612d9b565b6020026020010151604001906001600160801b031690816001600160801b03168152505080848481518110610afc57610afc612d9b565b602090810291909101015190151560609091015250506001016109c2565b509392505050565b6001600160a01b0381165f908152600260205260408120546108c3565b5f6060805f805f6060610b5061142e565b610b5861145a565b604080515f80825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6060600880546105be90612d38565b6001600160a01b038216610ba2573391505b600e54610bc3906001600160a01b031633306001600160801b038516611487565b600e54604051632e1a7d4d60e01b81526001600160801b03831660048201526001600160a01b0390911690632e1a7d4d906024015f604051808303815f87803b158015610c0e575f80fd5b505af1158015610c20573d5f803e3d5ffd5b50505050610c2e82826113dc565b506040516001600160801b03821681526001600160a01b0383169033907f22d919f8fb2c2e1f00bac873af4fa566d451a197adf8419a982aa8a0d611e4ad9060200160405180910390a35050565b5f610c8a836104c1846114e7565b9392505050565b5f33610c9e81858561157c565b949350505050565b5f610cb0826115da565b90505f81608001516001600160a01b031682604001516001600160801b03166040515f6040518083038185875af1925050503d805f8114610d0c576040519150601f19603f3d011682016040523d82523d5f602084013e610d11565b606091505b5050905080610d335760405163b12d13eb60e01b815260040160405180910390fd5b81608001516001600160a01b0316336001600160a01b03167f4dad872852846b196bc1d02bfc8b3ce902adb76a418e89ac44a43f2c6769be7b8460400151604051610d8d91906001600160801b0391909116815260200190565b60405180910390a3505050565b5f8160600135421115610dcb5760405163313c898160e11b8152606083013560048201526024015b60405180910390fd5b610dd860208301836129c1565b6001600160a01b0316856001600160a01b031614610e2a5784610dfe60208401846129c1565b6040516312441e3960e21b81526001600160a01b03928316600482015291166024820152604401610dc2565b610e3a60408301602084016129c1565b6001600160a01b0316336001600160a01b031614610e8f5733610e6360408401602085016129c1565b60405163ae8c825f60e01b81526001600160a01b03928316600482015291166024820152604401610dc2565b8251604083013514610ec35782516040805163112139c560e01b815260048101929092528301356024820152604401610dc2565b5f7f93d8009bee40988d1c028b4098d01ce80031d9f6d397b9d85bbf53f8390279df610ef260208501856129c1565b610f0260408601602087016129c1565b6040860135610f39610f1760208901896129c1565b6001600160a01b03165f90815260026020526040902080546001810190915590565b8760600135604051602001610f82969594939291909586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b6040516020818303038152906040528051906020012090505f610fa48261177e565b90505f610fca82610fbb60a0880160808901612daf565b8760a001358860c001356117aa565b9050610fd960208601866129c1565b6001600160a01b0316816001600160a01b03161461102b5780610fff60208701876129c1565b6040516325c0072360e11b81526001600160a01b03928316600482015291166024820152604401610dc2565b5f611035876114e7565b905061104289898361157c565b9998505050505050505050565b61105761135e565b6001600160a01b03811661108057604051631e4fbdf760e01b81525f6004820152602401610dc2565b6110898161138b565b50565b6001600160a01b03821661109e573391505b5f6110a933836117d6565b90506110b481611817565b6110bf838383611839565b6040516001600160801b03831681526001600160a01b0384169033907f626bc4dd07035597c477c46b5da5c3397c49c6df13e99a17614c1a03db5892a390602001610d8d565b335f908152600d6020526040902060609061111f9061190b565b67ffffffffffffffff81111561113757611137612b04565b60405190808252806020026020018201604052801561117057816020015b61115d612857565b8152602001906001900390816111555790505b50335f908152600d602052604081209192509061118c90611422565b90505f5b81518110156111e0576111bb8282815181106111ae576111ae612d9b565b60200260200101516115da565b8382815181106111cd576111cd612d9b565b6020908102919091010152600101611190565b505090565b5f306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614801561123d57507f000000000000000000000000000000000000000000000000000000000000000046145b1561126757507f000000000000000000000000000000000000000000000000000000000000000090565b61066e604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b5f805f8061131b85611914565b90969095509350505050565b5f6001600160801b0382111561135a576040516306dfcc6560e41b81526080600482015260248101839052604401610dc2565b5090565b600b546001600160a01b031633146108da5760405163118cdaa760e01b8152336004820152602401610dc2565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f6001600160a01b0383166114065760405163ec442f0560e01b81525f6004820152602401610dc2565b610c8a5f8461141d856001600160801b0316611992565b61199d565b60605f610c8a83611d09565b606061066e7f00000000000000000000000000000000000000000000000000000000000000005f611d62565b606061066e7f00000000000000000000000000000000000000000000000000000000000000006001611d62565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526114e1908590611e0b565b50505050565b60408101515f9060069060ff1681146115265760408084015190516367cf307160e01b815260ff91821660048201529082166024820152604401610dc2565b60408051608080820183525f808352602080840182905283850191909152606092830183905283519182018452865182528087015160ff16908201526006928101929092528085015190820152610c8a90611e77565b5f6001600160a01b0384166115a657604051634b637e8f60e11b81525f6004820152602401610dc2565b6001600160a01b0383166115cf5760405163ec442f0560e01b81525f6004820152602401610dc2565b610c9e84848461199d565b6115e2612857565b505f818152600c6020908152604091829020825160c0810184528154815260018201546001600160801b0380821694830194909452600160801b90049092169282019290925260029091015460ff808216151560608401526001600160a01b0361010083041660808401819052600160a81b90920416151560a083015261167c5760405163022af77760e11b815260040160405180910390fd5b8060a001511561169f57604051630c8d9eab60e31b815260040160405180910390fd5b5f6116b16116ac84611ef2565b611327565b6001600160801b03818116604085810191825260016060870181815260a088018281525f8a8152600c60209081528582208b518155818c01519751978916600160801b9890991697909702979097179386019390935590516002909401805460808a015192516001600160a81b0319909116951515610100600160a81b031916959095176101006001600160a01b039093169283021760ff60a81b1916600160a81b9515159590950294909417909355918252600d909252209091506117779084611efc565b5050919050565b5f6108c361178a6111e5565b8360405161190160f01b8152600281019290925260228201526042902090565b5f805f806117ba88888888611f07565b9250925092506117ca8282611fcf565b50909695505050505050565b5f6001600160a01b03831661180057604051634b637e8f60e11b81525f6004820152602401610dc2565b610c8a835f61141d856001600160801b0316611992565b61182081612087565b6118305761182d5f611992565b90505b6107d981612090565b6040805160c0810182528281526001600160801b0380851660208084019182525f848601818152606086018281526001600160a01b03808c166080890181815260a08a018681528c8752600c88528b87209a518b55975194518916600160801b0294909816939093176001890155905160029097018054965195511515600160a81b0260ff60a81b199690921661010002610100600160a81b0319981515989098166001600160a81b0319909716969096179690961793909316949094179092558252600d9052206114e190826120fe565b5f6108c3825490565b60405163458693c960e01b8152600481018290525f90819073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d99063458693c9906024016040805180830381865afa158015611965573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119899190612dc8565b91509150915091565b5f6108c3825f612109565b5f6001600160a01b038416156119ea576001600160a01b0384165f908152600460205260409020546119e3906119d4908490612117565b836119de5f611992565b612122565b90506119ed565b50805b6001600160a01b038416611a3657600554611a0b9061ffff1661217b565b6005805461ffff191661ffff92909216919091179055600654611a2e90826121ab565b600655611ab5565b6001600160a01b0384165f90815260046020526040902054611a5890826121ec565b6001600160a01b0385165f90815260046020908152604080832093909355600390522054611a899061ffff1661222d565b6001600160a01b0385165f908152600360205260409020805461ffff191661ffff929092169190911790555b6001600160a01b038316611afe57600554611ad39061ffff1661222d565b6005805461ffff191661ffff92909216919091179055600654611af690826121ec565b600655611b7d565b6001600160a01b0383165f90815260046020526040902054611b2090826121ab565b6001600160a01b0384165f90815260046020908152604080832093909355600390522054611b519061ffff1661217b565b6001600160a01b0384165f908152600360205260409020805461ffff191661ffff929092169190911790555b6001600160a01b0384165f9081526004602052604090205415611be7576001600160a01b0384165f90815260046020526040902054611bbb9061225c565b6001600160a01b0384165f90815260046020526040902054611bdd90856122c6565b611be781856122c6565b6001600160a01b0383165f9081526004602052604090205415611c51576001600160a01b0383165f90815260046020526040902054611c259061225c565b6001600160a01b0383165f90815260046020526040902054611c4790846122c6565b611c5181846122c6565b611c5b81336122c6565b611c66600654612339565b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600a54604051611cad91815260200190565b60405180910390a3826001600160a01b0316846001600160a01b03167f27717e7ab7bb4c260a567a3e9e1800d1d1d9f9dda250385529cb585b7f549e9483604051611cfa91815260200190565b60405180910390a39392505050565b6060815f01805480602002602001604051908101604052809291908181526020018280548015611d5657602002820191905f5260205f20905b815481526020019060010190808311611d42575b50505050509050919050565b606060ff8314611d7c57611d7583612371565b90506108c3565b818054611d8890612d38565b80601f0160208091040260200160405190810160405280929190818152602001828054611db490612d38565b8015611dff5780601f10611dd657610100808354040283529160200191611dff565b820191905f5260205f20905b815481529060010190602001808311611de257829003601f168201915b505050505090506108c3565b5f8060205f8451602086015f885af180611e2a576040513d5f823e3d81fd5b50505f513d91508115611e41578060011415611e4e565b6001600160a01b0384163b155b156114e157604051635274afe760e01b81526001600160a01b0385166004820152602401610dc2565b6040516313fce3b160e11b81525f9073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906327f9c76290611eb29085903390600401612def565b6020604051808303815f875af1158015611ece573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108c39190612e46565b5f6108c3826123ae565b5f610c8a83836123fe565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115611f4057505f91506003905082611fc5565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015611f91573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b038116611fbc57505f925060019150829050611fc5565b92505f91508190505b9450945094915050565b5f826003811115611fe257611fe2612e5d565b03611feb575050565b6001826003811115611fff57611fff612e5d565b0361201d5760405163f645eedf60e01b815260040160405180910390fd5b600282600381111561203157612031612e5d565b036120525760405163fce698f760e01b815260048101829052602401610dc2565b600382600381111561206657612066612e5d565b036107d9576040516335e2f38360e21b815260048101829052602401610dc2565b5f8115156108c3565b604051630828982760e01b8152600481018290523360248201525f9073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906308289827906044015f604051808303815f87803b1580156120e2575f80fd5b505af11580156120f4573d5f803e3d5ffd5b5093949350505050565b5f610c8a83836124e8565b5f80610c9e84600685612534565b5f610c8a83836125d9565b5f61212c84612087565b61213c576121395f61261a565b93505b61214583612087565b612155576121525f611992565b92505b61215e82612087565b61216e5761216b5f611992565b91505b610c9e6006858585612625565b5f61ffff8216158061219257508161ffff1661270f145b156121a05750611389919050565b6108c3826001612e71565b5f6121b583612087565b6121c5576121c25f611992565b92505b6121ce82612087565b6121de576121db5f611992565b91505b610c8a6006848460086126c8565b5f6121f683612087565b612206576122035f611992565b92505b61220f82612087565b61221f5761221c5f611992565b91505b610c8a6006848460076126c8565b5f61ffff8216158061224357508161ffff166001145b156122515750611387919050565b6108c3600183612e8c565b604051631974142760e21b81526004810182905230602482015273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906365d0509c906044015b5f604051808303815f87803b1580156122ad575f80fd5b505af11580156122bf573d5f803e3d5ffd5b5050505050565b604051631974142760e21b8152600481018390526001600160a01b038216602482015273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906365d0509c906044015f604051808303815f87803b15801561231f575f80fd5b505af1158015612331573d5f803e3d5ffd5b505050505050565b604051631a778f2d60e11b81526004810182905273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906334ef1e5a90602401612296565b60605f61237d836126ef565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b60405163f6bc7f3f60e01b8152600481018290525f9073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d99063f6bc7f3f90602401602060405180830381865afa158015611ece573d5f803e3d5ffd5b5f81815260018301602052604081205480156124d8575f612420600183612ea7565b85549091505f9061243390600190612ea7565b9050808214612492575f865f01828154811061245157612451612d9b565b905f5260205f200154905080875f01848154811061247157612471612d9b565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806124a3576124a3612eba565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f9055600193505050506108c3565b5f9150506108c3565b5092915050565b5f81815260018301602052604081205461252d57508154600181810184555f8481526020808220909301849055845484825282860190935260409020919091556108c3565b505f6108c3565b604080515f8082526020820190925273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d990631888debd908590601a9061257a898960ff166125758a612716565b61274b565b6040518563ffffffff1660e01b81526004016125999493929190612ece565b6020604051808303815f875af11580156125b5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c9e9190612e46565b5f6125e383612087565b6125f3576125f05f611992565b92505b6125fc82612087565b61260c576126095f611992565b91505b610c8a6006848460136126c8565b5f6108c3825f6127d6565b5f73ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9631888debd86600461264e88888861274b565b604080515f815260208101918290526001600160e01b031960e087901b1690915261267f9392919060248101612ece565b6020604051808303815f875af115801561269b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126bf9190612e46565b95945050505050565b5f73ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9631888debd868461264e88886127ee565b5f60ff8216601f8111156108c357604051632cd44ac360e21b815260040160405180910390fd5b5f808260030b1215612741576040516311ead17f60e31b8152600383900b6004820152602401610dc2565b5063ffffffff1690565b604080516003808252608082019092526060915f919060208201848036833701905050905084815f8151811061278357612783612d9b565b60200260200101818152505083816001815181106127a3576127a3612d9b565b60200260200101818152505082816002815181106127c3576127c3612d9b565b6020908102919091010152949350505050565b5f8083156127e2575060015b5f6126bf825f86612534565b60408051600280825260608083018452925f92919060208301908036833701905050905083815f8151811061282557612825612d9b565b602002602001018181525050828160018151811061284557612845612d9b565b60209081029190910101529392505050565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a081019190915290565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f610c8a602083018461288b565b80356001600160a01b03811681146128e1575f80fd5b919050565b5f80604083850312156128f7575f80fd5b612900836128cb565b946020939093013593505050565b5f805f60608486031215612920575f80fd5b612929846128cb565b9250612937602085016128cb565b9150604084013590509250925092565b5f60208284031215612957575f80fd5b5035919050565b8051825260208101516001600160801b038082166020850152806040840151166040850152505060608101511515606083015260018060a01b03608082015116608083015260a0810151151560a08301525050565b60c081016108c3828461295e565b5f602082840312156129d1575f80fd5b610c8a826128cb565b602080825282518282018190525f9190848201906040850190845b818110156117ca57612a0883855161295e565b9284019260c092909201916001016129f5565b5f815180845260208085019450602084015f5b83811015612a4a57815187529582019590820190600101612a2e565b509495945050505050565b60ff60f81b8816815260e060208201525f612a7360e083018961288b565b8281036040840152612a85818961288b565b606084018890526001600160a01b038716608085015260a0840186905283810360c08501529050612ab68185612a1b565b9a9950505050505050505050565b5f8060408385031215612ad5575f80fd5b612ade836128cb565b915060208301356001600160801b0381168114612af9575f80fd5b809150509250929050565b634e487b7160e01b5f52604160045260245ffd5b6040516080810167ffffffffffffffff81118282101715612b3b57612b3b612b04565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715612b6a57612b6a612b04565b604052919050565b803560ff811681146128e1575f80fd5b5f60808284031215612b92575f80fd5b612b9a612b18565b9050813581526020612bad818401612b72565b81830152612bbd60408401612b72565b6040830152606083013567ffffffffffffffff80821115612bdc575f80fd5b818501915085601f830112612bef575f80fd5b813581811115612c0157612c01612b04565b612c13601f8201601f19168501612b41565b91508082528684828501011115612c28575f80fd5b80848401858401375f8482840101525080606085015250505092915050565b5f8060408385031215612c58575f80fd5b612c61836128cb565b9150602083013567ffffffffffffffff811115612c7c575f80fd5b612c8885828601612b82565b9150509250929050565b5f8060408385031215612ca3575f80fd5b612cac836128cb565b9150612cba602084016128cb565b90509250929050565b5f805f80848603610140811215612cd8575f80fd5b612ce1866128cb565b9450612cef602087016128cb565b9350604086013567ffffffffffffffff811115612d0a575f80fd5b612d1688828901612b82565b93505060e0605f1982011215612d2a575f80fd5b509295919450926060019150565b600181811c90821680612d4c57607f821691505b602082108103612d6a57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176108c3576108c3612d70565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215612dbf575f80fd5b610c8a82612b72565b5f8060408385031215612dd9575f80fd5b8251915060208301518015158114612af9575f80fd5b604081528251604082015260ff602084015116606082015260ff60408401511660808201525f6060840151608060a0840152612e2e60c084018261288b565b91505060018060a01b03831660208301529392505050565b5f60208284031215612e56575f80fd5b5051919050565b634e487b7160e01b5f52602160045260245ffd5b61ffff8181168382160190808211156124e1576124e1612d70565b61ffff8281168282160390808211156124e1576124e1612d70565b818103818111156108c3576108c3612d70565b634e487b7160e01b5f52603160045260245ffd5b60ff851681525f60208510612ef157634e487b7160e01b5f52602160045260245ffd5b84602083015260806040830152612f0b6080830185612a1b565b8281036060840152612f1d8185612a1b565b97965050505050505056fea2646970667358221220f548e59bf4eb86f3dd5b4d3b1aa290e7ea690fcb01454a37d4b7145a96feb64464736f6c634300081900330000000000000000000000007b79995e5f793a07bc00c21412e50ecae098e7f9
Deployed Bytecode
0x6080604052600436106101d9575f3560e01c806384b0196e11610100578063b4b2019011610099578063dfc4d7c71161006b578063dfc4d7c7146104ff578063e985fb4614610533578063f242862114610552578063f2fde38b14610571578063f9f89c9b1461059057005b8063b4b201901461047f578063bab20208146104a7578063c34ea859146104c6578063dd62ed3e146104e557005b8063a415f269116100d2578063a415f269146102c0578063a64d572814610441578063a9059cbb1461020c578063aa3502921461046057005b806384b0196e146103d55780638da5cb5b146103fc57806395d89b41146104195780639a04a3121461042d57005b8063490690f311610172578063785e9e8611610144578063785e9e86146103465780637b525a0e146103775780637bcb4a641461038a5780637ecebe00146103b657005b8063490690f3146102d35780635aef2447146102e757806370a0823114610313578063715018a61461033257005b80632e81ef79116101ab5780632e81ef7914610277578063313ce5671461028b5780633644e515146102ac578063365ac002146102c057005b806306fdde03146101e2578063095ea7b31461020c57806318160ddd1461023b57806323b872dd1461025d57005b366101e057005b005b3480156101ed575f80fd5b506101f66105af565b60405161020391906128b9565b60405180910390f35b348015610217575f80fd5b5061022b6102263660046128e6565b61063f565b6040519015158152602001610203565b348015610246575f80fd5b5061024f610659565b604051908152602001610203565b348015610268575f80fd5b5061022b61022636600461290e565b348015610282575f80fd5b506101e0610673565b348015610296575f80fd5b5060095460405160ff9091168152602001610203565b3480156102b7575f80fd5b5061024f6107dd565b3480156102cb575f80fd5b50600161022b565b3480156102de575f80fd5b50600a5461024f565b3480156102f2575f80fd5b50610306610301366004612947565b6107e6565b60405161020391906129b3565b34801561031e575f80fd5b5061024f61032d3660046129c1565b610899565b34801561033d575f80fd5b506101e06108c9565b348015610351575f80fd5b50600e546001600160a01b03165b6040516001600160a01b039091168152602001610203565b6101e06103853660046129c1565b6108dc565b348015610395575f80fd5b506103a96103a43660046129c1565b610943565b60405161020391906129da565b3480156103c1575f80fd5b5061024f6103d03660046129c1565b610b22565b3480156103e0575f80fd5b506103e9610b3f565b6040516102039796959493929190612a55565b348015610407575f80fd5b50600b546001600160a01b031661035f565b348015610424575f80fd5b506101f6610b81565b348015610438575f80fd5b5060065461024f565b34801561044c575f80fd5b506101e061045b366004612ac4565b610b90565b34801561046b575f80fd5b5061024f61047a366004612c47565b610c7c565b34801561048a575f80fd5b506101e0335f908152600360205260409020805461ffff19169055565b3480156104b2575f80fd5b5061024f6104c13660046128e6565b610c91565b3480156104d1575f80fd5b506101e06104e0366004612947565b610ca6565b3480156104f0575f80fd5b5061024f610226366004612c92565b34801561050a575f80fd5b5061024f6105193660046129c1565b6001600160a01b03165f9081526004602052604090205490565b34801561053e575f80fd5b5061024f61054d366004612cc3565b610d9a565b34801561055d575f80fd5b50600e5461035f906001600160a01b031681565b34801561057c575f80fd5b506101e061058b3660046129c1565b61104f565b34801561059b575f80fd5b506101e06105aa366004612ac4565b61108c565b6060600780546105be90612d38565b80601f01602080910402602001604051908101604052809291908181526020018280546105ea90612d38565b80156106355780601f1061060c57610100808354040283529160200191610635565b820191905f5260205f20905b81548152906001019060200180831161061857829003601f168201915b5050505050905090565b5f60405163d411f9a960e01b815260040160405180910390fd5b600a546005545f9161066e9161ffff16612d84565b905090565b5f61067c611105565b90505f5b81518110156107d9575f82828151811061069c5761069c612d9b565b6020026020010151608001516001600160a01b03168383815181106106c3576106c3612d9b565b6020026020010151604001516001600160801b03166040515f6040518083038185875af1925050503d805f8114610715576040519150601f19603f3d011682016040523d82523d5f602084013e61071a565b606091505b505090508061073c5760405163b12d13eb60e01b815260040160405180910390fd5b82828151811061074e5761074e612d9b565b6020026020010151608001516001600160a01b0316336001600160a01b03167f4dad872852846b196bc1d02bfc8b3ce902adb76a418e89ac44a43f2c6769be7b8585815181106107a0576107a0612d9b565b6020026020010151604001516040516107c891906001600160801b0391909116815260200190565b60405180910390a350600101610680565b5050565b5f61066e6111e5565b6107ee612857565b5f828152600c60209081526040808320815160c0810183528154815260018201546001600160801b0380821695830195909552600160801b9004909316918301919091526002015460ff808216151560608401526001600160a01b036101008304166080840152600160a81b90910416151560a082015290806108708561130e565b9150915061087d82611327565b6001600160801b03166040840152151560608301525092915050565b600a546001600160a01b0382165f9081526003602052604081205490916108c39161ffff16612d84565b92915050565b6108d161135e565b6108da5f61138b565b565b6001600160a01b0381166108ed5750335b6108ff816108fa34611327565b6113dc565b506040513481526001600160a01b0382169033907f1e44a64c60b655bab6b04784fe476fb93a2a2f3199e4783ecf83a34f22606bef9060200160405180910390a350565b6001600160a01b0381165f908152600d602052604081206060919061096790611422565b90505f815167ffffffffffffffff81111561098457610984612b04565b6040519080825280602002602001820160405280156109bd57816020015b6109aa612857565b8152602001906001900390816109a25790505b5090505f5b8251811015610b1a57600c5f8483815181106109e0576109e0612d9b565b60209081029190910181015182528181019290925260409081015f20815160c0810183528154815260018201546001600160801b0380821695830195909552600160801b9004909316918301919091526002015460ff808216151560608401526001600160a01b036101008304166080840152600160a81b90910416151560a08201528251839083908110610a7757610a77612d9b565b60200260200101819052505f80610aa6858481518110610a9957610a99612d9b565b602002602001015161130e565b91509150610ab382611327565b848481518110610ac557610ac5612d9b565b6020026020010151604001906001600160801b031690816001600160801b03168152505080848481518110610afc57610afc612d9b565b602090810291909101015190151560609091015250506001016109c2565b509392505050565b6001600160a01b0381165f908152600260205260408120546108c3565b5f6060805f805f6060610b5061142e565b610b5861145a565b604080515f80825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6060600880546105be90612d38565b6001600160a01b038216610ba2573391505b600e54610bc3906001600160a01b031633306001600160801b038516611487565b600e54604051632e1a7d4d60e01b81526001600160801b03831660048201526001600160a01b0390911690632e1a7d4d906024015f604051808303815f87803b158015610c0e575f80fd5b505af1158015610c20573d5f803e3d5ffd5b50505050610c2e82826113dc565b506040516001600160801b03821681526001600160a01b0383169033907f22d919f8fb2c2e1f00bac873af4fa566d451a197adf8419a982aa8a0d611e4ad9060200160405180910390a35050565b5f610c8a836104c1846114e7565b9392505050565b5f33610c9e81858561157c565b949350505050565b5f610cb0826115da565b90505f81608001516001600160a01b031682604001516001600160801b03166040515f6040518083038185875af1925050503d805f8114610d0c576040519150601f19603f3d011682016040523d82523d5f602084013e610d11565b606091505b5050905080610d335760405163b12d13eb60e01b815260040160405180910390fd5b81608001516001600160a01b0316336001600160a01b03167f4dad872852846b196bc1d02bfc8b3ce902adb76a418e89ac44a43f2c6769be7b8460400151604051610d8d91906001600160801b0391909116815260200190565b60405180910390a3505050565b5f8160600135421115610dcb5760405163313c898160e11b8152606083013560048201526024015b60405180910390fd5b610dd860208301836129c1565b6001600160a01b0316856001600160a01b031614610e2a5784610dfe60208401846129c1565b6040516312441e3960e21b81526001600160a01b03928316600482015291166024820152604401610dc2565b610e3a60408301602084016129c1565b6001600160a01b0316336001600160a01b031614610e8f5733610e6360408401602085016129c1565b60405163ae8c825f60e01b81526001600160a01b03928316600482015291166024820152604401610dc2565b8251604083013514610ec35782516040805163112139c560e01b815260048101929092528301356024820152604401610dc2565b5f7f93d8009bee40988d1c028b4098d01ce80031d9f6d397b9d85bbf53f8390279df610ef260208501856129c1565b610f0260408601602087016129c1565b6040860135610f39610f1760208901896129c1565b6001600160a01b03165f90815260026020526040902080546001810190915590565b8760600135604051602001610f82969594939291909586526001600160a01b0394851660208701529290931660408501526060840152608083019190915260a082015260c00190565b6040516020818303038152906040528051906020012090505f610fa48261177e565b90505f610fca82610fbb60a0880160808901612daf565b8760a001358860c001356117aa565b9050610fd960208601866129c1565b6001600160a01b0316816001600160a01b03161461102b5780610fff60208701876129c1565b6040516325c0072360e11b81526001600160a01b03928316600482015291166024820152604401610dc2565b5f611035876114e7565b905061104289898361157c565b9998505050505050505050565b61105761135e565b6001600160a01b03811661108057604051631e4fbdf760e01b81525f6004820152602401610dc2565b6110898161138b565b50565b6001600160a01b03821661109e573391505b5f6110a933836117d6565b90506110b481611817565b6110bf838383611839565b6040516001600160801b03831681526001600160a01b0384169033907f626bc4dd07035597c477c46b5da5c3397c49c6df13e99a17614c1a03db5892a390602001610d8d565b335f908152600d6020526040902060609061111f9061190b565b67ffffffffffffffff81111561113757611137612b04565b60405190808252806020026020018201604052801561117057816020015b61115d612857565b8152602001906001900390816111555790505b50335f908152600d602052604081209192509061118c90611422565b90505f5b81518110156111e0576111bb8282815181106111ae576111ae612d9b565b60200260200101516115da565b8382815181106111cd576111cd612d9b565b6020908102919091010152600101611190565b505090565b5f306001600160a01b037f00000000000000000000000087a3effb84cbe1e4cab6ab430139ec41d156d55a1614801561123d57507f0000000000000000000000000000000000000000000000000000000000aa36a746145b1561126757507f32158359a96ebfef507e94ad257b9e24c64357608869a3654a311038f037ce9d90565b61066e604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f6a1b9c4c81480f7abb286d74daa3da6ca34a13b15a52609589adc8f6978d3048918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b5f805f8061131b85611914565b90969095509350505050565b5f6001600160801b0382111561135a576040516306dfcc6560e41b81526080600482015260248101839052604401610dc2565b5090565b600b546001600160a01b031633146108da5760405163118cdaa760e01b8152336004820152602401610dc2565b600b80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b5f6001600160a01b0383166114065760405163ec442f0560e01b81525f6004820152602401610dc2565b610c8a5f8461141d856001600160801b0316611992565b61199d565b60605f610c8a83611d09565b606061066e7f436f6e666964656e7469616c205772617070656420455448455200000000001a5f611d62565b606061066e7f31000000000000000000000000000000000000000000000000000000000000016001611d62565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526114e1908590611e0b565b50505050565b60408101515f9060069060ff1681146115265760408084015190516367cf307160e01b815260ff91821660048201529082166024820152604401610dc2565b60408051608080820183525f808352602080840182905283850191909152606092830183905283519182018452865182528087015160ff16908201526006928101929092528085015190820152610c8a90611e77565b5f6001600160a01b0384166115a657604051634b637e8f60e11b81525f6004820152602401610dc2565b6001600160a01b0383166115cf5760405163ec442f0560e01b81525f6004820152602401610dc2565b610c9e84848461199d565b6115e2612857565b505f818152600c6020908152604091829020825160c0810184528154815260018201546001600160801b0380821694830194909452600160801b90049092169282019290925260029091015460ff808216151560608401526001600160a01b0361010083041660808401819052600160a81b90920416151560a083015261167c5760405163022af77760e11b815260040160405180910390fd5b8060a001511561169f57604051630c8d9eab60e31b815260040160405180910390fd5b5f6116b16116ac84611ef2565b611327565b6001600160801b03818116604085810191825260016060870181815260a088018281525f8a8152600c60209081528582208b518155818c01519751978916600160801b9890991697909702979097179386019390935590516002909401805460808a015192516001600160a81b0319909116951515610100600160a81b031916959095176101006001600160a01b039093169283021760ff60a81b1916600160a81b9515159590950294909417909355918252600d909252209091506117779084611efc565b5050919050565b5f6108c361178a6111e5565b8360405161190160f01b8152600281019290925260228201526042902090565b5f805f806117ba88888888611f07565b9250925092506117ca8282611fcf565b50909695505050505050565b5f6001600160a01b03831661180057604051634b637e8f60e11b81525f6004820152602401610dc2565b610c8a835f61141d856001600160801b0316611992565b61182081612087565b6118305761182d5f611992565b90505b6107d981612090565b6040805160c0810182528281526001600160801b0380851660208084019182525f848601818152606086018281526001600160a01b03808c166080890181815260a08a018681528c8752600c88528b87209a518b55975194518916600160801b0294909816939093176001890155905160029097018054965195511515600160a81b0260ff60a81b199690921661010002610100600160a81b0319981515989098166001600160a81b0319909716969096179690961793909316949094179092558252600d9052206114e190826120fe565b5f6108c3825490565b60405163458693c960e01b8152600481018290525f90819073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d99063458693c9906024016040805180830381865afa158015611965573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119899190612dc8565b91509150915091565b5f6108c3825f612109565b5f6001600160a01b038416156119ea576001600160a01b0384165f908152600460205260409020546119e3906119d4908490612117565b836119de5f611992565b612122565b90506119ed565b50805b6001600160a01b038416611a3657600554611a0b9061ffff1661217b565b6005805461ffff191661ffff92909216919091179055600654611a2e90826121ab565b600655611ab5565b6001600160a01b0384165f90815260046020526040902054611a5890826121ec565b6001600160a01b0385165f90815260046020908152604080832093909355600390522054611a899061ffff1661222d565b6001600160a01b0385165f908152600360205260409020805461ffff191661ffff929092169190911790555b6001600160a01b038316611afe57600554611ad39061ffff1661222d565b6005805461ffff191661ffff92909216919091179055600654611af690826121ec565b600655611b7d565b6001600160a01b0383165f90815260046020526040902054611b2090826121ab565b6001600160a01b0384165f90815260046020908152604080832093909355600390522054611b519061ffff1661217b565b6001600160a01b0384165f908152600360205260409020805461ffff191661ffff929092169190911790555b6001600160a01b0384165f9081526004602052604090205415611be7576001600160a01b0384165f90815260046020526040902054611bbb9061225c565b6001600160a01b0384165f90815260046020526040902054611bdd90856122c6565b611be781856122c6565b6001600160a01b0383165f9081526004602052604090205415611c51576001600160a01b0383165f90815260046020526040902054611c259061225c565b6001600160a01b0383165f90815260046020526040902054611c4790846122c6565b611c5181846122c6565b611c5b81336122c6565b611c66600654612339565b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600a54604051611cad91815260200190565b60405180910390a3826001600160a01b0316846001600160a01b03167f27717e7ab7bb4c260a567a3e9e1800d1d1d9f9dda250385529cb585b7f549e9483604051611cfa91815260200190565b60405180910390a39392505050565b6060815f01805480602002602001604051908101604052809291908181526020018280548015611d5657602002820191905f5260205f20905b815481526020019060010190808311611d42575b50505050509050919050565b606060ff8314611d7c57611d7583612371565b90506108c3565b818054611d8890612d38565b80601f0160208091040260200160405190810160405280929190818152602001828054611db490612d38565b8015611dff5780601f10611dd657610100808354040283529160200191611dff565b820191905f5260205f20905b815481529060010190602001808311611de257829003601f168201915b505050505090506108c3565b5f8060205f8451602086015f885af180611e2a576040513d5f823e3d81fd5b50505f513d91508115611e41578060011415611e4e565b6001600160a01b0384163b155b156114e157604051635274afe760e01b81526001600160a01b0385166004820152602401610dc2565b6040516313fce3b160e11b81525f9073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906327f9c76290611eb29085903390600401612def565b6020604051808303815f875af1158015611ece573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108c39190612e46565b5f6108c3826123ae565b5f610c8a83836123fe565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115611f4057505f91506003905082611fc5565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015611f91573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b038116611fbc57505f925060019150829050611fc5565b92505f91508190505b9450945094915050565b5f826003811115611fe257611fe2612e5d565b03611feb575050565b6001826003811115611fff57611fff612e5d565b0361201d5760405163f645eedf60e01b815260040160405180910390fd5b600282600381111561203157612031612e5d565b036120525760405163fce698f760e01b815260048101829052602401610dc2565b600382600381111561206657612066612e5d565b036107d9576040516335e2f38360e21b815260048101829052602401610dc2565b5f8115156108c3565b604051630828982760e01b8152600481018290523360248201525f9073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906308289827906044015f604051808303815f87803b1580156120e2575f80fd5b505af11580156120f4573d5f803e3d5ffd5b5093949350505050565b5f610c8a83836124e8565b5f80610c9e84600685612534565b5f610c8a83836125d9565b5f61212c84612087565b61213c576121395f61261a565b93505b61214583612087565b612155576121525f611992565b92505b61215e82612087565b61216e5761216b5f611992565b91505b610c9e6006858585612625565b5f61ffff8216158061219257508161ffff1661270f145b156121a05750611389919050565b6108c3826001612e71565b5f6121b583612087565b6121c5576121c25f611992565b92505b6121ce82612087565b6121de576121db5f611992565b91505b610c8a6006848460086126c8565b5f6121f683612087565b612206576122035f611992565b92505b61220f82612087565b61221f5761221c5f611992565b91505b610c8a6006848460076126c8565b5f61ffff8216158061224357508161ffff166001145b156122515750611387919050565b6108c3600183612e8c565b604051631974142760e21b81526004810182905230602482015273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906365d0509c906044015b5f604051808303815f87803b1580156122ad575f80fd5b505af11580156122bf573d5f803e3d5ffd5b5050505050565b604051631974142760e21b8152600481018390526001600160a01b038216602482015273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906365d0509c906044015f604051808303815f87803b15801561231f575f80fd5b505af1158015612331573d5f803e3d5ffd5b505050505050565b604051631a778f2d60e11b81526004810182905273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9906334ef1e5a90602401612296565b60605f61237d836126ef565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b60405163f6bc7f3f60e01b8152600481018290525f9073ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d99063f6bc7f3f90602401602060405180830381865afa158015611ece573d5f803e3d5ffd5b5f81815260018301602052604081205480156124d8575f612420600183612ea7565b85549091505f9061243390600190612ea7565b9050808214612492575f865f01828154811061245157612451612d9b565b905f5260205f200154905080875f01848154811061247157612471612d9b565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806124a3576124a3612eba565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f9055600193505050506108c3565b5f9150506108c3565b5092915050565b5f81815260018301602052604081205461252d57508154600181810184555f8481526020808220909301849055845484825282860190935260409020919091556108c3565b505f6108c3565b604080515f8082526020820190925273ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d990631888debd908590601a9061257a898960ff166125758a612716565b61274b565b6040518563ffffffff1660e01b81526004016125999493929190612ece565b6020604051808303815f875af11580156125b5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c9e9190612e46565b5f6125e383612087565b6125f3576125f05f611992565b92505b6125fc82612087565b61260c576126095f611992565b91505b610c8a6006848460136126c8565b5f6108c3825f6127d6565b5f73ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9631888debd86600461264e88888861274b565b604080515f815260208101918290526001600160e01b031960e087901b1690915261267f9392919060248101612ece565b6020604051808303815f875af115801561269b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126bf9190612e46565b95945050505050565b5f73ea30c4b8b44078bbf8a6ef5b9f1ec1626c7848d9631888debd868461264e88886127ee565b5f60ff8216601f8111156108c357604051632cd44ac360e21b815260040160405180910390fd5b5f808260030b1215612741576040516311ead17f60e31b8152600383900b6004820152602401610dc2565b5063ffffffff1690565b604080516003808252608082019092526060915f919060208201848036833701905050905084815f8151811061278357612783612d9b565b60200260200101818152505083816001815181106127a3576127a3612d9b565b60200260200101818152505082816002815181106127c3576127c3612d9b565b6020908102919091010152949350505050565b5f8083156127e2575060015b5f6126bf825f86612534565b60408051600280825260608083018452925f92919060208301908036833701905050905083815f8151811061282557612825612d9b565b602002602001018181525050828160018151811061284557612845612d9b565b60209081029190910101529392505050565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a081019190915290565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f610c8a602083018461288b565b80356001600160a01b03811681146128e1575f80fd5b919050565b5f80604083850312156128f7575f80fd5b612900836128cb565b946020939093013593505050565b5f805f60608486031215612920575f80fd5b612929846128cb565b9250612937602085016128cb565b9150604084013590509250925092565b5f60208284031215612957575f80fd5b5035919050565b8051825260208101516001600160801b038082166020850152806040840151166040850152505060608101511515606083015260018060a01b03608082015116608083015260a0810151151560a08301525050565b60c081016108c3828461295e565b5f602082840312156129d1575f80fd5b610c8a826128cb565b602080825282518282018190525f9190848201906040850190845b818110156117ca57612a0883855161295e565b9284019260c092909201916001016129f5565b5f815180845260208085019450602084015f5b83811015612a4a57815187529582019590820190600101612a2e565b509495945050505050565b60ff60f81b8816815260e060208201525f612a7360e083018961288b565b8281036040840152612a85818961288b565b606084018890526001600160a01b038716608085015260a0840186905283810360c08501529050612ab68185612a1b565b9a9950505050505050505050565b5f8060408385031215612ad5575f80fd5b612ade836128cb565b915060208301356001600160801b0381168114612af9575f80fd5b809150509250929050565b634e487b7160e01b5f52604160045260245ffd5b6040516080810167ffffffffffffffff81118282101715612b3b57612b3b612b04565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715612b6a57612b6a612b04565b604052919050565b803560ff811681146128e1575f80fd5b5f60808284031215612b92575f80fd5b612b9a612b18565b9050813581526020612bad818401612b72565b81830152612bbd60408401612b72565b6040830152606083013567ffffffffffffffff80821115612bdc575f80fd5b818501915085601f830112612bef575f80fd5b813581811115612c0157612c01612b04565b612c13601f8201601f19168501612b41565b91508082528684828501011115612c28575f80fd5b80848401858401375f8482840101525080606085015250505092915050565b5f8060408385031215612c58575f80fd5b612c61836128cb565b9150602083013567ffffffffffffffff811115612c7c575f80fd5b612c8885828601612b82565b9150509250929050565b5f8060408385031215612ca3575f80fd5b612cac836128cb565b9150612cba602084016128cb565b90509250929050565b5f805f80848603610140811215612cd8575f80fd5b612ce1866128cb565b9450612cef602087016128cb565b9350604086013567ffffffffffffffff811115612d0a575f80fd5b612d1688828901612b82565b93505060e0605f1982011215612d2a575f80fd5b509295919450926060019150565b600181811c90821680612d4c57607f821691505b602082108103612d6a57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176108c3576108c3612d70565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215612dbf575f80fd5b610c8a82612b72565b5f8060408385031215612dd9575f80fd5b8251915060208301518015158114612af9575f80fd5b604081528251604082015260ff602084015116606082015260ff60408401511660808201525f6060840151608060a0840152612e2e60c084018261288b565b91505060018060a01b03831660208301529392505050565b5f60208284031215612e56575f80fd5b5051919050565b634e487b7160e01b5f52602160045260245ffd5b61ffff8181168382160190808211156124e1576124e1612d70565b61ffff8281168282160390808211156124e1576124e1612d70565b818103818111156108c3576108c3612d70565b634e487b7160e01b5f52603160045260245ffd5b60ff851681525f60208510612ef157634e487b7160e01b5f52602160045260245ffd5b84602083015260806040830152612f0b6080830185612a1b565b8281036060840152612f1d8185612a1b565b97965050505050505056fea2646970667358221220f548e59bf4eb86f3dd5b4d3b1aa290e7ea690fcb01454a37d4b7145a96feb64464736f6c63430008190033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000007b79995e5f793a07bc00c21412e50ecae098e7f9
-----Decoded View---------------
Arg [0] : wETH_ (address): 0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000007b79995e5f793a07bc00c21412e50ecae098e7f9
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.