diff --git a/cli/downloadZkeys.sh b/cli/downloadZkeys.sh new file mode 100644 index 0000000000..df9b84803a --- /dev/null +++ b/cli/downloadZkeys.sh @@ -0,0 +1,16 @@ +PKGS="zkeys_10-2-1-2_glibc-211.tar.gz ProcessMessages_10-2-1-2_test.0.zkey TallyVotes_10-1-2_test.0.zkey SubsidyPerBatch_10-1-2_test.0.zkey" + +BASE_URL=https://maci-develop-fra.s3.eu-central-1.amazonaws.com/v1.1.1-aa4ba27/10-2-1-2 +OUT_DIR=./zkeys + +for p in $PKGS +do + url="$BASE_URL/$p" + echo "downloading $url" + curl $url -o "$OUT_DIR/$p" + extension="${p##*.}" + if [ "$extension" == "gz" ] + then + tar -xvf "$OUT_DIR/$p" -C "$OUT_DIR" + fi +done \ No newline at end of file diff --git a/cli/ts/airdrop.ts b/cli/ts/airdrop.ts index 974c32b937..267fc30eea 100644 --- a/cli/ts/airdrop.ts +++ b/cli/ts/airdrop.ts @@ -60,20 +60,20 @@ const airdrop = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["TopupCredit"]) && !args.erc20_contract) { console.error('Error: ERC20 contract address is empty') - return 1 + return } const ERC20Address = args.erc20_contract ? args.erc20_contract: contractAddrs["TopupCredit"] if (!validateEthAddress(ERC20Address)) { console.error('Error: invalid topup credit contract address') - return 1 + return } const signer = await getDefaultSigner() if (! await contractExists(signer.provider, ERC20Address)) { console.error('Error: there is no contract deployed at the specified address') - return 1 + return } const ERC20ContractAbi = parseArtifact('TopupCredit')[0] @@ -85,7 +85,7 @@ const airdrop = async (args: any) => { const amount = args.amount if (amount < 0) { console.error('Error: airdrop amount must be greater than 0') - return 1 + return } let tx @@ -101,19 +101,19 @@ const airdrop = async (args: any) => { if (e.message) { console.error(e.message) } - return 1 + return } if (typeof args.poll_id !== 'undefined') { const pollId = args.poll_id if (pollId < 0) { console.error('Error: the Poll ID should be a positive integer.') - return 1 + return } if ((!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] const maciContractAbi = parseArtifact('MACI')[0] @@ -138,10 +138,10 @@ const airdrop = async (args: any) => { if (e.message) { console.error(e.message) } - return 1 + return } } - return 0 + return } export { diff --git a/cli/ts/checkVerifyingKey.ts b/cli/ts/checkVerifyingKey.ts index e391a5e3c5..858f70b68e 100644 --- a/cli/ts/checkVerifyingKey.ts +++ b/cli/ts/checkVerifyingKey.ts @@ -113,7 +113,7 @@ const checkVerifyingKey = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.maci_address) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.maci_address ? args.maci_address: contractAddrs["MACI"] @@ -132,7 +132,7 @@ const checkVerifyingKey = async (args: any) => { const signer = await getDefaultSigner() if (!await contractExists(signer.provider, maciAddress)) { console.error('Error: there is no contract deployed at the specified address') - return {} + return } const [ maciContractAbi ] = parseArtifact('MACI') @@ -171,21 +171,20 @@ const checkVerifyingKey = async (args: any) => { if (!compareVks(processVk, processVkOnChain)) { console.error('Error: processVk mismatch') - return 1 + return } if (!compareVks(tallyVk, tallyVkOnChain)) { console.error('Error: tallyVk mismatch') - return 1 + return } } catch (e) { console.error(e.message) - return 1 + return } console.log('Success: zkey files match the keys in the registry') - return 0 } export { diff --git a/cli/ts/create.ts b/cli/ts/create.ts index f061779e35..6176482554 100644 --- a/cli/ts/create.ts +++ b/cli/ts/create.ts @@ -61,7 +61,7 @@ const create = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["VkRegistry"]) && !args.vk_registry) { console.error('Error: vkRegistry contract address is empty') - return 1 + return } const TopupCreditContract = await deployTopupCreditContract() @@ -76,7 +76,7 @@ const create = async (args: any) => { // Whether we should deploy a ConstantInitialVoiceCreditProxy if (initialVoiceCreditProxy != undefined && initialVoiceCredits != undefined) { console.error('Error: only one of the following can be specified: the initial voice credit proxy or the amount of initial voice credits.') - return 1 + return } let initialVoiceCreditProxyContractAddress @@ -135,7 +135,6 @@ const create = async (args: any) => { contractAddrs['PoseidonT5'] = poseidonAddrs[2] contractAddrs['PoseidonT6'] = poseidonAddrs[3] writeJSONFile(contractFilepath, contractAddrs) - return 0 } export { diff --git a/cli/ts/deployPoll.ts b/cli/ts/deployPoll.ts index f71ed05dca..b917451522 100644 --- a/cli/ts/deployPoll.ts +++ b/cli/ts/deployPoll.ts @@ -126,28 +126,28 @@ const deployPoll = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.maci_address) { console.error('Error: MACI contract address is empty') - return 1 + return } // The poll duration const duration = args.duration if (duration <= 0) { console.error('Error: the duration should be positive') - return 1 + return } // Max values const maxMessages = args.max_messages if (maxMessages <= 0) { console.error('Error: the maximum number of messages should be positive') - return 1 + return } // Max vote options const maxVoteOptions = args.max_vote_options if (maxVoteOptions <= 0) { console.error('Error: the maximum number of vote options be positive') - return 1 + return } const intStateTreeDepth = args.int_state_tree_depth const messageTreeSubDepth = args.msg_batch_depth @@ -159,7 +159,7 @@ const deployPoll = async (args: any) => { const maciAddress = args.maci_address ? args.maci_address: contractAddrs["MACI"] if (!(await contractExists(signer.provider, maciAddress))) { console.error('Error: a MACI contract is not deployed at', maciAddress) - return 1 + return } // The coordinator's MACI public key @@ -167,7 +167,7 @@ const deployPoll = async (args: any) => { if (!PubKey.isValidSerializedPubKey(coordinatorPubkey)) { console.error('Error: invalid MACI public key') - return {} + return } const unserialisedPubkey = PubKey.unserialize(coordinatorPubkey) @@ -210,7 +210,7 @@ const deployPoll = async (args: any) => { const name = log.name if (name !== 'DeployPoll') { console.error('Error: invalid event log.') - return 1 + return } const pollId = log.args._pollId const pollAddr = log.args._pollAddr @@ -229,10 +229,10 @@ const deployPoll = async (args: any) => { } catch (e) { console.error('Error: could not deploy poll') console.error(e.message) - return 1 + return } - return 0 + return } export { diff --git a/cli/ts/deployPollWithSigner.ts b/cli/ts/deployPollWithSigner.ts index 90c15b4c2f..588957e7e8 100644 --- a/cli/ts/deployPollWithSigner.ts +++ b/cli/ts/deployPollWithSigner.ts @@ -132,34 +132,34 @@ const deployPollWithSigner = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.maci_address) { console.error('Error: MACI contract address is empty') - return 1 + return } const privateKey = args.signer_private_key if (!privateKey) { console.error('Error: signer private key is empty') - return 1 + return } // The poll duration const duration = args.duration if (duration <= 0) { console.error('Error: the duration should be positive') - return 1 + return } // Max values const maxMessages = args.max_messages if (maxMessages <= 0) { console.error('Error: the maximum number of messages should be positive') - return 1 + return } // Max vote options const maxVoteOptions = args.max_vote_options if (maxVoteOptions <= 0) { console.error('Error: the maximum number of vote options be positive') - return 1 + return } const intStateTreeDepth = args.int_state_tree_depth const messageTreeSubDepth = args.msg_batch_depth @@ -172,7 +172,7 @@ const deployPollWithSigner = async (args: any) => { const maciAddress = args.maci_address ? args.maci_address: contractAddrs["MACI"] if (!(await contractExists(signer.provider, maciAddress))) { console.error('Error: a MACI contract is not deployed at', maciAddress) - return 1 + return } // The coordinator's MACI public key @@ -180,7 +180,7 @@ const deployPollWithSigner = async (args: any) => { if (!PubKey.isValidSerializedPubKey(coordinatorPubkey)) { console.error('Error: invalid MACI public key') - return 1 + return } const unserialisedPubkey = PubKey.unserialize(coordinatorPubkey) @@ -217,7 +217,7 @@ const deployPollWithSigner = async (args: any) => { const name = log.name if (name !== 'DeployPoll') { console.error('Error: invalid event log.') - return 1 + return } const pollId = log.args._pollId const pollAddr = log.args._pollAddr @@ -232,10 +232,10 @@ const deployPollWithSigner = async (args: any) => { } catch (e) { console.error('Error: could not deploy poll') console.error(e.message) - return 1 + return } - return 0 + return } export { diff --git a/cli/ts/deployVkRegistry.ts b/cli/ts/deployVkRegistry.ts index 9d7ed69393..2a69744985 100644 --- a/cli/ts/deployVkRegistry.ts +++ b/cli/ts/deployVkRegistry.ts @@ -24,7 +24,7 @@ const deployVkRegistry = async (args: any) => { fs.renameSync(contractFilepath, contractFilepathOld) } writeJSONFile(contractFilepath, {'VkRegistry':vkRegistryContract.address}) - return 0 + return } export { diff --git a/cli/ts/fundWallet.ts b/cli/ts/fundWallet.ts index a5a4d3e3a3..dfa139b416 100644 --- a/cli/ts/fundWallet.ts +++ b/cli/ts/fundWallet.ts @@ -50,10 +50,10 @@ const fundWallet = async (args: any) => { await tx.wait() } catch (e) { console.error(e) - return 1 + return } - return 0 + return } export { diff --git a/cli/ts/genMaciPubkey.ts b/cli/ts/genMaciPubkey.ts index 2c3c4b90fd..b574d77611 100644 --- a/cli/ts/genMaciPubkey.ts +++ b/cli/ts/genMaciPubkey.ts @@ -28,14 +28,14 @@ const genMaciPubkey = async (args: any) => { const isValid = PrivKey.isValidSerializedPrivKey(args.privkey) if (!isValid) { console.error('Error: invalid private key') - return 1 + return } const unserialisedPrivkey = PrivKey.unserialize(args.privkey) const pubkey = new PubKey(genPubKey(unserialisedPrivkey.rawPrivKey)) console.log(pubkey.serialize()) - return 0 + return } export { diff --git a/cli/ts/genProofs.ts b/cli/ts/genProofs.ts index 2e0afc43e5..bcb52580e6 100644 --- a/cli/ts/genProofs.ts +++ b/cli/ts/genProofs.ts @@ -184,7 +184,7 @@ const genProofs = async (args: any) => { if (fs.existsSync(args.tally_file)) { console.error(`Error: ${args.tally_file} exists. Please specify a different filepath.`) - return 1 + return } const rapidsnarkExe = args.rapidsnark @@ -202,22 +202,22 @@ const genProofs = async (args: any) => { ]) if (!ok) { console.error(`Error: ${path} does not exist.`) - return 1 + return } let subsidyVk: VerifyingKey if (args.subsidy_file) { if (fs.existsSync(args.subsidy_file)) { console.error(`Error: ${args.subsidy_file} exists. Please specify a different filepath.`) - return 1 + return } if (!args.subsidy_zkey) { console.error('Please specify subsidy zkey file location') - return 1 + return } if (!args.subsidy_witnessgen) { console.error('Please specify subsidy witnessgen file location') - return 1 + return } const subsidyDatFile = args.subsidy_witnessgen + ".dat" @@ -229,7 +229,7 @@ const genProofs = async (args: any) => { ]) if (!ok) { console.error(`Error: ${path} does not exist.`) - return 1 + return } subsidyVk = extractVk(args.subsidy_zkey) @@ -249,7 +249,7 @@ const genProofs = async (args: any) => { if (!PrivKey.isValidSerializedPrivKey(serializedPrivkey)) { console.error('Error: invalid MACI private key') - return 1 + return } const maciPrivkey = PrivKey.unserialize(serializedPrivkey) @@ -258,28 +258,28 @@ const genProofs = async (args: any) => { const contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } const signer = await getDefaultSigner() if (! (await contractExists(signer.provider, maciAddress))) { console.error('Error: there is no MACI contract deployed at the specified address') - return 1 + return } const pollId = Number(args.poll_id) if (pollId < 0) { console.error('Error: the Poll ID should be a positive integer.') - return 1 + return } const [ maciContractAbi ] = parseArtifact('MACI') @@ -295,7 +295,7 @@ const genProofs = async (args: any) => { const pollAddr = await maciContractEthers.polls(pollId) if (! (await contractExists(signer.provider, pollAddr))) { console.error('Error: there is no Poll contract with this poll ID linked to the specified MACI contract.') - return 1 + return } const pollContract = new ethers.Contract( @@ -320,7 +320,7 @@ const genProofs = async (args: any) => { 'Error: the state tree has not been merged yet. ' + 'Please use the mergeSignups subcommmand to do so.' ) - return 1 + return } const messageTreeDepth = Number( @@ -334,7 +334,7 @@ const genProofs = async (args: any) => { 'Error: the message tree has not been merged yet. ' + 'Please use the mergeMessages subcommmand to do so.' ) - return 1 + return } // Build an off-chain representation of the MACI contract using data in the contract storage @@ -390,7 +390,7 @@ const genProofs = async (args: any) => { } catch (e) { console.error('Error: could not generate proof.') console.error(e) - return 1 + return } // Verify the proof @@ -402,7 +402,7 @@ const genProofs = async (args: any) => { if (!isValid) { console.error('Error: generated an invalid proof') - return 1 + return } const thisProof = { @@ -443,7 +443,7 @@ const genProofs = async (args: any) => { const isValid = verifyProof(r.publicInputs, r.proof, subsidyVk) if (!isValid) { console.error('Error: generated an invalid subsidy calc proof') - return 1 + return } const thisProof = { circuitInputs: subsidyCircuitInputs, @@ -509,7 +509,7 @@ const genProofs = async (args: any) => { if (!isValid) { console.error('Error: generated an invalid proof') - return 1 + return } const thisProof = { @@ -582,7 +582,7 @@ const genProofs = async (args: any) => { endTime = Date.now() console.log(`----------gen tally proof took ${(endTime - startTime)/1000} seconds`) - return 0 + return } const saveOutput = ( diff --git a/cli/ts/mergeMessages.ts b/cli/ts/mergeMessages.ts index 31521b90f3..d0a2af9c7b 100644 --- a/cli/ts/mergeMessages.ts +++ b/cli/ts/mergeMessages.ts @@ -56,14 +56,14 @@ const mergeMessages = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } const signer = await getDefaultSigner() @@ -73,14 +73,14 @@ const mergeMessages = async (args: any) => { 'Error: there is no MACI contract deployed at the ' + 'specified address', ) - return 1 + return } const pollId = Number(args.poll_id) if (pollId < 0) { console.error('Error: the Poll ID should be a positive integer.') - return 1 + return } const [ maciContractAbi ] = parseArtifact('MACI') @@ -99,7 +99,7 @@ const mergeMessages = async (args: any) => { 'Error: there is no Poll contract with this poll ID linked to ' + 'the specified MACI contract.', ) - return 1 + return } const pollContract = new ethers.Contract( @@ -124,7 +124,7 @@ const mergeMessages = async (args: any) => { 'Error: the signer is not the owner of this Poll contract ' + pollAddr, ) - return 1 + return } // Check if the voting period is over @@ -139,7 +139,7 @@ const mergeMessages = async (args: any) => { 'Error: the voting period is not over. ' + 'Please wait till ' + new Date(deadline * 1000), ) - return 1 + return } while (true) { @@ -210,7 +210,7 @@ const mergeMessages = async (args: any) => { //} //console.log(numLeaves, messageAqSubDepth, numOps) - return 0 + return } export { diff --git a/cli/ts/mergeSignups.ts b/cli/ts/mergeSignups.ts index 1f334a003b..a1e916129b 100644 --- a/cli/ts/mergeSignups.ts +++ b/cli/ts/mergeSignups.ts @@ -57,28 +57,28 @@ const mergeSignups = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } const signer = await getDefaultSigner() if (! (await contractExists(signer.provider, maciAddress))) { console.error('Error: there is no MACI contract deployed at the specified address') - return 1 + return } const pollId = args.poll_id if (pollId < 0) { console.error('Error: the Poll ID should be a positive integer.') - return 1 + return } const [ maciContractAbi ] = parseArtifact('MACI') @@ -94,7 +94,7 @@ const mergeSignups = async (args: any) => { const pollAddr = await maciContractEthers.polls(pollId) if (! (await contractExists(signer.provider, pollAddr))) { console.error('Error: there is no Poll contract with this poll ID linked to the specified MACI contract.') - return 1 + return } const pollContract = new ethers.Contract( @@ -121,7 +121,7 @@ const mergeSignups = async (args: any) => { 'Error: the voting period is not over. ' + 'Please wait till ' + new Date(deadline * 1000), ) - return 1 + return } while (true) { @@ -172,7 +172,7 @@ const mergeSignups = async (args: any) => { // TODO: intelligently set num_queue_ops - return 0 + return } export { diff --git a/cli/ts/proveOnChain.ts b/cli/ts/proveOnChain.ts index e110c89a55..ffd47f93d2 100644 --- a/cli/ts/proveOnChain.ts +++ b/cli/ts/proveOnChain.ts @@ -83,19 +83,19 @@ const proveOnChain = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } if ((!contractAddrs||!contractAddrs["MessageProcessor-"+pollId]) && !args.mp) { console.error('Error: MessageProcessor contract address is empty') - return 1 + return } if ((!contractAddrs||!contractAddrs["Tally-"+pollId]) && !args.tally) { console.error('Error: Tally contract address is empty') - return 1 + return } if ((!contractAddrs||!contractAddrs["Subsidy-"+pollId]) && !args.subsidy) { console.error('Error: Subsidy contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] @@ -106,28 +106,28 @@ const proveOnChain = async (args: any) => { // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } // MessageProcessor contract if (!validateEthAddress(mpAddress)) { console.error('Error: invalid MessageProcessor contract address') - return 1 + return } if (! (await contractExists(signer.provider, mpAddress))) { console.error('Error: there is no contract deployed at the specified address') - return 1 + return } if (!validateEthAddress(tallyAddress)) { console.error('Error: invalid Tally contract address') - return 1 + return } if (!validateEthAddress(subsidyAddress)) { console.error('Error: invalid Subsidy contract address') - return 1 + return } const [ maciContractAbi ] = parseArtifact('MACI') @@ -148,7 +148,7 @@ const proveOnChain = async (args: any) => { const pollAddr = await maciContract.polls(pollId) if (! (await contractExists(signer.provider, pollAddr))) { console.error('Error: there is no Poll contract with this poll ID linked to the specified MACI contract.') - return 1 + return } const pollContract = new ethers.Contract( @@ -310,12 +310,12 @@ const proveOnChain = async (args: any) => { // Perform checks if (circuitInputs.pollEndTimestamp !== pollEndTimestampOnChain.toString()) { console.error('Error: pollEndTimestamp mismatch.') - return 1 + return } if (BigInt(circuitInputs.msgRoot).toString() !== messageRootOnChain.toString()) { console.error('Error: message root mismatch.') - return 1 + return } let currentSbCommitmentOnChain @@ -328,7 +328,7 @@ const proveOnChain = async (args: any) => { if (currentSbCommitmentOnChain.toString() !== circuitInputs.currentSbCommitment) { console.error('Error: currentSbCommitment mismatch.') - return 1 + return } const coordPubKeyHashOnChain = BigInt(await pollContract.coordinatorPubKeyHash()) @@ -339,7 +339,7 @@ const proveOnChain = async (args: any) => { ).toString() !== coordPubKeyHashOnChain.toString() ) { console.error('Error: coordPubKey mismatch.') - return 1 + return } const packedValsOnChain = BigInt(await mpContract.genProcessMessagesPackedVals( @@ -350,7 +350,7 @@ const proveOnChain = async (args: any) => { if (circuitInputs.packedVals !== packedValsOnChain) { console.error('Error: packedVals mismatch.') - return 1 + return } const formattedProof = formatProofForVerifierContract(proof) @@ -366,7 +366,7 @@ const proveOnChain = async (args: any) => { if (publicInputHashOnChain.toString() !== publicInputs[0].toString()) { console.error('Public input mismatch.') - return 1 + return } const isValidOnChain = await verifierContract.verify( @@ -377,7 +377,7 @@ const proveOnChain = async (args: any) => { if (!isValidOnChain) { console.error('Error: the verifier contract found the proof invalid.') - return 1 + return } let tx @@ -396,7 +396,7 @@ const proveOnChain = async (args: any) => { if (receipt.status !== 1) { console.error(txErr) - return 1 + return } console.log(`Transaction hash: ${tx.hash}`) @@ -441,19 +441,19 @@ const proveOnChain = async (args: any) => { const subsidyCommitmentOnChain = await subsidyContract.subsidyCommitment() if (subsidyCommitmentOnChain.toString() !== circuitInputs.currentSubsidyCommitment) { console.error(`Error: subsidycommitment mismatch`) - return 1 + return } const packedValsOnChain = BigInt( await subsidyContract.genSubsidyPackedVals(numSignUps) ) if (circuitInputs.packedVals !== packedValsOnChain.toString()) { console.error('Error: subsidy packedVals mismatch.') - return 1 + return } const currentSbCommitmentOnChain = await subsidyContract.sbCommitment() if (currentSbCommitmentOnChain.toString() !== circuitInputs.sbCommitment) { console.error('Error: currentSbCommitment mismatch.') - return 1 + return } const publicInputHashOnChain = await subsidyContract.genSubsidyPublicInputHash( numSignUps, @@ -462,7 +462,7 @@ const proveOnChain = async (args: any) => { if (publicInputHashOnChain.toString() !== publicInputs[0]) { console.error('Error: public input mismatch.') - return 1 + return } const txErr = 'Error: updateSubsidy() failed...' @@ -484,7 +484,7 @@ const proveOnChain = async (args: any) => { if (receipt.status !== 1) { console.error(txErr) - return 1 + return } console.log(`Progress: ${subsidyBatchNum + 1} / ${totalBatchNum}`) @@ -544,7 +544,7 @@ const proveOnChain = async (args: any) => { const currentTallyCommitmentOnChain = await tallyContract.tallyCommitment() if (currentTallyCommitmentOnChain.toString() !== circuitInputs.currentTallyCommitment) { console.error('Error: currentTallyCommitment mismatch.') - return 1 + return } const packedValsOnChain = BigInt( @@ -556,13 +556,13 @@ const proveOnChain = async (args: any) => { ) if (circuitInputs.packedVals !== packedValsOnChain.toString()) { console.error('Error: packedVals mismatch.') - return 1 + return } const currentSbCommitmentOnChain = await mpContract.sbCommitment() if (currentSbCommitmentOnChain.toString() !== circuitInputs.sbCommitment) { console.error('Error: currentSbCommitment mismatch.') - return 1 + return } const publicInputHashOnChain = await tallyContract.genTallyVotesPublicInputHash( @@ -573,7 +573,7 @@ const proveOnChain = async (args: any) => { ) if (publicInputHashOnChain.toString() !== publicInputs[0]) { console.error(`Error: public input mismatch. tallyBatchNum=${i}, onchain=${publicInputHashOnChain.toString()}, offchain=${publicInputs[0]}`) - return 1 + return } const formattedProof = formatProofForVerifierContract(proof) @@ -594,7 +594,7 @@ const proveOnChain = async (args: any) => { if (receipt.status !== 1) { console.error(txErr) - return 1 + return } console.log(`Progress: ${tallyBatchNum + 1} / ${totalTallyBatches}`) @@ -621,7 +621,7 @@ const proveOnChain = async (args: any) => { } - return 0 + return } export { diff --git a/cli/ts/publish.ts b/cli/ts/publish.ts index 794314942e..c9a4f5d48d 100644 --- a/cli/ts/publish.ts +++ b/cli/ts/publish.ts @@ -139,7 +139,7 @@ const publish = async (args: any) => { // User's MACI public key if (!PubKey.isValidSerializedPubKey(args.pubkey)) { console.error('Error: invalid MACI public key') - return 1 + return } const userMaciPubKey = PubKey.unserialize(args.pubkey) @@ -148,14 +148,14 @@ const publish = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } // Ethereum provider @@ -171,7 +171,7 @@ const publish = async (args: any) => { if (!PrivKey.isValidSerializedPrivKey(serializedPrivkey)) { console.error('Error: invalid MACI private key') - return 1 + return } const userMaciPrivkey = PrivKey.unserialize(serializedPrivkey) @@ -180,7 +180,7 @@ const publish = async (args: any) => { const stateIndex = BigInt(args.state_index) if (stateIndex < 0) { console.error('Error: the state index must be greater than 0') - return 1 + return } // Vote option index @@ -188,7 +188,7 @@ const publish = async (args: any) => { if (voteOptionIndex < 0) { console.error('Error: the vote option index should be 0 or greater') - return 1 + return } // The nonce @@ -196,7 +196,7 @@ const publish = async (args: any) => { if (nonce < 0) { console.error('Error: the nonce should be 0 or greater') - return 1 + return } // The salt @@ -204,14 +204,14 @@ const publish = async (args: any) => { if (args.salt) { if (!validateSaltFormat(args.salt)) { console.error('Error: the salt should be a 32-byte hexadecimal string') - return 1 + return } salt = BigInt(args.salt) if (!validateSaltSize(args.salt)) { console.error('Error: the salt should less than the BabyJub field size') - return 1 + return } } else { salt = DEFAULT_SALT @@ -220,14 +220,14 @@ const publish = async (args: any) => { const signer = await getDefaultSigner() if (! (await contractExists(signer.provider, maciAddress))) { console.error('Error: there is no MACI contract deployed at the specified address') - return 1 + return } const pollId = args.poll_id if (pollId < 0) { console.error('Error: the Poll ID should be a positive integer.') - return 1 + return } const [ maciContractAbi ] = parseArtifact('MACI') @@ -242,7 +242,7 @@ const publish = async (args: any) => { const pollAddr = await maciContractEthers.getPoll(pollId) if (! (await contractExists(signer.provider, pollAddr))) { console.error('Error: there is no Poll contract with this poll ID linked to the specified MACI contract.') - return 1 + return } //const pollContract = new web3.eth.Contract(pollContractAbi, pollAddr) @@ -331,10 +331,10 @@ const publish = async (args: any) => { console.error(e.message) } } - return 1 + return } - return 0 + return } export { diff --git a/cli/ts/setVerifyingKeys.ts b/cli/ts/setVerifyingKeys.ts index c8e635fe97..2cfb5d5771 100644 --- a/cli/ts/setVerifyingKeys.ts +++ b/cli/ts/setVerifyingKeys.ts @@ -110,7 +110,7 @@ const setVerifyingKeys = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["VkRegistry"]) && !args.vk_registry) { console.error('Error: vkRegistry contract address is empty') - return 1 + return } const vkRegistryAddress = args.vk_registry ? args.vk_registry: contractAddrs["VkRegistry"] // State tree depth @@ -124,11 +124,11 @@ const setVerifyingKeys = async (args: any) => { const tvZkeyFile = path.resolve(args.tally_votes_zkey) if (!fs.existsSync(pmZkeyFile)) { console.error(`Error: ${pmZkeyFile} does not exist.`) - return 1 + return } if (!fs.existsSync(tvZkeyFile)) { console.error(`Error: ${tvZkeyFile} does not exist.`) - return 1 + return } const processVk: VerifyingKey = VerifyingKey.fromObj(extractVk(pmZkeyFile)) @@ -141,7 +141,7 @@ const setVerifyingKeys = async (args: any) => { ssZkeyFile = path.resolve(args.subsidy_zkey) if (!fs.existsSync(ssZkeyFile)) { console.error(`Error: ${ssZkeyFile} does not exist.`) - return 1 + return } subsidyVk = VerifyingKey.fromObj(extractVk(ssZkeyFile)) @@ -156,19 +156,19 @@ const setVerifyingKeys = async (args: any) => { msgBatchDepth < 1 ) { console.error('Error: invalid depth or batch size parameters') - return 1 + return } if (stateTreeDepth < intStateTreeDepth) { console.error('Error: invalid state tree depth or intermediate state tree depth') - return 1 + return } // Check the pm zkey filename against specified params const pmMatch = pmZkeyFile.match(/.+_(\d+)-(\d+)-(\d+)-(\d+)_/) if (pmMatch == null) { console.error(`Error: ${pmZkeyFile} has an invalid filename`) - return 1 + return } const pmStateTreeDepth = Number(pmMatch[1]) const pmMsgTreeDepth = Number(pmMatch[2]) @@ -178,7 +178,7 @@ const setVerifyingKeys = async (args: any) => { const tvMatch = tvZkeyFile.match(/.+_(\d+)-(\d+)-(\d+)_/) if (tvMatch == null) { console.error(`Error: ${tvZkeyFile} has an invalid filename`) - return 1 + return } const tvStateTreeDepth = Number(tvMatch[1]) const tvIntStateTreeDepth = Number(tvMatch[2]) @@ -195,7 +195,7 @@ const setVerifyingKeys = async (args: any) => { ) { console.error('Error: incorrect .zkey file; please check the circuit params') - return 1 + return } @@ -203,7 +203,7 @@ const setVerifyingKeys = async (args: any) => { const signer = await getDefaultSigner() if (!(await contractExists(signer.provider,vkRegistryAddress))) { console.error('Error: a VkRegistry contract is not deployed at', vkRegistryAddress) - return 1 + return } const [ vkRegistryAbi ] = parseArtifact('VkRegistry') @@ -229,7 +229,7 @@ const setVerifyingKeys = async (args: any) => { if (isProcessVkSet) { console.error('Error: this process verifying key is already set in the contract') - return 1 + return } // Query the contract to see if the tallyVk has been set @@ -242,14 +242,14 @@ const setVerifyingKeys = async (args: any) => { const isTallyVkSet = await vkRegistryContract.isTallyVkSet(tallyVkSig) if (isTallyVkSet ) { console.error('Error: this tally verifying key is already set in the contract') - return 1 + return } if (args.subsidy_zkey) { const ssMatch = ssZkeyFile.match(/.+_(\d+)-(\d+)-(\d+)_/) if (ssMatch == null) { console.error(`Error: ${ssZkeyFile} has an invalid filename`) - return 1 + return } const ssStateTreeDepth = Number(ssMatch[1]) const ssIntStateTreeDepth = Number(ssMatch[2]) @@ -260,7 +260,7 @@ const setVerifyingKeys = async (args: any) => { voteOptionTreeDepth != ssVoteOptionTreeDepth ) { console.error('Error: incorrect .zkey file; please check the circuit params') - return 1 + return } const subsidyVkSig = genSubsidyVkSig( stateTreeDepth, @@ -270,7 +270,7 @@ const setVerifyingKeys = async (args: any) => { const isSubsidyVkSet = await vkRegistryContract.isSubsidyVkSet(subsidyVkSig) if (isSubsidyVkSet ) { console.error('Error: this subsidy verifying key is already set in the contract') - return 1 + return } } @@ -308,11 +308,11 @@ const setVerifyingKeys = async (args: any) => { if (!compareVks(processVk, processVkOnChain)) { console.error('Error: processVk mismatch') - return 1 + return } if (!compareVks(tallyVk, tallyVkOnChain)) { console.error('Error: tallyVk mismatch') - return 1 + return } if (args.subsidy_zkey) { @@ -338,16 +338,16 @@ const setVerifyingKeys = async (args: any) => { ) if (!compareVks(subsidyVk, subsidyVkOnChain)) { console.error('Error: subsidyVk mismatch') - return 1 + return } } - return 0 + return } catch (e) { console.error('Error: transaction failed') console.error(e.message) - return 1 + return } } diff --git a/cli/ts/topup.ts b/cli/ts/topup.ts index 1ac628f038..4949b00811 100644 --- a/cli/ts/topup.ts +++ b/cli/ts/topup.ts @@ -63,37 +63,37 @@ const topup = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } const signer = await getDefaultSigner() if (! await contractExists(signer.provider, maciAddress)) { console.error('Error: there is no contract deployed at the specified address') - return 1 + return } const amount = args.amount if (amount < 0) { console.error('Error: topup amount must be greater than 0') - return 1 + return } const stateIndex = BigInt(args.state_index) if (stateIndex < 0) { console.error('Error: the state index must be greater than 0') - return 1 + return } const pollId = args.poll_id if (pollId < 0) { console.error('Error: the Poll ID should be a positive integer.') - return 1 + return } const maciContractAbi = parseArtifact('MACI')[0] @@ -106,7 +106,7 @@ const topup = async (args: any) => { const pollAddr = await maciContract.getPoll(pollId) if (! (await contractExists(signer.provider, pollAddr))) { console.error('Error: there is no Poll contract with this poll ID linked to the specified MACI contract.') - return 1 + return } const pollContract = new ethers.Contract( @@ -134,9 +134,9 @@ const topup = async (args: any) => { console.error(e.message) } } - return 1 + return } - return 0 + return } export { diff --git a/cli/ts/verify.ts b/cli/ts/verify.ts index d2fc3b740b..c4826d6c7d 100644 --- a/cli/ts/verify.ts +++ b/cli/ts/verify.ts @@ -85,15 +85,15 @@ const verify = async (args: any) => { let contractAddrs = readJSONFile(contractFilepath) if ((!contractAddrs||!contractAddrs["MACI"]) && !args.contract) { console.error('Error: MACI contract address is empty') - return 1 + return } if ((!contractAddrs||!contractAddrs["Tally-"+pollId]) && !args.tally_contract) { console.error('Error: Tally contract address is empty') - return 1 + return } if ((!contractAddrs||!contractAddrs["Subsidy-"+pollId]) && !args.subsidy_contract) { console.error('Error: Subsidy contract address is empty') - return 1 + return } const maciAddress = args.contract ? args.contract: contractAddrs["MACI"] @@ -103,19 +103,19 @@ const verify = async (args: any) => { // MACI contract if (!validateEthAddress(maciAddress)) { console.error('Error: invalid MACI contract address') - return 1 + return } // Tally contract if (!validateEthAddress(tallyAddress)) { console.error('Error: invalid Tally contract address') - return 1 + return } // Subsidy contract if (!validateEthAddress(subsidyAddress)) { console.error('Error: invalid Subsidy contract address') - return 1 + return } const [ maciContractAbi ] = parseArtifact('MACI') const [ pollContractAbi ] = parseArtifact('Poll') @@ -124,11 +124,11 @@ const verify = async (args: any) => { if (! (await contractExists(signer.provider, tallyAddress))) { console.error(`Error: there is no contract deployed at ${tallyAddress}.`) - return 1 + return } if (!(await contractExists(signer.provider, subsidyAddress))) { console.error(`Error: there is no contract deployed at ${subsidyAddress}.`) - return 1 + return } const maciContract = new ethers.Contract( @@ -140,7 +140,7 @@ const verify = async (args: any) => { const pollAddr = await maciContract.polls(pollId) if (!(await contractExists(signer.provider, pollAddr))) { console.error('Error: there is no Poll contract with this poll ID linked to the specified MACI contract.') - return 1 + return } const pollContract = new ethers.Contract( @@ -172,7 +172,7 @@ const verify = async (args: any) => { contents = fs.readFileSync(args.tally_file, { encoding: 'utf8' }) } catch { console.error('Error: unable to open ', args.tally_file) - return 1 + return } // Parse the tally file @@ -181,7 +181,7 @@ const verify = async (args: any) => { data = JSON.parse(contents) } catch { console.error('Error: unable to parse ', args.tally_file) - return 1 + return } console.log('-------------tally data -------------------') @@ -193,7 +193,7 @@ const verify = async (args: any) => { if (!validResultsCommitment) { console.error('Error: invalid results commitment format') - return 1 + return } const treeDepths = await pollContract.treeDepths() @@ -205,12 +205,12 @@ const verify = async (args: any) => { // Get vote option tree depth if (data.results.tally.length !== numVoteOptions) { console.error(wrongNumVoteOptions) - return 1 + return } if (data.perVOSpentVoiceCredits.tally.length !== numVoteOptions) { console.error(wrongNumVoteOptions) - return 1 + return } // Verify that the results commitment matches the output of @@ -247,7 +247,7 @@ const verify = async (args: any) => { if (onChainTallyCommitment !== newTallyCommitment) { console.log('Error: the on-chain tally commitment does not match.') - return 1 + return } // ---------------------------------------------- @@ -261,14 +261,14 @@ const verify = async (args: any) => { contents = fs.readFileSync(args.subsidy_file, { encoding: 'utf8' }) } catch { console.error('Error: unable to open ', args.subsidy_file) - return 0 + return } // Parse the file try { data = JSON.parse(contents) } catch { console.error('Error: unable to parse ', args.subsidy_file) - return 0 + return } console.log('-------------subsidy data -------------------') console.log(data) @@ -279,12 +279,12 @@ const verify = async (args: any) => { if (!validResultsCommitment) { console.error('Error: invalid results commitment format') - return 1 + return } if (data.results.subsidy.length !== numVoteOptions) { console.error(wrongNumVoteOptions) - return 1 + return } // to compute newSubsidyCommitment, we can use genTallyResultCommitment @@ -296,13 +296,13 @@ const verify = async (args: any) => { if (onChainSubsidyCommitment !== newSubsidyCommitment) { console.log('Error: the on-chain subsidy commitment does not match.') - return 1 + return } } console.log('OK. finish verify') - return 0 + return } export {