This repository provides a starter template for building applications on the Enclave Protocol. It offers a starting point for developers to create, activate, and interact with E3 rounds within the protocol. The template includes both server-side infrastructure and tools for writing secure zkVM-based computations (using RISC Zero).
The server plays a critical role in:
- Listening to protocol events (e.g., Key Publish, Input Publish).
- Managing the progression of E3 rounds by taking actions like gathering encrypted votes, computing tallies, and publishing results.
- Serving as a reliable nudge layer for the protocol.
Additionally, this repository includes an example of a voting application built on top of the Enclave Protocol, designed for securely processing and tallying encrypted votes off-chain.
For a more detailed example, check out CRISP.
The repository structure is organized to support modular development, with separate packages for server-side functionality, zkVM guest programs, and smart contracts:
.
├── packages
│ ├── server # Server implementation for interacting with the protocol
│ ├── risc0 # RISC Zero-based zkVM application and smart contracts
│ └── ... # Additional dependencies and modules
Key directories:
packages/server
: Implements the server to listen to blockchain events, handle user inputs, and nudge the protocol forward.packages/risc0
: Includes RISC Zero zkVM programs, smart contracts, and supporting libraries for secure computation.
Before you begin, ensure you have the following installed:
-
Rust: Install Rust via rustup:
curl https://sh.rustup.rs -sSf | sh
-
Foundry: Install Foundry via Foundry's installation script:
curl -L https://foundry.paradigm.xyz | bash
-
RISC Zero Tools: Install the RISC Zero toolchain:
curl -L https://risczero.com/install | bash rzup
Verify installation:
cargo risczero --version
cd packages/server
cargo build
Follow the RISC Zero Foundry Template for detailed documentation. A summary is provided below:
-
Update Git submodules:
git submodule update --init
-
Build the zkVM program and Rust code:
cd packages/risc0 cargo build
-
Build the Solidity smart contracts (requires
cargo build
to be run first):forge build
The server acts as a "nudger," ensuring smooth protocol progression by:
- Listening to blockchain events (e.g.,
E3 Key Published
,Round Ended
). - Aggregating encrypted user inputs.
- Processing tallies using zkVM logic and publishing results.
Key subdirectories:
blockchain
: Handles interactions with the blockchain, including event listeners and transaction relayers.routes
: Defines API endpoints for interacting with the server.models
: Contains data structures and models for the server.database
: Manages the storage and retrieval of encrypted votes and results.
This package provides the zkVM environment for secure computations:
apps
: Interfaces for interacting with the zkVM and Ethereum.contracts
: Smart contracts for verifying proofs and interacting with the Enclave Protocol.CRISPRisc0.sol
: Main contract for zkVM proof verification.ImageID.sol
: Contract for zkVM image identifiers.
core
: Core business logic for zkVM guest computations.methods
: zkVM guest programs that run off-chain to perform secure computations.
To build your application on the Enclave Protocol using this starter template, follow these steps:
-
Set Up Interaction with the Enclave Contract:
- Implement a method for users to submit encrypted votes to the Enclave contract. This can be a web-based client, a mobile app, or another frontend solution.
-
Run the Server:
- Use the server to handle protocol events and interact with the blockchain.
- The server nudges the protocol forward by activating rounds and processing inputs.
-
Write Your Secure zkVM Logic:
- Implement the core secure process logic in
packages/risc0/core/src/lib.rs
. This code runs off-chain in the RISC Zero zkVM and performs computations like vote tallying. - Write the zkVM guest program in
packages/risc0/methods/src/lib.rs
. This program is executed by the zkVM to perform secure computations. - Write the application logic in
packages/risc0/apps/src/lib.rs
. This code is executed by the server to interact with the zkVM.
- Implement the core secure process logic in
-
Deploy Smart Contracts:
- Write and deploy the on-chain logic in
packages/risc0/contracts/CRISPRisc0.sol
. This contract verifies zkVM proofs and publishes results back to the Enclave contract.
- Write and deploy the on-chain logic in