zama-fhevm-upgradable-contracts-uups-v2

star 0

Production-grade v6.1.0 elite guide to fhevm upgradable contracts uups v2 on Zama FHEVM.

nickthelegend By nickthelegend schedule Updated 4/26/2026

name: zama-fhevm-upgradable-contracts-uups-v2 description: Production-grade v6.1.0 elite guide to fhevm upgradable contracts uups v2 on Zama FHEVM. category: Operations difficulty: Advanced version: "6.1.0"

Zama FHEVM UPGRADABLE CONTRACTS UUPS V2

Overview

This skill provides a comprehensive, production-grade implementation of fhevm upgradable contracts uups v2 using Zama's Fully Homomorphic Encryption (FHE) Virtual Machine.

Architecture

mermaid graph TD User[User / AI Agent] -->|Encrypted Input| SC[Smart Contract] SC -->|Symbolic Task| Coprocessor[Coprocessor] Coprocessor -->|FHE Computation| KMS[KMS / Gateway] KMS -->|Encrypted Result| SC

Prerequisites

  • Mastery of encrypted types (euint8, euint32, etc.).
  • Understanding of the Zama Gateway and Coprocessor architecture.

Full Implementation

Smart Contract Logic

`solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.24;

import { FHE, euint32, ebureau } from "@fhevm/solidity/lib/FHE.sol";

contract fhevmupgradablecontractsuupsv2 { // Encrypted state variable euint32 private secretData;

constructor() {
    secretData = FHE.asEuint32(0);
}

// Core business logic for fhevm upgradable contracts uups v2
function executeTask(bytes calldata encryptedInput) public {
    euint32 input = FHE.asEuint32(encryptedInput);
    
    // Branchless logic using FHE.select
    secretData = FHE.select(FHE.gt(input, secretData), input, secretData);
    
    // Ensure availability
    FHE.allow(secretData, msg.sender);
}

} `

Deployment to Sepolia

  1. Configure your hardhat.config.ts with the Zama Sepolia RPC.
  2. Run the deployment script: ash npx hardhat run scripts/deploy.ts --network sepolia

Security Checklist

  • No Branching: Ensure no if or while statements rely on decrypted values.
  • Input Proofs: Validate all user-provided encrypted handles using FHE.asEuintXX.
  • Access Control: Use FHE.allow() and FHE.isAllowed() to manage visibility.

Common Pitfalls & Fixes

  • Handle Expiration: FHE handles are ephemeral; do not store them off-chain for long periods.
  • Gas Costs: FHE operations are computationally expensive; batch operations where possible.

AI Agent Prompt

"Act as a Zama FHEVM Senior Architect. Review this fhevm upgradable contracts uups v2 implementation. Focus on identifying potential information leaks through gas usage patterns or incorrect application of the branchless programming paradigm."

Install via CLI
npx skills add https://github.com/nickthelegend/zama-skills --skill zama-fhevm-upgradable-contracts-uups-v2
Repository Details
star Stars 0
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
nickthelegend
nickthelegend Explore all skills →