@maci-protocol/cli 0.0.0-ci.a577366 → 0.0.0-ci.a73cfa9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/build/package.json +12 -12
- package/build/ts/index.js +291 -253
- package/build/ts/index.js.map +1 -1
- package/build/ts/utils/constants.d.ts +2 -0
- package/build/ts/utils/constants.d.ts.map +1 -1
- package/build/ts/utils/constants.js +7 -1
- package/build/ts/utils/constants.js.map +1 -1
- package/build/ts/utils/storage.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +16 -16
package/build/ts/index.js
CHANGED
|
@@ -45,6 +45,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
45
45
|
const path_1 = __importDefault(require("path"));
|
|
46
46
|
require("./cliInit");
|
|
47
47
|
const utils_1 = require("./utils");
|
|
48
|
+
const constants_1 = require("./utils/constants");
|
|
48
49
|
const defaults_1 = require("./utils/defaults");
|
|
49
50
|
// set the description version and name of the cli tool
|
|
50
51
|
const { description, version, name } = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname, "..", "package.json"), "utf8"));
|
|
@@ -66,25 +67,25 @@ program
|
|
|
66
67
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
67
68
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
68
69
|
.requiredOption("-s, --stateTreeDepth <stateTreeDepth>", "the state tree depth", parseInt)
|
|
69
|
-
.action(async (
|
|
70
|
+
.action(async (args) => {
|
|
70
71
|
try {
|
|
71
72
|
const signer = await getSigner();
|
|
72
|
-
(0, utils_1.banner)(
|
|
73
|
+
(0, utils_1.banner)(args.quiet);
|
|
73
74
|
const network = await signer.provider?.getNetwork();
|
|
74
75
|
const [poseidonT3, poseidonT4, poseidonT5, poseidonT6] = (0, utils_1.readContractAddresses)({
|
|
75
76
|
contractNames: [sdk_1.EContracts.PoseidonT3, sdk_1.EContracts.PoseidonT4, sdk_1.EContracts.PoseidonT5, sdk_1.EContracts.PoseidonT6],
|
|
76
77
|
network: network?.name,
|
|
77
78
|
});
|
|
78
79
|
let [signupPolicyContractAddress] = (0, utils_1.readContractAddresses)({
|
|
79
|
-
contractNames: [
|
|
80
|
+
contractNames: [args.signupPolicyContractName.toString()],
|
|
80
81
|
network: network?.name,
|
|
81
82
|
});
|
|
82
83
|
if (!signupPolicyContractAddress) {
|
|
83
|
-
const checkerFactory =
|
|
84
|
-
? sdk_1.FreeForAllCheckerFactory__factory.connect(
|
|
84
|
+
const checkerFactory = args.freeForAllCheckerFactoryAddress
|
|
85
|
+
? sdk_1.FreeForAllCheckerFactory__factory.connect(args.freeForAllCheckerFactoryAddress, signer)
|
|
85
86
|
: undefined;
|
|
86
|
-
const policyFactory =
|
|
87
|
-
? sdk_1.FreeForAllPolicyFactory__factory.connect(
|
|
87
|
+
const policyFactory = args.freeForAllPolicyFactoryAddress
|
|
88
|
+
? sdk_1.FreeForAllPolicyFactory__factory.connect(args.freeForAllPolicyFactoryAddress, signer)
|
|
88
89
|
: undefined;
|
|
89
90
|
const [contract] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({ checker: checkerFactory, policy: policyFactory }, signer, true);
|
|
90
91
|
signupPolicyContractAddress = await contract.getAddress();
|
|
@@ -102,13 +103,13 @@ program
|
|
|
102
103
|
poseidonT6,
|
|
103
104
|
},
|
|
104
105
|
signer,
|
|
105
|
-
stateTreeDepth:
|
|
106
|
+
stateTreeDepth: args.stateTreeDepth,
|
|
106
107
|
});
|
|
107
|
-
const emptyBallotRoots = (0, sdk_1.
|
|
108
|
+
const emptyBallotRoots = (0, sdk_1.generateEmptyBallotRoots)(args.stateTreeDepth);
|
|
108
109
|
// save to the JSON File
|
|
109
110
|
await (0, utils_1.storeContractAddresses)({
|
|
110
111
|
data: {
|
|
111
|
-
[
|
|
112
|
+
[args.signupPolicyContractName]: { address: signupPolicyContractAddress, args: [] },
|
|
112
113
|
[sdk_1.EContracts.Verifier]: { address: verifierContractAddress, args: [] },
|
|
113
114
|
[sdk_1.EContracts.MACI]: {
|
|
114
115
|
address: maciContractAddress,
|
|
@@ -117,7 +118,7 @@ program
|
|
|
117
118
|
messageProcessorFactoryContractAddress,
|
|
118
119
|
tallyFactoryContractAddress,
|
|
119
120
|
signupPolicyContractAddress,
|
|
120
|
-
|
|
121
|
+
args.stateTreeDepth,
|
|
121
122
|
emptyBallotRoots.map((root) => root.toString()),
|
|
122
123
|
],
|
|
123
124
|
},
|
|
@@ -131,7 +132,7 @@ program
|
|
|
131
132
|
},
|
|
132
133
|
signer,
|
|
133
134
|
});
|
|
134
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
135
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`MACI deployed at: ${maciContractAddress}`) });
|
|
135
136
|
}
|
|
136
137
|
catch (error) {
|
|
137
138
|
program.error(error.message, { exitCode: 1 });
|
|
@@ -140,75 +141,81 @@ program
|
|
|
140
141
|
program
|
|
141
142
|
.command("checkVerifyingKeys")
|
|
142
143
|
.description("check that the verifying keys in the contract match the local ones")
|
|
143
|
-
.option("-
|
|
144
|
+
.option("-m, --mode <mode>", "Voting mode (qv, non-qv, full)", (value) => constants_1.MODE_NAME_TO_ENUM[value], sdk_1.EMode.QV)
|
|
144
145
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
145
146
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
146
|
-
.option("-k, --vk-contract <vkContract>", "the
|
|
147
|
+
.option("-k, --vk-contract <vkContract>", "the VerifyingKeysRegistry contract address")
|
|
147
148
|
.requiredOption("-s, --state-tree-depth <stateTreeDepth>", "the state tree depth", parseInt)
|
|
148
|
-
.requiredOption("-i, --
|
|
149
|
+
.requiredOption("-i, --tally-processing-state-tree-depth <tallyProcessingStateTreeDepth>", "the intermediate state tree depth", parseInt)
|
|
149
150
|
.requiredOption("-v, --vote-option-tree-depth <voteOptionTreeDepth>", "the vote option tree depth", parseInt)
|
|
150
|
-
.requiredOption("-b, --
|
|
151
|
-
.requiredOption("-p, --
|
|
152
|
-
.requiredOption("-t, --tally-
|
|
151
|
+
.requiredOption("-b, --message-batch-size <messageBatchSize>", "the message batch size", parseInt)
|
|
152
|
+
.requiredOption("-p, --message-processor-zkey <messageProcessorZkeyPath>", "the message processor zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
153
|
+
.requiredOption("-t, --vote-tally-zkey <voteTallyZkeyPath>", "the vote tally zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
153
154
|
.requiredOption("--poll-joining-zkey <pollJoiningZkey>", "the poll joining zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
154
155
|
.requiredOption("--poll-joined-zkey <pollJoinedZkey>", "the poll joined zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
155
|
-
.action(async (
|
|
156
|
+
.action(async (args) => {
|
|
156
157
|
try {
|
|
157
158
|
const signer = await getSigner();
|
|
158
159
|
const network = await signer.provider?.getNetwork();
|
|
159
|
-
const [
|
|
160
|
-
contractNames: [sdk_1.EContracts.
|
|
160
|
+
const [contractAddress] = (0, utils_1.readContractAddresses)({
|
|
161
|
+
contractNames: [sdk_1.EContracts.VerifyingKeysRegistry],
|
|
161
162
|
network: network?.name,
|
|
162
|
-
defaultAddresses: [
|
|
163
|
+
defaultAddresses: [args.vkContract],
|
|
163
164
|
});
|
|
164
|
-
(0, sdk_1.logYellow)({ quiet:
|
|
165
|
+
(0, sdk_1.logYellow)({ quiet: args.quiet, text: (0, sdk_1.info)("Retrieving verifying keys from the contract...") });
|
|
165
166
|
await (0, sdk_1.checkVerifyingKeys)({
|
|
166
|
-
stateTreeDepth:
|
|
167
|
-
|
|
168
|
-
voteOptionTreeDepth:
|
|
169
|
-
messageBatchSize:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
pollJoiningZkeyPath:
|
|
173
|
-
pollJoinedZkeyPath:
|
|
174
|
-
|
|
175
|
-
|
|
167
|
+
stateTreeDepth: args.stateTreeDepth,
|
|
168
|
+
tallyProcessingStateTreeDepth: args.tallyProcessingStateTreeDepth,
|
|
169
|
+
voteOptionTreeDepth: args.voteOptionTreeDepth,
|
|
170
|
+
messageBatchSize: args.messageBatchSize,
|
|
171
|
+
messageProcessorZkeyPath: args.messageProcessorZkey,
|
|
172
|
+
voteTallyZkeyPath: args.voteTallyZkey,
|
|
173
|
+
pollJoiningZkeyPath: args.pollJoiningZkey,
|
|
174
|
+
pollJoinedZkeyPath: args.pollJoinedZkey,
|
|
175
|
+
verifyingKeysRegistry: contractAddress,
|
|
176
|
+
mode: args.mode,
|
|
176
177
|
signer,
|
|
177
178
|
});
|
|
178
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
179
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)("Verifying keys match") });
|
|
179
180
|
}
|
|
180
181
|
catch (error) {
|
|
181
182
|
program.error(error.message, { exitCode: 1 });
|
|
182
183
|
}
|
|
183
184
|
});
|
|
184
185
|
program
|
|
185
|
-
.command("
|
|
186
|
+
.command("generateMaciPubKey")
|
|
186
187
|
.description("generate a new MACI public key")
|
|
187
|
-
.requiredOption("-k, --
|
|
188
|
+
.requiredOption("-k, --private-key <privateKey>", "the private key")
|
|
188
189
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
189
190
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
190
|
-
.action((
|
|
191
|
-
const publicKey = (0, sdk_1.generateMaciPublicKey)(
|
|
192
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
191
|
+
.action((args) => {
|
|
192
|
+
const publicKey = (0, sdk_1.generateMaciPublicKey)(args.privateKey);
|
|
193
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Public key: ${publicKey}`) });
|
|
193
194
|
});
|
|
194
195
|
program
|
|
195
|
-
.command("
|
|
196
|
+
.command("generateMaciKeyPair")
|
|
196
197
|
.description("generate a new MACI key pair")
|
|
197
198
|
.option("-s, --seed <seed>", "seed value for keypair", (value) => (value ? BigInt(value) : undefined), undefined)
|
|
198
199
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
199
|
-
.action((
|
|
200
|
-
const { publicKey, privateKey } = (0, sdk_1.generateKeypair)({ seed:
|
|
201
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
202
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
200
|
+
.action((args) => {
|
|
201
|
+
const { publicKey, privateKey, publicKeyAsContractParam } = (0, sdk_1.generateKeypair)({ seed: args.seed });
|
|
202
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Public key: ${publicKey}`) });
|
|
203
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Private key: ${privateKey}`) });
|
|
204
|
+
(0, sdk_1.logGreen)({
|
|
205
|
+
quiet: args.quiet,
|
|
206
|
+
text: (0, sdk_1.success)(`Public key as contract param:
|
|
207
|
+
X: ${publicKeyAsContractParam.x}
|
|
208
|
+
Y: ${publicKeyAsContractParam.y}`),
|
|
209
|
+
});
|
|
203
210
|
});
|
|
204
211
|
program
|
|
205
|
-
.command("
|
|
212
|
+
.command("deployVerifyingKeysRegistry")
|
|
206
213
|
.description("deploy a new verification key registry contract")
|
|
207
214
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
208
215
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
209
|
-
.action(async (
|
|
216
|
+
.action(async (args) => {
|
|
210
217
|
try {
|
|
211
|
-
(0, utils_1.banner)(
|
|
218
|
+
(0, utils_1.banner)(args.quiet);
|
|
212
219
|
const signer = await getSigner();
|
|
213
220
|
// assume that the vkRegistry contract is the first one to be deployed
|
|
214
221
|
const isContractAddressesStoreExists = fs_1.default.existsSync(utils_1.contractAddressesStorePath);
|
|
@@ -217,12 +224,15 @@ program
|
|
|
217
224
|
(0, utils_1.resetContractAddresses)(network?.name);
|
|
218
225
|
}
|
|
219
226
|
// deploy and store the address
|
|
220
|
-
const
|
|
227
|
+
const verifyingKeysRegistryAddress = await (0, sdk_1.deployVerifyingKeysRegistryContract)({ signer });
|
|
221
228
|
await (0, utils_1.storeContractAddresses)({
|
|
222
|
-
data: { [sdk_1.EContracts.
|
|
229
|
+
data: { [sdk_1.EContracts.VerifyingKeysRegistry]: { address: verifyingKeysRegistryAddress, args: [] } },
|
|
223
230
|
signer,
|
|
224
231
|
});
|
|
225
|
-
(0, sdk_1.logGreen)({
|
|
232
|
+
(0, sdk_1.logGreen)({
|
|
233
|
+
quiet: args.quiet,
|
|
234
|
+
text: (0, sdk_1.success)(`VerifyingKeysRegistry deployed at: ${verifyingKeysRegistryAddress}`),
|
|
235
|
+
});
|
|
226
236
|
}
|
|
227
237
|
catch (error) {
|
|
228
238
|
program.error(error.message, { exitCode: 1 });
|
|
@@ -249,37 +259,38 @@ program
|
|
|
249
259
|
program
|
|
250
260
|
.command("deployPoll")
|
|
251
261
|
.description("deploy a new poll")
|
|
252
|
-
.option("-k, --
|
|
253
|
-
.requiredOption("
|
|
254
|
-
.requiredOption("
|
|
255
|
-
.requiredOption("-i, --
|
|
256
|
-
.requiredOption("-b, --
|
|
262
|
+
.option("-k, --verifyingKeysRegistryAddress <verifyingKeysRegistryAddress>", "the vk registry contract address")
|
|
263
|
+
.requiredOption("--start <pollStartDate>", "the poll start date", parseInt)
|
|
264
|
+
.requiredOption("--end <pollEndDate>", "the poll end date", parseInt)
|
|
265
|
+
.requiredOption("-i, --tally-processing-state-tree-depth <tallyProcessingStateTreeDepth>", "the int state tree depth", parseInt)
|
|
266
|
+
.requiredOption("-b, --message-batch-size <messageBatchSize>", "the message batch size", parseInt)
|
|
257
267
|
.requiredOption("-s, --state-tree-depth <stateTreeDepth>", "the state tree depth", parseInt)
|
|
258
268
|
.requiredOption("-v, --vote-option-tree-depth <voteOptionTreeDepth>", "the vote option tree depth", parseInt)
|
|
259
|
-
.requiredOption("-p, --
|
|
260
|
-
.option("-
|
|
269
|
+
.requiredOption("-p, --public-key <publicKey>", "the coordinator public key")
|
|
270
|
+
.option("-m, --mode <mode>", "Voting mode (qv, non-qv, full)", (value) => constants_1.MODE_NAME_TO_ENUM[value], sdk_1.EMode.QV)
|
|
261
271
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
262
|
-
.option("
|
|
272
|
+
.option("--relayers <relayers>", "the relayer addresses", (value) => value.split(",").map((item) => item.trim()))
|
|
263
273
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
264
274
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
265
275
|
.option("-o, --vote-options <voteOptions>", "the number of vote options", parseInt)
|
|
266
276
|
.option("--initial-voice-credits <initialVoiceCredits>", "the initial voice credits", parseInt)
|
|
267
277
|
.option("--initial-voice-credits-proxy <initialVoiceCreditsProxy>", "the initial voice credits proxy address")
|
|
268
278
|
.option("--signup-policy <signupPolicy>", "the signup policy contract address")
|
|
269
|
-
.action(async (
|
|
279
|
+
.action(async (args) => {
|
|
270
280
|
try {
|
|
271
|
-
(0, utils_1.banner)(
|
|
281
|
+
(0, utils_1.banner)(args.quiet);
|
|
272
282
|
const signer = await getSigner();
|
|
273
283
|
const network = await signer.provider?.getNetwork();
|
|
274
|
-
const [
|
|
284
|
+
const [verifyingKeysRegistryAddress, maciAddress, initialVoiceCreditProxyAddress, initialVoiceCreditProxyFactoryAddress, verifierContractAddress,] = (0, utils_1.readContractAddresses)({
|
|
275
285
|
contractNames: [
|
|
276
|
-
sdk_1.EContracts.
|
|
286
|
+
sdk_1.EContracts.VerifyingKeysRegistry,
|
|
277
287
|
sdk_1.EContracts.MACI,
|
|
278
288
|
sdk_1.EContracts.ConstantInitialVoiceCreditProxy,
|
|
289
|
+
sdk_1.EContracts.ConstantInitialVoiceCreditProxyFactory,
|
|
279
290
|
sdk_1.EContracts.Verifier,
|
|
280
291
|
],
|
|
281
292
|
network: network?.name,
|
|
282
|
-
defaultAddresses: [
|
|
293
|
+
defaultAddresses: [args.verifyingKeysRegistryAddress, args.maciAddress, args.initialVoiceCreditsProxy],
|
|
283
294
|
});
|
|
284
295
|
const maciContract = sdk_1.MACI__factory.connect(maciAddress, signer);
|
|
285
296
|
const nextPollId = await maciContract.nextPollId();
|
|
@@ -289,40 +300,41 @@ program
|
|
|
289
300
|
contractNames: [policyContractName.toString()],
|
|
290
301
|
keys: [nextPollId.toString()],
|
|
291
302
|
network: network?.name,
|
|
292
|
-
defaultAddresses: [
|
|
303
|
+
defaultAddresses: [args.signupPolicy],
|
|
293
304
|
});
|
|
294
305
|
const { pollId, pollContractAddress, tallyContractAddress, messageProcessorContractAddress, initialVoiceCreditProxyContractAddress, policyContractAddress, } = await (0, sdk_1.deployPoll)({
|
|
295
|
-
initialVoiceCredits:
|
|
296
|
-
pollStartTimestamp:
|
|
297
|
-
pollEndTimestamp:
|
|
298
|
-
|
|
299
|
-
messageBatchSize:
|
|
300
|
-
stateTreeDepth:
|
|
301
|
-
voteOptionTreeDepth:
|
|
302
|
-
|
|
306
|
+
initialVoiceCredits: args.initialVoiceCredits || defaults_1.DEFAULT_INITIAL_VOICE_CREDITS,
|
|
307
|
+
pollStartTimestamp: args.start,
|
|
308
|
+
pollEndTimestamp: args.end,
|
|
309
|
+
tallyProcessingStateTreeDepth: args.tallyProcessingStateTreeDepth,
|
|
310
|
+
messageBatchSize: args.messageBatchSize,
|
|
311
|
+
stateTreeDepth: args.stateTreeDepth,
|
|
312
|
+
voteOptionTreeDepth: args.voteOptionTreeDepth,
|
|
313
|
+
coordinatorPublicKey: domainobjs_1.PublicKey.deserialize(args.publicKey),
|
|
303
314
|
maciAddress,
|
|
304
|
-
|
|
305
|
-
relayers:
|
|
306
|
-
mode:
|
|
315
|
+
verifyingKeysRegistryContractAddress: verifyingKeysRegistryAddress,
|
|
316
|
+
relayers: args.relayers ?? [ethers_1.ZeroAddress],
|
|
317
|
+
mode: args.mode,
|
|
307
318
|
signer,
|
|
308
|
-
voteOptions:
|
|
319
|
+
voteOptions: args.voteOptions ?? defaults_1.DEFAULT_VOTE_OPTIONS,
|
|
309
320
|
verifierContractAddress,
|
|
310
321
|
policyContractAddress: signupPolicyContractAddress,
|
|
322
|
+
initialVoiceCreditProxyFactoryAddress,
|
|
311
323
|
initialVoiceCreditProxyContractAddress: initialVoiceCreditProxyAddress,
|
|
312
324
|
});
|
|
313
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
314
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
315
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
325
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Poll ID: ${pollId}`) });
|
|
326
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Poll contract address: ${pollContractAddress}`) });
|
|
327
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Tally contract address: ${tallyContractAddress}`) });
|
|
316
328
|
(0, sdk_1.logGreen)({
|
|
317
|
-
quiet:
|
|
329
|
+
quiet: args.quiet,
|
|
318
330
|
text: (0, sdk_1.success)(`Message processor contract address: ${messageProcessorContractAddress}`),
|
|
319
331
|
});
|
|
320
332
|
(0, sdk_1.logGreen)({
|
|
321
|
-
quiet:
|
|
333
|
+
quiet: args.quiet,
|
|
322
334
|
text: (0, sdk_1.success)(`Initial voice credit proxy contract address: ${initialVoiceCreditProxyContractAddress}`),
|
|
323
335
|
});
|
|
324
336
|
(0, sdk_1.logGreen)({
|
|
325
|
-
quiet:
|
|
337
|
+
quiet: args.quiet,
|
|
326
338
|
text: (0, sdk_1.success)(`Signup policy contract address: ${policyContractAddress}`),
|
|
327
339
|
});
|
|
328
340
|
}
|
|
@@ -333,8 +345,7 @@ program
|
|
|
333
345
|
program
|
|
334
346
|
.command("joinPoll")
|
|
335
347
|
.description("join the poll")
|
|
336
|
-
.requiredOption("-k, --
|
|
337
|
-
.option("-i, --state-index <stateIndex>", "the user's state index", BigInt)
|
|
348
|
+
.requiredOption("-k, --private-key <privateKey>", "the private key")
|
|
338
349
|
.option("-s, --sg-data <sgData>", "the signup policy data")
|
|
339
350
|
.option("-v, --ivcp-data <ivcpData>", "the initial voice credit proxy data")
|
|
340
351
|
.option("-n, --new-voice-credit-balance <newVoiceCreditBalance>", "the voice credit balance of the user for the poll", BigInt)
|
|
@@ -350,38 +361,37 @@ program
|
|
|
350
361
|
.requiredOption("--poll-joining-zkey <pollZkeyPath>", "the poll join zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
351
362
|
.option("-w, --wasm", "whether to use the wasm binaries")
|
|
352
363
|
.option("-r, --rapidsnark <rapidsnark>", "the path to the rapidsnark binary")
|
|
353
|
-
.option("-g, --poll-
|
|
354
|
-
.action(async (
|
|
364
|
+
.option("-g, --poll-witness-generator <pollWitnessGenerator>", "the path to the poll witness generation binary")
|
|
365
|
+
.action(async (args) => {
|
|
355
366
|
try {
|
|
356
367
|
const signer = await getSigner();
|
|
357
368
|
const network = await signer.provider?.getNetwork();
|
|
358
369
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
359
370
|
contractNames: [sdk_1.EContracts.MACI],
|
|
360
371
|
network: network?.name,
|
|
361
|
-
defaultAddresses: [
|
|
372
|
+
defaultAddresses: [args.maciAddress],
|
|
362
373
|
});
|
|
363
|
-
const privateKey =
|
|
374
|
+
const privateKey = args.privateKey || (await (0, utils_1.promptSensitiveValue)("Insert your MACI private key"));
|
|
364
375
|
const data = await (0, sdk_1.joinPoll)({
|
|
365
376
|
maciAddress,
|
|
366
377
|
privateKey,
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
pollId: cmdObj.pollId,
|
|
378
|
+
stateFile: args.stateFile,
|
|
379
|
+
pollId: args.pollId,
|
|
370
380
|
signer,
|
|
371
|
-
startBlock:
|
|
372
|
-
endBlock:
|
|
373
|
-
blocksPerBatch:
|
|
374
|
-
pollJoiningZkey:
|
|
375
|
-
pollWasm:
|
|
376
|
-
useWasm:
|
|
377
|
-
rapidsnark:
|
|
378
|
-
|
|
379
|
-
sgDataArg:
|
|
380
|
-
ivcpDataArg:
|
|
381
|
-
});
|
|
382
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
383
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
384
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
381
|
+
startBlock: args.startBlock,
|
|
382
|
+
endBlock: args.endBlock,
|
|
383
|
+
blocksPerBatch: args.blocksPerBatch,
|
|
384
|
+
pollJoiningZkey: args.pollJoiningZkey,
|
|
385
|
+
pollWasm: args.pollWasm,
|
|
386
|
+
useWasm: args.wasm,
|
|
387
|
+
rapidsnark: args.rapidsnark,
|
|
388
|
+
pollWitnessGenerator: args.pollWitnessGenerator,
|
|
389
|
+
sgDataArg: args.sgData ?? utils_1.DEFAULT_SG_DATA,
|
|
390
|
+
ivcpDataArg: args.ivcpData ?? utils_1.DEFAULT_IVCP_DATA,
|
|
391
|
+
});
|
|
392
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.info)(`User joined poll with nullifier: ${data.nullifier}`) });
|
|
393
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.info)(`User joined poll with state index: ${data.pollStateIndex}`) });
|
|
394
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.info)(`User joined poll with ${data.voiceCredits} voice credits`) });
|
|
385
395
|
}
|
|
386
396
|
catch (error) {
|
|
387
397
|
program.error(error.message, { exitCode: 1 });
|
|
@@ -391,49 +401,70 @@ program
|
|
|
391
401
|
.command("setVerifyingKeys")
|
|
392
402
|
.description("set the verifying keys")
|
|
393
403
|
.requiredOption("-s, --state-tree-depth <stateTreeDepth>", "the state tree depth", parseInt)
|
|
394
|
-
.requiredOption("-i, --
|
|
404
|
+
.requiredOption("-i, --tally-processing-state-tree-depth <tallyProcessingStateTreeDepth>", "the intermediate state tree depth", parseInt)
|
|
395
405
|
.requiredOption("-v, --vote-option-tree-depth <voteOptionTreeDepth>", "the vote option tree depth", parseInt)
|
|
396
|
-
.requiredOption("-b, --
|
|
406
|
+
.requiredOption("-b, --message-batch-size <messageBatchSize>", "the message batch size", parseInt)
|
|
397
407
|
.option("--poll-state-tree-depth <pollStateTreeDepth>", "the poll state tree depth", parseInt)
|
|
398
408
|
.option("--poll-joining-zkey <pollJoiningZkeyPath>", "the poll joining zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
399
409
|
.option("--poll-joined-zkey <pollJoinedZkeyPath>", "the poll joined zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
400
|
-
.option("--
|
|
401
|
-
.option("--tally-
|
|
402
|
-
.option("--
|
|
403
|
-
.option("--tally-
|
|
404
|
-
.option("
|
|
410
|
+
.option("--message-processor-zkey-qv <messageProcessorZkeyPathQv>", "the message processor qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
411
|
+
.option("--vote-tally-zkey-qv <voteTallyZkeyPathQv>", "the vote tally qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
412
|
+
.option("--message-processor-zkey-non-qv <messageProcessorZkeyPathNonQv>", "the message processor non-qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
413
|
+
.option("--vote-tally-zkey-non-qv <voteTallyZkeyPathNonQv>", "the vote tally non-qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
414
|
+
.option("--message-processor-zkey-full <messageProcessorZkeyPathFull>", "the message processor full zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
415
|
+
.option("--vote-tally-zkey-full <tallyVotesZkeyPathFull>", "the vote tally full zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
416
|
+
.option("-m, --modes <modes>", "Comma-separated list of voting modes (qv, non-qv, full)", (value) => value.split(",").map((v) => constants_1.MODE_NAME_TO_ENUM[v.trim()]), [sdk_1.EMode.QV])
|
|
405
417
|
.option("-k, --vk-registry <vkRegistry>", "the vk registry contract address")
|
|
406
418
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
407
419
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
408
|
-
.action(async (
|
|
420
|
+
.action(async (args) => {
|
|
409
421
|
try {
|
|
410
422
|
const signer = await getSigner();
|
|
411
423
|
const network = await signer.provider?.getNetwork();
|
|
412
|
-
const [
|
|
413
|
-
contractNames: [sdk_1.EContracts.
|
|
424
|
+
const [verifyingKeysRegistryAddress] = (0, utils_1.readContractAddresses)({
|
|
425
|
+
contractNames: [sdk_1.EContracts.VerifyingKeysRegistry],
|
|
414
426
|
network: network?.name,
|
|
415
|
-
defaultAddresses: [
|
|
427
|
+
defaultAddresses: [args.vkRegistry],
|
|
416
428
|
});
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
429
|
+
const processKeys = {
|
|
430
|
+
[sdk_1.EMode.QV]: args.messageProcessorZkeyQv,
|
|
431
|
+
[sdk_1.EMode.NON_QV]: args.messageProcessorZkeyNonQv,
|
|
432
|
+
[sdk_1.EMode.FULL]: args.messageProcessorZkeyFull,
|
|
433
|
+
};
|
|
434
|
+
const tallyKeys = {
|
|
435
|
+
[sdk_1.EMode.QV]: args.voteTallyZkeyQv,
|
|
436
|
+
[sdk_1.EMode.NON_QV]: args.voteTallyZkeyNonQv,
|
|
437
|
+
[sdk_1.EMode.FULL]: args.voteTallyZkeyFull,
|
|
438
|
+
};
|
|
439
|
+
const { pollJoiningVerifyingKey, pollJoinedVerifyingKey } = await (0, sdk_1.extractAllVerifyingKeys)({
|
|
440
|
+
pollJoiningZkeyPath: args.pollJoiningZkey,
|
|
441
|
+
pollJoinedZkeyPath: args.pollJoinedZkey,
|
|
442
|
+
});
|
|
443
|
+
const keysResults = await Promise.all(args.modes.map((mode) => (0, sdk_1.extractAllVerifyingKeys)({
|
|
444
|
+
messageProcessorZkeyPath: processKeys[mode],
|
|
445
|
+
voteTallyZkeyPath: tallyKeys[mode],
|
|
446
|
+
})));
|
|
447
|
+
const processVerifyingKeys = [];
|
|
448
|
+
const tallyVerifyingKeys = [];
|
|
449
|
+
keysResults.forEach(({ processVerifyingKey, tallyVerifyingKey }, idx) => {
|
|
450
|
+
if (!processVerifyingKey || !tallyVerifyingKey) {
|
|
451
|
+
throw new Error(`Verifying keys for mode ${args.modes[idx]} are not valid`);
|
|
452
|
+
}
|
|
453
|
+
processVerifyingKeys.push(processVerifyingKey);
|
|
454
|
+
tallyVerifyingKeys.push(tallyVerifyingKey);
|
|
424
455
|
});
|
|
425
456
|
await (0, sdk_1.setVerifyingKeys)({
|
|
426
|
-
stateTreeDepth:
|
|
427
|
-
|
|
428
|
-
voteOptionTreeDepth:
|
|
429
|
-
messageBatchSize:
|
|
430
|
-
pollStateTreeDepth:
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
457
|
+
stateTreeDepth: args.stateTreeDepth,
|
|
458
|
+
tallyProcessingStateTreeDepth: args.tallyProcessingStateTreeDepth,
|
|
459
|
+
voteOptionTreeDepth: args.voteOptionTreeDepth,
|
|
460
|
+
messageBatchSize: args.messageBatchSize,
|
|
461
|
+
pollStateTreeDepth: args.pollStateTreeDepth || args.stateTreeDepth,
|
|
462
|
+
pollJoiningVerifyingKey: pollJoiningVerifyingKey,
|
|
463
|
+
pollJoinedVerifyingKey: pollJoinedVerifyingKey,
|
|
464
|
+
processMessagesVerifyingKeys: processVerifyingKeys,
|
|
465
|
+
tallyVotesVerifyingKeys: tallyVerifyingKeys,
|
|
466
|
+
verifyingKeysRegistryAddress,
|
|
467
|
+
modes: args.modes,
|
|
437
468
|
signer,
|
|
438
469
|
});
|
|
439
470
|
}
|
|
@@ -444,9 +475,9 @@ program
|
|
|
444
475
|
program
|
|
445
476
|
.command("publish")
|
|
446
477
|
.description("publish a new message to a MACI Poll contract")
|
|
447
|
-
.requiredOption("-p, --
|
|
478
|
+
.requiredOption("-p, --public-key <publicKey>", "the MACI public key which should replace the user's public key in the state tree")
|
|
448
479
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
449
|
-
.option("-k, --
|
|
480
|
+
.option("-k, --private-key <privateKey>", "your serialized MACI private key")
|
|
450
481
|
.requiredOption("-i, --state-index <stateIndex>", "the user's state index", BigInt)
|
|
451
482
|
.requiredOption("-v, --vote-option-index <voteOptionIndex>", "the vote option index", BigInt)
|
|
452
483
|
.requiredOption("-n, --nonce <nonce>", "the message nonce", BigInt)
|
|
@@ -455,25 +486,25 @@ program
|
|
|
455
486
|
.requiredOption("-w, --new-vote-weight <newVoteWeight>", "the new vote weight", BigInt)
|
|
456
487
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
457
488
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
458
|
-
.action(async (
|
|
489
|
+
.action(async (args) => {
|
|
459
490
|
try {
|
|
460
491
|
const signer = await getSigner();
|
|
461
492
|
const network = await signer.provider?.getNetwork();
|
|
462
493
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
463
494
|
contractNames: [sdk_1.EContracts.MACI],
|
|
464
495
|
network: network?.name,
|
|
465
|
-
defaultAddresses: [
|
|
496
|
+
defaultAddresses: [args.maciAddress],
|
|
466
497
|
});
|
|
467
|
-
const privateKey =
|
|
498
|
+
const privateKey = args.privateKey || (await (0, utils_1.promptSensitiveValue)("Insert your MACI private key"));
|
|
468
499
|
await (0, sdk_1.publish)({
|
|
469
|
-
|
|
470
|
-
stateIndex:
|
|
471
|
-
voteOptionIndex:
|
|
472
|
-
nonce:
|
|
473
|
-
pollId:
|
|
474
|
-
newVoteWeight:
|
|
500
|
+
publicKey: args.publicKey,
|
|
501
|
+
stateIndex: args.stateIndex,
|
|
502
|
+
voteOptionIndex: args.voteOptionIndex,
|
|
503
|
+
nonce: args.nonce,
|
|
504
|
+
pollId: args.pollId,
|
|
505
|
+
newVoteWeight: args.newVoteWeight,
|
|
475
506
|
maciAddress,
|
|
476
|
-
salt:
|
|
507
|
+
salt: args.salt,
|
|
477
508
|
privateKey,
|
|
478
509
|
signer,
|
|
479
510
|
});
|
|
@@ -488,23 +519,23 @@ program
|
|
|
488
519
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
489
520
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
490
521
|
.requiredOption("-p, --poll-id <pollId>", "the poll id", BigInt)
|
|
491
|
-
.action(async (
|
|
522
|
+
.action(async (args) => {
|
|
492
523
|
try {
|
|
493
524
|
const signer = await getSigner();
|
|
494
525
|
const network = await signer.provider?.getNetwork();
|
|
495
526
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
496
527
|
contractNames: [sdk_1.EContracts.MACI],
|
|
497
528
|
network: network?.name,
|
|
498
|
-
defaultAddresses: [
|
|
529
|
+
defaultAddresses: [args.maciAddress],
|
|
499
530
|
});
|
|
500
531
|
const receipt = await (0, sdk_1.mergeSignups)({
|
|
501
|
-
pollId:
|
|
532
|
+
pollId: args.pollId,
|
|
502
533
|
maciAddress,
|
|
503
534
|
signer,
|
|
504
535
|
});
|
|
505
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
536
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.info)(`Transaction hash: ${receipt.hash}`) });
|
|
506
537
|
(0, sdk_1.logGreen)({
|
|
507
|
-
quiet:
|
|
538
|
+
quiet: args.quiet,
|
|
508
539
|
text: (0, sdk_1.success)(`Executed mergeSignups(); gas used: ${receipt.gasUsed.toString()}`),
|
|
509
540
|
});
|
|
510
541
|
}
|
|
@@ -518,37 +549,39 @@ program
|
|
|
518
549
|
.requiredOption("-s, --seconds <seconds>", "the number of seconds to fast-forward", parseInt)
|
|
519
550
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
520
551
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
521
|
-
.action(async (
|
|
552
|
+
.action(async (args) => {
|
|
522
553
|
try {
|
|
523
|
-
(0, utils_1.banner)(
|
|
554
|
+
(0, utils_1.banner)(args.quiet);
|
|
524
555
|
const signer = await getSigner();
|
|
525
|
-
await (0, sdk_1.timeTravel)({ seconds:
|
|
526
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
556
|
+
await (0, sdk_1.timeTravel)({ seconds: args.seconds, signer });
|
|
557
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`Fast-forwarded ${args.seconds} seconds`) });
|
|
527
558
|
}
|
|
528
559
|
catch (error) {
|
|
529
560
|
program.error(error.message, { exitCode: 1 });
|
|
530
561
|
}
|
|
531
562
|
});
|
|
532
563
|
program
|
|
533
|
-
.command("
|
|
564
|
+
.command("extractVerifyingKeyToFile")
|
|
534
565
|
.description("extract vkey to json file")
|
|
535
566
|
.requiredOption("--poll-joining-zkey <pollJoiningZkey>", "the poll joining zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
536
567
|
.requiredOption("--poll-joined-zkey <pollJoinedZkey>", "the poll joined zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
537
|
-
.requiredOption("--
|
|
538
|
-
.requiredOption("--tally-
|
|
539
|
-
.requiredOption("--
|
|
540
|
-
.requiredOption("--
|
|
568
|
+
.requiredOption("--message-processor-zkey-qv <messageProcessorZkeyPathQv>", "the message processor qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
569
|
+
.requiredOption("--vote-tally-zkey-qv <voteTallyZkeyPathQv>", "the vote tally qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
570
|
+
.requiredOption("--message-processor-zkey-non-qv <messageProcessorZkeyPathNonQv>", "the message processor non-qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
571
|
+
.requiredOption("--message-processor-zkey-full <messageProcessorZkeyPathFull>", "the message processor full zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
572
|
+
.requiredOption("--vote-tally-zkey-non-qv <voteTallyZkeyPathNonQv>", "the vote tally non-qv zkey path (see different options for zkey files to use specific circuits https://maci.pse.dev/docs/trusted-setup, https://maci.pse.dev/docs/testing/#pre-compiled-artifacts-for-testing)")
|
|
541
573
|
.requiredOption("-o, --output-file <outputFile>", "the output file path of extracted vkeys")
|
|
542
|
-
.action(async (
|
|
574
|
+
.action(async (args) => {
|
|
543
575
|
try {
|
|
544
|
-
await (0, sdk_1.
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
576
|
+
await (0, sdk_1.extractVerifyingKeyToFile)({
|
|
577
|
+
messageProcessorZkeyPathQv: args.messageProcessorZkeyQv,
|
|
578
|
+
messageProcessorZkeyPathFull: args.messageProcessorZkeyFull,
|
|
579
|
+
voteTallyZkeyPathQv: args.voteTallyZkeyQv,
|
|
580
|
+
messageProcessorZkeyPathNonQv: args.messageProcessorZkeyNonQv,
|
|
581
|
+
voteTallyZkeyPathNonQv: args.voteTallyZkeyNonQv,
|
|
582
|
+
pollJoiningZkeyPath: args.pollJoiningZkey,
|
|
583
|
+
pollJoinedZkeyPath: args.pollJoinedZkey,
|
|
584
|
+
outputFilePath: args.outputFile,
|
|
552
585
|
});
|
|
553
586
|
}
|
|
554
587
|
catch (error) {
|
|
@@ -558,28 +591,28 @@ program
|
|
|
558
591
|
program
|
|
559
592
|
.command("signup")
|
|
560
593
|
.description("Sign up to a MACI contract")
|
|
561
|
-
.requiredOption("-p, --
|
|
594
|
+
.requiredOption("-p, --public-key <publicKey>", "the MACI public key")
|
|
562
595
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
563
596
|
.option("-s, --sg-data <sgData>", "the signup gateway data")
|
|
564
597
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
565
598
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
566
|
-
.action(async (
|
|
599
|
+
.action(async (args) => {
|
|
567
600
|
try {
|
|
568
601
|
const signer = await getSigner();
|
|
569
602
|
const network = await signer.provider?.getNetwork();
|
|
570
603
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
571
604
|
contractNames: [sdk_1.EContracts.MACI],
|
|
572
605
|
network: network?.name,
|
|
573
|
-
defaultAddresses: [
|
|
606
|
+
defaultAddresses: [args.maciAddress],
|
|
574
607
|
});
|
|
575
608
|
const data = await (0, sdk_1.signup)({
|
|
576
|
-
|
|
609
|
+
maciPublicKey: args.publicKey,
|
|
577
610
|
maciAddress,
|
|
578
|
-
sgData:
|
|
611
|
+
sgData: args.sgData ?? utils_1.DEFAULT_SG_DATA,
|
|
579
612
|
signer,
|
|
580
613
|
});
|
|
581
614
|
(0, sdk_1.logGreen)({
|
|
582
|
-
quiet:
|
|
615
|
+
quiet: args.quiet,
|
|
583
616
|
text: (0, sdk_1.success)(`State index: ${data.stateIndex.toString()}\n Transaction hash: ${data.transactionHash}`),
|
|
584
617
|
});
|
|
585
618
|
}
|
|
@@ -590,28 +623,28 @@ program
|
|
|
590
623
|
program
|
|
591
624
|
.command("isRegisteredUser")
|
|
592
625
|
.description("Checks if user is registered with their public key and get their data")
|
|
593
|
-
.requiredOption("-p, --
|
|
626
|
+
.requiredOption("-p, --public-key <publicKey>", "the MACI public key")
|
|
594
627
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
595
628
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
596
|
-
.action(async (
|
|
629
|
+
.action(async (args) => {
|
|
597
630
|
try {
|
|
598
631
|
const signer = await getSigner();
|
|
599
632
|
const network = await signer.provider?.getNetwork();
|
|
600
633
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
601
634
|
contractNames: [sdk_1.EContracts.MACI],
|
|
602
635
|
network: network?.name,
|
|
603
|
-
defaultAddresses: [
|
|
636
|
+
defaultAddresses: [args.maciAddress],
|
|
604
637
|
});
|
|
605
638
|
const data = await (0, sdk_1.getSignedupUserData)({
|
|
606
|
-
|
|
639
|
+
maciPublicKey: args.publicKey,
|
|
607
640
|
maciAddress,
|
|
608
641
|
signer,
|
|
609
642
|
});
|
|
610
643
|
if (data.isRegistered) {
|
|
611
|
-
(0, sdk_1.logGreen)({ quiet:
|
|
644
|
+
(0, sdk_1.logGreen)({ quiet: args.quiet, text: (0, sdk_1.success)(`State index: ${data.stateIndex?.toString()}`) });
|
|
612
645
|
}
|
|
613
646
|
else {
|
|
614
|
-
(0, sdk_1.logRed)({ quiet:
|
|
647
|
+
(0, sdk_1.logRed)({ quiet: args.quiet, text: "User is not registered" });
|
|
615
648
|
}
|
|
616
649
|
}
|
|
617
650
|
catch (error) {
|
|
@@ -621,32 +654,32 @@ program
|
|
|
621
654
|
program
|
|
622
655
|
.command("isJoinedUser")
|
|
623
656
|
.description("Checks if user is joined to the poll with public key")
|
|
624
|
-
.requiredOption("-p, --
|
|
657
|
+
.requiredOption("-p, --public-key <publicKey>", "the MACI public key")
|
|
625
658
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
626
659
|
.requiredOption("-o, --poll-id <pollId>", "the poll id", BigInt)
|
|
627
660
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
628
661
|
.option("--start-block <startBlock>", "the block number to start looking for events from", parseInt)
|
|
629
662
|
.option("--end-block <endBlock>", "the block number to end looking for events from", parseInt)
|
|
630
663
|
.option("--blocks-per-batch <blockPerBatch>", "the number of blocks to process per batch", parseInt)
|
|
631
|
-
.action(async (
|
|
664
|
+
.action(async (args) => {
|
|
632
665
|
try {
|
|
633
666
|
const signer = await getSigner();
|
|
634
667
|
const network = await signer.provider?.getNetwork();
|
|
635
668
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
636
669
|
contractNames: [sdk_1.EContracts.MACI],
|
|
637
670
|
network: network?.name,
|
|
638
|
-
defaultAddresses: [
|
|
671
|
+
defaultAddresses: [args.maciAddress],
|
|
639
672
|
});
|
|
640
673
|
const data = await (0, sdk_1.getJoinedUserData)({
|
|
641
|
-
|
|
642
|
-
startBlock:
|
|
674
|
+
pollPublicKey: args.publicKey,
|
|
675
|
+
startBlock: args.startBlock,
|
|
643
676
|
maciAddress,
|
|
644
|
-
pollId:
|
|
677
|
+
pollId: args.pollId,
|
|
645
678
|
signer,
|
|
646
679
|
});
|
|
647
680
|
if (data.isJoined) {
|
|
648
681
|
(0, sdk_1.logGreen)({
|
|
649
|
-
quiet:
|
|
682
|
+
quiet: args.quiet,
|
|
650
683
|
text: (0, sdk_1.success)([
|
|
651
684
|
`Poll state index: ${data.pollStateIndex?.toString()}, registered: ${data.isJoined}`,
|
|
652
685
|
`Voice credits: ${data.voiceCredits?.toString()}`,
|
|
@@ -654,7 +687,7 @@ program
|
|
|
654
687
|
});
|
|
655
688
|
}
|
|
656
689
|
else {
|
|
657
|
-
(0, sdk_1.logRed)({ quiet:
|
|
690
|
+
(0, sdk_1.logRed)({ quiet: args.quiet, text: "User has not joined the poll" });
|
|
658
691
|
}
|
|
659
692
|
}
|
|
660
693
|
catch (error) {
|
|
@@ -666,29 +699,34 @@ program
|
|
|
666
699
|
.description("Get deployed poll from MACI contract")
|
|
667
700
|
.option("-p, --poll <poll>", "the poll id")
|
|
668
701
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
669
|
-
.action(async (
|
|
702
|
+
.action(async (args) => {
|
|
670
703
|
try {
|
|
671
704
|
const signer = await getSigner();
|
|
672
705
|
const network = await signer.provider?.getNetwork();
|
|
673
706
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
674
707
|
contractNames: [sdk_1.EContracts.MACI],
|
|
675
708
|
network: network?.name,
|
|
676
|
-
defaultAddresses: [
|
|
709
|
+
defaultAddresses: [args.maciAddress],
|
|
677
710
|
});
|
|
678
711
|
const details = await (0, sdk_1.getPoll)({
|
|
679
|
-
pollId:
|
|
712
|
+
pollId: args.poll,
|
|
680
713
|
maciAddress,
|
|
681
714
|
signer,
|
|
682
715
|
});
|
|
716
|
+
const modeNames = {
|
|
717
|
+
[sdk_1.EMode.QV]: "Quadratic Voting",
|
|
718
|
+
[sdk_1.EMode.NON_QV]: "Non-Quadratic Voting",
|
|
719
|
+
[sdk_1.EMode.FULL]: "Full Credits Voting",
|
|
720
|
+
};
|
|
683
721
|
(0, sdk_1.logGreen)({
|
|
684
722
|
quiet: true,
|
|
685
723
|
text: (0, sdk_1.success)([
|
|
686
724
|
`ID: ${details.id}`,
|
|
687
725
|
`Start time: ${new Date(Number(details.startDate) * 1000).toString()}`,
|
|
688
726
|
`End time: ${new Date(Number(details.endDate) * 1000).toString()}`,
|
|
689
|
-
`Number of signups ${details.
|
|
727
|
+
`Number of signups ${details.totalSignups}`,
|
|
690
728
|
`State tree merged: ${details.isMerged}`,
|
|
691
|
-
`Mode: ${details.mode
|
|
729
|
+
`Mode: ${modeNames[details.mode]}`,
|
|
692
730
|
].join("\n")),
|
|
693
731
|
});
|
|
694
732
|
}
|
|
@@ -703,15 +741,15 @@ program
|
|
|
703
741
|
.requiredOption("-w, --address <address>", "the address to fund")
|
|
704
742
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
705
743
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
706
|
-
.action(async (
|
|
744
|
+
.action(async (args) => {
|
|
707
745
|
try {
|
|
708
|
-
(0, utils_1.banner)(
|
|
746
|
+
(0, utils_1.banner)(args.quiet);
|
|
709
747
|
const signer = await getSigner();
|
|
710
|
-
const hash = await (0, sdk_1.fundWallet)({ amount:
|
|
711
|
-
(0, sdk_1.logYellow)({ quiet:
|
|
748
|
+
const hash = await (0, sdk_1.fundWallet)({ amount: args.amount, address: args.address, signer });
|
|
749
|
+
(0, sdk_1.logYellow)({ quiet: args.quiet, text: (0, sdk_1.info)(`Transaction hash: ${hash}`) });
|
|
712
750
|
(0, sdk_1.logGreen)({
|
|
713
|
-
quiet:
|
|
714
|
-
text: (0, sdk_1.success)(`Successfully funded ${
|
|
751
|
+
quiet: args.quiet,
|
|
752
|
+
text: (0, sdk_1.success)(`Successfully funded ${args.address} with ${args.amount} wei`),
|
|
715
753
|
});
|
|
716
754
|
}
|
|
717
755
|
catch (error) {
|
|
@@ -726,34 +764,34 @@ program
|
|
|
726
764
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
727
765
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
728
766
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
729
|
-
.action(async (
|
|
767
|
+
.action(async (args) => {
|
|
730
768
|
try {
|
|
731
|
-
(0, utils_1.banner)(
|
|
769
|
+
(0, utils_1.banner)(args.quiet);
|
|
732
770
|
const signer = await getSigner();
|
|
733
771
|
const network = await signer.provider?.getNetwork();
|
|
734
772
|
// read the tally file
|
|
735
|
-
const isTallyFileExists = fs_1.default.existsSync(
|
|
736
|
-
if (!
|
|
737
|
-
throw new Error(`Unable to open ${
|
|
773
|
+
const isTallyFileExists = fs_1.default.existsSync(args.tallyFile);
|
|
774
|
+
if (!args.tallyFile || !isTallyFileExists) {
|
|
775
|
+
throw new Error(`Unable to open ${args.tallyFile}`);
|
|
738
776
|
}
|
|
739
|
-
const tallyData = await (0, utils_1.readJSONFile)(
|
|
777
|
+
const tallyData = await (0, utils_1.readJSONFile)(args.tallyFile);
|
|
740
778
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
741
779
|
contractNames: [sdk_1.EContracts.MACI],
|
|
742
780
|
network: network?.name,
|
|
743
|
-
defaultAddresses: [
|
|
781
|
+
defaultAddresses: [args.maciAddress],
|
|
744
782
|
});
|
|
745
|
-
const pollParams = await (0, sdk_1.getPollParams)({ pollId:
|
|
783
|
+
const pollParams = await (0, sdk_1.getPollParams)({ pollId: args.pollId, maciContractAddress: maciAddress, signer });
|
|
746
784
|
const tallyCommitments = (0, sdk_1.generateTallyCommitments)({
|
|
747
785
|
tallyData,
|
|
748
786
|
voteOptionTreeDepth: pollParams.voteOptionTreeDepth,
|
|
749
787
|
});
|
|
750
788
|
await (0, sdk_1.verify)({
|
|
751
789
|
tallyData,
|
|
752
|
-
pollId:
|
|
790
|
+
pollId: args.pollId,
|
|
753
791
|
maciAddress,
|
|
754
792
|
signer,
|
|
755
793
|
tallyCommitments,
|
|
756
|
-
|
|
794
|
+
totalVoteOptions: pollParams.totalVoteOptions,
|
|
757
795
|
voteOptionTreeDepth: pollParams.voteOptionTreeDepth,
|
|
758
796
|
});
|
|
759
797
|
}
|
|
@@ -762,34 +800,34 @@ program
|
|
|
762
800
|
}
|
|
763
801
|
});
|
|
764
802
|
program
|
|
765
|
-
.command("
|
|
803
|
+
.command("generateProofs")
|
|
766
804
|
.description("generate the proofs for a poll")
|
|
767
|
-
.option("-k, --
|
|
805
|
+
.option("-k, --private-key <privateKey>", "your serialized MACI private key")
|
|
768
806
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
769
807
|
.requiredOption("-o, --poll-id <pollId>", "the poll id", BigInt)
|
|
770
808
|
.requiredOption("-t, --tally-file <tallyFile>", "the tally file with results, per vote option spent credits, spent voice credits total")
|
|
771
809
|
.option("-r, --rapidsnark <rapidsnark>", "the path to the rapidsnark binary")
|
|
772
|
-
.option("-g, --
|
|
773
|
-
.option("--
|
|
774
|
-
.option("--tally-
|
|
775
|
-
.option("--tally-
|
|
810
|
+
.option("-g, --message-processor-witness-generator <messageProcessorWitnessGenerator>", "the path to the process witness generation binary")
|
|
811
|
+
.option("--message-processor-witnessDat <messageProcessorWitnessDat>", "the path to the process witness dat file")
|
|
812
|
+
.option("--vote-tally-witness-generator <voteTallyWitnessGenerator>", "the path to the tally witness generation binary")
|
|
813
|
+
.option("--vote-tally-witnessDat <voteTallyWitnessDat>", "the path to the tally witness dat file")
|
|
776
814
|
.requiredOption("--poll-joining-zkey <processJoinZkey>", "the path to the poll join zkey")
|
|
777
|
-
.requiredOption("--
|
|
778
|
-
.requiredOption("--tally-zkey <
|
|
815
|
+
.requiredOption("--message-processor-zkey <messageProcessorZkey>", "the path to the process zkey")
|
|
816
|
+
.requiredOption("--vote-tally-zkey <voteTallyZkey>", "the path to the tally zkey")
|
|
779
817
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
780
818
|
.option("-p, --rpc-provider <provider>", "the rpc provider URL")
|
|
781
819
|
.requiredOption("-f, --output <outputDir>", "the output directory for proofs")
|
|
782
820
|
.option("--transaction-hash <transactionHash>", "transaction hash of MACI contract creation")
|
|
783
821
|
.option("-w, --wasm", "whether to use the wasm binaries")
|
|
784
|
-
.option("--
|
|
785
|
-
.option("--tally-wasm <
|
|
822
|
+
.option("--message-processor-wasm <messageProcessorWasm>", "the path to the process witness generation wasm binary")
|
|
823
|
+
.option("--vote-tally-wasm <voteTallyWasm>", "the path to the tally witness generation wasm binary")
|
|
786
824
|
.option("--state-file <stateFile>", "the path to the state file containing the serialized maci state")
|
|
787
825
|
.option("--start-block <startBlock>", "the block number to start looking for events from", parseInt)
|
|
788
826
|
.option("--end-block <endBlock>", "the block number to end looking for events from", parseInt)
|
|
789
827
|
.option("--blocks-per-batch <blockPerBatch>", "the number of blocks to process per batch", parseInt)
|
|
790
|
-
.option("-
|
|
828
|
+
.option("-m, --mode <mode>", "Voting mode (qv, non-qv, full)", (value) => constants_1.MODE_NAME_TO_ENUM[value], sdk_1.EMode.QV)
|
|
791
829
|
.option("-b, --ipfs-message-backup-files <ipfsMessageBackupFiles>", "Backup files for ipfs messages (name format: ipfsHash1.json, ipfsHash2.json, ..., ipfsHashN.json)", (value) => value?.split(/\s*,\s*/))
|
|
792
|
-
.action(async ({ quiet, maciAddress, pollId, ipfsMessageBackupFiles, stateFile, startBlock, endBlock, blocksPerBatch,
|
|
830
|
+
.action(async ({ quiet, maciAddress, pollId, ipfsMessageBackupFiles, stateFile, startBlock, endBlock, blocksPerBatch, privateKey, transactionHash, output, tallyFile, voteTallyZkey, voteTallyWitnessGenerator, voteTallyWasm, messageProcessorZkey, messageProcessorWitnessGenerator, messageProcessorWasm, mode, voteTallyWitnessDat, messageProcessorWitnessDat, wasm, rapidsnark, }) => {
|
|
793
831
|
try {
|
|
794
832
|
(0, utils_1.banner)(quiet);
|
|
795
833
|
const signer = await getSigner();
|
|
@@ -799,7 +837,7 @@ program
|
|
|
799
837
|
network: network?.name,
|
|
800
838
|
defaultAddresses: [maciAddress],
|
|
801
839
|
});
|
|
802
|
-
const coordinatorPrivateKey =
|
|
840
|
+
const coordinatorPrivateKey = privateKey || (await (0, utils_1.promptSensitiveValue)("Insert your MACI private key"));
|
|
803
841
|
await (0, sdk_1.generateProofs)({
|
|
804
842
|
maciAddress: maciContractAddress,
|
|
805
843
|
coordinatorPrivateKey,
|
|
@@ -813,15 +851,15 @@ program
|
|
|
813
851
|
signer,
|
|
814
852
|
outputDir: output,
|
|
815
853
|
tallyFile,
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
854
|
+
voteTallyZkey,
|
|
855
|
+
voteTallyWitnessGenerator,
|
|
856
|
+
voteTallyWasm,
|
|
857
|
+
messageProcessorZkey,
|
|
858
|
+
messageProcessorWitnessGenerator,
|
|
859
|
+
messageProcessorWasm,
|
|
860
|
+
mode,
|
|
861
|
+
voteTallyWitnessDatFile: voteTallyWitnessDat,
|
|
862
|
+
messageProcessorWitnessDatFile: messageProcessorWitnessDat,
|
|
825
863
|
useWasm: wasm,
|
|
826
864
|
rapidsnark,
|
|
827
865
|
});
|
|
@@ -831,12 +869,12 @@ program
|
|
|
831
869
|
}
|
|
832
870
|
});
|
|
833
871
|
program
|
|
834
|
-
.command("
|
|
872
|
+
.command("generateLocalState")
|
|
835
873
|
.description("generate a local MACI state from the smart contracts events")
|
|
836
874
|
.requiredOption("-o, --output <outputPath>", "the path where to write the state")
|
|
837
875
|
.requiredOption("-p, --poll-id <pollId>", "the id of the poll", BigInt)
|
|
838
876
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
839
|
-
.option("-k, --
|
|
877
|
+
.option("-k, --private-key <privateKey>", "your serialized MACI private key")
|
|
840
878
|
.option("--start-block <startBlock>", "the start block number", parseInt)
|
|
841
879
|
.option("--end-block <endBlock>", "the end block number", parseInt)
|
|
842
880
|
.option("--blocks-per-batch <blockPerBatch>", "the blocks per batch", parseInt)
|
|
@@ -846,30 +884,30 @@ program
|
|
|
846
884
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
847
885
|
.option("-b, --ipfs-message-backup-files <ipfsMessageBackupFiles>", "Backup files for ipfs messages (name format: ipfsHash1.json, ipfsHash2.json, ..., ipfsHashN.json)", (value) => value?.split(/\s*,\s*/))
|
|
848
886
|
.option("-l, --logs-output <logsOutputPath>", "the path where to save the logs for debugging and auditing purposes")
|
|
849
|
-
.action(async (
|
|
887
|
+
.action(async (args) => {
|
|
850
888
|
try {
|
|
851
889
|
const signer = await getSigner();
|
|
852
890
|
const network = await signer.provider?.getNetwork();
|
|
853
891
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
854
892
|
contractNames: [sdk_1.EContracts.MACI],
|
|
855
893
|
network: network?.name,
|
|
856
|
-
defaultAddresses: [
|
|
894
|
+
defaultAddresses: [args.maciAddress],
|
|
857
895
|
});
|
|
858
|
-
const coordinatorPrivateKey =
|
|
896
|
+
const coordinatorPrivateKey = args.privateKey || (await (0, utils_1.promptSensitiveValue)("Insert your MACI private key"));
|
|
859
897
|
await (0, sdk_1.generateMaciState)({
|
|
860
|
-
outputPath:
|
|
861
|
-
pollId:
|
|
898
|
+
outputPath: args.output.toString(),
|
|
899
|
+
pollId: args.pollId,
|
|
862
900
|
maciAddress,
|
|
863
901
|
coordinatorPrivateKey,
|
|
864
|
-
provider:
|
|
865
|
-
endBlock:
|
|
866
|
-
startBlock:
|
|
867
|
-
blockPerBatch:
|
|
868
|
-
transactionHash:
|
|
869
|
-
ipfsMessageBackupFiles:
|
|
870
|
-
sleep:
|
|
902
|
+
provider: args.rpcProvider,
|
|
903
|
+
endBlock: args.endBlock,
|
|
904
|
+
startBlock: args.startBlock,
|
|
905
|
+
blockPerBatch: args.blocksPerBatch,
|
|
906
|
+
transactionHash: args.transactionHash,
|
|
907
|
+
ipfsMessageBackupFiles: args.ipfsMessageBackupFiles,
|
|
908
|
+
sleep: args.sleep,
|
|
871
909
|
signer,
|
|
872
|
-
logsOutputPath:
|
|
910
|
+
logsOutputPath: args.logsOutput,
|
|
873
911
|
});
|
|
874
912
|
}
|
|
875
913
|
catch (error) {
|
|
@@ -884,20 +922,20 @@ program
|
|
|
884
922
|
.option("-q, --quiet <quiet>", "whether to print values to the console", (value) => value === "true", false)
|
|
885
923
|
.option("-r, --rpc-provider <provider>", "the rpc provider URL")
|
|
886
924
|
.option("-x, --maci-address <maciAddress>", "the MACI contract address")
|
|
887
|
-
.requiredOption("-f, --proof-dir <proofDir>", "the proof output directory from the
|
|
888
|
-
.action(async (
|
|
925
|
+
.requiredOption("-f, --proof-dir <proofDir>", "the proof output directory from the generateProofs subcommand")
|
|
926
|
+
.action(async (args) => {
|
|
889
927
|
try {
|
|
890
928
|
const signer = await getSigner();
|
|
891
929
|
const network = await signer.provider?.getNetwork();
|
|
892
930
|
const [maciAddress] = (0, utils_1.readContractAddresses)({
|
|
893
931
|
contractNames: [sdk_1.EContracts.MACI],
|
|
894
932
|
network: network?.name,
|
|
895
|
-
defaultAddresses: [
|
|
933
|
+
defaultAddresses: [args.maciAddress],
|
|
896
934
|
});
|
|
897
935
|
await (0, sdk_1.proveOnChain)({
|
|
898
|
-
pollId:
|
|
899
|
-
tallyFile:
|
|
900
|
-
proofDir:
|
|
936
|
+
pollId: args.pollId,
|
|
937
|
+
tallyFile: args.tallyFile,
|
|
938
|
+
proofDir: args.proofDir,
|
|
901
939
|
maciAddress,
|
|
902
940
|
signer,
|
|
903
941
|
});
|