Running an E3 Program
In this section, we will go through all the steps to run an E3 Program using CRISP. We will run a complete voting round of CRISP and do the following:
- Start the infrastructure (nodes and contracts)
- Start the CRISP applications (client, server, program)
- Request an E3 Voting Round
- Submit votes through the web interface
- Compute and verify results
Please make sure you have followed the CRISP Setup guide before proceeding.
Start Infrastructure
First, ensure you have the infrastructure running. If you haven't already, complete the setup:
Terminal 1: Start Anvil
anvil
Terminal 2: Start Ciphernodes
cd examples/CRISP
enclave nodes up -v
Make sure contracts are deployed and ciphernodes are added to the registry as described in the setup guide.
Start the Client Application
Terminal 3: Client
Navigate to the client directory and start the React application:
cd examples/CRISP/apps/client
pnpm dev
The client application will start on http://localhost:3000
.
Start the Server Application
Terminal 4: Server
Navigate to the server directory and start the backend server:
cd examples/CRISP/apps/server
cargo run --bin server
The server will start and begin listening for blockchain events.
Start the Program Server
Terminal 5: Program
Navigate to the program directory and start the program server:
cd examples/CRISP/apps/program
cargo run
This runs the RISC Zero program server that handles secure computations.
Initialize a New Voting Round
Terminal 6: CLI
Navigate to the server directory and start the CLI:
cd examples/CRISP/apps/server
cargo run --bin cli
Follow these steps in the CLI:
- Select
CRISP: Voting Protocol (ETH)
from the menu - Choose
Initialize new E3 round
to start a new voting round
You should see output similar to:
[2024-10-22 11:56:11] [commands.rs:42] - Starting new CRISP round!
[2024-10-22 11:56:11] [commands.rs:46] - Enabling E3 Program...
[2024-10-22 11:56:11] [commands.rs:50] - E3 Program enabled. TxHash: 0xa391a4cd2dcc59f4bc6dd1f5ed1c78006dbba4556ea633f4b6a53e2271538682
[2024-10-22 11:56:11] [commands.rs:74] - E3 request sent. TxHash: 0xe7998b9748e3526f6ca992c9bb498beabe4f387b02240a23d0f42a2386d3c305
Set Up MetaMask
To interact with the client application, you need to configure MetaMask:
- Open MetaMask in your browser
- Add the Anvil private key to your wallet:
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- Connect to the local Anvil network:
- Network Name: Anvil Local
- RPC URL:
http://localhost:8545
- Chain ID:
31337
- Currency Symbol:
ETH
Submit Votes via Web Interface
- Navigate to
http://localhost:3000
in your browser - Connect your MetaMask wallet
- You should see the active voting round
- Submit your vote by selecting your choice and confirming the transaction
Monitor the Process
You can monitor the entire process through the various terminal outputs:
Server logs will show:
- Vote submissions being received
- Computation starting when the voting period ends
- Results being computed and published
Example server output:
[2024-10-22 11:59:12] [handlers.rs:95] - Vote Count: 1
[2024-10-22 11:59:12] [handlers.rs:101] - Starting computation for E3: 0
Prove function execution time: 2 minutes and 37 seconds
[2024-10-22 12:01:49] [handlers.rs:109] - Computation completed for E3: 0
[2024-10-22 12:01:49] [handlers.rs:110] - RISC0 Output: Risc0Output { result: ComputeResult } ...
[2024-10-22 12:01:49] [handlers.rs:111] - Publishing ciphertext...
Ciphernode logs will show:
INFO Extracted log from evm sending now.
INFO evt=CiphertextOutputPublished(e3_id: 0) e3_id=0
INFO evt=DecryptionshareCreated(e3_id: 0, node: 0x2546BcD3c84621e976D8185a91A922aE77ECEc30) e3_id=0
INFO evt=PlaintextAggregated(e3_id: 0, src_chain_id: 31337) e3_id=0
INFO evt=E3RequestComplete(e3_id: 0)
INFO Plaintext published. tx=0x320dd95358cc86c2a709b6fec0c6865b43fa063cb61dfcb8a748005d4886f040
Final result logs:
[2024-10-22 12:01:49] [handlers.rs:171] - Handling PlaintextOutputPublished event...
[2024-10-22 12:01:49] [handlers.rs:181] - Vote Count: 1
[2024-10-22 12:01:49] [handlers.rs:182] - Votes Option 1: 0
[2024-10-22 12:01:49] [handlers.rs:183] - Votes Option 2: 1
[2024-10-22 12:01:49] [handlers.rs:187] - PlaintextOutputPublished event handled.
Understanding the Process
The CRISP voting process involves several key steps:
- Initialization: A new E3 round is created on the blockchain
- Vote Submission: Users submit encrypted votes through the web interface
- Computation: After the voting period, RISC Zero computes the results using FHE
- Decryption: Ciphernodes collaboratively decrypt the results
- Publication: Final results are published to the blockchain and displayed
Troubleshooting
- Ensure all terminals remain open during the voting process
- MetaMask connection issues: Check that you're connected to the correct network (Chain ID: 31337)
- Transaction failures: Verify you have sufficient ETH balance from the Anvil faucet
- Server errors: Monitor the server logs for detailed error messages
- Ciphernode issues: Ensure all ciphernode processes are running and connected
Next Steps
Once you've successfully run a voting round, you can:
- Experiment with different voting scenarios: Try multiple votes and different options
- Modify voting parameters: Adjust the configuration for different use cases
- Explore the codebase: Understand the implementation details for your own E3 programs
- Deploy to testnet: Move beyond local development to public testnets