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.

55 lines
1.7 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 chai = require("chai");
  2. const path = require("path");
  3. var blake2b = require("blake2b");
  4. const bigInt = require("big-integer");
  5. const tester = require("circom").tester;
  6. const poseidon = require("../src/poseidon.js");
  7. const assert = chai.assert;
  8. describe("Blake2b version test", function() {
  9. it("Should give the expected output for blake2b version", async () => {
  10. var output = new Uint8Array(32);
  11. var input = Buffer.from("poseidon_constants");
  12. const h = blake2b(output.length).update(input).digest("hex");
  13. assert.equal("e57ba154fb2c47811dc1a2369b27e25a44915b4e4ece4eb8ec74850cb78e01b1", h);
  14. });
  15. });
  16. describe("Poseidon Circuit test", function () {
  17. let circuit;
  18. this.timeout(100000);
  19. before( async () => {
  20. circuit = await tester(path.join(__dirname, "circuits", "poseidon_test.circom"));
  21. });
  22. it("Should check constrain of hash([1, 2])", async () => {
  23. const w = await circuit.calculateWitness({inputs: [1, 2]}, true);
  24. const hash = poseidon.createHash(6, 8, 57);
  25. const res2 = hash([1,2]);
  26. assert.equal("12242166908188651009877250812424843524687801523336557272219921456462821518061", res2.toString());
  27. await circuit.assertOut(w, {out : res2});
  28. await circuit.checkConstraints(w);
  29. });
  30. it("Should check constrain of hash([3, 4])", async () => {
  31. const w = await circuit.calculateWitness({inputs: [3, 4]}, true);
  32. const hash = poseidon.createHash(6, 8, 57);
  33. const res2 = hash([3, 4]);
  34. assert.equal("17185195740979599334254027721507328033796809509313949281114643312710535000993", res2.toString());
  35. await circuit.assertOut(w, {out : res2});
  36. await circuit.checkConstraints(w);
  37. });
  38. });