Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/circom dl #258

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
934ca6e
Merge pull request #232 from zk-passport/dev
remicolin Oct 28, 2024
bdfb3a5
Merge pull request #237 from zk-passport/dev
remicolin Oct 31, 2024
b03c78d
Merge pull request #241 from zk-passport/dev
remicolin Nov 2, 2024
e33f52b
Merge pull request #244 from zk-passport/dev
remicolin Nov 6, 2024
d0204ec
Merge pull request #246 from openpassport-org/dev
remicolin Nov 14, 2024
48f0f2e
Merge pull request #250 from openpassport-org/dev
remicolin Dec 1, 2024
616e165
Merge pull request #252 from openpassport-org/dev
remicolin Dec 1, 2024
90f6091
Merge pull request #253 from openpassport-org/dev
remicolin Dec 1, 2024
14c42a5
Merge pull request #254 from openpassport-org/dev
remicolin Dec 1, 2024
13ff332
feat: replace circomlib dependency with circom-dl
Nesopie Dec 14, 2024
2c83884
feat: replace circomlib with circom-dl
Nesopie Dec 14, 2024
05ef259
fix yarn behaviour
remicolin Dec 14, 2024
cfb95d7
use new certificate parsing functions in csca.ts
remicolin Dec 14, 2024
01e66e3
Merge branch 'feat/circom-dl' of https://github.com/zk-passport/openp…
remicolin Dec 14, 2024
e88e528
import circomlib-dl locally - fix import issues
remicolin Dec 14, 2024
ae7eb97
Merge pull request #259 from openpassport-org/fix/dsc-circuits
remicolin Dec 14, 2024
85ad6bd
update import from secp256r1Verifier to local circomlib
remicolin Dec 15, 2024
7b97702
fix for circom-dl
motemotech Dec 15, 2024
5a98974
remove circomlib from test code
motemotech Dec 15, 2024
99deb1e
remove dummy from other codes
motemotech Dec 15, 2024
d395856
Merge pull request #261 from openpassport-org/feat/rsa-on-circom-dl
remicolin Dec 15, 2024
e8f5e5c
import comparators and bitify from circomlib
remicolin Dec 15, 2024
a7f789c
uncomment smt check
remicolin Dec 15, 2024
222084a
import mux1.circom from circomlib
remicolin Dec 15, 2024
655882f
fix ofac tests and move ofac to utils/passport/ofac repo
remicolin Dec 15, 2024
bd701f9
refactored circomlib repo
remicolin Dec 15, 2024
e986758
Remove unused FormatECDSAInputs template from circom utils
remicolin Dec 15, 2024
32876e8
add sha1
seshanthS Dec 15, 2024
9d5fd14
Merge branch 'feat/circom-dl' of github.com:openpassport-org/openpass…
seshanthS Dec 15, 2024
1d60790
add ecdsa.circom
remicolin Dec 15, 2024
9fede8d
remove err.log
remicolin Dec 15, 2024
cfeb7c3
add err.log to .gitignore
remicolin Dec 15, 2024
78b1b75
refactor disclose circuits
remicolin Dec 15, 2024
b2cded4
fix vc_and_disclose.circom
remicolin Dec 15, 2024
772cf00
Merge branch 'feat/circom-dl' of github.com:openpassport-org/openpass…
seshanthS Dec 15, 2024
f06d6bb
sha1: fix import
seshanthS Dec 15, 2024
08e6f68
add sha256
seshanthS Dec 15, 2024
74e1ac3
add sha256Bytes.circom
seshanthS Dec 15, 2024
7edb511
add splitSignalsToWords
remicolin Dec 15, 2024
75c5cd8
remove circuits/utils/other repo
remicolin Dec 15, 2024
382578d
move sha256 to sha256_temp
remicolin Dec 15, 2024
86686bc
add rsapss-sha256-65537
seshanthS Dec 15, 2024
f8fed74
add rsapss-sha256-65537-3072
seshanthS Dec 15, 2024
2257e00
add rsapsss-sha256-3-4096
seshanthS Dec 15, 2024
eb0f909
add rsapss-sha256-3-3072
seshanthS Dec 15, 2024
eb204d2
uncomment test
seshanthS Dec 15, 2024
5798121
move shaBytesDynamic to circomlib repo
remicolin Dec 15, 2024
7cdd858
Merge pull request #262 from openpassport-org/feat/circomdl-rsapss
remicolin Dec 15, 2024
103f5fd
Merge branch 'feat/circom-dl' of https://github.com/zk-passport/openp…
remicolin Dec 15, 2024
1458335
move rsapss to circomlib/signature
remicolin Dec 15, 2024
258134e
uncomment rsapss tests
remicolin Dec 15, 2024
f86e709
clean openpassportVerifier
remicolin Dec 15, 2024
ddd89e4
use n,k=64 for dsc, use new parsing library to build csca merkle tree
remicolin Dec 15, 2024
b6b71ab
fix prove circuits
motemotech Dec 15, 2024
ea48b51
Merge remote-tracking branch 'origin/feat/circom-dl' into feat/update…
motemotech Dec 15, 2024
97155f6
fix rsa test
motemotech Dec 15, 2024
c8504f7
fix dir structure
motemotech Dec 15, 2024
03b312a
update contracts test code
motemotech Dec 16, 2024
0e00117
Merge pull request #263 from openpassport-org/feat/update-for-new-rsa
remicolin Dec 16, 2024
df70f7a
comment tests
remicolin Dec 16, 2024
bb25ddb
feat: working secp256r1 verifier
Nesopie Dec 16, 2024
a4b00d8
Merge branch 'feat/circom-dl' into feat/ecdsa
Nesopie Dec 16, 2024
57d094d
chore: change n and k params for ecdsa
Nesopie Dec 16, 2024
7de5a3a
chore: remove describe.only from prove test
Nesopie Dec 16, 2024
e672a32
Merge pull request #265 from openpassport-org/feat/ecdsa
remicolin Dec 16, 2024
b58d2f7
fix n,k for ecdsa circuits
remicolin Dec 16, 2024
065374a
uncomment tests, clean code and remove dummy from circuit inputs
remicolin Dec 16, 2024
f6ce4bc
remove dummy from dsc circuit inputs and remove uncessary logs
remicolin Dec 16, 2024
f816696
add openpassport register contract
motemotech Dec 17, 2024
29c90af
Merge branch 'test/contracts' into fix/register-contract
motemotech Dec 17, 2024
be67f50
add test and merge test/contracts
motemotech Dec 17, 2024
039f122
add test cases
motemotech Dec 17, 2024
7f4f2f7
Merge pull request #267 from openpassport-org/fix/register-contract
remicolin Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion circuits/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
inputs
build
node_modules/
node_modules/
err.log
Binary file added circuits/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions circuits/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
15 changes: 8 additions & 7 deletions circuits/circuits/disclose/vc_and_disclose.circom
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma circom 2.1.9;

