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.

35 lines
1.1 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const snarkjs = require("snarkjs");
  4. const crypto = require("crypto");
  5. const compiler = require("circom");
  6. const assert = chai.assert;
  7. describe("Sum test", () => {
  8. it("Should create a constant circuit", async () => {
  9. const cirDef = await compiler(path.join(__dirname, "circuits", "constants_test.circom"));
  10. assert.equal(cirDef.nVars, 2);
  11. const circuit = new snarkjs.Circuit(cirDef);
  12. const witness = circuit.calculateWitness({ "in": "0xd807aa98" });
  13. assert(witness[0].equals(snarkjs.bigInt(1)));
  14. assert(witness[1].equals(snarkjs.bigInt("0xd807aa98")));
  15. });
  16. it("Should create a sum circuit", async () => {
  17. const cirDef = await compiler(path.join(__dirname, "circuits", "sum_test.circom"));
  18. assert.equal(cirDef.nVars, 97); // 32 (in1) + 32(in2) + 32(out) + 1 (carry)
  19. const circuit = new snarkjs.Circuit(cirDef);
  20. const witness = circuit.calculateWitness({ "a": "111", "b": "222" });
  21. assert(witness[0].equals(snarkjs.bigInt(1)));
  22. assert(witness[1].equals(snarkjs.bigInt("333")));
  23. });
  24. });