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.

66 lines
1.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. const path = require("path");
  2. const bigInt = require("big-integer");
  3. const c_tester = require("../index.js").c_tester;
  4. const wasm_tester = require("../index.js").wasm_tester;
  5. const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
  6. const basicCases = require("./basiccases.json");
  7. function normalize(o) {
  8. if ((typeof(o) == "bigint") || o.isZero !== undefined) {
  9. const res = bigInt(o);
  10. return norm(res);
  11. } else if (Array.isArray(o)) {
  12. return o.map(normalize);
  13. } else if (typeof o == "object") {
  14. const res = {};
  15. for (let k in o) {
  16. res[k] = normalize(o[k]);
  17. }
  18. return res;
  19. } else {
  20. const res = bigInt(o);
  21. return norm(res);
  22. }
  23. function norm(n) {
  24. let res = n.mod(__P__);
  25. if (res.isNegative()) res = __P__.add(res);
  26. return res;
  27. }
  28. }
  29. async function doTest(tester, circuit, testVectors) {
  30. const cir = await tester(path.join(__dirname, "circuits", circuit));
  31. for (let i=0; i<testVectors.length; i++) {
  32. const w = await cir.calculateWitness(normalize(testVectors[i][0]));
  33. // console.log(testVectors[i][0]);
  34. // console.log(w);
  35. // console.log(testVectors[i][1]);
  36. await cir.assertOut(w, normalize(testVectors[i][1]) );
  37. }
  38. await cir.release();
  39. }
  40. describe("basic cases", function () {
  41. this.timeout(100000);
  42. /*
  43. for (let i=0; i<basicCases.length; i++) {
  44. it("c/c++ " + basicCases[i].name, async () => {
  45. await doTest(c_tester, basicCases[i].circuit, basicCases[i].tv);
  46. });
  47. }
  48. */
  49. for (let i=16; i<17; i++) {
  50. it("wasm " + basicCases[i].name, async () => {
  51. await doTest(wasm_tester, basicCases[i].circuit, basicCases[i].tv);
  52. });
  53. }
  54. });