How to modify the source code of tfhe and applicate it on concrete

I know that tfhe’s C++ source code library can be directly modified and then compiled to generate a dynamic library. So how to modify the source code in concrete-ml and then compile and run it?

Hello @rsynn,

I am not sure to understand your question, what do you want to do with Concrete ML?

I want to know if using concrete ml can only use the functions of tfhe that you have encapsulated, such as bootstrapping, or can we modify the source code, recompile, and use it on concrete ml?

Maybe you can give an example of a specific modification you’ll want to do. I am assuming you want to plug your own implementation of some operator (e.g. a TLU) or a completely different crypto backend.

TL;DR There is no easy way to do that.

Concrete ML use Concrete Python, which generates MLIR code, that is compiled by the Concrete Compiler. The generated MLIR code is very specific to the Concrete Compiler and tfhe.

The first thing you can do is to look at this MLIR code to have a better idea of what it looks like. (save the circuit using the via_mlir option)

But even if you could generate a different MLIR before giving it to the Concrete Compiler, the latter will reject it for non authorized construction (for example if you replace a tlu call by a call on an external library).

So in any case you’ll have to do some changes directly in the Concrete Compiler. (In Cpp using MLIR framework).


I want to plug my own implementation of some operator such as lut, change some operator of gate bootstrapping.

I want to change the testvector of blind rotation of gate bootstrapping and apply it on concrete-ml. Can this be achieved?

I want to plug my own implementation of some operator such as lut, change some operator of gate bootstrapping.

Sorry for the late reply. I really want to know if bootstrapping can be used in concrete-ml.

BS are already used by Concrete ML and Concrete Python: each time there is a table lookup, under the hood, it’s replaced by a BS. When you compile, you can activate show_mlir=True, and you will see the MLIR: and then, you’ll see some lines like

%7 = "FHELinalg.apply_mapped_lookup_table"(%collapsed, %cst_6, %cst_5) : (tensor<240x1x!FHE.esint<5>>, tensor<10x32xi64>, tensor<240x1xindex>) -> tensor<240x1x!FHE.eint<6>>

and FHELinalg.apply_mapped_lookup_table is the MLIR operation which will be replaced by a PBS during the compilation

If you want to experiment, it will be easier for you to have a look to TFHE-rs, since there, you have access to low-level operators