---
name: zama-fhevm-coprocessor-integration
description: Production-grade v6.1.0 elite guide to fhevm coprocessor integration on Zama FHEVM.
category: Foundation
difficulty: Advanced
version: "6.1.0"
---

# Zama FHEVM COPROCESSOR INTEGRATION

## Overview
This skill provides a comprehensive, production-grade implementation of fhevm coprocessor integration 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 fhevmcoprocessorintegration {
    // Encrypted state variable
    euint32 private secretData;

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

    // Core business logic for fhevm coprocessor integration
    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 coprocessor integration implementation. Focus on identifying potential information leaks through gas usage patterns or incorrect application of the branchless programming paradigm."