-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
209a111
commit 23350b0
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pragma circom 2.1.5; | ||
|
||
include "../helpers/sha.circom"; | ||
|
||
component main { public [in_padded, in_len_padded_bytes] } = Sha256Bytes(640); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import fs from "fs"; | ||
import { buildMimcSponge } from "circomlibjs"; | ||
import { wasm as wasm_tester } from "circom_tester"; | ||
import { Scalar } from "ffjavascript"; | ||
import path from "path"; | ||
import { DKIMVerificationResult } from "@zk-email/helpers/src/dkim"; | ||
import { generateCircuitInputs } from "@zk-email/helpers/src/input-helpers"; | ||
import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; | ||
import { sha256Pad, shaHash } from "@zk-email/helpers/src/shaHash"; | ||
import { MAX_HEADER_PADDED_BYTES } from "@twitter-verifier/circuits/helpers"; | ||
import { Uint8ArrayToCharArray, uint8ToBits } from "@zk-email/helpers/src/binaryFormat"; | ||
|
||
exports.p = Scalar.fromString( | ||
"21888242871839275222246405745257275088548364400416034343698204186575808495617" | ||
); | ||
|
||
describe("SHA256 for email header", () => { | ||
jest.setTimeout(10 * 60 * 1000); // 10 minutes | ||
|
||
let circuit: any; | ||
|
||
beforeAll(async () => { | ||
circuit = await wasm_tester( | ||
path.join(__dirname, "./sha256-test.circom"), | ||
{ | ||
// @dev During development recompile can be set to false if you are only making changes in the tests. | ||
// This will save time by not recompiling the circuit every time. | ||
// Compile: circom "./tests/email-verifier-test.circom" --r1cs --wasm --sym --c --wat --output "./tests/compiled-test-circuit" | ||
recompile: true, | ||
output: path.join(__dirname, "./compiled-test-circuit"), | ||
include: path.join(__dirname, "../../../node_modules"), | ||
} | ||
); | ||
}); | ||
|
||
it("should hash correctly", async function () { | ||
const inputs = [ | ||
"0", "hello world", "" | ||
] | ||
for (const input of inputs) { | ||
const [ | ||
paddedMsg, | ||
messageLen, | ||
] = sha256Pad( | ||
Buffer.from(input, "ascii"), 640 | ||
) | ||
|
||
const witness = await circuit.calculateWitness({ | ||
in_len_padded_bytes: messageLen, | ||
in_padded: Uint8ArrayToCharArray(paddedMsg) | ||
}); | ||
|
||
await circuit.checkConstraints(witness); | ||
await circuit.assertOut(witness, { out: [...uint8ToBits(shaHash(Buffer.from(input, "ascii")))] }) | ||
} | ||
}); | ||
}); |