-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from EYBlockchain/westlad/verify
feat: add verify capability and update zokrates
- Loading branch information
Showing
8 changed files
with
144 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
FROM docker.pkg.github.com/eyblockchain/zokrates-zexe/zokrates_zexe:a6bfd3bf3fa81fc4b4ced9d6b4a998cb240b21fe as builder | ||
FROM zokrates/zokrates:0.6.3 as builder | ||
|
||
# Actual application (for testing purposes) | ||
FROM node:12 | ||
RUN mkdir /app | ||
WORKDIR /app | ||
COPY ./package.json ./package-lock.json ./ | ||
COPY --from=builder /home/zokrates/zokrates /app/zokrates | ||
COPY --from=builder /home/zokrates/.zokrates* /app/stdlib | ||
COPY --from=builder /home/zokrates/.zokrates/bin/zokrates /app/ | ||
COPY --from=builder /home/zokrates/.zokrates/stdlib/ /app/ | ||
ENV ZOKRATES_HOME='/app' | ||
RUN npm ci | ||
RUN npm install jest --g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const childProcess = require('child_process'); | ||
const jsonfile = require('jsonfile'); | ||
const deleteFile = require('./utils/utils'); | ||
|
||
const { spawn } = childProcess; | ||
const { writeFile } = jsonfile; | ||
|
||
/** | ||
* Takes in a proof and a verification key and determines if the proof verifies. | ||
* | ||
* @example | ||
* generateProof('./code/ft-mint/ft-mint-pk.key', | ||
* './code/ft-mint/ft-mint-compiled', | ||
* 'gm17', | ||
* { | ||
* createFile: true, | ||
* directory: './code/ft-mint', | ||
* fileName: 'ft-mint-proof.json', | ||
* }, | ||
* ); | ||
* | ||
* @param {String} provingKeyPath - Path to proving key | ||
* @param {String} codePath - Path to code file (Result of compile that doesn't end in .code) | ||
* @param {String} provingScheme - Available options are 'g16', 'pghr13', 'gm17' | ||
* @param {String} backEnd - Available options are 'libsnark', 'bellman', 'ark' | ||
* @param {Object} [options] - Options for output | ||
* @param {Boolean} options.createFile - Whether or not to output a json file | ||
* @param {String} [options.directory=./] - Directory to output files in | ||
* @param {String} [options.fileName=proof.json] - Name of JSON proof file () | ||
* @returns {Object} JSON of the proof. | ||
*/ | ||
async function verify(vk, proof, provingScheme = 'gm17', backend = 'ark', curve = 'bn128') { | ||
// we've provided a json proof and a verifying key but Zokrates needs to read | ||
// these from a file. Thus we should write them to temporary files. | ||
const proofTempFile = '/tmp/proof.json'; | ||
const vkTempFile = '/tmp/verify.key'; | ||
await Promise.all([writeFile(vkTempFile, vk), writeFile(proofTempFile, proof)]); | ||
|
||
const args = [ | ||
'verify', | ||
'-v', | ||
vkTempFile, | ||
'-j', | ||
proofTempFile, | ||
'--proving-scheme', | ||
provingScheme, | ||
'--backend', | ||
backend, | ||
'--curve', | ||
curve, | ||
]; | ||
|
||
return new Promise((resolve, reject) => { | ||
const zokrates = spawn('/app/zokrates', args, { | ||
stdio: ['ignore', 'pipe', 'pipe'], | ||
env: { | ||
ZOKRATES_HOME: '/app/stdlib', | ||
}, | ||
}); | ||
|
||
let output = ''; | ||
zokrates.stdout.on('data', data => { | ||
output += data.toString('utf8'); | ||
}); | ||
|
||
zokrates.stderr.on('data', err => { | ||
reject(new Error(`Verify failed: ${err}`)); | ||
}); | ||
|
||
zokrates.on('close', () => { | ||
// we no longer need the temporary files | ||
deleteFile(proofTempFile); | ||
deleteFile(vkTempFile); | ||
// ZoKrates sometimes outputs error through stdout instead of stderr, | ||
// so we need to catch those errors manually. | ||
if (output.includes('panicked')) reject(new Error(output.slice(output.indexOf('panicked')))); | ||
|
||
if (output.includes('PASS')) resolve(true); | ||
else resolve(false); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = verify; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters