Skip to content

Commit

Permalink
docs: update the deployment docs as well as installation/circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Mar 19, 2024
1 parent 1b370ae commit 4bdce00
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 11 deletions.
16 changes: 12 additions & 4 deletions website/versioned_docs/version-v1.x/circuits.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,22 @@ Before building the project, make sure you have the following dependencies insta

### Building MACI circuits

To build the two main circuits of MACI, run the following commands:
To build the main circuits of MACI, run the following command (`-c` postfix for c++ witness gen, and `-wasm` postfix for WASM witness gen only):

```
circom --r1cs --sym --wasm --output ./build circom/test/processMessages_10-2-1-2_test.circom
circom --r1cs --sym --wasm --output ./build circom/test/tallyVotes_10-1-2_test.circom
pnpm build-test-circuits-c
pnpm build-test-circuits-wasm
```

Please note that the circuit is configured with testing purpose parameters, which means it can only handle a limited amount of messages (up to 25 messages). For more information on the parameters and how to configure them, refer to [this page](/docs/circuits/#compile-circuits).
Please note that the circuits are configured with testing purpose parameters, which means it can only handle a limited amount of messages (up to 25 messages). For more information on the parameters and how to configure them, please refer to the individual circuit documentation within this page. Also, within the [configure-circomkit](https://maci.pse.dev/docs/installation#configure-circomkit) section of the `installation` page, you'll see how you can update the config file with new params.

To compile a single circuit, you can run:

```
pnpm circom:build $CIRCUIT_NAME
```

> Please note that the name should match one of the circuit names inside the `circom.json` file.
### Generating zKeys

Expand Down
9 changes: 5 additions & 4 deletions website/versioned_docs/version-v1.x/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ Next, we have the `signUp` function, which allows users to `signUp`, as long as
This function does the following:

- checks that the maximum number of signups has not been reached. As of now, this will be $5 ** 10 - 1$ due to circuit limitations.
- ensure the subtrees have not been merged already, to prevent a DoS on the coordinator full tree merge
- checks that the provided public key is a valid baby-jubjub point
- increases signups counter
- registers the user using the sign up gatekeeper contract. It is important that whichever gatekeeper is used, this reverts if a user tries to sign up twice or the conditions are not met (i.e returning false is not enoguh)
- registers the user using the sign up gatekeeper contract. It is important that whichever gatekeeper is used, this reverts if a user tries to sign up twice or the conditions are not met (i.e returning false is not enough)
- calls the voice credit proxy to retrieve the number of allocated voice credits allocated to this voter
- hashes the voice credits alongside the user's MACI public key and the current time
- enqueues this hashed data into the `stateAq` contract
Expand Down Expand Up @@ -318,7 +319,7 @@ It will process messages in batches, and after all batches have been processed,

## Tally

::info
:::info
The `Tally` contract is present also in a non quadratic voting fashion, and is slightly smaller due to not having the `verifyPerVOSpentVoiceCredits` function. This is not required because with normal (non quadratic) voting, each vote by a user is not the square root of the voice credits spent.
:::

Expand All @@ -332,7 +333,7 @@ Below are the functions which users can use to verify the results:

## Subsidy (optional)

The subsidy contract can be used by the coordinator to post proofs of valid subsidy calcuations, as well as users to verify that the subsidy calculations were performed correctly.
The subsidy contract can be used by the coordinator to post proofs of valid subsidy calculations, as well as users to verify that the subsidy calculations were performed correctly.

## SignUpToken (optional)

Expand All @@ -344,7 +345,7 @@ MACI requires a signup gatekeeper to ensure that only designed users register. I

- `FreeForAllSignUpGatekeeper` - This allows anyone to signup on MACI.
- `SignUpTokenGatekeeper` - This makes use of a ERC721 token to gatekeep the signup function.
- `EASGatekeeper` - This allows to gatekeep signups to only users which have a specific EAS attestation.
- `EASGatekeeper` - This allows gatekeeping signups to only users who have a specific EAS attestation.

An abstract contract to inherit from is also provided, with two function signatures as shown below:

Expand Down
122 changes: 122 additions & 0 deletions website/versioned_docs/version-v1.x/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: MACI Deployment
description: MACI Smart Contracts deployment
sidebar_label: MACI deployment
sidebar_position: 24
---

# MACI Deployment

Currently, it is possible to deploy MACI contracts in two ways:

- using the cli (`maci-cli`)
- using the hardhat tasks inside the `maci-contracts` package

## MACI Deployment Steps

In order, these are the steps for contract deployment:

1. Deploy crypto (Hasher, Poseidon)
2. Deploy VK Registry
3. Set verification keys
4. Deploy VoiceCreditProxy
5. Deploy Gatekeeper
6. Deploy Verifier
7. Deploy Topup credit
8. Deploy MessageProcessorFactory, PollFactory, SubsidyFactory, TallyFactory
9. Deploy MACI, AccQueueQuinaryMaci
10. Deploy Poll, AccQueueQuinaryMaci, MessageProcessor, Tally and Subsidy (optional)

### Note on ZKey artifacts

For testing purposes, you can use the test zkeys and artifacts that you can download using `pnpm download:test-zkeys`. For production use, you can download the most recent artifacts that have undergone a trusted setup. Please refer to the [Trusted Setup](/docs/trusted-setup) section for more information. To download those, please use `pnpm download:ceremony-zkeys`.

Please do not use test artifacts in production. If you do require zKeys configured for larger param sizes, please reach out to us if you will be using them in production and we'll discuss running a new ceremony for those parameters. To build new circuits artifacts for testing purposes, please refer to the [installation page](/docs/installation/#configure-circomkit) and to the [circuits](/docs/circuits) section.

### Deployment using `maci-cli`

```bash
maci-cli deployVkRegistry
maci-cli setVerifyingKeys \
--state-tree-depth 10 \
--int-state-tree-depth 1 \
--msg-tree-depth 2 \
--vote-option-tree-depth 2 \
--msg-batch-depth 1 \
--process-messages-zkey ./zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey \
--tally-votes-zkey ./zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey
maci-cli create --stateTreeDepth 10 --use-quadratic-voting true
maci-cli deployPoll \
--pubkey coordinator-public-key \
--duration 300 \
--int-state-tree-depth 1 \
--msg-tree-depth 2 \
--msg-batch-depth 1 \
--vote-option-tree-depth 2 \
--subsidy-enabled false
```

:::info
For quadratic voting polls, you can use the `--use-quadratic-voting true` flag when creating the MACI instance.
For non-quadratic voting polls, you can use the `--use-quadratic-voting false` flag when creating the MACI instance.
:::

### Deployment using `maci-contracts` hardhat tasks

1. Take the `deploy-config-example.json` file and copy it over to `deploy-config.json`
2. Update the fields as necessary:

```json
{
"sepolia": {
"ConstantInitialVoiceCreditProxy": {
"deploy": true,
"amount": 99
},
"FreeForAllGatekeeper": {
"deploy": false
},
"EASGatekeeper": {
"deploy": true,
"easAddress": "0xC2679fBD37d54388Ce493F1DB75320D236e1815e",
"schema": "0xe2636f31239f7948afdd9a9c477048b7fc2a089c347af60e3aa1251e5bf63e5c",
"attester": "attester-address"
},
"MACI": {
"stateTreeDepth": 10,
"gatekeeper": "EASGatekeeper"
},
"VkRegistry": {
"stateTreeDepth": 10,
"intStateTreeDepth": 1,
"messageTreeDepth": 2,
"voteOptionTreeDepth": 2,
"messageBatchDepth": 1,
"processMessagesZkey": "../cli/zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey",
"tallyVotesZkey": "../cli/zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey"
},
"Poll": {
"pollDuration": 30,
"coordinatorPubkey": "macipk.ea638a3366ed91f2e955110888573861f7c0fc0bb5fb8b8dca9cd7a08d7d6b93",
"subsidyEnabled": false,
"useQuadraticVoting": true
}
}
}
```

3. Fill the `.env` file with the appropriate data (you will find an example in the `.env.example` file:
- your mnemonic
- an RPC key
4. Run `pnpm deploy` to deploy the contracts (you can specify the network by appending `:network` to the command, e.g. `pnpm deploy:sepolia` - please refer to the available networks on the `package.json` scripts section)
5. Run `pnpm deploy-poll` to deploy your first Poll (you can specify the network by appending `:network` to the command, e.g. `pnpm deploy-poll:sepolia` - please refer to the available networks on the `package.json` scripts section)

:::info
Should you wish to deploy on a different network, you will need to update the [contracts/tasks/helpers/constants.ts](https://github.com/privacy-scaling-explorations/maci/blob/dev/contracts/tasks/helpers/constants.ts) file.
:::

6. You will find all of the deployed contracts addresses and configs in the `deployed-contracts.json` file inside the contracts folder.

:::info
You can find more information on integration and usage in the [Integrating MACI](/docs/integrating) section.
:::
4 changes: 1 addition & 3 deletions website/versioned_docs/version-v1.x/integrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ maci-cli setVerifyingKeys \
--msg-batch-depth 1 \
--process-messages-zkey ./zkeys/ProcessMessages_10-2-1-2_test/ProcessMessages_10-2-1-2_test.0.zkey \
--tally-votes-zkey ./zkeys/TallyVotes_10-1-2_test/TallyVotes_10-1-2_test.0.zkey
maci-cli create --stateTreeDepth 10
maci-cli create --stateTreeDepth 10 --use-quadratic-voting true
maci-cli deployPoll \
--pubkey coordinator-public-key \
--duration 30 \
--max-messages 25 \
--max-vote-options 25 \
--int-state-tree-depth 1 \
--msg-tree-depth 2 \
--msg-batch-depth 1 \
Expand Down

0 comments on commit 4bdce00

Please sign in to comment.