Skip to content

Commit

Permalink
Merge pull request #766 from privacy-scaling-explorations/fix/error-c…
Browse files Browse the repository at this point in the history
…odes

fix(cli) - fix incosistencies on return codes
  • Loading branch information
baumstern authored Oct 30, 2023
2 parents d1af4c1 + be79cf3 commit 300772d
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 180 deletions.
16 changes: 16 additions & 0 deletions cli/downloadZkeys.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions cli/ts/airdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -138,10 +138,10 @@ const airdrop = async (args: any) => {
if (e.message) {
console.error(e.message)
}
return 1
return
}
}
return 0
return
}

export {
Expand Down
11 changes: 5 additions & 6 deletions cli/ts/checkVerifyingKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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')
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions cli/ts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -135,7 +135,6 @@ const create = async (args: any) => {
contractAddrs['PoseidonT5'] = poseidonAddrs[2]
contractAddrs['PoseidonT6'] = poseidonAddrs[3]
writeJSONFile(contractFilepath, contractAddrs)
return 0
}

export {
Expand Down
18 changes: 9 additions & 9 deletions cli/ts/deployPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -159,15 +159,15 @@ 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
const coordinatorPubkey = args.pubkey

if (!PubKey.isValidSerializedPubKey(coordinatorPubkey)) {
console.error('Error: invalid MACI public key')
return {}
return
}

const unserialisedPubkey = PubKey.unserialize(coordinatorPubkey)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions cli/ts/deployPollWithSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,34 +134,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
Expand All @@ -174,15 +174,15 @@ 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
const coordinatorPubkey = args.pubkey

if (!PubKey.isValidSerializedPubKey(coordinatorPubkey)) {
console.error('Error: invalid MACI public key')
return 1
return
}

const unserialisedPubkey = PubKey.unserialize(coordinatorPubkey)
Expand Down Expand Up @@ -226,7 +226,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
Expand All @@ -245,10 +245,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 {
Expand Down
2 changes: 1 addition & 1 deletion cli/ts/deployVkRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const deployVkRegistry = async (args: any) => {
fs.renameSync(contractFilepath, contractFilepathOld)
}
writeJSONFile(contractFilepath, {'VkRegistry':vkRegistryContract.address})
return 0
return
}

export {
Expand Down
4 changes: 2 additions & 2 deletions cli/ts/fundWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ const fundWallet = async (args: any) => {
await tx.wait()
} catch (e) {
console.error(e)
return 1
return
}

return 0
return
}

export {
Expand Down
4 changes: 3 additions & 1 deletion cli/ts/genMaciPubkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ const genMaciPubkey = async (args: any) => {
const isValid = PrivKey.isValidSerializedPrivKey(args.privkey)
if (!isValid) {
console.error('Error: invalid private key')
return
return
}

const unserialisedPrivkey = PrivKey.unserialize(args.privkey)
const pubkey = new PubKey(genPubKey(unserialisedPrivkey.rawPrivKey))
console.log(pubkey.serialize())

return
}

export {
Expand Down
Loading

0 comments on commit 300772d

Please sign in to comment.