Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/relayer refactor #4

Merged
merged 49 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b9a6d5f
Add ECDSAOwnedDKIMRegistry.
wshino Mar 13, 2024
355c9a2
Update dev-setup.ts that generates Groth16Verifier.sol.
wshino Mar 13, 2024
814ac9c
Implement verifyEmailProof function.
wshino Mar 13, 2024
e5a9ca6
[WIP] Add implementations regarding authEmail function till step 7.
wshino Mar 15, 2024
86a1cdc
Add isValidSignature function.
wshino Mar 15, 2024
c835942
Add EmailAccountRecovery.
wshino Mar 15, 2024
cd9da35
Move usedNullifiers from Verifier to EmailAuth.
wshino Mar 17, 2024
d638c22
Tweak variable name.
wshino Mar 17, 2024
31260e2
Update correct timestamp validation condition.
wshino Mar 17, 2024
577a2a1
Update isValidSignature function.
wshino Mar 17, 2024
a21a33e
Add unit test functions.
wshino Mar 17, 2024
c84c559
Add testAuthEmail.
wshino Mar 17, 2024
e55ce44
Remove comment.
wshino Mar 18, 2024
afd29df
Delete unused mock directory.
wshino Mar 18, 2024
37b973e
Add testIsValidSignature.
wshino Mar 19, 2024
58804ab
Format solidity files.
wshino Mar 19, 2024
594e51d
Add deploy script.
wshino Mar 19, 2024
4c1f7ef
Merge branch 'feat/contracts' of https://github.com/zkemail/ether-ema…
SoraSuegami Mar 19, 2024
3435495
Modify ECSDSAOwnedDKIMRegistry to be independent of the chain id.
SoraSuegami Mar 19, 2024
f0f0d4c
Refactor EmailAuth contracts.
SoraSuegami Mar 19, 2024
1ec9ca7
Refactor EmailAccountRecovery.
SoraSuegami Mar 19, 2024
aa48c7d
Add simple wallet to be recovered with emails.
SoraSuegami Mar 19, 2024
d5cc39f
Fix EmailAuth.t.sol.
wshino Mar 20, 2024
f4df9d9
Add DeploymentHelper.
wshino Mar 20, 2024
1883702
Add create SimpleWallet instance in setUp function.
wshino Mar 20, 2024
7ef1163
Add test EmailAccountRecovery.
wshino Mar 20, 2024
73b1de7
Fix EmailAccountRecovery.t.sol.
wshino Mar 20, 2024
61ff826
Merge branch 'feat/contracts-refactor' into feat/contracts
wshino Mar 21, 2024
5d406c4
Fix parameter decoding in recoverWallet method.
wshino Mar 21, 2024
d66dcde
Rename recoverWallet to processRecovery and add completeRecovery.
SoraSuegami Mar 21, 2024
6e7d0d8
Add recipient's email address commitment to the circuit.
SoraSuegami Mar 23, 2024
32b4e98
Add script to generate circuit inputs.
SoraSuegami Mar 23, 2024
59d90b2
Add prover.
SoraSuegami Mar 23, 2024
091c358
Add relayer.
SoraSuegami Mar 23, 2024
7ba7f56
Update utils and relayer.
SoraSuegami Mar 24, 2024
9315f3c
Fix database.
SoraSuegami Mar 24, 2024
c53d555
Remove unused code.
SoraSuegami Mar 24, 2024
a104a23
Update database and web_server
SoraSuegami Mar 25, 2024
7560780
Fix config.rs
SoraSuegami Mar 25, 2024
1a78ae4
Merge branch 'feat/relayer' of https://github.com/zkemail/ether-email…
SoraSuegami Apr 1, 2024
87c5467
Fix modal server name.
SoraSuegami Apr 1, 2024
dfa96fe
Merge branch 'feat/relayer' of https://github.com/zkemail/ether-email…
SoraSuegami Apr 1, 2024
b079343
Fix typo of EmailAccountRecoery.t.sol.
wshino Apr 1, 2024
a643650
Fix Dockerfile in prover.
SoraSuegami Apr 2, 2024
16397aa
Merge branch 'feat/relayer' of https://github.com/zkemail/ether-email…
SoraSuegami Apr 2, 2024
22afe78
Merge branch 'main' of https://github.com/zkemail/ether-email-auth in…
SoraSuegami Apr 2, 2024
7bb132a
Merge branch 'feat/relayer' of https://github.com/zkemail/ether-email…
SoraSuegami Apr 2, 2024
94e6a67
Update utils package.
SoraSuegami Apr 3, 2024
dce9d19
feat: fixes
Bisht13 Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 111 additions & 33 deletions Cargo.lock

