diff --git a/deploy/local/contracts.sh b/deploy/local/contracts.sh index 0598ffa36f..fa12cf0635 100755 --- a/deploy/local/contracts.sh +++ b/deploy/local/contracts.sh @@ -4,7 +4,7 @@ # cargo install --locked --path ./crates/cli --bin enclave -f # Deploy CRISP Contracts -(cd examples/CRISP/packages/crisp-contracts && pnpm deploy:contracts:full --network localhost) +(cd examples/CRISP/packages/crisp-contracts && pnpm deploy:contracts:full:mock --network localhost) # Add Ciphernodes to Enclave sleep 2 # wait for enclave to start diff --git a/examples/CRISP/packages/crisp-contracts/README.md b/examples/CRISP/packages/crisp-contracts/README.md index a3f1160e03..5868660933 100644 --- a/examples/CRISP/packages/crisp-contracts/README.md +++ b/examples/CRISP/packages/crisp-contracts/README.md @@ -20,6 +20,34 @@ Alternatively, you can run tests directly from this directory: pnpm test ``` +## Deployment + +### For testing + +For testing, you can deploy the contracts without using the Risc0 verifier. The following command +can be run: + +```bash +pnpm deploy:contracts:full:mock +``` + +This will also print out the environment variables needed for the CRISP server to work with your +newly deployed contracts. + +### Full deployment with Risc0Verifier + +You can deploy CRISP contracts only using: + +```bash +pnpm deploy:contracts +``` + +Or the following to deploy Enclave contracts too (useful for testing scenarios): + +```bash +pnpm deploy:contracts:full +``` + ## CRISP Program This is the main logic of CRISP - an enclave program for secure voting. @@ -31,15 +59,10 @@ It exposes two main functions: (`Enclave.publishCiphertextOutput`). This function ensures that the ciphertext output is valid. CRISP uses Risc0 as the compute provider for running the FHE program, thus the proof will be a Risc0 proof. - -## Input validator - -The input validator contract is used to validate the input data that is submitted to the E3 -instance. It is called by the Enclave contract when a new input is published -(`Enclave.publishInput`). In CRISP, the data providers (the ones submitting the inputs) are the -voters, and the input submitted is the vote itself. - -The validator checks that gating conditions are satisfied and that the ciphertext is constructed -correctly using -[Greco](https://github.com/gnosisguild/enclave/tree/main/circuits/crates/libs/greco). See the Greco -[paper](https://eprint.iacr.org/2024/594). +- `validateInput` - validate the input data that is submitted to the E3 instance. It is called by + the Enclave contract when a new input is published (`Enclave.publishInput`). In CRISP, the data + providers (the ones submitting the inputs) are the voters, and the input submitted is the vote + itself. The logic checks that gating conditions are satisfied and that the ciphertext is + constructed correctly using + [Greco](https://github.com/gnosisguild/enclave/tree/main/circuits/crates/libs/greco). See the + Greco [paper](https://eprint.iacr.org/2024/594). diff --git a/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts b/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts index 6377cbf48a..90f7a359fd 100644 --- a/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts +++ b/examples/CRISP/packages/crisp-contracts/deploy/deploy.ts @@ -3,7 +3,7 @@ // This file is provided WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY // or FITNESS FOR A PARTICULAR PURPOSE. -import { deployEnclave, updateE3Config } from '@enclave-e3/contracts/scripts' +import { deployEnclave, readDeploymentArgs, updateE3Config } from '@enclave-e3/contracts/scripts' import { deployCRISPContracts } from './crisp' import path from 'path' @@ -30,6 +30,7 @@ export const deploy = async () => { const chain = hre.globalOptions.network const shouldDeployEnclave = Boolean(process.env.DEPLOY_ENCLAVE) + const shouldPrintEnv = Boolean(process.env.PRINT_ENV_VARS) if (shouldDeployEnclave) { await deployEnclave(true) @@ -38,6 +39,23 @@ export const deploy = async () => { // this expects you to run it from CRISP's root updateE3Config(chain, path.join(__dirname, '..', '..', '..', 'enclave.config.yaml'), contractMapping) + + if (shouldPrintEnv) { + const enclaveAddress = readDeploymentArgs('Enclave', chain)?.address + const tokenAddress = readDeploymentArgs('MockUSDC', chain)?.address + const programAddress = readDeploymentArgs('CRISPProgram', chain)?.address + const ciphernodeRegistryAddress = readDeploymentArgs('CiphernodeRegistryOwnable', chain)?.address + + if (!enclaveAddress || !tokenAddress || !programAddress || !ciphernodeRegistryAddress) { + console.error('Error: Missing deployment addresses. Ensure all contracts are deployed.') + return + } + + console.log('\nAdd these to your server .env') + console.log( + `ENCLAVE_ADDRESS=${enclaveAddress}\nFEE_TOKEN_ADDRESS=${tokenAddress}\nE3_PROGRAM_ADDRESS=${programAddress}\nCIPHERNODE_REGISTRY_ADDRESS=${ciphernodeRegistryAddress}`, + ) + } } deploy().catch((err) => { diff --git a/examples/CRISP/packages/crisp-contracts/package.json b/examples/CRISP/packages/crisp-contracts/package.json index 4b94c46a0e..060df5537b 100644 --- a/examples/CRISP/packages/crisp-contracts/package.json +++ b/examples/CRISP/packages/crisp-contracts/package.json @@ -33,7 +33,8 @@ "ciphernode:add:self": "hardhat ciphernode:add", "clean:deployments": "hardhat utils:clean-deployments", "deploy:contracts": "hardhat run deploy/deploy.ts", - "deploy:contracts:full": "export DEPLOY_ENCLAVE=true USE_MOCK_VERIFIER=true && pnpm deploy:contracts", + "deploy:contracts:full": "export DEPLOY_ENCLAVE=true && pnpm deploy:contracts", + "deploy:contracts:full:mock": "export DEPLOY_ENCLAVE=true USE_MOCK_VERIFIER=true PRINT_ENV_VARS=true && pnpm deploy:contracts", "test": "hardhat test mocha", "verify": "hardhat run deploy/verify.ts", "updateSubmissionWindow": "hardhat ciphernode:window" diff --git a/examples/CRISP/scripts/crisp_deploy.sh b/examples/CRISP/scripts/crisp_deploy.sh index e305517bb4..47670347d0 100755 --- a/examples/CRISP/scripts/crisp_deploy.sh +++ b/examples/CRISP/scripts/crisp_deploy.sh @@ -9,4 +9,4 @@ export PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4 cd packages/crisp-contracts pnpm clean:deployments --network localhost -USE_MOCK_VERIFIER=true pnpm deploy:contracts:full --network localhost +USE_MOCK_VERIFIER=true pnpm deploy:contracts:full:mock --network localhost