Configuration
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.
Core configuration setup
To utilize encrypted computations in Solidity contracts, you must configure the TFHE library and Gateway addresses. 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.
Key components configured automatically
TFHE library: Sets up encryption parameters and cryptographic keys.
Gateway: Manages secure cryptographic operations, including reencryption and decryption.
Network-specific settings: Adapts to local testing, testnets (Sepolia for example), or mainnet deployment.
By inheriting these configuration contracts, you ensure seamless initialization and functionality across environments.
ZamaFHEVMConfig.sol
This configuration contract initializes the fhEVM environment with required encryption parameters.
Import based on your environment:
Purpose:
Sets encryption parameters such as cryptographic keys and supported ciphertext types.
Ensures proper initialization of the FHEVM environment.
Example: using Sepolia configuration
ZamaGatewayConfig.sol
To perform decryption or reencryption, your contract must interact with the Gateway, which acts as a secure bridge between the blockchain, coprocessor, and Key Management System (KMS).
Import based on your environment
Purpose
Configures the Gateway for secure cryptographic operations.
Facilitates reencryption and decryption requests.
Example: Configuring the gateway with Sepolia settings
Using isInitialized
isInitialized
The isInitialized
utility function checks whether an encrypted variable has been properly initialized, preventing unexpected behavior due to uninitialized values.
Function signature
Purpose
Ensures encrypted variables are initialized before use.
Prevents potential logic errors in contract execution.
Example: Initialization Check for Encrypted Counter
Summary
By leveraging prebuilt configuration contracts like ZamaFHEVMConfig.sol
and ZamaGatewayConfig.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.
Last updated