Skip to content

Commit

Permalink
Merge pull request privacy-scaling-explorations#7 from succinctlabs/k…
Browse files Browse the repository at this point in the history
…evjue/verification_subcommands_fixes

Fixes for verification subcommands
  • Loading branch information
kevjue authored Mar 10, 2023
2 parents a9877c9 + f41d785 commit 8ff7729
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
42 changes: 20 additions & 22 deletions ts/verify_contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand All @@ -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}`)
Expand Down
20 changes: 11 additions & 9 deletions ts/verify_initial_zkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

const configureSubparsers = (subparsers: ArgumentParser) => {
const parser = subparsers.add_parser(
'verify',
'verify_initial_zkeys',
{ add_help: true },
)

Expand All @@ -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)
Expand All @@ -48,29 +51,28 @@ 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.`)

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 })
Expand Down

0 comments on commit 8ff7729

Please sign in to comment.