Manuscript Offprint
arXiv:2610.29983Free-XOR TFHE via Lazy Bootstrapping
Abstract
Gate bootstrapping (GB) is a widely used technique in FHEW-like fully homomorphic encryption schemes, such as TFHE, for evaluating Boolean gates while simultaneously reducing the noise of the resulting ciphertext. However, the computational cost of GB is typically dominated by an expensive blind rotation (BR). [7] proposed a gate bootstrapping framework in which XOR gates can be evaluated simply by adding the two input ciphertexts, resulting in what they call free-XOR. To obtain a functionally complete set of operations, they further designed a GB procedure for evaluating AND gates using two lightweight blind rotations. In this work, we propose a similar gate bootstrapping framework that supports free evaluation of XOR gates while evaluating all symmetric binary Boolean gates, i.e., the 8 gates whose output is identical for the inputs (0, 1) and (1, 0), using two blind rotations. In addition to providing broader gate support, our construction is substantially simpler than that of [7], both conceptually and in terms of implementation.
CCS Concepts: • Software and its engineering → Software organization and properties.
Keywords: Fully Homomorphic Encryption, Gate Bootstrapping, Free-XOR, TFHE
1 Introduction
Fully homomorphic encryption (FHE) allows computation directly on encrypted data without decrypting it. Among FHE schemes, TFHE [11] is widely used for Boolean circuits. In the conventional TFHE approach, each bit is encrypted independently as an LWE ciphertext, and each gate is evaluated through programmable bootstrapping (PBS), which computes a function on the encrypted value while refreshing the ciphertext to control noise accumulation. PBS is one of the most expensive operations in TFHE, so the cost of evaluating a circuit is strongly influenced by the number of bootstrappings it requires.
In conventional TFHE, every gate, including XOR gates, is evaluated via PBS. Chen et al. [7] proposed an approach called free-XOR, which allows XOR gates to be evaluated without PBS. This is possible because XOR corresponds to addition modulo 2, which can be implemented directly using lightweight homomorphic addition. Therefore, circuits containing many XOR gates, such as those arising in symmetric cryptography and arithmetic, can benefit significantly from this technique.
Osman Biçer
University of Basel
Switzerland
Although achieving free-XOR for circuits consisting only of XOR gates is straightforward, extending the approach to support a complete set of Boolean gates is considerably more challenging. To obtain a functionally complete gate set, Chen et al. [7] proposed an algorithm for evaluating AND gates based on the NTRU hardness assumption, at the cost of two blind rotations.
Our contribution. In this work, we propose a similar gate bootstrapping framework that supports free evaluation of XOR gates while evaluating all symmetric binary Boolean gates, i.e., the 8 gates whose output is identical for the inputs and , using two blind rotations. Our construction is conceptually simpler than that of [7], only based on learning with error (LWE) hardness assumption, making it easier to implement.
Our main ideas are as follows.
- Two-bit encoding with the Free-XOR property. We encode each bit as an element of , with the least significant bit representing the encoded Boolean value. Addition modulo 4 therefore computes the XOR of the underlying bits without requiring a programmable bootstrapping (PBS). The most significant bit acts as a redundant component that can be eliminated through bootstrapping when necessary. As in conventional TFHE constructions, we also reserve a padding bit to support non-negacyclic functions during programmable bootstrapping. Additionally, we introduce headroom into the encoding to accommodate multiple consecutive XOR additions over the integers without carrying into the padding bit. Since the available headroom is bounded and the noise accumulates across successive additions, we periodically estimate headroom consumption and refresh the ciphertext when necessary. We refer to this strategy as lazy bootstrapping.
• Symmetric gate evaluation with two PBS. For two input bits of a symmetric gate, the corresponding truth-table row can be indexed by . Given their two-bit encoded values and , we obtain this index as , where . The function is evaluated homomorphically using one PBS, yielding an encryption of the truth-table index. A second PBS then applies a lookup table representing the gate's truth table to obtain an encryption of the gate output. Thus, any two-input symmetric Boolean gate can be evaluated using two PBSs.
• Headroom analysis and failure probability. We analyze the constraints on the headroom, deriving a lower bound determined by the number of consecutive additions between bootstrappings and an upper bound imposed by modulus-switching noise. We also analyze the resulting failure probability to guide the selection of suitable parameters.
We implemented our approach in Rust using the low-level API of TFHE-rs [21]. As expected, our experimental results show that our framework reduces circuit evaluation time compared with standard TFHE gate bootstrapping when the number of XOR gates significantly exceeds the number of symmetric gates. This improvement stems from evaluating XOR gates without programmable bootstrapping (PBS), whereas each symmetric gate requires two PBS operations. Consequently, our approach is particularly beneficial for circuits in which XOR gates dominate the gate composition.
Organization. Section 2 reviews the necessary background, including LWE and GLWE encryption, programmable bootstrapping, and TFHE for Boolean circuits. Section 3 presents our free-XOR framework, including the noise analysis. Section 4 describes our implementation and experimental results. Finally, Section 5 summarizes our work.
Notations. When an integer encodes the Boolean value false, we denote it by . Similarly, when encodes true, we denote it by . We denote polynomials by uppercase letters, whereas represents the indeterminate in polynomial expressions. Given a polynomial , we denote by its coefficient of the monomial . Vectors are denoted by bold characters, whereas scalars are written in non-bold characters. We use to denote sampling from a distribution or a set . When is a set, the sampling is assumed to be uniform.
We denote the polynomial ring by . The expectation of a random variable is denoted by . A random variable following a Gaussian distribution with mean and variance is denoted by . For a standard Gaussian random variable , we have
where, erfc stands for complementary error function, defined as , and erf is the error function defined by
We use to denote rounding to the nearest integer. The inner (dot) product of two vectors a and b is denoted by .
2.1 FHE
Fully homomorphic encryption (FHE), often regarded as a long-standing goal of modern cryptography, is a framework in which a function can be evaluated directly on a ciphertext encrypting a message , producing a ciphertext that decrypts to . The notion of computing on encrypted data was originally introduced as privacy homomorphism by Rivest, Adleman, and Dertouzos in 1978 [18], while the first construction supporting arbitrary-depth computation was given by Gentry nearly three decades later [14]. Before Gentry’s construction, several homomorphic encryption schemes supported restricted classes of computations. For example, RSA [19] and ElGamal [13] support a single homomorphic operation and are therefore referred to as partially homomorphic encryption (PHE). Other schemes, such as BGN [4], support both addition and multiplication, but only for circuits with a bounded multiplicative depth; these are commonly referred to as somewhat homomorphic encryption (SHE). Surveys of homomorphic encryption and its different categories can be found in [1, 16].
A fundamental limitation of early SHE schemes is that homomorphic operations, particularly multiplication, introduce noise into ciphertexts. As this noise accumulates, it eventually exceeds the decryption tolerance, causing decryption to fail. Gentry addressed this limitation by introducing bootstrapping, in which a noisy ciphertext is homomorphically decrypted using an encryption of the secret key, producing a new ciphertext encrypting the same plaintext with reduced noise. By periodically bootstrapping a ciphertext before its noise becomes too large, an encryption scheme can support arbitrarily deep computations and thereby achieve FHE.
An FHE scheme only needs to support a functionally complete set of operations to evaluate arbitrary functions. Based on the type of computation they natively support, FHE schemes can be broadly divided into three categories. First, Boolean FHE schemes, such as TFHE [10] and FHEW [12], operate on Boolean values and evaluate Boolean circuits composed of functionally complete sets of gates, such as NAND alone or the combination of AND and XOR. Second, arithmetic FHE schemes, such as BGV [5] and BFV [6], support modular addition and multiplication over finite rings and are particularly well suited to arithmetic circuits and SIMD-style batched computation. Third, approximate-arithmetic FHE schemes, such as CKKS [8], support arithmetic over approximate representations of real or complex numbers and are designed for applications in which numerical approximation is acceptable, such as statistical and machine-learning computations.
FHE schemes can also be classified according to their key structure as either symmetric-key or public-key schemes. In particular, a symmetric-key FHE scheme can, under suitable constructions, be transformed into a public-key scheme [20].
2.2 TFHE
Fast Fully Homomorphic Encryption over the Torus (TFHE) is a fully homomorphic encryption scheme known for its efficient and fast evaluation of Boolean circuits over encrypted data [11]. Its security is based on the Learning With Errors (LWE) problem, introduced by Regev [17].
2.2.1 LWE Hardness Asumptions. In its standard form, an LWE sample is generated as
where is sampled uniformly at random, is the secret vector , and is sampled from an error distribution , typically a discrete Gaussian distribution .
The hardness of LWE is commonly formulated in two variants:
• Decision-LWE: Given samples (a, b) generated according to the LWE distribution and samples (a, u), where is uniformly random, no PPT adversary can distinguish between the two distributions with more than a negligible advantage.
• Search-LWE: Given polynomially many LWE samples satisfying , recovering the secret vector is assumed to be computationally hard.
2.2.2 LWE Encryption Scheme. To encrypt a message , where , the plaintext must first be encoded into using a scaling-based encoding:
where typically and is an error. This encoding maps consecutive plaintext values in to points in separated by approximately . The resulting spacing provides room to place the error introduced by . This noisy encoding is known as ciphertext phase. Decoding this value gives
Since the error distribution has unbounded support, correct decoding is not guaranteed for every sample. Instead, is chosen such that the probability of is negligible. Consequently, with overwhelming probability, and the decoding correctly recovers . Assuming and letting ,
and therefore . This gives the decoding failure probability for the parameters and .
The noisy-encoded plaintext is incorporated into an LWE ciphertext by adding the inner product of a uniformly random vector and a secret key:
where s is a secret key sampled uniformly at random from . The vector a and the scalar b are referred to as the mask and body, respectively. In the rest of the paper, we denote by interchangeably.
Given a ciphertext , decryption first removes the contribution of the secret key:
The plaintext is then recovered by applying the decoding function:
which correctly recovers m with overwhelming probability.
Homomorphic Operations. To add two messages homomorphically in the ciphertext space, it is sufficient to add their corresponding ciphertexts component-wise. Similarly, multiplying a plaintext scalar by all components of a ciphertext corresponding to a message m results in a ciphertext corresponding to . Homomorphic multiplication of two ciphertexts, however, is not simply performed by component-wise multiplication of two LWE ciphertexts and requires additional techniques. We refer to [15] for a detailed treatment of homomorphic operations.
A sequence of homomorphic operations causes the noise in a ciphertext to accumulate. As the noise increases, the resulting ciphertext may eventually violate the condition , making correct decryption impossible. To prevent this, a bootstrapping operation can be performed before the noise becomes too large. Bootstrapping reduces the noise in a ciphertext and produces a refreshed ciphertext that can be used for further homomorphic computation.
In TFHE, bootstrapping can additionally evaluate a function on the encoded plaintext while simultaneously reducing the ciphertext noise. This technique, known as programmable bootstrapping, allows a single bootstrapping operation to perform both noise reduction and function evaluation. Programmable bootstrapping is discussed in Section 2.3.
2.2.3 GLWE Encryption Scheme. The LWE encryption scheme can be generalized to the General Learning With Errors (GLWE) scheme by replacing the underlying space with a polynomial ring . In GLWE, the secret key S and the mask A are vectors of polynomials in , while the message M and the error E are polynomials
Usually, the secret vector is sampled as a binary vector .
Each element of can be represented using bits, whereas a message in requires bits. The scaling effectively places the message in the most significant bits of the representation in , leaving the remaining lower bits to accommodate the noise.
in the same ring. Specifically, for a message , where , the encryption is defined as
where is the secret key, is the scaling factor, and is an error polynomial whose coefficients are sampled from an error distribution . In the rest of the paper, is denoted by interchangeably.
Given a ciphertext GLWE( ) = (A, B), decryption first removes the contribution of the secret key:
The resulting noisy encoded message is then decoded coefficient-wise by
In some applications, a polynomial needs to be represented in the form of a GLWE ciphertext without introducing encryption noise or hiding the polynomial. In this case, the mask is set to zero, i.e., , and the body is set to . This representation is called a trivial encryption of and is denoted by .
Sample Extraction. Given a GLWE ciphertext encrypting a polynomial
one can homomorphically construct an LWE ciphertext , where , encrypting a selected coefficient of . This can be achieved by appropriately selecting and rearranging coefficients of the GLWE ciphertext to form the LWE ciphertext . Consequently, the secret key of , known as the extracted secret key, is obtained by flattening the coefficients of the GLWE secret key:
This operation is called sample extraction [11] and is denoted by
Key Switching. A key-switching operation is a homomorphic operation that takes as input a ciphertext , encrypted under a key , together with an encryption of every component of under a (possibly different) key , and produces a ciphertext encrypting the same underlying message under . The set of ciphertexts encrypting the elements of under is called the key-switching key (KSK). The operation is denoted by:
The general idea is to homomorphically cancel out of the ciphertext using the encryption of under , yielding a ciphertext under . Several types of key switching are used in practice, including LWE-to-LWE, GLWE-to-GLWE, LWE-to-GLWE, and many-LWE-to-one-GLWE [9].
Blind Rotation. Homomorphic polynomial rotation has several applications, particularly in programmable bootstrapping. In the plaintext domain, rotating the coefficients of a polynomial M by t positions corresponds to multiplying M by . When M belongs to the polynomial ring , this operation has two important properties:
-
Periodicity modulo 2N. Since , we have . Therefore, the rotation exponent is interpreted modulo 2N, and we can restrict the rotation position to .
-
Negacyclicity. Since , as well . Consequently,
Thus, rotating by an additional N positions negates the resulting polynomial.
Given a GLWE ciphertext C encrypting a polynomial and an LWE ciphertext encrypting a rotation position under the secret key , TFHE homomorphically computes a GLWE ciphertext encrypting the rotated polynomial. This operation is called blind rotation because the rotation is performed without revealing the encrypted position . It relies on GLWE encryptions of the individual secret-key components , which collectively form the blind rotation key (BRK). The operation is denoted by
To understand how blind rotation is performed, recall that the LWE ciphertext satisfies
The rotation position is therefore represented by a noisy encoding in , rather than being available directly as a plaintext integer. TFHE uses modulus switching to map the ciphertext components from to the rotation-exponent domain modulo 2N. At the algebraic level, the underlying decomposition is
This decomposition consists of an initial rotation determined by , followed by conditional rotations: for each , the polynomial is rotated by when and remains unchanged when . The BRK enables these conditional rotations to
A function is called negacyclic when for all it satisfies .
Since , we have , and hence .
be evaluated homomorphically without revealing the secret-key bits. Blind rotation is therefore a central and computationally expensive operation in TFHE.
2.3 Programmable Bootstrapping (PBS)
Introduced by Gentry [14], bootstrapping reduces the noise accumulated in a ciphertext through a sequence of homomorphic operations by homomorphically evaluating its decryption function, using a homomorphic encryption of the secret key. The resulting ciphertext encrypts the same underlying plaintext, while its noise is essentially independent of the noise in the input ciphertext. TFHE further allows a target function h to be evaluated during bootstrapping, i.e.,
by encoding h into a polynomial called a test polynomial. We first elaborate on test polynomials in Section 2.3.1 and then provide further details on the operation of PBS in Section 2.3.2.
2.3.1 Test Polynomial and Lookup Table (LUT). Consider a polynomial as
and define the following function for each
That is, rotates V by t positions via multiplying it by the monomial and extracts the constant coefficient of the result. In the ciphertext domain, V is represented as a GLWE trivial encryption, the multiplication is performed via a blind rotation, and the constant coefficient is extracted via sample extraction.
As discussed in the context of blind rotation, the operation in is negacyclic, therefore for samples the -th coefficient of , while for it samples the negative of the coefficient at position , namely:
Note that the coefficients of remain free and unconstrained, while the generated length-2N sequence is negacyclic, with its second half equal to the negation of its first half.
A negacyclic function can be encoded by using the polynomial
which satisfies and can be computed homomorphically via a blind rotation followed by a sample extraction. Such a polynomial is called a test polynomial and can be represented as a lookup table containing N entries, each corresponding to one of its coefficients. We refer to such a function f as LUT function.
Negacyclicity is a structural property of and cannot be circumvented: a non-negacyclic function on domain has no test-polynomial encoding. However, any function with can still be encoded, by defining a negacyclic as
This works precisely because the target domain never reaches the second half of . Consequently, under this construction every valid input to has its most significant bit equal to zero — so at the design level, one padding bit must be reserved for the input , and no sequence of operations may ever carry into it.
Recoding Input via Modulo Switching. To evaluate on an LWE ciphertext encoding , its value must be recoded into the index range . Direct reduction modulo 2N is unsuitable because it retains low-order bits, which primarily contain noise, while discarding the high-order bits encoding the message. Instead, we use modulus switching to change the modulus from to .
Given an LWE ciphertext , modulus switching scales and rounds each component:
Consequently, the encoded message is rescaled from to :
where is the scaled noise, ignoring rounding errors. Thus, modulus switching preserves the message encoding while mapping it to the desired index range.
Denoting rounding errors by and , the phase of the switched ciphertext is
Each rounding error is modeled as independent and uniform on , so it has mean 0 and variance 1/12. Hence,
where denotes the number of elements in the secret key for which . For a uniformly random binary key, , hence
The error already present before the rounding has standard deviation , where is the standard deviation of . Since and are independent, the total error seen by has standard deviation
Consecutive messages are positions apart, so decoding is correct if and only if . Modeling the total error as Gaussian distribution and denoting , the failure probability is
Since , a target negligible failure probability determines . For given , , and , the plaintext modulus must therefore satisfy
Designing Test Polynomials. At the design level, we aim to evaluate , whereas implements . This mismatch is addressed by adjusting the input and output encodings.
Since , each plaintext corresponds to a block of consecutive indices in . The input message associated with an index is therefore
To ensure valid ciphertext encoding, each output is scaled by .
Accordingly, the 2N indices are partitioned into 2p blocks of elements each, with every index in a block assigned the same scaled output. For a function compatible with negacyclic evaluation, the corresponding test polynomial is
Non-negacyclic functions can be handled using the technique described in Equation 2.
2.3.2 How PBS Works. To bootstrap a ciphertext encrypted under a secret key and containing accumulated error , TFHE requires a bootstrapping key (BSK). The BSK is actually a blind rotation key consists of a collection of GLWE ciphertexts under an encryption key , with one ciphertext associated with each component of the input LWE secret key. These ciphertexts enable the components of the input secret key to be used homomorphically during the blind rotation. We refer to [9] for details on the construction of the BSK.
Given c, the BSK, and a trivial GLWE encryption of a test polynomial V corresponding to a target negacyclic function , TFHE homomorphically evaluates , where , to obtain a ciphertext LWE( ). This proceeds as follows:
-
Obtain LWE( ) via modulus switching, i.e., by scaling all components of c by 2N/q and rounding the results.
-
Compute homomorphically via a blind rotation, which takes GLWE( ), LWE( ), and the BSK as input and outputs a GLWE encryption of , denoted by . In other words,
This ciphertext is encrypted under the key by which BSK is generated.
-
Extract the constant coefficient of as an LWE ciphertext, yielding an LWE encryption of , via sample extraction operator . As discussed in Section 2.2.3, this extracted ciphertext is under a key obtained by flattening of .
-
Having an appropriate LWE to LWE key-switching key KSK from to s, switch the encryption key of from back to s via a key-switching operation as
will be LWE( ).
Note that no modulus switching from 2N back to q is needed. Although the input to the blind rotation is represented modulo 2N, the test polynomial GLWE( ) itself lives in throughout the computation. Consequently, the sample-extracted LWE ciphertext is already defined modulo q and is therefore a valid LWE ciphertext.
2.3.3 TFHE Boolean Circuits. In TFHE, Boolean values are encrypted as LWE ciphertexts, and binary gates can be evaluated homomorphically by applying a programmable bootstrapping (PBS) to an appropriate linear combination of the input ciphertexts. The linear combination depends on the Boolean function to be evaluated, while the PBS evaluates a corresponding look-up table (LUT) and simultaneously reduces the ciphertext noise. This process is commonly referred to as gate bootstrapping. In particular, all standard binary Boolean gates, such as AND, OR, XOR, NAND, and NOR, can be evaluated in this way [11].
A natural starting point for Boolean values is to set for a chosen ciphertext modulus . According to the encoding introduced in Section 2.2.2, this gives and the two Boolean messages are encoded as ,
By the central limit theorem, since E is a sum of several independent random variables, namely , it can be approximated by a Gaussian distribution.
One can instead hide V by encrypting it as a non-trivial GLWE ciphertext.
that is, and . However, the linear combination of two such encoded values needs at least two bits of precision to remain distinguishable, so a larger must be chosen. Moreover, the underlying function whose test polynomial realizes a given gate type is not negacyclic, so, as stated in Section 2.3, padding bits are needed.
An alternative, the shifted encoding [9–11], is defined as
which gives and . Under this encoding, boolean values take the form of a negative/positive sign representation, which makes gate bootstrapping more convenient. Here the LUT function is a sign function on the rotation index,
whose corresponding test polynomial is . Since sgn is negacyclic, no padding bit is required. It is then sufficient to define, for each gate type, a linear combination of the encoded inputs that sgn maps to the correct output. For example, as shown in Table 1, the combination evaluates the OR gate: encodes 0, while encodes 1.
| false | false | |||
| false | true | |||
| true | false | |||
| true | true |
Table 1. Linear combination used for OR gate bootstrapping with the shifted Boolean encoding.
Similarly, the combination is the right choice for AND gates, as shown in Table 2.
| false | false | |||
| false | true | |||
| true | false | |||
| true | true |
Table 2. Linear combination used for AND gate bootstrapping with the shifted Boolean encoding.
3 Free-XOR Gate Bootstrapping Framework
For a circuit consisting only of XOR gates, an encoding with is sufficient, as XOR can be obtained simply by homomorphically adding the two input ciphertexts. This works because XOR is equivalent to addition modulo 2, which the encoding preserves automatically, without requiring bootstrapping to evaluate nonlinear operations. Moreover, the noise grows relatively slowly, so many common circuits can be evaluated without bootstrapping for noise reduction. Specifically, after XORs the ciphertext contains independent encryption noises, each with standard deviation , so the total noise is approximately Gaussian with . Decryption fails when is at least half a step, , hence
where . For a target failure probability , let be the value satisfying . Requiring gives the maximal number of XORs,
Example. Take the modulus and a noise standard deviation , which is of the order commonly used for LWE ciphertexts with a dimension of a few hundred. Then and the bound becomes
For we have , which gives
Thus about twenty million XORs can be chained while keeping the failure probability below . For () the bound is about .
3.1 Supporting Other Boolean Gate Types
For circuits with other types of binary gates the situation is different. A linear combination of two input ciphertexts, which TFHE handles very efficiently, cannot implement a non-linear gate such as AND or OR. Instead, the gate is implemented by a programmable bootstrapping applied to an appropriate linear combination of the inputs.
For bits , the linear combination
uniquely identifies the input pair, as shown in Table 3. Thus, the index identifies the corresponding row in the truth table of the target gate. This design supports only eight of the sixteen possible binary Boolean gates: AND, NAND, OR, NOR, XOR, XNOR, FALSE, and TRUE. These gates produce the same output for the input pairs and . Consequently, their outputs can be determined from either index convention, or . The remaining eight
It is common to give as a fraction of the modulus ; here .
gates distinguish these two input pairs and are therefore not supported by our design.
For a gate type T, we define a function whose output matches the truth table of that gate, i.e., . Homomorphically evaluating and then applying programmable bootstrapping with a lookup table (LUT) representing yields the correct gate output. We call the gate characteristic function for a gate T.
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 2 | 0 | 1 |
| 1 | 1 | 3 | 1 | 1 |
Table 3. Truth-table indices and corresponding output functions for AND and OR gates.
3.1.1 Encoding. We need a mapping for each bit b that supports Free-XOR while also allowing the index i in Equation 7 to be computed efficiently. A two-bit mapping whose least significant bit equals b achieves the Free-XOR property and, with programmable bootstrapping, also supports the computation of i. Specifically, b = 0 is mapped to the bit patterns 00 and 10, denoted by 0 and 2, respectively, whereas b = 1 is mapped to 01 and 11, denoted by and , respectively. Formally, the mapping is given by , where is the parity of m, i.e., whether m is even or odd. With a slight abuse of notation, we denote the canonical representatives 0 and by and respectively.
We define a function that computes the index from Equation 7 for any pair of mapped inputs:
where . Thus, for a gate type T with characteristic function , the output for encoded inputs is given by
To demonstrate the Free-XOR property and compatibility with Equation 7, we introduce a table over the mapping space that we call the modulo table. It contains 16 rows, one for each pair of values . Each input pair in the Boolean truth table corresponds to four rows in the modulo table, since each bit has two possible representations. We call these four rows an equivalent chunk. For example, the input pair corresponds to the four pairs
Accordingly, the modulo table is partitioned into four equivalent chunks, denoted by , corresponding to the Boolean input pairs , respectively.
We avoid the term encoding here because TFHE uses it to refer to the scaling-by- operation.
Table 4. The mapping achieves free-XOR by addition modulo 4. The index is obtained as , where .
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 2 | 2 | 0 | 0 | 0 | 0 |
| 2 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 2 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 | 1 |
| 0 | 3 | 3 | 0 | 1 | 1 | 1 |
| 2 | 1 | 3 | 0 | 1 | 1 | 1 |
| 2 | 3 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 | 1 | 2 |
| 1 | 2 | 3 | 1 | 0 | 1 | 2 |
| 3 | 0 | 3 | 1 | 0 | 1 | 2 |
| 3 | 2 | 1 | 1 | 0 | 1 | 2 |
| 1 | 1 | 2 | 1 | 1 | 0 | 3 |
| 1 | 3 | 0 | 1 | 1 | 0 | 3 |
| 3 | 1 | 0 | 1 | 1 | 0 | 3 |
| 3 | 3 | 2 | 1 | 1 | 0 | 3 |
Table 4 shows that addition modulo 4 preserves the Free-XOR property for all 16 pairs of mapped values . It also shows that the function computes the index from Equation 7.
Padding Bit and Headroom. The difficulty in our approach is that for the gate types AND, NAND, OR, and NOR the corresponding function is not negacyclic. In particular, as shown in Table 3, and , whereas negacyclicity requires . Therefore, as discussed in Section 2.3.1, a padding bit must be reserved. This bit, however, breaks the mod 4 arithmetic that our encoding previously provided automatically.
To address this problem, in addition to the padding bit, we reserve a headroom in our encoding to keep the intermediate values obtained from a sequence of additions (XOR gates) away from the padding bit. For a headroom , each intermediate value is encoded as with . The factor of 2 accounts for the reserved padding bit: the lower half of holds distinct values and the upper half is the padding. Additions are then performed over the integers instead of modulo 4, and no wrap-around occurs as long as the value stays below . Whenever a gate requires the non-linear function , programmable bootstrapping is applied using the LUT , defined over the entire range . Similarly, when the value approaches , programmable bootstrapping is applied using the LUT to obtain a fresh ciphertext.
Choosing Headroom. A larger headroom allows more XORs between bootstrappings, but it is limited by the modulus switching error of Equation (3). With the padding bit the plaintext modulus is , so the condition of Equation 4 gives
where l is chosen based on the target failure probability. Thus H must be larger than the biggest value reached between two bootstrappings, and, at the same time, small enough for this bound to hold.
3.2 Gate Bootstrapping for Supported Non-linear Boolean Gates
To evaluate a gate T with characteristic function on two input ciphertexts, it suffices to homomorphically evaluate as in Equation 9. Let and G denote programmable bootstrapping operations implementing the functions and , respectively. Given and , with , where is the headroom and are mapped inputs, the homomorphic addition and scalar multiplication properties of TFHE yield
The LUT of G is defined on the whole range and reduces its input modulo 4 before applying the indexed truth table. This is what makes the third line valid: the sum is computed over the integers and may exceed 3, but depends only on the parity of . It must stay below , i.e., , otherwise it spills into the padding bit. Figure 1 shows the resulting circuit for the supported non-free gates AND, NAND, OR and NOR (XOR and XNOR are handled by the free-XOR property, XNOR with an additional plaintext addition of 1). Each such gate costs two bootstrappings, one for and one for G.
The unary NOT gate is free in the same way: it is the XOR with the constant 1, i.e., a single plaintext addition of that needs no bootstrapping and adds no noise. The constant gates FALSE and TRUE need no bootstrapping either, since their output is a trivial encryption of 0 or 1 that is independent of the inputs.

