← Back to home

FHE2P

Our decentralised marketplace enables secure trading of encrypted vouchers like prepaid Visa cards using stablecoins.

Screenshots

FHE2P screenshot 1
FHE2P screenshot 2
FHE2P screenshot 3

Problem Statement

MA DescriptionGo in as much detail as you can about what this project is. Please be as clear as possible!This project, named FHE2P (Fully Homomorphic Encryption Peer-to-Peer), is a decentralized voucher marketplace implemented as a smart contract on a blockchain that supports Fully Homomorphic Encryption (FHE). Here's a detailed description of the project:Core Concept: It allows for the creation, sale, resale, and redemption of encrypted vouchers. The system uses FHE to maintain privacy and security of sensitive voucher data. Key Features: Voucher Creation: Administrators can create vouchers with encrypted codes and PINs. Buying and Reselling: Users can purchase vouchers directly or buy resold vouchers. Voucher Revelation: Owners can reveal their vouchers using a PIN. Metadata Retrieval: Public voucher information can be accessed without revealing private data. Privacy and Security: Voucher codes and PINs are stored in encrypted form. FHE allows for computations on encrypted data without decryption. Only the rightful owner can reveal a voucher's contents. Economic Model: Platform fees are applied to resold vouchers. Stablecoin integration for payments. Voucher Structure: Each voucher contains: Encrypted code and PIN Price Expiry date Owner and seller information Public metadata (image URL, description) User Interactions: Buying: Users can purchase available vouchers. Reselling: Owners can resell their unrevealed vouchers. Revealing: Owners can reveal their vouchers using the correct PIN. Viewing: Users can view available vouchers and their own purchased vouchers. Administrative Functions: Voucher listing Platform fee adjustment Emergency controls (pausing, fund withdrawal) Technical Implementation: Uses Solidity with FHE extensions. Integrates OpenZeppelin libraries for standard functionalities. Implements custom FHE operations for encrypted data handling. Use Cases: Gift card marketplaces Ticket reselling platforms Confidential coupon systems This project aims to create a secure, private, and flexible system for voucher trading, leveraging blockchain technology and advanced cryptography to ensure user privacy and data security while maintaining the functionality of a dynamic marketplace.

Solution

This FHE2P (Fully Homomorphic Encryption Peer-to-Peer) project was built using a combination of cutting-edge blockchain technologies and cryptographic techniques. Here's a detailed breakdown of how it was made:Core Technology Stack:Solidity (v0.8.20): The primary smart contract language.Fhenix Protocol: Leveraged for Fully Homomorphic Encryption capabilities.OpenZeppelin Contracts: Used for standard, secure implementations of common contract functionality.FHE Integration:Imported "@fhenixprotocol/contracts/FHE.sol" to access FHE operations.Utilized encrypted types like euint256, euint32, ebool, and eaddress for sensitive data.Implemented FHE operations (e.g., FHE.eq, FHE.lt, FHE.add) for computations on encrypted data.Voucher Structure:Designed a Voucher struct combining encrypted and public fields.Used euint256 for encrypted voucher codes and euint64 for PINs.Stored public metadata (price, expiry date, image URL, description) for easy retrieval.Smart Contract Architecture:Inherited from OpenZeppelin's Ownable, Pausable, and ReentrancyGuard for security.Implemented SafeERC20 for secure token transfers.Created a mapping of voucher IDs to Voucher structs for efficient storage and retrieval.Key Functionalities:Voucher Listing: Admins can list vouchers with encrypted and public data.Buying Mechanism: Implemented separate functions for buying new and resold vouchers.Reselling: Allows users to resell their unrevealed vouchers.Revelation: Users can reveal vouchers using encrypted PINs.Privacy-Preserving Features:Used FHE.sealoutput for secure revelation of voucher codes.Implemented encrypted comparisons for expiry checks and ownership verification.Metadata Handling:Created a separate VoucherMetaData struct for public information.Implemented functions to retrieve metadata for available vouchers and user-owned vouchers.Economic Model:Integrated a platform fee system for resold vouchers.Used SafeERC20 for secure stablecoin transfers.Security Measures:Implemented pause functionality for emergency situations.Added nonReentrant modifiers to prevent reentrancy attacks.Used require statements and FHE.req for validation checks.Optimization Techniques:Two-pass approach in metadata retrieval functions to optimize gas usage.Used uint32 for prices and expiry dates to save storage space.Notable "Hacky" Solutions:Used FHE.decrypt within view functions to check encrypted conditions, allowing for gas-efficient queries of encrypted data.Implemented a custom approach to handle encrypted booleans (ebool) in conditional logic.Partner Technologies:Fhenix Protocol: Enabled FHE operations, significantly enhancing the privacy and security of the system.OpenZeppelin: Provided battle-tested implementations of common contract patterns, improving security and reducing development time.Testing and Deployment:Developed on a local blockchain environment supporting FHE operations.Planned for deployment on Fhenix's testnet for real-world testing.This project demonstrates a novel approach to building a privacy-preserving marketplace by leveraging FHE in smart contracts. The combination of blockchain technology and advanced cryptography allows for a secure, private, yet transparent system for voucher trading.

Hackathon

ETHOnline 2024

2024

Contributors