From 504c11945b5d1ab60e7da4761483d04ecba10054 Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Thu, 14 Mar 2024 17:01:16 +0300 Subject: [PATCH 1/2] added email wallet utils circuits --- packages/circuits/utils/bytes2ints.circom | 41 +++++++++++ packages/circuits/utils/constants.circom | 25 +++++++ packages/circuits/utils/digit2int.circom | 30 ++++++++ .../circuits/utils/email_addr_commit.circom | 18 +++++ .../circuits/utils/email_nullifier.circom | 24 +++++++ packages/circuits/utils/hash_sign.circom | 38 ++++++++++ packages/circuits/utils/hex2int.circom | 69 +++++++++++++++++++ 7 files changed, 245 insertions(+) create mode 100644 packages/circuits/utils/bytes2ints.circom create mode 100644 packages/circuits/utils/constants.circom create mode 100644 packages/circuits/utils/digit2int.circom create mode 100644 packages/circuits/utils/email_addr_commit.circom create mode 100644 packages/circuits/utils/email_nullifier.circom create mode 100644 packages/circuits/utils/hash_sign.circom create mode 100644 packages/circuits/utils/hex2int.circom diff --git a/packages/circuits/utils/bytes2ints.circom b/packages/circuits/utils/bytes2ints.circom new file mode 100644 index 000000000..29e7fc5a8 --- /dev/null +++ b/packages/circuits/utils/bytes2ints.circom @@ -0,0 +1,41 @@ + +pragma circom 2.1.5; + +include "circomlib/circuits/bitify.circom"; +include "circomlib/circuits/comparators.circom"; +include "circomlib/circuits/poseidon.circom"; +include "./constants.circom"; + +function compute_ints_size(bytes_size) { + var pack_bytes = pack_bytes_const(); + var remain = bytes_size % pack_bytes; + var num_chunk = (bytes_size - remain) / pack_bytes; + if(remain>0) { + num_chunk += 1; + } + return num_chunk; +} + +template Bytes2Ints(bytes_size) { + var num_chunk = compute_ints_size(bytes_size); + signal input bytes[bytes_size]; + signal output ints[num_chunk]; + + var pack_bytes = pack_bytes_const(); + signal ints_sums[num_chunk][pack_bytes]; + for(var i=0; i=bytes_size) { + ints_sums[i][j] <== ints_sums[i][j-1]; + } else if (j==0){ + ints_sums[i][j] <== bytes[idx]; + } else { + ints_sums[i][j] <== ints_sums[i][j-1] + (1<<(8*j)) * bytes[idx]; + } + } + } + for(var i=0; i> 1; + if(k % 2 == 1) { + k2_chunked_size += 1; + } + signal output sign_ints[k2_chunked_size]; + + // signal pubkey_hash_input[k2_chunked_size]; + // for(var i = 0; i < k2_chunked_size; i++) { + // if(i==k2_chunked_size-1 && k2_chunked_size % 2 == 1) { + // pubkey_hash_input[i] <== pubkey[2*i]; + // } else { + // pubkey_hash_input[i] <== pubkey[2*i] + (1< Date: Mon, 18 Mar 2024 02:05:13 +0300 Subject: [PATCH 2/2] Added utils and changed imports --- packages/circuits/emailtest.circom | 10 +++++----- .../circuits/utils/email_addr_pointer.circom | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 packages/circuits/utils/email_addr_pointer.circom diff --git a/packages/circuits/emailtest.circom b/packages/circuits/emailtest.circom index 09c71fd50..f369daf44 100644 --- a/packages/circuits/emailtest.circom +++ b/packages/circuits/emailtest.circom @@ -6,11 +6,11 @@ include "circomlib/circuits/comparators.circom"; include "circomlib/circuits/poseidon.circom"; include "@zk-email/circuits/email-verifier.circom"; include "@zk-email/circuits/helpers/extract.circom"; -include "./utils/constants.circom"; -include "./utils/email_addr_pointer.circom"; -include "./utils/email_addr_commit.circom"; -include "./utils/hash_sign.circom"; -include "./utils/email_nullifier.circom"; +include "@zk-email/circuits/utils/constants.circom"; +include "@zk-email/circuits/utils/email_addr_pointer.circom"; +include "@zk-email/circuits/utils/email_addr_commit.circom"; +include "@zk-email/circuits/utils/hash_sign.circom"; +include "@zk-email/circuits/utils/email_nullifier.circom"; include "./utils/bytes2ints.circom"; include "./utils/digit2int.circom"; include "@zk-email/zk-regex-circom/circuits/common/from_addr_regex.circom"; diff --git a/packages/circuits/utils/email_addr_pointer.circom b/packages/circuits/utils/email_addr_pointer.circom new file mode 100644 index 000000000..ea14e7c6f --- /dev/null +++ b/packages/circuits/utils/email_addr_pointer.circom @@ -0,0 +1,18 @@ + +pragma circom 2.1.5; + +include "circomlib/circuits/poseidon.circom"; + +// email_addr_pointer = hash(relayerRand, emailAddr||0..0) +template EmailAddrPointer(num_ints) { + signal input relayer_rand; + signal input email_addr_ints[num_ints]; + signal output pointer; + + component poseidon = Poseidon(1+num_ints); + poseidon.inputs[0] <== relayer_rand; + for(var i=0; i