docs/solidity-guides/configure.md
This document explains how to enable encrypted computations in your smart contract by setting up the fhevm environment. Learn how to integrate essential libraries, configure encryption, and add secure computation logic to your contracts.
To utilize encrypted computations in Solidity contracts, you must configure the FHE library. The fhevm package simplifies this process with prebuilt configuration contracts, allowing you to focus on developing your contract's logic without handling the underlying cryptographic setup.
This library and its associated contracts provide a standardized way to configure and interact with Zama's FHEVM (Fully Homomorphic Encryption Virtual Machine) infrastructure on different Ethereum networks. It supplies the necessary contract addresses for Zama's FHEVM components (ACL, FHEVMExecutor, KMSVerifier, InputVerifier), enabling seamless integration for Solidity contracts that require FHEVM support.
By inheriting these configuration contracts, you ensure seamless initialization and functionality across environments.
The ZamaConfig library exposes functions to retrieve FHEVM configuration structs and contract addresses for supported networks (currently only the Sepolia testnet).
Under the hood, this library encapsulates the network-specific addresses of Zama's FHEVM infrastructure into a single struct (FHEVMConfigStruct).
The ZamaEthereumConfig contract is designed to be inherited by a user contract. The constructor automatically sets up the FHEVM coprocessor using the configuration provided by the library for the respective network. When a contract inherits from ZamaEthereumConfig, the constructor calls FHE.setCoprocessor with the appropriate addresses. This ensures that the inheriting contract is automatically wired to the correct FHEVM contracts for the target network, abstracting away manual address management and reducing the risk of misconfiguration.
Example
// SPDX-License-Identifier: BSD-3-Clause-Clear
pragma solidity ^0.8.24;
import { ZamaEthereumConfig } from "@fhevm/solidity/config/ZamaConfig.sol";
contract MyERC20 is ZamaEthereumConfig {
constructor() {
// Additional initialization logic if needed
}
}
isInitializedThe isInitialized utility function checks whether an encrypted variable has been properly initialized, preventing unexpected behavior due to uninitialized values.
Function signature
function isInitialized(T v) internal pure returns (bool)
Purpose
Example: Initialization Check for Encrypted Counter
require(FHE.isInitialized(counter), "Counter not initialized!");
By leveraging prebuilt a configuration contract like ZamaEthereumConfig in ZamaConfig.sol, you can efficiently set up your smart contract for encrypted computations. These tools abstract the complexity of cryptographic initialization, allowing you to focus on building secure, confidential smart contracts.