fhEVM v0.4: New Encrypted Types and Asynchronous Decryption

April 8, 2024
  -  
Clément Danjou

This new version of fhEVM introduces new encrypted types and the new asynchronous decryption API. Additionally, we’ve published the first version of our standard fhEVM contracts library.

These new features aim to improve the overall performance of fhEVM, enhance efficiency, and unlock the potential of new use cases. 

Encrypted boolean, 4 bits, 64 bits, and addresses

fhEVM v0.4 expands the types of encrypted data supported:

  • [.c-inline-code]ebool[.c-inline-code]: Encrypted booleans. [.c-inline-code]ebool[.c-inline-code]allows users to perform boolean operations at lower gas fees, compared to the previous use of 8-bit integers to represent encrypted booleans.
  • [.c-inline-code]euint4[.c-inline-code]: Encrypted 4-bit integers.
  • [.c-inline-code]euint64[.c-inline-code]: Encrypted 64-bit integers.
  • [.c-inline-code]eaddress[.c-inline-code]: Encrypted address. [.c-inline-code]eaddress[.c-inline-code] unlocks a wide range of new use cases in privacy-preserving decentralized applications, such as confidential asset transfer, address verification, and many others. [.c-inline-code]eaddress[.c-inline-code] is compatible with [.c-inline-code]eq[.c-inline-code](equal to) and [.c-inline-code]ne[.c-inline-code](not equal to).

New asynchronous decryption

Zama’s fhEVM v0.4 introduces a new asynchronous decryption API - fhEVM smart contracts can now initiate decryption requests via an oracle, and receive answers through callbacks. 

Compared to the previous synchronous decryption within the blockchain network, the new asynchronous decryption enables fhEVM smart contracts to offload decryption tasks, freeing up resources and improving overall performance. With the possibility to request multiple decryptions at once and handle callback parameters, this improvement optimizes the efficiency and scalability of operations on the blockchain.

Here is a simple example of asynchronous decryption:

// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.20;

import "fhevm/lib/TFHE.sol";
import "fhevm/oracle/OracleCaller.sol";

contract MyContract is OracleCaller {
    uint256 public total;
    function requestDecryption(uint256 input1, uint256 input2) public {
        euint8[] memory cts = new euint8[](1);
        cts[0] = TFHE.asEuint8(42);
        uint256 requestID = Oracle.requestDecryption(cts, this.callback.selector, 0, block.timestamp + 100);
        addParamsUint(requestID, input1);
        addParamsUint(requestID, input2);
    }

    function callback(uint256 requestID, uint8 decryptedInput) public onlyOracle returns (uint8) {
        uint256[] memory params = getParamsUint(requestID);
        total = uint256(decryptedInput) + params[0] + params[1];
    }
}

⚠️ This new asynchronous decryption feature deprecates the synchronous decryption. While TFHE.decrypt is still working in this version (fhEVM v0.4), it will be removed in the next release (fhEVM v0.5). We strongly recommend users to upgrade their code using the new asynchronous decryption method.

New fhEVM standard library

In this release, the Zama team introduces a new package that provides a foundational suite of standard contracts including ERC20 and DAO – the fhevm-contracts. This library is designed to be easily extended and customized. It aims to help developers save significant development time so they can focus more on fostering innovation. To use the fhEVM standard library, simply install it with [.c-inline-code]npm install fhevm-contracts[.c-inline-code]. For a more detailed explanation and code examples, visit the fhEVM documentation. 

Additional links 

Read more related posts

Zama Product Releases - April 2024

With these releases, Zama continues to build its suite of products to make homomorphic encryption accessible, easy, and fast.

Read Article

TFHE-rs v0.6: Zero-Knowledge Support and Signed Integer Operations on GPU

TFHE-rs v0.6 introduces Zero-Knowledge Proofs, GPU enhancements, and other cryptographic features.

Read Article

Concrete v2.6: Approximate PBS, Input Compression, Extended Composable Functions, Speed Improvements

Concrete v2.6 introduces the approximate programmable bootstrapping (PBS), input compression, and other enhancements.

Read Article

Concrete ML v1.5: Encrypted DataFrames and Faster Neural Networks

Concrete ML v1.5 introduces a new DataFrame API and a new option that speeds up neural networks.

Read Article