-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
email address extraction circuit + inputs setup but not passing
- Loading branch information
Showing
20 changed files
with
351 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ target | |
dist | ||
.tsbuildinfo | ||
zk-email-verify | ||
|
||
!*/email-*.eml |
4 changes: 2 additions & 2 deletions
4
examples/recipient_search/Nargo.toml → examples/email_mask/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[package] | ||
name = "recipient_search" | ||
name = "email_mask" | ||
type = "bin" | ||
authors = ["Mach 34"] | ||
compiler_version = ">=0.34.0" | ||
compiler_version = ">=0.35.0" | ||
|
||
[dependencies] | ||
zkemail = { path = "../../lib"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use dep::zkemail::{ | ||
KEY_LIMBS_2048, dkim::RSAPubkey, headers::body_hash::get_body_hash, | ||
standard_outputs, Sequence, masking::mask_text | ||
}; | ||
use dep::std::{collections::bounded_vec::BoundedVec, hash::sha256_var}; | ||
|
||
global MAX_EMAIL_HEADER_LENGTH: u32 = 512; | ||
global MAX_EMAIL_BODY_LENGTH: u32 = 1024; | ||
|
||
/** | ||
* Verify an arbitrary email signed by a 2048-bit RSA DKIM signature and mask outputs | ||
* | ||
* @param header - The email header, 0-padded at end to the MAX_EMAIL_HEADER_LENGTH | ||
* @param body - The email body, 0-padded at end to the MAX_EMAIL_BODY_LENGTH | ||
* @param pubkey - The DKIM RSA Public Key modulus and reduction parameter | ||
* @param signature - The DKIM RSA Signature | ||
* @param body_hash_index - The index of the body hash in the partial hash array | ||
* @param dkim_header_sequence - The index and length of the DKIM header field | ||
* @param header_mask - The mask for the header | ||
* @param body_mask - The mask for the body | ||
* @return - | ||
* 0: Pedersen hash of DKIM public key (root of trust) | ||
* 1: Pedersen hash of DKIM signature (email nullifier) | ||
*/ | ||
fn main( | ||
header: BoundedVec<u8, MAX_EMAIL_HEADER_LENGTH>, | ||
body: BoundedVec<u8, MAX_EMAIL_BODY_LENGTH>, | ||
pubkey: RSAPubkey<KEY_LIMBS_2048>, | ||
signature: [Field; KEY_LIMBS_2048], | ||
body_hash_index: u32, | ||
dkim_header_sequence: Sequence, | ||
header_mask: [bool; MAX_EMAIL_HEADER_LENGTH], | ||
body_mask: [bool; MAX_EMAIL_BODY_LENGTH] | ||
) -> pub ([Field; 2], [u8; MAX_EMAIL_HEADER_LENGTH], [u8; MAX_EMAIL_BODY_LENGTH]) { | ||
// check the body and header lengths are within bounds | ||
assert(header.len() <= MAX_EMAIL_HEADER_LENGTH); | ||
assert(body.len() <= MAX_EMAIL_BODY_LENGTH); | ||
|
||
// verify the dkim signature over the header | ||
pubkey.verify_dkim_signature(header, signature); | ||
|
||
// extract the body hash from the header | ||
let signed_body_hash = get_body_hash(header, dkim_header_sequence, body_hash_index); | ||
|
||
// hash the asserted body | ||
let computed_body_hash: [u8; 32] = sha256_var(body.storage, body.len() as u64); | ||
|
||
// compare the body hashes | ||
assert( | ||
signed_body_hash == computed_body_hash, "SHA256 hash computed over body does not match body hash found in DKIM-signed header" | ||
); | ||
|
||
// mask the header and body | ||
let masked_header = mask_text(header, header_mask); | ||
let masked_body = mask_text(body, body_mask); | ||
|
||
// hash the pubkey and signature for the standard outputs | ||
let standard_out = standard_outputs(pubkey.modulus, signature); | ||
(standard_out, masked_header, masked_body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "extract_addresses" | ||
type = "bin" | ||
authors = ["Mach 34"] | ||
compiler_version = ">=0.35.0" | ||
|
||
[dependencies] | ||
zkemail = { path = "../../lib"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use dep::zkemail::{ | ||
KEY_LIMBS_2048, dkim::RSAPubkey, | ||
headers::{body_hash::get_body_hash, email_address::get_email_address}, standard_outputs, Sequence, | ||
MAX_EMAIL_ADDRESS_LENGTH | ||
}; | ||
use dep::std::{collections::bounded_vec::BoundedVec, hash::sha256_var}; | ||
|
||
global MAX_EMAIL_HEADER_LENGTH: u32 = 512; | ||
global MAX_EMAIL_BODY_LENGTH: u32 = 1024; | ||
|
||
/** | ||
* Verify an arbitrary email signed by a 2048-bit RSA DKIM signature and extract sender and recipient addresses | ||
* @dev example of only constraining access to the header too | ||
* | ||
* @param header - The email header, 0-padded at end to the MAX_EMAIL_HEADER_LENGTH | ||
* @param pubkey - The DKIM RSA Public Key modulus and reduction parameter | ||
* @param signature - The DKIM RSA Signature | ||
* @param from_header_sequence - The index and length of the "From" header field | ||
* @param from_address_sequence - The index and length of the "From" email address | ||
* @param to_header_sequence - The index and length of the "To" header field | ||
* @param to_address_sequence - The index and length of the "To" email address | ||
* @return - | ||
* 0: Pedersen hash of DKIM public key (root of trust) | ||
* 1: Pedersen hash of DKIM signature (email nullifier) | ||
*/ | ||
fn main( | ||
header: BoundedVec<u8, MAX_EMAIL_HEADER_LENGTH>, | ||
pubkey: RSAPubkey<KEY_LIMBS_2048>, | ||
signature: [Field; KEY_LIMBS_2048], | ||
from_header_sequence: Sequence, | ||
from_address_sequence: Sequence, | ||
to_header_sequence: Sequence, | ||
to_address_sequence: Sequence | ||
) -> pub ([Field; 2], BoundedVec<u8, MAX_EMAIL_ADDRESS_LENGTH>, BoundedVec<u8, MAX_EMAIL_ADDRESS_LENGTH>) { | ||
// check the body and header lengths are within bounds | ||
assert(header.len() <= MAX_EMAIL_HEADER_LENGTH); | ||
|
||
// verify the dkim signature over the header | ||
pubkey.verify_dkim_signature(header, signature); | ||
|
||
// extract to and from email addresses | ||
let from = comptime { | ||
"from".as_bytes() | ||
}; | ||
let to = comptime { | ||
"to".as_bytes() | ||
}; | ||
// 16k gate cost? has to be able to be brought down | ||
let from_address = get_email_address(header, from_header_sequence, from_address_sequence, from); | ||
let to_address = get_email_address(header, to_header_sequence, to_address_sequence, to); | ||
|
||
// hash the pubkey and signature for the standard outputs | ||
let standard_out = standard_outputs(pubkey.modulus, signature); | ||
(standard_out, from_address, to_address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.