Skip to content

Commit

Permalink
Merge branch 'feat/audit-fix-2024-09' into feat/body-parsing-with-aud…
Browse files Browse the repository at this point in the history
…it-fix
  • Loading branch information
SoraSuegami committed Oct 24, 2024
2 parents 7f6ac43 + 948104b commit 1481070
Show file tree
Hide file tree
Showing 114 changed files with 11,496 additions and 5,017 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
override: true
components: rustfmt, clippy

- name: Download circom v2.1.8 (Linux)
run: wget https://github.com/iden3/circom/releases/download/v2.1.8/circom-linux-amd64 -O /usr/local/bin/circom && chmod +x /usr/local/bin/circom
- name: Download circom v2.1.9 (Linux)
run: wget https://github.com/iden3/circom/releases/download/v2.1.9/circom-linux-amd64 -O /usr/local/bin/circom && chmod +x /usr/local/bin/circom

- name: Print circom version
run: circom --version

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.0.0",
"description": "Smart contracts to auth messages via emails",
"engines": {
"node": "18"
"node": ">=18"
},
"scripts": {
"test": "yarn workspaces -pt run test",
Expand Down Expand Up @@ -41,4 +41,4 @@
]
]
}
}
}
28 changes: 17 additions & 11 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
{
"name": "@zk-email/ether-email-auth-circom",
"license": "MIT",
"version": "1.0.0",
"version": "0.1.1-preview",
"scripts": {
"build": "mkdir -p build && circom src/email_auth.circom --r1cs --wasm --sym -l ../../node_modules -o ./build",
"build-body": "mkdir -p build && circom src/email_auth_with_body_parsing_with_qp_encoding.circom --r1cs --wasm --sym -l ../../node_modules -o ./build",
"build": "mkdir -p build && circom src/email_auth.circom --r1cs --wasm --sym --c -l ../../node_modules -o ./build",
"build-legacy": "mkdir -p build && circom src/email_auth_legacy.circom --r1cs --wasm --sym --c -l ../../node_modules -o ./build",
"dev-setup": "NODE_OPTIONS=--max_old_space_size=16384 npx ts-node scripts/dev-setup.ts --output ./build",
"gen-input": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/gen_input.ts",
"verify-proofs": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/verify_proofs.ts",
"test": "NODE_OPTIONS=--max_old_space_size=8192 jest"
},
"dependencies": {
"@zk-email/circuits": "=6.1.5",
"@zk-email/circuits": "https://gitpkg.vercel.app/zkemail/zk-email-verify/packages/circuits?057b8e95b7bca2884d8da384379c15be9975b30d",
"@zk-email/relayer-utils": "=0.3.7",
"@zk-email/zk-regex-circom": "=2.1.1",
"commander": "^11.0.0",
"snarkjs": "^0.7.4"
"@zk-email/zk-regex-circom": "=2.2.0",
"commander": "^12.1.0",
"snarkjs": "^0.7.5"
},
"devDependencies": {
"@babel/preset-env": "^7.22.20",
"@babel/preset-typescript": "^7.23.0",
"@types/jest": "^29.5.4",
"chai": "^4.3.7",
"circom_tester": "^0.0.19",
"circom_tester": "^0.0.20",
"circomlib": "^2.0.5",
"circomlibjs": "^0.1.2",
"ffjavascript": "^0.2.59",
"ffjavascript": "^0.3.1",
"jest": "^29.5.0",
"mocha": "^10.2.0",
"ts-jest": "^29.1.1",
Expand All @@ -41,5 +40,12 @@
"jest"
]
]
}
},
"files": [
"/src",
"/helpers",
"/scripts",
"package.json",
"README.md"
]
}
22 changes: 11 additions & 11 deletions packages/circuits/scripts/dev-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ program
"Path to the directory storing output files"
)
.option("--silent", "No console logs")
.option("--body", "Enable body parsing");
.option("--legacy", "Use a legacy circuit");

program.parse();
const args = program.opts();
Expand All @@ -42,10 +42,10 @@ if (ZKEY_BEACON == null) {
}

