From 0f5641a438ace086bbb0f3bfdaf3995403365f77 Mon Sep 17 00:00:00 2001 From: 0xjei Date: Fri, 10 Oct 2025 14:07:27 +0200 Subject: [PATCH 1/5] update CRISP readme --- examples/CRISP/Readme.md | 188 ++++++++++++++---- examples/CRISP/package.json | 1 - .../ICiphernodeRegistry.json | 4 +- .../interfaces/IEnclave.sol/IEnclave.json | 4 +- .../NaiveRegistryFilter.json | 2 +- .../enclave-contracts/deployed_contracts.json | 49 ++++- 6 files changed, 200 insertions(+), 48 deletions(-) diff --git a/examples/CRISP/Readme.md b/examples/CRISP/Readme.md index feb492f557..c9a57a9bbe 100644 --- a/examples/CRISP/Readme.md +++ b/examples/CRISP/Readme.md @@ -1,43 +1,36 @@ # CRISP - Coercion-Resistant Impartial Selection Protocol -Welcome to the CRISP project! This document provides a comprehensive guide to setting up and deploying the application both locally. Follow the steps carefully to ensure that all dependencies, services, and components are properly configured. +CRISP (Coercion-Resistant Impartial Selection Protocol) is a secure protocol for digital decision-making, leveraging fully homomorphic encryption (FHE) and distributed threshold cryptography (DTC) to enable verifiable secret ballots. Built with Enclave, CRISP safeguards democratic systems and decision-making applications against coercion, manipulation, and other vulnerabilities. To learn more about CRISP, you can read our [blog post](https://blog.enclave.gg/crisp-private-voting-secret-ballot-fhe-zkp-mpc/) or visit the [documentation](https://docs.enclave.gg/CRISP/introduction). ## Project Structure +CRISP follows a modern structure with clear separation of concerns + +```bash +CRISP/ +|── client/ # React frontend application +|── server/ # Rust coordination server +|── program/ # RISC Zero computation program +├── contracts/ # Smart contracts (Solidity) +├── circuits/ # Noir circuits for ZK proofs +├── scripts/ # Development and utility scripts +├── enclave.config.yaml # Ciphernode configuration ``` -CRISP -├── Dockerfile - Dockerfile for a local development environment -├── client -├── server -├── wasm-crypto -├── contracts - Contracts for the CRISP protocol -├── docker-compose.yaml -└── scripts - Scripts for the CRISP protocol, including setup and testing -``` - -## Development -To start the development environment, run the following commands from inside the CRISP directory: +You can have an extended explanation of the single folders in the dedicated [documentation](https://docs.enclave.gg/CRISP/introduction#project-structure). -```sh -pnpm install # install dependencies -pnpm dev:setup # build the project -pnpm dev:up # run the services -``` +# Usage -The two commands above will start everything you need to run the CRISP protocol. You can then interact with it using the web application at `http://localhost:3000`. Please ensure you follow the prerequisites installation for running the protocol locally. - -## Prerequisites for running without Docker - -Before getting started, make sure you have the following tools installed: +## Prerequisites -- **Rust** -- **RISC Zero toolchain** (not needed for development only) -- **Foundry** and **Anvil** (for local testnet) -- **Node.js** (for client-side dependencies) -- **Pnpm** (as Node package manager) +Before getting started, ensure you have installed: -## Dependencies +- [Rust](https://rust-lang.org/tools/install/) +- [Foundry](https://getfoundry.sh) +- [RiscZero](https://dev.risczero.com/api/zkvm/install) +- [NodeJS](https://nodejs.org/en/download) +- [pnpm](https://pnpm.io) +- [Metamask](https://metamask.io) ### Install Node @@ -47,6 +40,10 @@ You can install Node following the official [documentation](https://nodejs.org/e You can install Pnpm following the official [documentation](https://pnpm.io/installation). +### Install Metamask + +You can add Metamask as extension to your browser following the official [documentation](https://metamask.io). + ### Install Rust and Foundry You need to install Rust and Foundry first. After installation, restart your terminal. @@ -79,7 +76,113 @@ cargo risczero --version At this point, you should have all the tools required to develop and deploy an application with [RISC Zero](https://www.risczero.com). -## Setting Up the project +## Environment + +You need to setup your environment variables for `client/` and `server/`. Just copy and paste the `.env.default` as `.env` and overwrite with your values the following variables (you can leave the others initialized with the default values). + +### Client + +```bash +VITE_E3_PROGRAM_ADDRESS=0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44 # Default E3 program address from anvil +VITE_SEMAPHORE_ADDRESS=0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE +``` + +### Server + +```bash +ENCLAVE_ADDRESS="0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" +CIPHERNODE_REGISTRY_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" +NAIVE_REGISTRY_FILTER_ADDRESS="0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" +E3_PROGRAM_ADDRESS="0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44" # CRISPProgram Contract Address +``` + +These address will be displayed after successfully running the `pnpm dev:up` command in a log that will look like the following: + +```bash +[DEPLOY] Script ran successfully. +[DEPLOY] +[DEPLOY] == Logs == +[DEPLOY] Deploying on ChainID 31337 +[DEPLOY] Using config profile: custom +[DEPLOY] Using MockRISC0Verifier +[DEPLOY] Deployed MockRISC0Verifier to 0x0B306BF915C4d645ff596e518fAf3F9669b97016 +[DEPLOY] Enclave Address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +[DEPLOY] Verifier Address: 0x0B306BF915C4d645ff596e518fAf3F9669b97016 +[DEPLOY] Deployed SemaphoreNoirVerifier to 0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1 +[DEPLOY] Deployed Semaphore to 0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE +[DEPLOY] Deployed CRISPCheckerFactory to 0x68B1D87F95878fE05B998F19b66F4baba5De1aed +[DEPLOY] Deployed CRISPPolicyFactory to 0x3Aa5ebB10DC797CAC828524e59A333d0A371443c +[DEPLOY] Using CRISPInputValidator +[DEPLOY] Deployed InputValidator to: 0xc6e7DF5E7b4f2A278906862b61205850344D4e7d +[DEPLOY] Deployed CRISPInputValidatorFactory to 0x59b670e9fA9D0A427751Af201D676719a970857b +[DEPLOY] Deployed HonkVerifier to 0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1 +[DEPLOY] Deployed CRISPProgram to 0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44 +[DEPLOY] Enabled E3 Program on Enclave +``` + +If you find any inconsistency with the addresses on the environment, you must update them and run the script again (they must match). + +## Quick Start + +The fastest way to get CRISP running is using the scripts provided in the `scripts/` directory: + +```bash +# Install dependencies +pnpm install + +# Setup and build the development environment +pnpm dev:setup + +# Start all services (Anvil, Ciphernodes, Applications) +pnpm dev:up + +# Clean up all artifacts and generated output (e.g., builds) +# This must be run from enclave root (do cd ../../ if you are inside examples/CRISP) +pnpm clean +``` + +This will: + +- Start Anvil (local blockchain) +- Deploy all contracts +- Compile all ZK circuits +- Start the ciphernode network +- Launch all CRISP applications + +```bash +# Build the development containers +pnpm dev:setup + +# Start all services +pnpm dev:up + +# Rebuild containers +pnpm dev:build + +# Invoke the Server CLI +pnpm cli +``` + +Once everything is running, you can: + +1. Navigate `http://localhost:3000` for the client interface +2. Add the Anvil private key to your wallet: `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` +3. Press `Connect Wallet` button and complete the association with your MetaMask account +4. Switch to `Anvil` local network (this will be handled automatically by the app. You just need to press on the connected account on the frontend and select the network. Then, complete the configuration on MetaMask pop-up). +5. Open a new terminal, run `pnpm cli` and start a new E3 Round. +6. Refresh and interact with the round following the Client interface. + +Before getting started, make sure you have the following tools installed: + +- **Rust** +- **RISC Zero toolchain** (not needed for development only) +- **Foundry** and **Anvil** (for local testnet) +- **Node.js** (for client-side dependencies) +- **Pnpm** (as Node package manager) + +## Manual Start + +### Setting Up the project 1. Navigate to the root directory: @@ -93,7 +196,7 @@ At this point, you should have all the tools required to develop and deploy an a pnpm install ``` -## Setting Up the Web App +### Setting Up the Web App To set up the CRISP dApp in your local environment, follow these steps: @@ -102,13 +205,14 @@ To set up the CRISP dApp in your local environment, follow these steps: ```sh cd examples/CRISP/client ``` + 2. Start the development server: ```sh pnpm dev ``` -## Setting Up the CRISP Server +### Setting Up the CRISP Server Setting up the CRISP server involves several components, but this guide will walk you through each step. @@ -128,7 +232,7 @@ Keep Anvil running in the terminal, and open a new terminal for the next steps. git clone https://github.com/gnosisguild/enclave.git ``` -2. Navigate to the `evm` directory: +2. Navigate to the `enclave-contracts` directory: ```sh cd enclave/packages/enclave-contracts @@ -164,9 +268,9 @@ After deployment, you will see the addresses for the following contracts: Note down the first four addresses as they will be needed to configure `risc0`, `local_testnet` and the `server`. -### Step 3: Deploy the RISC Zero Contracts +### Step 3: Deploy the RISC Zero Contracts -> Please note that this step is optional for development only. You can run the program server in dev mode which does not use Risc0. +> Please note that this step is optional for development only. You can run the program server in dev mode which does not use Risc0. 1. Navigate to the `CRISP/lib/risc0-ethereum` directory. @@ -227,6 +331,7 @@ Create a `.env` file in the `server` directory with the following: PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 ENCLAVE_SERVER_URL=http://0.0.0.0:4000 HTTP_RPC_URL=http://127.0.0.1:8545 +PROGRAM_SERVER_URL=http://127.0.0.1:13151 WS_RPC_URL=ws://127.0.0.1:8545 CHAIN_ID=31337 @@ -235,15 +340,16 @@ CRON_API_KEY=1234567890 # Based on Default Anvil Deployments (Only for testing) ENCLAVE_ADDRESS="0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" -CIPHERNODE_REGISTRY_ADDRESS="0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" -NAIVE_REGISTRY_FILTER_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" -E3_PROGRAM_ADDRESS="0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1" # CRISPProgram Contract Address +CIPHERNODE_REGISTRY_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" +NAIVE_REGISTRY_FILTER_ADDRESS="0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" +E3_PROGRAM_ADDRESS="0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44" # CRISPProgram Contract Address # E3 Config -E3_WINDOW_SIZE=600 +E3_WINDOW_SIZE=40 E3_THRESHOLD_MIN=1 E3_THRESHOLD_MAX=2 -E3_DURATION=600 +E3_DURATION=160 + # E3 Compute Provider Config E3_COMPUTE_PROVIDER_NAME="RISC0" E3_COMPUTE_PROVIDER_PARALLEL=false @@ -255,7 +361,7 @@ E3_COMPUTE_PROVIDER_BATCH_SIZE=4 # Must be a power of 2 To run three ciphernodes, use the following command inside the CRISP directory: ```sh -./scripts/dev_ciphernodes.sh +./scripts/dev_cipher.sh ``` This script will start the ciphernodes, add the ciphernodes to the registry on chain. diff --git a/examples/CRISP/package.json b/examples/CRISP/package.json index a7fd07bfc3..2a221246d3 100644 --- a/examples/CRISP/package.json +++ b/examples/CRISP/package.json @@ -14,7 +14,6 @@ "dev:setup": "bash ./scripts/setup.sh", "dev:build": "bash ./scripts/build.sh", "dev:up": "bash ./scripts/dev.sh", - "dev:down": "bash ./scripts/clean.sh", "test:e2e": "bash ./scripts/test_e2e.sh", "test": "pnpm test:e2e", "test:contracts": "hardhat test tests/crisp.contracts.test.ts --network localhost", diff --git a/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json b/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json index 6fcabb0550..1aa8abfd67 100644 --- a/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json +++ b/packages/enclave-contracts/artifacts/contracts/interfaces/ICiphernodeRegistry.sol/ICiphernodeRegistry.json @@ -219,5 +219,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/interfaces/ICiphernodeRegistry.sol", - "buildInfoId": "solc-0_8_27-9aea5e3f6e25811e781e96c22e8edaf1eb1a01c5" -} \ No newline at end of file + "buildInfoId": "solc-0_8_27-97c5c59c2349d6c07bd9b7583fed40a5ace84d56" +} diff --git a/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json b/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json index 7af0578553..e8f3c4bc25 100644 --- a/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json +++ b/packages/enclave-contracts/artifacts/contracts/interfaces/IEnclave.sol/IEnclave.json @@ -704,5 +704,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/interfaces/IEnclave.sol", - "buildInfoId": "solc-0_8_27-9aea5e3f6e25811e781e96c22e8edaf1eb1a01c5" -} + "buildInfoId": "solc-0_8_27-97c5c59c2349d6c07bd9b7583fed40a5ace84d56" +} \ No newline at end of file diff --git a/packages/enclave-contracts/artifacts/contracts/registry/NaiveRegistryFilter.sol/NaiveRegistryFilter.json b/packages/enclave-contracts/artifacts/contracts/registry/NaiveRegistryFilter.sol/NaiveRegistryFilter.json index 88b78ae36f..60a39695bf 100644 --- a/packages/enclave-contracts/artifacts/contracts/registry/NaiveRegistryFilter.sol/NaiveRegistryFilter.json +++ b/packages/enclave-contracts/artifacts/contracts/registry/NaiveRegistryFilter.sol/NaiveRegistryFilter.json @@ -305,5 +305,5 @@ "deployedLinkReferences": {}, "immutableReferences": {}, "inputSourceName": "project/contracts/registry/NaiveRegistryFilter.sol", - "buildInfoId": "solc-0_8_27-9aea5e3f6e25811e781e96c22e8edaf1eb1a01c5" + "buildInfoId": "solc-0_8_27-97c5c59c2349d6c07bd9b7583fed40a5ace84d56" } \ No newline at end of file diff --git a/packages/enclave-contracts/deployed_contracts.json b/packages/enclave-contracts/deployed_contracts.json index 906896bb54..312edf48ca 100644 --- a/packages/enclave-contracts/deployed_contracts.json +++ b/packages/enclave-contracts/deployed_contracts.json @@ -26,5 +26,52 @@ "blockNumber": 9181753, "address": "0x58708A1bf1AEdf8e75755FDa1882F8dc46985009" } + }, + "localhost": { + "Enclave": { + "constructorArgs": { + "params": "0x000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000fc00100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000003fffffff000001", + "owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "maxDuration": "2592000", + "registry": "0x0000000000000000000000000000000000000001" + }, + "blockNumber": 2, + "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" + }, + "CiphernodeRegistry": { + "constructorArgs": { + "enclaveAddress": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + "owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + }, + "blockNumber": 4, + "address": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" + }, + "NaiveRegistryFilter": { + "constructorArgs": { + "ciphernodeRegistryAddress": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", + "owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + }, + "blockNumber": 5, + "address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" + }, + "MockComputeProvider": { + "blockNumber": 7, + "address": "0x0165878A594ca255338adfa4d48449f69242Eb8F" + }, + "MockDecryptionVerifier": { + "blockNumber": 8, + "address": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853" + }, + "MockInputValidator": { + "blockNumber": 9, + "address": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6" + }, + "MockE3Program": { + "constructorArgs": { + "mockInputValidator": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6" + }, + "blockNumber": 10, + "address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318" + } } -} +} \ No newline at end of file From 117b5b4b40d0b37df71d6ed6210ec61bf5775a74 Mon Sep 17 00:00:00 2001 From: 0xjei Date: Fri, 10 Oct 2025 14:10:59 +0200 Subject: [PATCH 2/5] run prettier for deployed contracts --- packages/enclave-contracts/deployed_contracts.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/enclave-contracts/deployed_contracts.json b/packages/enclave-contracts/deployed_contracts.json index 312edf48ca..fcb78eeb49 100644 --- a/packages/enclave-contracts/deployed_contracts.json +++ b/packages/enclave-contracts/deployed_contracts.json @@ -74,4 +74,4 @@ "address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318" } } -} \ No newline at end of file +} From e76f26c21076431274453a9f6f3301ec997e3b6b Mon Sep 17 00:00:00 2001 From: 0xjei Date: Fri, 10 Oct 2025 14:20:52 +0200 Subject: [PATCH 3/5] update docs --- docs/pages/CRISP/setup.mdx | 422 +++++++++++++++++++++++-------------- examples/CRISP/Readme.md | 12 +- 2 files changed, 269 insertions(+), 165 deletions(-) diff --git a/docs/pages/CRISP/setup.mdx b/docs/pages/CRISP/setup.mdx index 453a0ab0a3..5c6ec40784 100644 --- a/docs/pages/CRISP/setup.mdx +++ b/docs/pages/CRISP/setup.mdx @@ -1,5 +1,5 @@ --- -title: 'Setup - CRISP' +title: 'Setup - CRISP' description: '' --- @@ -7,132 +7,188 @@ import { Steps } from 'nextra/components' # Getting Started with CRISP -This guide will walk you through the steps to set up and run CRISP locally. CRISP is a complete example of an E3 Program, built with a modern Hardhat-based architecture that includes smart contracts, frontend applications, and secure computation components. +This guide will walk you through the steps to set up and run CRISP locally. CRISP is a complete +example of an E3 Program, built with a modern Hardhat-based architecture that includes smart +contracts, frontend applications, and secure computation components. The setup includes the following: - **CRISP contracts**: Smart contracts located in the `contracts/` directory -- **Applications**: Frontend, server, and computation programs in the `apps/` directory +- **Applications**: Frontend, server, and computation programs in the `apps/` directory - **Ciphernodes**: Distributed nodes managed through the Enclave CLI - **Development environment**: Hardhat + Foundry hybrid setup -## Quick Start with Docker (Recommended) +## Prerequisites -The fastest way to get CRISP running is using the scripts provided in the `scripts/` directory: +Before getting started, ensure you have installed: -```sh -cd examples/CRISP +- [Rust](https://rust-lang.org/tools/install/) +- [Foundry](https://getfoundry.sh) +- [RiscZero](https://dev.risczero.com/api/zkvm/install) +- [NodeJS](https://nodejs.org/en/download) +- [pnpm](https://pnpm.io) +- [Metamask](https://metamask.io) -# Setup and build the development environment -pnpm dev:setup +### Install Node -# Start all services (Anvil, Ciphernodes, Applications) -pnpm dev:up -``` +You can install Node following the official [documentation](https://nodejs.org/en) or using a Node +Version Manager (e.g., [nvm](https://github.com/nvm-sh/nvm)). -This will: -- Build all necessary Docker containers -- Start Anvil (local blockchain) -- Deploy all contracts -- Start the ciphernode network -- Launch all CRISP applications +### Install Pnpm -**Available Docker Commands:** -- `pnpm dev:setup` - Build the development containers -- `pnpm dev:up` - Start all services -- `pnpm dev:down` - Stop and clean up all services -- `pnpm dev:build` - Rebuild containers -- `pnpm cli` - Invoke the Server CLI inside the Docker Container +You can install Pnpm following the official [documentation](https://pnpm.io/installation). -Once everything is running, you can: -1. Run `pnpm cli` to start a new E3 Round. -2. Open `http://localhost:3000` for the client interface -3. Configure MetaMask with the Anvil network (see [MetaMask Setup](#metamask-setup) below) -4. Start voting! +### Install Metamask -## Manual Setup +You can add Metamask as extension to your browser following the official +[documentation](https://metamask.io). -If you prefer to set up CRISP manually or want to understand each component: - -## Prerequisites +### Install Rust and Foundry -Before getting started, ensure you have the following tools installed: +You need to install Rust and Foundry first. After installation, restart your terminal. -- **Rust** (programming language and package manager) -- **Foundry** (Ethereum development framework) -- **RISC Zero toolchain** (for RISC Zero program development) - Note that you can also run the program server in dev mode which does not use Risc0. -- **Node.js** (JavaScript runtime for client-side dependencies) -- **Anvil** (local Ethereum node) -- **Enclave CLI** (for managing ciphernodes) +```sh +# Install Rust +curl https://sh.rustup.rs -sSf | sh -## Install Dependencies +# Install Foundry +curl -L https://foundry.paradigm.xyz | bash +``` -### Install Enclave CLI +### Install RISC Zero Toolchain -The recommended way to install the Enclave CLI is using our installer script: +Next, install `rzup` for the `cargo-risczero` toolchain. ```sh -curl -fsSL https://raw.githubusercontent.com/gnosisguild/enclave/main/install | bash +# Install rzup +curl -L https://risczero.com/install | bash + +# Install RISC Zero toolchain +rzup install cargo-risczero ``` -This will install `enclaveup`, which can then install the Enclave CLI: +Verify the installation was successful by running: ```sh -enclaveup install +cargo risczero --version ``` -For more installation options and details, see the [Installation Guide](/installation). +At this point, you should have all the tools required to develop and deploy an application with +[RISC Zero](https://www.risczero.com). -**Alternative: Build from Source** +## Environment -If you prefer to build from source: +You need to setup your environment variables for `client/` and `server/`. Just copy and paste the +`.env.default` as `.env` and overwrite with your values the following variables (you can leave the +others initialized with the default values). -```sh -cargo install --locked --path ./crates/cli --bin enclave -f -``` +### Client -### Install Rust and Foundry +```bash +VITE_E3_PROGRAM_ADDRESS=0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44 # Default E3 program address from anvil +VITE_SEMAPHORE_ADDRESS=0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE +``` -First, install Rust and Foundry. After installation, restart your terminal. +### Server -```sh -# Install Rust -curl https://sh.rustup.rs -sSf | sh +```bash +ENCLAVE_ADDRESS="0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" +CIPHERNODE_REGISTRY_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" +NAIVE_REGISTRY_FILTER_ADDRESS="0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" +E3_PROGRAM_ADDRESS="0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44" # CRISPProgram Contract Address +``` -# Install Foundry -curl -L https://foundry.paradigm.xyz | bash +These address will be displayed after successfully running the `pnpm dev:up` command in a log that +will look like the following: + +```bash +[DEPLOY] Script ran successfully. +[DEPLOY] +[DEPLOY] == Logs == +[DEPLOY] Deploying on ChainID 31337 +[DEPLOY] Using config profile: custom +[DEPLOY] Using MockRISC0Verifier +[DEPLOY] Deployed MockRISC0Verifier to 0x0B306BF915C4d645ff596e518fAf3F9669b97016 +[DEPLOY] Enclave Address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 +[DEPLOY] Verifier Address: 0x0B306BF915C4d645ff596e518fAf3F9669b97016 +[DEPLOY] Deployed SemaphoreNoirVerifier to 0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1 +[DEPLOY] Deployed Semaphore to 0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE +[DEPLOY] Deployed CRISPCheckerFactory to 0x68B1D87F95878fE05B998F19b66F4baba5De1aed +[DEPLOY] Deployed CRISPPolicyFactory to 0x3Aa5ebB10DC797CAC828524e59A333d0A371443c +[DEPLOY] Using CRISPInputValidator +[DEPLOY] Deployed InputValidator to: 0xc6e7DF5E7b4f2A278906862b61205850344D4e7d +[DEPLOY] Deployed CRISPInputValidatorFactory to 0x59b670e9fA9D0A427751Af201D676719a970857b +[DEPLOY] Deployed HonkVerifier to 0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1 +[DEPLOY] Deployed CRISPProgram to 0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44 +[DEPLOY] Enabled E3 Program on Enclave ``` -### Install RISC Zero Toolchain +If you find any inconsistency with the addresses on the environment, you must update them and run +the script again (they must match). -> Optional: you can run CRISP in dev mode which does not use Risc0. +## Quick Start -Next, install `rzup`, which provides the `cargo-risczero` toolchain. +The fastest way to get CRISP running is using the scripts provided in the `scripts/` directory: -```sh -# Install rzup -curl -L https://risczero.com/install | bash +```bash +# Install dependencies +pnpm install -# Install the RISC Zero toolchain -rzup +# Setup and build the development environment +pnpm dev:setup + +# Start all services (Anvil, Ciphernodes, Applications) +pnpm dev:up + +# Clean up all artifacts and generated output (e.g., builds) +# This must be run from enclave root (do cd ../../ if you are inside examples/CRISP) +pnpm clean ``` -Verify the installation by running the following command: +This will: + +- Start Anvil (local blockchain) +- Deploy all contracts +- Compile all ZK circuits +- Start the ciphernode network +- Launch all CRISP applications -```sh -cargo risczero --version +```bash +# Build the development containers +pnpm dev:setup + +# Start all services +pnpm dev:up + +# Rebuild containers +pnpm dev:build + +# Invoke the Server CLI +pnpm cli ``` -At this point, you should have all the necessary tools to develop and deploy applications with [RISC Zero](https://www.risczero.com). +Once everything is running, you can: + +1. Navigate `http://localhost:3000` for the client interface +2. Add the Anvil private key to your wallet: + `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` +3. Press `Connect Wallet` button and complete the association with your MetaMask account +4. Switch to `Anvil` local network (this will be handled automatically by the app. You just need to + press on the connected account on the frontend and select the network. Then, complete the + configuration on MetaMask pop-up). +5. Open a new terminal, run `pnpm cli` and start a new E3 Round. +6. Refresh and interact with the round following the Client interface. -## Setting Up the Client +## Manual Start -The Client is a React application used to interact with the CRISP Server. Follow these steps to set it up locally: +If you prefer to set up CRISP manually or want to understand each component: -1. Navigate to the client directory: +### Setting Up the project + +1. Navigate to the root directory: ```sh - cd examples/CRISP/client + cd examples/CRISP ``` 2. Install dependencies: @@ -141,152 +197,210 @@ The Client is a React application used to interact with the CRISP Server. Follow pnpm install ``` -3. Start the development server: +### Setting Up the Web App + +To set up the CRISP dApp in your local environment, follow these steps: + +1. Navigate to the `client` directory: ```sh - pnpm dev + cd examples/CRISP/client ``` -## Setting Up the CRISP Server +2. Start the development server: -The CRISP server setup involves several components. This guide will walk you through each step. + ```sh + pnpm dev + ``` - +### Setting Up the CRISP Server -### Start a Local Testnet with Anvil +Setting up the CRISP server involves several components, but this guide will walk you through each +step. -1. In a terminal, start a local Ethereum testnet using Anvil: +### Step 1: Start a Local Testnet with Anvil - ```sh - anvil - ``` +```sh +anvil +``` -Keep this terminal open and running. Open a new terminal for the next steps. +Keep Anvil running in the terminal, and open a new terminal for the next steps. -### Deploy the Enclave Contracts +### Step 2: Setting Up the Ciphernodes -1. Clone the [Enclave Repository](https://github.com/gnosisguild/enclave) if you haven't already: +1. Clone the [Enclave Repo](https://github.com/gnosisguild/enclave): ```sh git clone https://github.com/gnosisguild/enclave.git - cd enclave ``` -2. Install the dependencies: +2. Navigate to the `enclave-contracts` directory: + + ```sh + cd enclave/packages/enclave-contracts + ``` + +3. Install dependencies: ```sh pnpm install ``` -3. Navigate to the `packages/enclave-contracts` directory: +4. Delete any previous local deployment (if any): ```sh - cd packages/enclave-contracts + rm -rf deployments/localhost/ ``` -4. Deploy the Enclave contracts on the local testnet: +5. Deploy the contracts on the local testnet: ```sh - pnpm clean:deployments pnpm deploy:mocks --network localhost ``` -After deployment, take note of the addresses for the following contracts: +After deployment, you will see the addresses for the following contracts: -- **Enclave**: Main protocol contract -- **Ciphernode Registry**: Registry for compute nodes -- **Filter Registry**: Registry for computation filters -- **Mock Input Validator**: Development input validation +- Enclave +- Ciphernode Registry +- Naive Registry Filter +- Mock Input Validator +- Mock E3 Program +- Mock Decryption Verifier +- Mock Compute Provider -### Deploy the CRISP Contracts +Note down the first four addresses as they will be needed to configure `risc0`, `local_testnet` and +the `server`. -1. Navigate to the CRISP directory: +### Step 3: Deploy the RISC Zero Contracts - ```sh - cd examples/CRISP - ``` +> Please note that this step is optional for development only. You can run the program server in dev +> mode which does not use Risc0. -2. Set up the environment variables by exporting the ETH wallet private key (Anvil's default private key): +1. Navigate to the `CRISP/lib/risc0-ethereum` directory. - ```sh - export ETH_WALLET_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" - ``` +--- -3. **Optional**: Set up Bonsai for faster proving (requires API key): +**Faster Proving w/ Bonsai** - > **_Note:_** _You can request a Bonsai API Key [here](https://bonsai.xyz/apply)._ +The following steps are optional. You can config +[Bonsai](https://dev.risczero.com/api/generating-proofs/remote-proving) for faster proving. - ```sh - export BONSAI_API_KEY="your_api_key" - export BONSAI_API_URL="your_api_url" - ``` +- Set up environment variables by creating a `.cargo` directory and `config.toml` file: -4. Deploy the CRISP contracts using Foundry: + ```sh + mkdir .cargo && cd .cargo && touch config.toml + ``` - ```sh - FOUNDRY_PROFILE=local forge script --rpc-url http://localhost:8545 --broadcast deploy/Deploy.s.sol - ``` +- Add the following configuration to `config.toml`: -Make sure to take note of the **CRISP Program Contract Address**, as this will serve as the **E3 Program Address**. + > **_Note:_** _This requires having access to a Bonsai API Key. To request an API key + > [complete the form here](https://bonsai.xyz/apply)._ -### Set Up Ciphernodes + ```toml + [env] + BONSAI_API_KEY="your_api_key" + BONSAI_API_URL="your_api_url" + ``` -Start the ciphernodes using the Enclave CLI: +--- -1. Set up the aggregator wallet: +2. In the `risc0/script` directory, update the `config.toml` with the deployed contract addresses. + The following configuration is based on default deployment addresses using local Anvil node: - ```sh - enclave wallet set --name ag --private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" + ```toml + [profile.custom] + chainId = 31337 + riscZeroVerifierAddress = "0x0000000000000000000000000000000000000000" + enclaveAddress = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" + inputValidatorAddress = "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853" ``` -2. Start the ciphernode network: +3. Export the ETH_WALLET_PRIVATE_KEY environment variable (Anvil's default private key): ```sh - enclave nodes up -v + export ETH_WALLET_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" ``` -3. Add ciphernodes to the registry: +4. Deploy the contracts: ```sh - # Navigate back to the Enclave repository - cd ../../packages/enclave-contracts - - # Add the ciphernodes - pnpm ciphernode:add --ciphernode-address "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E" --network "localhost" - pnpm ciphernode:add --ciphernode-address "0xdD2FD4581271e230360230F9337D5c0430Bf44C0" --network "localhost" - pnpm ciphernode:add --ciphernode-address "0x2546BcD3c84621e976D8185a91A922aE77ECEc30" --network "localhost" + forge script --rpc-url http://localhost:8545 --broadcast script/Deploy.s.sol ``` -### Configuration +Note down the `CRISPProgram` contract Address, which will be used as the E3 Program Address. + +### Step 4: Set up Environment Variables + +Create a `.env` file in the `server` directory with the following: + +```sh +# Private key for the enclave server +PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +ENCLAVE_SERVER_URL=http://0.0.0.0:4000 +HTTP_RPC_URL=http://127.0.0.1:8545 +PROGRAM_SERVER_URL=http://127.0.0.1:13151 +WS_RPC_URL=ws://127.0.0.1:8545 +CHAIN_ID=31337 + +# Cron-job API key to trigger new rounds +CRON_API_KEY=1234567890 + +# Based on Default Anvil Deployments (Only for testing) +ENCLAVE_ADDRESS="0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" +CIPHERNODE_REGISTRY_ADDRESS="0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" +NAIVE_REGISTRY_FILTER_ADDRESS="0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" +E3_PROGRAM_ADDRESS="0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44" # CRISPProgram Contract Address + +# E3 Config +E3_WINDOW_SIZE=40 +E3_THRESHOLD_MIN=1 +E3_THRESHOLD_MAX=2 +E3_DURATION=160 + +# E3 Compute Provider Config +E3_COMPUTE_PROVIDER_NAME="RISC0" +E3_COMPUTE_PROVIDER_PARALLEL=false +E3_COMPUTE_PROVIDER_BATCH_SIZE=4 # Must be a power of 2 +``` -The CRISP project uses an `enclave.config.yaml` file that defines: +## Running Ciphernodes -- **Chains**: Network configuration (Hardhat/Anvil) -- **Contract addresses**: Enclave, Ciphernode Registry, Filter Registry -- **Nodes**: Configuration for ciphernodes (cn1, cn2, cn3) and aggregator (ag) +To run three ciphernodes, use the following command inside the CRISP directory: -The default configuration is already set up for local development with Anvil. +```sh +./scripts/dev_cipher.sh +``` - +This script will start the ciphernodes, add the ciphernodes to the registry on chain. -## MetaMask Setup +## Running the CRISP Server -To interact with CRISP through the web interface, configure MetaMask: +To run the CRISP Server, open a new terminal and navigate to the `server` directory. Then, execute +the following command: -1. **Add the Anvil private key** to your wallet: - ``` - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - ``` +```sh +cargo run --bin server +``` + +## Interacting with CRISP via CLI + +Open a new terminal and navigate to the `server` directory. Then, execute the following command: + +```sh +cargo run --bin cli +``` + +Once the CLI client is running, you can interact with the CRISP voting protocol by following these +steps: -2. **Add the local Anvil network**: - - Network Name: `Anvil Local` - - RPC URL: `http://localhost:8545` - - Chain ID: `31337` - - Currency Symbol: `ETH` +1. Select `CRISP: Voting Protocol (ETH)` from the menu. -3. **Connect to the application** at `http://localhost:3000` +2. To initiate a new CRISP round, choose the option `Initialize new CRISP round`. +Ensure all services are running correctly and that components are communicating as expected before +starting a new CRISP round. ## Next Steps -Once you have completed the setup, you can proceed to [Running an E3 Program](/CRISP/running-e3) to learn how to interact with CRISP and run voting rounds. \ No newline at end of file +Once you have completed the setup, you can proceed to [Running an E3 Program](/CRISP/running-e3) to +learn how to interact with CRISP and run voting rounds. diff --git a/examples/CRISP/Readme.md b/examples/CRISP/Readme.md index c9a57a9bbe..8b0378a988 100644 --- a/examples/CRISP/Readme.md +++ b/examples/CRISP/Readme.md @@ -19,8 +19,6 @@ CRISP/ You can have an extended explanation of the single folders in the dedicated [documentation](https://docs.enclave.gg/CRISP/introduction#project-structure). -# Usage - ## Prerequisites Before getting started, ensure you have installed: @@ -122,7 +120,7 @@ These address will be displayed after successfully running the `pnpm dev:up` com If you find any inconsistency with the addresses on the environment, you must update them and run the script again (they must match). -## Quick Start +## Quick Start The fastest way to get CRISP running is using the scripts provided in the `scripts/` directory: @@ -172,14 +170,6 @@ Once everything is running, you can: 5. Open a new terminal, run `pnpm cli` and start a new E3 Round. 6. Refresh and interact with the round following the Client interface. -Before getting started, make sure you have the following tools installed: - -- **Rust** -- **RISC Zero toolchain** (not needed for development only) -- **Foundry** and **Anvil** (for local testnet) -- **Node.js** (for client-side dependencies) -- **Pnpm** (as Node package manager) - ## Manual Start ### Setting Up the project From fdc57bd61b81a492de3c9e8c492df46b63aeb914 Mon Sep 17 00:00:00 2001 From: 0xjei Date: Fri, 10 Oct 2025 17:03:07 +0200 Subject: [PATCH 4/5] better descriptions and fix wrong folder --- docs/pages/CRISP/setup.mdx | 8 ++++---- examples/CRISP/Readme.md | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pages/CRISP/setup.mdx b/docs/pages/CRISP/setup.mdx index 5c6ec40784..8ec294db22 100644 --- a/docs/pages/CRISP/setup.mdx +++ b/docs/pages/CRISP/setup.mdx @@ -145,13 +145,13 @@ pnpm dev:up pnpm clean ``` -This will: +This will start all CRISP components: -- Start Anvil (local blockchain) +- Anvil (local blockchain) - Deploy all contracts - Compile all ZK circuits -- Start the ciphernode network -- Launch all CRISP applications +- Ciphernodes network +- CRISP applications (server, client) ```bash # Build the development containers diff --git a/examples/CRISP/Readme.md b/examples/CRISP/Readme.md index 8b0378a988..f469b6e2c8 100644 --- a/examples/CRISP/Readme.md +++ b/examples/CRISP/Readme.md @@ -139,13 +139,13 @@ pnpm dev:up pnpm clean ``` -This will: +This will start all CRISP components: -- Start Anvil (local blockchain) +- Anvil (local blockchain) - Deploy all contracts - Compile all ZK circuits -- Start the ciphernode network -- Launch all CRISP applications +- Ciphernodes network +- CRISP applications (server, client) ```bash # Build the development containers @@ -237,7 +237,7 @@ Keep Anvil running in the terminal, and open a new terminal for the next steps. 4. Delete any previous local deployment (if any): ```sh - rm -rf deployments/localhost/ + pnpm clean:ignition:deployments ``` 5. Deploy the contracts on the local testnet: From cbc5d3b452bbe0270c649991a5406070385ba77d Mon Sep 17 00:00:00 2001 From: 0xjei Date: Fri, 10 Oct 2025 18:32:36 +0200 Subject: [PATCH 5/5] revert deployed contracts --- .../enclave-contracts/deployed_contracts.json | 47 ------------------- 1 file changed, 47 deletions(-) diff --git a/packages/enclave-contracts/deployed_contracts.json b/packages/enclave-contracts/deployed_contracts.json index fcb78eeb49..906896bb54 100644 --- a/packages/enclave-contracts/deployed_contracts.json +++ b/packages/enclave-contracts/deployed_contracts.json @@ -26,52 +26,5 @@ "blockNumber": 9181753, "address": "0x58708A1bf1AEdf8e75755FDa1882F8dc46985009" } - }, - "localhost": { - "Enclave": { - "constructorArgs": { - "params": "0x000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000fc00100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000003fffffff000001", - "owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "maxDuration": "2592000", - "registry": "0x0000000000000000000000000000000000000001" - }, - "blockNumber": 2, - "address": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512" - }, - "CiphernodeRegistry": { - "constructorArgs": { - "enclaveAddress": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", - "owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" - }, - "blockNumber": 4, - "address": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" - }, - "NaiveRegistryFilter": { - "constructorArgs": { - "ciphernodeRegistryAddress": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", - "owner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" - }, - "blockNumber": 5, - "address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" - }, - "MockComputeProvider": { - "blockNumber": 7, - "address": "0x0165878A594ca255338adfa4d48449f69242Eb8F" - }, - "MockDecryptionVerifier": { - "blockNumber": 8, - "address": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853" - }, - "MockInputValidator": { - "blockNumber": 9, - "address": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6" - }, - "MockE3Program": { - "constructorArgs": { - "mockInputValidator": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6" - }, - "blockNumber": 10, - "address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318" - } } }