- Live Deployed App: https://zk-auction-dun.vercel.app/
- Deployed Preprod Contract:
b41e9f3039d8783040b27a6da5353a72c42f863b1878bad594af6e1fc76e5352(View on Explorer) - Demo Video: https://youtu.be/SgigJdq82VI
In traditional transparent blockchains, auction parameters such as the reserve price are fully public. This creates a significant disadvantage for sellers, as bidders will often wait until the last minute and bid exactly the reserve price, artificially suppressing the true market value of the item. Furthermore, bidders' identities and bidding strategies are completely visible, allowing competitors to track their behavior, maliciously outbid them, or front-run their transactions using MEV bots.
ZKAuction solves this by leveraging the Midnight Network's zero-knowledge (ZK) data protection capabilities. By utilizing ZK smart contracts (written in Compact), ZKAuction allows sellers to cryptographically hide their reserve price. Bidders can place bids freely without knowing the exact reserve limit. When the auction ends, the smart contract settles the auction and proves whether the highest bid met the hidden reserve priceβwithout ever revealing the reserve price itself! Additionally, bidder identities are kept strictly private and decoupled from their real wallet addresses.
ZKAuction heavily relies on Midnight's hybrid state model to ensure maximum privacy and security:
-
What an observer CAN learn (Public On-chain State):
reserve_commitment: A cryptographic hash of the reserve price and a random salt.highest_bid: The current highest bid amount.highest_bidder: A ZK-derived identity key (NOT the actual wallet address).status: Whether the auction is OPEN, SETTLED, or EXPIRED.bid_count: Total number of bids placed.
-
What an observer CANNOT learn (Private Zero-Knowledge Witness):
- Actual Reserve Price: Kept entirely secret on the seller's device.
- Seller's Private Salt: Used to generate the commitment; never touches the chain.
- Real Wallet Addresses: Hidden behind ZK proofs to prevent identity tracking.
- Bid History Correlation: Observers cannot determine who placed which bid.
The landing page welcoming users to the ZKAuction platform with a fully responsive, dark-mode glassmorphism design.
A sleek loading overlay that displays when the app is actively syncing state with the Midnight blockchain.
The main dashboard displaying live auctions, their ZK-protected states, and the highest ZK-derived bidder keys.
Sellers can easily create a new auction by entering their item details and a hidden reserve price.
Bidders can securely place bids on active auctions without ever seeing the hidden reserve price.
The platform clearly breaks down what data is visible on-chain and what is strictly protected by zero-knowledge proofs.
The ZKAuction smart contract is written in Compact (Midnight's specialized ZK DSL). It exposes four main circuits:
createAuction: Initializes the auction. The seller provides thereserve_priceand asaltas private witnesses. The circuit computes the hash and stores only thereserve_commitmentin the public state.placeBid: Allows anyone to place a bid. The circuit verifies that the new bid is higher than the currenthighest_bidand updates the public state accordingly.settle: Called by the seller to finalize the auction. The seller provides the originalreserve_priceandsalt. The circuit proves thathash(reserve_price, salt) == reserve_commitmentand securely evaluates if thehighest_bid >= reserve_price.withdrawExpired: If the auction reaches its end block without meeting the reserve, participants can safely withdraw their locked funds.
| Action / Type | Address / Hash | Explorer Link |
|---|---|---|
| Smart Contract Deployment | 2806e44f...acff |
View Transaction |
| Create Auction | dd318ad7...15d0 |
View Transaction |
| Place Bid | 2806e44f...acff |
View Transaction |
| Contract (Create Auction) | b41e9f30...5352 |
View Contract |
| Contract (Place Bid) | 13312f0e...adfd |
View Contract |
A snippet of our zero-knowledge smart contract written in Midnight's Compact language.
Verification of the core ZKAuction smart contract successfully deployed to the Midnight Preprod Network.
The on-chain transaction record of a seller securely creating a new auction with a hidden reserve commitment.
The on-chain transaction record of a bidder placing a bid, showing how actual wallet addresses remain private.
graph TD
A[Next.js Frontend] -->|API Routes| B(Prisma / Neon Postgres)
A -->|window.midnight.1am| C{1AM Wallet}
C -->|Sign Tx| D[Midnight Preprod Network]
A -->|Midnight JS SDK| D
A -->|Local ZK Proofs| E[Midnight Proof Server]
B -->|Store off-chain data| F[(Neon DB)]
D -->|Read on-chain state| A
sequenceDiagram
actor Seller
actor Bidder
participant ZKAuction App
participant Midnight Network
Seller->>ZKAuction App: Enter Item Name & Reserve Price
ZKAuction App->>ZKAuction App: Hash(Reserve Price, Salt)
ZKAuction App->>Midnight Network: createAuction(Commitment)
Midnight Network-->>ZKAuction App: Contract Deployed
Bidder->>ZKAuction App: View Active Auctions
Bidder->>ZKAuction App: Enter Bid Amount
ZKAuction App->>Midnight Network: placeBid()
Midnight Network-->>ZKAuction App: Highest Bid Updated
Seller->>ZKAuction App: Click "Reveal & Settle"
ZKAuction App->>Midnight Network: settle(Private Reserve Price, Salt)
Midnight Network-->>ZKAuction App: Auction Settled / Winner Declared
ZKAuction/
βββ app/ # Next.js App Router (Frontend)
β βββ api/ # API Routes for database interactions
β βββ auctions/ # Main Auction Dashboard page
β βββ globals.css # UI Design system (Tailwind)
βββ components/ # Reusable React components (Navbar, AuctionCard)
βββ contract/
β βββ src/
β βββ auction.compact # The Midnight ZK Smart Contract
β βββ auction.test.ts # Smart Contract automated tests
βββ hooks/ # Custom React hooks (e.g., useWallet)
βββ lib/ # Core logic and Midnight SDK integration
β βββ auction-api.ts # Wraps the Midnight JS SDK for auction interactions
β βββ providers.ts # Configures the 6 Midnight providers
β βββ prisma.ts # Database client
βββ prisma/ # Prisma schema for Neon Postgres DB
βββ public/ # Static assets and ZK compiled keys
βββ scripts/ # Utility deployment scripts
The smart contract is rigorously tested using Vitest and the Midnight testing environment to ensure the privacy and security of the ZK circuits.
How to run the tests locally:
# Install dependencies
npm install
# Run the test suite
npm test
All 15 rigorous test cases testing the ZK logic, privacy constraints, and auction lifecycle have passed successfully in the Midnight test environment.
If you are a judge or a new user wanting to run this project locally, follow these simple steps to set up your Midnight environment and start bidding!
ZKAuction interacts with the Midnight Network via the 1AM Wallet browser extension.
- Download the 1AM Wallet extension from the Chrome Web Store (or compatible Chromium browser).
- Create a new wallet and securely save your 24-word recovery phrase.
- Once created, click on the network dropdown at the top of the wallet and ensure it is set to Midnight Preprod (TestNet).
You need test tokens (tNIGHT) to deploy contracts and place bids.
- Copy your wallet address from the 1AM Wallet extension.
- Go to the Midnight Preprod Faucet.
- Paste your address, request tokens, and wait a few seconds. Your wallet will be funded!
Now that your wallet is ready, let's run the application.
# 1. Clone the repository
git clone https://github.com/thisisouvik/ZKAuction.git
cd ZKAuction
# 2. Install Node.js dependencies
npm install
# 3. Set up environment variables
# (You only need a Postgres database URL if you are testing the backend DB sync)
cp .env.example .env.local
# 4. Start the development server
npm run devOpen http://localhost:3000 in your browser. Click "Connect Wallet", approve the connection in your 1AM extension, and you are ready to create private auctions!
Future Enhancements:
- Dynamic Bidding: Implementing auto-bidding limits without revealing maximum bids.
- Multi-token support: Allowing bids in stablecoins or other Midnight-native tokens.
- NFT Integration: Extending the contract to officially transfer Midnight-native NFTs to the winner upon settlement.
Real World Applications:
- High-Value Art & Real Estate: Wealthy buyers often want to bid anonymously. Sellers want to ensure their minimum acceptable price is hidden to drive competitive bidding.
- Sealed-bid Procurements: Government and corporate contract bidding where prices must remain completely secret until the auction ends.
- DeFi Liquidations: Liquidating collateral privately without causing market panic or front-running by MEV bots.
Done in Midnight! Bug Fixedx in MidNight! Wallet started syncing in Daytime but finished in MidNight!
Thanks to the Midnight team for their support and guidance throughout the development of this project. Special thanks to the Midnight community for their feedback and testing assistance.