mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
First iteration sha256
This commit is contained in:
2371
test/circuits/out.json
Normal file
2371
test/circuits/out.json
Normal file
File diff suppressed because it is too large
Load Diff
15
test/circuits/sha256_2_test.circom
Normal file
15
test/circuits/sha256_2_test.circom
Normal file
@@ -0,0 +1,15 @@
|
||||
include "../../circuits/sha256/sha256_2.circom";
|
||||
|
||||
template Main() {
|
||||
signal private input a;
|
||||
signal private input b;
|
||||
signal output out;
|
||||
|
||||
component sha256_2 = Sha256_2();
|
||||
|
||||
sha256_2.a <== a;
|
||||
sha256_2.b <== a;
|
||||
out <== sha256_2.out;
|
||||
}
|
||||
|
||||
component main = Main();
|
||||
@@ -1,6 +1,7 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
const zkSnark = require("zksnark");
|
||||
const crypto = require("crypto");
|
||||
|
||||
const compiler = require("../index.js");
|
||||
|
||||
@@ -31,6 +32,23 @@ describe("SHA256 test", () => {
|
||||
assert(witness[0].equals(zkSnark.bigInt(1)));
|
||||
assert(witness[1].equals(zkSnark.bigInt("333")));
|
||||
});
|
||||
it("Should calculate a hash", async () => {
|
||||
const cirDef = await compiler(path.join(__dirname, "circuits", "sha256_2_test.circom"));
|
||||
const circuit = new zkSnark.Circuit(cirDef);
|
||||
|
||||
const witness = circuit.calculateWitness({ "a": "1", "b": "2" });
|
||||
|
||||
const b = new Buffer.alloc(432);
|
||||
b[115] = 1;
|
||||
b[431] = 2;
|
||||
|
||||
const hash = crypto.createHash("sha256")
|
||||
.update(b)
|
||||
.digest("hex");
|
||||
const r = "0x" + hash.slice(40);
|
||||
|
||||
assert(witness[1].equals(zkSnark.bigInt(r)));
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user