Skip to main content
The FHE library provides functions for working with Fully Homomorphic Encryption (FHE) in Solidity smart contracts. It enables computations on encrypted data without decrypting it, ensuring privacy throughout your contract’s execution.

Import

import '@fhenixprotocol/cofhe-contracts/FHE.sol';
All functions are prefixed with FHE. when called. For example: FHE.add(a, b) or FHE.allowPublic(value).

Encrypted Data Types

TypeDescription
eboolEncrypted boolean value
euint8Encrypted 8-bit unsigned integer
euint16Encrypted 16-bit unsigned integer
euint32Encrypted 32-bit unsigned integer
euint64Encrypted 64-bit unsigned integer
euint128Encrypted 128-bit unsigned integer
eaddressEncrypted Ethereum address

Input Types

Each encrypted type has a corresponding input struct used when receiving encrypted data from the client SDK:
Input TypeEncrypted Type
InEboolebool
InEuint8euint8
InEuint16euint16
InEuint32euint32
InEuint64euint64
InEuint128euint128
InEaddresseaddress

Security Considerations

  1. Initialization: All FHE functions check if their inputs are initialized and set them to 0 if not.
  2. Decryption: Decryption is a two-phase process — mark values with allowPublic on-chain, decrypt off-chain via the Client SDK, then publish/verify the result with publishDecryptResult or verifyDecryptResult. Only reveal values when absolutely necessary.
  3. Security Zones: Some functions accept a securityZone parameter to isolate different encrypted computations. FHE operations can only be performed between ciphertexts that share the same security zone.
  4. Access Control: The library provides fine-grained access control through the allow* functions. Always set proper permissions before accessing encrypted values.
  5. Type Safety: Ensure encrypted values use compatible types when performing operations. Type mismatches will cause errors.