Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/local/contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 35 additions & 12 deletions examples/CRISP/packages/crisp-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
20 changes: 19 additions & 1 deletion examples/CRISP/packages/crisp-contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand All @@ -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}`,
)
}
Comment thread
ctrlc03 marked this conversation as resolved.
}

deploy().catch((err) => {
Expand Down
3 changes: 2 additions & 1 deletion examples/CRISP/packages/crisp-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment thread
ctrlc03 marked this conversation as resolved.
"test": "hardhat test mocha",
"verify": "hardhat run deploy/verify.ts",
"updateSubmissionWindow": "hardhat ciphernode:window"
Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/scripts/crisp_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading