Skip to content

dharmanan/winnerprice

Repository files navigation

WinnerPrice - FHE Auction App πŸ†

A Zama FHE project - production-ready privacy-preserving auction application powered by Fully Homomorphic Encryption (FHEVM) using Zama's official Relayer SDK.

Note: This project demonstrates real-world FHE implementation using the Zama FHEVM ecosystem. It's built following patterns from dharmanan/fhevm-react-template and deployed live on Vercel for public testing.

Deployed on Vercel License Tech Stack Zama Powered

🌐 Live Demo: https://winnerprice.vercel.app
πŸ“– Documentation: DEVELOPMENT_SUMMARY.md | README_LATEST.md


✨ What is WinnerPrice?

A privacy-preserving auction where:

  • βœ… All bids are encrypted with FHEVM - mathematically secure, never decrypted until reveal
  • βœ… Secret target price is never revealed during bidding
  • βœ… Winner is determined by closest bid to the secret price
  • βœ… MetaMask wallet integration for transaction signing
  • βœ… Real WASM-based encryption on client-side
  • βœ… Multi-bid auction (1 manual + 9 simulated bids)

Example Flow

1. User joins auction (pays entry fee, requires MetaMask signature)
2. User enters bid amount (stays private, encrypted with FHEVM)
3. System simulates 9 additional participant bids (all encrypted)
4. Auction ends automatically
5. Click "Reveal Winner" to see winner without ever decrypting bids

⚠️ Important: Architecture & Scope

What This Project IS βœ…

  • Production-ready working example of FHE-based auction logic
  • Real client-side FHEVM encryption using Zama Relayer SDK (v0.2.0)
  • Functional concept implementation showing FHE auction workflow
  • Ready for testing & demonstration on Sepolia testnet
  • Foundation for future on-chain reveal implementation

What This Project IS NOT ❌

  • Full on-chain FHE computation - Winner reveal is client-side (local computation)
  • Mainnet-ready - Currently deployed on Sepolia testnet only
  • Complete FHE solution - Demonstrates encryption flow, not full FHE operations on-chain
  • Production auction system - Proof of concept for educational/demonstration purposes

Future: Zama v0.9 & Beyond πŸš€

This implementation is designed to be upgraded when Zama releases:

  • FHEVM v0.9 - On-chain FHE key generation & computation
  • Relayer SDK v0.3.0+ - Enhanced on-chain reveal capabilities
  • Full homomorphic computation - Direct FHE operations on blockchain

Upgrade path ready: The current architecture supports migration to full on-chain FHE without major refactoring.


⚑ Quick Start

# Clone repository
git clone https://github.com/dharmanan/winnerprice
cd winnerprice

# Install dependencies
pnpm install

# Navigate to app
cd examples/nextjs-app

# Start development server
pnpm dev

Open http://localhost:5173


🎯 Choose Your Framework

The FHEVM SDK is completely framework-agnostic - the core encryption logic has zero dependencies. Pick your JavaScript environment and start encrypting in minutes:

Framework Type Setup Best For Status Start
React + Next.js Frontend 2 min Modern web apps with routing βœ… Production nextjs-app
Vue 3 Frontend 2 min Composition API, SFC support βœ… Production vue-example
Node.js Backend 1 min CLI, batch processing, CI/CD βœ… Production node-example
Vanilla JS Frontend 0 min No build, GitHub Pages, instant βœ… Production vanilla-js-example

All examples are identical functionally - they share the same:

  • βœ… Real FHEVM encryption (Relayer SDK v0.2.0)
  • βœ… TypeScript support (strict mode ready)
  • βœ… Error handling & logging
  • βœ… Copy-paste ready, production code

πŸ› οΈ Tech Stack

Frontend:    React 19.0.0
Build:       Vite 6.4.0
Styling:     Tailwind CSS 3.x
Crypto:      Zama FHEVM Relayer SDK 0.2.0
Web3:        ethers.js 5.7.2
Network:     Ethereum Sepolia Testnet
Deployment:  Vercel (auto-deploy on push)
Language:    TypeScript 5.x

🎯 Key Features

Feature Status Details
FHE Encryption βœ… Live Real Zama FHEVM Relayer SDK with WASM
MetaMask Integration βœ… Live Wallet connection & transaction signing
Sepolia Testnet βœ… Live Ethereum testnet deployment
Responsive UI βœ… Live Tailwind CSS with mobile support
Auto-Deployment βœ… Live GitHub β†’ Vercel auto-deploy pipeline
Winner Reveal βœ… Live Client-side computation (ready for on-chain upgrade)
Bid Simulation βœ… Live Simulate realistic auctions with 10 encrypted bids

πŸ“‚ Project Structure

