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
| Type | Description |
|---|
ebool | Encrypted boolean value |
euint8 | Encrypted 8-bit unsigned integer |
euint16 | Encrypted 16-bit unsigned integer |
euint32 | Encrypted 32-bit unsigned integer |
euint64 | Encrypted 64-bit unsigned integer |
euint128 | Encrypted 128-bit unsigned integer |
eaddress | Encrypted Ethereum address |
Each encrypted type has a corresponding input struct used when receiving encrypted data from the client SDK:
| Input Type | Encrypted Type |
|---|
InEbool | ebool |
InEuint8 | euint8 |
InEuint16 | euint16 |
InEuint32 | euint32 |
InEuint64 | euint64 |
InEuint128 | euint128 |
InEaddress | eaddress |
Security Considerations
-
Initialization: All FHE functions check if their inputs are initialized and set them to 0 if not.
-
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.
-
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.
-
Access Control: The library provides fine-grained access control through the
allow* functions. Always set proper permissions before accessing encrypted values.
-
Type Safety: Ensure encrypted values use compatible types when performing operations. Type mismatches will cause errors.