Control Structures
There are two primary ways to use the encrypted boolean (ebool), generated from TFHE comparisons, within design logic.
TFHE.select
TFHE.isInitialized
TFHE.select
The TFHE.select
multiplexer function allows you to pass in the ebool
as the first argument and returns the second argument if the ebool
is true
, and the third argument if it'sfalse
. This is particularly useful for avoiding information leakage, as TFHE.select
provides conditional logic without exposing data through traditional if/else statements.
In the private voting example, we first compare whether or not the encryptedChoice matches 1 or 0, which gives us an ebool
. If the encrypted boolean is a true
value, then inFavorCountToCast
will take on the value of encryptedVoteCount
. If it’s false, inFavorCountToCast
will be assigned an encrypted value of 0. Therefore, from an outside perspective, you wouldn't know if inFavorCountToCast
was assigned the actual vote count or 0. The same logic is applied to againstCountToCast
but in reverse. And finally, both inFavorCountToCast
and againstCountToCast
are added to the encrypted tallies, inFavorCountEncrypted
, and againstCountEncrypted
, but only one of them would have incremented.
TFHE.isInitialized
TFHE.isInitialized returns a boolean that specifies whether or not an encrypted handle has been initialized.
Last updated