winnerprice/
β”œβ”€β”€ examples/nextjs-app/              # Main React application
β”‚   β”œβ”€β”€ components/                   # UI components
β”‚   β”‚   β”œβ”€β”€ AuctionStatus.tsx        # Timer & participant display
β”‚   β”‚   β”œβ”€β”€ Header.tsx               # App header
β”‚   β”‚   β”œβ”€β”€ ProductDisplay.tsx       # Product showcase
β”‚   β”‚   β”œβ”€β”€ ProductSelector.tsx      # Product selection
β”‚   β”‚   β”œβ”€β”€ UserActions.tsx          # Join/Bid/Reveal controls
β”‚   β”‚   └── WinnerDisplay.tsx        # Winner information
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   └── useAuction.ts            # State management
β”‚   β”œβ”€β”€ App.tsx                       # Main component
β”‚   β”œβ”€β”€ types.ts                     # TypeScript interfaces
β”‚   β”œβ”€β”€ constants.ts                 # Product definitions
β”‚   └── vite.config.ts               # Build config
β”‚
β”œβ”€β”€ packages/
β”‚   └── fhevm-sdk/                    # FHEVM SDK package
β”‚       β”œβ”€β”€ core/                     # Non-hook functions
β”‚       β”‚   β”œβ”€β”€ encrypt.ts            # Bid encryption
β”‚       β”‚   β”œβ”€β”€ contract.ts           # Contract interaction
β”‚       β”‚   β”œβ”€β”€ relayer.ts            # Relayer SDK wrapper
β”‚       β”‚   β”œβ”€β”€ decrypt.ts            # Decryption utils
β”‚       β”‚   └── readWinner.ts         # Data reading
β”‚       β”œβ”€β”€ react/                    # React hooks
β”‚       β”‚   β”œβ”€β”€ useEncryptBid.ts      # Encryption hook
β”‚       β”‚   β”œβ”€β”€ useDecryptWinner.ts   # Decryption hook
β”‚       β”‚   └── useSubmitEncryptedBid.ts
β”‚       β”œβ”€β”€ ARCHITECTURE.md           # Design patterns & decisions
β”‚       └── API_REFERENCE.md          # Complete API docs
β”‚
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ nextjs-app/                   # React + Next.js demo
β”‚   β”œβ”€β”€ vue-example/                  # Vue 3 Composition API demo
β”‚   β”œβ”€β”€ node-example/                 # Node.js CLI & batch encryption
β”‚   └── vanilla-js-example/           # Single HTML file, zero deps
β”‚
β”œβ”€β”€ contracts/
β”‚   └── MockAuction.sol               # Smart contract for auction
β”‚
└── docs/
    β”œβ”€β”€ DEVELOPMENT_SUMMARY.md        # Technical deep-dive & issues
    └── README_LATEST.md              # Full feature documentation

πŸ“– Documentation

Document Purpose Read Time
DEVELOPMENT_SUMMARY.md Technical guide, all issues & solutions, architecture patterns 15 min
README_LATEST.md Full feature documentation, deployment, security details 10 min
packages/fhevm-sdk/ARCHITECTURE.md Design patterns & framework-agnostic decisions 10 min
packages/fhevm-sdk/API_REFERENCE.md Complete API docs & function references 15 min

πŸ§ͺ Usage

Connect Wallet

Click "Connect Wallet" β†’ Approve MetaMask popup

Select Product & Join

Select a product β†’ Click "Join Auction" β†’ Confirm MetaMask signature

Place Encrypted Bid

Enter bid amount ($1,000-$50,000) β†’ Click "Submit My Encrypted Bid"
Bid encrypted with FHEVM β†’ MetaMask signature required

Reveal Winner

Click "Reveal Winner" β†’ Winner calculated from closest bid
No bids ever decrypted - winner determined locally

πŸ” What is FHEVM?

Fully Homomorphic Encryption Virtual Machine (FHEVM) enables computation on encrypted data without decryption. Imagine an auction where bids are encrypted end-to-end - the contract determines a winner without ever seeing the bid amounts. That's FHEVM.

This SDK demonstrates production-grade FHEVM integration across all JavaScript environments.


πŸ’‘ How It Works

1. Core SDK (Zero Dependencies)

// Works ANYWHERE - browser, Node.js, Deno, even edge functions!
import { encryptBid } from 'fhevm-sdk/core';

const encrypted = await encryptBid(bidAmount, contractAddress);
// Returns: { handles: Uint8Array[], inputProof: Uint8Array }

2. Framework-Specific Hooks (Optional)

// React? Use the hook:
import { useEncryptBid } from 'fhevm-sdk/react';
const { encryptBid, isLoading } = useEncryptBid();

// Vue? Same SDK, different wrapper
// Node.js? Same SDK, no wrapper needed
// Vanilla JS? Same SDK, native await

