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.24;

import "fhevm/lib/TFHE.sol";

You need to strictly use Solidity version 0.8.24 in your contracts.

Here's the list of operations:

Name
Function
Operator
Type

Addition

TFHE.add

+

Binary

Subtraction

TFHE.sub

-

Binary

Multiplication

TFHE.mul

*

Binary

Division (over plaintext denominator)

TFHE.div

NA

Binary

Remainder (over plaintext denominator)

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

Rotate Right

TFHE.rotr

NA

Binary

Rotate Left

TFHE.rotl

NA

Binary

Supported Comparison Operations:

Name
Function
Operator
Type

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 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