From 8368c53976dd7643073c2c732571158c9b85242d Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Mon, 31 May 2021 20:41:10 +0200 Subject: [PATCH] Fix tutorial test and templates relative path --- build/cli.cjs | 16 +- circuit_final.zkey.json | 329 ---------------------------------------- cli.js | 16 +- 3 files changed, 26 insertions(+), 335 deletions(-) delete mode 100644 circuit_final.zkey.json diff --git a/build/cli.cjs b/build/cli.cjs index be4f0b7..1f90e95 100755 --- a/build/cli.cjs +++ b/build/cli.cjs @@ -8328,6 +8328,11 @@ async function zkeyExportJson$1(params, options) { await fs__default['default'].promises.writeFile(zkeyJsonName, S); } +async function fileExists(file) { + return fs__default['default'].promises.access(file, fs__default['default'].constants.F_OK) + .then(() => true) + .catch(() => false); +} // solidity genverifier [circuit_final.zkey] [verifier.sol] async function zkeyExportSolidityVerifier(params, options) { let zkeyName; @@ -8349,9 +8354,14 @@ async function zkeyExportSolidityVerifier(params, options) { const templates = {}; - templates.groth16 = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "templates", "verifier_groth16.sol.ejs"), "utf8"); - templates.plonk = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "templates", "verifier_plonk.sol.ejs"), "utf8"); - + if (await fileExists(path__default['default'].join(__dirname$2, "templates"))) { + templates.groth16 = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "templates", "verifier_groth16.sol.ejs"), "utf8"); + templates.plonk = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "templates", "verifier_plonk.sol.ejs"), "utf8"); + } else { + templates.groth16 = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "..", "templates", "verifier_groth16.sol.ejs"), "utf8"); + templates.plonk = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "..", "templates", "verifier_plonk.sol.ejs"), "utf8"); + } + const verifierCode = await exportSolidityVerifier(zkeyName, templates); fs__default['default'].writeFileSync(verifierName, verifierCode, "utf-8"); diff --git a/circuit_final.zkey.json b/circuit_final.zkey.json deleted file mode 100644 index 7577878..0000000 --- a/circuit_final.zkey.json +++ /dev/null @@ -1,329 +0,0 @@ -{ - "protocol": "groth16", - "n8q": 32, - "q": "21888242871839275222246405745257275088696311157297823662689037894645226208583", - "n8r": 32, - "r": "21888242871839275222246405745257275088548364400416034343698204186575808495617", - "nVars": 6, - "nPublic": 2, - "domainSize": 8, - "power": 3, - "vk_alpha_1": [ - "1", - "2", - "1" - ], - "vk_beta_1": [ - "1", - "2", - "1" - ], - "vk_beta_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - [ - "1", - "0" - ] - ], - "vk_gamma_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - [ - "1", - "0" - ] - ], - "vk_delta_1": [ - "1", - "2", - "1" - ], - "vk_delta_2": [ - [ - "10857046999023057135944570762232829481370756359578518086990519993285655852781", - "11559732032986387107991004021392285783925812861821192530917403151452391805634" - ], - [ - "8495653923123431417604973247489272438418190587263600148770280649306958101930", - "4082367875863433681332203403145435568316851327593401208105741076214120093531" - ], - [ - "1", - "0" - ] - ], - "IC": [ - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "1", - "2", - "1" - ] - ], - "ccoefs": [ - { - "matrix": 0, - "constraint": 1, - "signal": 4, - "value": "1" - }, - { - "matrix": 1, - "constraint": 1, - "signal": 2, - "value": "1" - }, - { - "matrix": 0, - "constraint": 3, - "signal": 0, - "value": "1" - }, - { - "matrix": 0, - "constraint": 4, - "signal": 1, - "value": "1" - }, - { - "matrix": 0, - "constraint": 5, - "signal": 2, - "value": "1" - } - ], - "A": [ - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ] - ], - "B1": [ - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ] - ], - "B2": [ - [ - [ - "0", - "0" - ], - [ - "1", - "0" - ], - [ - "0", - "0" - ] - ], - [ - [ - "0", - "0" - ], - [ - "1", - "0" - ], - [ - "0", - "0" - ] - ], - [ - [ - "0", - "0" - ], - [ - "1", - "0" - ], - [ - "0", - "0" - ] - ], - [ - [ - "0", - "0" - ], - [ - "1", - "0" - ], - [ - "0", - "0" - ] - ], - [ - [ - "0", - "0" - ], - [ - "1", - "0" - ], - [ - "0", - "0" - ] - ], - [ - [ - "0", - "0" - ], - [ - "1", - "0" - ], - [ - "0", - "0" - ] - ] - ], - "C": [ - null, - null, - null, - [ - "1", - "21888242871839275222246405745257275088696311157297823662689037894645226208581", - "1" - ], - [ - "1", - "21888242871839275222246405745257275088696311157297823662689037894645226208581", - "1" - ], - [ - "0", - "1", - "0" - ] - ], - "hExps": [ - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ], - [ - "0", - "1", - "0" - ] - ] -} \ No newline at end of file diff --git a/cli.js b/cli.js index a048941..c4c895d 100755 --- a/cli.js +++ b/cli.js @@ -546,6 +546,11 @@ async function zkeyExportJson(params, options) { await fs.promises.writeFile(zkeyJsonName, S); } +async function fileExists(file) { + return fs.promises.access(file, fs.constants.F_OK) + .then(() => true) + .catch(() => false); +} // solidity genverifier [circuit_final.zkey] [verifier.sol] async function zkeyExportSolidityVerifier(params, options) { let zkeyName; @@ -567,9 +572,14 @@ async function zkeyExportSolidityVerifier(params, options) { const templates = {}; - templates.groth16 = await fs.promises.readFile(path.join(__dirname, "templates", "verifier_groth16.sol.ejs"), "utf8"); - templates.plonk = await fs.promises.readFile(path.join(__dirname, "templates", "verifier_plonk.sol.ejs"), "utf8"); - + if (await fileExists(path.join(__dirname, "templates"))) { + templates.groth16 = await fs.promises.readFile(path.join(__dirname, "templates", "verifier_groth16.sol.ejs"), "utf8"); + templates.plonk = await fs.promises.readFile(path.join(__dirname, "templates", "verifier_plonk.sol.ejs"), "utf8"); + } else { + templates.groth16 = await fs.promises.readFile(path.join(__dirname, "..", "templates", "verifier_groth16.sol.ejs"), "utf8"); + templates.plonk = await fs.promises.readFile(path.join(__dirname, "..", "templates", "verifier_plonk.sol.ejs"), "utf8"); + } + const verifierCode = await zkey.exportSolidityVerifier(zkeyName, templates, logger); fs.writeFileSync(verifierName, verifierCode, "utf-8");