Skip to content

Commit

Permalink
Merge pull request #272 from openpassport-org/feat/remove-dummy-inputs
Browse files Browse the repository at this point in the history
Feat/remove dummy inputs
  • Loading branch information
remicolin authored Dec 18, 2024
2 parents c417fee + 7ae00cb commit e4dd6e7
Show file tree
Hide file tree
Showing 56 changed files with 145 additions and 533 deletions.
1 change: 0 additions & 1 deletion circuits/circuits/disclose/vc_and_disclose.circom
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ template VC_AND_DISCLOSE( nLevels,FORBIDDEN_COUNTRIES_LIST_LENGTH) {
component poseidon_nullifier = PoseidonHash(2);
poseidon_nullifier.in[0] <== secret;
poseidon_nullifier.in[1] <== scope;
poseidon_nullifier.dummy <== 0;
signal output nullifier <== poseidon_nullifier.out;
signal output revealedData_packed[3] <== disclose.revealedData_packed;
signal output older_than[2] <== disclose.older_than;
Expand Down
5 changes: 2 additions & 3 deletions circuits/circuits/dsc/openpassport_dsc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ template OPENPASSPORT_DSC(signatureAlgorithm, n_dsc, k_dsc, n_csca, k_csca, max_
signal input path[nLevels];
signal input siblings[nLevels];

signal dummy <== 0;

// leaf
signal leaf <== LeafHasher(kScaled)(csca_pubKey, signatureAlgorithm);
Expand All @@ -45,7 +44,7 @@ template OPENPASSPORT_DSC(signatureAlgorithm, n_dsc, k_dsc, n_csca, k_csca, max_
// verify certificate signature
signal hashedCertificate[hashLength] <== ShaBytesDynamic(hashLength, max_cert_bytes)(raw_dsc_cert, raw_dsc_cert_padded_bytes);

SignatureVerifier(signatureAlgorithm, n_csca, k_csca)(hashedCertificate, csca_pubKey, signature, dummy);
SignatureVerifier(signatureAlgorithm, n_csca, k_csca)(hashedCertificate, csca_pubKey, signature);

// verify DSC csca_pubKey
component shiftLeft = VarShiftLeft(max_cert_bytes, dscPubkeyBytesLength); // use select subarray for dscPubKey variable length
Expand All @@ -59,6 +58,6 @@ template OPENPASSPORT_DSC(signatureAlgorithm, n_dsc, k_dsc, n_csca, k_csca, max_

// blinded dsc commitment
signal pubkeyHash <== CustomHasher(k_dsc)(dsc_pubKey);
signal output blinded_dsc_commitment <== PoseidonHash(2)([secret, pubkeyHash], 0);
signal output blinded_dsc_commitment <== PoseidonHash(2)([secret, pubkeyHash]);
}

6 changes: 2 additions & 4 deletions circuits/circuits/prove/openpassport_prove.circom
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
signal input secret;
signal input dsc_secret;

signal dummy <== 0;

signal attestation_id <== 1;

Expand All @@ -59,7 +58,7 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
isWrongSelectorMode === 0;

// verify passport signature
PassportVerifier(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, MAX_SIGNED_ATTR_PADDED_LEN)(dg1,dg1_hash_offset, dg2_hash, eContent,eContent_padded_length, signed_attr, signed_attr_padded_length, signed_attr_econtent_hash_offset, pubKey, signature, dummy);
PassportVerifier(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, MAX_SIGNED_ATTR_PADDED_LEN)(dg1,dg1_hash_offset, dg2_hash, eContent,eContent_padded_length, signed_attr, signed_attr_padded_length, signed_attr_econtent_hash_offset, pubKey, signature);
// verify passport is not expired
component isValid = IsValid();
isValid.currDate <== current_date;
Expand All @@ -72,7 +71,6 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
component poseidon_hasher = PoseidonHash(2);
poseidon_hasher.in[0] <== signatureHashed;
poseidon_hasher.in[1] <== scope;
poseidon_hasher.dummy <== 0;
signal output nullifier <== poseidon_hasher.out;

// DISCLOSE (optional)
Expand Down Expand Up @@ -116,6 +114,6 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
signal output commitment <== commitmentPrivate * selectorModeCommitment;
// // blinded dsc commitment
signal pubkeyHash <== CustomHasher(kScaled)(pubKey);
signal blindedDscCommitmenPrivate <== PoseidonHash(2)([dsc_secret, pubkeyHash],0);
signal blindedDscCommitmenPrivate <== PoseidonHash(2)([dsc_secret, pubkeyHash]);
signal output blinded_dsc_commitment <== blindedDscCommitmenPrivate * selectorModeBlindedDscCommitment;
}
72 changes: 72 additions & 0 deletions circuits/circuits/removeDummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import re

def process_line(line):
# Handle "+ dummy * dummy" pattern at the end (only lowercase, standalone 'dummy')
line = re.sub(r'\s*\+\s*\bdummy\b\s*\*\s*\bdummy\b', '', line)

# Handle "dummy * dummy +" pattern at the start of expression (only lowercase, standalone 'dummy')
line = re.sub(r'<==\s*\bdummy\b\s*\*\s*\bdummy\b\s*\+\s*', '<== ', line)

# If line starts with uppercase or contains 'template'
if line[0].isupper() or 'template' in line.lower():
# Remove ', dummy' or 'dummy,' pattern (only lowercase, standalone 'dummy')
line = re.sub(r',\s*\bdummy\b(?![A-Za-z])', '', line)
line = re.sub(r'\bdummy\b(?![A-Za-z]),', '', line)
# Remove standalone 'dummy' (only lowercase)
line = re.sub(r'\bdummy\b(?![A-Za-z])', '', line)
return line
# Handle function calls with dummy parameter
elif '(' in line and ')' in line:
# Remove ', dummy' before closing parenthesis (only lowercase, standalone 'dummy')
line = re.sub(r',\s*\bdummy\b(?![A-Za-z])\s*\)', ')', line)
return line
# For other lines, if they contain standalone 'dummy' (lowercase only), return None to remove the entire line
elif re.search(r'\bdummy\b(?![A-Za-z])', line):
return None
return line

def remove_dummy_lines(directory):
# Walk through all directories and files
for root, dirs, files in os.walk(directory):
# Filter for .circom files
for file in files:
if file.endswith('.circom'):
file_path = os.path.join(root, file)
print(f"Processing: {file_path}")

# Read file content
with open(file_path, 'r') as f:
lines = f.readlines()

# Process lines
new_lines = []
lines_removed = 0
for line in lines:
processed_line = process_line(line)
if processed_line is not None:
new_lines.append(processed_line)
else:
lines_removed += 1

# If we found and modified/removed any lines
if len(lines) != len(new_lines):
print(f"Modified/Removed {lines_removed} lines containing 'dummy' in {file_path}")

# Write back the filtered content
with open(file_path, 'w') as f:
f.writelines(new_lines)

if __name__ == "__main__":
# Get the current directory where the script is running
current_dir = os.getcwd()

# Ask for confirmation
print(f"This will process 'dummy' occurrences in .circom files in {current_dir} and its subdirectories.")
confirm = input("Do you want to continue? (y/n): ")

if confirm.lower() == 'y':
remove_dummy_lines(current_dir)
print("Process completed!")
else:
print("Operation cancelled.")
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ template VerifyRsaPkcs1v1_5Tester() {
signal input modulus[32];
signal input message[32];

signal input dummy;

VerifyRsaPkcs1v1_5(3, 64, 32, 65537, 160)(signature, modulus, message, dummy);
VerifyRsaPkcs1v1_5(3, 64, 32, 65537, 160)(signature, modulus, message);
}

component main = VerifyRsaPkcs1v1_5Tester();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ template VerifyRsaPkcs1v1_5Tester() {
signal input modulus[32];
signal input message[32];

signal input dummy;

VerifyRsaPkcs1v1_5(13, 64, 32, 3, 256)(signature, modulus, message, dummy);
VerifyRsaPkcs1v1_5(13, 64, 32, 3, 256)(signature, modulus, message);
}

component main = VerifyRsaPkcs1v1_5Tester();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ template VerifyRsaPkcs1v1_5Tester() {
signal input modulus[32];
signal input message[32];

signal input dummy;

VerifyRsaPkcs1v1_5(1, 64, 32, 65537, 256)(signature, modulus, message, dummy);
VerifyRsaPkcs1v1_5(1, 64, 32, 65537, 256)(signature, modulus, message);
}

component main = VerifyRsaPkcs1v1_5Tester();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ template VerifyRsaPkcs1v1_5Tester() {
signal input modulus[32];
signal input message[32];

signal input dummy;

VerifyRsaPkcs1v1_5(14, 96, 32, 65537, 256)(signature, modulus, message, dummy);
VerifyRsaPkcs1v1_5(14, 96, 32, 65537, 256)(signature, modulus, message);
}

component main = VerifyRsaPkcs1v1_5Tester();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ template VerifyRsaPkcs1v1_5Tester() {
signal input modulus[64];
signal input message[64];

signal input dummy;

VerifyRsaPkcs1v1_5(10, 64, 64, 65537, 256)(signature, modulus, message, dummy);
VerifyRsaPkcs1v1_5(10, 64, 64, 65537, 256)(signature, modulus, message);
}

component main = VerifyRsaPkcs1v1_5Tester();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ template VerifyRsaPkcs1v1_5Tester() {
signal input modulus[64];
signal input message[64];

signal input dummy;

VerifyRsaPkcs1v1_5(15, 64, 64, 65537, 512)(signature, modulus, message, dummy);
VerifyRsaPkcs1v1_5(15, 64, 64, 65537, 512)(signature, modulus, message);
}

component main = VerifyRsaPkcs1v1_5Tester();
Loading

0 comments on commit e4dd6e7

Please sign in to comment.