Large diffs are not rendered by default.

40 changes: 4 additions & 36 deletions packages/circuits/helpers/email_auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import { promisify } from "util";
import { generateCircuitInputs } from "@zk-email/helpers/dist/input-helpers";
const emailWalletUtils = require("../../utils");
// import { generateCircuitInputs } from "@zk-email/helpers/dist/input-helpers";
const relayerUtils = require("../../utils");


export async function genEmailAuthInput(emailFilePath: string, accountCode: string):
Expand All @@ -18,38 +18,6 @@ export async function genEmailAuthInput(emailFilePath: string, accountCode: stri
code_idx: number
}> {
const emailRaw = await promisify(fs.readFile)(emailFilePath, "utf8");
const parsedEmail = await emailWalletUtils.parseEmail(emailRaw);
const emailCircuitInputs = generateCircuitInputs({
body: Buffer.from(""),
message: Buffer.from(parsedEmail.canonicalizedHeader),
bodyHash: "",
rsaSignature: BigInt(parsedEmail.signature),
rsaPublicKey: BigInt(parsedEmail.publicKey),
maxMessageLength: 1024,
maxBodyLength: 64,
ignoreBodyHashCheck: true
});
const from_addr_idxes = emailWalletUtils.extractFromAddrIdxes(parsedEmail.canonicalizedHeader)[0];
const fromEmailAddrPart = parsedEmail.canonicalizedHeader.slice(from_addr_idxes[0], from_addr_idxes[1]);
const subject_idx = emailWalletUtils.extractSubjectAllIdxes(parsedEmail.canonicalizedHeader)[0][0];
const domainIdx = emailWalletUtils.extractEmailDomainIdxes(fromEmailAddrPart)[0][0];
const timestampIdx = emailWalletUtils.extractTimestampIdxes(parsedEmail.canonicalizedHeader)[0][0];
let codeIdx = 0;
try {
codeIdx = emailWalletUtils.extractInvitationCodeIdxes(parsedEmail.canonicalizedHeader)[0][0];
} catch (e) {
console.log("No invitation code in header");
}
return {
padded_header: emailCircuitInputs.in_padded,
public_key: emailCircuitInputs.pubkey,
signature: emailCircuitInputs.signature,
padded_header_len: emailCircuitInputs.in_len_padded_bytes,
account_code: accountCode,
from_addr_idx: from_addr_idxes[0],
subject_idx: subject_idx,
domain_idx: domainIdx,
timestamp_idx: timestampIdx,
code_idx: codeIdx,
};
const jsonStr = await relayerUtils.genEmailAuthInput(emailRaw, accountCode);
return JSON.parse(jsonStr);
}
10 changes: 5 additions & 5 deletions packages/circuits/helpers/recipient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import { promisify } from "util";
import { generateCircuitInputs } from "@zk-email/helpers/dist/input-helpers";
const emailWalletUtils = require("../../utils");
const relayerUtils = require("../../utils");


