Circom-tfhe-rs enables users to generate a TFHE circuit that corresponds to the arithmetization of a Circom circuit. In simpler terms, it translates Circom circuits into their TFHE equivalents. Circom code is compiled into an arithmetic circuit using circom-2-arithc and then translated gate by gate to the corresponding tfhe-rs operators.
NOTE: Now circom-2-arithc also conveniently outputs the Bristol format with corresponding circuit_info (hence the json_arbistol is not necessary anymore).
| Op | FheUint | FheInt |
|---|---|---|
+ Addition |
✅ | ✅ |
/ Division |
✅ | ✅ |
== Equality |
✅ | ✅ |
> Greater Than |
✅ | ✅ |
>= Greater Than or Equal |
✅ | ✅ |
< Less Than |
✅ | ✅ |
<= Less Than or Equal |
✅ | ✅ |
* Multiplication |
✅ | ✅ |
!= Not Equal |
✅ | ✅ |
- Subtraction |
✅ | ✅ |
** Exponentiation |
❌ | ❌ |
<< Shift Left |
✅ | ❌ |
>> Shift Right |
✅ | ❌ |
^ Bitwise XOR |
✅ | ✅ |
| Bitwise OR |
✅ | ✅ |
& Bitwise AND |
✅ | ✅ |
% Modulo |
✅ | ✅ |
- circom-2-arithc - we are using the latest version.
- tfhe-rs - supports the arithmetization on tfhe
- main.py - the main script to run the circom-tfhe. It does the following:
- Compiles the Circom code to the arithmetic circuit with
circom-2-arithc. - Generates tfhe-rs program by converting bristol fashion circuit.
- Performs the computation using tfhe-rs.
- Compiles the Circom code to the arithmetic circuit with
- examples - example circuits to run with circom-tfhe.
git clone https://github.com/Vishalkulkarni45/circom-tfhe-rs
git clone https://github.com/namnc/circom-2-arithcGo to the circom-2-arithc submodule directory:
cd circom-2-arithcInitialize the .env file:
touch .env
vim .envBuild the compiler:
cargo build --releaseWe have two examples available:
- ops_tests - a benchmark of supported operations
- naive_search - a benchmark of naive search
For both the examples ,We successfully executed them for FheUint8, FheUint16, and FheUint64 on a 4-core machine with 16GB of RAM, but encountered memory limitations when attempting FheUint128.
In both examples, you will find the following files in each example directory:
circuit.circom- the circom code representing the circuit{circuit_name}.py- automated generator for input files andraw_circuittfhe-rs program
You can run these examples by following the instructions in the root directory.
#Before running this you need to change the raw tfhe code plain and cipher text data type manunal
python main.py {circuit_name} {plain_text_data_type} {circuit_name}is the name of the circuit you want to run. Can either beops_testsornaive_search.- Intermediate files will be stored in the
outputs/{circuit_name}directory. - Outputs are directly printed to the console.
-
Generate Rust directory in the
outputsfolder;outputs/{circuit_name}andoutputs/{circuit_name}_raw- If the directory exists, it deletes the directory and makes new directory.
-
Add the necessary dependencies in
Cargo.tomlin each Rust directory. -
For existing circom circuit, run circom-2-arithc.
-
Run python script in
examples/{circuit_name}/- It generates
raw_circuittfhe-rs code,input.json - After generating
input.json, make a new fileinput_struct.jsonwhich has different format. - After generating
raw_circuittfhe-rs code, copy it intooutputs/{circuit_name}_raw - Copy
input.jsonandinput_struct.jsoninoutputs/{circuit_name}andoutputs/{circuit_name}_raw
- It generates
-
Using bristol fashion circuit, generate tfhe-rs code.
- It divides the operation into two folder: client and server.
- Client code is responside for encrypting the inputs and decrypting the output
- Server code handles performing operations on the encrypted inputs.
-
Run converted tfhe-rs code, and compare it with model tfhe-rs code.
- It compares the output of the generated TFHE circuit with that of the manually created TFHE circuit.
- It also compares the output of the generated TFHE circuit with the functionality executed using unencrypted methods (via native Rust , which is present in circuit_name_raw folder)