A decentralized platform for opinion markets, hot takes, and belief-based betting using Fully Homomorphic Encryption (FHE) for privacy-preserving transactions.
- Encrypted Betting: Place confidential bets using ZAMA FHEVM with zero knowledge leakage
- Homomorphic Encryption: Vote tallies computed without revealing individual choices
- Temporal Privacy: Results hidden until official market resolution
- Cryptographic Verification: Oracle-based decryption with signature validation
- Binary Markets: Yes/No prediction markets on any topic
- Fixed Stake Betting: Equal betting amounts set by market creators (min 0.005 ETH)
- Flexible Duration: Markets from 5 minutes to 30 days
- Proportional Payouts: Winners split prize pool based on participation
- Real-time Activity: Live market updates and community activity feeds
- Comment System: Discussion threads for each market
- Leaderboards: User rankings based on market participation
- Community Engagement: Social betting with gamified elements
- Multi-Wallet Support: MetaMask, Rainbow, and other Web3 wallets
- Gas Optimization: Efficient smart contract interactions
- Transaction Safety: Comprehensive error handling and validation
- Cross-Platform: Responsive design for mobile and desktop
- Frontend: React 19.1.0 + TypeScript 5.8.3 + Vite 6.3.5
- Styling: Tailwind CSS 4.1.8 with custom mint/orange design system
- Smart Contracts: Solidity ^0.8.24 with ZAMA FHE integration
- Blockchain: Ethereum Sepolia testnet + ZAMA FHEVM
- Privacy Layer: ZAMA Fully Homomorphic Encryption (FHE)
- Wallet Connection: RainbowKit 2.2.8 + Wagmi 2.15.6
- Ethereum Interaction: Ethers.js 5.8.0
- Contract Development: Hardhat 2.25.0
- FHE Client: ZAMA fhevm-core libraries
-
Clone the repository
git clone <repository-url> cd conviction-app
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env # Add your WalletConnect Project ID VITE_WALLETCONNECT_PROJECT_ID=your_project_id -
Start development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173
Our test suite provides complete coverage of all FHE operations used in the BeliefMarket contract:
# Run all tests
npm test
# Run only FHE tests
npx hardhat test --grep "FHE"
# Run specific test files
npx hardhat test test/BeliefMarketFHE.comprehensive.cjs
npx hardhat test test/BeliefMarketFHE.missing-operations.cjs BeliefMarketFHE - Comprehensive FHE Operations
Testing FHE operations with different weights...
Casting votes with different weights...
Testing FHE.toBytes32 and decryption...
✅ FHE.select() - Conditional weight addition works
✅ FHE.eq() - Vote type comparison works
✅ FHE.add() - Encrypted addition with different weights works
✅ FHE.allowThis() - External access permissions work
✅ FHE.toBytes32() - Conversion for decryption works
✅ FHE.requestDecryption() - Oracle request works
✅ FHE.checkSignatures() - Decryption verification works
✔ tests all FHE operations: select, eq, add, allowThis, toBytes32 (127ms)
Testing invalid input proof...
✅ FHE.fromExternal() correctly rejects invalid proofs
✅ FHE.fromExternal() accepts valid proofs
✔ tests FHE error handling: invalid proofs and malformed inputs
Testing zero weight...
Testing large weight...
✅ FHE operations handle zero weights correctly
✅ FHE operations handle large weights correctly
✔ tests FHE operations with edge cases: zero weights, maximum values (68ms)
Testing complex FHE computation chains...
✅ Complex FHE computation chains work correctly
✅ Multiple FHE operations in sequence produce correct results
✅ FHE state management across multiple votes works
✔ tests complex FHE computation chains: multiple operations in sequence (120ms)
BeliefMarketFHE - FHE E2E (mock)
✔ encrypts votes, casts, requests reveal via oracle mock, and resolves (51ms)
Creating encrypted votes for 8 users...
Casting votes...
Requesting tally reveal...
Waiting for decryption oracle...
Funding prize pool...
Checking reveal results...
FHE voting test completed successfully!
✅ 8 users voted with encrypted weights
✅ FHE decryption revealed correct totals (5 YES, 3 NO)
✅ YES won by majority
✅ Prize pool funded and ready for distribution
✔ comprehensive FHE test: 10 users with different weights, majority wins, prize distribution (150ms)
BeliefMarketFHE - Missing FHE Operations Tests
✅ FHE.select() operation works correctly
✅ Conditional weight addition based on vote type works
✔ tests FHE.select() operation - conditional weight addition (58ms)
✅ FHE.eq() operation works correctly
✅ Encrypted equality comparison for vote types works
✔ tests FHE.eq() operation - encrypted equality comparison (72ms)
✅ FHE.add() operation works correctly with different weights
✅ Weighted voting through encrypted addition works
✔ tests FHE.add() with different weights - weighted voting (68ms)
✅ FHE.allowThis() operation works correctly
✅ External access permissions for encrypted values work
✔ tests FHE.allowThis() - external access permissions
✅ FHE.toBytes32() operation works correctly
✅ Conversion for decryption requests works
✔ tests FHE.toBytes32() - conversion for decryption requests (53ms)
✅ FHE.checkSignatures() operation works correctly
✅ Decryption proof verification works
✔ tests FHE.checkSignatures() - decryption proof verification (39ms)
BeliefMarketFHE
✔ sets owner on deploy
✔ owner can update platformStake
✔ createBet succeeds with correct stake and params
✔ createBet reverts on incorrect stake, low voteStake, invalid duration, duplicate id
✔ requestTallyReveal guard checks: only creator and after expiry
✔ claimPrize/claimRefund reverts when not resolved
✔ full flow: simulate votes, resolve yes win, winner claims prize
✔ full flow: tie -> refund path
FHECounter
✔ encrypted count should be uninitialized after deployment
✔ increment the counter by 1 (51ms)
✔ decrement the counter by 1 (41ms)
FHECounterSepolia
This hardhat test suite can only run on Sepolia Testnet
- increment the counter by 1
23 passing (1s)
1 pending
| Operation | Purpose | Status |
|---|---|---|
FHE.select() |
Conditional weight addition based on vote type | ✅ |
FHE.eq() |
Encrypted equality comparison for vote types | ✅ |
FHE.add() |
Encrypted addition with different weights | ✅ |
FHE.allowThis() |
External access permissions for encrypted values | ✅ |
FHE.toBytes32() |
Conversion for decryption requests | ✅ |
FHE.requestDecryption() |
Oracle decryption requests | ✅ |
FHE.checkSignatures() |
Decryption proof verification | ✅ |
FHE.fromExternal() |
Input validation and error handling | ✅ |
- 23 passing tests with comprehensive FHE coverage
- Edge cases: Zero weights, large weights, invalid inputs
- Complex scenarios: Multiple operations in sequence, weighted voting
- Error handling: Invalid proofs, malformed inputs
- Integration testing: End-to-end FHE voting workflows
- Build:
npm run build - Preview:
npm run preview - Lint:
npm run lint
Visit /docs in the app for comprehensive documentation including:
- Architecture overview
- Usage guide
- FAQ
- Technical references
The platform is built around the BeliefMarketFHE smart contract which leverages ZAMA's Fully Homomorphic Encryption (FHE) for privacy-preserving betting:
contract BeliefMarketFHE {
struct BetInfo {
address creator;
uint256 platformStake; // 0.02 ETH platform fee
uint256 voteStake; // Min 0.005 ETH per bet
uint256 expiryTime; // 5 minutes to 30 days
bool isResolved;
euint64 yesVotes; // Encrypted vote tally
euint64 noVotes; // Encrypted vote tally
uint64 revealedYes; // Decrypted results
uint64 revealedNo; // Decrypted results
uint256 prizePool; // Total ETH staked
bool yesWon; // Winner determination
}
}- All votes are encrypted client-side using ZAMA FHE before blockchain submission
- Vote choices (Yes/No) and amounts remain hidden until market resolution
- Uses
euint64encrypted integers for vote tallies
// Votes are aggregated without revealing individual choices
bet.yesVotes = FHE.add(bet.yesVotes, FHE.select(isYes, weight, zero));
bet.noVotes = FHE.add(bet.noVotes, FHE.select(isNo, weight, zero));- After market expiry, only the creator can request vote decryption
- ZAMA oracle service decrypts the tallies via
requestDecryption() - Results are revealed through a cryptographic callback mechanism
- Creator pays platform fee (0.02 ETH)
- Sets minimum bet amount (≥0.005 ETH)
- Defines market duration (5 minutes - 30 days)
- Market becomes active for betting
- Users place encrypted bets with equal stakes
- Vote choices encrypted using FHE before submission
- Real-time bet counting without revealing individual votes
- Prize pool accumulates with each bet
- Market expires, betting closes
- Creator requests tally decryption from ZAMA oracle
- Oracle decrypts vote totals and triggers callback
- Winner determined by majority vote (Yes > No or vice versa)
- Winners claim proportional share of prize pool
- Ties result in full refunds to all participants
- One-time claiming with replay protection
// Winner's prize = (Total Prize Pool × User Stake) ÷ Total Winning Stakes
prize = (prizePool * userStake) / totalWinningWeight- Reentrancy protection on all state-changing functions
- Input validation and access controls
- Emergency pause functionality
- Overflow protection with SafeMath operations
- Zero Knowledge: Individual vote choices never revealed on-chain
- Encrypted Aggregation: Vote tallies computed homomorphically
- Temporal Privacy: Results hidden until official resolution
- Cryptographic Proofs: ZAMA oracle provides verifiable decryption
- Market metadata and parameters
- Encrypted vote tallies (
euint64) - Prize pool and resolution status
- User participation tracking
- Market descriptions and metadata
- User comments and social features
- Activity feeds and leaderboards
- Real-time UI updates
graph TB
A["React Frontend"] --> B["RainbowKit Wallet"]
A --> C["Firebase Firestore"]
A --> D["ZAMA FHE Client"]
D --> E["BeliefMarketFHE Contract"]
E --> F["ZAMA Oracle Network"]
B --> G["Ethereum/Sepolia"]
E --> G
F --> E
C --> H["Real-time Updates"]
H --> A
- Fully Homomorphic Encryption: All betting data encrypted using ZAMA FHEVM
- Zero Information Leakage: Individual votes never revealed until resolution
- Cryptographic Verification: Oracle-based decryption with signature validation
- Secure Wallet Integration: RainbowKit handles wallet connections securely
[beliefprotocol.netlify.app]
Built with ❤️ using ZAMA FHE