Skip to main content

AI-powered FHE smart contract generator for Fhenix CoFHE

Project description

Division 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.

Built by Sunima

Installation

pip install division-fhe

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

Quick Start

CLI

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

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

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

# List available tasks
division-fhe --list-tasks

# Use Groq instead of DeepSeek
division-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)

410 passing tests, 14 deployed contracts, 100% compilation rate

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

division_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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: division_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 division_fhe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b7f1428080c02b70885d8745fe69d09a58f50266dbeba248bac35f6ea1391465
MD5 ff89634cbb34666f2b677ee0f4749d95
BLAKE2b-256 c1658659a8cb48833fdad6a62c7b1191837cdb2b1c2ab6701d48d23f71b4fcc2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: division_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 division_fhe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d523eb79818b0c14ac69759829e021783d7c2b3f5fb5f84de56b95de75b3b61
MD5 293ffbcd39f2d9b7d9b471bbcb006eb5
BLAKE2b-256 ce0bd95e39637ab8965b5dc0839e997f005dcc73323784f90bff1cc6c2f954eb

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