Decryption
Encrypted values that are stored on-chain can be decrypted in 2 ways, depending on the need.
The function TFHE.decrypt()
can be used to directly decrypt an encrypted state. For example, you could use it to reveal everyone's cards at the end of each round. Please note that once decrypted, the plain text value will be viewable to the public, so it is important to make sure that this function is well protected under various smart contracts logics.
Alternatively, it is also possible to decrypt in a way so that only the end user can see the plain text value using TFHE.reencrypt()
. This can be useful in scenarios in which a user wants to view their own private balances, without revealing the plain text to the public. The difference between TFHE.decrypt()
and TFHE.reencrypt()
is that the latter also takes in a publicKey
as input. The validators will decrypt the user data and immediately re-encrypt the plain text using this publicKey
. The re-encrypted plain text can then be decrypted locally by the user on the client side, using the respective privateKey
.
The publicKey
and privateKey
pair is generated using generateToken()
from fhevmjs (see Decryption).
Here's an example of how TFHE.reencrypt()
is used for the balanceOf
function the private ERC-20 contract:
Last updated