Skip to main content

Overview

The CoFHE library is a Solidity framework that enables secure, private computation on encrypted data within smart contracts. This library allows developers to perform operations on encrypted values without revealing the underlying plaintext data, preserving privacy while maintaining the transparency and trustlessness of blockchain technology.

Core Components

The FHE library consists of the following key components:

1. Encrypted Data Types

The library supports multiple encrypted data types, each representing an encrypted version of a standard Solidity type:
TypeDescriptionPlaintext Equivalent
eboolEncrypted boolean valuebool
euint8Encrypted 8-bit unsigned integeruint8
euint16Encrypted 16-bit unsigned integeruint16
euint32Encrypted 32-bit unsigned integeruint32
euint64Encrypted 64-bit unsigned integeruint64
euint128Encrypted 128-bit unsigned integeruint128
eaddressEncrypted Ethereum addressaddress

2. Encrypted Input Structures

ICofhe.sol defines various input structures that enable secure data submission:
  • EncryptedInput: The core structure containing:
    • Ciphertext hash: A unique hash representing the encrypted data, used to reference it across the system.
    • Security zone parameter: Defines the trust context or boundary in which the encrypted data is valid and accessible.
    • Type indicator: Specifies the data type of the encrypted value (e.g. euint8, euint16) to ensure correct handling.
    • Cryptographic signature: A signature proving that the data and its metadata were generated and verified by an authorized entity.
  • Type-specific input structures:
    • InEuint8, InEuint16, InEuint32
    • InEuint64, InEuint128
    • InEbool, InEaddress

3. Core Functionality (FHE.sol)

The FHE library provides a comprehensive set of operations for encrypted data manipulation:

1. Arithmetic Operations

Enables basic math (FHE.add) directly on encrypted integers.

2. Bitwise Operations

Supports bitwise logic (AND, OR, XOR, shifts) on encrypted data.

3. Comparison Operations

Performs encrypted comparisons (eq, gt, lt, etc.) that return an eboolan encrypted boolean value that contains the result of the comparison.

4. Control Flow

Includes conditionals like select to allowing encrypted branching without revealing decision paths.

5. Data and Access Management

Provides functions for sealing outputs, decrypting values securely, and managing user access via permits, ensuring only authorized parties can access decrypted data.

4. Task Management

The library interacts with a TaskManager contract that coordinates:
  • Execution of FHE operations
  • Access control for encrypted data
  • Decryption request processing