Skip to content

Commit

Permalink
Merge pull request #41 from zkemail/fix/working-again
Browse files Browse the repository at this point in the history
Fix/working again
  • Loading branch information
jp4g authored Feb 4, 2025
2 parents ec97629 + 7e3c59c commit f52b1aa
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In your Nargo.toml file, add the version of this library you would like to insta

```toml
[dependencies]
zkemail = { tag = "v0.4.0", git = "https://github.com/zkemail/zkemail.nr", directory = "lib" }
zkemail = { tag = "v0.4.2", git = "https://github.com/zkemail/zkemail.nr", directory = "lib" }
```

The library exports the following functions:
Expand Down
4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/zkemail-nr",
"version": "1.3.0",
"version": "1.3.1",
"main": "dist",
"types": "dist",
"license": "MIT",
Expand All @@ -12,7 +12,7 @@
},
"dependencies": {
"@aztec/bb.js": "0.66.0",
"@mach-34/noir-bignum-paramgen": "^1.1.0",
"@mach-34/noir-bignum-paramgen": "^1.1.2",
"@noir-lang/noir_js": "1.0.0-beta.1",
"@noir-lang/noirc_abi": "^1.0.0-beta.1",
"@zk-email/helpers": "^6.3.2"
Expand Down
10 changes: 5 additions & 5 deletions js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function generateEmailVerifierInputs(
rawEmail: Buffer | string,
params: InputGenerationArgs = {}
) {
const dkimResult = await verifyDKIMSignature(rawEmail);
const dkimResult = await verifyDKIMSignature(rawEmail, undefined, undefined, true);

return generateEmailVerifierInputsFromDKIMResult(dkimResult, params);
}
Expand All @@ -120,7 +120,7 @@ export function generateEmailVerifierInputsFromDKIMResult(
dkimResult: DKIMVerificationResult,
params: InputGenerationArgs = {}
): CircuitInput {
const { headers, body, bodyHash, publicKey, signature } = dkimResult;
const { headers, body, bodyHash, publicKey, signature, modulusLength } = dkimResult;

// SHA add padding
const [messagePadded] = sha256Pad(
Expand All @@ -135,11 +135,11 @@ export function generateEmailVerifierInputsFromDKIMResult(
len: headers.length.toString(),
},
pubkey: {
modulus: NoirBignum.bnToLimbStrArray(publicKey),
redc: NoirBignum.bnToRedcLimbStrArray(publicKey),
modulus: NoirBignum.bnToLimbStrArray(publicKey, modulusLength),
redc: NoirBignum.bnToRedcLimbStrArray(publicKey, modulusLength),
},
// modified from original: use noir bignum to format
signature: NoirBignum.bnToLimbStrArray(signature),
signature: NoirBignum.bnToLimbStrArray(signature, modulusLength),
dkim_header_sequence: getHeaderSequence(headers, "dkim-signature"),
};

Expand Down
13 changes: 8 additions & 5 deletions js/src/prover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { UltraPlonkBackend, UltraHonkBackend, ProofData } from "@aztec/bb.js";
import { UltraPlonkBackend, UltraHonkBackend } from "@aztec/bb.js";
import { ProofData } from "@aztec/bb.js/dest/node-cjs/proof";
import { Noir, InputMap, CompiledCircuit } from "@noir-lang/noir_js";
import { InputValue } from "@noir-lang/noirc_abi";
import { InputValue, } from "@noir-lang/noirc_abi";

type ProvingBackend = "honk" | "plonk" | "all";

Expand All @@ -15,14 +16,16 @@ export class ZKEmailProver {
/* The ACIR of the Noir circuit to prove */
circuit: CompiledCircuit,
/* Define the prover backend to use */
private provingBackend: ProvingBackend = "plonk"
private provingBackend: ProvingBackend = "plonk",
/* Threads to use */
private threads: number = 1
) {
// initialize the backends
if (provingBackend === "plonk" || provingBackend === "all") {
this.plonk = new UltraPlonkBackend(circuit.bytecode);
this.plonk = new UltraPlonkBackend(circuit.bytecode, { threads: this.threads });
}
if (provingBackend === "honk" || provingBackend === "all") {
this.honk = new UltraHonkBackend(circuit.bytecode);
this.honk = new UltraHonkBackend(circuit.bytecode, { threads: this.threads });
}
// initialize the Noir instance
this.noir = new Noir(circuit);
Expand Down
14 changes: 8 additions & 6 deletions js/tests/circuits.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import os from "os";
import path from "path";
import { ZKEmailProver } from "../src/prover";
import { generateEmailVerifierInputs } from "../src/index";
Expand Down Expand Up @@ -32,16 +33,17 @@ describe("ZKEmail.nr Circuit Unit Tests", () => {
beforeAll(() => {
//@ts-ignore
// prover1024 = new ZKEmailProver(circuit1024, "all");
let num_cpus = os.cpus().length;
// @ts-ignore
prover2048 = new ZKEmailProver(circuit2048, num_cpus);
//@ts-ignore
prover2048 = new ZKEmailProver(circuit2048);
proverPartialHash = new ZKEmailProver(circuitPartialHash, num_cpus);
//@ts-ignore
proverPartialHash = new ZKEmailProver(circuitPartialHash);
proverMasked = new ZKEmailProver(circuitEmailMask, num_cpus);
//@ts-ignore
proverMasked = new ZKEmailProver(circuitEmailMask);
proverExtractAddresses = new ZKEmailProver(circuitExtractAddresses, num_cpus);
//@ts-ignore
proverExtractAddresses = new ZKEmailProver(circuitExtractAddresses);
//@ts-ignore
proverRemoveSoftLineBreak = new ZKEmailProver(circuitRemoveSoftLineBreak);
proverRemoveSoftLineBreak = new ZKEmailProver(circuitRemoveSoftLineBreak, num_cpus);
});

afterAll(async () => {
Expand Down
22 changes: 12 additions & 10 deletions js/tests/proving.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import os from "os";
import path from "path";
import { ZKEmailProver } from "../src/prover";
import { generateEmailVerifierInputs } from "../src/index";
Expand All @@ -21,14 +22,15 @@ const inputParams = {
maxHeadersLength: 512,
maxBodyLength: 1024,
};
const threads = os.cpus().length;

describe("ZKEmail.nr E2E Tests", () => {
describe("2048-bit circuit", () => {
let prover: ZKEmailProver;
describe("UltraPlonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuit2048, "plonk");
prover = new ZKEmailProver(circuit2048, "plonk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -55,7 +57,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraHonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuit2048, "honk");
prover = new ZKEmailProver(circuit2048, "honk", threads);
});
afterAll(async () => {
prover.destroy();
Expand Down Expand Up @@ -85,7 +87,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraPlonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitPartialHash, "plonk");
prover = new ZKEmailProver(circuitPartialHash, "plonk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -104,7 +106,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraHonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitPartialHash, "honk");
prover = new ZKEmailProver(circuitPartialHash, "honk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -126,7 +128,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraPlonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitEmailMask, "plonk");
prover = new ZKEmailProver(circuitEmailMask, "plonk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -153,7 +155,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraHonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitEmailMask, "honk");
prover = new ZKEmailProver(circuitEmailMask, "honk", threads);
});
afterAll(async () => {
prover.destroy();
Expand Down Expand Up @@ -183,7 +185,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraPlonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitExtractAddresses, "plonk");
prover = new ZKEmailProver(circuitExtractAddresses, "plonk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -202,7 +204,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraHonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitExtractAddresses, "honk");
prover = new ZKEmailProver(circuitExtractAddresses, "honk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -224,7 +226,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraPlonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitRemoveSoftLineBreak, "plonk");
prover = new ZKEmailProver(circuitRemoveSoftLineBreak, "plonk", threads);
});
afterAll(async () => {
prover.destroy();
Expand All @@ -242,7 +244,7 @@ describe("ZKEmail.nr E2E Tests", () => {
describe("UltraHonk", () => {
beforeAll(async () => {
//@ts-ignore
prover = new ZKEmailProver(circuitRemoveSoftLineBreak, "honk");
prover = new ZKEmailProver(circuitRemoveSoftLineBreak, "honk", threads);
});
afterAll(async () => {
prover.destroy();
Expand Down
2 changes: 1 addition & 1 deletion js/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@mach-34/noir-bignum-paramgen@^1.1.0":
"@mach-34/noir-bignum-paramgen@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@mach-34/noir-bignum-paramgen/-/noir-bignum-paramgen-1.1.2.tgz#ba97b7afe43fc28b66abdd67c4e6d68c2bae335c"
integrity sha512-9U/PETHR4Yf8/ezyQgXE5Qz+7mo1wlTv2JuxW90uwXEV3pFlfl5c/Sl95vaHP+ldTllZkUdTXjDnGiirbiUn3w==
Expand Down
4 changes: 2 additions & 2 deletions lib/src/dkim.nr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl RSAPubkey<KEY_LIMBS_1024> {
self.redc[i].assert_max_bit_size::<120>();
}
self.modulus[KEY_LIMBS_1024 - 1].assert_max_bit_size::<1024 - ((KEY_LIMBS_1024 - 1) * 120)>();
self.redc[KEY_LIMBS_1024 - 1].assert_max_bit_size::<1024 - ((KEY_LIMBS_1024 - 1) * 120)>();
self.redc[KEY_LIMBS_1024 - 1].assert_max_bit_size::<120>();
}
}

Expand Down Expand Up @@ -103,6 +103,6 @@ impl RSAPubkey<KEY_LIMBS_2048> {
self.redc[i].assert_max_bit_size::<120>();
}
self.modulus[KEY_LIMBS_2048 - 1].assert_max_bit_size::<2048 - ((KEY_LIMBS_2048 - 1) * 120)>();
self.redc[KEY_LIMBS_2048 - 1].assert_max_bit_size::<2048 - ((KEY_LIMBS_2048 - 1) * 120)>();
self.redc[KEY_LIMBS_2048 - 1].assert_max_bit_size::<120>(); // we get 2053 sometimes?
}
}

0 comments on commit f52b1aa

Please sign in to comment.