Skip to content

Commit

Permalink
circuit: add email nullifier helper
Browse files Browse the repository at this point in the history
  • Loading branch information
saleel committed Mar 30, 2024
1 parent b9ce992 commit 0d29c5b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/circuits/email-verifier.circom
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ template EmailVerifier(maxHeaderLength, maxBodyLength, n, k, ignoreBodyHashCheck

// Calculate the Poseidon hash of DKIM public key as output
// This can be used to verify (by verifier/contract) the pubkey used in the proof without needing the full key
// Since PoseidonLarge concatenates nearby values its important to use same n/k (recommended 121*17) to produce uniform hashes
// https://zkrepl.dev/?gist=43ce7dce2466c63812f6efec5b13aa73 - This can be used to calculate the pubkey hash separately
pubkeyHash <== PoseidonLarge(n, k)(pubkey);
}
22 changes: 22 additions & 0 deletions packages/circuits/helpers/email-nullifier.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

pragma circom 2.1.5;

include "circomlib/circuits/poseidon.circom";


/// @title EmailNullifier
/// @notice An opinionated way of calculating the email nullifier
/// @notice nullifier = poseidon(poseidon(signature))
/// @param bitPerChunk The number of bits per chunk the signature is split into
/// @param chunkSize The number of chunks the signature is split into
/// @input signature The signature of the email
/// @output out The email nullifier
template EmailNullifier(bitPerChunk, chunkSize) {
signal input signature[chunkSize];

signal output out;

signal signatureHash <== PoseidonLarge(bitPerChunk, chunkSize)(signature);

out <== Poseidon(1)([signatureHash]);
}
4 changes: 2 additions & 2 deletions packages/circuits/utils/extract.circom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include "circomlib/circuits/bitify.circom";
include "./bytes.circom";

/// @title ExtractRegexReveal
/// @dev Extracts reveal part from a regex match
/// @notice Extracts reveal part from a regex match
/// @param maxArrayLen Maximum length of the input array
/// @param maxRevealLen Maximum length of the reveal part
/// @input in Input array
Expand Down Expand Up @@ -50,7 +50,7 @@ template ExtractRegexReveal(maxArrayLen, maxRevealLen) {


/// @title PackRegexReveal
/// @dev Packs reveal data from a regex match into int[]
/// @notice Packs reveal data from a regex match into int[]
/// @param maxArrayLen Maximum length of the input array
/// @param maxRevealLen Maximum length of the reveal part
/// @input in Input array
Expand Down

0 comments on commit 0d29c5b

Please sign in to comment.