Skip to main content

Hands-on fhEVM

This hands-on guide will walk you through understanding, setting up, and working with fhEVM to develop encrypted smart contracts and test them on fhEVM network.

What You’ll Learn

  • Basics of fhEVM and its architecture.
  • Setting up a local fhEVM development environment.
  • Writing, compiling, and deploying FHE-enabled Solidity contracts.
  • Testing encrypted contract interactions.

1. Understanding fhEVM

fhEVM is a privacy-first smart contract platform that allows computations on encrypted data without decryption. This ensures on-chain privacy while maintaining verifiability and interoperability.

Core Principles

  1. Security: No compromise on blockchain security.
  2. Public Verifiability: Confidential yet verifiable computations.
  3. Developer-Friendly: Familiar Solidity tools.
  4. Composability: Interoperable confidential and public contracts.

Key Features

  • Encrypted Data Types: ebool, euintX, eaddress, ebytesX, etc.
  • Homomorphic Computation: Arithmetic on encrypted numbers.
  • Confidential Transactions: Data remains encrypted even on-chain.
  • EVM-Compatible: Supports Solidity with added FHE functionalities.

Encrypted Data Types

fhEVM introduces special encrypted types for secure computations:

  • Booleans: ebool
  • Integers: euint4, euint8, ... euint256
  • Addresses: eaddress
  • Bytes: ebytes64, ebytes128, ebytes256
  • Inputs: einput

Type Casting

fhEVM provides utility functions to convert between encrypted types:

  • TFHE.asEbool(value): Converts a boolean to an encrypted boolean.
  • TFHE.asEuintX(value): Converts an integer to an encrypted integer.
  • TFHE.asEaddress(value): Converts an address to an encrypted address.

fhEVM empowers secure and efficient computation on encrypted data while preserving blockchain functionality.


2. fhEVM Architecture

Core Components

fhEVM consists of several interdependent components:

  • Smart Contracts: Interact with encrypted data to execute logic securely on the blockchain.
  • fhEVM-native: On-chain processing that handles homomorphic computations on ciphertexts using evaluation keys.
  • Key Management System (KMS): Safeguards private keys for decryption and re-encryption processes.
  • Gateway: Acts as a bridge between the blockchain and the KMS, enabling secure operations like decryption and re-encryption.
  • Connector: A service that connects the gateway to the KMS.
  • Gateway Store: A service that stores ciphertexts.
  • fhEVM.js Library: Facilitates client-side interactions such as encryption, decryption, and re-encryption.

End-to-End Confidentiality

fhEVM ensures that:

  • Plaintext data is never exposed during processing or transmission.
  • Homomorphic computations enable complex operations on encrypted data.
  • Secure re-encryption allows sharing and interoperability without compromising privacy.

This tightly integrated architecture supports decentralized applications (dApps) requiring privacy-preserving operations, paving the way for more secure and trustless systems.

For more detailed insights, you can refer to the official documentation by Zama.


What's Next?

Now that you understand the fhEVM architecture, let's set up an fhEVM network. ➡ Move on to Network Setup to learn how to proceed.