Skip to content

jimmychu0807/analytics-dapp-zama

Repository files navigation

Analytics dApp built on Zama fhEVM

Project Artifacts

Overview

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:

  1. 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.

    Question Set
  2. 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.

    Answer
  3. 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.

    Query Request
  4. 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:

Development

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.

project screenshot

About

Analytics dApp smart contract and web frontend built on Zama fhEVM

Resources

Stars

Watchers

Forks

Releases

No releases published