3. Real FHEVM Encryption

  • Uses official Relayer SDK v0.2.0 from Zama
  • Encrypted on client-side (frontend)
  • Submitted via contract (backend)
  • Never exposed in plaintext

🧬 Origin & Framework

This project is inspired by & built upon:

  • 🎯 dharmanan/fhevm-react-template - Production FHEVM SDK architecture
  • πŸ“š Zama FHEVM Documentation - Core encryption concepts
  • πŸ”’ Zama Relayer SDK v0.2.0 - Official FHE encryption library

Developed for: Zama FHE community & education
License: MIT (open source, production-ready)


πŸ“– Using the SDK

For React/Vue Developers

  1. See DEVELOPMENT_SUMMARY.md
  2. Pick your framework
  3. Copy the integration code from your example app
  4. Done! βœ…

For Backend/Node.js Developers

  1. See node-example/README.md
  2. Import encryptBid from core
  3. Integrate into your pipeline
  4. No framework overhead! βœ…

For Advanced Users

  1. Read packages/fhevm-sdk/ARCHITECTURE.md
  2. Review packages/fhevm-sdk/API_REFERENCE.md
  3. Check examples/nextjs-app/ for real code
  4. Implement your own wrapper! βœ…

πŸ§ͺ Testing the Examples

Each example includes a multi-bid auction (1 manual + 9 simulated) that demonstrates real encryption:

# React - interactive UI with live simulation
cd examples/nextjs-app && pnpm install && pnpm dev

# Vue - same auction, different framework
cd examples/vue-example && pnpm install && pnpm dev

# Node.js - encrypt multiple bids programmatically
cd examples/node-example && pnpm install && node src/index.ts

# Vanilla JS - open in browser immediately
cd examples/vanilla-js-example && open index.html

All examples produce encrypted bids ready for contract submission. βœ…


πŸ”§ Common Tasks

Install Dependencies

cd winnerprice
pnpm install  # Installs all monorepo packages

Run Specific Example

cd examples/nextjs-app
pnpm dev --port 3000

Build for Production

cd examples/nextjs-app
pnpm build
pnpm start

TypeScript Compilation Check

pnpm tsc --noEmit  # Verify no errors

πŸ” Security

  • Client-side encryption: WASM-based real FHE, not mock
  • Zero-knowledge: Server never sees plaintext bids
  • Zama Relayer: Handles encryption key management
  • MetaMask signing: Required for all state changes
  • Testnet only: Current deployment on Sepolia (demo/testing)

🌐 Deployment

Vercel (Current - Live)

# Auto-deploy on push to main
# Manual redeploy: Vercel Dashboard β†’ Redeploy button

Environment Variables (Production)

VITE_RELAYER_ENDPOINT=https://relayer.testnet.zama.cloud
VITE_AUCTION_CONTRACT=0xb6E160B1ff80D67Bfe90A85eE06Ce0A2613607D1

⚠️ Known Limitations

  1. Testnet Only - Currently on Sepolia testnet (demo purposes)
  2. Browser Support - Requires WebAssembly support (all modern browsers)
  3. Gas Costs - Each encryption & transaction costs testnet gas
  4. Single Session - One product per session (refresh to change)
  5. Manual Reveal - Winner reveal not automated (requires button click)

πŸ“Š Performance

Build:       291 modules, 3.25 seconds
Bundle Size: 216 KB (gzipped: 67 KB) main
             292 KB (gzipped: 96 KB) vendor
Encryption:  ~2-3 seconds per bid (WASM FHE)
Deploy:      2-3 minutes to Vercel

πŸ“ Recent Updates

Session October 21-22, 2025

Fixed Issues:

  • βœ… Vercel deployment build failures
  • βœ… React hook context errors
  • βœ… Workflow integrity (MetaMask signatures required)
  • βœ… Winner reveal crashes
  • βœ… Removed all debug console.log statements
  • βœ… Cleanup unnecessary files

Improvements:

  • βœ… Production-ready codebase
  • βœ… Comprehensive documentation
  • βœ… Clear architecture & scope documentation

See DEVELOPMENT_SUMMARY.md for full details.


🀝 Contributing

Contributions welcome! Areas for improvement:

  • Mainnet deployment
  • On-chain winner reveal (FHEVM v0.9+)
  • More sophisticated auction types
  • Enhanced UI/UX
  • Additional test coverage

Contributing Steps

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

All contributions welcome! πŸ™Œ


πŸ™‹ Support & Resources


πŸ“„ License

MIT License - See LICENSE file for details


Made with ❀️ using Zama FHEVM technology

Status: βœ… Production Ready
Live: https://winnerprice.vercel.app
Last Updated: October 22, 2025

Releases

No releases published

Packages

 
 
 

Contributors