let phase1Url =
"https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_22.ptau";
if (args.body) {
"https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_23.ptau";
if (args.legacy) {
phase1Url =
"https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_23.ptau";
"https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_22.ptau";
}
// const buildDir = path.join(__dirname, "../build");
// const phase1Path = path.join(buildDir, "powersOfTau28_hez_final_21.ptau");
Expand Down Expand Up @@ -142,30 +142,30 @@ async function exec() {
const buildDir = args.output;


if (!args.body) {
if (args.legacy) {
const phase1Path = path.join(buildDir, "powersOfTau28_hez_final_22.ptau");

await downloadPhase1(phase1Path);
log("✓ Phase 1:", phase1Path);

const emailAuthR1csPath = path.join(buildDir, "email_auth.r1cs");
const emailAuthR1csPath = path.join(buildDir, "email_auth_legacy.r1cs");
if (!fs.existsSync(emailAuthR1csPath)) {
throw new Error(`${emailAuthR1csPath} does not exist.`);
}
await generateKeys(phase1Path, emailAuthR1csPath, path.join(buildDir, "email_auth.zkey"), path.join(buildDir, "email_auth.vkey"), path.join(buildDir, "Groth16Verifier.sol"));
log("✓ Keys for email auth circuit generated");
await generateKeys(phase1Path, emailAuthR1csPath, path.join(buildDir, "email_auth_legacy.zkey"), path.join(buildDir, "email_auth_legacy.vkey"), path.join(buildDir, "Groth16LegacyVerifier.sol"));
log("✓ Keys for email auth legacy circuit generated");
} else {
const phase1Path = path.join(buildDir, "powersOfTau28_hez_final_23.ptau");

await downloadPhase1(phase1Path);
log("✓ Phase 1:", phase1Path);

const emailAuthR1csPath = path.join(buildDir, "email_auth_with_body_parsing_with_qp_encoding.r1cs");
const emailAuthR1csPath = path.join(buildDir, "email_auth.r1cs");
if (!fs.existsSync(emailAuthR1csPath)) {
throw new Error(`${emailAuthR1csPath} does not exist.`);
}
await generateKeys(phase1Path, emailAuthR1csPath, path.join(buildDir, "email_auth_with_body_parsing_with_qp_encoding.zkey"), path.join(buildDir, "email_auth_with_body_parsing_with_qp_encoding.vkey"), path.join(buildDir, "Groth16BodyParsingVerifier.sol"));
log("✓ Keys for email auth with body parsing circuit generated");
await generateKeys(phase1Path, emailAuthR1csPath, path.join(buildDir, "email_auth.zkey"), path.join(buildDir, "email_auth.vkey"), path.join(buildDir, "Groth16Verifier.sol"));
log("✓ Keys for email auth circuit generated");
}

}
Expand Down
18 changes: 9 additions & 9 deletions packages/circuits/scripts/gen_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ program
"Path of a json file to write the generated input"
)
.option("--silent", "No console logs")
.option("--body", "Enable body parsing")
.option("--legacy", "Use a legacy circuit")
.option("--prove", "Also generate proof");

program.parse();
Expand All @@ -43,7 +43,7 @@ async function generate() {
throw new Error("--input file path arg must end with .json");
}

if (!args.body) {
if (args.legacy) {
log("Generating Inputs for:", args);

const circuitInputs = await genEmailCircuitInput(args.emailFile, args.accountCode, {
Expand All @@ -58,10 +58,10 @@ async function generate() {

if (args.prove) {
const dir = path.dirname(args.inputFile);
const { proof, publicSignals } = await snarkjs.groth16.fullProve(circuitInputs, path.join(dir, "email_auth.wasm"), path.join(dir, "email_auth.zkey"), console);
await promisify(fs.writeFile)(path.join(dir, "email_auth_proof.json"), JSON.stringify(proof, null, 2));
await promisify(fs.writeFile)(path.join(dir, "email_auth_public.json"), JSON.stringify(publicSignals, null, 2));
log("✓ Proof for email auth circuit generated");
const { proof, publicSignals } = await snarkjs.groth16.fullProve(circuitInputs, path.join(dir, "email_auth_legacy.wasm"), path.join(dir, "email_auth_legacy.zkey"), console);
await promisify(fs.writeFile)(path.join(dir, "email_auth_legacy_proof.json"), JSON.stringify(proof, null, 2));
await promisify(fs.writeFile)(path.join(dir, "email_auth_legacy_public.json"), JSON.stringify(publicSignals, null, 2));
log("✓ Proof for email auth legacy circuit generated");
}
} else {
log("Generating Inputs for:", args);
Expand All @@ -81,9 +81,9 @@ async function generate() {

if (args.prove) {
const dir = path.dirname(args.inputFile);
const { proof, publicSignals } = await snarkjs.groth16.fullProve(circuitInputs, path.join(dir, "email_auth_with_body_parsing_with_qp_encoding.wasm"), path.join(dir, "email_auth_with_body_parsing_with_qp_encoding.zkey"), console);
await promisify(fs.writeFile)(path.join(dir, "email_auth_with_body_parsing_with_qp_encoding_proof.json"), JSON.stringify(proof, null, 2));
await promisify(fs.writeFile)(path.join(dir, "email_auth_with_body_parsing_with_qp_encoding_public.json"), JSON.stringify(publicSignals, null, 2));
const { proof, publicSignals } = await snarkjs.groth16.fullProve(circuitInputs, path.join(dir, "email_auth.wasm"), path.join(dir, "email_auth.zkey"), console);
await promisify(fs.writeFile)(path.join(dir, "email_auth_proof.json"), JSON.stringify(proof, null, 2));
await promisify(fs.writeFile)(path.join(dir, "email_auth_public.json"), JSON.stringify(publicSignals, null, 2));
log("✓ Proof for email auth circuit generated");
}
}
Expand Down
69 changes: 0 additions & 69 deletions packages/circuits/scripts/verify_proofs.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/circuits/src/email_auth.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.6;

include "./email_auth_template.circom";

component main = EmailAuth(121, 17, 1024, 605, 0);
component main = EmailAuth(121, 17, 1024, 1024, 605, 0, 1);
5 changes: 5 additions & 0 deletions packages/circuits/src/email_auth_legacy.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.6;

include "./email_auth_legacy_template.circom";

component main = EmailAuthLegacy(121, 17, 1024, 605, 0);
Loading

0 comments on commit 1481070

Please sign in to comment.