fhEVM: FHE Smart Contracts & Private Tokens
Learning Goal: "Building Private Smart Contracts with Fully Homomorphic Encryption (FHE): Designing and Deploying Confidential Tokens and Private Voting DApps on fhEVM"
Prerequisites
- Basic programming experience (JavaScript/TypeScript or Python).
- Fundamental understanding of command-line tools (terminal) and Git.
- Conceptual knowledge of web development (HTML/JS) is helpful for frontend integration.
Estimated Total Study Time
- 24 Hours (Includes video lectures, theoretical study, and hands-on setup/coding exercises).
Module 1: Introduction to Blockchains & Solidity Smart Contracts
This module establishes the core foundations of decentralized execution. You will understand how public blockchains function, dive into the mechanics of the Ethereum Virtual Machine (EVM) stack-based architecture, and learn how to write smart contracts using Solidity.
Recommended Videos
Why this video is valuable
This deep dive is crucial for mastering how Solidity maps to compilation outputs executed by the EVM. It walks through stack execution, memory allocation, persistent storage mechanics, and bytecode interpretation. Understanding these concepts is essential because Fully Homomorphic Encryption (FHE) on fhEVM relies on custom precompiles and opcodes that operate directly on these low-level data structures.
Why this video is valuable
If you are new to smart contract development, this fast-paced tutorial introduces Solidity syntax, data types (strings, booleans, unsigned integers), and basic functional structure. It acts as an excellent, efficient syntax primer before you begin implementing custom cryptographic data types.
Why this video is valuable
This comprehensive, hands-on masterclass steps through the process of building a complete decentralized application (DApp). It teaches you how to coordinate a Solidity smart contract backend with a user-facing frontend. The architecture established in this tutorial serves as the baseline structure for the private DApps built later in the course.
Knowledge Checkpoint
- Explain the difference between
memory,storage, andcalldatain the EVM. - Compile a basic Solidity contract and describe how standard state variables are updated during a transaction.
- Connect a standard Web3 wallet (e.g., MetaMask) to a local or public test network.
- Describe the standard compilation pipeline from high-level Solidity code down to raw EVM bytecode.
Module 2: Cryptography and the Blockchain Privacy Problem
Public blockchains are built for public verifiability, meaning all transactions, state variables, and execution details are exposed to the world. In this module, you will analyze why this default design is incompatible with financial and personal privacy, and compare modern solutions like Zero-Knowledge Proofs (ZKPs) versus Fully Homomorphic Encryption (FHE).
Recommended Videos
Why this video is valuable
In this interview, Zama's CEO Rand Hindi explains the massive shift from completely public databases to secure, private state computations. He discusses why institutional finance requires on-chain privacy (the "HTTPS moment" for Web3) and frames FHE as the ultimate solution for enabling shared, encrypted state calculations.
Why this video is valuable
This episode provides a clear breakdown of Zero-Knowledge Proofs (ZKPs). By understanding how ZKPs allow a user to prove a statement is true without revealing the underlying data, you can better appreciate the trade-offs between ZKPs (which are great for user-specific, off-chain computations) and FHE (which is ideal for shared, on-chain state computations).
Knowledge Checkpoint
- Why does standard public key cryptography (like ECDSA used in Ethereum) fail to protect state variable privacy on-chain?
- Contrast the architectural differences and ideal use cases of Zero-Knowledge Proofs (ZKPs) versus Fully Homomorphic Encryption (FHE).
- Define the term "shared state privacy" and explain why standard ZKPs struggle to execute multi-user private calculations (e.g., automated market makers or private bidding) without FHE.
Module 3: Demystifying Fully Homomorphic Encryption (FHE)
This module introduces the mathematical intuition and practical realities of Fully Homomorphic Encryption (FHE). You will learn how computations are performed on ciphertexts without decrypting them, explore noise growth management, and analyze the Torus FHE (TFHE) scheme.
Recommended Videos
Why this video is valuable
Presented by Pascal Paillier, a pioneer in homomorphic cryptography, this foundational lecture explains the historical evolution of homomorphic schemes. It provides the essential math foundations, starting from partially homomorphic systems (such as Paillier and ElGamal) up to fully homomorphic architectures.
Why this video is valuable
In this deep dive, Ilaria Chillotti (one of the co-creators of TFHE) explains Torus Fully Homomorphic Encryption. This scheme is the mathematical foundation for Zama's fhEVM. You will learn about bootstrapping, noise accumulation, ciphertext mechanics, and how fast homomorphic operations on booleans and integers are achieved.
Why this video is valuable
This brief, high-level overview simplifies modern cryptography concepts. It serves as a helpful, beginner-friendly conceptual wrap-up to consolidate the complex mathematical concepts introduced in the deep-dive lectures.
Knowledge Checkpoint
- What is the role of "noise" in FHE ciphertexts, and why does it increase with each successive arithmetic operation?
- Define "bootstrapping" in FHE and explain why it is necessary for achieving arbitrary-depth, Turing-complete computations.
- Describe the performance differences between executing homomorphic additions versus homomorphic multiplications under the TFHE scheme.
Module 4: Introducing fhEVM: Smart Contracts on Encrypted Data
This module bridges theory and development by exploring Zama's fhEVM architecture. You will learn how FHE is integrated directly into the Ethereum Virtual Machine, explore the encrypted data types (euint8, euint16, euint32), and configure a local Hardhat/Remix development workspace.
Recommended Videos
Why this video is valuable
This presentation outlines the core architecture of Zama's fhEVM. You will learn how public states and encrypted states exist side-by-side within the same smart contract, and how developers can utilize standard Solidity libraries alongside encrypted types.
Why this video is valuable
This presentation provides a deep dive into the runtime environment of fhEVM. It explains how transactions process encrypted parameters, how state updates are committed homomorphically, and how security remains consistent with Ethereum's trust model.
Practical Setup Guide: Preparing Your Development Workspace
Before moving to implementation, you must set up your local development environment to support FHE operations. Because standard EVM nodes cannot process encrypted types, you need a local fhEVM node running in Docker.
- Prerequisites: Install Docker, Node.js (v18+), and Yarn/NPM.
- Clone the fhEVM Hardhat Template:
git clone https://github.com/zama-ai/fhevm-hardhat-template.git private-fhe-tokens cd private-fhe-tokens yarn install - Spin Up the Local fhEVM Node:
This fires up a local, single-node testnet running custom FHE precompiles on portdocker compose up -d8545. - Compile Your Workspace:
yarn compile
Knowledge Checkpoint
- Identify the differences between a standard EVM balance variable (
uint256) and an fhEVM encrypted balance variable (euint32oreuint64). - Explain how a validator processes and verifies a block containing encrypted state updates without knowing the underlying values.
- Confirm your local fhEVM Hardhat environment is successfully connected to your running local Docker container.
Module 5: Developing and Deploying Confidential Tokens
In this module, you will design and implement a Confidential ERC-20 token contract. You will learn how to hide token balances, execute encrypted transfers, write robust tests, and deploy your contracts to a live fhEVM test network.
Recommended Videos
Why this video is valuable
This video details the mechanics of Confidential ERC-20 (cERC20) tokens. It walks through how balances are stored in encrypted mappings and how transactions (such as private transfers and hidden minting operations) are executed on-chain.
Why this video is valuable
This tutorial establishes the standard ERC-20 baseline. While standard ERC-20 uses public uint256 balances, watching this video first is crucial: it shows you the interface, logic flow, and state update patterns that you will transform into FHE-encrypted structures.
Step-by-Step implementation: From Standard ERC-20 to fhEVM Confidential Token
To implement a Confidential Token, we must modify the standard ERC-20 design by replacing plaintext balances with encrypted balances (euint32).
Here is a simplified code walkthrough of how FHE operations are applied using Zama’s fhevm Solidity library:
// SPDX-License-Identifier: BSD-3-Clause-Clear pragma solidity ^0.8.20;
import "fhevm/lib/TFHE.sol";
contract ConfidentialToken { // Plaintext owner, but encrypted balances address public owner; mapping(address => euint32) internal balances;
event Transfer(address indexed from, address indexed to);
constructor() {
owner = msg.sender;
// Mint an initial balance of 1000 tokens privately to the deployer
balances[msg.sender] = TFHE.asEuint32(1000);
}
// Transfers require an encrypted input argument (ebytes)
// The contract processes the subtraction and addition homomorphically!
function transfer(address to, bytes calldata encryptedAmount) public returns (bool) {
euint32 transferVal = TFHE.asEuint32(encryptedAmount);
// FHE logic: Check if sender has enough balance without revealing the values
ebool canTransfer = TFHE.le(transferVal, balances[msg.sender]);
// Compute new balances homomorphically based on execution condition
euint32 amountToMove = TFHE.select(canTransfer, transferVal, TFHE.asEuint32(0));
balances[msg.sender] = TFHE.sub(balances[msg.sender], amountToMove);
balances[to] = TFHE.add(balances[to], amountToMove);
emit Transfer(msg.sender, to);
return true;
}
}
Deploying Your Confidential Token
To deploy to the fhEVM test network, configure your hardhat.config.ts file to target the network's custom RPC and chain ID:
const config: HardhatUserConfig = { solidity: "0.8.24", networks: { fhevmTestnet: { url: "https://validator.fhe-testnet.zama.ai", chainId: 8009, accounts: [process.env.PRIVATE_KEY || ""], } } };
Execute the deployment using Hardhat:
npx hardhat run scripts/deploy.ts --network fhevmTestnet
Knowledge Checkpoint
- Explain how
TFHE.selectfunctions as an on-chain conditional branch without decrypting the data. - Write a Hardhat test that simulates a confidential transaction and asserts that balances are updated correctly.
- Successfully deploy your completed Confidential Token smart contract to the live fhEVM test network.
Module 6: Designing a Private Voting DApp on fhEVM
In this final module, you will design and build a private voting decentralized application. You will learn how votes remain completely encrypted throughout the ballot phase, and how the contract decrypts only the final tally at the end of the election using secure threshold decryption.
Recommended Videos
Why this video is valuable
This tutorial walks through the architectural flow of a decentralized voting platform. While it uses open, transparent variables, it provides a solid foundation for structuring ballot initialization, voter registration, and frontend UI logic. You will learn to swap the contract's public state updates with the secure FHE decryption model described below.
Why this video is valuable
This demo showcases Orion Finance's implementation of Zama's fhEVM in production environments. Watching this will help you understand how complex, multi-party computations are coordinated across user interfaces, decentralized smart contract networks, and secure backends.
Designing Secure Voting & Threshold Decryption
When building a private voting contract, individual votes must remain hidden from both validators and other users. However, at the end of the election, the total tally must be revealed.
The application architecture follows these security steps:
[Voter 1 (Vote: Encrypted "Yes")] ──┐ │ [Voter 2 (Vote: Encrypted "No")] ───┼─► [Smart Contract (Encrypted State)] │ Updates tally: Tally = Tally + Vote [Voter 3 (Vote: Encrypted "Yes")] ──┘ │ ▼ [Threshold Decryption Request] Validator committee aggregates keys │ ▼ [Public Decrypted Result Released]
-
Encrypted Ballot Submission: Voters submit their vote as an encrypted ciphertext payload. The smart contract validates their registration and adds their input homomorphically to the running aggregate sum:
euint32 private encryptedTally; function vote(bytes calldata encryptedBallot) public { require(!hasVoted[msg.sender], "Already voted"); euint32 userVote = TFHE.asEuint32(encryptedBallot); // Homomorphically add vote to running tally (1 for Yes, 0 for No) encryptedTally = TFHE.add(encryptedTally, userVote); hasVoted[msg.sender] = true; } -
Threshold Decryption Phase: Once voting is closed, the contract initiates a decryption request. Under the hood, validators on the network run a consensus protocol to generate decryption shares. No individual validator can decrypt the state on their own. Once the threshold of validator signatures is reached, the final plaintext tally is computed and written to the contract state.
Gaps & Independent Search Recommendation
Because threshold decryption and developer interfaces on fhEVM are evolving quickly, step-by-step videos for these integrations are limited. To implement threshold decryption in your dApp, read the official Zama fhEVM Decryption Documentation. Search github for the phrase TFHE.requestDecryption to find reference implementations of the callback structure.
Knowledge Checkpoint
- Draft a complete architectural flowchart explaining the lifecycle of a vote from client-side encryption to the final tally decryption.
- Define "threshold decryption" and explain how validator consensus secures the decryption key.
- Implement a function that locks user voting, triggers a decryption callback, and writes the plaintext tally to a public state variable.
Course Map
Below is the recommended pathway through the curriculum. Completing the modules in this order ensures you build a strong foundation in blockchain and cryptography before tackling complex FHE integrations.
Key People Index
- Pascal Paillier: Cryptographer and inventor of the Paillier Cryptosystem. His work on homomorphic encryption laid the foundation for modern practical homomorphic computation frameworks.
- Ilaria Chillotti: Director of Research at Zama and co-creator of the Torus Fully Homomorphic Encryption (TFHE) scheme. Her research focuses on making FHE computations fast and practical.
- Rand Hindi: Co-founder and CEO of Zama. He is a leading advocate for web3 privacy, working to secure on-chain transactions and shared state computations using FHE.
Final Self-Assessment
Test your mastery of the curriculum by completing this comprehensive self-assessment checklist.
- Explain why standard public blockchains are unable to natively protect transaction values, and why zero-knowledge proofs (ZKPs) alone struggle with multi-user shared state applications.
- Describe how fully homomorphic encryption (FHE) processes operations on encrypted data without ever decrypting it on-chain.
- Contrast the performance characteristics of homomorphic addition versus multiplication under the TFHE scheme.
- Define "bootstrapping" in FHE and explain its role in managing noise growth during execution.
- Successfully run a local fhEVM development node using Docker and confirm your connection in Hardhat.
- Implement a smart contract that processes encrypted variables using Zama's
TFHElibrary. - Write and deploy an ERC-20-like token with hidden balances and secure private transfers on the fhEVM test network.
- Explain how threshold decryption securely reveals the output of homomorphic calculations without exposing individual input variables.
- Design, deploy, and verify a decentralized voting application where votes remain encrypted and only the final tally is decrypted and revealed.



![[EN&CN]E65. 为什么150万亿传统金融上链需要隐私技术 \| The HTTPS Moment of Blockchain ft. @zama_fhe CEO Rand](https://i.ytimg.com/vi/qfl3lDhGomQ/maxresdefault.jpg)









