TFHE Library

The TFHE functions can be used on encrypted data inside fhEVM. For instance, you could add 2 encrypted states together with TFHE.add(encryptedValue1, encryptedValue2).

To access all the TFHE functions, you can just import the library at the beginning of your solidity code:

pragma solidity ^0.8.20;

import "fhevm/lib/TFHE.sol";

We recommend to use the same solidity version (for example v0.8.24) throughout your whole project, unless you are using Foundry that can work with multiple solidity versions. In Remix you might want to stick to v0.8.24.

Here's the list of operations:

NameFunctionOperatorType

Addition

TFHE.add

+

Binary

Subtraction

TFHE.sub

-

Binary

Multiplication

TFHE.mul

*

Binary

Division

TFHE.div

NA

Binary

Remainder

TFHE.rem

NA

Binary

BitAnd

TFHE.and

&

Binary

BitOr

TFHE.or

|

Binary

BitXor

TFHE.xor

^

Binary

Shift Right

TFHE.shr

NA

Binary

Shift Left

TFHE.shl

NA

Binary

And the list of comparisons:

NameFunctionOperatorType

Equal

TFHE.eq

NA

Binary

Not equal

TFHE.ne

NA

Binary

Greater than or equal

TFHE.ge

NA

Binary

Greater than

TFHE.gt

NA

Binary

Less than or equal

TFHE.le

NA

Binary

Less than

TFHE.lt

NA

Binary

Min

TFHE.min

NA

Binary

Max

TFHE.max

NA

Binary

Neg

TFHE.neg

-

Unary

Not

TFHE.not

~

Unary

The library has a limited support for operator overloading, so far only +, -, *, &, |, ^, -, ~ are supported for all encrypted types.

More information about the supported operations can be found on the Rust FHE library from Zama: TFHE-rs

Last updated