The circuits package exports the circom circuits needed for building on ZK Email. All circuits in this package are libraries that can be imported to your circom project.
Installation
yarn add @zk-email/circuits
EmailVerifier Circuit
EmailVerifier is the primary circuit exported from @zk-email/circuits which is used for proving the signature of the input email is valid.
Usage:
Import to your circuit file like below.
include "@zk-email/circuits/email-verifier.circom";
Parameters:
maxHeadersLength: Maximum length for the email header.
maxBodyLength: Maximum length for the email body.
n: Number of bits per chunk the RSA key is split into. Recommended to be 121.
k: Number of chunks the RSA key is split into. Recommended to be 17.
ignoreBodyHashCheck: Set 1 to skip body hash check in case data to prove/extract is only in the headers.
enableHeaderMasking: Set to 1 to enable masking of the email header.
enableBodyMasking: Set to 1 to enable masking of the email body.
removeSoftLineBreaks: Set to 1 to remove soft line breaks from the email body (=\r).
Note: We use these values for n and k because their product (n * k) needs to be more than 2048 (RSA constraint) and n has to be less than half of 255 to fit in a circom signal.
Input Signals:
emailHeader[maxHeadersLength]: Email headers that are signed (ones in DKIM-Signature header) as ASCII int[], padded as per SHA-256 block size.
emailHeaderLength: Length of the email header including the SHA-256 padding.
pubkey[k]: RSA public key split into k chunks of n bits each.
signature[k]: RSA signature split into k chunks of n bits each.
emailBody[maxBodyLength]: Email body after the precomputed SHA as ASCII int[], padded as per SHA-256 block size.
emailBodyLength: Length of the email body including the SHA-256 padding.
bodyHashIndex: Index of the body hash bh in the emailHeader.
precomputedSHA[32]: Precomputed SHA-256 hash of the email body till the bodyHashIndex.
If removeSoftLineBreaks is enabled:
decodedEmailBodyIn[maxBodyLength]: The email body with soft line breaks removed, provided as input for validation.
If enableHeaderMasking is enabled:
headerMask[maxHeadersLength]: A mask array for the email header, where each element is 1 (reveal) or 0 (hide).
If enableBodyMasking is enabled:
bodyMask[maxBodyLength]: A mask array for the email body, where each element is 1 (reveal) or 0 (hide).
Output Signals:
pubkeyHash: Poseidon hash of the pubkey - Poseidon(n/2)(n/2 chunks of pubkey with k*2 bits per chunk).
If removeSoftLineBreaks is enabled:
decodedEmailBodyOut[maxBodyLength]: The decoded email body with soft line breaks removed.
If enableHeaderMasking is enabled:
maskedHeader[maxHeadersLength]: The masked email header after applying the headerMask.
If enableBodyMasking is enabled:
maskedBody[maxBodyLength]: The masked email body after applying the bodyMask.
Libraries
This section contains a template library located in the @zk-email/circuits/lib directory. These templates are important for building your main circuit (EmailVerifier).
These templates are used in the EmailVerifier circuit, and can also be used in a wide range of ZK projects, even those not directly related to ZK Email.
lib/rsa.circom
RSAVerifier65537: Verifies RSA signatures with exponent 65537.
This section provides an overview of utility circom templates available in the @zk-email/circuits/utils directory. These templates assist in the construction of zk circuits for various applications beyond the core ZK Email functionalities.
utils/array.circom
AssertZeroPadding: Asserts that the input array is zero-padded from the given `startIndex`.