Integrating MACI
MACI can be used in any protocol that requires collusion resistance, for instance it has been proven to be quite efficient when integrated in quadratic funding applications such as clr.fund and qfi.
Here we will be looking at QFI and how it was used. Please note that this will be expanded as QFI is updated to use the newest version of MACI. Should you decide to integrate MACI in the meantime, feel free to open an issue on the GitHub repo.
Deployment
First, you need to deploy contracts to start using MACI. This could be done through either maci-cli
or by using hardhat tasks in the contracts
folder.
Via maci-cli
This can be easily done via maci-cli
.
Deployment order is:
- Deploy crypto (Hasher, Poseidon)
- Deploy VK Registry
- Set verification keys
- Deploy VoiceCreditProxy
- Deploy Gatekeeper
- Deploy Verifier
- Deploy Topup credit
- Deploy MessageProcessorFactory, PollFactory, SubsidyFactory, TallyFactory
- Deploy MACI, AccQueueQuinaryMaci
- Deploy Poll, AccQueueQuinaryMaci, MessageProcessor, Tally and Subsidy (optional)
Before running the deploy command make sure you have zkey files from trusted setup and env variables ETH_PROVIDER
(RPC endpoint) and ETH_SK
(wallet private key) are set. For production environment make sure you don't use zkey files from our examples.
Make sure that if you intend to run a non quadratic voting Poll, you set the NonQv zKey files on the VkRegistry contract, as well as deploy the Poll with the option --use-quadratic-voting false
. Finally, remember to use the correct zk-SNARK artifacts (zKeys, and witnesses) in the genProof/prove commands.
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 30 \
--int-state-tree-depth 1 \
--msg-tree-depth 2 \
--msg-batch-depth 1 \
--vote-option-tree-depth 2
Deploy contracts in maci/contracts
This could also be done via running commands in maci/contracts
. Please download the maci repository, install and build everything, then navigate to the contracts
folder.
First of all, modify the deploy-config.json
file:
{
"choose-a-network": {
"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,
"zkeys": {
"qv": {
"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"
},
"nonQv": {
"processMessagesZkey": "../cli/zkeys/ProcessMessagesNonQv_10-2-1-2_test/ProcessMessagesNonQv_10-2-1-2_test.0.zkey",
"tallyVotesZkey": "../cli/zkeys/TallyVotesNonQv_10-1-2_test/TallyVotesNonQv_10-1-2_test.0.zkey"
}
}
},
"Poll": {
"pollDuration": 30,
"coordinatorPubkey": "macipk.9a59264310d95cfd8eb7083aebeba221b5c26e77427f12b7c0f50bc1cc35e621",
"useQuadraticVoting": true
}
}
}
and run the following command:
pnpm run deploy:[network]
pnpm run deploy-poll:[network]
The network options are: localhost, sepolia, and optimism-sepolia, and the tasks flags and parameters are as follows:
Command | Flags | Options |
---|---|---|
deploy | --incremental : incremental deployment --strict : fail on warning --verify : verify contracts on Etherscan | --skip <index> : Skip steps with less or equal index |
deploy-poll | --incremental : incremental deployment --strict : fail on warning --verify : verify contracts on Etherscan | --skip <index> : Skip steps with less or equal index |
Signups and votes
Next, you can start accept user signup and votes. This can be done via maci-cli
as well:
maci-cli signup \
--pubkey user-public-key
maci-cli publish \
--pubkey user-public-key \
--privkey user-private-key \
--state-index 1 \
--vote-option-index 0 \
--new-vote-weight 9 \
--nonce 1 \
--poll-id 0