Decrypting multiple encrypted values (ebool, euint32, euint64) for a user. Highlights that each value requires individual permission grants, as there is no batching for FHE.allow() or FHE.allowThis().
To run this example correctly, make sure the files are placed in the following directories:
.sol file → <your-project-root-dir>/contracts/
.ts file → <your-project-root-dir>/test/
This ensures Hardhat can compile and test your contracts as expected.
🔐 FHE API Reference (10 items)
Types:ebool · euint32 · euint64
Functions:
FHE.add() - Homomorphic addition: result = a + b (overflow wraps)
FHE.allow() - Grants PERMANENT permission for address to decrypt/use value
FHE.allowThis() - Grants contract permission to operate on ciphertext
FHE.asEbool() - Encrypts a plaintext boolean into ebool
FHE.asEuint32() - Encrypts a plaintext uint32 value into euint32
FHE.asEuint64() - Encrypts a plaintext uint64 value into euint64
FHE.xor() - Homomorphic bitwise XOR
// SPDX-License-Identifier: BSD-3-Clause-Clearpragmasolidity^0.8.24;import {FHE, ebool, euint32, euint64}from"@fhevm/solidity/lib/FHE.sol";import {ZamaEthereumConfig}from"@fhevm/solidity/config/ZamaConfig.sol";/** * @notice Decrypting multiple encrypted values (ebool, euint32, euint64) for a user. * Highlights that each value requires individual permission grants, * as there is no batching for FHE.allow() or FHE.allowThis(). * * @dev Individual permissions are required for each encrypted value. */contractUserDecryptMultipleValuesisZamaEthereumConfig{ ebool private _encryptedBool; euint32 private _encryptedUint32; euint64 private _encryptedUint64;/// @notice Initialize multiple values from plaintext/// @dev FHE.asEuintX() creates encrypted constants from plaintextfunctioninitialize(boola,uint32b,uint64c)external{// Create encrypted values from plaintext _encryptedBool = FHE.xor(FHE.asEbool(a), FHE.asEbool(false)); _encryptedUint32 = FHE.add(FHE.asEuint32(b), FHE.asEuint32(1)); _encryptedUint64 = FHE.add(FHE.asEuint64(c), FHE.asEuint64(1));// ⚠️ Why separate? No batching for permissions - each needs individual allow() FHE.allowThis(_encryptedBool); FHE.allowThis(_encryptedUint32); FHE.allowThis(_encryptedUint64); FHE.allow(_encryptedBool,msg.sender); FHE.allow(_encryptedUint32,msg.sender); FHE.allow(_encryptedUint64,msg.sender);}functionencryptedBool()publicviewreturns(ebool){return _encryptedBool;}functionencryptedUint32()publicviewreturns(euint32){return _encryptedUint32;}functionencryptedUint64()publicviewreturns(euint64){return _encryptedUint64;}}