export async function genRecipientInput(emailFilePath: string):
Expand All @@ -10,17 +10,17 @@ export async function genRecipientInput(emailFilePath: string):
rand: string
}> {
const emailRaw = await promisify(fs.readFile)(emailFilePath, "utf8");
const parsedEmail = await emailWalletUtils.parseEmail(emailRaw);
const subjectEmailIdxes = emailWalletUtils.extractSubjectAllIdxes(parsedEmail.canonicalizedHeader)[0];
const parsedEmail = await relayerUtils.parseEmail(emailRaw);
const subjectEmailIdxes = relayerUtils.extractSubjectAllIdxes(parsedEmail.canonicalizedHeader)[0];
const subject = parsedEmail.canonicalizedHeader.slice(subjectEmailIdxes[0], subjectEmailIdxes[1]);
let subjectEmailAddrIdx = 0;
try {
subjectEmailAddrIdx = emailWalletUtils.extractEmailAddrIdxes(subject)[0][0];
subjectEmailAddrIdx = relayerUtils.extractEmailAddrIdxes(subject)[0][0];
} catch (e) {
console.log("No email address in subject");
subjectEmailAddrIdx = 0;
}
const rand = emailWalletUtils.extractRandFromSignature(parsedEmail.signature);
const rand = relayerUtils.extractRandFromSignature(parsedEmail.signature);
return {
subject_email_addr_idx: subjectEmailAddrIdx,
rand: rand
Expand Down
107 changes: 54 additions & 53 deletions packages/circuits/tests/email_auth.test.ts

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions packages/circuits/tests/invitation_code_regex.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const circom_tester = require("circom_tester");
const wasm_tester = circom_tester.wasm;
import * as path from "path";
const emailWalletUtils = require("../../utils");
const relayerUtils = require("../../utils");
const option = {
include: path.join(__dirname, "../../../node_modules")
};
Expand All @@ -14,7 +14,7 @@ describe("Invitation Code Regex", () => {
const codeStr = "Code 123abc";
// const prefixLen = "ACCOUNTKEY.0x".length;
// const revealed = "123abc";
const paddedStr = emailWalletUtils.padString(codeStr, 256);
const paddedStr = relayerUtils.padString(codeStr, 256);
const circuitInputs = {
msg: paddedStr,
};
Expand All @@ -23,7 +23,7 @@ describe("Invitation Code Regex", () => {
await circuit.checkConstraints(witness);
// console.log(witness);
expect(1n).toEqual(witness[1]);
const prefixIdxes = emailWalletUtils.extractInvitationCodeIdxes(codeStr)[0];
const prefixIdxes = relayerUtils.extractInvitationCodeIdxes(codeStr)[0];
for (let idx = 0; idx < 256; ++idx) {
if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) {
expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]);
Expand All @@ -37,7 +37,7 @@ describe("Invitation Code Regex", () => {
const codeStr = "Swap 0.1 ETH to DAI code 123abc";
// const prefixLen = "sepolia+ACCOUNTKEY.0x".length;
// const revealed = "123abc";
const paddedStr = emailWalletUtils.padString(codeStr, 256);
const paddedStr = relayerUtils.padString(codeStr, 256);
const circuitInputs = {
msg: paddedStr,
};
Expand All @@ -46,7 +46,7 @@ describe("Invitation Code Regex", () => {
await circuit.checkConstraints(witness);
// console.log(witness);
expect(1n).toEqual(witness[1]);
const prefixIdxes = emailWalletUtils.extractInvitationCodeIdxes(codeStr)[0];
const prefixIdxes = relayerUtils.extractInvitationCodeIdxes(codeStr)[0];
// const revealedStartIdx = emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8"))[0][0];
// console.log(emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8")));
for (let idx = 0; idx < 256; ++idx) {
Expand All @@ -62,7 +62,7 @@ describe("Invitation Code Regex", () => {
const codeStr = "Send 0.1 ETH to [email protected] code 123abc";
// const prefixLen = "sepolia+ACCOUNTKEY.0x".length;
// const revealed = "123abc";
const paddedStr = emailWalletUtils.padString(codeStr, 256);
const paddedStr = relayerUtils.padString(codeStr, 256);
const circuitInputs = {
msg: paddedStr,
};
Expand All @@ -71,7 +71,7 @@ describe("Invitation Code Regex", () => {
await circuit.checkConstraints(witness);
// console.log(witness);
expect(1n).toEqual(witness[1]);
const prefixIdxes = emailWalletUtils.extractInvitationCodeIdxes(codeStr)[0];
const prefixIdxes = relayerUtils.extractInvitationCodeIdxes(codeStr)[0];
// const revealedStartIdx = emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8"))[0][0];
// console.log(emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8")));
for (let idx = 0; idx < 256; ++idx) {
Expand All @@ -87,7 +87,7 @@ describe("Invitation Code Regex", () => {
const codeStr = "[email protected]";
// const prefixLen = "sepolia+ACCOUNTKEY.0x".length;
// const revealed = "123abc";
const paddedStr = emailWalletUtils.padString(codeStr, 256);
const paddedStr = relayerUtils.padString(codeStr, 256);
const circuitInputs = {
msg: paddedStr,
};
Expand All @@ -96,7 +96,7 @@ describe("Invitation Code Regex", () => {
await circuit.checkConstraints(witness);
// console.log(witness);
expect(1n).toEqual(witness[1]);
const prefixIdxes = emailWalletUtils.extractInvitationCodeIdxes(codeStr)[0];
const prefixIdxes = relayerUtils.extractInvitationCodeIdxes(codeStr)[0];
// const revealedStartIdx = emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8"))[0][0];
// console.log(emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8")));
for (let idx = 0; idx < 256; ++idx) {
Expand All @@ -112,7 +112,7 @@ describe("Invitation Code Regex", () => {
const codeStr = "Swap 0.1 ETH to DAI code 123abc";
// const prefixLen = "sepolia+ACCOUNTKEY.0x".length;
// const revealed = "123abc";
const paddedStr = emailWalletUtils.padString(codeStr, 256);
const paddedStr = relayerUtils.padString(codeStr, 256);
const circuitInputs = {
msg: paddedStr,
};
Expand All @@ -121,7 +121,7 @@ describe("Invitation Code Regex", () => {
await circuit.checkConstraints(witness);
// console.log(witness);
expect(1n).toEqual(witness[1]);
const prefixIdxes = emailWalletUtils.extractInvitationCodeWithPrefixIdxes(codeStr)[0];
const prefixIdxes = relayerUtils.extractInvitationCodeWithPrefixIdxes(codeStr)[0];
// const revealedStartIdx = emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8"))[0][0];
// console.log(emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8")));
for (let idx = 0; idx < 256; ++idx) {
Expand All @@ -137,7 +137,7 @@ describe("Invitation Code Regex", () => {
const codeStr = "Re: Accept guardian request for 0x04884491560f38342C56E26BDD0fEAbb68E2d2FC Code 01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76";
// const prefixLen = "sepolia+ACCOUNTKEY.0x".length;
// const revealed = "123abc";
const paddedStr = emailWalletUtils.padString(codeStr, 256);
const paddedStr = relayerUtils.padString(codeStr, 256);
const circuitInputs = {
msg: paddedStr,
};
Expand All @@ -146,7 +146,7 @@ describe("Invitation Code Regex", () => {
await circuit.checkConstraints(witness);
// console.log(witness);
expect(1n).toEqual(witness[1]);
const prefixIdxes = emailWalletUtils.extractInvitationCodeWithPrefixIdxes(codeStr)[0];
const prefixIdxes = relayerUtils.extractInvitationCodeWithPrefixIdxes(codeStr)[0];
// const revealedStartIdx = emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8"))[0][0];
// console.log(emailWalletUtils.extractSubstrIdxes(codeStr, readFileSync(path.join(__dirname, "../src/regexes/invitation_code.json"), "utf8")));
for (let idx = 0; idx < 256; ++idx) {
Expand Down
Loading
Loading