include "./verify_commitment.circom";
include "./disclose.circom";
include "./proveCountryIsNotInList.circom";
include "../ofac/ofac_name.circom";
include "../utils/passport/disclose/verify_commitment.circom";
include "../utils/passport/disclose/disclose.circom";
include "../utils/passport/disclose/proveCountryIsNotInList.circom";
include "../utils/passport/ofac/ofac_name.circom";

template VC_AND_DISCLOSE( nLevels,FORBIDDEN_COUNTRIES_LIST_LENGTH) {

Expand Down Expand Up @@ -45,9 +45,10 @@ template VC_AND_DISCLOSE( nLevels,FORBIDDEN_COUNTRIES_LIST_LENGTH) {
disclose.majority <== majority;

// generate scope nullifier
component poseidon_nullifier = Poseidon(2);
poseidon_nullifier.inputs[0] <== secret;
poseidon_nullifier.inputs[1] <== scope;
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.9;

include "../openpassport_dsc.circom";

component main { public [ merkle_root ] } = OPENPASSPORT_DSC(11, 64, 32, 120, 35, 1664, 256, 12);
component main { public [ merkle_root ] } = OPENPASSPORT_DSC(11, 64, 32, 64, 64, 1664, 256, 12);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.9;

include "../openpassport_dsc.circom";

component main { public [ merkle_root ] } = OPENPASSPORT_DSC(10, 64, 32, 120, 35, 1664, 256, 12);
component main { public [ merkle_root ] } = OPENPASSPORT_DSC(10, 64, 32, 64, 64, 1664, 256, 12);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.9;

include "../openpassport_dsc.circom";

component main { public [ merkle_root ] } = OPENPASSPORT_DSC(12, 64, 32, 120, 35, 1664, 256, 12);
component main { public [ merkle_root ] } = OPENPASSPORT_DSC(12, 64, 32, 64, 64, 1664, 256, 12);
32 changes: 23 additions & 9 deletions circuits/circuits/dsc/openpassport_dsc.circom
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
pragma circom 2.1.9;

include "circomlib/circuits/bitify.circom";
include "circomlib/circuits/poseidon.circom";
include "circomlib/circuits/comparators.circom";
include "binary-merkle-root.circom";
include "../utils/circomlib/bitify/bitify.circom";
include "../utils/circomlib/hasher/shaBytes/shaBytesDynamic.circom";
include "../utils/circomlib/bitify/comparators.circom";
include "../utils/circomlib/hasher/hash.circom";
include "../utils/circomlib/merkle-trees/binary-merkle-root.circom";
include "../utils/passport/customHashers.circom";
include "../utils/other/bytes.circom";
include "../utils/passport/signatureAlgorithm.circom";
include "../utils/passport/signatureVerifier.circom";
include "../utils/shaBytes/shaBytesDynamic.circom";
include "../utils/other/bytes.circom";
include "../utils/circomlib/utils/bytes.circom";


template OPENPASSPORT_DSC(signatureAlgorithm, n_dsc, k_dsc, n_csca, k_csca, max_cert_bytes, dscPubkeyBytesLength, nLevels) {
Expand All @@ -35,15 +34,30 @@ 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);

signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings);
merkle_root === computed_merkle_root;

// signal raw_dsc_cert_bits[max_cert_bytes * 8];

// component n2b[max_cert_bytes];
// for (var i = 0; i < max_cert_bytes; i++) {
// n2b[i] = Num2Bits(8);
// n2b[i].in <== raw_dsc_cert[i];
// for (var j = 0; j < 8; j++) {
// raw_dsc_cert_bits[i * 8 + j] <== n2b[i].out[j];
// }
// }

// 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);
// for now 512 but it can be 1024 as well
// signal hashedCertificate[hashLength] <== ShaHashChunks((max_cert_bytes * 8) \ 512, hashLength)(raw_dsc_cert_bits, 0);
SignatureVerifier(signatureAlgorithm, n_csca, k_csca)(hashedCertificate, csca_pubKey, signature, dummy);

// verify DSC csca_pubKey
component shiftLeft = VarShiftLeft(max_cert_bytes, dscPubkeyBytesLength); // use select subarray for dscPubKey variable length
Expand All @@ -57,6 +71,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 <== Poseidon(2)([secret, pubkeyHash]);
signal output blinded_dsc_commitment <== PoseidonHash(2)([secret, pubkeyHash], 0);
}

