// SPDX-License-Identifier: BSD-3-Clause-Clear pragma solidity ^0.8.24; import "./Impl.sol"; import {FhevmECDSA} from "./cryptography/FhevmECDSA.sol"; import {FheType} from "./FheType.sol"; import "encrypted-types/EncryptedTypes.sol"; /** * @title IKMSVerifier * @notice This interface contains the only function required from KMSVerifier. */ interface IKMSVerifier { function verifyDecryptionEIP712KMSSignatures( bytes32[] memory handlesList, bytes memory decryptedResult, bytes memory decryptionProof ) external returns (bool); function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); function getContextSignersAndThresholdFromExtraData( bytes calldata extraData ) external view returns (address[] memory signers, uint256 threshold); } /** * @title FHE * @notice This library is the interaction point for all smart contract developers * that interact with the FHEVM protocol. */ library FHE { /// @notice Decryption result typehash. bytes32 private constant DECRYPTION_RESULT_TYPEHASH = keccak256("PublicDecryptVerification(bytes32[] ctHandles,bytes decryptedResult,bytes extraData)"); /// @notice EIP-712 domain typehash. bytes32 private constant EIP712_DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /// @notice Returned if the deserializing of the decryption proof fails. error DeserializingDecryptionProofFail(); /// @notice Returned if the decryption proof is empty. error EmptyDecryptionProof(); /// @notice Returned if the recovered KMS signer is not a valid KMS signer. /// @param invalidSigner Address of the invalid signer. error KMSInvalidSigner(address invalidSigner); /// @notice Returned if the number of signatures is inferior to the threshold. /// @param numSignatures Number of signatures. error KMSSignatureThresholdNotReached(uint256 numSignatures); /// @notice Returned if the number of signatures is equal to 0. error KMSZeroSignature(); /// @notice Returned if the returned KMS signatures are not valid. error InvalidKMSSignatures(); /// @notice Returned if the sender is not allowed to use the handle. error SenderNotAllowedToUseHandle(bytes32 handle, address sender); /// @notice This event is emitted when public decryption has been successfully verified. event PublicDecryptionVerified(bytes32[] handlesList, bytes abiEncodedCleartexts); /** * @notice Sets the coprocessor addresses. * @param coprocessorConfig Coprocessor config struct that contains contract addresses. */ function setCoprocessor(CoprocessorConfig memory coprocessorConfig) internal { Impl.setCoprocessor(coprocessorConfig); } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(ebool v) internal pure returns (bool) { return ebool.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(euint8 v) internal pure returns (bool) { return euint8.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(euint16 v) internal pure returns (bool) { return euint16.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(euint32 v) internal pure returns (bool) { return euint32.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(euint64 v) internal pure returns (bool) { return euint64.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(euint128 v) internal pure returns (bool) { return euint128.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(eaddress v) internal pure returns (bool) { return eaddress.unwrap(v) != 0; } /** * @dev Returns true if the encrypted integer is initialized and false otherwise. */ function isInitialized(euint256 v) internal pure returns (bool) { return euint256.unwrap(v) != 0; } /** * @dev Evaluates and(ebool a, ebool b) and returns the result. */ function and(ebool a, ebool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.and(ebool.unwrap(a), ebool.unwrap(b), false)); } /** * @dev Evaluates or(ebool a, ebool b) and returns the result. */ function or(ebool a, ebool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.or(ebool.unwrap(a), ebool.unwrap(b), false)); } /** * @dev Evaluates xor(ebool a, ebool b) and returns the result. */ function xor(ebool a, ebool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.xor(ebool.unwrap(a), ebool.unwrap(b), false)); } /** * @dev Evaluates eq(ebool a, ebool b) and returns the result. */ function eq(ebool a, ebool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.eq(ebool.unwrap(a), ebool.unwrap(b), false)); } /** * @dev Evaluates ne(ebool a, ebool b) and returns the result. */ function ne(ebool a, ebool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.ne(ebool.unwrap(a), ebool.unwrap(b), false)); } /** * @dev Evaluates add(euint8 a, euint8 b) and returns the result. */ function add(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.add(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates sub(euint8 a, euint8 b) and returns the result. */ function sub(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.sub(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates mul(euint8 a, euint8 b) and returns the result. */ function mul(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.mul(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates and(euint8 a, euint8 b) and returns the result. */ function and(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.and(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates or(euint8 a, euint8 b) and returns the result. */ function or(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.or(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates xor(euint8 a, euint8 b) and returns the result. */ function xor(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.xor(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates eq(euint8 a, euint8 b) and returns the result. */ function eq(euint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates ne(euint8 a, euint8 b) and returns the result. */ function ne(euint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates ge(euint8 a, euint8 b) and returns the result. */ function ge(euint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ge(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates gt(euint8 a, euint8 b) and returns the result. */ function gt(euint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.gt(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates le(euint8 a, euint8 b) and returns the result. */ function le(euint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.le(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates lt(euint8 a, euint8 b) and returns the result. */ function lt(euint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.lt(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates min(euint8 a, euint8 b) and returns the result. */ function min(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.min(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates max(euint8 a, euint8 b) and returns the result. */ function max(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.max(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates add(euint8 a, euint16 b) and returns the result. */ function add(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.add(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates sub(euint8 a, euint16 b) and returns the result. */ function sub(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.sub(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates mul(euint8 a, euint16 b) and returns the result. */ function mul(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.mul(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates and(euint8 a, euint16 b) and returns the result. */ function and(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.and(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates or(euint8 a, euint16 b) and returns the result. */ function or(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.or(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates xor(euint8 a, euint16 b) and returns the result. */ function xor(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.xor(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates eq(euint8 a, euint16 b) and returns the result. */ function eq(euint8 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates ne(euint8 a, euint16 b) and returns the result. */ function ne(euint8 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates ge(euint8 a, euint16 b) and returns the result. */ function ge(euint8 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ge(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates gt(euint8 a, euint16 b) and returns the result. */ function gt(euint8 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.gt(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates le(euint8 a, euint16 b) and returns the result. */ function le(euint8 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.le(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates lt(euint8 a, euint16 b) and returns the result. */ function lt(euint8 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.lt(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates min(euint8 a, euint16 b) and returns the result. */ function min(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.min(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates max(euint8 a, euint16 b) and returns the result. */ function max(euint8 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.max(euint16.unwrap(asEuint16(a)), euint16.unwrap(b), false)); } /** * @dev Evaluates add(euint8 a, euint32 b) and returns the result. */ function add(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.add(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates sub(euint8 a, euint32 b) and returns the result. */ function sub(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.sub(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates mul(euint8 a, euint32 b) and returns the result. */ function mul(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.mul(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates and(euint8 a, euint32 b) and returns the result. */ function and(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.and(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates or(euint8 a, euint32 b) and returns the result. */ function or(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.or(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates xor(euint8 a, euint32 b) and returns the result. */ function xor(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.xor(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates eq(euint8 a, euint32 b) and returns the result. */ function eq(euint8 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates ne(euint8 a, euint32 b) and returns the result. */ function ne(euint8 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates ge(euint8 a, euint32 b) and returns the result. */ function ge(euint8 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ge(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates gt(euint8 a, euint32 b) and returns the result. */ function gt(euint8 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.gt(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates le(euint8 a, euint32 b) and returns the result. */ function le(euint8 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.le(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates lt(euint8 a, euint32 b) and returns the result. */ function lt(euint8 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.lt(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates min(euint8 a, euint32 b) and returns the result. */ function min(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.min(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates max(euint8 a, euint32 b) and returns the result. */ function max(euint8 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.max(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates add(euint8 a, euint64 b) and returns the result. */ function add(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.add(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates sub(euint8 a, euint64 b) and returns the result. */ function sub(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.sub(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates mul(euint8 a, euint64 b) and returns the result. */ function mul(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.mul(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates and(euint8 a, euint64 b) and returns the result. */ function and(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.and(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates or(euint8 a, euint64 b) and returns the result. */ function or(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.or(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates xor(euint8 a, euint64 b) and returns the result. */ function xor(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.xor(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates eq(euint8 a, euint64 b) and returns the result. */ function eq(euint8 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates ne(euint8 a, euint64 b) and returns the result. */ function ne(euint8 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates ge(euint8 a, euint64 b) and returns the result. */ function ge(euint8 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ge(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates gt(euint8 a, euint64 b) and returns the result. */ function gt(euint8 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.gt(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates le(euint8 a, euint64 b) and returns the result. */ function le(euint8 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.le(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates lt(euint8 a, euint64 b) and returns the result. */ function lt(euint8 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.lt(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates min(euint8 a, euint64 b) and returns the result. */ function min(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.min(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates max(euint8 a, euint64 b) and returns the result. */ function max(euint8 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.max(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates add(euint8 a, euint128 b) and returns the result. */ function add(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates sub(euint8 a, euint128 b) and returns the result. */ function sub(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates mul(euint8 a, euint128 b) and returns the result. */ function mul(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint8 a, euint128 b) and returns the result. */ function and(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates or(euint8 a, euint128 b) and returns the result. */ function or(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates xor(euint8 a, euint128 b) and returns the result. */ function xor(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates eq(euint8 a, euint128 b) and returns the result. */ function eq(euint8 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ne(euint8 a, euint128 b) and returns the result. */ function ne(euint8 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ge(euint8 a, euint128 b) and returns the result. */ function ge(euint8 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates gt(euint8 a, euint128 b) and returns the result. */ function gt(euint8 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates le(euint8 a, euint128 b) and returns the result. */ function le(euint8 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates lt(euint8 a, euint128 b) and returns the result. */ function lt(euint8 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates min(euint8 a, euint128 b) and returns the result. */ function min(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates max(euint8 a, euint128 b) and returns the result. */ function max(euint8 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint8 a, euint256 b) and returns the result. */ function and(euint8 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates or(euint8 a, euint256 b) and returns the result. */ function or(euint8 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates xor(euint8 a, euint256 b) and returns the result. */ function xor(euint8 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(euint8 a, euint256 b) and returns the result. */ function eq(euint8 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates ne(euint8 a, euint256 b) and returns the result. */ function ne(euint8 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates add(euint16 a, euint8 b) and returns the result. */ function add(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.add(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates sub(euint16 a, euint8 b) and returns the result. */ function sub(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.sub(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates mul(euint16 a, euint8 b) and returns the result. */ function mul(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.mul(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates and(euint16 a, euint8 b) and returns the result. */ function and(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.and(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates or(euint16 a, euint8 b) and returns the result. */ function or(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.or(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates xor(euint16 a, euint8 b) and returns the result. */ function xor(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.xor(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates eq(euint16 a, euint8 b) and returns the result. */ function eq(euint16 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates ne(euint16 a, euint8 b) and returns the result. */ function ne(euint16 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates ge(euint16 a, euint8 b) and returns the result. */ function ge(euint16 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ge(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates gt(euint16 a, euint8 b) and returns the result. */ function gt(euint16 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.gt(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates le(euint16 a, euint8 b) and returns the result. */ function le(euint16 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.le(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates lt(euint16 a, euint8 b) and returns the result. */ function lt(euint16 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.lt(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates min(euint16 a, euint8 b) and returns the result. */ function min(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.min(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates max(euint16 a, euint8 b) and returns the result. */ function max(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.max(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates add(euint16 a, euint16 b) and returns the result. */ function add(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.add(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates sub(euint16 a, euint16 b) and returns the result. */ function sub(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.sub(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates mul(euint16 a, euint16 b) and returns the result. */ function mul(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.mul(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates and(euint16 a, euint16 b) and returns the result. */ function and(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.and(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates or(euint16 a, euint16 b) and returns the result. */ function or(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.or(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates xor(euint16 a, euint16 b) and returns the result. */ function xor(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.xor(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates eq(euint16 a, euint16 b) and returns the result. */ function eq(euint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates ne(euint16 a, euint16 b) and returns the result. */ function ne(euint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates ge(euint16 a, euint16 b) and returns the result. */ function ge(euint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ge(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates gt(euint16 a, euint16 b) and returns the result. */ function gt(euint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.gt(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates le(euint16 a, euint16 b) and returns the result. */ function le(euint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.le(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates lt(euint16 a, euint16 b) and returns the result. */ function lt(euint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.lt(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates min(euint16 a, euint16 b) and returns the result. */ function min(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.min(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates max(euint16 a, euint16 b) and returns the result. */ function max(euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.max(euint16.unwrap(a), euint16.unwrap(b), false)); } /** * @dev Evaluates add(euint16 a, euint32 b) and returns the result. */ function add(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.add(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates sub(euint16 a, euint32 b) and returns the result. */ function sub(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.sub(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates mul(euint16 a, euint32 b) and returns the result. */ function mul(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.mul(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates and(euint16 a, euint32 b) and returns the result. */ function and(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.and(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates or(euint16 a, euint32 b) and returns the result. */ function or(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.or(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates xor(euint16 a, euint32 b) and returns the result. */ function xor(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.xor(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates eq(euint16 a, euint32 b) and returns the result. */ function eq(euint16 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates ne(euint16 a, euint32 b) and returns the result. */ function ne(euint16 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates ge(euint16 a, euint32 b) and returns the result. */ function ge(euint16 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ge(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates gt(euint16 a, euint32 b) and returns the result. */ function gt(euint16 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.gt(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates le(euint16 a, euint32 b) and returns the result. */ function le(euint16 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.le(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates lt(euint16 a, euint32 b) and returns the result. */ function lt(euint16 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.lt(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates min(euint16 a, euint32 b) and returns the result. */ function min(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.min(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates max(euint16 a, euint32 b) and returns the result. */ function max(euint16 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.max(euint32.unwrap(asEuint32(a)), euint32.unwrap(b), false)); } /** * @dev Evaluates add(euint16 a, euint64 b) and returns the result. */ function add(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.add(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates sub(euint16 a, euint64 b) and returns the result. */ function sub(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.sub(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates mul(euint16 a, euint64 b) and returns the result. */ function mul(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.mul(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates and(euint16 a, euint64 b) and returns the result. */ function and(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.and(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates or(euint16 a, euint64 b) and returns the result. */ function or(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.or(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates xor(euint16 a, euint64 b) and returns the result. */ function xor(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.xor(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates eq(euint16 a, euint64 b) and returns the result. */ function eq(euint16 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates ne(euint16 a, euint64 b) and returns the result. */ function ne(euint16 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates ge(euint16 a, euint64 b) and returns the result. */ function ge(euint16 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ge(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates gt(euint16 a, euint64 b) and returns the result. */ function gt(euint16 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.gt(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates le(euint16 a, euint64 b) and returns the result. */ function le(euint16 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.le(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates lt(euint16 a, euint64 b) and returns the result. */ function lt(euint16 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.lt(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates min(euint16 a, euint64 b) and returns the result. */ function min(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.min(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates max(euint16 a, euint64 b) and returns the result. */ function max(euint16 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.max(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates add(euint16 a, euint128 b) and returns the result. */ function add(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates sub(euint16 a, euint128 b) and returns the result. */ function sub(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates mul(euint16 a, euint128 b) and returns the result. */ function mul(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint16 a, euint128 b) and returns the result. */ function and(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates or(euint16 a, euint128 b) and returns the result. */ function or(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates xor(euint16 a, euint128 b) and returns the result. */ function xor(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates eq(euint16 a, euint128 b) and returns the result. */ function eq(euint16 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ne(euint16 a, euint128 b) and returns the result. */ function ne(euint16 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ge(euint16 a, euint128 b) and returns the result. */ function ge(euint16 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates gt(euint16 a, euint128 b) and returns the result. */ function gt(euint16 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates le(euint16 a, euint128 b) and returns the result. */ function le(euint16 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates lt(euint16 a, euint128 b) and returns the result. */ function lt(euint16 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates min(euint16 a, euint128 b) and returns the result. */ function min(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates max(euint16 a, euint128 b) and returns the result. */ function max(euint16 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint16 a, euint256 b) and returns the result. */ function and(euint16 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates or(euint16 a, euint256 b) and returns the result. */ function or(euint16 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates xor(euint16 a, euint256 b) and returns the result. */ function xor(euint16 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(euint16 a, euint256 b) and returns the result. */ function eq(euint16 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates ne(euint16 a, euint256 b) and returns the result. */ function ne(euint16 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates add(euint32 a, euint8 b) and returns the result. */ function add(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.add(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates sub(euint32 a, euint8 b) and returns the result. */ function sub(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.sub(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates mul(euint32 a, euint8 b) and returns the result. */ function mul(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.mul(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates and(euint32 a, euint8 b) and returns the result. */ function and(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.and(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates or(euint32 a, euint8 b) and returns the result. */ function or(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.or(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates xor(euint32 a, euint8 b) and returns the result. */ function xor(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.xor(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates eq(euint32 a, euint8 b) and returns the result. */ function eq(euint32 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates ne(euint32 a, euint8 b) and returns the result. */ function ne(euint32 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates ge(euint32 a, euint8 b) and returns the result. */ function ge(euint32 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ge(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates gt(euint32 a, euint8 b) and returns the result. */ function gt(euint32 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.gt(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates le(euint32 a, euint8 b) and returns the result. */ function le(euint32 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.le(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates lt(euint32 a, euint8 b) and returns the result. */ function lt(euint32 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.lt(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates min(euint32 a, euint8 b) and returns the result. */ function min(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.min(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates max(euint32 a, euint8 b) and returns the result. */ function max(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.max(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates add(euint32 a, euint16 b) and returns the result. */ function add(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.add(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates sub(euint32 a, euint16 b) and returns the result. */ function sub(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.sub(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates mul(euint32 a, euint16 b) and returns the result. */ function mul(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.mul(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates and(euint32 a, euint16 b) and returns the result. */ function and(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.and(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates or(euint32 a, euint16 b) and returns the result. */ function or(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.or(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates xor(euint32 a, euint16 b) and returns the result. */ function xor(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.xor(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates eq(euint32 a, euint16 b) and returns the result. */ function eq(euint32 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates ne(euint32 a, euint16 b) and returns the result. */ function ne(euint32 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates ge(euint32 a, euint16 b) and returns the result. */ function ge(euint32 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ge(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates gt(euint32 a, euint16 b) and returns the result. */ function gt(euint32 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.gt(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates le(euint32 a, euint16 b) and returns the result. */ function le(euint32 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.le(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates lt(euint32 a, euint16 b) and returns the result. */ function lt(euint32 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.lt(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates min(euint32 a, euint16 b) and returns the result. */ function min(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.min(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates max(euint32 a, euint16 b) and returns the result. */ function max(euint32 a, euint16 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint32.wrap(Impl.max(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates add(euint32 a, euint32 b) and returns the result. */ function add(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.add(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates sub(euint32 a, euint32 b) and returns the result. */ function sub(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.sub(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates mul(euint32 a, euint32 b) and returns the result. */ function mul(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.mul(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates and(euint32 a, euint32 b) and returns the result. */ function and(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.and(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates or(euint32 a, euint32 b) and returns the result. */ function or(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.or(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates xor(euint32 a, euint32 b) and returns the result. */ function xor(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.xor(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates eq(euint32 a, euint32 b) and returns the result. */ function eq(euint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates ne(euint32 a, euint32 b) and returns the result. */ function ne(euint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates ge(euint32 a, euint32 b) and returns the result. */ function ge(euint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ge(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates gt(euint32 a, euint32 b) and returns the result. */ function gt(euint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.gt(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates le(euint32 a, euint32 b) and returns the result. */ function le(euint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.le(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates lt(euint32 a, euint32 b) and returns the result. */ function lt(euint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.lt(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates min(euint32 a, euint32 b) and returns the result. */ function min(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.min(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates max(euint32 a, euint32 b) and returns the result. */ function max(euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.max(euint32.unwrap(a), euint32.unwrap(b), false)); } /** * @dev Evaluates add(euint32 a, euint64 b) and returns the result. */ function add(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.add(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates sub(euint32 a, euint64 b) and returns the result. */ function sub(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.sub(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates mul(euint32 a, euint64 b) and returns the result. */ function mul(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.mul(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates and(euint32 a, euint64 b) and returns the result. */ function and(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.and(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates or(euint32 a, euint64 b) and returns the result. */ function or(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.or(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates xor(euint32 a, euint64 b) and returns the result. */ function xor(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.xor(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates eq(euint32 a, euint64 b) and returns the result. */ function eq(euint32 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates ne(euint32 a, euint64 b) and returns the result. */ function ne(euint32 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates ge(euint32 a, euint64 b) and returns the result. */ function ge(euint32 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ge(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates gt(euint32 a, euint64 b) and returns the result. */ function gt(euint32 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.gt(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates le(euint32 a, euint64 b) and returns the result. */ function le(euint32 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.le(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates lt(euint32 a, euint64 b) and returns the result. */ function lt(euint32 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.lt(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates min(euint32 a, euint64 b) and returns the result. */ function min(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.min(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates max(euint32 a, euint64 b) and returns the result. */ function max(euint32 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.max(euint64.unwrap(asEuint64(a)), euint64.unwrap(b), false)); } /** * @dev Evaluates add(euint32 a, euint128 b) and returns the result. */ function add(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates sub(euint32 a, euint128 b) and returns the result. */ function sub(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates mul(euint32 a, euint128 b) and returns the result. */ function mul(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint32 a, euint128 b) and returns the result. */ function and(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates or(euint32 a, euint128 b) and returns the result. */ function or(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates xor(euint32 a, euint128 b) and returns the result. */ function xor(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates eq(euint32 a, euint128 b) and returns the result. */ function eq(euint32 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ne(euint32 a, euint128 b) and returns the result. */ function ne(euint32 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ge(euint32 a, euint128 b) and returns the result. */ function ge(euint32 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates gt(euint32 a, euint128 b) and returns the result. */ function gt(euint32 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates le(euint32 a, euint128 b) and returns the result. */ function le(euint32 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates lt(euint32 a, euint128 b) and returns the result. */ function lt(euint32 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates min(euint32 a, euint128 b) and returns the result. */ function min(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates max(euint32 a, euint128 b) and returns the result. */ function max(euint32 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint32 a, euint256 b) and returns the result. */ function and(euint32 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates or(euint32 a, euint256 b) and returns the result. */ function or(euint32 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates xor(euint32 a, euint256 b) and returns the result. */ function xor(euint32 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(euint32 a, euint256 b) and returns the result. */ function eq(euint32 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates ne(euint32 a, euint256 b) and returns the result. */ function ne(euint32 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates add(euint64 a, euint8 b) and returns the result. */ function add(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.add(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates sub(euint64 a, euint8 b) and returns the result. */ function sub(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.sub(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates mul(euint64 a, euint8 b) and returns the result. */ function mul(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.mul(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates and(euint64 a, euint8 b) and returns the result. */ function and(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.and(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates or(euint64 a, euint8 b) and returns the result. */ function or(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.or(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates xor(euint64 a, euint8 b) and returns the result. */ function xor(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.xor(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates eq(euint64 a, euint8 b) and returns the result. */ function eq(euint64 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates ne(euint64 a, euint8 b) and returns the result. */ function ne(euint64 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates ge(euint64 a, euint8 b) and returns the result. */ function ge(euint64 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ge(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates gt(euint64 a, euint8 b) and returns the result. */ function gt(euint64 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.gt(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates le(euint64 a, euint8 b) and returns the result. */ function le(euint64 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.le(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates lt(euint64 a, euint8 b) and returns the result. */ function lt(euint64 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.lt(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates min(euint64 a, euint8 b) and returns the result. */ function min(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.min(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates max(euint64 a, euint8 b) and returns the result. */ function max(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.max(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates add(euint64 a, euint16 b) and returns the result. */ function add(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.add(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates sub(euint64 a, euint16 b) and returns the result. */ function sub(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.sub(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates mul(euint64 a, euint16 b) and returns the result. */ function mul(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.mul(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates and(euint64 a, euint16 b) and returns the result. */ function and(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.and(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates or(euint64 a, euint16 b) and returns the result. */ function or(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.or(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates xor(euint64 a, euint16 b) and returns the result. */ function xor(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.xor(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates eq(euint64 a, euint16 b) and returns the result. */ function eq(euint64 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates ne(euint64 a, euint16 b) and returns the result. */ function ne(euint64 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates ge(euint64 a, euint16 b) and returns the result. */ function ge(euint64 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ge(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates gt(euint64 a, euint16 b) and returns the result. */ function gt(euint64 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.gt(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates le(euint64 a, euint16 b) and returns the result. */ function le(euint64 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.le(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates lt(euint64 a, euint16 b) and returns the result. */ function lt(euint64 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.lt(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates min(euint64 a, euint16 b) and returns the result. */ function min(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.min(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates max(euint64 a, euint16 b) and returns the result. */ function max(euint64 a, euint16 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint64.wrap(Impl.max(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates add(euint64 a, euint32 b) and returns the result. */ function add(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.add(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates sub(euint64 a, euint32 b) and returns the result. */ function sub(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.sub(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates mul(euint64 a, euint32 b) and returns the result. */ function mul(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.mul(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates and(euint64 a, euint32 b) and returns the result. */ function and(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.and(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates or(euint64 a, euint32 b) and returns the result. */ function or(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.or(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates xor(euint64 a, euint32 b) and returns the result. */ function xor(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.xor(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates eq(euint64 a, euint32 b) and returns the result. */ function eq(euint64 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates ne(euint64 a, euint32 b) and returns the result. */ function ne(euint64 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates ge(euint64 a, euint32 b) and returns the result. */ function ge(euint64 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ge(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates gt(euint64 a, euint32 b) and returns the result. */ function gt(euint64 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.gt(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates le(euint64 a, euint32 b) and returns the result. */ function le(euint64 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.le(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates lt(euint64 a, euint32 b) and returns the result. */ function lt(euint64 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.lt(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates min(euint64 a, euint32 b) and returns the result. */ function min(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.min(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates max(euint64 a, euint32 b) and returns the result. */ function max(euint64 a, euint32 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint64.wrap(Impl.max(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates add(euint64 a, euint64 b) and returns the result. */ function add(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.add(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates sub(euint64 a, euint64 b) and returns the result. */ function sub(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.sub(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates mul(euint64 a, euint64 b) and returns the result. */ function mul(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.mul(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates and(euint64 a, euint64 b) and returns the result. */ function and(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.and(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates or(euint64 a, euint64 b) and returns the result. */ function or(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.or(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates xor(euint64 a, euint64 b) and returns the result. */ function xor(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.xor(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates eq(euint64 a, euint64 b) and returns the result. */ function eq(euint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates ne(euint64 a, euint64 b) and returns the result. */ function ne(euint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates ge(euint64 a, euint64 b) and returns the result. */ function ge(euint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ge(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates gt(euint64 a, euint64 b) and returns the result. */ function gt(euint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.gt(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates le(euint64 a, euint64 b) and returns the result. */ function le(euint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.le(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates lt(euint64 a, euint64 b) and returns the result. */ function lt(euint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.lt(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates min(euint64 a, euint64 b) and returns the result. */ function min(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.min(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates max(euint64 a, euint64 b) and returns the result. */ function max(euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.max(euint64.unwrap(a), euint64.unwrap(b), false)); } /** * @dev Evaluates add(euint64 a, euint128 b) and returns the result. */ function add(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates sub(euint64 a, euint128 b) and returns the result. */ function sub(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates mul(euint64 a, euint128 b) and returns the result. */ function mul(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint64 a, euint128 b) and returns the result. */ function and(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates or(euint64 a, euint128 b) and returns the result. */ function or(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates xor(euint64 a, euint128 b) and returns the result. */ function xor(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates eq(euint64 a, euint128 b) and returns the result. */ function eq(euint64 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ne(euint64 a, euint128 b) and returns the result. */ function ne(euint64 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates ge(euint64 a, euint128 b) and returns the result. */ function ge(euint64 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates gt(euint64 a, euint128 b) and returns the result. */ function gt(euint64 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates le(euint64 a, euint128 b) and returns the result. */ function le(euint64 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates lt(euint64 a, euint128 b) and returns the result. */ function lt(euint64 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates min(euint64 a, euint128 b) and returns the result. */ function min(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates max(euint64 a, euint128 b) and returns the result. */ function max(euint64 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(asEuint128(a)), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint64 a, euint256 b) and returns the result. */ function and(euint64 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates or(euint64 a, euint256 b) and returns the result. */ function or(euint64 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates xor(euint64 a, euint256 b) and returns the result. */ function xor(euint64 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(euint64 a, euint256 b) and returns the result. */ function eq(euint64 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates ne(euint64 a, euint256 b) and returns the result. */ function ne(euint64 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates add(euint128 a, euint8 b) and returns the result. */ function add(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.add(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates sub(euint128 a, euint8 b) and returns the result. */ function sub(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.sub(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates mul(euint128 a, euint8 b) and returns the result. */ function mul(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.mul(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates and(euint128 a, euint8 b) and returns the result. */ function and(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.and(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates or(euint128 a, euint8 b) and returns the result. */ function or(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.or(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates xor(euint128 a, euint8 b) and returns the result. */ function xor(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.xor(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates eq(euint128 a, euint8 b) and returns the result. */ function eq(euint128 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ne(euint128 a, euint8 b) and returns the result. */ function ne(euint128 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ge(euint128 a, euint8 b) and returns the result. */ function ge(euint128 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ge(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates gt(euint128 a, euint8 b) and returns the result. */ function gt(euint128 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.gt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates le(euint128 a, euint8 b) and returns the result. */ function le(euint128 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.le(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates lt(euint128 a, euint8 b) and returns the result. */ function lt(euint128 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.lt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates min(euint128 a, euint8 b) and returns the result. */ function min(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.min(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates max(euint128 a, euint8 b) and returns the result. */ function max(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.max(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates add(euint128 a, euint16 b) and returns the result. */ function add(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.add(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates sub(euint128 a, euint16 b) and returns the result. */ function sub(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.sub(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates mul(euint128 a, euint16 b) and returns the result. */ function mul(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.mul(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates and(euint128 a, euint16 b) and returns the result. */ function and(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.and(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates or(euint128 a, euint16 b) and returns the result. */ function or(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.or(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates xor(euint128 a, euint16 b) and returns the result. */ function xor(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.xor(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates eq(euint128 a, euint16 b) and returns the result. */ function eq(euint128 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ne(euint128 a, euint16 b) and returns the result. */ function ne(euint128 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ge(euint128 a, euint16 b) and returns the result. */ function ge(euint128 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ge(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates gt(euint128 a, euint16 b) and returns the result. */ function gt(euint128 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.gt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates le(euint128 a, euint16 b) and returns the result. */ function le(euint128 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.le(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates lt(euint128 a, euint16 b) and returns the result. */ function lt(euint128 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.lt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates min(euint128 a, euint16 b) and returns the result. */ function min(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.min(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates max(euint128 a, euint16 b) and returns the result. */ function max(euint128 a, euint16 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint128.wrap(Impl.max(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates add(euint128 a, euint32 b) and returns the result. */ function add(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.add(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates sub(euint128 a, euint32 b) and returns the result. */ function sub(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.sub(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates mul(euint128 a, euint32 b) and returns the result. */ function mul(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.mul(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates and(euint128 a, euint32 b) and returns the result. */ function and(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.and(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates or(euint128 a, euint32 b) and returns the result. */ function or(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.or(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates xor(euint128 a, euint32 b) and returns the result. */ function xor(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.xor(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates eq(euint128 a, euint32 b) and returns the result. */ function eq(euint128 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ne(euint128 a, euint32 b) and returns the result. */ function ne(euint128 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ge(euint128 a, euint32 b) and returns the result. */ function ge(euint128 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ge(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates gt(euint128 a, euint32 b) and returns the result. */ function gt(euint128 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.gt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates le(euint128 a, euint32 b) and returns the result. */ function le(euint128 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.le(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates lt(euint128 a, euint32 b) and returns the result. */ function lt(euint128 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.lt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates min(euint128 a, euint32 b) and returns the result. */ function min(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.min(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates max(euint128 a, euint32 b) and returns the result. */ function max(euint128 a, euint32 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint128.wrap(Impl.max(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates add(euint128 a, euint64 b) and returns the result. */ function add(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.add(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates sub(euint128 a, euint64 b) and returns the result. */ function sub(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.sub(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates mul(euint128 a, euint64 b) and returns the result. */ function mul(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.mul(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates and(euint128 a, euint64 b) and returns the result. */ function and(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.and(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates or(euint128 a, euint64 b) and returns the result. */ function or(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.or(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates xor(euint128 a, euint64 b) and returns the result. */ function xor(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.xor(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates eq(euint128 a, euint64 b) and returns the result. */ function eq(euint128 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ne(euint128 a, euint64 b) and returns the result. */ function ne(euint128 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates ge(euint128 a, euint64 b) and returns the result. */ function ge(euint128 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ge(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates gt(euint128 a, euint64 b) and returns the result. */ function gt(euint128 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.gt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates le(euint128 a, euint64 b) and returns the result. */ function le(euint128 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.le(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates lt(euint128 a, euint64 b) and returns the result. */ function lt(euint128 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.lt(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates min(euint128 a, euint64 b) and returns the result. */ function min(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.min(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates max(euint128 a, euint64 b) and returns the result. */ function max(euint128 a, euint64 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint128.wrap(Impl.max(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates add(euint128 a, euint128 b) and returns the result. */ function add(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates sub(euint128 a, euint128 b) and returns the result. */ function sub(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates mul(euint128 a, euint128 b) and returns the result. */ function mul(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint128 a, euint128 b) and returns the result. */ function and(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates or(euint128 a, euint128 b) and returns the result. */ function or(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates xor(euint128 a, euint128 b) and returns the result. */ function xor(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates eq(euint128 a, euint128 b) and returns the result. */ function eq(euint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates ne(euint128 a, euint128 b) and returns the result. */ function ne(euint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates ge(euint128 a, euint128 b) and returns the result. */ function ge(euint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates gt(euint128 a, euint128 b) and returns the result. */ function gt(euint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates le(euint128 a, euint128 b) and returns the result. */ function le(euint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates lt(euint128 a, euint128 b) and returns the result. */ function lt(euint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates min(euint128 a, euint128 b) and returns the result. */ function min(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates max(euint128 a, euint128 b) and returns the result. */ function max(euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(a), euint128.unwrap(b), false)); } /** * @dev Evaluates and(euint128 a, euint256 b) and returns the result. */ function and(euint128 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates or(euint128 a, euint256 b) and returns the result. */ function or(euint128 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates xor(euint128 a, euint256 b) and returns the result. */ function xor(euint128 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(euint128 a, euint256 b) and returns the result. */ function eq(euint128 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates ne(euint128 a, euint256 b) and returns the result. */ function ne(euint128 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(asEuint256(a)), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(eaddress a, eaddress b) and returns the result. */ function eq(eaddress a, eaddress b) internal returns (ebool) { if (!isInitialized(a)) { a = asEaddress(address(0)); } if (!isInitialized(b)) { b = asEaddress(address(0)); } return ebool.wrap(Impl.eq(eaddress.unwrap(a), eaddress.unwrap(b), false)); } /** * @dev Evaluates ne(eaddress a, eaddress b) and returns the result. */ function ne(eaddress a, eaddress b) internal returns (ebool) { if (!isInitialized(a)) { a = asEaddress(address(0)); } if (!isInitialized(b)) { b = asEaddress(address(0)); } return ebool.wrap(Impl.ne(eaddress.unwrap(a), eaddress.unwrap(b), false)); } /** * @dev Evaluates and(euint256 a, euint8 b) and returns the result. */ function and(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates or(euint256 a, euint8 b) and returns the result. */ function or(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates xor(euint256 a, euint8 b) and returns the result. */ function xor(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates eq(euint256 a, euint8 b) and returns the result. */ function eq(euint256 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates ne(euint256 a, euint8 b) and returns the result. */ function ne(euint256 a, euint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates and(euint256 a, euint16 b) and returns the result. */ function and(euint256 a, euint16 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates or(euint256 a, euint16 b) and returns the result. */ function or(euint256 a, euint16 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates xor(euint256 a, euint16 b) and returns the result. */ function xor(euint256 a, euint16 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates eq(euint256 a, euint16 b) and returns the result. */ function eq(euint256 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates ne(euint256 a, euint16 b) and returns the result. */ function ne(euint256 a, euint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates and(euint256 a, euint32 b) and returns the result. */ function and(euint256 a, euint32 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates or(euint256 a, euint32 b) and returns the result. */ function or(euint256 a, euint32 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates xor(euint256 a, euint32 b) and returns the result. */ function xor(euint256 a, euint32 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates eq(euint256 a, euint32 b) and returns the result. */ function eq(euint256 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates ne(euint256 a, euint32 b) and returns the result. */ function ne(euint256 a, euint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates and(euint256 a, euint64 b) and returns the result. */ function and(euint256 a, euint64 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates or(euint256 a, euint64 b) and returns the result. */ function or(euint256 a, euint64 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates xor(euint256 a, euint64 b) and returns the result. */ function xor(euint256 a, euint64 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates eq(euint256 a, euint64 b) and returns the result. */ function eq(euint256 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates ne(euint256 a, euint64 b) and returns the result. */ function ne(euint256 a, euint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates and(euint256 a, euint128 b) and returns the result. */ function and(euint256 a, euint128 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates or(euint256 a, euint128 b) and returns the result. */ function or(euint256 a, euint128 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates xor(euint256 a, euint128 b) and returns the result. */ function xor(euint256 a, euint128 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates eq(euint256 a, euint128 b) and returns the result. */ function eq(euint256 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates ne(euint256 a, euint128 b) and returns the result. */ function ne(euint256 a, euint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates and(euint256 a, euint256 b) and returns the result. */ function and(euint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), euint256.unwrap(b), false)); } /** * @dev Evaluates or(euint256 a, euint256 b) and returns the result. */ function or(euint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), euint256.unwrap(b), false)); } /** * @dev Evaluates xor(euint256 a, euint256 b) and returns the result. */ function xor(euint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), euint256.unwrap(b), false)); } /** * @dev Evaluates eq(euint256 a, euint256 b) and returns the result. */ function eq(euint256 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), euint256.unwrap(b), false)); } /** * @dev Evaluates ne(euint256 a, euint256 b) and returns the result. */ function ne(euint256 a, euint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), euint256.unwrap(b), false)); } /** * @dev Evaluates and(ebool a, bool b) and returns the result. */ function and(ebool a, bool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } return ebool.wrap(Impl.and(ebool.unwrap(a), bytes32(uint256(b ? 1 : 0)), true)); } /** * @dev Evaluates and(bool a, ebool b) and returns the result. */ function and(bool a, ebool b) internal returns (ebool) { if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.and(ebool.unwrap(b), bytes32(uint256(a ? 1 : 0)), true)); } /** * @dev Evaluates or(ebool a, bool b) and returns the result. */ function or(ebool a, bool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } return ebool.wrap(Impl.or(ebool.unwrap(a), bytes32(uint256(b ? 1 : 0)), true)); } /** * @dev Evaluates or(bool a, ebool b) and returns the result. */ function or(bool a, ebool b) internal returns (ebool) { if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.or(ebool.unwrap(b), bytes32(uint256(a ? 1 : 0)), true)); } /** * @dev Evaluates xor(ebool a, bool b) and returns the result. */ function xor(ebool a, bool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } return ebool.wrap(Impl.xor(ebool.unwrap(a), bytes32(uint256(b ? 1 : 0)), true)); } /** * @dev Evaluates xor(bool a, ebool b) and returns the result. */ function xor(bool a, ebool b) internal returns (ebool) { if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.xor(ebool.unwrap(b), bytes32(uint256(a ? 1 : 0)), true)); } /** * @dev Evaluates eq(ebool a, bool b) and returns the result. */ function eq(ebool a, bool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } return ebool.wrap(Impl.eq(ebool.unwrap(a), bytes32(uint256(b ? 1 : 0)), true)); } /** * @dev Evaluates eq(bool a, ebool b) and returns the result. */ function eq(bool a, ebool b) internal returns (ebool) { if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.eq(ebool.unwrap(b), bytes32(uint256(a ? 1 : 0)), true)); } /** * @dev Evaluates ne(ebool a, bool b) and returns the result. */ function ne(ebool a, bool b) internal returns (ebool) { if (!isInitialized(a)) { a = asEbool(false); } return ebool.wrap(Impl.ne(ebool.unwrap(a), bytes32(uint256(b ? 1 : 0)), true)); } /** * @dev Evaluates ne(bool a, ebool b) and returns the result. */ function ne(bool a, ebool b) internal returns (ebool) { if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.ne(ebool.unwrap(b), bytes32(uint256(a ? 1 : 0)), true)); } /** * @dev Evaluates add(euint8 a, uint8 b) and returns the result. */ function add(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.add(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates add(uint8 a, euint8 b) and returns the result. */ function add(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.add(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates sub(euint8 a, uint8 b) and returns the result. */ function sub(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.sub(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates sub(uint8 a, euint8 b) and returns the result. */ function sub(uint8 a, euint8 b) internal returns (euint8) { euint8 aEnc = asEuint8(a); if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.sub(euint8.unwrap(aEnc), euint8.unwrap(b), false)); } /** * @dev Evaluates mul(euint8 a, uint8 b) and returns the result. */ function mul(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.mul(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates mul(uint8 a, euint8 b) and returns the result. */ function mul(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.mul(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates div(euint8 a, uint8 b) and returns the result. */ function div(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.div(euint8.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates rem(euint8 a, uint8 b) and returns the result. */ function rem(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.rem(euint8.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates and(euint8 a, uint8 b) and returns the result. */ function and(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.and(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates and(uint8 a, euint8 b) and returns the result. */ function and(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.and(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates or(euint8 a, uint8 b) and returns the result. */ function or(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.or(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates or(uint8 a, euint8 b) and returns the result. */ function or(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.or(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates xor(euint8 a, uint8 b) and returns the result. */ function xor(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.xor(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates xor(uint8 a, euint8 b) and returns the result. */ function xor(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.xor(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(euint8 a, uint8 b) and returns the result. */ function eq(euint8 a, uint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } return ebool.wrap(Impl.eq(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates eq(uint8 a, euint8 b) and returns the result. */ function eq(uint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.eq(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ne(euint8 a, uint8 b) and returns the result. */ function ne(euint8 a, uint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } return ebool.wrap(Impl.ne(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ne(uint8 a, euint8 b) and returns the result. */ function ne(uint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ne(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ge(euint8 a, uint8 b) and returns the result. */ function ge(euint8 a, uint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } return ebool.wrap(Impl.ge(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ge(uint8 a, euint8 b) and returns the result. */ function ge(uint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.le(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates gt(euint8 a, uint8 b) and returns the result. */ function gt(euint8 a, uint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } return ebool.wrap(Impl.gt(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates gt(uint8 a, euint8 b) and returns the result. */ function gt(uint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.lt(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates le(euint8 a, uint8 b) and returns the result. */ function le(euint8 a, uint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } return ebool.wrap(Impl.le(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates le(uint8 a, euint8 b) and returns the result. */ function le(uint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.ge(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates lt(euint8 a, uint8 b) and returns the result. */ function lt(euint8 a, uint8 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint8(0); } return ebool.wrap(Impl.lt(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates lt(uint8 a, euint8 b) and returns the result. */ function lt(uint8 a, euint8 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint8(0); } return ebool.wrap(Impl.gt(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates min(euint8 a, uint8 b) and returns the result. */ function min(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.min(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates min(uint8 a, euint8 b) and returns the result. */ function min(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.min(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates max(euint8 a, uint8 b) and returns the result. */ function max(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.max(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates max(uint8 a, euint8 b) and returns the result. */ function max(uint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.max(euint8.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates add(euint16 a, uint16 b) and returns the result. */ function add(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.add(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates add(uint16 a, euint16 b) and returns the result. */ function add(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.add(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates sub(euint16 a, uint16 b) and returns the result. */ function sub(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.sub(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates sub(uint16 a, euint16 b) and returns the result. */ function sub(uint16 a, euint16 b) internal returns (euint16) { euint16 aEnc = asEuint16(a); if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.sub(euint16.unwrap(aEnc), euint16.unwrap(b), false)); } /** * @dev Evaluates mul(euint16 a, uint16 b) and returns the result. */ function mul(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.mul(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates mul(uint16 a, euint16 b) and returns the result. */ function mul(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.mul(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates div(euint16 a, uint16 b) and returns the result. */ function div(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.div(euint16.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates rem(euint16 a, uint16 b) and returns the result. */ function rem(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.rem(euint16.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates and(euint16 a, uint16 b) and returns the result. */ function and(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.and(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates and(uint16 a, euint16 b) and returns the result. */ function and(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.and(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates or(euint16 a, uint16 b) and returns the result. */ function or(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.or(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates or(uint16 a, euint16 b) and returns the result. */ function or(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.or(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates xor(euint16 a, uint16 b) and returns the result. */ function xor(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.xor(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates xor(uint16 a, euint16 b) and returns the result. */ function xor(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.xor(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(euint16 a, uint16 b) and returns the result. */ function eq(euint16 a, uint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } return ebool.wrap(Impl.eq(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates eq(uint16 a, euint16 b) and returns the result. */ function eq(uint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.eq(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ne(euint16 a, uint16 b) and returns the result. */ function ne(euint16 a, uint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } return ebool.wrap(Impl.ne(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ne(uint16 a, euint16 b) and returns the result. */ function ne(uint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ne(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ge(euint16 a, uint16 b) and returns the result. */ function ge(euint16 a, uint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } return ebool.wrap(Impl.ge(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ge(uint16 a, euint16 b) and returns the result. */ function ge(uint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.le(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates gt(euint16 a, uint16 b) and returns the result. */ function gt(euint16 a, uint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } return ebool.wrap(Impl.gt(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates gt(uint16 a, euint16 b) and returns the result. */ function gt(uint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.lt(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates le(euint16 a, uint16 b) and returns the result. */ function le(euint16 a, uint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } return ebool.wrap(Impl.le(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates le(uint16 a, euint16 b) and returns the result. */ function le(uint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.ge(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates lt(euint16 a, uint16 b) and returns the result. */ function lt(euint16 a, uint16 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint16(0); } return ebool.wrap(Impl.lt(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates lt(uint16 a, euint16 b) and returns the result. */ function lt(uint16 a, euint16 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint16(0); } return ebool.wrap(Impl.gt(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates min(euint16 a, uint16 b) and returns the result. */ function min(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.min(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates min(uint16 a, euint16 b) and returns the result. */ function min(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.min(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates max(euint16 a, uint16 b) and returns the result. */ function max(euint16 a, uint16 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.max(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates max(uint16 a, euint16 b) and returns the result. */ function max(uint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.max(euint16.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates add(euint32 a, uint32 b) and returns the result. */ function add(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.add(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates add(uint32 a, euint32 b) and returns the result. */ function add(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.add(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates sub(euint32 a, uint32 b) and returns the result. */ function sub(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.sub(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates sub(uint32 a, euint32 b) and returns the result. */ function sub(uint32 a, euint32 b) internal returns (euint32) { euint32 aEnc = asEuint32(a); if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.sub(euint32.unwrap(aEnc), euint32.unwrap(b), false)); } /** * @dev Evaluates mul(euint32 a, uint32 b) and returns the result. */ function mul(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.mul(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates mul(uint32 a, euint32 b) and returns the result. */ function mul(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.mul(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates div(euint32 a, uint32 b) and returns the result. */ function div(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.div(euint32.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates rem(euint32 a, uint32 b) and returns the result. */ function rem(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.rem(euint32.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates and(euint32 a, uint32 b) and returns the result. */ function and(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.and(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates and(uint32 a, euint32 b) and returns the result. */ function and(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.and(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates or(euint32 a, uint32 b) and returns the result. */ function or(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.or(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates or(uint32 a, euint32 b) and returns the result. */ function or(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.or(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates xor(euint32 a, uint32 b) and returns the result. */ function xor(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.xor(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates xor(uint32 a, euint32 b) and returns the result. */ function xor(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.xor(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(euint32 a, uint32 b) and returns the result. */ function eq(euint32 a, uint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } return ebool.wrap(Impl.eq(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates eq(uint32 a, euint32 b) and returns the result. */ function eq(uint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.eq(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ne(euint32 a, uint32 b) and returns the result. */ function ne(euint32 a, uint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } return ebool.wrap(Impl.ne(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ne(uint32 a, euint32 b) and returns the result. */ function ne(uint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ne(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ge(euint32 a, uint32 b) and returns the result. */ function ge(euint32 a, uint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } return ebool.wrap(Impl.ge(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ge(uint32 a, euint32 b) and returns the result. */ function ge(uint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.le(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates gt(euint32 a, uint32 b) and returns the result. */ function gt(euint32 a, uint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } return ebool.wrap(Impl.gt(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates gt(uint32 a, euint32 b) and returns the result. */ function gt(uint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.lt(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates le(euint32 a, uint32 b) and returns the result. */ function le(euint32 a, uint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } return ebool.wrap(Impl.le(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates le(uint32 a, euint32 b) and returns the result. */ function le(uint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.ge(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates lt(euint32 a, uint32 b) and returns the result. */ function lt(euint32 a, uint32 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint32(0); } return ebool.wrap(Impl.lt(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates lt(uint32 a, euint32 b) and returns the result. */ function lt(uint32 a, euint32 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint32(0); } return ebool.wrap(Impl.gt(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates min(euint32 a, uint32 b) and returns the result. */ function min(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.min(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates min(uint32 a, euint32 b) and returns the result. */ function min(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.min(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates max(euint32 a, uint32 b) and returns the result. */ function max(euint32 a, uint32 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.max(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates max(uint32 a, euint32 b) and returns the result. */ function max(uint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.max(euint32.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates add(euint64 a, uint64 b) and returns the result. */ function add(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.add(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates add(uint64 a, euint64 b) and returns the result. */ function add(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.add(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates sub(euint64 a, uint64 b) and returns the result. */ function sub(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.sub(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates sub(uint64 a, euint64 b) and returns the result. */ function sub(uint64 a, euint64 b) internal returns (euint64) { euint64 aEnc = asEuint64(a); if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.sub(euint64.unwrap(aEnc), euint64.unwrap(b), false)); } /** * @dev Evaluates mul(euint64 a, uint64 b) and returns the result. */ function mul(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.mul(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates mul(uint64 a, euint64 b) and returns the result. */ function mul(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.mul(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates div(euint64 a, uint64 b) and returns the result. */ function div(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.div(euint64.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates rem(euint64 a, uint64 b) and returns the result. */ function rem(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.rem(euint64.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates and(euint64 a, uint64 b) and returns the result. */ function and(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.and(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates and(uint64 a, euint64 b) and returns the result. */ function and(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.and(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates or(euint64 a, uint64 b) and returns the result. */ function or(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.or(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates or(uint64 a, euint64 b) and returns the result. */ function or(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.or(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates xor(euint64 a, uint64 b) and returns the result. */ function xor(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.xor(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates xor(uint64 a, euint64 b) and returns the result. */ function xor(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.xor(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(euint64 a, uint64 b) and returns the result. */ function eq(euint64 a, uint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } return ebool.wrap(Impl.eq(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates eq(uint64 a, euint64 b) and returns the result. */ function eq(uint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.eq(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ne(euint64 a, uint64 b) and returns the result. */ function ne(euint64 a, uint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } return ebool.wrap(Impl.ne(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ne(uint64 a, euint64 b) and returns the result. */ function ne(uint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ne(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ge(euint64 a, uint64 b) and returns the result. */ function ge(euint64 a, uint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } return ebool.wrap(Impl.ge(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ge(uint64 a, euint64 b) and returns the result. */ function ge(uint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.le(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates gt(euint64 a, uint64 b) and returns the result. */ function gt(euint64 a, uint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } return ebool.wrap(Impl.gt(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates gt(uint64 a, euint64 b) and returns the result. */ function gt(uint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.lt(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates le(euint64 a, uint64 b) and returns the result. */ function le(euint64 a, uint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } return ebool.wrap(Impl.le(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates le(uint64 a, euint64 b) and returns the result. */ function le(uint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.ge(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates lt(euint64 a, uint64 b) and returns the result. */ function lt(euint64 a, uint64 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint64(0); } return ebool.wrap(Impl.lt(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates lt(uint64 a, euint64 b) and returns the result. */ function lt(uint64 a, euint64 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint64(0); } return ebool.wrap(Impl.gt(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates min(euint64 a, uint64 b) and returns the result. */ function min(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.min(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates min(uint64 a, euint64 b) and returns the result. */ function min(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.min(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates max(euint64 a, uint64 b) and returns the result. */ function max(euint64 a, uint64 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.max(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates max(uint64 a, euint64 b) and returns the result. */ function max(uint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.max(euint64.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates add(euint128 a, uint128 b) and returns the result. */ function add(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates add(uint128 a, euint128 b) and returns the result. */ function add(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.add(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates sub(euint128 a, uint128 b) and returns the result. */ function sub(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates sub(uint128 a, euint128 b) and returns the result. */ function sub(uint128 a, euint128 b) internal returns (euint128) { euint128 aEnc = asEuint128(a); if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.sub(euint128.unwrap(aEnc), euint128.unwrap(b), false)); } /** * @dev Evaluates mul(euint128 a, uint128 b) and returns the result. */ function mul(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates mul(uint128 a, euint128 b) and returns the result. */ function mul(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.mul(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates div(euint128 a, uint128 b) and returns the result. */ function div(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.div(euint128.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates rem(euint128 a, uint128 b) and returns the result. */ function rem(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.rem(euint128.unwrap(a), bytes32(uint256(b)))); } /** * @dev Evaluates and(euint128 a, uint128 b) and returns the result. */ function and(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates and(uint128 a, euint128 b) and returns the result. */ function and(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.and(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates or(euint128 a, uint128 b) and returns the result. */ function or(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates or(uint128 a, euint128 b) and returns the result. */ function or(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.or(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates xor(euint128 a, uint128 b) and returns the result. */ function xor(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates xor(uint128 a, euint128 b) and returns the result. */ function xor(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.xor(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(euint128 a, uint128 b) and returns the result. */ function eq(euint128 a, uint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates eq(uint128 a, euint128 b) and returns the result. */ function eq(uint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.eq(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ne(euint128 a, uint128 b) and returns the result. */ function ne(euint128 a, uint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ne(uint128 a, euint128 b) and returns the result. */ function ne(uint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ne(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ge(euint128 a, uint128 b) and returns the result. */ function ge(euint128 a, uint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ge(uint128 a, euint128 b) and returns the result. */ function ge(uint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates gt(euint128 a, uint128 b) and returns the result. */ function gt(euint128 a, uint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates gt(uint128 a, euint128 b) and returns the result. */ function gt(uint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates le(euint128 a, uint128 b) and returns the result. */ function le(euint128 a, uint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } return ebool.wrap(Impl.le(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates le(uint128 a, euint128 b) and returns the result. */ function le(uint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.ge(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates lt(euint128 a, uint128 b) and returns the result. */ function lt(euint128 a, uint128 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint128(0); } return ebool.wrap(Impl.lt(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates lt(uint128 a, euint128 b) and returns the result. */ function lt(uint128 a, euint128 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint128(0); } return ebool.wrap(Impl.gt(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates min(euint128 a, uint128 b) and returns the result. */ function min(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates min(uint128 a, euint128 b) and returns the result. */ function min(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.min(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates max(euint128 a, uint128 b) and returns the result. */ function max(euint128 a, uint128 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates max(uint128 a, euint128 b) and returns the result. */ function max(uint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.max(euint128.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(eaddress a, address b) and returns the result. */ function eq(eaddress a, address b) internal returns (ebool) { if (!isInitialized(a)) { a = asEaddress(address(0)); } return ebool.wrap(Impl.eq(eaddress.unwrap(a), bytes32(uint256(uint160(b))), true)); } /** * @dev Evaluates eq(address a, eaddress b) and returns the result. */ function eq(address a, eaddress b) internal returns (ebool) { if (!isInitialized(b)) { b = asEaddress(address(0)); } return ebool.wrap(Impl.eq(eaddress.unwrap(b), bytes32(uint256(uint160(a))), true)); } /** * @dev Evaluates ne(eaddress a, address b) and returns the result. */ function ne(eaddress a, address b) internal returns (ebool) { if (!isInitialized(a)) { a = asEaddress(address(0)); } return ebool.wrap(Impl.ne(eaddress.unwrap(a), bytes32(uint256(uint160(b))), true)); } /** * @dev Evaluates ne(address a, eaddress b) and returns the result. */ function ne(address a, eaddress b) internal returns (ebool) { if (!isInitialized(b)) { b = asEaddress(address(0)); } return ebool.wrap(Impl.ne(eaddress.unwrap(b), bytes32(uint256(uint160(a))), true)); } /** * @dev Evaluates and(euint256 a, uint256 b) and returns the result. */ function and(euint256 a, uint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates and(uint256 a, euint256 b) and returns the result. */ function and(uint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.and(euint256.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates or(euint256 a, uint256 b) and returns the result. */ function or(euint256 a, uint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates or(uint256 a, euint256 b) and returns the result. */ function or(uint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.or(euint256.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates xor(euint256 a, uint256 b) and returns the result. */ function xor(euint256 a, uint256 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates xor(uint256 a, euint256 b) and returns the result. */ function xor(uint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.xor(euint256.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates eq(euint256 a, uint256 b) and returns the result. */ function eq(euint256 a, uint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates eq(uint256 a, euint256 b) and returns the result. */ function eq(uint256 a, euint256 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.eq(euint256.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates ne(euint256 a, uint256 b) and returns the result. */ function ne(euint256 a, uint256 b) internal returns (ebool) { if (!isInitialized(a)) { a = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates ne(uint256 a, euint256 b) and returns the result. */ function ne(uint256 a, euint256 b) internal returns (ebool) { if (!isInitialized(b)) { b = asEuint256(0); } return ebool.wrap(Impl.ne(euint256.unwrap(b), bytes32(uint256(a)), true)); } /** * @dev Evaluates shl(euint8 a, euint8 b) and returns the result. */ function shl(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.shl(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates shl(euint8 a, uint8) and returns the result. */ function shl(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.shl(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shr(euint8 a, euint8 b) and returns the result. */ function shr(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.shr(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates shr(euint8 a, uint8) and returns the result. */ function shr(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.shr(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotl(euint8 a, euint8 b) and returns the result. */ function rotl(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.rotl(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates rotl(euint8 a, uint8) and returns the result. */ function rotl(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.rotl(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotr(euint8 a, euint8 b) and returns the result. */ function rotr(euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.rotr(euint8.unwrap(a), euint8.unwrap(b), false)); } /** * @dev Evaluates rotr(euint8 a, uint8) and returns the result. */ function rotr(euint8 a, uint8 b) internal returns (euint8) { if (!isInitialized(a)) { a = asEuint8(0); } return euint8.wrap(Impl.rotr(euint8.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shl(euint16 a, euint8 b) and returns the result. */ function shl(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.shl(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates shl(euint16 a, uint8) and returns the result. */ function shl(euint16 a, uint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.shl(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shr(euint16 a, euint8 b) and returns the result. */ function shr(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.shr(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates shr(euint16 a, uint8) and returns the result. */ function shr(euint16 a, uint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.shr(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotl(euint16 a, euint8 b) and returns the result. */ function rotl(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.rotl(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates rotl(euint16 a, uint8) and returns the result. */ function rotl(euint16 a, uint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.rotl(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotr(euint16 a, euint8 b) and returns the result. */ function rotr(euint16 a, euint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint16.wrap(Impl.rotr(euint16.unwrap(a), euint16.unwrap(asEuint16(b)), false)); } /** * @dev Evaluates rotr(euint16 a, uint8) and returns the result. */ function rotr(euint16 a, uint8 b) internal returns (euint16) { if (!isInitialized(a)) { a = asEuint16(0); } return euint16.wrap(Impl.rotr(euint16.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shl(euint32 a, euint8 b) and returns the result. */ function shl(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.shl(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates shl(euint32 a, uint8) and returns the result. */ function shl(euint32 a, uint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.shl(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shr(euint32 a, euint8 b) and returns the result. */ function shr(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.shr(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates shr(euint32 a, uint8) and returns the result. */ function shr(euint32 a, uint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.shr(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotl(euint32 a, euint8 b) and returns the result. */ function rotl(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.rotl(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates rotl(euint32 a, uint8) and returns the result. */ function rotl(euint32 a, uint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.rotl(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotr(euint32 a, euint8 b) and returns the result. */ function rotr(euint32 a, euint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint32.wrap(Impl.rotr(euint32.unwrap(a), euint32.unwrap(asEuint32(b)), false)); } /** * @dev Evaluates rotr(euint32 a, uint8) and returns the result. */ function rotr(euint32 a, uint8 b) internal returns (euint32) { if (!isInitialized(a)) { a = asEuint32(0); } return euint32.wrap(Impl.rotr(euint32.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shl(euint64 a, euint8 b) and returns the result. */ function shl(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.shl(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates shl(euint64 a, uint8) and returns the result. */ function shl(euint64 a, uint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.shl(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shr(euint64 a, euint8 b) and returns the result. */ function shr(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.shr(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates shr(euint64 a, uint8) and returns the result. */ function shr(euint64 a, uint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.shr(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotl(euint64 a, euint8 b) and returns the result. */ function rotl(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.rotl(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates rotl(euint64 a, uint8) and returns the result. */ function rotl(euint64 a, uint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.rotl(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotr(euint64 a, euint8 b) and returns the result. */ function rotr(euint64 a, euint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint64.wrap(Impl.rotr(euint64.unwrap(a), euint64.unwrap(asEuint64(b)), false)); } /** * @dev Evaluates rotr(euint64 a, uint8) and returns the result. */ function rotr(euint64 a, uint8 b) internal returns (euint64) { if (!isInitialized(a)) { a = asEuint64(0); } return euint64.wrap(Impl.rotr(euint64.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shl(euint128 a, euint8 b) and returns the result. */ function shl(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.shl(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates shl(euint128 a, uint8) and returns the result. */ function shl(euint128 a, uint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.shl(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shr(euint128 a, euint8 b) and returns the result. */ function shr(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.shr(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates shr(euint128 a, uint8) and returns the result. */ function shr(euint128 a, uint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.shr(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotl(euint128 a, euint8 b) and returns the result. */ function rotl(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.rotl(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates rotl(euint128 a, uint8) and returns the result. */ function rotl(euint128 a, uint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.rotl(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotr(euint128 a, euint8 b) and returns the result. */ function rotr(euint128 a, euint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint128.wrap(Impl.rotr(euint128.unwrap(a), euint128.unwrap(asEuint128(b)), false)); } /** * @dev Evaluates rotr(euint128 a, uint8) and returns the result. */ function rotr(euint128 a, uint8 b) internal returns (euint128) { if (!isInitialized(a)) { a = asEuint128(0); } return euint128.wrap(Impl.rotr(euint128.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shl(euint256 a, euint8 b) and returns the result. */ function shl(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.shl(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates shl(euint256 a, uint8) and returns the result. */ function shl(euint256 a, uint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.shl(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates shr(euint256 a, euint8 b) and returns the result. */ function shr(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.shr(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates shr(euint256 a, uint8) and returns the result. */ function shr(euint256 a, uint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.shr(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotl(euint256 a, euint8 b) and returns the result. */ function rotl(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.rotl(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates rotl(euint256 a, uint8) and returns the result. */ function rotl(euint256 a, uint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.rotl(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev Evaluates rotr(euint256 a, euint8 b) and returns the result. */ function rotr(euint256 a, euint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint256.wrap(Impl.rotr(euint256.unwrap(a), euint256.unwrap(asEuint256(b)), false)); } /** * @dev Evaluates rotr(euint256 a, uint8) and returns the result. */ function rotr(euint256 a, uint8 b) internal returns (euint256) { if (!isInitialized(a)) { a = asEuint256(0); } return euint256.wrap(Impl.rotr(euint256.unwrap(a), bytes32(uint256(b)), true)); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, ebool a, ebool b) internal returns (ebool) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEbool(false); } if (!isInitialized(b)) { b = asEbool(false); } return ebool.wrap(Impl.select(ebool.unwrap(control), ebool.unwrap(a), ebool.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, euint8 a, euint8 b) internal returns (euint8) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEuint8(0); } if (!isInitialized(b)) { b = asEuint8(0); } return euint8.wrap(Impl.select(ebool.unwrap(control), euint8.unwrap(a), euint8.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, euint16 a, euint16 b) internal returns (euint16) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEuint16(0); } if (!isInitialized(b)) { b = asEuint16(0); } return euint16.wrap(Impl.select(ebool.unwrap(control), euint16.unwrap(a), euint16.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, euint32 a, euint32 b) internal returns (euint32) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEuint32(0); } if (!isInitialized(b)) { b = asEuint32(0); } return euint32.wrap(Impl.select(ebool.unwrap(control), euint32.unwrap(a), euint32.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, euint64 a, euint64 b) internal returns (euint64) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEuint64(0); } if (!isInitialized(b)) { b = asEuint64(0); } return euint64.wrap(Impl.select(ebool.unwrap(control), euint64.unwrap(a), euint64.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, euint128 a, euint128 b) internal returns (euint128) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEuint128(0); } if (!isInitialized(b)) { b = asEuint128(0); } return euint128.wrap(Impl.select(ebool.unwrap(control), euint128.unwrap(a), euint128.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, eaddress a, eaddress b) internal returns (eaddress) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEaddress(address(0)); } if (!isInitialized(b)) { b = asEaddress(address(0)); } return eaddress.wrap(Impl.select(ebool.unwrap(control), eaddress.unwrap(a), eaddress.unwrap(b))); } /** * @dev If 'control's value is 'true', the result has the same value as 'ifTrue'. * If 'control's value is 'false', the result has the same value as 'ifFalse'. */ function select(ebool control, euint256 a, euint256 b) internal returns (euint256) { if (!isInitialized(control)) { control = asEbool(false); } if (!isInitialized(a)) { a = asEuint256(0); } if (!isInitialized(b)) { b = asEuint256(0); } return euint256.wrap(Impl.select(ebool.unwrap(control), euint256.unwrap(a), euint256.unwrap(b))); } /** * @dev Casts an encrypted integer from 'euint16' to 'euint8'. */ function asEuint8(euint16 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint16(0); } return euint8.wrap(Impl.cast(euint16.unwrap(value), FheType.Uint8)); } /** * @dev Casts an encrypted integer from 'euint32' to 'euint8'. */ function asEuint8(euint32 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint32(0); } return euint8.wrap(Impl.cast(euint32.unwrap(value), FheType.Uint8)); } /** * @dev Casts an encrypted integer from 'euint64' to 'euint8'. */ function asEuint8(euint64 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint64(0); } return euint8.wrap(Impl.cast(euint64.unwrap(value), FheType.Uint8)); } /** * @dev Casts an encrypted integer from 'euint128' to 'euint8'. */ function asEuint8(euint128 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint128(0); } return euint8.wrap(Impl.cast(euint128.unwrap(value), FheType.Uint8)); } /** * @dev Casts an encrypted integer from 'euint256' to 'euint8'. */ function asEuint8(euint256 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint256(0); } return euint8.wrap(Impl.cast(euint256.unwrap(value), FheType.Uint8)); } /** /** * @dev Converts an 'ebool' to an 'euint8'. */ function asEuint8(ebool b) internal returns (euint8) { if (!isInitialized(b)) { b = asEbool(false); } return euint8.wrap(Impl.cast(ebool.unwrap(b), FheType.Uint8)); } /** * @dev Casts an encrypted integer from 'euint8' to 'ebool'. */ function asEbool(euint8 value) internal returns (ebool) { if (!isInitialized(value)) { value = asEuint8(0); } return ne(value, 0); } /** * @dev Casts an encrypted integer from 'euint8' to 'euint16'. */ function asEuint16(euint8 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint8(0); } return euint16.wrap(Impl.cast(euint8.unwrap(value), FheType.Uint16)); } /** * @dev Casts an encrypted integer from 'euint32' to 'euint16'. */ function asEuint16(euint32 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint32(0); } return euint16.wrap(Impl.cast(euint32.unwrap(value), FheType.Uint16)); } /** * @dev Casts an encrypted integer from 'euint64' to 'euint16'. */ function asEuint16(euint64 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint64(0); } return euint16.wrap(Impl.cast(euint64.unwrap(value), FheType.Uint16)); } /** * @dev Casts an encrypted integer from 'euint128' to 'euint16'. */ function asEuint16(euint128 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint128(0); } return euint16.wrap(Impl.cast(euint128.unwrap(value), FheType.Uint16)); } /** * @dev Casts an encrypted integer from 'euint256' to 'euint16'. */ function asEuint16(euint256 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint256(0); } return euint16.wrap(Impl.cast(euint256.unwrap(value), FheType.Uint16)); } /** /** * @dev Converts an 'ebool' to an 'euint16'. */ function asEuint16(ebool b) internal returns (euint16) { if (!isInitialized(b)) { b = asEbool(false); } return euint16.wrap(Impl.cast(ebool.unwrap(b), FheType.Uint16)); } /** * @dev Casts an encrypted integer from 'euint16' to 'ebool'. */ function asEbool(euint16 value) internal returns (ebool) { if (!isInitialized(value)) { value = asEuint16(0); } return ne(value, 0); } /** * @dev Casts an encrypted integer from 'euint8' to 'euint32'. */ function asEuint32(euint8 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint8(0); } return euint32.wrap(Impl.cast(euint8.unwrap(value), FheType.Uint32)); } /** * @dev Casts an encrypted integer from 'euint16' to 'euint32'. */ function asEuint32(euint16 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint16(0); } return euint32.wrap(Impl.cast(euint16.unwrap(value), FheType.Uint32)); } /** * @dev Casts an encrypted integer from 'euint64' to 'euint32'. */ function asEuint32(euint64 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint64(0); } return euint32.wrap(Impl.cast(euint64.unwrap(value), FheType.Uint32)); } /** * @dev Casts an encrypted integer from 'euint128' to 'euint32'. */ function asEuint32(euint128 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint128(0); } return euint32.wrap(Impl.cast(euint128.unwrap(value), FheType.Uint32)); } /** * @dev Casts an encrypted integer from 'euint256' to 'euint32'. */ function asEuint32(euint256 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint256(0); } return euint32.wrap(Impl.cast(euint256.unwrap(value), FheType.Uint32)); } /** /** * @dev Converts an 'ebool' to an 'euint32'. */ function asEuint32(ebool b) internal returns (euint32) { if (!isInitialized(b)) { b = asEbool(false); } return euint32.wrap(Impl.cast(ebool.unwrap(b), FheType.Uint32)); } /** * @dev Casts an encrypted integer from 'euint32' to 'ebool'. */ function asEbool(euint32 value) internal returns (ebool) { if (!isInitialized(value)) { value = asEuint32(0); } return ne(value, 0); } /** * @dev Casts an encrypted integer from 'euint8' to 'euint64'. */ function asEuint64(euint8 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint8(0); } return euint64.wrap(Impl.cast(euint8.unwrap(value), FheType.Uint64)); } /** * @dev Casts an encrypted integer from 'euint16' to 'euint64'. */ function asEuint64(euint16 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint16(0); } return euint64.wrap(Impl.cast(euint16.unwrap(value), FheType.Uint64)); } /** * @dev Casts an encrypted integer from 'euint32' to 'euint64'. */ function asEuint64(euint32 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint32(0); } return euint64.wrap(Impl.cast(euint32.unwrap(value), FheType.Uint64)); } /** * @dev Casts an encrypted integer from 'euint128' to 'euint64'. */ function asEuint64(euint128 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint128(0); } return euint64.wrap(Impl.cast(euint128.unwrap(value), FheType.Uint64)); } /** * @dev Casts an encrypted integer from 'euint256' to 'euint64'. */ function asEuint64(euint256 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint256(0); } return euint64.wrap(Impl.cast(euint256.unwrap(value), FheType.Uint64)); } /** /** * @dev Converts an 'ebool' to an 'euint64'. */ function asEuint64(ebool b) internal returns (euint64) { if (!isInitialized(b)) { b = asEbool(false); } return euint64.wrap(Impl.cast(ebool.unwrap(b), FheType.Uint64)); } /** * @dev Casts an encrypted integer from 'euint64' to 'ebool'. */ function asEbool(euint64 value) internal returns (ebool) { if (!isInitialized(value)) { value = asEuint64(0); } return ne(value, 0); } /** * @dev Casts an encrypted integer from 'euint8' to 'euint128'. */ function asEuint128(euint8 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint8(0); } return euint128.wrap(Impl.cast(euint8.unwrap(value), FheType.Uint128)); } /** * @dev Casts an encrypted integer from 'euint16' to 'euint128'. */ function asEuint128(euint16 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint16(0); } return euint128.wrap(Impl.cast(euint16.unwrap(value), FheType.Uint128)); } /** * @dev Casts an encrypted integer from 'euint32' to 'euint128'. */ function asEuint128(euint32 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint32(0); } return euint128.wrap(Impl.cast(euint32.unwrap(value), FheType.Uint128)); } /** * @dev Casts an encrypted integer from 'euint64' to 'euint128'. */ function asEuint128(euint64 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint64(0); } return euint128.wrap(Impl.cast(euint64.unwrap(value), FheType.Uint128)); } /** * @dev Casts an encrypted integer from 'euint256' to 'euint128'. */ function asEuint128(euint256 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint256(0); } return euint128.wrap(Impl.cast(euint256.unwrap(value), FheType.Uint128)); } /** /** * @dev Converts an 'ebool' to an 'euint128'. */ function asEuint128(ebool b) internal returns (euint128) { if (!isInitialized(b)) { b = asEbool(false); } return euint128.wrap(Impl.cast(ebool.unwrap(b), FheType.Uint128)); } /** * @dev Casts an encrypted integer from 'euint128' to 'ebool'. */ function asEbool(euint128 value) internal returns (ebool) { if (!isInitialized(value)) { value = asEuint128(0); } return ne(value, 0); } /** * @dev Casts an encrypted integer from 'euint8' to 'euint256'. */ function asEuint256(euint8 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint8(0); } return euint256.wrap(Impl.cast(euint8.unwrap(value), FheType.Uint256)); } /** * @dev Casts an encrypted integer from 'euint16' to 'euint256'. */ function asEuint256(euint16 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint16(0); } return euint256.wrap(Impl.cast(euint16.unwrap(value), FheType.Uint256)); } /** * @dev Casts an encrypted integer from 'euint32' to 'euint256'. */ function asEuint256(euint32 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint32(0); } return euint256.wrap(Impl.cast(euint32.unwrap(value), FheType.Uint256)); } /** * @dev Casts an encrypted integer from 'euint64' to 'euint256'. */ function asEuint256(euint64 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint64(0); } return euint256.wrap(Impl.cast(euint64.unwrap(value), FheType.Uint256)); } /** * @dev Casts an encrypted integer from 'euint128' to 'euint256'. */ function asEuint256(euint128 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint128(0); } return euint256.wrap(Impl.cast(euint128.unwrap(value), FheType.Uint256)); } /** /** * @dev Converts an 'ebool' to an 'euint256'. */ function asEuint256(ebool b) internal returns (euint256) { if (!isInitialized(b)) { b = asEbool(false); } return euint256.wrap(Impl.cast(ebool.unwrap(b), FheType.Uint256)); } /** * @dev Casts an encrypted integer from 'euint256' to 'ebool'. */ function asEbool(euint256 value) internal returns (ebool) { if (!isInitialized(value)) { value = asEuint256(0); } return ne(value, 0); } /** * @dev Evaluates not(ebool value) and returns the result. */ function not(ebool value) internal returns (ebool) { if (!isInitialized(value)) { value = asEbool(false); } return ebool.wrap(Impl.not(ebool.unwrap(value))); } /** * @dev Evaluates neg(euint8 value) and returns the result. */ function neg(euint8 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint8(0); } return euint8.wrap(Impl.neg(euint8.unwrap(value))); } /** * @dev Evaluates not(euint8 value) and returns the result. */ function not(euint8 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint8(0); } return euint8.wrap(Impl.not(euint8.unwrap(value))); } /** * @dev Evaluates neg(euint16 value) and returns the result. */ function neg(euint16 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint16(0); } return euint16.wrap(Impl.neg(euint16.unwrap(value))); } /** * @dev Evaluates not(euint16 value) and returns the result. */ function not(euint16 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint16(0); } return euint16.wrap(Impl.not(euint16.unwrap(value))); } /** * @dev Evaluates neg(euint32 value) and returns the result. */ function neg(euint32 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint32(0); } return euint32.wrap(Impl.neg(euint32.unwrap(value))); } /** * @dev Evaluates not(euint32 value) and returns the result. */ function not(euint32 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint32(0); } return euint32.wrap(Impl.not(euint32.unwrap(value))); } /** * @dev Evaluates neg(euint64 value) and returns the result. */ function neg(euint64 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint64(0); } return euint64.wrap(Impl.neg(euint64.unwrap(value))); } /** * @dev Evaluates not(euint64 value) and returns the result. */ function not(euint64 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint64(0); } return euint64.wrap(Impl.not(euint64.unwrap(value))); } /** * @dev Evaluates neg(euint128 value) and returns the result. */ function neg(euint128 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint128(0); } return euint128.wrap(Impl.neg(euint128.unwrap(value))); } /** * @dev Evaluates not(euint128 value) and returns the result. */ function not(euint128 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint128(0); } return euint128.wrap(Impl.not(euint128.unwrap(value))); } /** * @dev Evaluates neg(euint256 value) and returns the result. */ function neg(euint256 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint256(0); } return euint256.wrap(Impl.neg(euint256.unwrap(value))); } /** * @dev Evaluates not(euint256 value) and returns the result. */ function not(euint256 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint256(0); } return euint256.wrap(Impl.not(euint256.unwrap(value))); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted ebool integer. * @dev If inputProof is empty, the externalEbool inputHandle can be used as a regular ebool handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEbool inputHandle, bytes memory inputProof) internal returns (ebool) { if (inputProof.length != 0) { return ebool.wrap(Impl.verify(externalEbool.unwrap(inputHandle), inputProof, FheType.Bool)); } else { bytes32 inputBytes32 = externalEbool.unwrap(inputHandle); if (inputBytes32 == 0) { return asEbool(false); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return ebool.wrap(inputBytes32); } } /** * @dev Converts a plaintext boolean to an encrypted boolean. */ function asEbool(bool value) internal returns (ebool) { return ebool.wrap(Impl.trivialEncrypt(value ? 1 : 0, FheType.Bool)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint8 integer. * @dev If inputProof is empty, the externalEuint8 inputHandle can be used as a regular euint8 handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEuint8 inputHandle, bytes memory inputProof) internal returns (euint8) { if (inputProof.length != 0) { return euint8.wrap(Impl.verify(externalEuint8.unwrap(inputHandle), inputProof, FheType.Uint8)); } else { bytes32 inputBytes32 = externalEuint8.unwrap(inputHandle); if (inputBytes32 == 0) { return asEuint8(0); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return euint8.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted euint8 value. */ function asEuint8(uint8 value) internal returns (euint8) { return euint8.wrap(Impl.trivialEncrypt(uint256(value), FheType.Uint8)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint16 integer. * @dev If inputProof is empty, the externalEuint16 inputHandle can be used as a regular euint16 handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEuint16 inputHandle, bytes memory inputProof) internal returns (euint16) { if (inputProof.length != 0) { return euint16.wrap(Impl.verify(externalEuint16.unwrap(inputHandle), inputProof, FheType.Uint16)); } else { bytes32 inputBytes32 = externalEuint16.unwrap(inputHandle); if (inputBytes32 == 0) { return asEuint16(0); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return euint16.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted euint16 value. */ function asEuint16(uint16 value) internal returns (euint16) { return euint16.wrap(Impl.trivialEncrypt(uint256(value), FheType.Uint16)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint32 integer. * @dev If inputProof is empty, the externalEuint32 inputHandle can be used as a regular euint32 handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEuint32 inputHandle, bytes memory inputProof) internal returns (euint32) { if (inputProof.length != 0) { return euint32.wrap(Impl.verify(externalEuint32.unwrap(inputHandle), inputProof, FheType.Uint32)); } else { bytes32 inputBytes32 = externalEuint32.unwrap(inputHandle); if (inputBytes32 == 0) { return asEuint32(0); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return euint32.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted euint32 value. */ function asEuint32(uint32 value) internal returns (euint32) { return euint32.wrap(Impl.trivialEncrypt(uint256(value), FheType.Uint32)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint64 integer. * @dev If inputProof is empty, the externalEuint64 inputHandle can be used as a regular euint64 handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEuint64 inputHandle, bytes memory inputProof) internal returns (euint64) { if (inputProof.length != 0) { return euint64.wrap(Impl.verify(externalEuint64.unwrap(inputHandle), inputProof, FheType.Uint64)); } else { bytes32 inputBytes32 = externalEuint64.unwrap(inputHandle); if (inputBytes32 == 0) { return asEuint64(0); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return euint64.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted euint64 value. */ function asEuint64(uint64 value) internal returns (euint64) { return euint64.wrap(Impl.trivialEncrypt(uint256(value), FheType.Uint64)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint128 integer. * @dev If inputProof is empty, the externalEuint128 inputHandle can be used as a regular euint128 handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEuint128 inputHandle, bytes memory inputProof) internal returns (euint128) { if (inputProof.length != 0) { return euint128.wrap(Impl.verify(externalEuint128.unwrap(inputHandle), inputProof, FheType.Uint128)); } else { bytes32 inputBytes32 = externalEuint128.unwrap(inputHandle); if (inputBytes32 == 0) { return asEuint128(0); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return euint128.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted euint128 value. */ function asEuint128(uint128 value) internal returns (euint128) { return euint128.wrap(Impl.trivialEncrypt(uint256(value), FheType.Uint128)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted eaddress integer. * @dev If inputProof is empty, the externalEaddress inputHandle can be used as a regular eaddress handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEaddress inputHandle, bytes memory inputProof) internal returns (eaddress) { if (inputProof.length != 0) { return eaddress.wrap(Impl.verify(externalEaddress.unwrap(inputHandle), inputProof, FheType.Uint160)); } else { bytes32 inputBytes32 = externalEaddress.unwrap(inputHandle); if (inputBytes32 == 0) { return asEaddress(address(0)); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return eaddress.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted eaddress value. */ function asEaddress(address value) internal returns (eaddress) { return eaddress.wrap(Impl.trivialEncrypt(uint256(uint160(value)), FheType.Uint160)); } /** * @dev Convert an inputHandle with corresponding inputProof to an encrypted euint256 integer. * @dev If inputProof is empty, the externalEuint256 inputHandle can be used as a regular euint256 handle if it * has already been verified and allowed to the sender. * This could facilitate integrating smart contract accounts with fhevm. */ function fromExternal(externalEuint256 inputHandle, bytes memory inputProof) internal returns (euint256) { if (inputProof.length != 0) { return euint256.wrap(Impl.verify(externalEuint256.unwrap(inputHandle), inputProof, FheType.Uint256)); } else { bytes32 inputBytes32 = externalEuint256.unwrap(inputHandle); if (inputBytes32 == 0) { return asEuint256(0); } if (!Impl.isAllowed(inputBytes32, msg.sender)) revert SenderNotAllowedToUseHandle(inputBytes32, msg.sender); return euint256.wrap(inputBytes32); } } /** * @dev Convert a plaintext value to an encrypted euint256 value. */ function asEuint256(uint256 value) internal returns (euint256) { return euint256.wrap(Impl.trivialEncrypt(uint256(value), FheType.Uint256)); } /** * @dev Generates a random encrypted value. */ function randEbool() internal returns (ebool) { return ebool.wrap(Impl.rand(FheType.Bool)); } /** * @dev Generates a random encrypted value. */ function randEuint8() internal returns (euint8) { return euint8.wrap(Impl.rand(FheType.Uint8)); } /** * @dev Generates a random encrypted 8-bit unsigned integer in the [0, upperBound) range. * The upperBound must be a power of 2. */ function randEuint8(uint8 upperBound) internal returns (euint8) { return euint8.wrap(Impl.randBounded(upperBound, FheType.Uint8)); } /** * @dev Generates a random encrypted value. */ function randEuint16() internal returns (euint16) { return euint16.wrap(Impl.rand(FheType.Uint16)); } /** * @dev Generates a random encrypted 16-bit unsigned integer in the [0, upperBound) range. * The upperBound must be a power of 2. */ function randEuint16(uint16 upperBound) internal returns (euint16) { return euint16.wrap(Impl.randBounded(upperBound, FheType.Uint16)); } /** * @dev Generates a random encrypted value. */ function randEuint32() internal returns (euint32) { return euint32.wrap(Impl.rand(FheType.Uint32)); } /** * @dev Generates a random encrypted 32-bit unsigned integer in the [0, upperBound) range. * The upperBound must be a power of 2. */ function randEuint32(uint32 upperBound) internal returns (euint32) { return euint32.wrap(Impl.randBounded(upperBound, FheType.Uint32)); } /** * @dev Generates a random encrypted value. */ function randEuint64() internal returns (euint64) { return euint64.wrap(Impl.rand(FheType.Uint64)); } /** * @dev Generates a random encrypted 64-bit unsigned integer in the [0, upperBound) range. * The upperBound must be a power of 2. */ function randEuint64(uint64 upperBound) internal returns (euint64) { return euint64.wrap(Impl.randBounded(upperBound, FheType.Uint64)); } /** * @dev Generates a random encrypted value. */ function randEuint128() internal returns (euint128) { return euint128.wrap(Impl.rand(FheType.Uint128)); } /** * @dev Generates a random encrypted 128-bit unsigned integer in the [0, upperBound) range. * The upperBound must be a power of 2. */ function randEuint128(uint128 upperBound) internal returns (euint128) { return euint128.wrap(Impl.randBounded(upperBound, FheType.Uint128)); } /** * @dev Generates a random encrypted value. */ function randEuint256() internal returns (euint256) { return euint256.wrap(Impl.rand(FheType.Uint256)); } /** * @dev Generates a random encrypted 256-bit unsigned integer in the [0, upperBound) range. * The upperBound must be a power of 2. */ function randEuint256(uint256 upperBound) internal returns (euint256) { return euint256.wrap(Impl.randBounded(upperBound, FheType.Uint256)); } /** * @dev Evaluates sum(euint8[] values) and returns the result. */ function sum(euint8[] memory values) internal returns (euint8) { bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint8 v = values[i]; if (!isInitialized(v)) v = asEuint8(0); handles[i] = euint8.unwrap(v); } return euint8.wrap(Impl.sum(handles, FheType.Uint8)); } /** * @dev Evaluates sum(euint16[] values) and returns the result. */ function sum(euint16[] memory values) internal returns (euint16) { bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint16 v = values[i]; if (!isInitialized(v)) v = asEuint16(0); handles[i] = euint16.unwrap(v); } return euint16.wrap(Impl.sum(handles, FheType.Uint16)); } /** * @dev Evaluates sum(euint32[] values) and returns the result. */ function sum(euint32[] memory values) internal returns (euint32) { bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint32 v = values[i]; if (!isInitialized(v)) v = asEuint32(0); handles[i] = euint32.unwrap(v); } return euint32.wrap(Impl.sum(handles, FheType.Uint32)); } /** * @dev Evaluates sum(euint64[] values) and returns the result. */ function sum(euint64[] memory values) internal returns (euint64) { bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint64 v = values[i]; if (!isInitialized(v)) v = asEuint64(0); handles[i] = euint64.unwrap(v); } return euint64.wrap(Impl.sum(handles, FheType.Uint64)); } /** * @dev Evaluates sum(euint128[] values) and returns the result. */ function sum(euint128[] memory values) internal returns (euint128) { bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint128 v = values[i]; if (!isInitialized(v)) v = asEuint128(0); handles[i] = euint128.unwrap(v); } return euint128.wrap(Impl.sum(handles, FheType.Uint128)); } /** * @dev Evaluates isIn(euint8 value, uint8[] memory set) and returns the result. */ function isIn(euint8 value, euint8[] memory values) internal returns (ebool) { euint8 v = value; if (!isInitialized(v)) v = asEuint8(0); bytes32 handle = euint8.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint8 elem = values[i]; if (!isInitialized(elem)) elem = asEuint8(0); handles[i] = euint8.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint8)); } /** * @dev Evaluates isIn(euint16 value, euint16[] memory values) and returns the result. */ function isIn(euint16 value, euint16[] memory values) internal returns (ebool) { euint16 v = value; if (!isInitialized(v)) v = asEuint16(0); bytes32 handle = euint16.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint16 elem = values[i]; if (!isInitialized(elem)) elem = asEuint16(0); handles[i] = euint16.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint16)); } /** * @dev Evaluates isIn(euint32 value, euint32[] memory values) and returns the result. */ function isIn(euint32 value, euint32[] memory values) internal returns (ebool) { euint32 v = value; if (!isInitialized(v)) v = asEuint32(0); bytes32 handle = euint32.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint32 elem = values[i]; if (!isInitialized(elem)) elem = asEuint32(0); handles[i] = euint32.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint32)); } /** * @dev Evaluates isIn(euint64 value, euint64[] memory values) and returns the result. */ function isIn(euint64 value, euint64[] memory values) internal returns (ebool) { euint64 v = value; if (!isInitialized(v)) v = asEuint64(0); bytes32 handle = euint64.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint64 elem = values[i]; if (!isInitialized(elem)) elem = asEuint64(0); handles[i] = euint64.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint64)); } /** * @dev Evaluates isIn(euint128 value, euint128[] memory values) and returns the result. */ function isIn(euint128 value, euint128[] memory values) internal returns (ebool) { euint128 v = value; if (!isInitialized(v)) v = asEuint128(0); bytes32 handle = euint128.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint128 elem = values[i]; if (!isInitialized(elem)) elem = asEuint128(0); handles[i] = euint128.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint128)); } /** * @dev Evaluates isIn(eaddress value, eaddress[] memory values) and returns the result. */ function isIn(eaddress value, eaddress[] memory values) internal returns (ebool) { eaddress v = value; if (!isInitialized(v)) v = asEaddress(address(0)); bytes32 handle = eaddress.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { eaddress elem = values[i]; if (!isInitialized(elem)) elem = asEaddress(address(0)); handles[i] = eaddress.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint160)); } /** * @dev Evaluates isIn(euint256 value, euint256[] memory values) and returns the result. */ function isIn(euint256 value, euint256[] memory values) internal returns (ebool) { euint256 v = value; if (!isInitialized(v)) v = asEuint256(0); bytes32 handle = euint256.unwrap(v); bytes32[] memory handles = new bytes32[](values.length); for (uint256 i = 0; i < values.length; i++) { euint256 elem = values[i]; if (!isInitialized(elem)) elem = asEuint256(0); handles[i] = euint256.unwrap(elem); } return ebool.wrap(Impl.isIn(handle, handles, FheType.Uint256)); } /** * @dev This function cleans the transient storage for the ACL (accounts) and the InputVerifier * (input proofs). * This could be useful for integration with Account Abstraction when bundling several * UserOps calling the FHEVMExecutor. */ function cleanTransientStorage() internal { Impl.cleanTransientStorageACL(); Impl.cleanTransientStorageInputVerifier(); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(ebool value, address account) internal view returns (bool) { return Impl.isAllowed(ebool.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(ebool value) internal view returns (bool) { return Impl.isAllowed(ebool.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(ebool value, address account) internal returns (ebool) { if (!isInitialized(value)) { value = asEbool(false); } Impl.allow(ebool.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(ebool value) internal returns (ebool) { if (!isInitialized(value)) { value = asEbool(false); } Impl.allow(ebool.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(ebool value, address account) internal returns (ebool) { if (!isInitialized(value)) { value = asEbool(false); } Impl.allowTransient(ebool.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(ebool value) internal returns (ebool) { if (!isInitialized(value)) { value = asEbool(false); } Impl.makePubliclyDecryptable(ebool.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(ebool value) internal view returns (bool) { return Impl.isPubliclyDecryptable(ebool.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(euint8 value, address account) internal view returns (bool) { return Impl.isAllowed(euint8.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(euint8 value) internal view returns (bool) { return Impl.isAllowed(euint8.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(euint8 value, address account) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint8(0); } Impl.allow(euint8.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(euint8 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint8(0); } Impl.allow(euint8.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(euint8 value, address account) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint8(0); } Impl.allowTransient(euint8.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(euint8 value) internal returns (euint8) { if (!isInitialized(value)) { value = asEuint8(0); } Impl.makePubliclyDecryptable(euint8.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(euint8 value) internal view returns (bool) { return Impl.isPubliclyDecryptable(euint8.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(euint16 value, address account) internal view returns (bool) { return Impl.isAllowed(euint16.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(euint16 value) internal view returns (bool) { return Impl.isAllowed(euint16.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(euint16 value, address account) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint16(0); } Impl.allow(euint16.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(euint16 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint16(0); } Impl.allow(euint16.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(euint16 value, address account) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint16(0); } Impl.allowTransient(euint16.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(euint16 value) internal returns (euint16) { if (!isInitialized(value)) { value = asEuint16(0); } Impl.makePubliclyDecryptable(euint16.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(euint16 value) internal view returns (bool) { return Impl.isPubliclyDecryptable(euint16.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(euint32 value, address account) internal view returns (bool) { return Impl.isAllowed(euint32.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(euint32 value) internal view returns (bool) { return Impl.isAllowed(euint32.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(euint32 value, address account) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint32(0); } Impl.allow(euint32.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(euint32 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint32(0); } Impl.allow(euint32.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(euint32 value, address account) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint32(0); } Impl.allowTransient(euint32.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(euint32 value) internal returns (euint32) { if (!isInitialized(value)) { value = asEuint32(0); } Impl.makePubliclyDecryptable(euint32.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(euint32 value) internal view returns (bool) { return Impl.isPubliclyDecryptable(euint32.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(euint64 value, address account) internal view returns (bool) { return Impl.isAllowed(euint64.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(euint64 value) internal view returns (bool) { return Impl.isAllowed(euint64.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(euint64 value, address account) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint64(0); } Impl.allow(euint64.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(euint64 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint64(0); } Impl.allow(euint64.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(euint64 value, address account) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint64(0); } Impl.allowTransient(euint64.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(euint64 value) internal returns (euint64) { if (!isInitialized(value)) { value = asEuint64(0); } Impl.makePubliclyDecryptable(euint64.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(euint64 value) internal view returns (bool) { return Impl.isPubliclyDecryptable(euint64.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(euint128 value, address account) internal view returns (bool) { return Impl.isAllowed(euint128.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(euint128 value) internal view returns (bool) { return Impl.isAllowed(euint128.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(euint128 value, address account) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint128(0); } Impl.allow(euint128.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(euint128 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint128(0); } Impl.allow(euint128.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(euint128 value, address account) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint128(0); } Impl.allowTransient(euint128.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(euint128 value) internal returns (euint128) { if (!isInitialized(value)) { value = asEuint128(0); } Impl.makePubliclyDecryptable(euint128.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(euint128 value) internal view returns (bool) { return Impl.isPubliclyDecryptable(euint128.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(eaddress value, address account) internal view returns (bool) { return Impl.isAllowed(eaddress.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(eaddress value) internal view returns (bool) { return Impl.isAllowed(eaddress.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(eaddress value, address account) internal returns (eaddress) { if (!isInitialized(value)) { value = asEaddress(address(0)); } Impl.allow(eaddress.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(eaddress value) internal returns (eaddress) { if (!isInitialized(value)) { value = asEaddress(address(0)); } Impl.allow(eaddress.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(eaddress value, address account) internal returns (eaddress) { if (!isInitialized(value)) { value = asEaddress(address(0)); } Impl.allowTransient(eaddress.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(eaddress value) internal returns (eaddress) { if (!isInitialized(value)) { value = asEaddress(address(0)); } Impl.makePubliclyDecryptable(eaddress.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(eaddress value) internal view returns (bool) { return Impl.isPubliclyDecryptable(eaddress.unwrap(value)); } /** * @dev Returns whether the account is allowed to use the value. */ function isAllowed(euint256 value, address account) internal view returns (bool) { return Impl.isAllowed(euint256.unwrap(value), account); } /** * @dev Returns whether the sender is allowed to use the value. */ function isSenderAllowed(euint256 value) internal view returns (bool) { return Impl.isAllowed(euint256.unwrap(value), msg.sender); } /** * @dev Allows the use of value for the address account. */ function allow(euint256 value, address account) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint256(0); } Impl.allow(euint256.unwrap(value), account); return value; } /** * @dev Allows the use of value for this address (address(this)). */ function allowThis(euint256 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint256(0); } Impl.allow(euint256.unwrap(value), address(this)); return value; } /** * @dev Allows the use of value by address account for this transaction. */ function allowTransient(euint256 value, address account) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint256(0); } Impl.allowTransient(euint256.unwrap(value), account); return value; } /** * @dev Makes the value publicly decryptable. */ function makePubliclyDecryptable(euint256 value) internal returns (euint256) { if (!isInitialized(value)) { value = asEuint256(0); } Impl.makePubliclyDecryptable(euint256.unwrap(value)); return value; } /** * @dev Returns whether the the value is publicly decryptable. */ function isPubliclyDecryptable(euint256 value) internal view returns (bool) { return Impl.isPubliclyDecryptable(euint256.unwrap(value)); } /** * @dev Returns whether the account is on the deny list. */ function isAccountDenied(address account) internal view returns (bool) { return Impl.isAccountDenied(account); } /// @notice Checks if the `handle` can be decrypted in the given context (`user`, `contractAddress`). /// @param handle The handle as a bytes32. /// @param user The account address that is part of the user decryption context. /// @param contractAddress The address of the contract that is part of the user decryption context. /// @return False if `user` has not (user, contractAddress) context. function isUserDecryptable(bytes32 handle, address user, address contractAddress) internal view returns (bool) { if (user == contractAddress) { return false; } return Impl.persistAllowed(handle, user) && Impl.persistAllowed(handle, contractAddress); } /// @notice Checks if the user decryption rights have been delegated by `delegator` to `delegate` /// in the context of the given `contractAddress`. /// @param delegator The delegator address /// @param delegate The account authorized to request user decryptions on behalf of `delegator` /// @param contractAddress The address of the contract that is part of the user decryption context /// @param handle The handle as a bytes32 /// @return False if no active delegation exists for the (delegate, contractAddress) context, or if it has expired. function isDelegatedForUserDecryption( address delegator, address delegate, address contractAddress, bytes32 handle ) internal view returns (bool) { return Impl.isDelegatedForUserDecryption(delegator, delegate, contractAddress, handle); } /// @notice Delegates the user decryption rights that caller contract (`address(this)`) holds in the context /// of the given `contractAddress` to a new `delegate` account for a limited amount of time. /// @dev The ACL grants user decryption permission based on a (User, Contract) pair. If the pair /// (`address(this)`, `contractAddress`) has permission to decrypt a handle, calling this function grants /// the temporary permission to the new pair (`delegate`, `contractAddress`) to decrypt the same handle. /// @param delegate The account that will request a user decryption on behalf of delegator (`address(this)`). /// @param contractAddress The address of the contract that is part of the user decryption context. /// @param expirationDate UNIX timestamp when the delegation expires. /// /// @dev Requirements: /// - the ACL contract must not be paused. /// Reverts via an {PausableUpgradeable-EnforcedPause} error otherwise. /// /// - `expirationDate` must be strictly in the future. /// i.e. `expirationDate > block.timestamp` /// Reverts with an {IACL-ExpirationDateInThePast} error otherwise. /// /// - `expirationDate` must differ from the current value. /// Reverts with an {IACL-ExpirationDateAlreadySetToSameValue} error otherwise. /// /// - at most one delegate OR revoke per block for this /// (address(this), delegate, contractAddress) tuple to avoid racey /// state updates. /// Reverts with an {IACL-AlreadyDelegatedOrRevokedInSameBlock} error /// if a delegate OR revoke operation already occurred in the current /// block. See {canDelegateOrRevokeNow} /// /// - The `contractAddress` cannot be the caller contract (`address(this)`). /// Reverts with an {IACL-SenderCannotBeContractAddress} error if /// `contractAddress == address(this)`. /// /// - The `delegate` address cannot be the caller contract (`address(this)`). /// Reverts with an {IACL-SenderCannotBeDelegate} error if /// `delegate == address(this)`. /// /// - The `delegate` address cannot be the `contractAddress`. /// Reverts with an {IACL-DelegateCannotBeContractAddress} error if /// `delegate == contractAddress`. function delegateUserDecryption(address delegate, address contractAddress, uint64 expirationDate) internal { Impl.delegateForUserDecryption(delegate, contractAddress, expirationDate); } /// @notice Permanently delegates the user decryption rights that the caller contract (`address(this)`) holds in the /// context of the given `contractAddress` to a new `delegate` account. /// @dev This is the version without expiration of {delegateUserDecryption}. The permission remains active until explicitly /// revoked by the delegator using {revokeUserDecryptionDelegation}. /// @param delegate The account that will request a user decryption on behalf of delegator (`address(this)`). /// @param contractAddress The address of the contract that is part of the user decryption context. function delegateUserDecryptionWithoutExpiration(address delegate, address contractAddress) internal { Impl.delegateForUserDecryption(delegate, contractAddress, type(uint64).max); } /// @notice Batch delegates the user decryption rights that the caller contract (`address(this)`) holds in the context of the /// given `contractAddresses[i]` to a new `delegate` account for a limited amount of time. /// @param delegate The account that will request a user decryption on behalf of delegator (`address(this)`).. /// @param contractAddresses The array of contract addresses that form the user decryption context tuples /// (`address(this)`, `contractAddresses[i]`). /// @param expirationDate UNIX timestamp when the delegation expires. function delegateUserDecryptions( address delegate, address[] memory contractAddresses, uint64 expirationDate ) internal { Impl.delegateForUserDecryptions(delegate, contractAddresses, expirationDate); } /// @notice Batch delegates user decryption rights without expiration that the caller contract (`address(this)`) holds in the context of /// the given `contractAddresses[i]` to a new `delegate` account. /// @param delegate The account that will request a user decryption on behalf of delegator (`address(this)`).. /// @param contractAddresses The array of contract addresses that form the user decryption context tuples /// (`address(this)`, `contractAddresses[i]`). function delegateUserDecryptionsWithoutExpiration(address delegate, address[] memory contractAddresses) internal { Impl.delegateForUserDecryptions(delegate, contractAddresses, type(uint64).max); } /// @notice Revoke an existing delegation from delegator `address(this)` to a (delegate, contractAddress) user /// decryption context. /// @param delegate The account that was authorized to request user decryptions on behalf of the caller contract `address(this)` /// @param contractAddress The address of the contract that is part of the user decryption context /// @dev Requirements: /// - the ACL contract must not be paused. /// Reverts with an {PausableUpgradeable-EnforcedPause} error otherwise. /// /// - at most one delegate OR revoke per block for this /// (address(this), delegate, contractAddress) tuple to avoid racey /// state updates. /// Reverts with an {IACL-AlreadyDelegatedOrRevokedInSameBlock} error /// if a delegate OR revoke operation already occurred in the current /// block. /// /// - An active delegation must exist for the (delegate, contractAddress) /// context. /// Reverts with an {IACL-NotDelegatedYet} error otherwise. function revokeUserDecryptionDelegation(address delegate, address contractAddress) internal { Impl.revokeDelegationForUserDecryption(delegate, contractAddress); } /// @notice Batch revoke existing delegations from delegator `address(this)` to the given /// (delegate, contractAddresses[i]) pairs. /// @param delegate The account that was authorized to request user decryptions on behalf of the caller contract `address(this)` /// @param contractAddresses The array of contract addresses that form the user decryption context tuples /// (`address(this)`, `contractAddresses[i]`). function revokeUserDecryptionDelegations(address delegate, address[] memory contractAddresses) internal { Impl.revokeDelegationsForUserDecryption(delegate, contractAddresses); } /// @notice Get the expiry date of the delegation from delegator to a (delegate, contractAddress) pair. /// @param delegator The delegator address /// @param delegate The account authorized to request user decryptions on behalf of delegator /// @param contractAddress The address of the contract that is part of the user decryption context /// @return expirationDate The delegation's expiration limit, which can be one of: /// - 0 : If no delegation is currently active for the (delegate, contractAddress) context. /// - type(uint64).max : If the delegation is permanent (no expiry). /// - A strictly positive UNIX timestamp when this delegation expires. function getDelegatedUserDecryptionExpirationDate( address delegator, address delegate, address contractAddress ) internal view returns (uint64 expirationDate) { expirationDate = Impl.getUserDecryptionDelegationExpirationDate(delegator, delegate, contractAddress); } /// @notice Reverts if the KMS signatures verification against the provided handles and public decryption data /// fails. /// @dev The function MUST be called inside a public decryption callback function of a dApp contract /// to verify the signatures and prevent fake decryption results for being submitted. /// @param handlesList The list of handles as an array of bytes32 to check /// @param abiEncodedCleartexts The ABI-encoded list of decrypted values associated with each handle in the `handlesList`. /// The ABI-encoded list order must match the `handlesList` order. /// @param decryptionProof The KMS public decryption proof. It includes the KMS signatures, associated metadata, /// and the context needed for verification. /// @dev Reverts if any of the following conditions are met: /// - The `decryptionProof` is empty or has an invalid length. /// - The number of valid signatures is zero or less than the configured KMS signers threshold. /// - Any signature is produced by an address that is not a registered KMS signer. /// - The signatures verification returns false. function checkSignatures( bytes32[] memory handlesList, bytes memory abiEncodedCleartexts, bytes memory decryptionProof ) internal { bool isVerified = _verifySignatures(handlesList, abiEncodedCleartexts, decryptionProof); if (!isVerified) { revert InvalidKMSSignatures(); } emit PublicDecryptionVerified(handlesList, abiEncodedCleartexts); } /// @notice Returns false or reverts if the KMS signatures verification against the provided handles and public decryption data /// fails. Returns true only if KMS signatures verification pass. This is the `view` variant of `checkSignatures`. /// @dev **WARNING**: Prefer using `checkSignatures` (non-view) over this function whenever possible, for several reasons: /// 1. **Safety** – `checkSignatures` automatically reverts when signatures are invalid, making misuse impossible. /// In contrast, `isPublicDecryptionResultValid` returns a boolean: if the caller forgets to `require` the returned /// value, invalid signatures will silently pass, leaving the contract vulnerable to forged decryption results. /// 2. **Front-end integration** – `checkSignatures` emits a `PublicDecryptionVerified` event upon successful /// verification, which is critical for front-end applications that need to detect when a public decrypt result /// has been verified on-chain. This view function does not emit any event. /// 3. **Gas efficiency** – `checkSignatures` leverages a transient-storage mapping to cache verification results, /// making decryption result verification cheaper. /// Use this view variant only when you explicitly need a read-only call (e.g. off-chain simulation or static call). /// @param handlesList The list of handles as an array of bytes32 to check /// @param abiEncodedCleartexts The ABI-encoded list of decrypted values associated with each handle in the `handlesList`. /// The ABI-encoded list order must match the `handlesList` order. /// @param decryptionProof The KMS public decryption proof. It includes the KMS signatures, associated metadata, /// and the context needed for verification. /// @dev Reverts if any of the following conditions are met: /// - The `decryptionProof` is empty or has an invalid length. /// - The number of valid signatures is zero or less than the configured KMS signers threshold. /// - Any signature is produced by an address that is not a registered KMS signer. /// @dev Returns false if there are enough signatures to reach threshold, but some recovered signer is duplicated. /// @return true if the signatures verification succeeds, false or reverts otherwise. function isPublicDecryptionResultValid( bytes32[] memory handlesList, bytes memory abiEncodedCleartexts, bytes memory decryptionProof ) internal view returns (bool) { if (decryptionProof.length == 0) { revert EmptyDecryptionProof(); } /// @dev The decryptionProof is the numSigners + kmsSignatures + extraData (1 + 65*numSigners + extraData bytes) uint256 numSigners = uint256(uint8(decryptionProof[0])); /// @dev The extraData is the rest of the decryptionProof bytes after the numSigners + signatures. uint256 extraDataOffset = 1 + 65 * numSigners; /// @dev Check that the decryptionProof is long enough to contain at least the numSigners + kmsSignatures. if (decryptionProof.length < extraDataOffset) { revert DeserializingDecryptionProofFail(); } bytes[] memory signatures = new bytes[](numSigners); for (uint256 j = 0; j < numSigners; j++) { signatures[j] = new bytes(65); for (uint256 i = 0; i < 65; i++) { signatures[j][i] = decryptionProof[1 + 65 * j + i]; } } /// @dev Extract the extraData from the decryptionProof. uint256 extraDataSize = decryptionProof.length - extraDataOffset; bytes memory extraData = new bytes(extraDataSize); for (uint i = 0; i < extraDataSize; i++) { extraData[i] = decryptionProof[extraDataOffset + i]; } bytes32 digest = _hashDecryptionResult(handlesList, abiEncodedCleartexts, extraData); return _verifySignaturesDigest(digest, signatures, extraData); } /* * @notice Hashes the decryption result. * @param ctHandles The list of handles as an array of bytes32 to check. * @param decryptedResult ABI-encoded list of decrypted values * @param extraData Extra data. * @return hashTypedData Hash typed data. */ function _hashDecryptionResult( bytes32[] memory ctHandles, bytes memory decryptedResult, bytes memory extraData ) private view returns (bytes32) { CoprocessorConfig storage $ = Impl.getCoprocessorConfig(); ( , string memory name, string memory version, uint256 gatewayCahinId, address verifyingContract, , ) = IKMSVerifier($.KMSVerifierAddress).eip712Domain(); bytes32 domainHash = keccak256( abi.encode( EIP712_DOMAIN_TYPEHASH, keccak256(bytes(name)), keccak256(bytes(version)), gatewayCahinId, verifyingContract ) ); bytes32 structHash = keccak256( abi.encode( DECRYPTION_RESULT_TYPEHASH, keccak256(abi.encodePacked(ctHandles)), keccak256(decryptedResult), keccak256(abi.encodePacked(extraData)) ) ); bytes32 typedDataHash; assembly ("memory-safe") { let ptr := mload(0x40) mstore(ptr, hex"19_01") mstore(add(ptr, 0x02), domainHash) mstore(add(ptr, 0x22), structHash) typedDataHash := keccak256(ptr, 0x42) } return typedDataHash; } /** * @notice View function that verifies multiple signatures for a given message using context-aware verification. * @dev Delegates extraData parsing and context lookup to KMSVerifier via a single * cross-contract call to `getContextSignersAndThresholdFromExtraData`. * @param digest The hash of the message that was signed by all signers. * @param signatures An array of signatures to verify. * @param extraData The extra data bytes from the decryption proof, used to resolve the KMS context. * @return isVerified true if enough provided signatures are valid, false otherwise. */ function _verifySignaturesDigest( bytes32 digest, bytes[] memory signatures, bytes memory extraData ) private view returns (bool) { uint256 numSignatures = signatures.length; if (numSignatures == 0) { revert KMSZeroSignature(); } CoprocessorConfig storage $ = Impl.getCoprocessorConfig(); (address[] memory KMSSigners, uint256 threshold) = IKMSVerifier($.KMSVerifierAddress) .getContextSignersAndThresholdFromExtraData(extraData); if (numSignatures < threshold) { revert KMSSignatureThresholdNotReached(numSignatures); } address[] memory recoveredSigners = new address[](numSignatures); uint256 uniqueValidCount; for (uint256 i = 0; i < numSignatures; i++) { address signerRecovered = FhevmECDSA.recover(digest, signatures[i]); if (!_isSigner(signerRecovered, KMSSigners)) { revert KMSInvalidSigner(signerRecovered); } if (!_isSigner(signerRecovered, recoveredSigners)) { recoveredSigners[uniqueValidCount] = signerRecovered; uniqueValidCount++; } if (uniqueValidCount >= threshold) { return true; } } return false; } /** * @notice Checks whether a given address is present in an array of signers. * @param signer The address to look for. * @param signersArray The array of signer addresses to search. * @return isSigner true if the address is found, false otherwise. */ function _isSigner(address signer, address[] memory signersArray) private pure returns (bool) { uint256 signersArrayLength = signersArray.length; for (uint256 i = 0; i < signersArrayLength; i++) { if (signer == signersArray[i]) { return true; } } return false; } /** * @notice Recovers the signer's address from a `signature` and a `message` digest. * @dev It utilizes ECDSA for actual address recovery. It does not support contract signature (EIP-1271). * @param message The hash of the message that was signed. * @param signature The signature to verify. * @return signer The address that supposedly signed the message. */ function _recoverSigner(bytes32 message, bytes memory signature) private pure returns (address) { address signerRecovered = FhevmECDSA.recover(message, signature); return signerRecovered; } /// @notice Verifies KMS signatures against the provided handles and public decryption data. /// @param handlesList The list of handles as an array of bytes32 to verify /// @param abiEncodedCleartexts The ABI-encoded list of decrypted values associated with each handle in the `handlesList`. /// The list order must match the list of handles in `handlesList` /// @param decryptionProof The KMS public decryption proof computed by the KMS Signers associated to `handlesList` and /// `abiEncodedCleartexts` /// @return true if the signatures verification succeeds, false otherwise /// @dev Private low-level function used to verify the KMS signatures. /// The decryptionProof is the numSigners + kmsSignatures + extraData (1 + 65*numSigners + extraData bytes) /// Only static native solidity types for clear values are supported, so `abiEncodedCleartexts` is the concatenation of all clear values appended to 32 bytes. /// @dev Reverts if any of the following conditions are met by the underlying KMS verifier: /// - The `decryptionProof` is empty or has an invalid length. /// - The number of valid signatures is zero or less than the configured KMS signers threshold. /// - Any signature is produced by an address that is not a registered KMS signer. function _verifySignatures( bytes32[] memory handlesList, bytes memory abiEncodedCleartexts, bytes memory decryptionProof ) private returns (bool) { CoprocessorConfig storage $ = Impl.getCoprocessorConfig(); return IKMSVerifier($.KMSVerifierAddress).verifyDecryptionEIP712KMSSignatures( handlesList, abiEncodedCleartexts, decryptionProof ); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(ebool value) internal pure returns (bytes32 ct) { ct = ebool.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(euint8 value) internal pure returns (bytes32 ct) { ct = euint8.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(euint16 value) internal pure returns (bytes32 ct) { ct = euint16.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(euint32 value) internal pure returns (bytes32 ct) { ct = euint32.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(euint64 value) internal pure returns (bytes32 ct) { ct = euint64.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(euint128 value) internal pure returns (bytes32 ct) { ct = euint128.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(eaddress value) internal pure returns (bytes32 ct) { ct = eaddress.unwrap(value); } /** * @dev Converts handle from its custom type to the underlying bytes32. Used when requesting a decryption. */ function toBytes32(euint256 value) internal pure returns (bytes32 ct) { ct = euint256.unwrap(value); } }