snarkjs/test/kimleeoh.js

49 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-06-16 01:12:50 +03:00
/*
Copyright 2018 0kims association.
This file is part of zksnark JavaScript library.
zksnark JavaScript library is a free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your option)
any later version.
zksnark JavaScript library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
zksnark JavaScript library. If not, see <https://www.gnu.org/licenses/>.
*/
2020-03-28 21:40:30 +03:00
2019-06-16 01:12:50 +03:00
const chai = require("chai");
const fs = require("fs");
const path = require("path");
2020-03-28 21:40:30 +03:00
const loadR1cs = require("r1csfile").load;
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
const zkSnark = require("../index.js");
const WitnessCalculatorBuilder = require("circom_runtime").WitnessCalculatorBuilder;
2019-06-16 01:12:50 +03:00
const assert = chai.assert;
2020-03-28 21:40:30 +03:00
describe("zkSnark kimleeoh", () => {
it("Load a circuit, create trusted setup, create a proof and validate it", async () => {
const cir = await loadR1cs(path.join(__dirname, "circuit", "circuit.r1cs"), true);
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
const setup = zkSnark.kimleeoh.setup(cir);
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
const wasm = await fs.promises.readFile(path.join(__dirname, "circuit", "circuit.wasm"));
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
const wc = await WitnessCalculatorBuilder(wasm, {sanityCheck: true});
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
const witness = await wc.calculateWitness({"a": "33", "b": "34"});
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
const {proof, publicSignals} = zkSnark.kimleeoh.genProof(setup.vk_proof, witness);
2019-06-16 01:12:50 +03:00
2020-03-28 21:40:30 +03:00
assert( zkSnark.kimleeoh.isValid(setup.vk_verifier, proof, publicSignals));
2019-06-16 01:12:50 +03:00
}).timeout(10000000);
});
2020-03-28 21:40:30 +03:00