You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
1.1 KiB

5 years ago
  1. const assert = require("assert");
  2. const fs = require("fs");
  3. const path = require("path");
  4. const snarkjs = require("snarkjs");
  5. const buildGroth16 = require("../index.js").buildGroth16;
  6. describe("Basic tests for groth16 proof generator", () => {
  7. it("It should do a basic point doubling G1", async () => {
  8. const groth16 = await buildGroth16();
  9. const signals = fs.readFileSync(path.join(__dirname, "data", "witness.bin"));
  10. const provingKey = fs.readFileSync(path.join(__dirname, "data", "proving_key.bin"));
  11. const proofS = await groth16.proof(signals.buffer, provingKey.buffer);
  12. const proof = snarkjs.unstringifyBigInts(proofS);
  13. const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")));
  14. const pub = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "public.json"), "utf8")));
  15. assert(snarkjs.groth.isValid(verifierKey, proof, pub));
  16. groth16.terminate();
  17. }).timeout(10000000);
  18. });