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-arithc
Go to the circom-2-arithc submodule directory:
cd circom-2-arithc
Initialize the .env file:
touch .env
vim .env
Build the compiler:
cargo build --release
We have two examples available:
- ops_tests - a benchmark of supported operations
- naive_search - a benchmark of naive search
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_circuit
tfhe-rs program
You can run these examples by following the instructions in the root directory.
# Go back to the root directory of circom-tfhe-rs
cd ../circom-tfhe-rs
mkdir outputs
#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_tests
ornaive_search
.- Intermediate files will be stored in the
outputs/{circuit_name}
directory. - Outputs are directly printed to the console.
-
Generate Rust directory in the
outputs
folder;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.toml
in each Rust directory. -
For existing circom circuit, run circom-2-arithc.
-
Run python script in
examples/{circuit_name}/
- It generates
raw_circuit
tfhe-rs code,input.json
- After generating
input.json
, make a new fileinput_struct.json
which has different format. - After generating
raw_circuit
tfhe-rs code, copy it intooutputs/{circuit_name}_raw
- Copy
input.json
andinput_struct.json
inoutputs/{circuit_name}
andoutputs/{circuit_name}_raw
- It generates
-
Using bristol fashion circuit, generate tfhe-rs code.
-
Run converted tfhe-rs code, and compare it with model tfhe-rs code.
- It initially 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)