29 changes: 0 additions & 29 deletions circuits/circuits/ofac/ofac_name.circom

This file was deleted.

37 changes: 0 additions & 37 deletions circuits/circuits/ofac/ofac_name_dob.circom

This file was deleted.

25 changes: 0 additions & 25 deletions circuits/circuits/ofac/ofac_passport_number.circom

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.9;

include "../openpassport_prove.circom";

component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(7, 43, 6, 320, 192, 20);
component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(7, 64, 4, 320, 192, 20);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.9;

include "../openpassport_prove.circom";

component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(8, 43, 6, 384, 192, 20);
component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(8, 64, 4, 384, 192, 20);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../openpassport_prove.circom";

component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(16, 96, 32, 384, 192, 20);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../openpassport_prove.circom";

component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(17, 64, 64, 384, 192, 20);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../openpassport_prove.circom";

component main { public [ scope, user_identifier, current_date ] } = OPENPASSPORT_PROVE(19, 96, 32, 384, 192, 20);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../openpassport_prove.circom";

component main { public [ scope, user_identifier, current_date] } = OPENPASSPORT_PROVE(12, 64, 64, 384, 192, 20);
31 changes: 19 additions & 12 deletions circuits/circuits/prove/openpassport_prove.circom
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ pragma circom 2.1.9;
include "../utils/passport/customHashers.circom";
include "../utils/passport/computeCommitment.circom";
include "../utils/passport/signatureAlgorithm.circom";
include "../utils/passport/date/isValid.circom";
include "../utils/circomlib/hasher/poseidon/poseidon.circom";
include "../utils/passport/passportVerifier.circom";
include "../disclose/disclose.circom";
include "../disclose/proveCountryIsNotInList.circom";
include "../ofac/ofac_name.circom";
include "../utils/passport/disclose/disclose.circom";
include "../utils/passport/disclose/proveCountryIsNotInList.circom";
include "../utils/passport/ofac/ofac_name.circom";

