Skip to content

Admuad/PolyBid

Repository files navigation

PolyBid πŸ”

Privacy-Preserving Sealed-Bid Auctions on Blockchain

Built with Zama's fhEVM

License: MIT Solidity React fhEVM

🎯 The Problem

Traditional blockchain auctions suffer from critical privacy issues:

  • Front-running: Bots can see pending bids and outbid users
  • Bid sniping: Last-second bids exploit transparent bid amounts
  • Privacy leaks: All losing bids are permanently visible on-chain
  • Trust issues: Users must trust centralized platforms for sealed-bid auctions

πŸ’‘ Our Solution

PolyBid leverages Fully Homomorphic Encryption (FHE) to create truly private, trustless sealed-bid auctions directly on the blockchain. Bid amounts remain encrypted throughout the entire auction lifecycle, with the smart contract computing the winner without ever decrypting losing bids.

Key Innovation

Unlike commit-reveal schemes or zero-knowledge proofs, FHE allows:

  • βœ… Real-time bid validation (opening price checks) on encrypted values
  • βœ… On-chain winner determination without revealing any bid amounts
  • βœ… Permanent privacy for losing bidders (no reveal phase needed)
  • βœ… Trustless execution with no centralized components

πŸ—οΈ Architecture

Smart Contract Layer (Solidity + fhEVM)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   AuctionFactory.sol                    β”‚
β”‚  β€’ Creates new Auction contracts (Factory Pattern)      β”‚
β”‚  β€’ Stores auction metadata (IPFS images, descriptions)  β”‚
β”‚  β€’ Tracks all deployed auctions                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β”‚ deploys
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Auction.sol                        β”‚
β”‚                                                         β”‚
β”‚  FHE Operations:                                        β”‚
β”‚  β€’ submitBid(euint64 encryptedBid) - Store encrypted    β”‚
β”‚  β€’ TFHE.max(bid1, bid2) - Compare without decryption   β”‚
β”‚  β€’ amITheWinner() β†’ ebool - Private winner check        β”‚
β”‚                                                         β”‚
β”‚  Privacy Features:                                      β”‚
β”‚  β€’ ACL (Access Control Lists) for encrypted data        β”‚
β”‚  β€’ Only bidder can decrypt their own bid status         β”‚
β”‚  β€’ Winner revealed only after auction closes            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Frontend Layer (React + Viem + Zama SDK)

User Input (plaintext bid)
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Zama FHE SDK           β”‚
β”‚  β€’ Client-side encrypt  β”‚
β”‚  β€’ Generate proof       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
    euint64 + proof
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Smart Contract         β”‚
β”‚  β€’ Validate proof       β”‚
β”‚  β€’ Store encrypted bid  β”‚
β”‚  β€’ Compare with TFHE    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

✨ Features

πŸ”’ Privacy-First Design

  • Encrypted Bidding: All bid amounts encrypted client-side using Zama's FHE SDK
  • Anonymous Identities: Wallet addresses displayed as "Anon-XXXX" throughout the UI
  • Private Winner Checks: Users can verify if they won without revealing their bid
  • No Reveal Phase: Losing bids remain encrypted forever

🎨 Premium User Experience

  • Responsive Design: Mobile-first UI with TailwindCSS
  • Gmail-Style FAB: Floating Action Button for quick auction creation
  • Real-time Updates: Live auction countdowns and bid notifications
  • Smooth Animations: Framer Motion for polished interactions
  • IPFS Integration: Decentralized image storage via Pinata

πŸ›‘οΈ Security & Validation

  • Opening Price Enforcement: Bids validated against minimum price (encrypted)
  • Deposit Locking: Bid amounts locked until auction closes
  • Network Guards: Auto-switch to Sepolia testnet
  • Input Sanitization: XSS protection and address validation
  • Error Handling: User-friendly error messages for all edge cases

πŸ“Š Comprehensive Profile Dashboard

  • Selling Tab: Track auctions you've created (Active/Pending/Ended)
  • Buying Tab: Monitor your bids and check win status
  • Wallet Integration: RainbowKit for seamless wallet connection
  • Transaction History: Complete audit trail of all actions

πŸš€ Live Demo

Deployed on Sepolia Testnet

Quick Start (Local)

# Clone the repository
git clone https://github.com/Admuad/PolyBid.git
cd PolyBid

# Install dependencies
cd frontend && npm install
cd ../contracts && npm install

# Configure environment
cp frontend/.env.example frontend/.env.local
# Add your WalletConnect Project ID and Pinata keys

# Run frontend
cd frontend && npm run dev

Visit http://localhost:5173 and connect your wallet!


πŸ§ͺ Testing

Smart Contract Tests

cd contracts
npm test

Test Coverage:

  • βœ… Auction creation with opening price
  • βœ… Encrypted bid submission and validation
  • βœ… Winner determination using FHE comparisons
  • βœ… ACL permissions for encrypted data
  • βœ… Refund and withdrawal mechanisms
  • βœ… Edge cases (zero bids, expired auctions, etc.)

Frontend Testing

cd frontend
npm run lint
npm run build  # Validates TypeScript compilation

Manual Testing Checklist:

  • βœ… Create auction with IPFS image upload
  • βœ… Submit encrypted bid above opening price
  • βœ… Update bid (increase amount)
  • βœ… Close auction and reveal winner
  • βœ… Check win status (FHE decryption)
  • βœ… Claim refund (losing bidders)
  • βœ… Withdraw proceeds (seller)
  • βœ… Mobile responsiveness (all breakpoints)

πŸ“– How It Works

