From f41d785b352969a7a8e043b8986067d9192f6a39 Mon Sep 17 00:00:00 2001 From: Kevin Jue Date: Thu, 9 Mar 2023 18:33:44 -0800 Subject: [PATCH] got the verification sub commands working --- ts/index.ts | 2 +- ts/verify_contribution.ts | 42 ++++++++++++++++++-------------------- ts/verify_initial_zkeys.ts | 20 ++++++++++-------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/ts/index.ts b/ts/index.ts index 274c4be..8871ee0 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -65,7 +65,7 @@ const run = async () => { } else if (args.subcommand === 'upload') { return (await upload(args.contributorNum, args.contributorHandle, args.s3bucket)) } else if (args.subcommand === 'verify_contribution') { - return (await verify_contribution(args.participantNum, args.ptau)) + return (await verify_contribution(args.contributorNum, args.s3bucket)) } else if (args.subcommand === 'verify_initial_zkeys') { return (await verify_initial_zkeys(args.s3bucket)) } diff --git a/ts/verify_contribution.ts b/ts/verify_contribution.ts index d77024f..a3b483b 100644 --- a/ts/verify_contribution.ts +++ b/ts/verify_contribution.ts @@ -46,27 +46,23 @@ const verify_contribution = async ( ) => { // Download the contribution and initial zkey files - download(contributorNum, s3bucket) - download(0, s3bucket) + const contributionDirname = getDirName(contributorNum, s3bucket) + const initialDirName = getDirName(0, s3bucket) + + const contributionDirNameCmd = `aws s3 sync ${s3bucket}/${contributionDirname} ${WORKSPACE_DIR}/${contributionDirname} --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` + console.log("contributionDirNameCmd is:", contributionDirNameCmd); + const contributionDirNameOut = shelljs.exec(contributionDirNameCmd, { silent: false }) + const initialDirNameCmd = `aws s3 sync ${s3bucket}/${initialDirName} ${WORKSPACE_DIR}/${initialDirName} --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` + console.log("initialDirNameCmd is:", initialDirNameCmd); + const initialDirNameOut = shelljs.exec(initialDirNameCmd, { silent: false }) // Download the ptau file - const downloadPtauCmd = `aws s3 sync ${s3bucket}/ptau/${PTAU_FILENAME} ${WORKSPACE_DIR}/ --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` - const downloadPtauOut = shelljs.exec(downloadPtauCmd, { silent: true }) + const downloadPtauCmd = `aws s3 sync ${s3bucket}/ptau/ ${WORKSPACE_DIR}/ptau --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` + console.log("downloadPtauCmd is:", downloadPtauCmd); + const downloadPtauOut = shelljs.exec(downloadPtauCmd, { silent: false }) - if (downloadPtauOut.code !== 0) { - console.error(`Error: could not download file ${s3bucket}/ptau/${PTAU_FILENAME}`) - console.error(downloadPtauOut.code, downloadPtauOut.stderr) - return 1 - } - - const contributionDirname = getDirName(contributorNum, s3bucket); - const contributionFiles = getZkeyFiles(contributionDirname) - - const initialDirName = getDirName(0, s3bucket); - const initialZkeyFiles = getZkeyFiles(initialDirName) - - // At this point, we know that the downloaded directories each has a STEP and ROTATE zkey file. - // The download function will verify that. + const contributionFiles = getZkeyFiles(`${WORKSPACE_DIR}/${contributionDirname}`) + const initialZkeyFiles = getZkeyFiles(`${WORKSPACE_DIR}/${initialDirName}`) for (const zkeyName of ZKEY_NAMES.values()) { console.log(`Verifying the ${zkeyName} contribution.`) @@ -76,20 +72,22 @@ const verify_contribution = async ( for (const contribution of contributionFiles) { if (contribution.name == zkeyName) { - contributionFilename = path.join(WORKSPACE_DIR, contribution.name) + contributionFilename = contribution.filename + break } } for (const initial of initialZkeyFiles) { if (initial.name == zkeyName) { - initialFilename = path.join(WORKSPACE_DIR, initial.name) + initialFilename = initial.filename + break } } - const cmd = `node --es-module-specifier-resolution=node --async-stack-traces --no-warnings --max-old-space-size=2048000 --initial-old-space-size=2048000 --no-global-gc-scheduling --no-incremental-marking --max-semi-space-size=1024 --initial-heap-size=2048000 --expose-gc ./node_modules/.bin/snarkjs zkvi ${initialFilename} ${PTAU_FILENAME} ${contributionFilename}` + const cmd = `node --es-module-specifier-resolution=node --async-stack-traces --no-warnings --max-old-space-size=2048000 --initial-old-space-size=2048000 --no-global-gc-scheduling --no-incremental-marking --max-semi-space-size=1024 --initial-heap-size=2048000 --expose-gc ./node_modules/.bin/snarkjs -v zkvi ${initialFilename} ${WORKSPACE_DIR}/ptau/${PTAU_FILENAME} ${contributionFilename}` console.log("Going to run the command: " + cmd); - const out = shelljs.exec(cmd, { silent: true }) + const out = shelljs.exec(cmd, { silent: false }) if (out.code !== 0) { console.error(`Error: Verification failed for circuit ${zkeyName} and contributor ${contributorNum}`) diff --git a/ts/verify_initial_zkeys.ts b/ts/verify_initial_zkeys.ts index 7abd4f8..594a352 100644 --- a/ts/verify_initial_zkeys.ts +++ b/ts/verify_initial_zkeys.ts @@ -14,7 +14,7 @@ import { const configureSubparsers = (subparsers: ArgumentParser) => { const parser = subparsers.add_parser( - 'verify', + 'verify_initial_zkeys', { add_help: true }, ) @@ -35,11 +35,14 @@ const verify_initial_zkeys = async ( ) => { // Download the initial zkey files - download(0, s3bucket) + const initialDirName = getDirName(0, s3bucket) + const initialDirNameCmd = `aws s3 sync ${s3bucket}/${initialDirName} ${WORKSPACE_DIR}/${initialDirName} --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` + console.log("initialDirNameCmd is:", initialDirNameCmd); + const initialDirNameOut = shelljs.exec(initialDirNameCmd, { silent: false }) // Download the ptau file - const downloadPtauCmd = `aws s3 sync ${s3bucket}/ptau/${PTAU_FILENAME} ${WORKSPACE_DIR}/ --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` - const downloadPtauOut = shelljs.exec(downloadPtauCmd, { silent: true }) + const downloadPtauCmd = `aws s3 sync ${s3bucket}/ptau/${PTAU_FILENAME} ${WORKSPACE_DIR}/ptau --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` + const downloadPtauOut = shelljs.exec(downloadPtauCmd, { silent: false }) if (downloadPtauOut.code !== 0) { console.error(`Error: could not download file ${s3bucket}/ptau/${PTAU_FILENAME}`) console.error(downloadPtauOut.code, downloadPtauOut.stderr) @@ -48,15 +51,14 @@ const verify_initial_zkeys = async ( // Download the r1cs files const downloadR1CSCmd = `aws s3 sync ${s3bucket}/r1cs/ ${WORKSPACE_DIR}/r1cs/ --region us-east-1 --endpoint-url https://s3-accelerate.amazonaws.com` - const downloadR1CSOut = shelljs.exec(downloadR1CSCmd, { silent: true }) + const downloadR1CSOut = shelljs.exec(downloadR1CSCmd, { silent: false }) if (downloadR1CSOut.code !== 0) { console.error(`Error: could not download r1cs files from ${s3bucket}/r1cs/`) console.error(downloadR1CSOut.code, downloadR1CSOut.stderr) return 1 } - const initialDirName = getDirName(0, s3bucket); - const initialZkeyFiles = getZkeyFiles(initialDirName) + const initialZkeyFiles = getZkeyFiles(`${WORKSPACE_DIR}/${initialDirName}`) for (const zkeyName of ZKEY_NAMES.values()) { console.log(`Verifying the ${zkeyName} initial zkey.`) @@ -64,13 +66,13 @@ const verify_initial_zkeys = async ( let initialFilename = '' for (const initial of initialZkeyFiles) { if (initial.name == zkeyName) { - initialFilename = path.join(WORKSPACE_DIR, initial.name) + initialFilename = initial.filename } } const r1csFilename = path.join(WORKSPACE_DIR, 'r1cs', `${zkeyName}.r1cs`) - const cmd = `node --es-module-specifier-resolution=node --async-stack-traces --no-warnings --max-old-space-size=2048000 --initial-old-space-size=2048000 --no-global-gc-scheduling --no-incremental-marking --max-semi-space-size=1024 --initial-heap-size=2048000 --expose-gc ./node_modules/.bin/snarkjs zkey verify ${r1csFilename} ${PTAU_FILENAME} ${initialFilename}` + const cmd = `node --es-module-specifier-resolution=node --async-stack-traces --no-warnings --max-old-space-size=2048000 --initial-old-space-size=2048000 --no-global-gc-scheduling --no-incremental-marking --max-semi-space-size=1024 --initial-heap-size=2048000 --expose-gc ./node_modules/.bin/snarkjs zkey -v verify ${r1csFilename} ${WORKSPACE_DIR}/ptau/${PTAU_FILENAME} ${initialFilename}` console.log("Going to run the command: " + cmd); const out = shelljs.exec(cmd, { silent: true })