template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, MAX_SIGNED_ATTR_PADDED_LEN, FORBIDDEN_COUNTRIES_LIST_LENGTH) {
var kLengthFactor = getKLengthFactor(signatureAlgorithm);
Expand Down Expand Up @@ -45,6 +47,8 @@ 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;

signal selectorModeDisclosure <== selector_mode[0];
Expand All @@ -54,9 +58,8 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
signal isWrongSelectorMode <== IsEqual()([2*selector_mode[0] + selector_mode[1], 1]);
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);
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);
// verify passport is not expired
component isValid = IsValid();
isValid.currDate <== current_date;
Expand All @@ -65,8 +68,12 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
}

// nulifier
signal signatureHashed <== CustomHasher(kScaled)(signature); // generate nullifier
signal output nullifier <== Poseidon(2)([signatureHashed, scope]);
signal signatureHashed <== CustomHasher(kScaled)(signature);
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)
// optionally disclose data
Expand Down Expand Up @@ -102,13 +109,13 @@ template OPENPASSPORT_PROVE(signatureAlgorithm, n, k, MAX_ECONTENT_PADDED_LEN, M
signal ofacIntermediaryOutput <== ofacCheckResult * selector_ofac;
signal output ofac_result <== ofacIntermediaryOutput;

// REGISTRATION (optional)
// generate the commitment
// // REGISTRATION (optional)
// // generate the commitment
signal leaf <== LeafHasher(kScaled)(pubKey, signatureAlgorithm);
signal commitmentPrivate <== ComputeCommitment()(secret, attestation_id, leaf, dg1, dg2_hash);
signal output commitment <== commitmentPrivate * selectorModeCommitment;
// blinded dsc commitment
// // blinded dsc commitment
signal pubkeyHash <== CustomHasher(kScaled)(pubKey);
signal blindedDscCommitmenPrivate <== Poseidon(2)([dsc_secret, pubkeyHash]);
signal blindedDscCommitmenPrivate <== PoseidonHash(2)([dsc_secret, pubkeyHash],0);
signal output blinded_dsc_commitment <== blindedDscCommitmenPrivate * selectorModeBlindedDscCommitment;
}
}
2 changes: 1 addition & 1 deletion circuits/circuits/tests/ofac/ofac_name_dob_tester.circom
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pragma circom 2.1.9;
include "../../ofac/ofac_name_dob.circom";
include "../../utils/passport/ofac/ofac_name_dob.circom";
component main { public [ smt_root ] } = OFAC_NAME_DOB();
2 changes: 1 addition & 1 deletion circuits/circuits/tests/ofac/ofac_name_tester.circom
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pragma circom 2.1.9;
include "../../ofac/ofac_name.circom";
include "../../utils/passport/ofac/ofac_name.circom";
component main { public [ smt_root ] } = OFAC_NAME();
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pragma circom 2.1.9;
include "../../ofac/ofac_passport_number.circom";
include "../../utils/passport/ofac/ofac_passport_number.circom";
component main { public [ smt_root ] } = OFAC_PASSPORT_NUMBER();
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pragma circom 2.1.9;

include "../../../utils/rsa/verifyRsaPkcs1v1_5.circom";
include "../../../utils/circomlib/signature/rsa/verifyRsaPkcs1v1_5.circom";

template VerifyRsaPkcs1v1_5Tester() {
signal input signature[32];
signal input modulus[32];
signal input message[32];

VerifyRsaPkcs1v1_5(3, 64, 32, 17, 160)(signature, modulus, message);
signal input dummy;

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

component main = VerifyRsaPkcs1v1_5Tester();
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pragma circom 2.1.9;

include "../../../utils/rsa/verifyRsaPkcs1v1_5.circom";
include "../../../utils/circomlib/signature/rsa/verifyRsaPkcs1v1_5.circom";

template VerifyRsaPkcs1v1_5Tester() {
signal input signature[32];
signal input modulus[32];
signal input message[32];

VerifyRsaPkcs1v1_5(13, 64, 32, 2, 256)(signature, modulus, message);
signal input dummy;

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

component main = VerifyRsaPkcs1v1_5Tester();
Loading