Zero-overhead Rust toolkit for building, encrypting & evaluating fully homomorphic (FHE) circuits
Encircuit is a high-level Rust library for building and evaluating Boolean circuits using fully homomorphic encryption (FHE). It provides a clean, ergonomic API for constructing circuits, encrypting inputs, and performing computations on encrypted data without ever decrypting intermediate values.
Architecture: Encircuit focuses on Boolean circuits with an extensible trait-based architecture. While currently Boolean-only, the foundation supports future integer types through feature flags without breaking changes.
- 🛠️ Circuit Builder: Intuitive API for constructing Boolean circuits
- 🔒 FHE Integration: Built on top of the TFHE library for secure computation
- ⚡ Zero-Overhead: Efficient circuit representation and evaluation
- 🔧 Flexible Parameters: Configurable security levels and operation types
- 📦 Modular Design: Optional features for different use cases
- 🎯 Type Safety: Rust's type system ensures correctness at compile time
- 🚀 Extensible Architecture: Trait-based design enables future integer support
Add to your Cargo.toml:
[dependencies]
encircuit = "0.0.1-alpha.0"use encircuit::prelude::*;
// Generate parameters and keys
let params = Params::for_scenario(Scenario::SafeAndBalanced)?;
let keyset = Keyset::generate(¶ms)?;
let (client_key, server_key) = keyset.split();
// Build a circuit: (¬y ∧ x) ∨ (x ∧ y)
let mut builder = CircuitBuilder::default();
let x = builder.input();
let y = builder.input();
let not_y = builder.not(y);
let and1 = builder.and(not_y, x);
let and2 = builder.and(x, y);
let output = builder.or(and1, and2);
let circuit = builder.finish(output);
// Encrypt inputs and evaluate
let encrypted = circuit.encrypt_inputs(&[true, false], &client_key)?;
let result = encrypted.evaluate(&server_key);
let decrypted = result[0].decrypt(&client_key)?;
assert_eq!(decrypted, true); // (¬false ∧ true) ∨ (true ∧ false) = trueencircuit/
├── Cargo.toml # Workspace root
├── encircuit/ # Core library
│ ├── src/
│ │ ├── lib.rs # Public API
│ │ ├── prelude.rs # Convenient imports
│ │ ├── params.rs # Parameter configuration
│ │ ├── keys.rs # Key management
│ │ ├── ciphertext.rs # Ciphertext types
│ │ └── circuit/ # Circuit building & evaluation
│ └── Cargo.toml
└── encircuit_macros/ # Procedural macros (optional)
├── src/lib.rs
└── Cargo.toml
| Feature | Default | Description |
|---|---|---|
boolean |
✅ | Boolean FHE operations |
parallel |
✅ | Parallel encryption using Rayon |
serde |
✅ | Serialization support |
macros |
❌ | Procedural macro support |
integer8 |
❌ | (future) 8-bit integer ciphertext support |
integer32 |
❌ | (future) 32-bit integer ciphertext support |
🚧 Alpha Version - This library is currently in early development.
Implemented:
- ✅ Circuit builder API
- ✅ Type-safe circuit representation
- ✅ Parameter configuration
- ✅ Key management structures
- ✅ Ciphertext abstractions with production-ready serialization
- ✅ Comprehensive test suite
TODO:
- 🔄
circuit!procedural macro implementation - 🔄 Performance optimizations
- 🔄 Documentation improvements
Contributions are welcome! Please see our contribution guidelines for details.
- Run
rustfmtandclippy --all-targets - Ensure no
unsafecode without thorough review - Add tests for new functionality
- Update documentation
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
| Milestone | Focus | Goal |
|---|---|---|
| M1 | Core FHE | Boolean TFHE integration (< 100 µs circuits) |
| M2 | Macros | circuit! procedural macro |
| M3 | DSL | Text/JSON → Circuit parser |
| M4 | Runtime | gRPC/HTTP circuit evaluation service |
| M5 | Extended Types | Integer ciphertext types (Int8Ct, Int32Ct via feature flags) |
| M6 | Performance | GPU acceleration |