Skip to main content

AI-powered FHE smart contract generator for Fhenix CoFHE

Project description

SolAgent-FHE

AI-powered FHE (Fully Homomorphic Encryption) smart contract generator for Fhenix CoFHE.

Generate privacy-preserving Solidity contracts from natural language descriptions. The AI understands FHE patterns, encrypted types, access control, and compiles contracts automatically using Hardhat.

Installation

pip install solagent-fhe

Requirements: Node.js 18+ and the cofhe-hardhat-starter project for compilation.

Quick Start

CLI

# Generate a contract from description
solagent-fhe "Create a private voting contract with encrypted vote counts"

# Use a predefined task
solagent-fhe --task-key voting

# Run benchmark (all 9 contract types)
solagent-fhe --benchmark

# List available tasks
solagent-fhe --list-tasks

# Use Groq instead of DeepSeek
solagent-fhe --provider groq "Create a sealed-bid auction"

Python API

import asyncio
from solagent_fhe import generate, benchmark, FHE_TASKS

async def main():
    # Generate a single contract
    result = await generate(
        task="Create a private token with encrypted balances",
        contract_name="MyToken",
        provider="deepseek",  # or "groq"
    )

    if result['compiled']:
        print(f"Contract generated: {result['name']}.sol")
        print(f"Refine rounds: {result['rounds']}")
        print(result['code'])

    # Run full benchmark
    results = await benchmark(provider="deepseek")

asyncio.run(main())

Environment Variables

Variable Required Description
DEEPSEEK_API_KEY Yes* DeepSeek API key for code generation
GROQ_API_KEY Yes* Groq API key (alternative provider)
SOLAGENT_HARDHAT_DIR No Path to cofhe-hardhat-starter (auto-detected)

*At least one LLM provider key required.

Supported Contract Types

Key Contract Description
voting ConfidentialVoting Encrypted vote counts, admin-controlled
auction SealedBidAuction Hidden bids, FHE comparison for winner
token PrivateToken ERC20-like with encrypted balances
lottery BlindLottery FHE random number for winner selection
threshold SecretThreshold Encrypted threshold comparison
payroll ConfidentialPayroll Hidden salaries, batch payments
dex PrivateDEX Encrypted swap amounts and balances
dao PrivateDAO Encrypted voting power and tallies
vault FHESavingsVault Encrypted deposits with interest

How It Works

Description ──→ [Code Agent] ──→ Solidity ──→ [Hardhat Compile]
                  (DeepSeek)        │              │
                                    │         ✓ Success → Done
                                    │              │
                                    │         ✗ Errors
                                    │              │
                                    └──→ [Refine Agent] ──→ Fix ──→ Recompile
                                          (Groq/DeepSeek)     (up to 10 rounds)

Benchmark: 5/5 contracts compile successfully (100%)

FHE Patterns

The generator understands all Fhenix CoFHE patterns:

  • Encrypted types: euint8euint256, ebool, eaddress
  • Operations: FHE.add, FHE.sub, FHE.select, FHE.gte, etc.
  • Access control: FHE.allowThis(), FHE.allow(ct, addr)
  • Decryption: Async FHE.decrypt() + getDecryptResultSafe()
  • Random: FHE.randomEuint32() for on-chain randomness
  • Input: InEuint64 for client-encrypted values

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solagent_fhe-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solagent_fhe-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file solagent_fhe-0.1.0.tar.gz.

File metadata

  • Download URL: solagent_fhe-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for solagent_fhe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bedac791c054f7ce8dc8ed9e33e00aaa8926991082cfbbc1722b9c5b5f359178
MD5 df16f02c1b65ac4343f08fdfa86c009c
BLAKE2b-256 096dad96b2f0bb5220b50f2d373d02833f6aae35ee793cee4712371aa23e7b35

See more details on using hashes here.

File details

Details for the file solagent_fhe-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: solagent_fhe-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for solagent_fhe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76a2e4e7dec6f9da1f8a7fa963a32f5f549be9e28aeb2bfcab1d95ed73234535
MD5 eb64f0ad072dee703f9fd32e9992e1c4
BLAKE2b-256 7c5d9188fb18926bfd1e49654d06cb03cc19b065d1b399b17a1b91fbf5757e45

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page