-
Notifications
You must be signed in to change notification settings - Fork 1
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 #19 from EYBlockchain/liju.jose/concurrent-generat…
…e-proof-fix bug of concurrent generateProof fixed
- Loading branch information
Showing
11 changed files
with
228 additions
and
299 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
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,81 +1,27 @@ | ||
import fs from 'fs'; | ||
import util from 'util'; | ||
import zokrates from '@eyblockchain/zokrates-zexe.js'; | ||
import path from 'path'; | ||
import rabbitmq from '../utils/rabbitmq.mjs'; | ||
import { getProofByCircuitPath } from '../utils/filing.mjs'; | ||
import logger from '../utils/logger.mjs'; | ||
|
||
const unlink = util.promisify(fs.unlink); | ||
import generateProof from '../services/generateProof.mjs'; | ||
|
||
export default function receiveMessage() { | ||
const outputPath = `./output/`; | ||
|
||
rabbitmq.receiveMessage('generate-proof', async message => { | ||
const { replyTo, correlationId } = message.properties; | ||
const { | ||
folderpath, | ||
inputs, | ||
transactionInputs, | ||
outputDirectoryPath, | ||
proofFileName, | ||
backend = 'zexe', | ||
provingScheme = 'gm17', | ||
} = JSON.parse(message.content.toString()); | ||
|
||
const response = { | ||
error: null, | ||
data: null, | ||
}; | ||
|
||
const circuitName = path.basename(folderpath); | ||
|
||
// Delete previous witness/proof files if they exist. | ||
// Prevents bad inputs from going through anyway. | ||
try { | ||
await unlink(`${outputPath}/${folderpath}/${circuitName}_witness`); | ||
await unlink(`${outputPath}/${folderpath}/${circuitName}_proof.json`); | ||
} catch { | ||
// No files to delete. Do nothing. | ||
} | ||
|
||
const opts = {}; | ||
opts.createFile = true; | ||
opts.directory = `./output/${folderpath}` || outputDirectoryPath; | ||
opts.fileName = `${circuitName}_proof.json` || proofFileName; | ||
|
||
try { | ||
logger.info('Compute witness...'); | ||
await zokrates.computeWitness( | ||
`${outputPath}/${folderpath}/${circuitName}_out`, | ||
`${outputPath}/${folderpath}/`, | ||
`${circuitName}_witness`, | ||
inputs, | ||
); | ||
|
||
logger.info('Generate proof...'); | ||
await zokrates.generateProof( | ||
`${outputPath}/${folderpath}/${circuitName}_pk.key`, | ||
`${outputPath}/${folderpath}/${circuitName}_out`, | ||
`${outputPath}/${folderpath}/${circuitName}_witness`, | ||
provingScheme, | ||
backend, | ||
opts, | ||
); | ||
|
||
const { proof, inputs: publicInputs } = await getProofByCircuitPath(folderpath); | ||
|
||
logger.info(`Complete`); | ||
logger.debug(`Responding with proof and inputs:`); | ||
logger.debug(proof); | ||
logger.debug(publicInputs); | ||
|
||
response.data = { proof, inputs: publicInputs, transactionInputs }; | ||
response.data = await generateProof(JSON.parse( | ||
message.content.toString(), | ||
)); | ||
} catch (err) { | ||
logger.error('Error in generate-proof', err); | ||
response.error = 'Proof generation failed'; | ||
} | ||
|
||
rabbitmq.sendMessage(replyTo, response, { correlationId, type: folderpath }); | ||
|
||
rabbitmq.sendMessage(replyTo, response, { correlationId }); | ||
rabbitmq.sendACK(message); | ||
}); | ||
} |
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
Oops, something went wrong.