Skip to content

Commit

Permalink
Updating circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Jul 23, 2024
1 parent 88fa525 commit 698c312
Show file tree
Hide file tree
Showing 23 changed files with 203 additions and 1,064 deletions.
22 changes: 0 additions & 22 deletions packages/circuits/helpers/account_creation.ts

This file was deleted.

18 changes: 18 additions & 0 deletions packages/circuits/helpers/psi_points.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const emailWalletUtils = require("@zk-email/relayer-utils");

export async function genPsiPointsInput(
emailAddr: string,
accountCode: string,
relayerRand: string,
): Promise<{
email_addr: number[];
account_code: string;
relayer_rand: string;
}> {
const paddedEmailAddr = emailWalletUtils.padEmailAddr(emailAddr);
return {
email_addr: paddedEmailAddr,
account_code: accountCode,
relayer_rand: relayerRand,
};
}
15 changes: 8 additions & 7 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"license": "MIT",
"version": "1.0.0",
"scripts": {
"build": "mkdir -p build && yarn build-account-creation && yarn build-claim && yarn build-email-sender && yarn build-announcement",
"build-account-creation": "mkdir -p build/account_creation && circom src/account_creation.circom --r1cs --wasm --sym -l ../../node_modules -o ./build/account_creation",
"build": "mkdir -p build && yarn build-claim && yarn build-email-sender && yarn build-announcement && yarn build-psi-points",
"build-claim": "mkdir -p build/claim && circom src/claim.circom --r1cs --wasm --sym -l ../../node_modules -o ./build/claim",
"build-email-sender": "mkdir -p build/email_sender && circom src/email_sender.circom --r1cs --wasm --sym -l ../../node_modules -o ./build/email_sender",
"build-announcement": "mkdir -p build/announcement && circom src/announcement.circom --r1cs --wasm --sym -l ../../node_modules -o ./build/announcement",
"build-psi-points": "mkdir -p build/psi_points && circom src/psi_points.circom --r1cs --wasm --sym -l ../../node_modules -o ./build/psi_points",
"dev-setup": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/dev-setup.ts --output ./build",
"gen-account-creation-input": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/account_creation.ts",
"gen-claim-input": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/claim.ts",
"gen-email-sender-input": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/email_sender.ts",
"gen-announcement-input": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/announcement.ts",
"gen-psi-points-input": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/psi_points.ts",
"gen-random-proofs": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/gen_random_proofs.ts",
"verify-proofs": "NODE_OPTIONS=--max_old_space_size=8192 npx ts-node scripts/verify_proofs.ts",
"extract-email-sign-rand": "npx ts-node scripts/extract_email_sign_rand.ts",
Expand All @@ -22,10 +22,11 @@
"test": "NODE_OPTIONS=--max_old_space_size=8192 jest"
},
"dependencies": {
"@zk-email/circuits": "^3.2.3",
"@zk-email/helpers": "^3.1.3",
"@zk-email/zk-regex-circom": "^1.2.2",
"@zk-email/relayer-utils": "^0.2.3",
"@zk-email/circuits": "^6.1.1",
"@zk-email/ether-email-auth-circom": "/Users/suegamisora/codes/ether-email-auth/packages/circuits",
"@zk-email/helpers": "^6.1.1",
"@zk-email/relayer-utils": "/Users/suegamisora/codes/relayer-utils",
"@zk-email/zk-regex-circom": "^2.1.0",
"circom-grumpkin": "https://github.com/zkemail/circom-grumpkin.git",
"commander": "^11.0.0",
"snarkjs": "^0.7.0"
Expand Down
67 changes: 0 additions & 67 deletions packages/circuits/scripts/account_creation.ts

This file was deleted.

64 changes: 64 additions & 0 deletions packages/circuits/scripts/psi_points.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
*
* This script is for generating input for the claim circuit.
*
*/

import { program } from "commander";
import fs from "fs";
import { promisify } from "util";
import { genPsiPointsInput } from "../helpers/psi_points";
import path from "path";
const snarkjs = require("snarkjs");

program
.requiredOption("--email-addr <string>", "User's email address")
.requiredOption("--account-code <string>", "User's account code")
.requiredOption("--relayer-rand <string>", "Relayer's randomness")
.requiredOption("--input-file <string>", "Path of a json file to write the generated input")
.option("--silent", "No console logs")
.option("--prove", "Also generate proof");

program.parse();
const args = program.opts();

function log(...message: any) {
if (!args.silent) {
console.log(...message);
}
}

async function generate() {
if (!args.inputFile.endsWith(".json")) {
throw new Error("--input file path arg must end with .json");
}

log("Generating Inputs for:", args);

const circuitInputs = await genPsiPointsInput(args.emailAddr, args.accountCode, args.relayerRand);

log("\n\nGenerated Inputs:", circuitInputs, "\n\n");

await promisify(fs.writeFile)(args.inputFile, JSON.stringify(circuitInputs, null, 2));

log("Inputs written to", args.inputFile);

if (args.prove) {
const dir = path.dirname(args.inputFile);
const { proof, publicSignals } = await snarkjs.groth16.fullProve(
circuitInputs,
path.join(dir, "psi_points.wasm"),
path.join(dir, "psi_points.zkey"),
console,
);
await promisify(fs.writeFile)(path.join(dir, "psi_points_proof.json"), JSON.stringify(proof, null, 2));
await promisify(fs.writeFile)(path.join(dir, "psi_points_public.json"), JSON.stringify(publicSignals, null, 2));
log("✓ Proof for psi_points circuit generated");
}
process.exit(0);
}

generate().catch((err) => {
console.error("Error generating inputs", err);
process.exit(1);
});
116 changes: 0 additions & 116 deletions packages/circuits/src/account_creation.circom

This file was deleted.

6 changes: 3 additions & 3 deletions packages/circuits/src/announcement.circom
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma circom 2.1.5;

include "circomlib/circuits/poseidon.circom";
include "./utils/constants.circom";
include "./utils/email_addr_commit.circom";
include "./utils/bytes2ints.circom";
include "@zk-email/ether-email-auth-circom/src/utils/constants.circom";
include "@zk-email/ether-email-auth-circom/src/utils/email_addr_commit.circom";
include "@zk-email/ether-email-auth-circom/src/utils/bytes2ints.circom";

// Prove the commitment to an email address using a randomness
// Can be used to register unclaimed funds with announcement
Expand Down
12 changes: 4 additions & 8 deletions packages/circuits/src/claim.circom
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
pragma circom 2.1.5;

include "circomlib/circuits/poseidon.circom";
include "./utils/constants.circom";
include "./utils/account_salt.circom";
// include "./utils/email_addr_pointer.circom";
include "./utils/email_addr_commit.circom";
include "./utils/bytes2ints.circom";
include "@zk-email/ether-email-auth-circom/src/utils/constants.circom";
include "@zk-email/ether-email-auth-circom/src/utils/account_salt.circom";
include "@zk-email/ether-email-auth-circom/src/utils/email_addr_commit.circom";
include "@zk-email/ether-email-auth-circom/src/utils/bytes2ints.circom";

// Verify emailAddr commitmetn and pointer has the same email address.
// Used for claiming unclaimed funds
Expand All @@ -18,9 +17,6 @@ template Claim() {
signal output email_addr_commit;
signal output account_salt;

// signal recipient_relayer_rand_hash_input[1];
// recipient_relayer_rand_hash_input[0] <== recipient_relayer_rand;
// recipient_relayer_rand_hash <== Poseidon(1)(recipient_relayer_rand_hash_input);
var num_email_addr_ints = compute_ints_size(email_max_bytes);
signal email_addr_ints[num_email_addr_ints] <== Bytes2Ints(email_max_bytes)(email_addr);
email_addr_commit <== EmailAddrCommit(num_email_addr_ints)(cm_rand, email_addr_ints);
Expand Down
Loading

0 comments on commit 698c312

Please sign in to comment.