mirror of
https://github.com/luxfhe/example-dapps.git
synced 2026-10-30 18:13:32 +00:00
3.4 KiB
3.4 KiB
Blind Auction
Core Concept
This is a privacy-preserving blind auction implemented using Fully Homomorphic Encryption (FHE) through the fhEVM. All bids and critical values are encrypted, ensuring that participants cannot see others' bids during the auction process.
Key Components
State Variables
highestBid: Encrypted current highest bid amountwinningTicket: Encrypted ticket corresponding to the highest biduserTickets: Mapping of user addresses to their encrypted ticketsbids: Mapping of user addresses to their encrypted bid amountsendTime: When the auction endsbeneficiary: Who receives the winning bid amounttokenContract: The ConfidentialERC20 token used for bidding
Process Flow
- Initialization
constructor(
address _beneficiary,
ConfidentialERC20 _tokenContract,
uint256 biddingTime,
bool isStoppable
)
- Sets up the auction with a beneficiary, token contract, duration, and whether it can be manually stopped
- Initializes encrypted state variables
- Bidding Process
function bid(einput encryptedValue, bytes calldata inputProof)
- Users submit encrypted bids
- For each bid:
- Transfers tokens from bidder to contract
- Assigns a random encrypted ticket to the bidder
- Updates highest bid if the new bid is higher
- Allows multiple bids from the same user
- Auction Conclusion The auction can end in two ways:
- Natural end when
endTimeis reached - Manual stop if
stoppableis true and owner callsstop()
- Winner Determination
function decryptWinningTicket()
function claim()
- After auction ends, winning ticket is decrypted
- Winner can claim by proving they hold the winning ticket
- First highest bidder wins in case of a tie
- Settlement
function auctionEnd()
function withdraw()
- Winning bid is transferred to beneficiary
- Non-winners can withdraw their bids
Privacy Features
- Encrypted Bids
- All bids are encrypted using FHE
- Neither participants nor observers can see bid amounts
- Even the contract owner cannot see the bids
- Ticket System
- Each bid gets an encrypted random ticket
- Winning ticket is only decrypted after auction ends
- Prevents front-running and bid manipulation
- Confidential Token Integration
- Uses ConfidentialERC20 for encrypted token transfers
- Bid amounts remain private throughout the process
Security Measures
- Time Controls
modifier onlyBeforeEnd()
modifier onlyAfterEnd()
- Strict timing controls for different phases
- Prevents actions at incorrect times
- Ownership Management
- Uses OpenZeppelin's Ownable2Step for secure ownership
- Owner can only stop auction if
stoppableis true
- Safe Token Handling
- Careful management of token transfers
- Prevents double-spending and ensures proper refunds
Advantages of This Design
- True Privacy: All sensitive information remains encrypted until necessary
- Fair Participation: No one can see others' bids during the auction
- Flexible Bidding: Users can update their bids multiple times
- Secure Settlement: Automated and secure distribution of tokens and refunds
- Verifiable Outcome: Winner can prove their win without revealing other bids
This implementation provides a robust, private, and fair auction mechanism suitable for confidential token sales or other private auction needs.