A repository that generates and maintains standalone Hardhat-based FHEVM example projects, plus GitBook-compatible documentation.
π Zama Bounty December 2025 Submission
This project provides automation tools and a set of working examples for building privacy-preserving smart contracts using Zama's FHEVM.
- Automation tools (TypeScript CLI) to scaffold a standalone repo per example
- Example contracts + tests covering required topics (access control, input proofs, anti-patterns, handles lifecycle, decryption patterns, etc.)
- GitBook-style docs generated from code annotations
- A pinned base template based on Zama's Hardhat template
Note: The frontend/ folder is an optional demo app.
This repo tracks a curated core set of standalone Hardhat repos under examples/ (18 examples). The full catalog lives in the registry (scripts/examples.ts, 32 examples) and can be generated locally.
First, clone and install dependencies:
git clone https://github.com/dharmanan/FHE-HUB.git
cd FHE-HUB
npm installnpm run create-example -- list# Using npm scripts
npm run create-example -- create encrypted-balance ./my-project
# Navigate and run
cd my-project
npm install
npm testThis regenerates the curated core set into examples/.
npm run build-examples -- --coreIf you want to generate all registry examples (32) into examples/, use:
npm run build-examplesTo keep this repo lightweight and reviewable, only the curated core set (18) is committed under examples/.
The other 14 examples live in the registry (scripts/examples.ts) and can be discovered/generated locally:
# List all available example keys (full registry)
npm run create-example -- list
# Generate one example repo
npm run create-example -- create encrypted-voting ./my-projectTracked core example keys (18):
encrypted-counterencrypted-arithmeticencrypted-equalityencrypted-encrypt-singleencrypted-encrypt-multipleencrypted-user-decrypt-singleencrypted-user-decrypt-multipleencrypted-public-decrypt-singleencrypted-public-decrypt-multipleencrypted-access-control-transientencrypted-input-proofencrypted-anti-patternsencrypted-handles-lifecycleoz-confidential-fungible-tokenoz-confidential-erc20-wrapperoz-confidential-vesting-walletoz-confidential-swapencrypted-blind-auction
Registry-only example keys (14):
encrypted-auctionencrypted-balanceencrypted-collateralencrypted-crowdfundencrypted-erc20encrypted-escrowencrypted-lotteryencrypted-multisigencrypted-predictionencrypted-raffleencrypted-swapencrypted-timelockencrypted-vaultencrypted-voting
The frontend currently demonstrates these flows live:
encrypted-collateral(encrypted collateralized borrowing / liquidation UI)- Private token faucet + encrypted transfer demo (see frontend/contracts/PrivateZamaToken.sol)
Frontend details (helpers + addresses): docs/FrontendDemo.md
Vercel demo URL: https://fhehub.vercel.app
cd frontend
npm install
npm run dev
# Open http://localhost:3000The smoke test generates standalone repos into output/.smoke/ and runs npm install + npm test for each.
CI note: GitHub Actions runs the smoke test on a curated core set (currently 18 examples) for reliability and runtime.
# Run the full suite
npm run smoke-test
# Run only a single example (useful when the last one fails)
npm run smoke-test -- --only encrypted-blind-auction
# Resume from a specific example key (runs that key and the rest)
npm run smoke-test -- --from oz-confidential-fungible-tokenNotes:
- Disk usage can grow quickly because each generated repo installs its own dependencies.
- The script cleans
node_modulesafter successful runs to avoid filling your Codespace. - If you want to keep
node_modulesfor debugging, set:SMOKE_KEEP_NODE_MODULES=true. - If you need to free space manually, it is safe to delete:
rm -rf output/.smoke.
The docs in this repo are GitBook-style markdown generated from the registry.
- Docs index: docs/README.md
- GitBook sidebar ("Summary"): docs/SUMMARY.md
This project uses JSDoc/TSDoc-style annotations for automated documentation generation:
/**
* @chapter basic
* @title Simple FHE Counter
* @description Tests encrypted counter increment operations using euint32.
*/
describe("MyCounter", function () {
/**
* @test Increment encrypted counter
* @description Creates an encrypted input of value 5, increments the counter.
*/
it("should increment counter", async function () {
// test code
});
});/**
* @title MyCounter
* @notice Simple encrypted counter demonstrating basic FHE operations
* @dev Showcases euint32 operations, encrypted input handling
* @chapter basic
*/
contract MyCounter is ZamaEthereumConfig {
// contract code
}@chapter- Categorizes examples (basic, access-control, decryption, etc.)@title- Human-readable title for documentation@description/@notice- Detailed explanation@test- Marks individual test cases@dev- Implementation details
The documentation generator (scripts/generate-docs.ts) parses these tags and generates GitBook-compatible markdown files automatically.
FHE-HUB/
βββ fhevm-hardhat-template/ # Base Hardhat template (copied into each example)
βββ scripts/ # Automation tools + registry source-of-truth
βββ examples/ # Tracked standalone repos (core 18)
βββ docs/ # Generated GitBook documentation
βββ output/ # Throwaway smoke-test output (gitignored)
βββ frontend/ # Optional demo app
βββ README.md
Generates complete, standalone FHEVM example repositories from the base template.
Features:
- Clones
fhevm-hardhat-template/base template - Uses the registry entry in scripts/examples.ts as source-of-truth (contract/test/doc strings)
- Updates deployment scripts with correct contract name
- Generates example-specific README.md
- Creates a ready-to-use, standalone repository
Usage:
ts-node scripts/create-fhevm-example.ts list
ts-node scripts/create-fhevm-example.ts create <example-key> <output-dir>Generates a project containing all examples from a specific category.
Features:
- Groups registry examples by category
- Generates a standalone project that contains all examples for that category
- Generates unified deployment script
- Creates comprehensive README
- Perfect for learning multiple related concepts
Usage:
ts-node scripts/create-fhevm-category.ts <category> [output-dir]Creates GitBook-formatted documentation from contract and test files.
Features:
- Generates markdown from the registry entries
- Generates formatted markdown
- Updates SUMMARY.md index
- Organizes by category
Usage:
npm run generate-docs-
Add an entry in scripts/examples.ts
- Pick a stable example key (kebab-case)
- Provide
contractCode,testCode, anddocumentation
-
Regenerate docs
npm run generate-docs
-
Regenerate the standalone repo
npm run build-examples -- --only <example-key>
-
Generate Documentation
npm run generate-docs
-
Test Standalone Repository
npm run create-example -- create <example-key> ./test-output cd test-output npm install && npm run compile && npm run test
FHEVM uses encryption binding where values are bound to [contract, user] pairs:
- Encryption Binding: Values encrypted locally, bound to specific contract/user
- Input Proofs: Zero-knowledge proofs attest correct binding
- Permission System: Both contract and user need FHE permissions
β Correct Usage:
// Granting permissions (pattern varies by example)
FHE.allowThis(encryptedValue);
FHE.allow(encryptedValue, msg.sender);
// Encrypted operations
euint64 result = FHE.add(a, b);@fhevm/solidity- Core FHEVM Solidity libraryhardhat- Development environment@nomicfoundation/hardhat-toolbox- Testing toolstypescript- Type-safe automation scripts
- FHEVM Docs: https://docs.zama.ai/fhevm
- Protocol Examples: https://docs.zama.org/protocol/examples
- Base Template: https://github.com/zama-ai/fhevm-hardhat-template
- OpenZeppelin Confidential: https://github.com/OpenZeppelin/openzeppelin-confidential-contracts
Built for Zama Bounty December 2025: Build The FHEVM Example Hub
This project demonstrates:
- β Automated scaffolding tools - TypeScript CLI for generating example repositories
- β JSDoc/TSDoc documentation - Code annotations with @chapter tags for automated docs
- β Category-based organization - Examples grouped by functionality (basic, access-control, decryption, etc.)
- β Complete example coverage - 32 examples in registry, 18 core examples tracked
- β TypeScript-based automation - create-fhevm-example, create-fhevm-category, generate-docs
- β GitBook-compatible documentation - Auto-generated from code annotations
- β OpenZeppelin integration - Latest @openzeppelin/confidential-contracts v0.3.0
- β Comprehensive testing - Smoke tests, edge cases, error handling examples
- β Maintenance tools - Dependency management, bulk updates, test automation
β Project Structure & Simplicity
- Hardhat-only setup
- One repo per example
- Minimal structure
- Shared base template
β Scaffolding / Automation
create-fhevm-example.tsCLI toolcreate-fhevm-category.tsfor grouped examples- Automated template cloning and customization
- Auto-generated documentation from annotations
β Required Examples
- Basic: Counter, Arithmetic, Equality β
- Encryption: Single & Multiple values β
- User Decryption: Single & Multiple β
- Public Decryption: Single & Multiple β
- Access Control: allow() & allowTransient() β
- Input Proofs: Validation & explanation β
- Anti-patterns: Common mistakes & fixes β
- Handles Lifecycle: Handle generation & usage β
- OpenZeppelin: ERC7984, Wrapper, Swap, Vesting Wallet β
- Advanced: Blind Auction β
β Documentation Strategy
- JSDoc/TSDoc-style comments in tests β
- NatSpec @chapter tags in contracts β
- Auto-generated GitBook-compatible docs β
- Tag-based organization (@chapter, @test, @title) β
π₯ Video Demonstration
- οΏ½ Watch the full demo: YouTube Video
- Includes: Setup, CLI demos, example generation, test execution, and automation showcase
- Total Examples: 32 (registry)
- Core Tracked: 18 examples
- Test Coverage: Comprehensive with edge cases
- Documentation: Fully automated from code annotations
- CI/CD: GitHub Actions smoke test integration
MIT License - see LICENSE for details
This is a bounty submission. Feedback and suggestions are welcome!
- GitHub: @dharmanan
- Repository: FHE-HUB
Built with β€οΈ using FHEVM by Zama