Skip to content

Commit

Permalink
Outlook worked
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Dec 24, 2024
1 parent 6d58ece commit dcf73c5
Show file tree
Hide file tree
Showing 5 changed files with 325 additions and 111 deletions.
10 changes: 9 additions & 1 deletion packages/circuits/src/email_auth_legacy_template.circom
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ template EmailAuthLegacy(n, k, max_header_bytes, max_subject_bytes, recipient_en
(timestamp_regex_out, timestamp_regex_reveal) <== TimestampRegex(max_header_bytes)(padded_header);
signal is_valid_timestamp_idx <== LessThan(log2Ceil(max_header_bytes))([timestamp_idx, max_header_bytes]);
is_valid_timestamp_idx === 1;
signal replaced_timestamp_regex_reveal[max_header_bytes];
for(var i=0; i<max_header_bytes; i++) {
if(i>=0 && i < timestamp_len) {
replaced_timestamp_regex_reveal[i] <== (timestamp_regex_reveal[i] - 1) * timestamp_regex_out + 48;
} else {
replaced_timestamp_regex_reveal[i] <== timestamp_regex_reveal[i] * timestamp_regex_out;
}
}
signal timestamp_str[timestamp_len];
timestamp_str <== SelectRegexReveal(max_header_bytes, timestamp_len)(timestamp_regex_reveal, timestamp_idx);
timestamp_str <== SelectRegexReveal(max_header_bytes, timestamp_len)(replaced_timestamp_regex_reveal, timestamp_idx);
signal raw_timestamp <== Digit2Int(timestamp_len)(timestamp_str);
timestamp <== timestamp_regex_out * raw_timestamp;

Expand Down
12 changes: 10 additions & 2 deletions packages/circuits/src/email_auth_template.circom
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,18 @@ template EmailAuth(n, k, max_header_bytes, max_body_bytes, max_command_bytes, re
// Timestamp regex + convert to decimal format
signal timestamp_regex_out, timestamp_regex_reveal[max_header_bytes];
(timestamp_regex_out, timestamp_regex_reveal) <== TimestampRegex(max_header_bytes)(padded_header);
signal timestamp_str[timestamp_len];
signal is_valid_timestamp_idx <== LessThan(log2Ceil(max_header_bytes))([timestamp_idx, max_header_bytes]);
is_valid_timestamp_idx === 1;
timestamp_str <== SelectRegexReveal(max_header_bytes, timestamp_len)(timestamp_regex_reveal, timestamp_idx);
signal replaced_timestamp_regex_reveal[max_header_bytes];
for(var i=0; i<max_header_bytes; i++) {
if(i>=0 && i < timestamp_len) {
replaced_timestamp_regex_reveal[i] <== (timestamp_regex_reveal[i] - 1) * timestamp_regex_out + 48;
} else {
replaced_timestamp_regex_reveal[i] <== timestamp_regex_reveal[i] * timestamp_regex_out;
}
}
signal timestamp_str[timestamp_len];
timestamp_str <== SelectRegexReveal(max_header_bytes, timestamp_len)(replaced_timestamp_regex_reveal, timestamp_idx);
signal raw_timestamp <== Digit2Int(timestamp_len)(timestamp_str);
timestamp <== timestamp_regex_out * raw_timestamp;

Expand Down
130 changes: 65 additions & 65 deletions packages/circuits/tests/email_auth_production.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,80 +381,80 @@ describe("Email Auth Production", () => {
});

/// The outlook email fails at EmailAuth_723 line: 118. The circuit needs to put a dummy 1 in similar to `replaced_code_regex_reveal`.
// it("Verify a production email for recovery sent from outlook pc", async () => {
// const emailFilePath = path.join(
// __dirname,
// "./emails/recovery_outlook_pc.eml"
// );
it("Verify a production email for recovery sent from outlook pc", async () => {
const emailFilePath = path.join(
__dirname,
"./emails/recovery_outlook_pc.eml"
);

// const emailRaw = readFileSync(emailFilePath, "utf8");
// const parsedEmail = await relayerUtils.parseEmail(emailRaw);
// console.log(parsedEmail);
// const accountCode =
// "0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76";
const emailRaw = readFileSync(emailFilePath, "utf8");
const parsedEmail = await relayerUtils.parseEmail(emailRaw);
console.log(parsedEmail);
const accountCode =
"0x01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76";

// const circuitInputs =
// await genEmailCircuitInput(emailFilePath, accountCode, {
// maxHeaderLength: 1024,
// maxBodyLength: 1024,
// ignoreBodyHashCheck: false,
// shaPrecomputeSelector,
// });
// console.log(circuitInputs);
// const witness = await circuit.calculateWitness(circuitInputs);
// await circuit.checkConstraints(witness);
// console.log("checkConstraints done");
const circuitInputs =
await genEmailCircuitInput(emailFilePath, accountCode, {
maxHeaderLength: 1024,
maxBodyLength: 1024,
ignoreBodyHashCheck: false,
shaPrecomputeSelector,
});
console.log(circuitInputs);
const witness = await circuit.calculateWitness(circuitInputs);
await circuit.checkConstraints(witness);
console.log("checkConstraints done");

// const domainName = "outlook.com";
// const paddedDomain = relayerUtils.padString(domainName, 255);
// const domainFields = await relayerUtils.bytesToFields(paddedDomain);
// for (let idx = 0; idx < domainFields.length; ++idx) {
// expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
// }
// console.log("domainFields done");
const domainName = "outlook.com";
const paddedDomain = relayerUtils.padString(domainName, 255);
const domainFields = await relayerUtils.bytesToFields(paddedDomain);
for (let idx = 0; idx < domainFields.length; ++idx) {
expect(BigInt(domainFields[idx])).toEqual(witness[1 + idx]);
}
console.log("domainFields done");

// const expectedPubKeyHash = await relayerUtils.publicKeyHash(
// parsedEmail.publicKey
// );
// expect(BigInt(expectedPubKeyHash)).toEqual(
// witness[1 + domainFields.length]
// );
// console.log("expectedPubKeyHash done");
const expectedPubKeyHash = await relayerUtils.publicKeyHash(
parsedEmail.publicKey
);
expect(BigInt(expectedPubKeyHash)).toEqual(
witness[1 + domainFields.length]
);
console.log("expectedPubKeyHash done");

// const expectedEmailNullifier = await relayerUtils.emailNullifier(
// parsedEmail.signature
// );
// expect(BigInt(expectedEmailNullifier)).toEqual(
// witness[1 + domainFields.length + 1]
// );
// console.log("expectedEmailNullifier done");
const expectedEmailNullifier = await relayerUtils.emailNullifier(
parsedEmail.signature
);
expect(BigInt(expectedEmailNullifier)).toEqual(
witness[1 + domainFields.length + 1]
);
console.log("expectedEmailNullifier done");

// const timestamp = BigInt(0);
// expect(timestamp).toEqual(witness[1 + domainFields.length + 2]);
// console.log("timestamp done");
const timestamp = BigInt(0);
expect(timestamp).toEqual(witness[1 + domainFields.length + 2]);
console.log("timestamp done");

// const maskedCommand = "Accept guardian request for 0x04884491560f38342C56E26BDD0fEAbb68E2d2FC";
// const paddedMaskedCommand = relayerUtils.padString(maskedCommand, 605);
// const maskedCommandFields =
// await relayerUtils.bytesToFields(paddedMaskedCommand);
// for (let idx = 0; idx < maskedCommandFields.length; ++idx) {
// expect(BigInt(maskedCommandFields[idx])).toEqual(
// witness[1 + domainFields.length + 3 + idx]
// );
// }
const maskedCommand = "Accept guardian request for 0x04884491560f38342C56E26BDD0fEAbb68E2d2FC";
const paddedMaskedCommand = relayerUtils.padString(maskedCommand, 605);
const maskedCommandFields =
await relayerUtils.bytesToFields(paddedMaskedCommand);
for (let idx = 0; idx < maskedCommandFields.length; ++idx) {
expect(BigInt(maskedCommandFields[idx])).toEqual(
witness[1 + domainFields.length + 3 + idx]
);
}

// const fromAddr = "suegamisora@outlook.com";
// const accountSalt = await relayerUtils.generateAccountSalt(fromAddr, accountCode);
// expect(BigInt(accountSalt)).toEqual(
// witness[1 + domainFields.length + 3 + maskedCommandFields.length]
// );
const fromAddr = "suegamisora@outlook.com";
const accountSalt = await relayerUtils.generateAccountSalt(fromAddr, accountCode);
expect(BigInt(accountSalt)).toEqual(
witness[1 + domainFields.length + 3 + maskedCommandFields.length]
);

// expect(BigInt(1)).toEqual(
// witness[
// 1 + domainFields.length + 3 + maskedCommandFields.length + 1
// ]
// );
// });
expect(BigInt(1)).toEqual(
witness[
1 + domainFields.length + 3 + maskedCommandFields.length + 1
]
);
});


});
Expand Down
Loading

0 comments on commit dcf73c5

Please sign in to comment.