• Stars
    star
    860
  • Rank 53,022 (Top 2 %)
  • Language
    Rust
  • License
    Other
  • Created about 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TFHE-rs: A Pure Rust implementation of the TFHE Scheme for Boolean and Integer Arithmetics Over Encrypted Data.


📒 Read documentation | 💛 Community support


TFHE-rs is a pure Rust implementation of TFHE for boolean and integer arithmetics over encrypted data. It includes:

  • a Rust API
  • a C API
  • and a client-side WASM API

TFHE-rs is meant for developers and researchers who want full control over what they can do with TFHE, while not having to worry about the low level implementation. The goal is to have a stable, simple, high-performance, and production-ready library for all the advanced features of TFHE.

Getting Started

The steps to run a first example are described below.

Cargo.toml configuration

To use the latest version of TFHE-rs in your project, you first need to add it as a dependency in your Cargo.toml:

  • For x86_64-based machines running Unix-like OSes:
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64-unix"] }
  • For Apple Silicon or aarch64-based machines running Unix-like OSes:
tfhe = { version = "*", features = ["boolean", "shortint", "integer", "aarch64-unix"] }

Note: users with ARM devices must use TFHE-rs by compiling using the nightly toolchain.

tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] }

Note: aarch64-based machines are not yet supported for Windows as it's currently missing an entropy source to be able to seed the CSPRNGs used in TFHE-rs

A simple example

Here is a full example:

use tfhe::prelude::*;
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint32, FheUint8};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Basic configuration to use homomorphic integers
    let config = ConfigBuilder::all_disabled()
        .enable_default_integers()
        .build();

    // Key generation
    let (client_key, server_keys) = generate_keys(config);

    let clear_a = 1344u32;
    let clear_b = 5u32;
    let clear_c = 7u8;

    // Encrypting the input data using the (private) client_key
    // FheUint32: Encrypted equivalent to u32
    let mut encrypted_a = FheUint32::try_encrypt(clear_a, &client_key)?;
    let encrypted_b = FheUint32::try_encrypt(clear_b, &client_key)?;

    // FheUint8: Encrypted equivalent to u8
    let encrypted_c = FheUint8::try_encrypt(clear_c, &client_key)?;

    // On the server side:
    set_server_key(server_keys);

    // Clear equivalent computations: 1344 * 8 = 10752
    let encrypted_res_mul = &encrypted_a * &encrypted_b;

    // Clear equivalent computations: 1344 >> 8 = 42
    encrypted_a = &encrypted_res_mul >> &encrypted_b;

    // Clear equivalent computations: let casted_a = a as u8;
    let casted_a: FheUint8 = encrypted_a.cast_into();

    // Clear equivalent computations: min(42, 7) = 7
    let encrypted_res_min = &casted_a.min(&encrypted_c);

    // Operation between clear and encrypted data:
    // Clear equivalent computations: 7 & 1 = 1
    let encrypted_res = encrypted_res_min & 1_u8;

    // Decrypting on the client side:
    let clear_res: u8 = encrypted_res.decrypt(&client_key);
    assert_eq!(clear_res, 1_u8);

    Ok(())
}

To run this code, use the following command:

cargo run --release

Note that when running code that uses tfhe-rs, it is highly recommended to run in release mode with cargo's --release flag to have the best performances possible,

Contributing

There are two ways to contribute to TFHE-rs:

  • you can open issues to report bugs or typos, or to suggest new ideas
  • you can ask to become an official contributor by emailing [email protected]. (becoming an approved contributor involves signing our Contributor License Agreement (CLA))

Only approved contributors can send pull requests, so please make sure to get in touch before you do!

Credits

This library uses several dependencies and we would like to thank the contributors of those libraries.

Need support?

Citing TFHE-rs

To cite TFHE-rs in academic papers, please use the following entry:

@Misc{TFHE-rs,
  title={{TFHE-rs: A Pure Rust Implementation of the TFHE Scheme for Boolean and Integer Arithmetics Over Encrypted Data}},
  author={Zama},
  year={2022},
  note={\url{https://github.com/zama-ai/tfhe-rs}},
}

License

This software is distributed under the BSD-3-Clause-Clear license. If you have any questions, please contact us at [email protected].

Disclaimers

Security Estimation

Security estimations are done using the Lattice Estimator with red_cost_model = reduction.RC.BDGL16.

When a new update is published in the Lattice Estimator, we update parameters accordingly.

Side-Channel Attacks

Mitigation for side channel attacks have not yet been implemented in TFHE-rs, and will be released in upcoming versions.

More Repositories

1

concrete

Concrete: TFHE Compiler that converts python programs into FHE equivalent
C++
911
star
2

concrete-ml

Concrete ML: Privacy Preserving ML framework using Fully Homomorphic Encryption (FHE), built on top of Concrete, with bindings to traditional ML frameworks.
Python
881
star
3

fhevm

A Solidity library for interacting with an fhEVM blockchain.
TypeScript
387
star
4

bounty-program

Zama Bounty Program: Contribute to the FHE space and Zama's open source libraries and get rewarded 💰
233
star
5

concrete-numpy

Concrete-Numpy: A library to turn programs into their homomorphic equivalent.
Python
219
star
6

awesome-zama

A curated list of amazing Fully Homomorphic Encryption (FHE) resources created by the team at Zama.
204
star
7

concrete-core

Concrete Core contains a set of low-level primitives which can be used to implement Fully Homomorphically Encrypted (FHE) programs.
Rust
73
star
8

fhevm-go

fhevm-go is an open-source library used to easily integrate the fhEVM into an EVM-compatible blockchain.
Go
21
star
9

concrete-fft

Rust
15
star
10

fhevmjs

A dapp SDK for the fhEVM ecosystem
TypeScript
13
star
11

concrete-ntt

Rust
13
star
12

verifiable-fhe-paper

Verifiable FHE prototype
Rust
13
star
13

hnp-examples

Repository to store hnp usage examples
11
star
14

go-ethereum

fhEVM reference implementation
Go
8
star
15

demo_z8z

Demo using Concrete library to implement exact homomorphic computation with 3-bit integers
Rust
8
star
16

fhevm-decryptions-db

The fhEVM Decryptions Database is a key-value database of decryption results.
Rust
8
star
17

fhe-tutorials

Jupyter Notebook
8
star
18

evmos

Go
7
star
19

fhe-biometrics

Jupyter Notebook
7
star
20

fhevm-hardhat-template

fhEVM hardhat template
TypeScript
6
star
21

fhe_game_of_life

Rust
6
star
22

fhevm-tfhe-cli

TFHE-rs CLI tool for the fhEVM
Rust
4
star
23

ethcc23-workshop

Python
4
star
24

concrete-fftw

C
4
star
25

fhevm-L1-demo

Shell
4
star
26

fhevmjs-react-template

TypeScript
3
star
27

concrete-compiler-internal-llvm-project

Internal fork of llvm-project for concrete-compiler-internal
2
star
28

concrete-example-client-server

Rust
2
star
29

ethermint

A component of the fhEVM stack. Fork of the original ethermint repository.
Go
1
star
30

.github

1
star
31

fhevmjs-vue-template

Vue
1
star