Since the release of Zama's fhEVM white paper and alpha code a few weeks ago, the Zama team has released many minor versions. The latest to date (v0.2.0) introduces a comprehensive set of operators designed to provide robust functionality and versatility.
The following encrypted data types are now supported:
The equivalent signed types (and 64 bits) are coming soon.
Some operators are overloaded with the usual symbol, below is an example for addition overload:
The bitwise operations do not natively accept a mix of ciphertext and plaintext inputs, but the TFHE library adds function overloads to handle those cases.
The shift right operator can be used to perform division by powers of 2.
The result of comparison operations is an encrypted boolean (ebool). In the backend, the boolean is represented by an encrypted unsigned integer of bit width 8, but this is abstracted away by the Solidity library.
Now that we reviewed the common operators, let's deep dive into FHE specific ones.
This operator offers the ability to assign a value among two possibilities based on a condition, while preserving the encrypted state of the data.
This operator takes three inputs. The first input [.c-inline-code]b[.c-inline-code] is of type [.c-inline-code]ebool[.c-inline-code] and the two others of type [.c-inline-code]euintX[.c-inline-code]. If [.c-inline-code]b[.c-inline-code] is an encryption of [.c-inline-code]true[.c-inline-code], the first integer parameter is returned. Otherwise, the second integer parameter is returned.
Random encrypted integers can be generated fully on-chain.
WARNING: Don't use in production! Integers are currently generated in the plain via a PRNG whose seed and state are public, while the state is on-chain. An FHE-based PRNG is coming soon, where the seed and state will be encrypted.
Decryption currently occurs in the validator, which has full access to the private key (note that a threshold decryption protocol is under development). This function can potentially lead to information leakage, therefore, you should consider using [.c-inline-code]cmux[.c-inline-code] instead for safer operations.
Remember that all inputs are encrypted under the network public key. To return a user specific data, we need to reencrypt the given data under the user-provided public key.
Instead of interrupting the transaction flow by decrypting conditions at each occurrence, we accumulate these conditions until the end of the transaction and perform a single decryption with [.c-inline-code]optReq[.c-inline-code]. If all conditions are satisfied, state changes are applied. If not, they are reverted. This approach streamlines the process and enhances efficiency.
Note: this efficiency comes at the price of paying the full transaction gas cost if one of the boolean conditions is false.
Finally, you now have the ability to use our specialized Remix instance, designed specifically to handle input encryption, but you can also take advantage of our dedicated Hardhat template, which includes a single-line command for launching a local fhEVM instance.
News, research and product releases