Fix tutorial test and templates relative path

This commit is contained in:
Jordi Baylina 2021-05-31 20:41:10 +02:00
parent e161910344
commit 8368c53976
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
3 changed files with 26 additions and 335 deletions

@ -8328,6 +8328,11 @@ async function zkeyExportJson$1(params, options) {
await fs__default['default'].promises.writeFile(zkeyJsonName, S); 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] // solidity genverifier [circuit_final.zkey] [verifier.sol]
async function zkeyExportSolidityVerifier(params, options) { async function zkeyExportSolidityVerifier(params, options) {
let zkeyName; let zkeyName;
@ -8349,9 +8354,14 @@ async function zkeyExportSolidityVerifier(params, options) {
const templates = {}; const templates = {};
templates.groth16 = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "templates", "verifier_groth16.sol.ejs"), "utf8"); if (await fileExists(path__default['default'].join(__dirname$2, "templates"))) {
templates.plonk = await fs__default['default'].promises.readFile(path__default['default'].join(__dirname$2, "templates", "verifier_plonk.sol.ejs"), "utf8"); 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); const verifierCode = await exportSolidityVerifier(zkeyName, templates);
fs__default['default'].writeFileSync(verifierName, verifierCode, "utf-8"); fs__default['default'].writeFileSync(verifierName, verifierCode, "utf-8");

@ -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"
]
]
}

16
cli.js

@ -546,6 +546,11 @@ async function zkeyExportJson(params, options) {
await fs.promises.writeFile(zkeyJsonName, S); 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] // solidity genverifier [circuit_final.zkey] [verifier.sol]
async function zkeyExportSolidityVerifier(params, options) { async function zkeyExportSolidityVerifier(params, options) {
let zkeyName; let zkeyName;
@ -567,9 +572,14 @@ async function zkeyExportSolidityVerifier(params, options) {
const templates = {}; const templates = {};
templates.groth16 = await fs.promises.readFile(path.join(__dirname, "templates", "verifier_groth16.sol.ejs"), "utf8"); if (await fileExists(path.join(__dirname, "templates"))) {
templates.plonk = await fs.promises.readFile(path.join(__dirname, "templates", "verifier_plonk.sol.ejs"), "utf8"); 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); const verifierCode = await zkey.exportSolidityVerifier(zkeyName, templates, logger);
fs.writeFileSync(verifierName, verifierCode, "utf-8"); fs.writeFileSync(verifierName, verifierCode, "utf-8");