Skip to content

Commit

Permalink
Merge pull request #30 from zkemail/audit/cleanup-documentation
Browse files Browse the repository at this point in the history
veredise audit fix: Correct and add missing documentation in zkemail.nr
  • Loading branch information
jp4g authored Jan 13, 2025
2 parents d066c09 + a9e2c26 commit 465b6dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
14 changes: 5 additions & 9 deletions js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type BoundedVec = {
len: string;
};
/**
* Transforms a u32 array to a u8 array
* Transforms a u32 array to a u8 array in big-endian format
* @dev sha-utils in zk-email-verify encodes partial hash as u8 array but noir expects u32
* transform back to keep upstream code but not have noir worry about transformation
*
Expand Down Expand Up @@ -111,6 +111,7 @@ export function getAddressHeaderSequence(

/**
* Build a ROM table for allowable email characters
* === This function is used to generate a table to reference in Noir code ===
*/
export function makeEmailAddressCharTable(): string {
// max value: z = 122
Expand All @@ -119,7 +120,7 @@ export function makeEmailAddressCharTable(): string {
const emailChars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-@";
const precedingChars = "<: ";
const procedingChars = ">\r\n";
const proceedingChars = ">\r\n";
// set valid email chars
for (let i = 0; i < emailChars.length; i++) {
table[emailChars.charCodeAt(i)] = 1;
Expand All @@ -129,19 +130,14 @@ export function makeEmailAddressCharTable(): string {
table[precedingChars.charCodeAt(i)] = 2;
}
// set valid proceding chars
for (let i = 0; i < procedingChars.length; i++) {
table[procedingChars.charCodeAt(i)] = 3;
for (let i = 0; i < proceedingChars.length; i++) {
table[proceedingChars.charCodeAt(i)] = 3;
}
let tableStr = `global EMAIL_ADDRESS_CHAR_TABLE: [u8; ${tableLength}] = [\n`;
console.log();
for (let i = 0; i < table.length; i += 10) {
const end = i + 10 < table.length ? i + 10 : table.length;
tableStr += ` ${table.slice(i, end).join(", ")},\n`;
}
tableStr += "];";
return tableStr;
}

// export function computeStandardOutputs(email: Buffer): Promise<[bigint, bigint]> {

// }
3 changes: 2 additions & 1 deletion lib/src/headers/body_hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub fn get_body_hash<let MAX_HEADER_LENGTH: u32>(
}

/**
* Get the body hash from the header without validating the access index
* Get the body hash from the header without validating the access index. Does not validate body
* hash is valid base64 sequence (https://github.com/noir-lang/noir_base64/blob/4431d08ac661ada9d8d18b115487ff0190b43856/src/lib.nr#L209-L232)
*
* @param MAX_HEADER_LENGTH - The maximum length of the email header
* @param header - The email header as validated in the DKIM signature
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ global BODY_HASH_BASE64_LENGTH: u32 = 44;
global CR: u8 = 0x0D;
global LF: u8 = 0x0A;
global MAX_DKIM_HEADER_FIELD_LENGTH: u32 = 300; // kinda arbitrary but gives > 100 chars for selector and domain
global MAX_EMAIL_ADDRESS_LENGTH: u32 = 320;
global MAX_EMAIL_ADDRESS_LENGTH: u32 = 320; // derived via (https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.3.1.1)

pub struct Sequence {
index: u32,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/partial_hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ global BLOCK_SIZE = 64;
* @notice can be used for post-partial hashing where client proves part of hash and relies on server to finish
*
*
* @param N: the maximum length of the message to hash.
* @param N: the length of the message to hash.
* --- WARNING: N must be divisible by BLOCK_SIZE such that N % BLOCK_SIZE == 0
* otherwise the remaining bytes will not be inputted when computing the initial hash
* @param msg: the preimage to begin hashing
Expand Down

0 comments on commit 465b6dc

Please sign in to comment.