1️⃣ Create Auction

Seller creates an auction with:

  • Item name, description, and image (stored on IPFS)
  • Duration (minutes/hours/days)
  • Opening price (minimum bid)
  • 0.0001 ETH deposit (reward for auction closer)

2️⃣ Submit Encrypted Bids

Bidders:

  1. Enter bid amount in the UI
  2. Frontend encrypts the bid using Zama's FHE SDK
  3. Smart contract validates: encryptedBid >= encryptedOpeningPrice
  4. Bid amount locked as deposit

3️⃣ Close Auction

Anyone can close an expired auction:

  • Contract computes maxBid = TFHE.max(bid1, bid2, ...)
  • Winner determined without decrypting any bids
  • Closer receives 0.0001 ETH reward

4️⃣ Claim Funds

  • Winner: Contacts seller to arrange item transfer
  • Losers: Withdraw their bid deposits (refunds)
  • Seller: Withdraws winning bid amount

πŸŽ“ Technical Deep Dive

FHE Implementation Details

Encrypted Bid Storage:

mapping(address => euint64) private bids;  // Encrypted bid amounts
mapping(address => bool) public hasBid;    // Public participation flag

Encrypted Comparison:

function submitBid(einput encryptedAmount, bytes calldata inputProof) external payable {
    euint64 bid = TFHE.asEuint64(encryptedAmount, inputProof);
    
    // Compare encrypted bid with encrypted opening price
    ebool isValid = TFHE.ge(bid, openingPrice);
    require(TFHE.decrypt(isValid), "Bid below opening price");
    
    bids[msg.sender] = bid;
    TFHE.allow(bid, msg.sender);  // ACL: bidder can decrypt their own bid
}

Winner Determination:

function closeAuction() external {
    euint64 maxBid = bids[bidders[0]];
    
    for (uint i = 1; i < bidders.length; i++) {
        maxBid = TFHE.max(maxBid, bids[bidders[i]]);
    }
    
    // Winner is determined, but maxBid value remains encrypted!
}

Why This Matters

Traditional sealed-bid auctions require a reveal phase, exposing all bids. PolyBid's FHE approach:

  • Eliminates reveal phase entirely
  • Protects bidder privacy permanently
  • Enables trustless on-chain execution
  • Prevents collusion and manipulation

πŸ› οΈ Tech Stack

Layer Technology Purpose
Smart Contracts Solidity 0.8.28 Core auction logic
Zama fhEVM Encrypted computation
Hardhat Development & testing
Frontend React 18 + TypeScript UI framework
Vite Build tool
TailwindCSS Styling
Wagmi v2 + Viem Blockchain interaction
RainbowKit Wallet connection
Framer Motion Animations
Storage IPFS (Pinata) Decentralized images
Network Sepolia Testnet Deployment

🎯 Zama Developer Program Alignment

βœ… Baseline Requirements (50%)

Original Tech Architecture (35%)

  • Custom factory pattern for scalable auction deployment
  • Unique FHE integration: encrypted opening price validation
  • Novel ACL usage for privacy-preserving winner checks
  • Not boilerplate - built from scratch with Zama primitives

Working Demo Deployment (15%)

  • Live deployment on Sepolia testnet
  • Fully functional end-to-end flow
  • IPFS integration for production-ready UX

βœ… Quality & Completeness (30%)

Testing (10%)

  • Comprehensive Hardhat test suite
  • Manual testing checklist (documented above)
  • Edge case coverage (zero bids, expired auctions, etc.)

UI/UX Design (10%)

  • Premium, modern interface with dark mode
  • Mobile-responsive (tested on all breakpoints)
  • Intuitive user flows with helpful error messages
  • Smooth animations and loading states

Presentation Video (10%)

  • Watch the Demo Video
  • Walkthrough of create β†’ bid β†’ close β†’ claim flow
  • Explanation of FHE privacy benefits

βœ… Differentiators (20%)

Development Effort (10%)

  • 7 development phases completed (see task.md)
  • 50+ components and hooks
  • Comprehensive error handling and validation
  • Production-ready code quality

Business Potential (10%)

  • Target Market: NFT auctions, real estate, procurement
  • Competitive Advantage: Only truly private on-chain auctions
  • Scalability: Factory pattern enables unlimited auctions
  • Monetization: Transaction fees, premium features
  • Roadmap: Multi-chain deployment, DAO governance, advanced auction types

πŸ—ΊοΈ Roadmap

Phase 1: Core Platform βœ…

  • FHE-encrypted bidding
  • Factory pattern deployment
  • Profile dashboard
  • IPFS integration

Phase 2: Advanced Features 🚧

  • Dutch auctions (descending price)
  • Multi-item auctions (batch bidding)
  • Auction templates (NFTs, real estate, etc.)
  • Reputation system

Phase 3: Ecosystem Growth πŸ“…

  • Multi-chain deployment (Polygon, Arbitrum)
  • DAO governance for platform fees
  • Mobile app (React Native)
  • API for third-party integrations

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines.

Development Setup

# Install dependencies
npm install

# Run tests
cd contracts && npm test

# Start local dev server
cd frontend && npm run dev

# Lint code
npm run lint

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Zama for pioneering FHE technology and the fhEVM
  • Polynomial for the branding inspiration
  • Sepolia Testnet for reliable testing infrastructure
  • Zama Developer Program for the opportunity to build confidential dApps

πŸ“ž Contact


Built with πŸ’š using Zama's FHE technology
Making blockchain auctions private, fair, and trustless

About

A private Auction Marketplace using on Fully Homomorphic Encryption by Zama

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published