Figure 1. Gate bootstrapping for the supported non-free binary gates. The input is multiplied by 2, and is passed through the bootstrapping that computes . Their sum encrypts the index , and the bootstrapping G applies the indexed truth table of the gate T to it.
4 Implementations and Proof of Work
We implemented our proposed approach in Rust and made the source code publicly available in [2]. Our implementation uses the open-source TFHE-rs library [21], which provides high-level APIs for manipulating TFHE ciphertexts. To evaluate Boolean circuits, we developed a compiler that translates circuits represented in the Bristol Fashion (BF) format into equivalent circuits operating over TFHE ciphertexts. An interpreter then evaluates the resulting circuits using a valid set of ciphertexts as inputs.
4.1 Bristol Fashion (BF)
We use the Bristol Fashion (BF) syntax [3] to represent Boolean circuits within our framework. BF provides a textual representation of a circuit in which all gates are listed in topological order. Each gate is specified by its type together with the indices of its input and output wires. For a circuit with n input wires and m output wires, the first n wire indices are reserved for the input wires, while the final m wire indices are reserved for the output wires.
4.2 Parameters
As described in Section 3.1.1, our encoding uses two bits to represent the plaintext modulus, i.e., p = 4. To satisfy Equation 10 under the other chosen parameters, including N and , we allocate additional two bits for carry values arising during homomorphic computations. Accordingly, we set the headroom to four bits, i.e., H = 16. A larger value of H allows more homomorphic operations to be performed between bootstrapping operations, thereby reducing the frequency of bootstrapping. However, increasing H may require adjusting other parameters to maintain the desired security level and may increase the dimensions of the underlying polynomials and vectors, potentially increasing computational costs. Optimizing these parameters jointly to balance security, computational efficiency, and bootstrapping frequency remains an open engineering problem for our approach.
4.3 Lazy Bootstrapping
As explained in Section 3.1.1, we reserve a headroom that allows us to postpone the bootstrapping of XOR, XNOR, and NOT gates, while guaranteeing that intermediate values never overwrite the padding bit, which must remain zero for the trick that enables the evaluation of non-negacyclic
Table 5. Lazy bootstrapping conditions and estimated maximum possible value (MPV) of the output wire for each gate type, where is the MPV of input wire and is the headroom.
| Gate | Bootstrapping condition | Output wire MPV |
|---|---|---|
| XOR | ||
| XNOR | ||
| NOT | ||
| Others |
functions. If a value exceeds the maximum value that fits in the headroom, the padding bit is overwritten and the result is no longer valid.
One way to satisfy this requirement is to write a compiler that, given the input values, finds the optimal places to insert bootstrapping operations. However, this approach has two drawbacks: first, it may leak information about the input values, and second, it requires a new configuration for every evaluation.
Our approach instead estimates the maximum possible value (MPV) of each wire during homomorphic evaluation and applies a bootstrapping when this value approaches the headroom. To this end, we maintain a hashmap from wire indices to MPVs, which is filled and updated during the evaluation. For each gate, we look up the MPVs of its input wires and estimate the MPV of its output wire. If the estimate would overflow the headroom, we bootstrap one or two of the input wires.
The overflow condition depends on the gate type. For XOR, the evaluation is an addition of the two input ciphertexts, so an overflow occurs when the sum of the input MPVs is greater than . For NOT, the evaluation adds 1 to the ciphertext, so an overflow occurs when the input MPV plus 1 is greater than . For XNOR, we add the two input ciphertexts and 1, so an overflow occurs when the sum of the input MPVs plus 1 is greater than . For the other supported symmetric gates, which apply the index function , an overflow occurs when twice the MPV of the first input is greater than . Since is applied via a PBS, there is no need to check the sum . Table 5 summarizes all cases. For XOR and XNOR, we bootstrap the input with the larger MPV first, and then the other input only if the condition still holds.
4.4 Experimental Results
We evaluated our approach on toy circuits with varying combinations of free-XOR gates and symmetric gates requiring two PBS operations. Each experiment was repeated 10 times on an Apple M2 MacBook Pro with 24 GB of RAM. Table 6 presents a subset of the results, comparing the evaluation time of our approach with that of the standard approach, which performs bootstrapping after evaluating each gate. Our approach achieves an approximately speedup on XOR-only circuits, with diminishing gains as the proportion of symmetric gates relative to FreeXOR gates increases.
Table 6. Our experimental results. All the elapsed times are reported in seconds.
| Circuit | Gates | Standard | FreeXOR |
|---|---|---|---|
| XOR-tree | 63 XOR | 0.975 | 0.114 |
| Toy1 | 150 XOR, 15 INV, 20 AND, 15 OR | 2.866 | 1.422 |
| Toy2 | 100 XOR, 30 INV, 40 AND, 30 OR | 2.608 | 2.481 |
| Toy3 | 80 XOR, 20 INV, 50 AND, 50 OR | 2.682 | 3.711 |
5 Conclusion and Discussion
We proposed an encoding that enables XOR evaluation without immediate programmable bootstrapping (PBS), using homomorphic addition instead. To support other symmetric gates, such as AND, NAND, OR, and NOR, we introduced an indexing function that homomorphically identifies the corresponding row of a gate's truth table. Evaluating a symmetric gate requires two PBS operations: one to compute the index and another to evaluate the gate's functionality based on that index. In contrast, XOR gates can be evaluated without immediate bootstrapping. Our approach reserves headroom for intermediate results produced by operations performed without bootstrapping, allowing bootstrapping to be deferred until this headroom is about to overflow. Consequently, our approach is most efficient for circuits in which XOR gates significantly outnumber symmetric gates.
References
[1] Abbas Acar, Hidayet Aksu, A Selcuk Uluagac, and Mauro Conti. 2018. A survey on homomorphic encryption schemes: Theory and implementation. ACM Computing Surveys (Csur) 51, 4 (2018), 1–35.
[2] Ali Ajorian. 2026. FreeXOR-FHE. https://github.com/Ajorian/freexor-the Source code repository.
[3] David Archer, Victor Arribas Abril, Steve Lu, Pieter Maene, Nele Mertens, Danilo Sijacic, and Nigel Smart. 2019. Bristol Fashion MPC Circuits. https://nigelsmart.github.io/MPC-Circuits/. Accessed: 2026-09-10.
[4] Dan Boneh, Eu-Jin Goh, and Kobbi Nissim. 2005. Evaluating 2-DNF formulas on ciphertexts. In Theory of cryptography conference. Springer, 325–341.
[5] Zvika Brakerski, Craig Gentry, and Vinod Vaikuntanathan. 2014. (Leveled) fully homomorphic encryption without bootstrapping. ACM Transactions on Computation Theory (TOCT) 6, 3 (2014), 1–36.
[6] Zvika Brakerski and Vinod Vaikuntanathan. 2014. Efficient fully homomorphic encryption from (standard) LWE. SIAM Journal on computing 43, 2 (2014), 831–871.
[7] Chunling Chen, Xianhui Lu, Ruida Wang, Zhihao Li, Xuan Shen, and Benqiang Wei. 2024. Free-xor gate bootstrapping. Cryptology ePrint Archive (2024).
[8] Jung Hee Cheon, Andrey Kim, Miran Kim, and Yongsoo Song. 2017. Homomorphic encryption for arithmetic of approximate numbers. In International conference on the theory and application of cryptology and information security. Springer, 409–437.
[9] Ilaria Chillotti. 2022. TFHE Deep Dive - Part IV - Programmable Bootstrapping. https://www.zama.org/post/tfhe-deep-dive-part-4. Zama Blog.
[10] Ilaria Chillotti, Nicolas Gama, Mariya Georgieva, and Malika Izabachène. 2016. Faster Fully Homomorphic Encryption: Bootstrapping in Less Than 0.1 Seconds. In Advances in Cryptology – ASIACRYPT 2016. Springer, 3–33. doi:10.1007/978-3-662-53887-6_1
[11] Ilaria Chillotti, Nicolas Gama, Mariya Georgieva, and Malika Izabachène. 2020. TFHE: Fast Fully Homomorphic Encryption Over the Torus: I. Chillotti et al. Journal of Cryptology 33, 1 (2020), 34–91.
[12] Léo Ducas and Daniele Micciancio. 2015. FHEW: bootstrapping homomorphic encryption in less than a second. In Annual international conference on the theory and applications of cryptographic techniques. Springer, 617–640.
[13] Taher ElGamal. 1985. A public key cryptosystem and a signature scheme based on discrete logarithms. IEEE transactions on information theory 31, 4 (1985), 469–472.
[14] Craig Gentry. 2009. A fully homomorphic encryption scheme. Ph.D. Dissertation. Stanford University.
[15] Marc Joye. 2021. Guide to fully homomorphic encryption over the [discretized] torus. Cryptology ePrint Archive (2021).
[16] Chiara Marcolla, Victor Sucasas, Marc Manzano, Riccardo Bassoli, Frank HP Fitzek, and Najwa Aaraj. 2022. Survey on fully homomorphic encryption, theory, and applications. Proc. IEEE 110, 10 (2022), 1572–1609.
[17] Oded Regev. 2009. On lattices, learning with errors, random linear codes, and cryptography. Journal of the ACM (JACM) 56, 6 (2009), 1–40.
[18] Ronald L Rivest, Len Adleman, Michael L Dertouzos, et al. 1978. On data banks and privacy homomorphisms. Foundations of secure computation 4, 11 (1978), 169–180.
[19] Ronald L Rivest, Adi Shamir, and Len Adleman. 1978. A method for obtaining digital signatures and public-key cryptosystems. Commun. ACM 21, 2 (1978), 120–126.
[20] Ron Rothblum. 2011. Homomorphic encryption: From private-key to public-key. In Theory of cryptography conference. Springer, 219–234.
[21] Zama. 2022. TFHE-rs: A Pure Rust Implementation of the TFHE Scheme for Boolean and Integer Arithmetics Over Encrypted Data. https://github.com/zama-ai/tfhe-rs.