- 🌐 Project website
- 📜 Smart Contracts
- Analytic.sol: 0x5366a157ca0FD369B843Acd1CfB15f31B541ccF3 on Sepolia
- QuestionSpecLib.sol: 0x0Ea37D3264b940C94D68DA1EB34C291D62Ba8Ab5 on Sepolia
- 🎥 Demo Video - watch this first (at 1.2x speed) for a quick overview of the project and its features.
- 📝 Writeup
This repo is a solution for Zama Bounty Season 8: Build a Confidential Benchmarking and Polling System On-chain
This confidential polling dApp offers the following features:
-
The question creator can define a question set consisting of a main question and up to four meta questions. Each question can be either an option where the respondent selects one choice, or a value with specified minimum and maximum bounds.
Example 1:
- Main: Which L2 chain do you use most? (options: OP Mainnet, Base, Arbitrum, Zk Sync).
- Meta 1: Your Gender (option: male, female)
- meta 2: Your Age (value: 18 - 150)
Example 2:
- Main: What is your annual salary (USD)? (value: 0 - 100,000,000)
- Meta 1: Your Gender (option: male, female)
In practice, the meta question is capped to four in the application.
-
Respondent answer sets are encrypted client-side before being sent on-chain. The encrypted answer set is validated by the smart contract to ensure values fall within the specified range, leveraging Fully Homomorphic Encryption provided by the fhEVM library. After validation, the validity flag (a boolean) is decrypted. If the answer set is valid, it is stored on-chain.
-
When a question set reaches its query threshold, the question creator can raise a Query Request with zero or multiple predicates. If the main question is an Option type, all matching answers are tallied and displayed. If the main question is a Value type, the system computes the minimum, sum, and maximum. A predicate can apply to any meta question, using operators such as equal, not equal, greater than or equal, or less than or equal.
-
After a Query Request is created, the question creator must execute the query request to process the answers. This involves accumulating FHE-encrypted answer values, which can be gas-intensive. A
steps
parameter specifies how many answers to process at a time, writing intermediate results to storage. In practice, processing 5 - 8 answers per step balances execution count with the 3,000,000 FHE gas limit per block.Once a Query Request is fully processed, the result is re-encrypted and decrypted client-side.
For more details on data structures and development approach, see:
- hardhat package - refer to Development Approach for details.
- web package
To run the project locally:
cd /project-folder
# Install all the dependencies
pnpm install
# Setup the .env files
cp .env.dev .env
cd packages/hardhat
ln -sf .env ../../.env
cd ../web
ln -sf .env ../../.env
cd ../..
# Build the frontend
pnpm build
# Build the smart contract and run unit tests
pnpm test
# Kickstart a hardhat node, fhEVM mock server, and the web front end
pnpm dev
Visit http://localhost:3010 to view the app.