From 419cfbde5911364e8b4f970f69fcfca2138bb13c Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Mon, 9 Feb 2026 23:58:58 +0530 Subject: [PATCH 01/15] refactored passport libraries --- .../merkle_age_check/Nargo.toml | 0 .../merkle_age_check/README.md | 0 .../benchmark-inputs/case1/t_add_dsc_720.toml | 0 .../case1/t_add_id_data_720.toml | 0 .../case1/t_add_integrity_commit.toml | 0 .../benchmark-inputs/case1/t_attest.toml | 0 .../case2/t_add_dsc_hash_1300.toml | 0 .../case2/t_add_dsc_verify_1300.toml | 0 .../case2/t_add_id_data_1300.toml | 0 .../case2/t_add_integrity_commit.toml | 0 .../benchmark-inputs/case2/t_attest.toml | 0 .../scripts/case1/compile-circuits.sh | 0 .../scripts/case1/prepare-circuits.sh | 0 .../scripts/case1/prove-circuits.sh | 0 .../scripts/case2/compile-circuits.sh | 0 .../scripts/case2/prepare-circuits.sh | 0 .../scripts/case2/prove-circuits.sh | 0 .../merkle_age_check/t_add_dsc_720/Nargo.toml | 0 .../t_add_dsc_720/src/main.nr | 0 .../t_add_dsc_hash_1300/Nargo.toml | 0 .../t_add_dsc_hash_1300/src/main.nr | 0 .../t_add_dsc_verify_1300/Nargo.toml | 0 .../t_add_dsc_verify_1300/src/main.nr | 0 .../t_add_id_data_1300/Nargo.toml | 0 .../t_add_id_data_1300/src/main.nr | 0 .../t_add_id_data_720/Nargo.toml | 0 .../t_add_id_data_720/src/main.nr | 0 .../t_add_integrity_commit/Nargo.toml | 0 .../t_add_integrity_commit/src/main.nr | 0 .../merkle_age_check/t_attest/Nargo.toml | 0 .../merkle_age_check/t_attest/src/main.nr | 0 .../utils}/commitment/dsc-to-id/Nargo.toml | 0 .../utils}/commitment/dsc-to-id/src/lib.nr | 0 .../commitment/scoped-nullifier/Nargo.toml | 0 .../commitment/scoped-nullifier/src/lib.nr | 0 .../complete_age_check/Nargo.toml | 0 .../complete_age_check/Prover.toml | 0 .../complete_age_check/scripts/compile.sh | 0 .../complete_age_check/src/main.nr | 0 .../utils}/commitment/csc-to-dsc/Nargo.toml | 0 .../utils}/commitment/csc-to-dsc/src/lib.nr | 0 .../utils}/passport_validity_check/Nargo.toml | 0 .../utils}/passport_validity_check/src/lib.nr | 0 .../commitment/common/Nargo.toml | 0 .../commitment/common/src/lib.nr | 0 .../compare/age/Nargo.toml | 0 .../compare/age/src/lib.nr | 0 .../data-check/expiry/Nargo.toml | 0 .../data-check/expiry/src/lib.nr | 0 .../data-check/integrity/Nargo.toml | 0 .../data-check/integrity/src/lib.nr | 0 .../data-check/tbs-pubkey/Nargo.toml | 0 .../data-check/tbs-pubkey/src/lib.nr | 0 .../sig-check/common/Nargo.toml | 0 .../sig-check/common/src/lib.nr | 0 .../sig-check/rsa/Nargo.toml | 0 .../sig-check/rsa/src/lib.nr | 0 .../utils/Nargo.toml | 0 .../utils/src/constants.nr | 0 .../utils/src/lib.nr | 0 .../utils/src/tests.nr | 0 .../utils/src/types.nr | 0 .../zkpassport_libs/LICENSE | 202 ----------- .../zkpassport_libs/README.md | 1 - .../integrity-to-disclosure/Nargo.toml | 9 - .../integrity-to-disclosure/src/lib.nr | 66 ---- .../compare/citizenship/Nargo.toml | 9 - .../compare/citizenship/src/lib.nr | 9 - .../zkpassport_libs/compare/date/Nargo.toml | 12 - .../zkpassport_libs/compare/date/src/lib.nr | 145 -------- .../zkpassport_libs/disclose/Nargo.toml | 8 - .../zkpassport_libs/disclose/src/lib.nr | 152 -------- .../exclusion-check/country/Nargo.toml | 8 - .../exclusion-check/country/src/lib.nr | 75 ---- .../inclusion-check/country/Nargo.toml | 8 - .../inclusion-check/country/src/lib.nr | 68 ---- .../sig-check/ecdsa/Nargo.toml | 11 - .../sig-check/ecdsa/src/lib.nr | 336 ------------------ 78 files changed, 1119 deletions(-) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/README.md (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case1/t_attest.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/benchmark-inputs/case2/t_attest.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/scripts/case1/compile-circuits.sh (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/scripts/case1/prepare-circuits.sh (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/scripts/case1/prove-circuits.sh (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/scripts/case2/compile-circuits.sh (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/scripts/case2/prepare-circuits.sh (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/scripts/case2/prove-circuits.sh (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_dsc_720/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_dsc_720/src/main.nr (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_dsc_hash_1300/src/main.nr (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_dsc_verify_1300/src/main.nr (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_id_data_1300/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_id_data_1300/src/main.nr (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_id_data_720/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_id_data_720/src/main.nr (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_integrity_commit/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_add_integrity_commit/src/main.nr (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_attest/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => fragmented}/merkle_age_check/t_attest/src/main.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => fragmented/utils}/commitment/dsc-to-id/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => fragmented/utils}/commitment/dsc-to-id/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => fragmented/utils}/commitment/scoped-nullifier/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => fragmented/utils}/commitment/scoped-nullifier/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{ => monolithic}/complete_age_check/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => monolithic}/complete_age_check/Prover.toml (100%) rename noir-examples/noir-passport-examples/{ => monolithic}/complete_age_check/scripts/compile.sh (100%) rename noir-examples/noir-passport-examples/{ => monolithic}/complete_age_check/src/main.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => monolithic/utils}/commitment/csc-to-dsc/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => monolithic/utils}/commitment/csc-to-dsc/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{ => monolithic/utils}/passport_validity_check/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{ => monolithic/utils}/passport_validity_check/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/commitment/common/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/commitment/common/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/compare/age/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/compare/age/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/data-check/expiry/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/data-check/expiry/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/data-check/integrity/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/data-check/integrity/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/data-check/tbs-pubkey/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/data-check/tbs-pubkey/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/sig-check/common/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/sig-check/common/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/sig-check/rsa/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/sig-check/rsa/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/utils/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/utils/src/constants.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/utils/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/utils/src/tests.nr (100%) rename noir-examples/noir-passport-examples/{zkpassport_libs => shared-utils}/utils/src/types.nr (100%) delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/LICENSE delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/README.md delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/compare/date/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/compare/date/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/disclose/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/disclose/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/src/lib.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/README.md b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/README.md rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_attest.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case1/t_attest.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_attest.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/benchmark-inputs/case2/t_attest.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/scripts/case1/compile-circuits.sh b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/scripts/case1/compile-circuits.sh rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh diff --git a/noir-examples/noir-passport-examples/merkle_age_check/scripts/case1/prepare-circuits.sh b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/scripts/case1/prepare-circuits.sh rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh diff --git a/noir-examples/noir-passport-examples/merkle_age_check/scripts/case1/prove-circuits.sh b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/scripts/case1/prove-circuits.sh rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh diff --git a/noir-examples/noir-passport-examples/merkle_age_check/scripts/case2/compile-circuits.sh b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/scripts/case2/compile-circuits.sh rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh diff --git a/noir-examples/noir-passport-examples/merkle_age_check/scripts/case2/prepare-circuits.sh b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/scripts/case2/prepare-circuits.sh rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh diff --git a/noir-examples/noir-passport-examples/merkle_age_check/scripts/case2/prove-circuits.sh b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/scripts/case2/prove-circuits.sh rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_720/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_720/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_720/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_720/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_hash_1300/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_hash_1300/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_verify_1300/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_dsc_verify_1300/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_1300/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_1300/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_1300/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_1300/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_720/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_720/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_720/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_id_data_720/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_integrity_commit/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_integrity_commit/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_add_integrity_commit/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_add_integrity_commit/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_attest/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_attest/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml diff --git a/noir-examples/noir-passport-examples/merkle_age_check/t_attest/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/merkle_age_check/t_attest/src/main.nr rename to noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/dsc-to-id/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/dsc-to-id/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/dsc-to-id/src/lib.nr b/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/dsc-to-id/src/lib.nr rename to noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/scoped-nullifier/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/scoped-nullifier/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/scoped-nullifier/src/lib.nr b/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/scoped-nullifier/src/lib.nr rename to noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr diff --git a/noir-examples/noir-passport-examples/complete_age_check/Nargo.toml b/noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/complete_age_check/Nargo.toml rename to noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml diff --git a/noir-examples/noir-passport-examples/complete_age_check/Prover.toml b/noir-examples/noir-passport-examples/monolithic/complete_age_check/Prover.toml similarity index 100% rename from noir-examples/noir-passport-examples/complete_age_check/Prover.toml rename to noir-examples/noir-passport-examples/monolithic/complete_age_check/Prover.toml diff --git a/noir-examples/noir-passport-examples/complete_age_check/scripts/compile.sh b/noir-examples/noir-passport-examples/monolithic/complete_age_check/scripts/compile.sh similarity index 100% rename from noir-examples/noir-passport-examples/complete_age_check/scripts/compile.sh rename to noir-examples/noir-passport-examples/monolithic/complete_age_check/scripts/compile.sh diff --git a/noir-examples/noir-passport-examples/complete_age_check/src/main.nr b/noir-examples/noir-passport-examples/monolithic/complete_age_check/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/complete_age_check/src/main.nr rename to noir-examples/noir-passport-examples/monolithic/complete_age_check/src/main.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/csc-to-dsc/Nargo.toml b/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/csc-to-dsc/Nargo.toml rename to noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/csc-to-dsc/src/lib.nr b/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/csc-to-dsc/src/lib.nr rename to noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/src/lib.nr diff --git a/noir-examples/noir-passport-examples/passport_validity_check/Nargo.toml b/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/passport_validity_check/Nargo.toml rename to noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml diff --git a/noir-examples/noir-passport-examples/passport_validity_check/src/lib.nr b/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/passport_validity_check/src/lib.nr rename to noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/common/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/commitment/common/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/common/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/commitment/common/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/common/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/commitment/common/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/commitment/common/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/commitment/common/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/compare/age/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/compare/age/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/compare/age/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/compare/age/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/compare/age/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/compare/age/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/compare/age/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/compare/age/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/data-check/expiry/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/data-check/expiry/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/data-check/expiry/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/data-check/expiry/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/data-check/expiry/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/data-check/expiry/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/data-check/expiry/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/data-check/expiry/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/data-check/integrity/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/data-check/integrity/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/data-check/integrity/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/data-check/integrity/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/data-check/integrity/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/data-check/integrity/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/data-check/tbs-pubkey/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/data-check/tbs-pubkey/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/data-check/tbs-pubkey/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/common/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/sig-check/common/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/sig-check/common/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/sig-check/common/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/common/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/sig-check/common/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/sig-check/common/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/sig-check/common/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/sig-check/rsa/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/sig-check/rsa/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/utils/Nargo.toml b/noir-examples/noir-passport-examples/shared-utils/utils/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/utils/Nargo.toml rename to noir-examples/noir-passport-examples/shared-utils/utils/Nargo.toml diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/utils/src/constants.nr b/noir-examples/noir-passport-examples/shared-utils/utils/src/constants.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/utils/src/constants.nr rename to noir-examples/noir-passport-examples/shared-utils/utils/src/constants.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/utils/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/utils/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/utils/src/lib.nr rename to noir-examples/noir-passport-examples/shared-utils/utils/src/lib.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/utils/src/tests.nr b/noir-examples/noir-passport-examples/shared-utils/utils/src/tests.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/utils/src/tests.nr rename to noir-examples/noir-passport-examples/shared-utils/utils/src/tests.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/utils/src/types.nr b/noir-examples/noir-passport-examples/shared-utils/utils/src/types.nr similarity index 100% rename from noir-examples/noir-passport-examples/zkpassport_libs/utils/src/types.nr rename to noir-examples/noir-passport-examples/shared-utils/utils/src/types.nr diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/LICENSE b/noir-examples/noir-passport-examples/zkpassport_libs/LICENSE deleted file mode 100644 index 7a4a3ea24..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/README.md b/noir-examples/noir-passport-examples/zkpassport_libs/README.md deleted file mode 100644 index 955d76733..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/README.md +++ /dev/null @@ -1 +0,0 @@ -Code from https://github.com/zkpassport/circuits. \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/Nargo.toml deleted file mode 100644 index e67e03e45..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/Nargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "integrity_to_disclosure_commitment" -type = "lib" -authors = ["Theo Madzou", "Michael Elliot"] -compiler_version = ">=1.0.0" - -[dependencies] -utils = { path = "../../utils" } -common = { path = "../common" } diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/src/lib.nr deleted file mode 100644 index 9317f30e0..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/commitment/integrity-to-disclosure/src/lib.nr +++ /dev/null @@ -1,66 +0,0 @@ -use common::{ - get_country_from_dg1, - hash_salt_country_signed_attr_dg1_e_content_private_nullifier, - hash_salt_dg1_private_nullifier -}; -use utils::{get_expiry_date_from_mrz, types::SaltedValue}; - -/* -############################################################ -# Circuit C - Integrity to Disclosure Commitment -############################################################ -# Transitions from integrity verification commitment to disclosure commitment -############################################################ - -# Inputs/Outputs -############################################################ -comm_in `assert comm_in == H(salt_in, country, signed_attr, signed_attr_size, dg1, e_content, private_nullifier)` -salt_in salt used in the integrity commitment -salted_dg1 salted DG1 data (MRZ) -expiry_date_salt salt for expiry date -signed_attributes the signed attributes from the passport -signed_attributes_size actual size of signed attributes -e_content the eContent containing data group hashes -salted_private_nullifier salted private nullifier value -comm_out `H(salted_dg1_hash, salted_expiry_date_hash, salted_private_nullifier_hash)` - -# What this proves -############################################################ -- Verifies that comm_in matches the expected hash of integrity data -- Produces comm_out as a commitment to salted disclosure values -*/ -pub fn commit_to_disclosure( - comm_in: Field, - salt_in: Field, - salted_dg1: SaltedValue<[u8; 95]>, - expiry_date_salt: Field, - signed_attributes: [u8; SA_SIZE], - signed_attributes_size: Field, - e_content: [u8; ECONTENT_SIZE], - salted_private_nullifier: SaltedValue, -) -> Field { - let country = get_country_from_dg1(salted_dg1.value); - assert( - comm_in - == hash_salt_country_signed_attr_dg1_e_content_private_nullifier( - salt_in, - country, - signed_attributes, - signed_attributes_size, - salted_dg1.value, - e_content, - salted_private_nullifier.value, - ), - "Commitment from 2nd subproof doesn't match in 3rd subproof", - ); - - let salted_expiry_date = - SaltedValue::from_value(expiry_date_salt, get_expiry_date_from_mrz(salted_dg1.value)); - - let comm_out = hash_salt_dg1_private_nullifier( - salted_dg1, - salted_expiry_date, - salted_private_nullifier, - ); - comm_out -} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/Nargo.toml deleted file mode 100644 index 5f440061d..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/Nargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "compare_citizenship_lib" -type = "lib" -authors = ["Theo Madzou", "Michael Elliot"] -compiler_version = ">=1.0.0" - -[dependencies] -utils = { path = "../../utils" } - diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/src/lib.nr deleted file mode 100644 index cabee34dd..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/compare/citizenship/src/lib.nr +++ /dev/null @@ -1,9 +0,0 @@ -use utils::get_nationality_from_mrz; - -pub fn compare_citizenship(dg1: [u8; 95], country: [u8; 3]) { - let country_bytes = get_nationality_from_mrz(dg1); - - assert(country_bytes[0] == country[0]); - assert(country_bytes[1] == country[1]); - assert(country_bytes[2] == country[2]); -} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/compare/date/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/compare/date/Nargo.toml deleted file mode 100644 index fe86d8d26..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/compare/date/Nargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "compare_date_lib" -type = "lib" -authors = ["Theo Madzou", "Michael Elliot"] -compiler_version = ">=1.0.0" - -[dependencies] -date = { tag = "v0.5.4", git = "https://github.com/madztheo/noir-date.git" } -utils = { path = "../../utils" } -# noir_native_sha256 = { path = "../../../noir_native_sha256" } -sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } -poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/compare/date/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/compare/date/src/lib.nr deleted file mode 100644 index efcb4b6a3..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/compare/date/src/lib.nr +++ /dev/null @@ -1,145 +0,0 @@ -use date::Date; -use poseidon::poseidon2::Poseidon2; -use utils::{ - get_array_slice, get_mrz_from_dg1, ID_CARD_MRZ_BIRTHDATE_INDEX, ID_CARD_MRZ_EXPIRY_DATE_INDEX, - is_id_card, PASSPORT_MRZ_BIRTHDATE_INDEX, PASSPORT_MRZ_EXPIRY_DATE_INDEX, -}; - -fn get_date(dg1: [u8; 95], threshold_date: Date) -> Date { - let mrz = get_mrz_from_dg1(dg1); - - let date_bytes = get_array_slice(mrz, INDEX, INDEX + 6); - - // Create a Date object from the date using the current date as - // the pivot year to differentiate between 20th and 21st centuries - // as the format is "YYMMDD" - Date::from_bytes_short_year(date_bytes, threshold_date) -} - -pub fn get_birthdate(dg1: [u8; 95], timestamp: u64) -> Date { - let current_date = Date::from_timestamp(timestamp); - let mut birthdate = Date::new(1, 1, 1); - - // Get the slice of the MRZ representing the birthdate - if is_id_card(dg1) { - birthdate = get_date::(dg1, current_date); - } else { - birthdate = get_date::(dg1, current_date); - } - - birthdate -} - -pub fn get_expiry_date(dg1: [u8; 95], timestamp: u64) -> Date { - let current_date = Date::from_timestamp(timestamp); - let mut expiry_date = Date::new(1, 1, 1); - - // We base the threshold year for the expiry date on the current date plus 20 years - // As most documents will have a 10 year validity (and some maybe 15 years?) - // So with 20 years we should be safe - let threshold_year = current_date.add_years(20); - - // Get the slice of the MRZ representing the expiry date - if is_id_card(dg1) { - expiry_date = get_date::(dg1, threshold_year); - } else { - expiry_date = get_date::(dg1, threshold_year); - } - - expiry_date -} - -pub fn compare_date( - date_to_compare: Date, - min_date_timestamp: u64, - max_date_timestamp: u64, - epoch_year: u32, -) { - assert( - (min_date_timestamp != 0) | (max_date_timestamp != 0), - "Either min or max date must be non-zero", - ); - - let min_date = Date::from_timestamp_with_epoch(min_date_timestamp, epoch_year); - let max_date = Date::from_timestamp_with_epoch(max_date_timestamp, epoch_year); - - if (min_date_timestamp != 0) & (max_date_timestamp == 0) { - // The minimum date is more likely to be inclusive, so we use gte - assert(date_to_compare.gte(min_date), "Date is not above or equal to min date"); - } else if (max_date_timestamp != 0) & (min_date_timestamp == 0) { - // The maximum date is more likely to be inclusive, so we use lte - assert(date_to_compare.lte(max_date), "Date is not below or equal to max date"); - } else { - assert(min_date.lte(max_date), "Min date must be less than or equal to max date"); - - // Check if birthdate is within the range - assert(date_to_compare.gte(min_date), "Date is not above or equal to min date"); - assert(date_to_compare.lte(max_date), "Date is not below or equal to max date"); - } -} - -/// Calculate the commitment of the current date, min date and max date using Poseidon2 -/// -/// This is less demanding on the prover but much more demanding on EVM verifiers -/// -/// # Arguments -/// -/// * `proof_type`: The proof type -/// * `current_date`: The current date -/// * `min_date`: The minimum date -/// * `max_date`: The maximum date -/// -/// # Returns -/// -/// * `commitment`: The commitment of the current date, min date and max date -pub fn calculate_param_commitment( - proof_type: u8, - current_date_timestamp: u64, - min_date_timestamp: u64, - max_date_timestamp: u64, -) -> Field { - let mut params = [0 as Field; 4]; - params[0] = proof_type as Field; - params[1] = current_date_timestamp as Field; - params[2] = min_date_timestamp as Field; - params[3] = max_date_timestamp as Field; - Poseidon2::hash(params, 4) -} - -/// Calculate the commitment of the current date, min date and max date using SHA2-256 -/// -/// This is more demanding on the prover but less demanding on EVM verifiers -/// -/// # Arguments -/// -/// * `proof_type`: The proof type -/// * `current_date`: The current date -/// * `min_date`: The minimum date -/// * `max_date`: The maximum date -/// -/// # Returns -/// -/// * `commitment`: The commitment of the current date, min date and max date -pub fn calculate_param_commitment_sha2( - proof_type: u8, - current_date_timestamp: u64, - min_date_timestamp: u64, - max_date_timestamp: u64, -) -> Field { - let mut params = [0 as u8; 25]; - params[0] = proof_type; - let current_date_timestamp_bytes: [u8; 8] = (current_date_timestamp as Field).to_be_bytes(); - for i in 1..9 { - params[i] = current_date_timestamp_bytes[i - 1]; - } - let min_date_timestamp_bytes: [u8; 8] = (min_date_timestamp as Field).to_be_bytes(); - for i in 9..17 { - params[i] = min_date_timestamp_bytes[i - 9]; - } - let max_date_timestamp_bytes: [u8; 8] = (max_date_timestamp as Field).to_be_bytes(); - for i in 17..25 { - params[i] = max_date_timestamp_bytes[i - 17]; - } - let hash = noir_native_sha256::ryan_sha256_noir::sha256_var(params, 25); - utils::pack_be_bytes_into_field::<32, 31>(hash) -} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/disclose/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/disclose/Nargo.toml deleted file mode 100644 index 8176095ef..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/disclose/Nargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "disclose_lib" -type = "lib" -authors = ["Theo Madzou"] -compiler_version = ">=0.32.0" - -[dependencies] -utils = { path = "../utils" } \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/disclose/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/disclose/src/lib.nr deleted file mode 100644 index a9e38c3c0..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/disclose/src/lib.nr +++ /dev/null @@ -1,152 +0,0 @@ -use utils::{ - IDData, is_id_card, DisclosedData, DiscloseFlags, PASSPORT_MRZ_COUNTRY_INDEX, - PASSPORT_MRZ_LENGTH, PASSPORT_MRZ_BIRTHDATE_INDEX, PASSPORT_MRZ_NATIONALITY_INDEX, - PASSPORT_MRZ_NAME_INDEX, PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX, PASSPORT_MRZ_GENDER_INDEX, - PASSPORT_MRZ_EXPIRY_DATE_INDEX, PASSPORT_MRZ_DOCUMENT_TYPE_INDEX, ID_CARD_MRZ_COUNTRY_INDEX, - ID_CARD_MRZ_LENGTH, ID_CARD_MRZ_BIRTHDATE_INDEX, ID_CARD_MRZ_NATIONALITY_INDEX, - ID_CARD_MRZ_NAME_INDEX, ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX, ID_CARD_MRZ_GENDER_INDEX, - ID_CARD_MRZ_EXPIRY_DATE_INDEX, ID_CARD_MRZ_DOCUMENT_TYPE_INDEX, get_mrz_from_dg1, -}; - -fn get_array_slice(array: [u8; N], start: u32, end: u32) -> [u8; M] { - let mut slice = [0 as u8; M]; - for i in 0..M { - slice[i] = array[start + i]; - } - slice -} - -pub fn get_disclosed_data(dg1: [u8; 95], flags: DiscloseFlags) -> DisclosedData { - let mrz = get_mrz_from_dg1(dg1); - let mut disclosed_data = DisclosedData { - issuing_country: [0 as u8; 3], - date_of_birth: [0 as u8; 6], - nationality: [0 as u8; 3], - name: [0 as u8; 39], - document_number: [0 as u8; 9], - date_of_expiry: [0 as u8; 6], - document_type: [0 as u8; 2], - gender: [0 as u8; 1], - }; - - if is_id_card(dg1) { - if flags.issuing_country { - disclosed_data.issuing_country = get_array_slice( - mrz, - ID_CARD_MRZ_COUNTRY_INDEX, - ID_CARD_MRZ_COUNTRY_INDEX + 3, - ); - } - if flags.date_of_birth { - disclosed_data.date_of_birth = get_array_slice( - mrz, - ID_CARD_MRZ_BIRTHDATE_INDEX, - ID_CARD_MRZ_BIRTHDATE_INDEX + 6, - ); - } - if flags.nationality { - disclosed_data.nationality = get_array_slice( - mrz, - ID_CARD_MRZ_NATIONALITY_INDEX, - ID_CARD_MRZ_NATIONALITY_INDEX + 3, - ); - } - if flags.name { - disclosed_data.name = - get_array_slice(mrz, ID_CARD_MRZ_NAME_INDEX, ID_CARD_MRZ_NAME_INDEX + 30); - } - if flags.document_number { - disclosed_data.document_number = get_array_slice( - mrz, - ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX, - ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX + 9, - ); - } - if flags.date_of_expiry { - disclosed_data.date_of_expiry = get_array_slice( - mrz, - ID_CARD_MRZ_EXPIRY_DATE_INDEX, - ID_CARD_MRZ_EXPIRY_DATE_INDEX + 6, - ); - } - if flags.document_type { - disclosed_data.document_type = get_array_slice( - mrz, - ID_CARD_MRZ_DOCUMENT_TYPE_INDEX, - ID_CARD_MRZ_DOCUMENT_TYPE_INDEX + 2, - ); - } - if flags.gender { - disclosed_data.gender = get_array_slice( - mrz, - ID_CARD_MRZ_GENDER_INDEX, - ID_CARD_MRZ_GENDER_INDEX + 1, - ); - } - } else { - if flags.issuing_country { - disclosed_data.issuing_country = get_array_slice( - mrz, - PASSPORT_MRZ_COUNTRY_INDEX, - PASSPORT_MRZ_COUNTRY_INDEX + 3, - ); - } - if flags.date_of_birth { - disclosed_data.date_of_birth = get_array_slice( - mrz, - PASSPORT_MRZ_BIRTHDATE_INDEX, - PASSPORT_MRZ_BIRTHDATE_INDEX + 6, - ); - } - if flags.nationality { - disclosed_data.nationality = get_array_slice( - mrz, - PASSPORT_MRZ_NATIONALITY_INDEX, - PASSPORT_MRZ_NATIONALITY_INDEX + 3, - ); - } - if flags.name { - disclosed_data.name = - get_array_slice(mrz, PASSPORT_MRZ_NAME_INDEX, PASSPORT_MRZ_NAME_INDEX + 39); - } - if flags.document_number { - disclosed_data.document_number = get_array_slice( - mrz, - PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX, - PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX + 9, - ); - } - if flags.date_of_expiry { - disclosed_data.date_of_expiry = get_array_slice( - mrz, - PASSPORT_MRZ_EXPIRY_DATE_INDEX, - PASSPORT_MRZ_EXPIRY_DATE_INDEX + 6, - ); - } - if flags.document_type { - disclosed_data.document_type = get_array_slice( - mrz, - PASSPORT_MRZ_DOCUMENT_TYPE_INDEX, - PASSPORT_MRZ_DOCUMENT_TYPE_INDEX + 2, - ); - } - if flags.gender { - disclosed_data.gender = get_array_slice( - mrz, - PASSPORT_MRZ_GENDER_INDEX, - PASSPORT_MRZ_GENDER_INDEX + 1, - ); - } - } - - disclosed_data -} - -pub fn get_disclosed_bytes(dg1: [u8; 95], mask: [u8; 90]) -> [u8; 90] { - let mut disclosed_bytes = [0 as u8; 90]; - let mrz = get_mrz_from_dg1(dg1); - for i in 0..90 { - disclosed_bytes[i] = mask[i] * mrz[i]; - } - disclosed_bytes -} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/Nargo.toml deleted file mode 100644 index b8b85a2d7..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/Nargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "exclusion_check_country_lib" -type = "lib" -authors = ["Theo Madzou"] -compiler_version = ">=0.22.0" - -[dependencies] -utils = { path = "../../utils" } \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/src/lib.nr deleted file mode 100644 index 3eceaf2f7..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/exclusion-check/country/src/lib.nr +++ /dev/null @@ -1,75 +0,0 @@ -use utils::{get_issuing_country_from_mrz, get_nationality_from_mrz}; - -unconstrained fn get_closest_index(sorted_list: [u32; N], value: u32) -> u32 { - let mut index: u32 = 0; - for i in 0..N { - if sorted_list[i] > value { - index = i; - break; - } - } - index -} - -/// Check if the nationality from the MRZ is not in the country list -/// The list of countries is assumed to be sorted in ascending order -/// So it must come either from a public input that can be independently checked -/// or from a previous in-circuit check that the list is sorted -/// -/// # Arguments -/// -/// * `dg1` - The DG1 of the passport or ID card -/// * `country_list` - The sorted list of countries to check against, must be formatted as a list of u32 -/// which are the Alpha-3 codes of the countries with each letter ASCII code put together using a weighted sum. -/// e.g. for "FRA", the sum is 70 * 2^16 (0x10000) + 82 * 2^8 (0x100) + 65 = 4587520 + 20992 + 65 = 4608577 -pub fn check_nationality_exclusion(dg1: [u8; 95], country_list: [u32; N]) { - let nationality_bytes = get_nationality_from_mrz(dg1); - let nationality_sum: u32 = nationality_bytes[0] as u32 * 0x10000 - + nationality_bytes[1] as u32 * 0x100 - + nationality_bytes[2] as u32; - - // Safety: since the list is assumed to be sorted in ascending order, we can get the index to check against - // from an unconstrained function - let closest_index = unsafe { get_closest_index(country_list, nationality_sum) }; - // Assert that either the index is the first element of the list or the previous element is less than the nationality sum - if closest_index == 0 { - // Assert that the country at the index is greater than the nationality sum - assert(country_list[closest_index] > nationality_sum); - } - // Cannot be done in a single if statement otherwise the second check will fail if closest_index is 0 - else if country_list[closest_index - 1] < nationality_sum { - // Assert that the country at the index is greater than the nationality sum - assert(country_list[closest_index] > nationality_sum); - } else { - // Otherwise it should fail - assert(false); - } - // If those two checks pass, then the nationality is not in the country list -} - -/// Check if the issuing country from the MRZ is not in the country list -/// The list of countries is assumed to be sorted in ascending order -/// So it must come either from a public input that can be independently checked -/// or from a previous in-circuit check that the list is sorted -pub fn check_issuing_country_exclusion(dg1: [u8; 95], country_list: [u32; N]) { - let issuing_country_bytes = get_issuing_country_from_mrz(dg1); - let issuing_country_sum: u32 = issuing_country_bytes[0] as u32 * 0x10000 - + issuing_country_bytes[1] as u32 * 0x100 - + issuing_country_bytes[2] as u32; - - // Safety: since the list is assumed to be sorted in ascending order, we can get the index to check against - // from an unconstrained function - let closest_index = unsafe { get_closest_index(country_list, issuing_country_sum) }; - - if closest_index == 0 { - // Assert that the country at the index is greater than the issuing country sum - assert(country_list[closest_index] > issuing_country_sum); - } else if country_list[closest_index - 1] < issuing_country_sum { - // Assert that the country at the index is greater than the issuing country sum - assert(country_list[closest_index] > issuing_country_sum); - } else { - // Otherwise it should fail - assert(false); - } - // If those two checks pass, then the issuing country is not in the country list -} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/Nargo.toml deleted file mode 100644 index 763f3511e..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/Nargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "inclusion_check_country_lib" -type = "lib" -authors = ["Theo Madzou"] -compiler_version = ">=0.22.0" - -[dependencies] -utils = { path = "../../utils" } \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/src/lib.nr deleted file mode 100644 index a51d7da51..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/inclusion-check/country/src/lib.nr +++ /dev/null @@ -1,68 +0,0 @@ -use utils::{get_issuing_country_from_mrz, get_nationality_from_mrz}; - -unconstrained fn get_index(list: [str<3>; N], value: [u8; 3]) -> i32 { - let mut index: i32 = -1; - for i in 0..N { - let list_item = list[i].as_bytes(); - if (list_item[0] == value[0]) & (list_item[1] == value[1]) & (list_item[2] == value[2]) { - index = i as i32; - } - } - index -} - -/// Check if the nationality from the MRZ is in the country list -/// -/// # Arguments -/// -/// * `dg1`: The MRZ -/// * `country_list`: The list of countries -pub fn check_nationality_inclusion(dg1: [u8; 95], country_list: [str<3>; N]) { - let nationality_bytes = get_nationality_from_mrz(dg1); - - // Safety: get the index of the country in the list from an unconstrained function - let country_index = unsafe { get_index(country_list, nationality_bytes) }; - // Assert that the country was found - assert(country_index != -1, "Country not found in the list"); - - // Assert that the nationality is equal to the country in the list - // at the index found by the unconstrained function - let country_code = country_list[country_index].as_bytes(); - assert_eq(nationality_bytes[0], country_code[0], "Nationality does not match the country code"); - assert_eq(nationality_bytes[1], country_code[1], "Nationality does not match the country code"); - assert_eq(nationality_bytes[2], country_code[2], "Nationality does not match the country code"); -} - -/// Check if the issuing country from the MRZ is in the country list -/// -/// # Arguments -/// -/// * `dg1`: The MRZ -/// * `country_list`: The list of countries -pub fn check_issuing_country_inclusion(dg1: [u8; 95], country_list: [str<3>; N]) { - let issuing_country_bytes = get_issuing_country_from_mrz(dg1); - - // Safety: get the index of the country in the list from an unconstrained function - let country_index = unsafe { get_index(country_list, issuing_country_bytes) }; - // Assert that the country was found - assert(country_index != -1, "Country not found in the list"); - - // Assert that the issuing country is equal to the country in the list - // at the index found by the unconstrained function - let country_code = country_list[country_index].as_bytes(); - assert_eq( - issuing_country_bytes[0], - country_code[0], - "Issuing country does not match the country code", - ); - assert_eq( - issuing_country_bytes[1], - country_code[1], - "Issuing country does not match the country code", - ); - assert_eq( - issuing_country_bytes[2], - country_code[2], - "Issuing country does not match the country code", - ); -} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/Nargo.toml b/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/Nargo.toml deleted file mode 100644 index 024bc2ed7..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/Nargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "sig_check_ecdsa" -type = "lib" -authors = ["Theo Madzou", "Michael Elliot"] -compiler_version = ">=1.0.0" - -[dependencies] -utils = { path = "../../utils" } -ecdsa = { tag = "v0.2.8", git = "https://github.com/zkpassport/noir-ecdsa" } -bignum = {tag = "v0.7.3-3", git = "https://github.com/zkpassport/noir-bignum"} -bigcurve = {tag = "v0.9.0-2", git = "https://github.com/zkpassport/noir_bigcurve"} diff --git a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/src/lib.nr b/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/src/lib.nr deleted file mode 100644 index a0f3ba8f1..000000000 --- a/noir-examples/noir-passport-examples/zkpassport_libs/sig-check/ecdsa/src/lib.nr +++ /dev/null @@ -1,336 +0,0 @@ -use bignum::bignum::BigNum; -use bignum::fields::brainpoolP192r1Fq::BrainpoolP192r1_Fq; -use bignum::fields::brainpoolP192r1Fr::BrainpoolP192r1_Fr; -use bignum::fields::brainpoolP192t1Fq::BrainpoolP192t1_Fq; -use bignum::fields::brainpoolP192t1Fr::BrainpoolP192t1_Fr; -use bignum::fields::brainpoolP224r1Fq::BrainpoolP224r1_Fq; -use bignum::fields::brainpoolP224r1Fr::BrainpoolP224r1_Fr; -use bignum::fields::brainpoolP224t1Fq::BrainpoolP224t1_Fq; -use bignum::fields::brainpoolP224t1Fr::BrainpoolP224t1_Fr; -use bignum::fields::brainpoolP256r1Fq::BrainpoolP256r1_Fq; -use bignum::fields::brainpoolP256r1Fr::BrainpoolP256r1_Fr; -use bignum::fields::brainpoolP256t1Fq::BrainpoolP256t1_Fq; -use bignum::fields::brainpoolP256t1Fr::BrainpoolP256t1_Fr; -use bignum::fields::brainpoolP384r1Fq::BrainpoolP384r1_Fq; -use bignum::fields::brainpoolP384r1Fr::BrainpoolP384r1_Fr; -use bignum::fields::brainpoolP384t1Fq::BrainpoolP384t1_Fq; -use bignum::fields::brainpoolP384t1Fr::BrainpoolP384t1_Fr; -use bignum::fields::brainpoolP512r1Fq::BrainpoolP512r1_Fq; -use bignum::fields::brainpoolP512r1Fr::BrainpoolP512r1_Fr; -use bignum::fields::brainpoolP512t1Fq::BrainpoolP512t1_Fq; -use bignum::fields::brainpoolP512t1Fr::BrainpoolP512t1_Fr; -use bignum::fields::secp192r1Fq::Secp192r1_Fq; -use bignum::fields::secp192r1Fr::Secp192r1_Fr; -use bignum::fields::secp224r1Fq::Secp224r1_Fq; -use bignum::fields::secp224r1Fr::Secp224r1_Fr; -use bignum::fields::secp256r1Fq::Secp256r1_Fq; -use bignum::fields::secp256r1Fr::Secp256r1_Fr; -use bignum::fields::secp384r1Fq::Secp384r1_Fq; -use bignum::fields::secp384r1Fr::Secp384r1_Fr; -use bignum::fields::secp521r1Fq::Secp521r1_Fq; -use bignum::fields::secp521r1Fr::Secp521r1_Fr; -use ecdsa::ecdsa::{ - verify_brainpoolp192r1_ecdsa, verify_brainpoolp192t1_ecdsa, verify_brainpoolp224r1_ecdsa, - verify_brainpoolp224t1_ecdsa, verify_brainpoolp256r1_ecdsa, verify_brainpoolp256t1_ecdsa, - verify_brainpoolp384r1_ecdsa, verify_brainpoolp384t1_ecdsa, verify_brainpoolp512r1_ecdsa, - verify_brainpoolp512t1_ecdsa, verify_secp192r1_ecdsa, verify_secp224r1_ecdsa, - verify_secp256r1_ecdsa, verify_secp384r1_ecdsa, verify_secp521r1_ecdsa, -}; -use std::ecdsa_secp256r1; -use utils::concat_array; - -pub fn verify_nist_p192( - pubkey_x: [u8; 24], - pubkey_y: [u8; 24], - signature_r: [u8; 24], - signature_s: [u8; 24], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: Secp192r1_Fq = Secp192r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: Secp192r1_Fq = Secp192r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: Secp192r1_Fr = Secp192r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: Secp192r1_Fr = Secp192r1_Fr::from_be_bytes(signature_s); - verify_secp192r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_nist_p224( - pubkey_x: [u8; 28], - pubkey_y: [u8; 28], - signature_r: [u8; 28], - signature_s: [u8; 28], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: Secp224r1_Fq = Secp224r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: Secp224r1_Fq = Secp224r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: Secp224r1_Fr = Secp224r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: Secp224r1_Fr = Secp224r1_Fr::from_be_bytes(signature_s); - verify_secp224r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_nist_p256_blackbox( - pubkey_x: [u8; 32], - pubkey_y: [u8; 32], - signature_r: [u8; 32], - signature_s: [u8; 32], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let signature = concat_array(signature_r, signature_s); - ecdsa_secp256r1::verify_signature(pubkey_x, pubkey_y, signature, msg_hash) -} - -pub fn verify_nist_p256( - pubkey_x: [u8; 32], - pubkey_y: [u8; 32], - signature_r: [u8; 32], - signature_s: [u8; 32], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: Secp256r1_Fq = Secp256r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: Secp256r1_Fq = Secp256r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: Secp256r1_Fr = Secp256r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: Secp256r1_Fr = Secp256r1_Fr::from_be_bytes(signature_s); - verify_secp256r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_nist_p384( - pubkey_x: [u8; 48], - pubkey_y: [u8; 48], - signature_r: [u8; 48], - signature_s: [u8; 48], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: Secp384r1_Fq = Secp384r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: Secp384r1_Fq = Secp384r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: Secp384r1_Fr = Secp384r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: Secp384r1_Fr = Secp384r1_Fr::from_be_bytes(signature_s); - verify_secp384r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_nist_p521( - pubkey_x: [u8; 66], - pubkey_y: [u8; 66], - signature_r: [u8; 66], - signature_s: [u8; 66], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: Secp521r1_Fq = Secp521r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: Secp521r1_Fq = Secp521r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: Secp521r1_Fr = Secp521r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: Secp521r1_Fr = Secp521r1_Fr::from_be_bytes(signature_s); - verify_secp521r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_192r1( - pubkey_x: [u8; 24], - pubkey_y: [u8; 24], - signature_r: [u8; 24], - signature_s: [u8; 24], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP192r1_Fq = BrainpoolP192r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP192r1_Fq = BrainpoolP192r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP192r1_Fr = BrainpoolP192r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP192r1_Fr = BrainpoolP192r1_Fr::from_be_bytes(signature_s); - verify_brainpoolp192r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_192t1( - pubkey_x: [u8; 24], - pubkey_y: [u8; 24], - signature_r: [u8; 24], - signature_s: [u8; 24], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP192t1_Fq = BrainpoolP192t1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP192t1_Fq = BrainpoolP192t1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP192t1_Fr = BrainpoolP192t1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP192t1_Fr = BrainpoolP192t1_Fr::from_be_bytes(signature_s); - verify_brainpoolp192t1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_224r1( - pubkey_x: [u8; 28], - pubkey_y: [u8; 28], - signature_r: [u8; 28], - signature_s: [u8; 28], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP224r1_Fq = BrainpoolP224r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP224r1_Fq = BrainpoolP224r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP224r1_Fr = BrainpoolP224r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP224r1_Fr = BrainpoolP224r1_Fr::from_be_bytes(signature_s); - verify_brainpoolp224r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_224t1( - pubkey_x: [u8; 28], - pubkey_y: [u8; 28], - signature_r: [u8; 28], - signature_s: [u8; 28], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP224t1_Fq = BrainpoolP224t1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP224t1_Fq = BrainpoolP224t1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP224t1_Fr = BrainpoolP224t1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP224t1_Fr = BrainpoolP224t1_Fr::from_be_bytes(signature_s); - verify_brainpoolp224t1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_256r1( - pubkey_x: [u8; 32], - pubkey_y: [u8; 32], - signature_r: [u8; 32], - signature_s: [u8; 32], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP256r1_Fq = BrainpoolP256r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP256r1_Fq = BrainpoolP256r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP256r1_Fr = BrainpoolP256r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP256r1_Fr = BrainpoolP256r1_Fr::from_be_bytes(signature_s); - verify_brainpoolp256r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_256t1( - pubkey_x: [u8; 32], - pubkey_y: [u8; 32], - signature_r: [u8; 32], - signature_s: [u8; 32], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP256t1_Fq = BrainpoolP256t1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP256t1_Fq = BrainpoolP256t1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP256t1_Fr = BrainpoolP256t1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP256t1_Fr = BrainpoolP256t1_Fr::from_be_bytes(signature_s); - verify_brainpoolp256t1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_384r1( - pubkey_x: [u8; 48], - pubkey_y: [u8; 48], - signature_r: [u8; 48], - signature_s: [u8; 48], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP384r1_Fq = BrainpoolP384r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP384r1_Fq = BrainpoolP384r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP384r1_Fr = BrainpoolP384r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP384r1_Fr = BrainpoolP384r1_Fr::from_be_bytes(signature_s); - verify_brainpoolp384r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_384t1( - pubkey_x: [u8; 48], - pubkey_y: [u8; 48], - signature_r: [u8; 48], - signature_s: [u8; 48], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP384t1_Fq = BrainpoolP384t1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP384t1_Fq = BrainpoolP384t1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP384t1_Fr = BrainpoolP384t1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP384t1_Fr = BrainpoolP384t1_Fr::from_be_bytes(signature_s); - verify_brainpoolp384t1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_512r1( - pubkey_x: [u8; 64], - pubkey_y: [u8; 64], - signature_r: [u8; 64], - signature_s: [u8; 64], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP512r1_Fq = BrainpoolP512r1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP512r1_Fq = BrainpoolP512r1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP512r1_Fr = BrainpoolP512r1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP512r1_Fr = BrainpoolP512r1_Fr::from_be_bytes(signature_s); - verify_brainpoolp512r1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} - -pub fn verify_brainpool_512t1( - pubkey_x: [u8; 64], - pubkey_y: [u8; 64], - signature_r: [u8; 64], - signature_s: [u8; 64], - msg_hash: [u8; HASH_BYTE_SIZE], -) -> bool { - let pubkey_x_bignum: BrainpoolP512t1_Fq = BrainpoolP512t1_Fq::from_be_bytes(pubkey_x); - let pubkey_y_bignum: BrainpoolP512t1_Fq = BrainpoolP512t1_Fq::from_be_bytes(pubkey_y); - let signature_r_bignum: BrainpoolP512t1_Fr = BrainpoolP512t1_Fr::from_be_bytes(signature_r); - let signature_s_bignum: BrainpoolP512t1_Fr = BrainpoolP512t1_Fr::from_be_bytes(signature_s); - verify_brainpoolp512t1_ecdsa( - pubkey_x_bignum, - pubkey_y_bignum, - msg_hash, - (signature_r_bignum, signature_s_bignum), - ) -} From 65fc3d5906aebe73e5e653963066091b72918605 Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 00:51:32 +0530 Subject: [PATCH 02/15] full migrate --- .../merkle_age_check/t_add_dsc_720/Nargo.toml | 6 +- .../t_add_dsc_hash_1300/Nargo.toml | 2 +- .../t_add_dsc_verify_1300/Nargo.toml | 9 +- .../t_add_dsc_verify_1300/src/main.nr | 2 +- .../t_add_id_data_1300/Nargo.toml | 8 +- .../t_add_id_data_720/Nargo.toml | 8 +- .../t_add_integrity_commit/Nargo.toml | 6 +- .../merkle_age_check/t_attest/Nargo.toml | 10 +- .../merkle_age_check/t_attest/src/main.nr | 4 +- .../utils}/commitment/common/Nargo.toml | 2 +- .../utils/commitment/common/src/lib.nr | 247 ++++++ .../utils/commitment/dsc-to-id/Nargo.toml | 2 +- .../commitment/scoped-nullifier/Nargo.toml | 3 +- .../commitment/scoped-nullifier/src/lib.nr | 82 +- .../utils}/data-check/integrity/Nargo.toml | 4 +- .../utils/data-check/integrity/src/lib.nr | 45 ++ .../fragmented/utils/sig-check/rsa/Nargo.toml | 9 + .../fragmented/utils/sig-check/rsa/src/lib.nr | 29 + .../monolithic/complete_age_check/Nargo.toml | 6 +- .../utils/commitment/csc-to-dsc/Nargo.toml | 9 - .../utils/commitment/csc-to-dsc/src/lib.nr | 52 -- .../utils/passport_validity_check/Nargo.toml | 11 +- .../shared-utils/commitment/common/src/lib.nr | 522 ------------ .../data-check/integrity/src/lib.nr | 206 ----- .../data-check/tbs-pubkey/src/lib.nr | 34 - .../shared-utils/utils/src/lib.nr | 747 ------------------ .../compare/age/Nargo.toml | 3 - .../compare/age/src/lib.nr | 60 +- .../data-check/expiry/Nargo.toml | 0 .../data-check/expiry/src/lib.nr | 0 .../data-check/tbs-pubkey/Nargo.toml | 0 .../utils/data-check/tbs-pubkey/src/lib.nr | 13 + .../sig-check/common/Nargo.toml | 0 .../sig-check/common/src/lib.nr | 0 .../sig-check/rsa/Nargo.toml | 0 .../sig-check/rsa/src/lib.nr | 26 - .../{shared-utils => utils}/utils/Nargo.toml | 0 .../utils/src/constants.nr | 5 - .../utils/utils/src/lib.nr | 227 ++++++ .../utils/src/tests.nr | 214 +---- .../utils/src/types.nr | 13 +- noir-examples/partial_sha256/Nargo.toml | 2 +- 42 files changed, 613 insertions(+), 2015 deletions(-) rename noir-examples/noir-passport-examples/{shared-utils => fragmented/utils}/commitment/common/Nargo.toml (81%) create mode 100644 noir-examples/noir-passport-examples/fragmented/utils/commitment/common/src/lib.nr rename noir-examples/noir-passport-examples/{shared-utils => fragmented/utils}/data-check/integrity/Nargo.toml (54%) create mode 100644 noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/src/lib.nr create mode 100644 noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/Nargo.toml create mode 100644 noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/Nargo.toml delete mode 100644 noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/shared-utils/commitment/common/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/shared-utils/data-check/integrity/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/src/lib.nr delete mode 100644 noir-examples/noir-passport-examples/shared-utils/utils/src/lib.nr rename noir-examples/noir-passport-examples/{shared-utils => utils}/compare/age/Nargo.toml (53%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/compare/age/src/lib.nr (58%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/data-check/expiry/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/data-check/expiry/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/data-check/tbs-pubkey/Nargo.toml (100%) create mode 100644 noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/src/lib.nr rename noir-examples/noir-passport-examples/{shared-utils => utils}/sig-check/common/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/sig-check/common/src/lib.nr (100%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/sig-check/rsa/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/sig-check/rsa/src/lib.nr (75%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/utils/Nargo.toml (100%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/utils/src/constants.nr (54%) create mode 100644 noir-examples/noir-passport-examples/utils/utils/src/lib.nr rename noir-examples/noir-passport-examples/{shared-utils => utils}/utils/src/tests.nr (55%) rename noir-examples/noir-passport-examples/{shared-utils => utils}/utils/src/types.nr (92%) diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml index 885d3b3de..27a26e4f8 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml @@ -4,7 +4,7 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -sig_check_rsa = { path = "../../zkpassport_libs/sig-check/rsa" } -utils = { path = "../../zkpassport_libs/utils" } -commitment = { path = "../../zkpassport_libs/commitment/common" } +sig_check_rsa = { path = "../../../utils/sig-check/rsa" } +utils = { path = "../../../utils/utils" } +commitment = { path = "../../utils/commitment/common" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml index 67321b8fb..baa071e67 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml @@ -4,4 +4,4 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -partial_sha256 = { path = "../../../partial_sha256" } +partial_sha256 = { path = "../../../../partial_sha256" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml index 1e4e17ffb..a459a092f 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml @@ -4,8 +4,9 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -partial_sha256 = { path = "../../../partial_sha256" } -sig_check_rsa = { path = "../../zkpassport_libs/sig-check/rsa" } -utils = { path = "../../zkpassport_libs/utils" } -commitment = { path = "../../zkpassport_libs/commitment/common" } +partial_sha256 = { path = "../../../../partial_sha256" } +sig_check_rsa = { path = "../../../utils/sig-check/rsa" } +fragmented_sig_check_rsa = { path = "../../utils/sig-check/rsa" } +utils = { path = "../../../utils/utils" } +commitment = { path = "../../utils/commitment/common" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr index 463dcdc12..6f2eca888 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr @@ -2,7 +2,7 @@ use commitment::hash_salt_country_tbs; use partial_sha256::{ SHA256State, sha256_continue, sha256_finalize, verify_sha256_state_and_data_commitment, commit_to_data_chunk, }; -use sig_check_rsa::verify_rsa_signature; +use fragmented_sig_check_rsa::verify_rsa_signature; use utils::types::{Alpha3CountryCode, SHA256Digest}; global CHUNK1_SIZE: u32 = 640; diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml index 37d0a50be..cdc2f9b24 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml @@ -4,7 +4,7 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -sig_check_rsa = { path = "../../zkpassport_libs/sig-check/rsa" } -utils = { path = "../../zkpassport_libs/utils" } -data_check_tbs_pubkey = { path = "../../zkpassport_libs/data-check/tbs-pubkey" } -commitment = { path = "../../zkpassport_libs/commitment/dsc-to-id" } +sig_check_rsa = { path = "../../../utils/sig-check/rsa" } +utils = { path = "../../../utils/utils" } +data_check_tbs_pubkey = { path = "../../../utils/data-check/tbs-pubkey" } +commitment = { path = "../../utils/commitment/dsc-to-id" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml index f4130e5b3..b34b902c6 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml @@ -4,7 +4,7 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -sig_check_rsa = { path = "../../zkpassport_libs/sig-check/rsa" } -utils = { path = "../../zkpassport_libs/utils" } -data_check_tbs_pubkey = { path = "../../zkpassport_libs/data-check/tbs-pubkey" } -commitment = { path = "../../zkpassport_libs/commitment/dsc-to-id" } +sig_check_rsa = { path = "../../../utils/sig-check/rsa" } +utils = { path = "../../../utils/utils" } +data_check_tbs_pubkey = { path = "../../../utils/data-check/tbs-pubkey" } +commitment = { path = "../../utils/commitment/dsc-to-id" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml index f10e16bf5..eed10146f 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml @@ -4,7 +4,7 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -data_check_integrity = { path = "../../zkpassport_libs/data-check/integrity" } -common = { path = "../../zkpassport_libs/commitment/common" } -utils = { path = "../../zkpassport_libs/utils" } +data_check_integrity = { path = "../../utils/data-check/integrity" } +common = { path = "../../utils/commitment/common" } +utils = { path = "../../../utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml index 62da7e184..d944dae79 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml @@ -4,9 +4,9 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -common = { path = "../../zkpassport_libs/commitment/common" } -compare_age_lib = { path = "../../zkpassport_libs/compare/age" } -data_check_expiry = { path = "../../zkpassport_libs/data-check/expiry" } -scoped_nullifier = { path = "../../zkpassport_libs/commitment/scoped-nullifier" } -utils = { path = "../../zkpassport_libs/utils" } +common = { path = "../../utils/commitment/common" } +compare_age_lib = { path = "../../../utils/compare/age" } +data_check_expiry = { path = "../../../utils/data-check/expiry" } +scoped_nullifier = { path = "../../utils/commitment/scoped-nullifier" } +utils = { path = "../../../utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr index 1303d1136..5ea03790b 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr @@ -1,5 +1,5 @@ -use common::compute_merkle_root; -use compare_age_lib::{calculate_param_commitment, compare_age}; +use common::{calculate_param_commitment, compute_merkle_root}; +use compare_age_lib::compare_age; use data_check_expiry::check_expiry; use poseidon::poseidon2::Poseidon2; use scoped_nullifier::compute_nullifier_and_type; diff --git a/noir-examples/noir-passport-examples/shared-utils/commitment/common/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/Nargo.toml similarity index 81% rename from noir-examples/noir-passport-examples/shared-utils/commitment/common/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/utils/commitment/common/Nargo.toml index c99126dc9..5c7f3591f 100644 --- a/noir-examples/noir-passport-examples/shared-utils/commitment/common/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/Nargo.toml @@ -5,5 +5,5 @@ authors = ["Theo Madzou"] compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../../utils" } +utils = { path = "../../../../utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/src/lib.nr b/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/src/lib.nr new file mode 100644 index 000000000..fb5b40868 --- /dev/null +++ b/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/src/lib.nr @@ -0,0 +1,247 @@ +use poseidon::poseidon2::Poseidon2; +use utils::{pack_be_bytes_into_fields, PASSPORT_MRZ_COUNTRY_INDEX, PROOF_TYPE_AGE}; + +pub fn calculate_scoped_nullifier( + salted_private_nullifier: utils::types::SaltedValue, + service_scope: Field, + service_subscope: Field, + nullifier_secret: Field, +) -> Field { + if salted_private_nullifier.value == 0 { + // If the private nullifier value is 0, it means it is hidden behind its salted hash + // inside the circuit, so we just return 0 making this proof not usable to derive + // the scoped nullifier + 0 + } + // A nullifier secret set to 0 means it should be ignored and the nullifier should be computed without it + // Otherwise, the nullifier should be computed with the secret + else if nullifier_secret != 0 { + Poseidon2::hash( + [salted_private_nullifier.value, service_scope, service_subscope, nullifier_secret], + 4, + ) + } else { + Poseidon2::hash( + [salted_private_nullifier.value, service_scope, service_subscope], + 3, + ) + } +} + +pub fn get_country_from_dg1(dg1: [u8; 95]) -> str<3> { + // There 5 padding bytes in the dg1 before the actual MRZ + let country_offset = 5 + PASSPORT_MRZ_COUNTRY_INDEX; + let mut country_bytes: [u8; 3] = [0; 3]; + for i in 0..3 { + country_bytes[i] = dg1[country_offset + i]; + } + let mut country = country_bytes.as_str_unchecked(); + // A special case for Germany + if (country == "D<<") { + country = "DEU"; + } + country +} + +pub fn hash_salt_country_tbs( + salt: Field, + country: str<3>, + tbs: [u8; TBS_MAX_SIZE], +) -> Field { + let country_bytes: [u8; 3] = country.as_bytes(); + let mut result: [Field; 2 + ((TBS_MAX_SIZE + 30) / 31)] = [0; 2 + ((TBS_MAX_SIZE + 30) / 31)]; + result[0] = salt; + + let packed_country: Field = pack_be_bytes_into_fields::<3, 1, 31>(country_bytes)[0]; + result[1] = packed_country; + + let packed_tbs: [Field; (TBS_MAX_SIZE + 30) / 31] = + pack_be_bytes_into_fields::(tbs); + for i in 0..((TBS_MAX_SIZE + 30) / 31) { + result[2 + i] = packed_tbs[i]; + } + + Poseidon2::hash(result, 2 + ((TBS_MAX_SIZE + 30) / 31)) +} + +pub fn hash_salt_dg1_private_nullifier( + salted_dg1: utils::types::SaltedValue<[u8; 95]>, + salted_expiry_date: utils::types::SaltedValue, + salted_private_nullifier: utils::types::SaltedValue, +) -> Field { + let mut hash_inputs: [Field; 3] = std::mem::zeroed(); + + hash_inputs[0] = salted_dg1.get_hash(); + hash_inputs[1] = salted_expiry_date.get_hash(); + hash_inputs[2] = salted_private_nullifier.get_hash(); + + Poseidon2::hash(hash_inputs, 3) +} + +pub fn calculate_private_nullifier( + dg1: [u8; DG1], + e_content: [u8; ECONTENT], + sod_sig: [u8; SIG], +) -> Field { + let mut result: [Field; (DG1 + 30) / 31 + (ECONTENT + 30) / 31 + (SIG + 30) / 31] = + [0; (DG1 + 30) / 31 + (ECONTENT + 30) / 31 + (SIG + 30) / 31]; + + let packed_dg1: [Field; (DG1 + 30) / 31] = pack_be_bytes_into_fields::(dg1); + for i in 0..((DG1 + 30) / 31) { + result[i] = packed_dg1[i]; + } + + let packed_e_content: [Field; (ECONTENT + 30) / 31] = + pack_be_bytes_into_fields::(e_content); + for i in 0..((ECONTENT + 30) / 31) { + result[(DG1 + 30) / 31 + i] = packed_e_content[i]; + } + + let packed_sod_sig: [Field; (SIG + 30) / 31] = pack_be_bytes_into_fields::(sod_sig); + for i in 0..((SIG + 30) / 31) { + result[(DG1 + 30) / 31 + ((ECONTENT + 30) / 31) + i] = packed_sod_sig[i]; + } + + Poseidon2::hash( + result, + (DG1 + 30) / 31 + ((ECONTENT + 30) / 31) + (SIG + 30) / 31, + ) +} + +pub fn calculate_sod_hash( + e_content: [u8; ECONTENT_SIZE], +) -> Field { + let packed: [Field; (ECONTENT_SIZE + 30) / 31] = + pack_be_bytes_into_fields::(e_content); + Poseidon2::hash(packed, (ECONTENT_SIZE + 30) / 31) +} + +pub fn hash_salt_country_signed_attr_dg1_e_content_private_nullifier( + salt: Field, + country: str<3>, + signed_attr: [u8; SA], + signed_attr_size: Field, + dg1: [u8; DG1], + e_content: [u8; ECONTENT], + private_nullifier: Field, +) -> Field { + let country_bytes: [u8; 3] = country.as_bytes(); + + let mut result: [Field; 4 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31)] = + [0; 4 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31)]; + result[0] = salt; + + let packed_country: Field = pack_be_bytes_into_fields::<3, 1, 31>(country_bytes)[0]; + result[1] = packed_country; + + let packed_signed_attr: [Field; (SA + 30) / 31] = + pack_be_bytes_into_fields::(signed_attr); + for i in 0..((SA + 30) / 31) { + result[2 + i] = packed_signed_attr[i]; + } + + result[2 + (SA + 30) / 31] = signed_attr_size; + + let packed_dg1: [Field; (DG1 + 30) / 31] = pack_be_bytes_into_fields::(dg1); + for i in 0..((DG1 + 30) / 31) { + result[3 + (SA + 30) / 31 + i] = packed_dg1[i]; + } + + let packed_e_content: [Field; (ECONTENT + 30) / 31] = + pack_be_bytes_into_fields::(e_content); + for i in 0..((ECONTENT + 30) / 31) { + result[3 + (SA + 30) / 31 + ((DG1 + 30) / 31) + i] = packed_e_content[i]; + } + result[3 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31)] = private_nullifier; + + Poseidon2::hash( + result, + 4 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31), + ) +} + +/// Calculate the commitment of the current date, min age and max age using Poseidon2 +pub fn calculate_param_commitment( + timestamp: u64, + min_age_required: u8, + max_age_required: u8, +) -> Field { + let mut params = [0 as Field; 4]; + params[0] = PROOF_TYPE_AGE as Field; + params[1] = timestamp as Field; + params[2] = min_age_required as Field; + params[3] = max_age_required as Field; + Poseidon2::hash(params, 4) +} + +// Returns the merkle root of the tree from the provided leaf, index and hash_path, using the Poseidon2 hash function +// Arity is expected to be 2 and the the tree depth is equal to the hash_path array length +pub fn compute_merkle_root(leaf: Field, index: Field, hash_path: [Field; N]) -> Field { + let index_bits: [u1; N] = index.to_le_bits(); + let mut current = leaf; + for i in 0..N { + let path_bit = index_bits[i] == 1; + let (hash_left, hash_right) = if path_bit { + (hash_path[i], current) + } else { + (current, hash_path[i]) + }; + current = Poseidon2::hash([hash_left, hash_right], 2); + } + current +} + +#[test] +fn test_compute_merkle_root1() { + let leaf = 0x2fe190f39de3fcf4cbc2eb334d0dc76e4d06f2350aa6056c91ff5f11ded9fb4a; + let index = 0; + let hash_path = [ + 0x00, + 0x0b63a53787021a4a962a452c2921b3663aff1ffd8d5510540f8e659e782956f1, + 0x0e34ac2c09f45a503d2908bcb12f1cbae5fa4065759c88d501c097506a8b2290, + 0x21f9172d72fdcdafc312eee05cf5092980dda821da5b760a9fb8dbdf607c8a20, + 0x2373ea368857ec7af97e7b470d705848e2bf93ed7bef142a490f2119bcf82d8e, + 0x120157cfaaa49ce3da30f8b47879114977c24b266d58b0ac18b325d878aafddf, + 0x01c28fe1059ae0237b72334700697bdf465e03df03986fe05200cadeda66bd76, + 0x2d78ed82f93b61ba718b17c2dfe5b52375b4d37cbbed6f1fc98b47614b0cf21b, + 0x067243231eddf4222f3911defbba7705aff06ed45960b27f6f91319196ef97e1, + 0x1849b85f3c693693e732dfc4577217acc18295193bede09ce8b97ad910310972, + 0x2a775ea761d20435b31fa2c33ff07663e24542ffb9e7b293dfce3042eb104686, + 0x0f320b0703439a8114f81593de99cd0b8f3b9bf854601abb5b2ea0e8a3dda4a7, + 0x0d07f6e7a8a0e9199d6d92801fff867002ff5b4808962f9da2ba5ce1bdd26a73, + 0x1c4954081e324939350febc2b918a293ebcdaead01be95ec02fcbe8d2c1635d1, + ]; + let root = compute_merkle_root(leaf, index, hash_path); + assert(root == 0x0742857aba0058b2167c4ac94fede8ec480600911aa871153b988c3f71095449); +} + +#[test] +fn test_compute_merkle_root2() { + let e00 = Poseidon2::hash([1], 1); + let e01 = Poseidon2::hash([1], 1); + let e02 = Poseidon2::hash([1], 1); + let e03 = Poseidon2::hash([1], 1); + assert(e00 == 0x168758332d5b3e2d13be8048c8011b454590e06c44bce7f702f09103eef5a373); + + let e10 = Poseidon2::hash([e00, e01], 2); + let e11 = Poseidon2::hash([e02, e03], 2); + assert(e10 == 0x113d8ff59c2e15d711241797c380264e39dc1b9e00f2713e707d8d7773b6d912); + + let expected_root = Poseidon2::hash([e10, e11], 2); + assert(expected_root == 0x0f4f16b234c1d5054b15d408282cb45ba6c10a629fe068e7f3cc253ceae4f08d); + + let hash_path = [e01, e10]; + assert( + hash_path + == [ + 0x168758332d5b3e2d13be8048c8011b454590e06c44bce7f702f09103eef5a373, + 0x113d8ff59c2e15d711241797c380264e39dc1b9e00f2713e707d8d7773b6d912, + ], + ); + + let leaf = Poseidon2::hash([1], 1); + let index = 0; + let root = compute_merkle_root(leaf, index, hash_path); + assert(root == 0x0f4f16b234c1d5054b15d408282cb45ba6c10a629fe068e7f3cc253ceae4f08d); +} + diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml index 52fdcc441..158fe3cbd 100644 --- a/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml @@ -5,6 +5,6 @@ authors = ["Theo Madzou", "Michael Elliot"] compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../../utils" } +utils = { path = "../../../../utils/utils" } common = { path = "../common" } diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml index 694505c97..1e7a99feb 100644 --- a/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml @@ -5,6 +5,5 @@ authors = ["Theo Madzou", "Michael Elliot"] compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../../utils" } -common = { path = "../common" } +utils = { path = "../../../../utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr b/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr index 11fe6d80e..5e285d71b 100644 --- a/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr +++ b/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr @@ -1,95 +1,15 @@ -use common::{hash_salt_dg1_private_nullifier, calculate_scoped_nullifier}; use poseidon::poseidon2::Poseidon2; use utils::{ constants::{ NON_SALTED_MOCK_NULLIFIER, NON_SALTED_NULLIFIER, SALTED_MOCK_NULLIFIER, SALTED_NULLIFIER, }, get_issuing_country_from_mrz, - types::{DG1Data, MRZExpiryDate, SaltedValue}, + types::DG1Data, }; // The ZKR (or Zero Knowledge Republic) is a mock country used for testing purposes global ZKR_COUNTRY_CODE_BYTES: [u8; 3] = [90, 75, 82]; -/* -############################################################ -# Circuit D -############################################################ -# Generates a scoped nullifier that is scoped by service -# Allows selective disclosure of dg1 via a reveal bitmask -############################################################ - -# Inputs/Outputs -############################################################ -comm_in `assert comm_in == H(salt, dg1, private_nullifier)` -salt -dg1 -private_nullifier -service_scope `H()` -service_subscope `H()` (Service-specific subscope) -scoped_nullifier `H(private_nullifier, service_scope, service_subscope)` - -# Checks -############################################################ -- Checks that dg1_reveal is the correct reveal of dg1 for the given dg1_mask -- Constrains scoped_nullifier to be `H(private_nullifier, service_scope, service_subscope)` -*/ -pub fn nullify( - comm_in: Field, - salted_dg1: SaltedValue, - salted_expiry_date: SaltedValue, - salted_private_nullifier: SaltedValue, - service_scope: Field, - service_subscope: Field, - nullifier_secret: Field, -) -> (Field, Field) { - assert( - comm_in - == hash_salt_dg1_private_nullifier( - salted_dg1, - salted_expiry_date, - salted_private_nullifier, - ), - "Commitment from 3rd subproof doesn't match in disclosure proof", - ); - let mut scoped_nullifier = calculate_scoped_nullifier( - salted_private_nullifier, - service_scope, - service_subscope, - nullifier_secret, - ); - // Determine the nullifier type based on the secret - let mut nullifier_type = if nullifier_secret != 0 { - // Set the nullifier type to the salted nullifier type - // as the secret was used to salt the nullifier - SALTED_NULLIFIER - } else { - // Set the nullifier type to the non-salted nullifier type - // as the secret was not used to salt the nullifier - NON_SALTED_NULLIFIER - }; - let issuing_country = get_issuing_country_from_mrz(salted_dg1.value); - // Doesn't matter if we already calculated the scoped nullifier above - // cause it's ZK all branches will be evaluated anyway - if issuing_country == ZKR_COUNTRY_CODE_BYTES { - // Set the nullifier type to one of the mock nullifier types - // to indicate the issuing country is not a real one - // and prevent the use of these proofs in production - // Note: ZKPassport's registries on mainnet blockchains will not include - // the ZKR certificates but still this distinction can be useful for testnets/devnets - if nullifier_secret != 0 { - // Set the nullifier type to the salted mock nullifier type - // as the secret was used to salt the nullifier - nullifier_type = SALTED_MOCK_NULLIFIER; - } else { - // Set the nullifier type to the non-salted mock nullifier type - // as the secret was not used to salt the nullifier - nullifier_type = NON_SALTED_MOCK_NULLIFIER; - } - } - (scoped_nullifier, nullifier_type) -} - /* ############################################################ # compute_nullifier_and_type diff --git a/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/Nargo.toml similarity index 54% rename from noir-examples/noir-passport-examples/shared-utils/data-check/integrity/Nargo.toml rename to noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/Nargo.toml index 352d50651..a7ed10cbc 100644 --- a/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/Nargo.toml +++ b/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/Nargo.toml @@ -5,7 +5,5 @@ authors = ["Theo Madzou"] compiler_version = ">=0.22.0" [dependencies] -utils = { path = "../../utils" } -# noir_native_sha256 = { path = "../../../noir_native_sha256" } +utils = { path = "../../../../utils/utils" } sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } -sha512 = { tag = "master", git = "https://github.com/noir-lang/sha512" } diff --git a/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/src/lib.nr b/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/src/lib.nr new file mode 100644 index 000000000..5e13f7b90 --- /dev/null +++ b/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/src/lib.nr @@ -0,0 +1,45 @@ +use sha256::sha256_var; +use utils::{ + check_zero_padding, + is_subarray_in_array, + types::EContentData, +}; + +pub fn check_dg1_hash_within_sod( + dg1: [u8; 95], + dg1_padded_length: u64, + econtent: [u8; 200], + econtent_len: u32, + dg1_hash_offset: u32, +) { + // Check zero padding for econtent + check_zero_padding(econtent, econtent_len); + + // Bounds check: ensure dg1_hash_offset + 32 doesn't exceed econtent_len + assert(dg1_hash_offset + 32 <= econtent_len, "dg1_hash_offset out of bounds"); + + let dg1_hash = sha256_var(dg1, dg1_padded_length); + + // The DG1 hash is located at the start of the SOD + // (offset is always 0 for DG1) + for i in 0..32 { + assert(dg1_hash[i] == econtent[dg1_hash_offset + i]); + } +} +/** +* Computes the hash (using SHA2-256) of eContent (containing the hashes of the data groups) and checks it is the same as the one +* included in the signed_attributes, which is the message signed by the Document Signing Certificate (DSC) +*/ +pub fn check_signed_attributes_sha256( + signed_attributes: [u8; SA_SIZE], + e_content: EContentData, + e_content_size: u32, +) { + let computed_final_hash = sha256_var(e_content, e_content_size as u64); + + // Check that the computed final hash is in the signed attributes + assert( + is_subarray_in_array(computed_final_hash, signed_attributes), + "Computed final hash not found in signed attributes", + ); +} diff --git a/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/Nargo.toml new file mode 100644 index 000000000..abafd4773 --- /dev/null +++ b/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/Nargo.toml @@ -0,0 +1,9 @@ +[package] +name = "fragmented_sig_check_rsa" +type = "lib" +compiler_version = ">=1.0.0" + +[dependencies] +rsa = { git = "https://github.com/zkpassport/noir_rsa", tag = "v0.9.2" } +bignum = { git = "https://github.com/noir-lang/noir-bignum", tag = "v0.8.0" } +utils = { path = "../../../../utils/utils" } diff --git a/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/src/lib.nr new file mode 100644 index 000000000..11a290bfc --- /dev/null +++ b/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/src/lib.nr @@ -0,0 +1,29 @@ +use bignum::{params::BigNumParams, RuntimeBigNum}; +use rsa::rsa::verify_sha256_pkcs1v15; + +// Part 2 RSA verification - takes pre-computed hash (used in fragmented circuits) +// Note: This function only supports SHA-256 with PKCS#1 v1.5 padding +pub fn verify_rsa_signature( + pubkey_bytes: [u8; SIG_BYTES], + sig_bytes: [u8; (((SIG_BYTES * 8) + 7) / 8)], + redc_param_bytes: [u8; SIG_BYTES + 1], + exponent: u32, + msg_hash: [u8; 32] // Pre-computed SHA256 hash +) -> bool { + assert( + (SIG_BYTES == 768) + | (SIG_BYTES == 512) + | (SIG_BYTES == 384) + | (SIG_BYTES == 256) + | (SIG_BYTES == 128), + "Only modulus of bit size 1024, 2048, 3072, 4096 and 6144 are supported", + ); + + let pubkey = + utils::pack_be_bytes_into_u128s::(pubkey_bytes); + let redc_param = utils::pack_be_bytes_into_u128s::(redc_param_bytes); + let params = BigNumParams::new(false, pubkey, redc_param); + + let signature = RuntimeBigNum::from_be_bytes(params, sig_bytes); + verify_sha256_pkcs1v15::<_, SIG_BYTES * 8>(msg_hash, signature, exponent) +} diff --git a/noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml b/noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml index 613bb8d17..a71792971 100644 --- a/noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml +++ b/noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml @@ -4,6 +4,6 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -compare_age = { path = "../zkpassport_libs/compare/age" } -data_check_expiry = { path = "../zkpassport_libs/data-check/expiry" } -passport_validity_check = { path = "../passport_validity_check" } +compare_age = { path = "../../utils/compare/age" } +data_check_expiry = { path = "../../utils/data-check/expiry" } +passport_validity_check = { path = "../utils/passport_validity_check" } diff --git a/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/Nargo.toml b/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/Nargo.toml deleted file mode 100644 index ce608c7b6..000000000 --- a/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/Nargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "csc_to_dsc_commitment" -type = "lib" -authors = ["Theo Madzou"] -compiler_version = ">=1.0.0" - -[dependencies] -utils = { path = "../../utils" } -common = { path = "../common" } diff --git a/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/src/lib.nr b/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/src/lib.nr deleted file mode 100644 index 10e21375b..000000000 --- a/noir-examples/noir-passport-examples/monolithic/utils/commitment/csc-to-dsc/src/lib.nr +++ /dev/null @@ -1,52 +0,0 @@ -use common::{ - calculate_certificate_registry_leaf, compute_merkle_root, CSC_CERT_TYPE, hash_salt_country_tbs, -}; - -/* -############################################################ -# Circuit A -############################################################ -# Verifies the CSC signed the DSC -############################################################ - -# Inputs/Outputs -############################################################ -certificate_registry_root (public) -certificate_registry -salt -country -csc_pubkey -dsc_pubkey -dsc_data -comm_out `H(salt, country, dsc_pubkey)` - -# Checks -############################################################ -- Check that leaf `H(registry_id, cert_type, country, csc_pubkey)` exists in tree with root certificate_registry_root -- Check that dsc_pubkey exists in dsc_tbs at offset dsc_tbs_pubkey_offset -- Check that dsc_sig is the signature of csc_pubkey over dsc_tbs -*/ - -pub fn commit_to_dsc( - certificate_registry_root: Field, - certificate_registry_index: Field, - certificate_registry_hash_path: [Field; HASH_PATH_SIZE], - certificate_tags: [Field; 3], - country: str<3>, - tbs_certificate: [u8; TBS_CERT_SIZE], - salt: Field, - csc_pubkey: [u8; CSC_KEY_SIZE], -) -> Field { - // Verify csc_pubkey exists in certificate registry - let leaf: Field = - calculate_certificate_registry_leaf(certificate_tags, CSC_CERT_TYPE, country, csc_pubkey); - let root = compute_merkle_root( - leaf, - certificate_registry_index, - certificate_registry_hash_path, - ); - assert(root == certificate_registry_root, "Certificate registry root mismatch"); - // Output commitment glue - let comm_out = hash_salt_country_tbs(salt, country, tbs_certificate); - comm_out -} diff --git a/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml b/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml index 2440d4700..448ded780 100644 --- a/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml +++ b/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml @@ -4,12 +4,7 @@ type = "lib" compiler_version = ">=1.0.0" [dependencies] -compare_age = { path = "../zkpassport_libs/compare/age" } -data_check_integrity = { path = "../zkpassport_libs/data-check/integrity" } -data_check_expiry = { path = "../zkpassport_libs/data-check/expiry" } -sig_check_rsa = { path = "../zkpassport_libs/sig-check/rsa" } -utils = { path = "../zkpassport_libs/utils" } -commitment = { path = "../zkpassport_libs/commitment/csc-to-dsc" } -data_check_tbs_pubkey = { path = "../zkpassport_libs/data-check/tbs-pubkey" } -# noir_native_sha256 = { path = "../noir_native_sha256" } +sig_check_rsa = { path = "../../../utils/sig-check/rsa" } +utils = { path = "../../../utils/utils" } +data_check_tbs_pubkey = { path = "../../../utils/data-check/tbs-pubkey" } sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } diff --git a/noir-examples/noir-passport-examples/shared-utils/commitment/common/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/commitment/common/src/lib.nr deleted file mode 100644 index abf5c8e0c..000000000 --- a/noir-examples/noir-passport-examples/shared-utils/commitment/common/src/lib.nr +++ /dev/null @@ -1,522 +0,0 @@ -use poseidon::poseidon2::Poseidon2; -use utils::{pack_be_bytes_into_fields, PASSPORT_MRZ_COUNTRY_INDEX}; - -pub global CSC_CERT_TYPE: u8 = 1; -pub global DSC_CERT_TYPE: u8 = 2; - -pub fn calculate_scoped_nullifier( - salted_private_nullifier: utils::types::SaltedValue, - service_scope: Field, - service_subscope: Field, - nullifier_secret: Field, -) -> Field { - if salted_private_nullifier.value == 0 { - // If the private nullifier value is 0, it means it is hidden behind its salted hash - // inside the circuit, so we just return 0 making this proof not usable to derive - // the scoped nullifier - 0 - } - // A nullifier secret set to 0 means it should be ignored and the nullifier should be computed without it - // Otherwise, the nullifier should be computed with the secret - else if nullifier_secret != 0 { - Poseidon2::hash( - [salted_private_nullifier.value, service_scope, service_subscope, nullifier_secret], - 4, - ) - } else { - Poseidon2::hash( - [salted_private_nullifier.value, service_scope, service_subscope], - 3, - ) - } -} - -/// Only used for testing purposes for now -fn has_value_in_tags( - tags: [Field; TAGS_LEN], - value: str<2>, -) -> bool { - // Index for A - let START_ASCII_INDEX: u32 = 65; - let value_bytes = value.as_bytes(); - let converted_value = (value_bytes[0] as u32 - START_ASCII_INDEX) * 26 - + (value_bytes[1] as u32 - START_ASCII_INDEX); - let mut result = false; - let mut tags_bits: [[u1; BIT_SIZE]; TAGS_LEN] = [[0; BIT_SIZE]; TAGS_LEN]; - for i in 0..TAGS_LEN { - tags[i].assert_max_bit_size::(); - tags_bits[i] = tags[i].to_le_bits(); - } - for i in 0..TAGS_LEN { - for j in 0..BIT_SIZE { - let actual_index = (i * BIT_SIZE) + j; - let has_bit_in_tag = (tags_bits[i][j] != 0); - if (has_bit_in_tag) & (actual_index == converted_value) { - result = true; - } - } - } - result -} - -pub fn calculate_certificate_registry_leaf( - tags: [Field; 3], - cert_type: u8, - country: str<3>, - public_key: [u8; N], -) -> Field { - // Pack certificate type and country code into a single field - let country_bytes: [u8; 3] = country.as_bytes(); - let unpacked_bytes: [u8; 4] = - [cert_type as u8, country_bytes[0], country_bytes[1], country_bytes[2]]; - // Prepare and hash Poseidon2 inputs - let mut poseidon_inputs: [Field; 4 + (N + 30) / 31] = [0; 4 + (N + 30) / 31]; - poseidon_inputs[0] = tags[0]; - poseidon_inputs[1] = tags[1]; - poseidon_inputs[2] = tags[2]; - poseidon_inputs[3] = utils::pack_be_bytes_into_fields::<4, 1, 31>(unpacked_bytes)[0]; - let packed_pubkey = utils::pack_be_bytes_into_fields::(public_key); - for i in 0..packed_pubkey.len() { - poseidon_inputs[4 + i] = packed_pubkey[i] as Field; - } - Poseidon2::hash(poseidon_inputs, poseidon_inputs.len()) -} - -#[test] -fn test_has_value_in_tags() { - let mut tags = [0x7, 0x0, 0x0]; - // We assume the Field can hold 253 bits, which is the case for BN254 - assert(has_value_in_tags::<253, _>(tags, "AA")); - assert(has_value_in_tags::<253, _>(tags, "AB")); - assert(has_value_in_tags::<253, _>(tags, "AC")); - assert(!has_value_in_tags::<253, _>(tags, "AD")); - assert(!has_value_in_tags::<253, _>(tags, "AE")); - - tags = [0x1, 0x0, 0x0]; - assert(has_value_in_tags::<253, _>(tags, "AA")); - assert(!has_value_in_tags::<253, _>(tags, "AB")); - assert(!has_value_in_tags::<253, _>(tags, "AC")); - assert(!has_value_in_tags::<253, _>(tags, "AD")); - assert(!has_value_in_tags::<253, _>(tags, "AE")); - - tags = [0x0, 0x0, 0x0]; - assert(!has_value_in_tags::<253, _>(tags, "AA")); - assert(!has_value_in_tags::<253, _>(tags, "AB")); - assert(!has_value_in_tags::<253, _>(tags, "AC")); - assert(!has_value_in_tags::<253, _>(tags, "AD")); - assert(!has_value_in_tags::<253, _>(tags, "AE")); - - tags = [0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x4, 0x0]; - assert(has_value_in_tags::<253, _>(tags, "JR")); - assert(has_value_in_tags::<253, _>(tags, "JS")); - assert(!has_value_in_tags::<253, _>(tags, "JT")); - assert(!has_value_in_tags::<253, _>(tags, "JU")); - assert(has_value_in_tags::<253, _>(tags, "JV")); - assert(!has_value_in_tags::<253, _>(tags, "JW")); - assert(!has_value_in_tags::<253, _>(tags, "JX")); - assert(!has_value_in_tags::<253, _>(tags, "JY")); - assert(!has_value_in_tags::<253, _>(tags, "JZ")); - - tags = [0x0, 0x0, 0x8000000]; - assert(has_value_in_tags::<253, _>(tags, "UN")); -} - -// This test should fail because a tag limb is too large (i.e. not fitting in 253 bits) -#[test(should_fail)] -fn test_has_value_in_tags_should_fail() { - let tags = [0x2fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0x0, 0x0]; - assert(has_value_in_tags::<253, _>(tags, "AA")); -} - -#[test] -pub fn test_calculate_certificate_registry_leaf() { - let public_key: [u8; _] = [ - 0x9f, 0xc3, 0x56, 0xd3, 0x71, 0x79, 0xe5, 0x27, 0xf8, 0xb6, 0xf4, 0x0c, 0x93, 0x62, 0x8d, - 0xf4, 0x20, 0xec, 0x32, 0xd7, 0x81, 0xad, 0xe2, 0x61, 0x1e, 0x67, 0xe3, 0xe5, 0x01, 0xf8, - 0x46, 0x35, 0x86, 0x0f, 0x0c, 0x7e, 0x5e, 0x2b, 0x06, 0x99, 0x90, 0xcc, 0xc6, 0xe9, 0x25, - 0x09, 0xf0, 0x95, 0x0a, 0x06, 0xca, 0x95, 0x5f, 0x69, 0x62, 0x5a, 0xc7, 0xda, 0x78, 0x80, - 0x03, 0xd2, 0x9d, 0x72, 0x6f, 0xf9, 0xf0, 0x0a, 0x97, 0xff, 0xd5, 0x62, 0xd2, 0x4b, 0x3c, - 0x9c, 0x49, 0x14, 0x63, 0x58, 0x3e, 0x09, 0xbd, 0xe8, 0x3f, 0x49, 0x59, 0x65, 0x1d, 0x10, - 0x29, 0x5a, 0xd2, 0xc8, 0x3e, 0xc2, 0xd7, 0xdd, 0x5d, 0xf7, 0xf7, 0x80, 0x02, 0x35, 0xeb, - 0x62, 0x09, 0x59, 0x50, 0xaf, 0x9c, 0xab, 0x67, 0xf5, 0xcd, 0x7a, 0x8a, 0x70, 0xf7, 0x25, - 0x36, 0x19, 0x0e, 0xa6, 0x86, 0xfd, 0x7b, 0x6f, 0x50, 0x94, 0xb3, 0xce, 0xe4, 0xd9, 0x66, - 0x7e, 0x4e, 0x99, 0x24, 0xa5, 0x54, 0x83, 0x9f, 0x9e, 0xc5, 0x0b, 0xd2, 0x18, 0x8d, 0xe4, - 0x0c, 0x84, 0xba, 0x89, 0xee, 0x1c, 0x3b, 0x5f, 0x1c, 0x2c, 0xbd, 0x2b, 0x55, 0xd1, 0xbc, - 0x27, 0x9d, 0x16, 0x42, 0xe1, 0xca, 0xf3, 0x97, 0x62, 0xfc, 0xff, 0xd4, 0xbd, 0x68, 0xd7, - 0x31, 0x97, 0xce, 0x10, 0xf4, 0x54, 0x8a, 0xfe, 0xe8, 0xc0, 0xa6, 0x79, 0x4b, 0x3f, 0x67, - 0x64, 0x26, 0x3c, 0xc8, 0x79, 0x45, 0x70, 0x20, 0xda, 0x8f, 0x06, 0x74, 0xd0, 0xbd, 0x8e, - 0x79, 0x73, 0x1b, 0x8c, 0x37, 0xde, 0xfd, 0x62, 0xd2, 0xb3, 0x18, 0xcf, 0x44, 0xb7, 0x2f, - 0x0c, 0xa3, 0x54, 0x0f, 0xb0, 0x9e, 0xe4, 0x12, 0x73, 0x8f, 0xe1, 0x20, 0x33, 0x7c, 0xf6, - 0x04, 0xc2, 0x02, 0x36, 0x12, 0x1f, 0xb2, 0x2e, 0x91, 0xe5, 0xe9, 0xb1, 0xbb, 0x73, 0xd6, - 0x82, 0xe2, 0x57, 0xad, 0xf9, 0xfa, 0x61, 0x5b, 0x26, 0xa2, 0x4b, 0x10, 0xd7, 0x17, 0x8a, - 0x76, 0x51, 0xae, 0xf9, 0xec, 0x44, 0x8b, 0x9f, 0x07, 0xbe, 0xac, 0x7c, 0x58, 0x91, 0x6c, - 0xc9, 0x20, 0x64, 0xcf, 0x4b, 0x3f, 0xed, 0xdd, 0x6b, 0x7f, 0xc1, 0x51, 0xaa, 0x19, 0x75, - 0xde, 0xab, 0xf8, 0x1b, 0x6b, 0xf4, 0x39, 0xf0, 0xb5, 0x2e, 0xd1, 0xbd, 0x2f, 0x7b, 0x8e, - 0x15, 0x1d, 0x19, 0xc2, 0x35, 0xa0, 0x68, 0xb3, 0x4c, 0xab, 0xad, 0xfd, 0xd1, 0x0d, 0xec, - 0xd2, 0x2e, 0x17, 0x8b, 0x3c, 0xac, 0x93, 0xc6, 0x8e, 0x37, 0x65, 0x23, 0xb6, 0xba, 0x99, - 0x79, 0x2a, 0x29, 0x24, 0x0a, 0x2c, 0xf4, 0x4e, 0x3e, 0x4c, 0x6b, 0x3e, 0x4a, 0x9d, 0xb5, - 0x3e, 0xa8, 0x9e, 0x11, 0xe6, 0x2d, 0x10, 0x3b, 0x93, 0x37, 0x71, 0x72, 0x3b, 0xc8, 0x7a, - 0x8e, 0x58, 0xec, 0xc8, 0x43, 0x9d, 0x4d, 0xc9, 0x9b, 0x01, 0x42, 0x06, 0xa4, 0x52, 0xb2, - 0xd6, 0x4e, 0xe8, 0xaf, 0xc2, 0x84, 0x79, 0x99, 0x12, 0xbb, 0x6a, 0x8e, 0x0f, 0x9c, 0xc9, - 0x36, 0x62, 0x8c, 0x7a, 0xf7, 0xb2, 0xb4, 0xf9, 0x80, 0x9c, 0x20, 0xb8, 0xc1, 0x10, 0x14, - 0x61, 0x40, 0x8b, 0x6e, 0xac, 0x5e, 0x05, 0x19, 0xd6, 0xc6, 0xbd, 0x5b, 0xed, 0x93, 0x17, - 0x61, 0xe3, 0x4c, 0x0d, 0xa2, 0xb9, 0x09, 0xe8, 0x7d, 0x30, 0x34, 0xc1, 0xea, 0x40, 0xa9, - 0x50, 0x26, 0xfd, 0xdc, 0x7d, 0xdc, 0xb1, 0x55, 0xf5, 0x86, 0xec, 0x51, 0x4e, 0x04, 0xa5, - 0x41, 0x3f, 0x7d, 0x52, 0xfc, 0x08, 0xf4, 0x06, 0x3b, 0xd6, 0x9c, 0xc6, 0x73, 0xad, 0x5d, - 0x3e, 0xf5, 0xad, 0x47, 0x50, 0xa7, 0x54, 0x2a, 0xe3, 0x1b, 0x57, 0x6b, 0xae, 0xbd, 0x27, - 0xc4, 0x34, 0x53, 0xda, 0xf7, 0x89, 0x53, 0x12, 0xbb, 0x95, 0xdf, 0xc3, 0xde, 0xd4, 0x1d, - 0x06, 0xb5, - ]; - - // UN (i.e. ICAO) = index 533 (253 * 2 + 27), so bit index 27 is set on the 3rd limb - let tags = [0x0, 0x0, 0x8000000]; - let cert_type = 1 as u8; // CSCA - let country = "AUS"; - - let leaf_hash = calculate_certificate_registry_leaf(tags, cert_type, country, public_key); - // Should match the result of getCertificateLeafHash() - assert(leaf_hash == 0x10370abe147332c5b039fb820a32964f7567998e9c54f93595bb95a1dc4ba62f); -} - -pub fn get_country_from_dg1(dg1: [u8; 95]) -> str<3> { - // There 5 padding bytes in the dg1 before the actual MRZ - let country_offset = 5 + PASSPORT_MRZ_COUNTRY_INDEX; - let mut country_bytes: [u8; 3] = [0; 3]; - for i in 0..3 { - country_bytes[i] = dg1[country_offset + i]; - } - let mut country = country_bytes.as_str_unchecked(); - // A special case for Germany - if (country == "D<<") { - country = "DEU"; - } - country -} - -pub fn hash_salt_country_tbs( - salt: Field, - country: str<3>, - tbs: [u8; TBS_MAX_SIZE], -) -> Field { - let country_bytes: [u8; 3] = country.as_bytes(); - let mut result: [Field; 2 + ((TBS_MAX_SIZE + 30) / 31)] = [0; 2 + ((TBS_MAX_SIZE + 30) / 31)]; - result[0] = salt; - - let packed_country: Field = pack_be_bytes_into_fields::<3, 1, 31>(country_bytes)[0]; - result[1] = packed_country; - - let packed_tbs: [Field; (TBS_MAX_SIZE + 30) / 31] = - pack_be_bytes_into_fields::(tbs); - for i in 0..((TBS_MAX_SIZE + 30) / 31) { - result[2 + i] = packed_tbs[i]; - } - - Poseidon2::hash(result, 2 + ((TBS_MAX_SIZE + 30) / 31)) -} - -pub fn hash_salt_dg1_private_nullifier( - salted_dg1: utils::types::SaltedValue<[u8; 95]>, - salted_expiry_date: utils::types::SaltedValue, - salted_private_nullifier: utils::types::SaltedValue, -) -> Field { - let mut hash_inputs: [Field; 3] = std::mem::zeroed(); - - hash_inputs[0] = salted_dg1.get_hash(); - hash_inputs[1] = salted_expiry_date.get_hash(); - hash_inputs[2] = salted_private_nullifier.get_hash(); - - Poseidon2::hash(hash_inputs, 3) -} - -pub fn calculate_private_nullifier( - dg1: [u8; DG1], - e_content: [u8; ECONTENT], - sod_sig: [u8; SIG], -) -> Field { - let mut result: [Field; (DG1 + 30) / 31 + (ECONTENT + 30) / 31 + (SIG + 30) / 31] = - [0; (DG1 + 30) / 31 + (ECONTENT + 30) / 31 + (SIG + 30) / 31]; - - let packed_dg1: [Field; (DG1 + 30) / 31] = pack_be_bytes_into_fields::(dg1); - for i in 0..((DG1 + 30) / 31) { - result[i] = packed_dg1[i]; - } - - let packed_e_content: [Field; (ECONTENT + 30) / 31] = - pack_be_bytes_into_fields::(e_content); - for i in 0..((ECONTENT + 30) / 31) { - result[(DG1 + 30) / 31 + i] = packed_e_content[i]; - } - - let packed_sod_sig: [Field; (SIG + 30) / 31] = pack_be_bytes_into_fields::(sod_sig); - for i in 0..((SIG + 30) / 31) { - result[(DG1 + 30) / 31 + ((ECONTENT + 30) / 31) + i] = packed_sod_sig[i]; - } - - Poseidon2::hash( - result, - (DG1 + 30) / 31 + ((ECONTENT + 30) / 31) + (SIG + 30) / 31, - ) -} - -pub fn calculate_sod_hash( - e_content: [u8; ECONTENT_SIZE], -) -> Field { - let packed: [Field; (ECONTENT_SIZE + 30) / 31] = - pack_be_bytes_into_fields::(e_content); - Poseidon2::hash(packed, (ECONTENT_SIZE + 30) / 31) -} - -pub fn hash_salt_country_signed_attr_dg1_e_content_private_nullifier( - salt: Field, - country: str<3>, - signed_attr: [u8; SA], - signed_attr_size: Field, - dg1: [u8; DG1], - e_content: [u8; ECONTENT], - private_nullifier: Field, -) -> Field { - let country_bytes: [u8; 3] = country.as_bytes(); - - let mut result: [Field; 4 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31)] = - [0; 4 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31)]; - result[0] = salt; - - let packed_country: Field = pack_be_bytes_into_fields::<3, 1, 31>(country_bytes)[0]; - result[1] = packed_country; - - let packed_signed_attr: [Field; (SA + 30) / 31] = - pack_be_bytes_into_fields::(signed_attr); - for i in 0..((SA + 30) / 31) { - result[2 + i] = packed_signed_attr[i]; - } - - result[2 + (SA + 30) / 31] = signed_attr_size; - - let packed_dg1: [Field; (DG1 + 30) / 31] = pack_be_bytes_into_fields::(dg1); - for i in 0..((DG1 + 30) / 31) { - result[3 + (SA + 30) / 31 + i] = packed_dg1[i]; - } - - let packed_e_content: [Field; (ECONTENT + 30) / 31] = - pack_be_bytes_into_fields::(e_content); - for i in 0..((ECONTENT + 30) / 31) { - result[3 + (SA + 30) / 31 + ((DG1 + 30) / 31) + i] = packed_e_content[i]; - } - result[3 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31)] = private_nullifier; - - Poseidon2::hash( - result, - 4 + (SA + 30) / 31 + ((DG1 + 30) / 31) + ((ECONTENT + 30) / 31), - ) -} - -// Returns the merkle root of the tree from the provided leaf, index and hash_path, using the Poseidon2 hash function -// Arity is expected to be 2 and the the tree depth is equal to the hash_path array length -pub fn compute_merkle_root(leaf: Field, index: Field, hash_path: [Field; N]) -> Field { - let index_bits: [u1; N] = index.to_le_bits(); - let mut current = leaf; - for i in 0..N { - let path_bit = index_bits[i] == 1; - let (hash_left, hash_right) = if path_bit { - (hash_path[i], current) - } else { - (current, hash_path[i]) - }; - current = Poseidon2::hash([hash_left, hash_right], 2); - } - current -} - -#[test] -fn test_compute_merkle_root1() { - let leaf = 0x2fe190f39de3fcf4cbc2eb334d0dc76e4d06f2350aa6056c91ff5f11ded9fb4a; - let index = 0; - let hash_path = [ - 0x00, - 0x0b63a53787021a4a962a452c2921b3663aff1ffd8d5510540f8e659e782956f1, - 0x0e34ac2c09f45a503d2908bcb12f1cbae5fa4065759c88d501c097506a8b2290, - 0x21f9172d72fdcdafc312eee05cf5092980dda821da5b760a9fb8dbdf607c8a20, - 0x2373ea368857ec7af97e7b470d705848e2bf93ed7bef142a490f2119bcf82d8e, - 0x120157cfaaa49ce3da30f8b47879114977c24b266d58b0ac18b325d878aafddf, - 0x01c28fe1059ae0237b72334700697bdf465e03df03986fe05200cadeda66bd76, - 0x2d78ed82f93b61ba718b17c2dfe5b52375b4d37cbbed6f1fc98b47614b0cf21b, - 0x067243231eddf4222f3911defbba7705aff06ed45960b27f6f91319196ef97e1, - 0x1849b85f3c693693e732dfc4577217acc18295193bede09ce8b97ad910310972, - 0x2a775ea761d20435b31fa2c33ff07663e24542ffb9e7b293dfce3042eb104686, - 0x0f320b0703439a8114f81593de99cd0b8f3b9bf854601abb5b2ea0e8a3dda4a7, - 0x0d07f6e7a8a0e9199d6d92801fff867002ff5b4808962f9da2ba5ce1bdd26a73, - 0x1c4954081e324939350febc2b918a293ebcdaead01be95ec02fcbe8d2c1635d1, - ]; - let root = compute_merkle_root(leaf, index, hash_path); - assert(root == 0x0742857aba0058b2167c4ac94fede8ec480600911aa871153b988c3f71095449); -} - -#[test] -fn test_compute_merkle_root2() { - let e00 = Poseidon2::hash([1], 1); - let e01 = Poseidon2::hash([1], 1); - let e02 = Poseidon2::hash([1], 1); - let e03 = Poseidon2::hash([1], 1); - assert(e00 == 0x168758332d5b3e2d13be8048c8011b454590e06c44bce7f702f09103eef5a373); - - let e10 = Poseidon2::hash([e00, e01], 2); - let e11 = Poseidon2::hash([e02, e03], 2); - assert(e10 == 0x113d8ff59c2e15d711241797c380264e39dc1b9e00f2713e707d8d7773b6d912); - - let expected_root = Poseidon2::hash([e10, e11], 2); - assert(expected_root == 0x0f4f16b234c1d5054b15d408282cb45ba6c10a629fe068e7f3cc253ceae4f08d); - - let hash_path = [e01, e10]; - assert( - hash_path - == [ - 0x168758332d5b3e2d13be8048c8011b454590e06c44bce7f702f09103eef5a373, - 0x113d8ff59c2e15d711241797c380264e39dc1b9e00f2713e707d8d7773b6d912, - ], - ); - - let leaf = Poseidon2::hash([1], 1); - let index = 0; - let root = compute_merkle_root(leaf, index, hash_path); - assert(root == 0x0f4f16b234c1d5054b15d408282cb45ba6c10a629fe068e7f3cc253ceae4f08d); -} - -pub fn get_vkey_hash(vkey: [Field; N]) -> Field { - Poseidon2::hash(vkey, N) -} - -#[test] -fn test_get_vkey_hash() { - let vkey = [ - 0x0000000000000000000000000000000000000000000000000000000000004000, - 0x000000000000000000000000000000000000000000000000000000000000001e, - 0x0000000000000000000000000000000000000000000000000000000000000001, - 0x0000000000000000000000000000000000000000000000000000000000000001, - 0x000000000000000000000000000000000000000000000000000000000000000e, - 0x000000000000000000000000000000000000000000000000000000000000000f, - 0x0000000000000000000000000000000000000000000000000000000000000010, - 0x0000000000000000000000000000000000000000000000000000000000000011, - 0x0000000000000000000000000000000000000000000000000000000000000012, - 0x0000000000000000000000000000000000000000000000000000000000000013, - 0x0000000000000000000000000000000000000000000000000000000000000014, - 0x0000000000000000000000000000000000000000000000000000000000000015, - 0x0000000000000000000000000000000000000000000000000000000000000016, - 0x0000000000000000000000000000000000000000000000000000000000000017, - 0x0000000000000000000000000000000000000000000000000000000000000018, - 0x0000000000000000000000000000000000000000000000000000000000000019, - 0x000000000000000000000000000000000000000000000000000000000000001a, - 0x000000000000000000000000000000000000000000000000000000000000001b, - 0x000000000000000000000000000000000000000000000000000000000000001c, - 0x000000000000000000000000000000000000000000000000000000000000001d, - 0x000000000000000000000000000000014d18053025847e890b73d1bd851d8010, - 0x00000000000000000000000000000000001604875484cd0af6333f892d9db03c, - 0x0000000000000000000000000000001aa505665b96ff23e66c8cc50617d912dd, - 0x000000000000000000000000000000000023761d0fc8b989dd96889c0e1dd500, - 0x0000000000000000000000000000005ec6b7adcaad33a31d00c481cada512ff2, - 0x00000000000000000000000000000000000619dc9f99c6e6318f58a3cd578e03, - 0x000000000000000000000000000000ca65a4903d4105e8ffb945a804fe5e758b, - 0x0000000000000000000000000000000000013d6fe1a9ccad8cf0da0cbb325a50, - 0x000000000000000000000000000000c3d521df3cd944a41cc6c93814e4bfb108, - 0x00000000000000000000000000000000002967d970e732ce06f745a1676e907a, - 0x000000000000000000000000000000bea006927efee453f22d7e5001156d8236, - 0x000000000000000000000000000000000003da37e3170387f7fc7fe67f3fd02d, - 0x0000000000000000000000000000007ecadab7d0191e9b27b8c118bcf63e39d7, - 0x00000000000000000000000000000000001aceee76600298bda7debc2a13e65f, - 0x00000000000000000000000000000094109ace5115b62b817510419b345bafb3, - 0x000000000000000000000000000000000007478caa1879b0d66eafb700c8eaff, - 0x000000000000000000000000000000c66580c6bd58511b6f734408a36072b4cb, - 0x000000000000000000000000000000000012a966c244f2d7aef31bf501d4c7b3, - 0x00000000000000000000000000000066953254478df3e72cd967c81f9d7520dd, - 0x000000000000000000000000000000000012836bbc2291cc1a76e191beeeff55, - 0x00000000000000000000000000000085f16f224863af3a2eb1640916d6e2f661, - 0x00000000000000000000000000000000001d2c4076e8dcb9be0e997d8c5715d9, - 0x000000000000000000000000000000e7e736564c69478322d60bf28db04d2180, - 0x000000000000000000000000000000000001bac3d335ee7aece9c8e8b83c4a0a, - 0x000000000000000000000000000000418412d57fe3f9d88befaf72e3f049aed6, - 0x00000000000000000000000000000000002640a81c852ebd44791d208778e3d4, - 0x0000000000000000000000000000003f0de2660faefec496cddfcf172d70f88a, - 0x000000000000000000000000000000000023f365597e5a0fe284fe40ba6df049, - 0x0000000000000000000000000000001ff3fdb800a12685d0225869a709c59ea1, - 0x000000000000000000000000000000000010485496ac517ce4626468b80c20d1, - 0x000000000000000000000000000000eae802a6cf93d2041722bcc7b827850d9c, - 0x00000000000000000000000000000000002c3eb537afd8670ec12382677e9dfd, - 0x000000000000000000000000000000da72208a8ea7aa2e70b8fc00cf95fbe413, - 0x00000000000000000000000000000000001994c139d6d63fbb02a95416dd2057, - 0x0000000000000000000000000000000c243e99da3df894bd68564c1f2189c436, - 0x000000000000000000000000000000000004714d9481f6dbd276728639c54996, - 0x0000000000000000000000000000007ffd262875ae684deba001fcc5fdea3bbf, - 0x000000000000000000000000000000000026c3846eed3340f6f2e861943f6f27, - 0x0000000000000000000000000000009e45b69b687387629e72688f33382df553, - 0x000000000000000000000000000000000017612f582a3500568851ebdcb62e72, - 0x000000000000000000000000000000898a13479bd1c1e27a6e0681a5d43985af, - 0x000000000000000000000000000000000002f9352d7ab76f7b9eda17515fd7b8, - 0x0000000000000000000000000000003c13860bb6a8f804652839fa9abe19bb7b, - 0x00000000000000000000000000000000000ea81714a4cd7294ac6300617eb610, - 0x000000000000000000000000000000dc6620bff3175f56800f1e44c3e79b256e, - 0x000000000000000000000000000000000003c53e0fb2f68008220ac57a71c7f4, - 0x000000000000000000000000000000ab9926a5dd872d669530c99c7d9be65720, - 0x00000000000000000000000000000000002ea70327e45061f95597e2ccf26540, - 0x00000000000000000000000000000032d9d845b89a70f07980c48344f7a599e6, - 0x000000000000000000000000000000000020828423a9331f84edb915eeb4733d, - 0x000000000000000000000000000000f020304aa06e327c9294f1254859db8ab6, - 0x00000000000000000000000000000000001f5964632befb3e8707483b77e7881, - 0x0000000000000000000000000000004d882ed48ddc17fda49a2e3c07bfa0b4a7, - 0x0000000000000000000000000000000000238a9bda3f2d414f43b6d68db016da, - 0x000000000000000000000000000000871bf5d454ed7a84525d3d52325dfb377c, - 0x000000000000000000000000000000000007584c1032621909192d308449ced1, - 0x0000000000000000000000000000005b72000fb18ad1bd936839038a2bc2b9e5, - 0x0000000000000000000000000000000000268cfce53a1c077c835540eb73a23c, - 0x00000000000000000000000000000000c747ae5e9a310b1d8baa8c34f92e8d0e, - 0x00000000000000000000000000000000002701e27eec246967ec650bbe990bab, - 0x000000000000000000000000000000a6783a604d35e125327e5fe8cf22398fdd, - 0x00000000000000000000000000000000002309c7ceac11535749dab8c9f4d851, - 0x00000000000000000000000000000065720cd086bae46f673f548239ceafb0b4, - 0x00000000000000000000000000000000000a8ac00f8a2042f8f81c554dc404f6, - 0x000000000000000000000000000000907c095579b757be6b50e41dc3692a224c, - 0x00000000000000000000000000000000000a45377f92a8d6d44afe54e3717f8a, - 0x000000000000000000000000000000d8642735ec11ef526dcffa791f1ad641ab, - 0x00000000000000000000000000000000001e4fbc154b0c6b4c559f58a7d19ac0, - 0x000000000000000000000000000000eff01a355a79835cc29ccf88cd9e3ca07f, - 0x00000000000000000000000000000000002af5e29ca00459725e2680c6a78a6f, - 0x000000000000000000000000000000da6c16f1483ae4228c68cc091f40d39aad, - 0x00000000000000000000000000000000000ea734a85cf7a6d1d775a08afc61e0, - 0x000000000000000000000000000000fd722ec69b8a01085785be11e41f873afe, - 0x000000000000000000000000000000000006b8a63c9cf273d4724fbb10d5f57a, - 0x000000000000000000000000000000f7d9fd5e858349061430d351c45499dfad, - 0x0000000000000000000000000000000000046edaae51ba84f2dabcd56e9eed5b, - 0x0000000000000000000000000000002f225a95524043ea68cc704f77ef4f6045, - 0x0000000000000000000000000000000000038d07b151361621e074699b374a85, - 0x000000000000000000000000000000da6a36c7ae48c4791868c3d10c8533fe6e, - 0x000000000000000000000000000000000014ce118be5ef951902f6e84a561e88, - 0x000000000000000000000000000000beabc4f9b42059a77a1b15b98856b48453, - 0x00000000000000000000000000000000002114644c4953246a959f25a4bf2052, - 0x0000000000000000000000000000009d10f2f38322da8ecb0b296bc729ff1c4e, - 0x000000000000000000000000000000000027f1245b7ec2b0cb360bb134218ed1, - 0x00000000000000000000000000000032957a466beb19e0675e0f739616187ecd, - 0x0000000000000000000000000000000000235e20011670e41d045fd8446ae100, - 0x000000000000000000000000000000691d28ce28c9ae3f7e8d3220cbfdb0fd36, - 0x000000000000000000000000000000000004d8e62001cadc95344edcfd429fed, - 0x0000000000000000000000000000008a34b9ab23bd2cd471701a5a76de4076b8, - 0x00000000000000000000000000000000002c853787226778520baf3c5f0ed65e, - 0x000000000000000000000000000000f357d89b0302e34eac204bc55974f0c37b, - 0x00000000000000000000000000000000001a04dfa8543c150c4f07b768f1752d, - 0x000000000000000000000000000000709f2727a8adda78f9cd125c85fc061557, - 0x0000000000000000000000000000000000180b5e9b2901b08360c598f18581d0, - 0x0000000000000000000000000000003f99f9fd98707c98fd62328a676c38bb38, - 0x000000000000000000000000000000000004880ff78661543813929232e5c4db, - 0x0000000000000000000000000000003fb3d6fdb1fe407fc26479a67309987378, - 0x0000000000000000000000000000000000152830347b8e35a842ea020f557635, - 0x0000000000000000000000000000004aed3df71695a6a5295e2117cc6c0a80df, - 0x0000000000000000000000000000000000007ee2c78519eb92faa04d10b2ae9e, - 0x0000000000000000000000000000000000000000000000000000000000000001, - 0x0000000000000000000000000000000000000000000000000000000000000000, - 0x0000000000000000000000000000000000000000000000000000000000000002, - 0x0000000000000000000000000000000000000000000000000000000000000000, - 0x000000000000000000000000000000feb33855ac28e08d8b02991fb3f3c211cf, - 0x000000000000000000000000000000000007d8476506cdef23b023ca072ed709, - 0x000000000000000000000000000000e985e0b015edca55f69192bdb7139b7224, - 0x000000000000000000000000000000000020470f3258600e780b46d6c7db1bc6, - ]; - let vkey_hash = get_vkey_hash(vkey); - assert(vkey_hash == 0x159c7f9777839c2449c0a0f90b411569ed72aaa9d090c82c9c028adf5419d3d6); -} diff --git a/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/src/lib.nr deleted file mode 100644 index cd4fc2543..000000000 --- a/noir-examples/noir-passport-examples/shared-utils/data-check/integrity/src/lib.nr +++ /dev/null @@ -1,206 +0,0 @@ -use sha512::{sha384, sha512}; -use sha256::sha256_var; -use utils::{ - check_zero_padding, - constants::{ID_CARD_DG1_LENGTH, PASSPORT_DG1_LENGTH}, - find_subarray_index, - is_id_card, - is_subarray_in_array, - types::{DG1Data, EContentData}, -}; -/** -* Computes the hash of the MRZ (Data Group 1) and checks it is the same as the one -* provided in the SOD file of the ID and then use it along with the rest of the -* hashes of the remaining data groups to compute the final hash contained in the last 32 bytes of -* eContent that is then signed by the Document Signing Certificate (DSC) -* This lets us make sure the data is authentic and has not been tampered with, so we can use the data -* of the MRZ to build subsequent proofs (age, citizenship, etc.) -*/ -pub fn check_integrity_of_data_sha256( - dg1: [u8; 95], - // --- This is clearly the thing which is actually signed --- - signed_attributes: [u8; 200], - signed_attributes_size: u32, - // --- Okay so this is clearly the SOD, i.e. the thing which the hash of DG1 is supposed to be contained in --- - e_content: [u8; 700], - e_content_size: u32, - dg1_offset_in_e_content: u32, -) { - // For passports we ignore the last padding characters - let mut dg1_size: u64 = 93; - let mut x: u64 = 0; - - // If it's an ID card then the array should not have any padding - // character - if is_id_card(dg1) { - println("this is reached"); - x = 3; - dg1_size = 95; - } - - // We only need to recompute the hash of the MRZ (or more accurately that of Data Group 1) - // within the circuit as this is the only data group we use to build the proof (age, country, etc.) - let dg1_hash = sha256_var(dg1, dg1.len() as u64); // This gives the wrong result but succeeds in R1CS constraints - - for i in 0..32 { - // Check the hash of dg1 is indeed in the e_content - assert(dg1_hash[i] == e_content[dg1_offset_in_e_content + i]); - } - - // --- Additionally, clearly the SOD itself is supposed to be hashed and then concatenated with some other "stuff" --- - // --- That "stuff" is the thing which is actually signed --- - let ryan_computed_final_hash = - sha256_var(e_content, e_content.len() as u64); // Wrong result but passes R1CS constraints - - for i in 0..32 { - // The last 32 bytes of the signed_attributes are the hash of the data groups - // The rest is padding and the signature date, not important to check - assert(ryan_computed_final_hash[i] == signed_attributes[signed_attributes_size - 32 + i]); - } -} - -pub fn check_integrity_of_data_sha384( - dg1: [u8; 95], - signed_attributes: [u8; 200], - signed_attributes_size: u32, - e_content: [u8; 700], - e_content_size: u32, - dg1_offset_in_e_content: u32, -) { - // For passports we ignore the last padding characters - let mut dg1_size: u64 = 93; - - // If it's an ID card then the array should not have any padding - // character - if is_id_card(dg1) { - dg1_size = 95; - } - - let dg1_bounded_vec = BoundedVec::from_parts(dg1, dg1_size as u32); - // We only need to recompute the hash of the MRZ (or more accurately that of Data Group 1) - // within the circuit as this is the only data group we use to build the proof (age, country, etc.) - let dg1_hash = sha384::sha384_var(dg1_bounded_vec); - - for i in 0..48 { - // Check the hash of dg1 is indeed in the e_content - assert(dg1_hash[i] == e_content[dg1_offset_in_e_content + i]); - } - - let e_content_bounded_vec = BoundedVec::from_parts(e_content, e_content_size as u32); - - let computed_final_hash = sha384::sha384_var(e_content_bounded_vec); - - for i in 0..48 { - // The last 48 bytes of the signed_attributes are the hash of the data groups - // The rest is padding and the signature date, not important to check - assert(computed_final_hash[i] == signed_attributes[signed_attributes_size - 48 + i]); - } -} - -pub fn check_integrity_of_data_sha512( - dg1: [u8; 95], - signed_attributes: [u8; 200], - signed_attributes_size: u32, - e_content: [u8; 700], - e_content_size: u32, - dg1_offset_in_e_content: u32, -) { - // For passports we ignore the last padding characters - let mut dg1_size: u64 = 93; - - // If it's an ID card then the array should not have any padding - // character - if is_id_card(dg1) { - dg1_size = 95; - } - - let dg1_bounded_vec = BoundedVec::from_parts(dg1, dg1_size as u32); - // We only need to recompute the hash of the MRZ (or more accurately that of Data Group 1) - // within the circuit as this is the only data group we use to build the proof (age, country, etc.) - let dg1_hash = sha512::sha512_var(dg1_bounded_vec); - - for i in 0..64 { - // Check the hash of dg1 is indeed in the e_content - assert(dg1_hash[i] == e_content[dg1_offset_in_e_content + i]); - } - - let e_content_bounded_vec = BoundedVec::from_parts(e_content, e_content_size as u32); - - let computed_final_hash = sha512::sha512_var(e_content_bounded_vec); - - for i in 0..64 { - // The last 64 bytes of the signed_attributes are the hash of the data groups - // The rest is padding and the signature date, not important to check - assert(computed_final_hash[i] == signed_attributes[signed_attributes_size - 64 + i]); - } -} - -pub fn get_dg1_size(dg1: DG1Data) -> u32 { - if is_id_card(dg1) { - ID_CARD_DG1_LENGTH - } else { - PASSPORT_DG1_LENGTH - } -} - -/** -* Computes the hash (using SHA2-256) of the first data group (containing the MRZ) and checks it is the same as the one -* included in eContent at the offset provided (along with the rest of the data group hashes) -*/ -pub fn check_dg1_sha256(dg1: DG1Data, e_content: EContentData, e_content_size: u32) { - check_zero_padding(e_content, e_content_size); - - // For passports we ignore the last padding characters - let dg1_size: u64 = get_dg1_size(dg1) as u64; - - // We only need to recompute the hash of the MRZ (or more accurately that of Data Group 1) - // within the circuit as this is the only data group we use to build the proof (age, country, etc.) - let dg1_hash = sha256_var(dg1, dg1_size); - - // Find the offset of the hash of dg1 in e_content - let dg1_offset_in_e_content = find_subarray_index(dg1_hash, e_content); - // Check that the hash of dg1 is in the e_content, we use the actual size rather than generic size - // of econtent to ignore the padding bytes at the end - assert( - dg1_offset_in_e_content + dg1_hash.len() <= e_content_size, - "Hash of dg1 not found in eContent", - ); -} -pub fn check_dg1_hash_within_sod( - dg1: [u8; 95], - dg1_padded_length: u64, - econtent: [u8; 200], - econtent_len: u32, - dg1_hash_offset: u32, -) { - // Check zero padding for econtent - check_zero_padding(econtent, econtent_len); - - // Bounds check: ensure dg1_hash_offset + 32 doesn't exceed econtent_len - assert(dg1_hash_offset + 32 <= econtent_len, "dg1_hash_offset out of bounds"); - - let dg1_hash = sha256_var(dg1, dg1_padded_length); - - // The DG1 hash is located at the start of the SOD - // (offset is always 0 for DG1) - for i in 0..32 { - assert(dg1_hash[i] == econtent[dg1_hash_offset + i]); - } -} -/** -* Computes the hash (using SHA2-256) of eContent (containing the hashes of the data groups) and checks it is the same as the one -* included in the signed_attributes, which is the message signed by the Document Signing Certificate (DSC) -*/ -pub fn check_signed_attributes_sha256( - signed_attributes: [u8; SA_SIZE], - e_content: EContentData, - e_content_size: u32, -) { - let computed_final_hash = sha256_var(e_content, e_content_size as u64); - - // Check that the computed final hash is in the signed attributes - assert( - is_subarray_in_array(computed_final_hash, signed_attributes), - "Computed final hash not found in signed attributes", - ); -} diff --git a/noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/src/lib.nr deleted file mode 100644 index 6da6d1759..000000000 --- a/noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/src/lib.nr +++ /dev/null @@ -1,34 +0,0 @@ -pub fn verify_rsa_pubkey_in_tbs( - dsc_pubkey: [u8; DSC_KEY_SIZE], - tbs_certificate: [u8; TBS_CERT_SIZE], - pubkey_offset: u32, -) { - // Check that the public key of the DSC is the same as the one in the TBS certificate. - // And since the TBS certificate is the data signed by the private key of the CSCA certificate - // we can make sure the DSC, which signed the data of the passport, has been signed by the - // root certificate of the issuing State (i.e. CSCA certificate) by verifying the signature below - for i in 0..DSC_KEY_SIZE { - assert(tbs_certificate[i + pubkey_offset] == dsc_pubkey[i]); - } -} -/// Check that an ECDSA public key x and y coord exists in a certificate TBS -pub fn verify_ecdsa_pubkey_in_tbs( - pubkey_x: [u8; PUBKEY_SIZE], - pubkey_y: [u8; PUBKEY_SIZE], - tbs: [u8; TBS_SIZE], -) { - let pubkey_x_offset = utils::find_subarray_index(pubkey_x, tbs); - let pubkey_y_offset = utils::find_subarray_index(pubkey_y, tbs); - for i in 0..PUBKEY_SIZE { - assert( - tbs[i + pubkey_x_offset] == pubkey_x[i], - "Public key x coord of DSC not found in TBS", - ); - } - for i in 0..PUBKEY_SIZE { - assert( - tbs[i + pubkey_y_offset] == pubkey_y[i], - "Public key y coord of DSC not found in TBS", - ); - } -} diff --git a/noir-examples/noir-passport-examples/shared-utils/utils/src/lib.nr b/noir-examples/noir-passport-examples/shared-utils/utils/src/lib.nr deleted file mode 100644 index bd1e5255d..000000000 --- a/noir-examples/noir-passport-examples/shared-utils/utils/src/lib.nr +++ /dev/null @@ -1,747 +0,0 @@ -/** -* The standards for passports and any other travel documents, electronic or not, -* are defined in the ICAO (International Civil Aviation Organization) 9303 document available here: -* https://www.icao.int/publications/pages/publication.aspx?docnum=9303 -*/ -pub mod tests; -pub mod types; -pub mod constants; - -/** -* The structure of the MRZ is well defined and standardized by the ICAO -* so the index will always be the same for every passport -* c.f. ICAO 9303-4, Appendix B -*/ - -// The following constants define the indices of the information -// we need to generate various proofs of identity from the MRZ -// The structure of the MRZ is slightly different between passports -// and ID cards so we need to define indices for both types - -use types::{ - DG1Data, MRZData, MRZName, MRZDOB, MRZYOB, MRZDocumentNumber, MRZNationality, MRZIssuingCountry, - MRZExpiryDate, -}; - -// Index for the country of issuance of the passport -pub global PASSPORT_MRZ_COUNTRY_INDEX: u32 = 2; -// Length of the country code in the MRZ -pub global PASSPORT_MRZ_COUNTRY_LENGTH: u32 = 3; -// Index for the three letter code of the country of citizenship -// Note that the first three letter code (index 2) in the MRZ is the country of issuance -// not citizenship. It is important to keep in mind for residence permits -// where the issuing country differs from the citizenship country -pub global PASSPORT_MRZ_NATIONALITY_INDEX: u32 = 54; -// Index for the gender of the passport holder (M, F or < if unspecified) -pub global PASSPORT_MRZ_GENDER_INDEX: u32 = 64; -// Index for the date of expiry (YYMMDD) -pub global PASSPORT_MRZ_EXPIRY_DATE_INDEX: u32 = 65; -// Index for the date of birth (YYMMDD) in TD1 (i.e. passport) MRZ -pub global PASSPORT_MRZ_BIRTHDATE_INDEX: u32 = 57; -// Length of the date of birth in the MRZ -pub global PASSPORT_MRZ_BIRTHDATE_LENGTH: u32 = 6; -// Length of the year of birth in the MRZ -pub global PASSPORT_MRZ_YEAR_OF_BIRTH_LENGTH: u32 = 2; -// Index for the document number in the MRZ -pub global PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX: u32 = 44; -// Length of the document number in the MRZ -pub global PASSPORT_MRZ_DOCUMENT_NUMBER_LENGTH: u32 = 9; -// Index for the document type in the MRZ -pub global PASSPORT_MRZ_DOCUMENT_TYPE_INDEX: u32 = 0; -// Index for the name of the passport holder -pub global PASSPORT_MRZ_NAME_INDEX: u32 = 5; -// Length of the name of the passport holder -pub global PASSPORT_MRZ_NAME_LENGTH: u32 = 39; -// Length of the MRZ on a passport -pub global PASSPORT_MRZ_LENGTH: u32 = 88; - -// Index for the country of issuance of the ID card -pub global ID_CARD_MRZ_COUNTRY_INDEX: u32 = 2; -// Length of the country code in the MRZ -pub global ID_CARD_MRZ_COUNTRY_LENGTH: u32 = 3; -// Note that the first three letter code (index 2) in the MRZ is the country of issuance -// not citizenship. It is important to keep in mind for residence permits -// where the issuing country differs from the citizenship country -pub global ID_CARD_MRZ_NATIONALITY_INDEX: u32 = 45; -// Index for the gender of the passport holder (M, F or < if unspecified) -pub global ID_CARD_MRZ_GENDER_INDEX: u32 = 37; -// Index for the date of expiry (YYMMDD) -pub global ID_CARD_MRZ_EXPIRY_DATE_INDEX: u32 = 38; -// Index for the date of birth (YYMMDD) in TD3 (i.e. ID cards) MRZ -pub global ID_CARD_MRZ_BIRTHDATE_INDEX: u32 = 30; -// Length of the date of birth in the MRZ -pub global ID_CARD_MRZ_BIRTHDATE_LENGTH: u32 = 6; -// Length of the year of birth in the MRZ -pub global ID_CARD_MRZ_YEAR_OF_BIRTH_LENGTH: u32 = 2; -// Index for the document number in the MRZ -pub global ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX: u32 = 5; -// Length of the document number in the MRZ -pub global ID_CARD_MRZ_DOCUMENT_NUMBER_LENGTH: u32 = 9; -// Index for the document type in the MRZ -pub global ID_CARD_MRZ_DOCUMENT_TYPE_INDEX: u32 = 0; -// Index for the name of the passport holder -pub global ID_CARD_MRZ_NAME_INDEX: u32 = 60; -/// Length for the MRZ on an ID card -pub global ID_CARD_MRZ_NAME_LENGTH: u32 = 30; -// Length of the MRZ on an ID card -pub global ID_CARD_MRZ_LENGTH: u32 = 90; - -// ASCII_CODE FOR < -pub global ASCII_CODE_FOR_LESS_THAN: u8 = 60; - -/// Offset of the MRZ in the DG1 -pub global DG1_TO_MRZ_OFFSET: u32 = 5; - -// ECDSA curves mapping -pub global ECDSA_CURVE_P256: u32 = 0; -pub global ECDSA_CURVE_P384: u32 = 1; -pub global ECDSA_CURVE_P521: u32 = 2; -pub global ECDSA_CURVE_BRAINPOOL_B256R1: u32 = 3; -pub global ECDSA_CURVE_BRAINPOOL_B256T1: u32 = 4; -pub global ECDSA_CURVE_BRAINPOOL_B384R1: u32 = 5; -pub global ECDSA_CURVE_BRAINPOOL_B384T1: u32 = 6; -pub global ECDSA_CURVE_BRAINPOOL_B512R1: u32 = 7; -pub global ECDSA_CURVE_BRAINPOOL_B512T1: u32 = 8; - -// Proof type to identify the circuit used for a given parameter commitment -pub global PROOF_TYPE_DISCLOSE: u8 = 0; -pub global PROOF_TYPE_AGE: u8 = 1; -pub global PROOF_TYPE_BIRTHDATE: u8 = 2; -pub global PROOF_TYPE_EXPIRY_DATE: u8 = 3; -pub global PROOF_TYPE_NATIONALITY_INCLUSION: u8 = 4; -pub global PROOF_TYPE_NATIONALITY_EXCLUSION: u8 = 5; -pub global PROOF_TYPE_ISSUING_COUNTRY_INCLUSION: u8 = 6; -pub global PROOF_TYPE_ISSUING_COUNTRY_EXCLUSION: u8 = 7; -pub global PROOF_TYPE_BIND: u8 = 8; -pub global PROOF_TYPE_SANCTIONS_EXCLUSION: u8 = 9; - -// D<< -global GERMANY_PASSPORT_CODE: [u8; 3] = [68, 60, 60]; -// DEU -global GERMANY_ISO_CODE: [u8; 3] = [68, 69, 85]; - -pub struct IDData { - // Regroups the hashes of all the data groups plus some padding - // at the start and in between each data group hashes - pub e_content: [u8; 700], - pub e_content_size: u32, - // Where we can find e_content in the signed_attributes - // It varies from document to document according to the length - // of the padding at the start - pub dg1_offset_in_e_content: u32, - // Last 32 bytes: result of the hash of all the hashes of the data groups - // Rest of the bytes: information about the signature algorithm, date, etc. - pub signed_attributes: [u8; 200], - pub signed_attributes_size: u32, - // The DG1 contains the Machine Readable Zone (MRZ) of the document - // The two lines at the bottom of the passport data page - // or the three bottom lines on the rear of an ID card - // 95 bytes for passports, 93 bytes for ID cards - // Including 88 bytes of MRZ and 5 bytes of padding for passports - // and 90 bytes of MRZ and 5 bytes of padding for ID cards - pub dg1: DG1Data, - // The signature over the data groups - pub sod_signature: [u8; 512], - pub sod_signature_size: u32, -} - -pub struct DSCData { - // The TBS certificate of the DSC - // TBS stands for To Be Signed - pub tbs_certificate: [u8; 1500], - pub tbs_certificate_size: u32, - // The public key of the DSC (up to 512 bytes to account for RSA-4096) - pub pubkey: [u8; 512], - // The actual size of the public key - pub pubkey_size: u32, - // The index of the public key in the TBS certificate - pub pubkey_index: u32, - // Data used to verify the signature - // Generated by the pre-compute function in Rust - // c.f. main.rs - pub pubkey_redc_param: [u8; 513], - // The signature over the TBS certificate - pub signature: [u8; 512], - pub signature_size: u32, - // The exponent of the public key - // Only useful for RSA, can be ignored for ECDSA - pub exponent: u32, -} - -pub struct CSCData { - // The public key of the CSC (up to 512 bytes to account for RSA-4096) - pub pubkey: [u8; 512], - // The actual size of the public key - pub pubkey_size: u32, - // Data used to verify the signature - // Generated by the pre-compute function in Rust - // c.f. main.rs - pub pubkey_redc_param: [u8; 513], - // Only useful for RSA, can be ignored for ECDSA - pub exponent: u32, -} - -pub struct DiscloseFlags { - pub issuing_country: bool, - pub nationality: bool, - pub document_type: bool, - pub document_number: bool, - pub date_of_expiry: bool, - pub date_of_birth: bool, - pub gender: bool, - pub name: bool, -} - -pub struct DisclosedData { - pub issuing_country: [u8; 3], - pub nationality: [u8; 3], - pub document_type: [u8; 2], - pub document_number: [u8; 9], - pub date_of_expiry: [u8; 6], - pub date_of_birth: [u8; 6], - pub name: [u8; 39], - pub gender: [u8; 1], -} - -pub fn get_array_slice(arr: [u8; N], start: u32, end: u32) -> [u8; M] { - let mut slice = [0 as u8; M]; - for i in start..end { - slice[i - start] = arr[i]; - } - slice -} - -pub fn get_array_slice_constant(arr: [u8; N]) -> [u8; M] { - let mut slice = [0 as u8; M]; - for i in 0..M { - slice[i] = arr[i]; - } - slice -} - -// Reverse the bytes of an array so you can switch from -// big endian to little endian order and vice versa -pub fn reverse_bytes_array(arr: [u8; N]) -> [u8; N] { - let mut reversed_arr = [0 as u8; N]; - for i in 0..N { - // Reverse - reversed_arr[i] = arr[N - 1 - i]; - } - reversed_arr -} - -pub fn insert_into_array( - mut arr: [u8; N], - sub_arr: [u8; M], - index: u32, -) -> [u8; N] { - for i in index..index + M { - arr[i] = sub_arr[i - index]; - } - arr -} - -pub fn dynamic_insert_into_array( - mut arr: [u8; N], - sub_arr: [u8; M], - index: u32, - max_size: u32, -) -> [u8; N] { - for i in index..index + max_size { - if i - index < M { - arr[i] = sub_arr[i - index]; - } - } - arr -} - -pub fn is_id_card(dg1: DG1Data) -> bool { - // For passport, the last two bytes are 0 - // since the real length is 93 for passports - // while it is 95 for ID cards - (dg1[93] != 0) & (dg1[94] != 0) -} - -pub fn pack_be_bytes_into_field( - x: [u8; NBytes], -) -> Field { - let mut result: Field = 0; - for i in 0..MAX_FIELD_SIZE { - result *= 256; - result += x[i] as Field; - } - std::as_witness(result); - result -} - -pub fn pack_be_bytes_into_u128s( - x: [u8; NBytes], -) -> [u128; N] { - let mut result = [0 as u128; N]; - - let mut limb: Field = 0; - let mut k = 0; - for _j in 0..(MAX_FIELD_SIZE - (N * MAX_FIELD_SIZE - NBytes)) { - limb *= 256; - limb += x[k] as Field; - k += 1; - } - std::as_witness(limb); - - result[N - 1] = limb as u128; - - for i in 1..N { - let mut limb: Field = 0; - for _j in 0..MAX_FIELD_SIZE { - limb *= 256; - limb += x[k] as Field; - k += 1; - } - std::as_witness(limb); - result[N - i - 1] = limb as u128; - } - - result -} - -pub fn pack_be_bytes_into_fields( - x: [u8; NBytes], -) -> [Field; N] { - let mut result = [0 as Field; N]; - - let mut limb: Field = 0; - let mut k = 0; - for _j in 0..(MAX_FIELD_SIZE - (N * MAX_FIELD_SIZE - NBytes)) { - limb *= 256; - limb += x[k] as Field; - k += 1; - } - std::as_witness(limb); - - result[N - 1] = limb; - - for i in 1..N { - let mut limb: Field = 0; - for _j in 0..MAX_FIELD_SIZE { - limb *= 256; - limb += x[k] as Field; - k += 1; - } - std::as_witness(limb); - result[N - i - 1] = limb; - } - - result -} - -fn pack_le_bytes_into_fields_internal( - x: [u8; NUM_BYTES], -) -> [Field; NUM_FIELDS] { - let mut result = [0 as Field; NUM_FIELDS]; - let mut k = 0; - // Pack all fields in little-endian order - for field_index in 0..NUM_FIELDS { - let remaining_bytes = NUM_BYTES - k; - let chunk_size = if remaining_bytes > BYTES_PER_FIELD { - BYTES_PER_FIELD - } else { - remaining_bytes - }; - let mut limb: Field = 0; - // Pack bytes in little-endian order (reverse the chunk) - for j in 0..chunk_size { - limb *= 256; - limb += x[k + chunk_size - 1 - j] as Field; - } - k += chunk_size; - std::as_witness(limb); - result[field_index] = limb; - } - result -} - -pub fn pack_le_bytes_into_fields( - x: [u8; NUM_BYTES], -) -> [Field; (NUM_BYTES + BYTES_PER_FIELD - 1) / BYTES_PER_FIELD] { - pack_le_bytes_into_fields_internal::( - x, - ) -} - -pub fn get_mrz_from_dg1(dg1: DG1Data) -> MRZData { - let mut mrz: MRZData = [0 as u8; 90]; - for i in 0..90 { - mrz[i] = dg1[i + DG1_TO_MRZ_OFFSET]; - } - mrz -} - -pub fn split_array(array: [u8; N * 2]) -> ([u8; N], [u8; N]) { - let mut array_x = [0 as u8; N]; - let mut array_y = [0 as u8; N]; - for i in 0..N { - array_x[i] = array[i]; - array_y[i] = array[i + N]; - } - (array_x, array_y) -} - -pub fn concat_array(array_x: [u8; N], array_y: [u8; N]) -> [u8; N * 2] { - let mut array = [0 as u8; N * 2]; - for i in 0..N { - array[i] = array_x[i]; - array[i + N] = array_y[i]; - } - array -} - -/** - * Concatenate two arrays (of different sizes) into one array - */ -pub fn array_concat_as_field( - array1: [u8; N], - array2: [u8; M], -) -> [Field; N + M] { - let mut result = [0 as Field; N + M]; - for i in 0..N { - result[i] = array1[i] as Field; - } - for i in 0..M { - result[N + i] = array2[i] as Field; - } - result -} - -pub unconstrained fn _find_subarray_index( - array: [u8; N], - subarray: [u8; M], -) -> u32 { - let mut index = 0; - for i in 0..(N - M + 1) { - let mut found = true; - for j in 0..M { - if array[i + j] != subarray[j] { - found = false; - break; - } - } - if found { - index = i; - break; - } - } - index -} - -pub fn check_zero_padding(padded_array: [T; N], len: u32) -where - T: Eq, - T: Default, -{ - for i in 0..N { - if i >= len { - assert_eq(padded_array[i], T::default()); - } - } -} - -pub fn get_nationality_from_mrz(dg1: DG1Data) -> MRZNationality { - let mrz = get_mrz_from_dg1(dg1); - - let mut country_bytes: MRZNationality = [0; 3]; - - if is_id_card(dg1) { - country_bytes = get_array_slice( - mrz, - ID_CARD_MRZ_NATIONALITY_INDEX, - ID_CARD_MRZ_NATIONALITY_INDEX + ID_CARD_MRZ_COUNTRY_LENGTH, - ); - } else { - country_bytes = get_array_slice( - mrz, - PASSPORT_MRZ_NATIONALITY_INDEX, - PASSPORT_MRZ_NATIONALITY_INDEX + PASSPORT_MRZ_COUNTRY_LENGTH, - ); - } - - // Handle the special case of Germany - if (country_bytes == GERMANY_PASSPORT_CODE) { - country_bytes = GERMANY_ISO_CODE; - } - - country_bytes -} - -pub fn get_issuing_country_from_mrz(dg1: DG1Data) -> MRZIssuingCountry { - let mrz = get_mrz_from_dg1(dg1); - // No need to check if it's an ID card since the issuing country - // is always at the same index for both passports and ID cards - let mut country_bytes = get_array_slice( - mrz, - PASSPORT_MRZ_COUNTRY_INDEX, - PASSPORT_MRZ_COUNTRY_INDEX + PASSPORT_MRZ_COUNTRY_LENGTH, - ); - - // Handle the special case of Germany - if (country_bytes == GERMANY_PASSPORT_CODE) { - country_bytes = GERMANY_ISO_CODE; - } - - country_bytes -} - -/// Get the name from the MRZ -/// -/// Conditionally calls the correct function based on the type of document -pub fn get_name_from_mrz(dg1: DG1Data) -> MRZName { - let mrz = get_mrz_from_dg1(dg1); - if is_id_card(dg1) { - get_name_id_card(mrz) - } else { - get_name_passport(mrz) - } -} - -/// Get the name from the MRZ for a passport -pub fn get_name_passport(mrz: MRZData) -> MRZName { - get_array_slice( - mrz, - PASSPORT_MRZ_NAME_INDEX, - PASSPORT_MRZ_NAME_INDEX + PASSPORT_MRZ_NAME_LENGTH, - ) -} - -/// Get the name from the MRZ for an ID card -pub fn get_name_id_card(mrz: MRZData) -> MRZName { - let mut mrz_name: MRZName = get_array_slice( - mrz, - ID_CARD_MRZ_NAME_INDEX, - ID_CARD_MRZ_NAME_INDEX + ID_CARD_MRZ_NAME_LENGTH, - ); - - // Pad the name with spaces to the length of the MRZ name - for i in 0..(PASSPORT_MRZ_NAME_LENGTH - ID_CARD_MRZ_NAME_LENGTH) { - mrz_name[ID_CARD_MRZ_NAME_LENGTH + i] = ASCII_CODE_FOR_LESS_THAN; - } - - mrz_name -} - -/// Get the date of birth from the MRZ -/// -/// Conditionally calls the correct function based on the type of document -pub fn get_dob_from_mrz(dg1: DG1Data) -> MRZDOB { - let mrz = get_mrz_from_dg1(dg1); - if is_id_card(dg1) { - get_date_of_birth_id_card(mrz) - } else { - get_date_of_birth_passport(mrz) - } -} - -/// Get the date of birth from the MRZ for a passport -pub fn get_date_of_birth_passport(mrz: MRZData) -> MRZDOB { - get_array_slice( - mrz, - PASSPORT_MRZ_BIRTHDATE_INDEX, - PASSPORT_MRZ_BIRTHDATE_INDEX + PASSPORT_MRZ_BIRTHDATE_LENGTH, - ) -} - -/// Get the date of birth from the MRZ for an ID card -pub fn get_date_of_birth_id_card(mrz: MRZData) -> MRZDOB { - get_array_slice( - mrz, - ID_CARD_MRZ_BIRTHDATE_INDEX, - ID_CARD_MRZ_BIRTHDATE_INDEX + ID_CARD_MRZ_BIRTHDATE_LENGTH, - ) -} - -/// Get the year of birth from the MRZ -/// -/// Conditionally calls the correct function based on the type of document -pub fn get_yob_from_mrz(dg1: DG1Data) -> MRZYOB { - let mrz = get_mrz_from_dg1(dg1); - if is_id_card(dg1) { - get_yob_from_mrz_id_card(mrz) - } else { - get_yob_from_mrz_passport(mrz) - } -} - -/// Get the year of birth from the MRZ for an ID card -pub fn get_yob_from_mrz_passport(mrz: MRZData) -> MRZYOB { - get_array_slice( - mrz, - PASSPORT_MRZ_BIRTHDATE_INDEX, - PASSPORT_MRZ_BIRTHDATE_INDEX + PASSPORT_MRZ_YEAR_OF_BIRTH_LENGTH, - ) -} - -/// Get the year of birth from the MRZ for an ID card -pub fn get_yob_from_mrz_id_card(mrz: MRZData) -> MRZYOB { - get_array_slice( - mrz, - ID_CARD_MRZ_BIRTHDATE_INDEX, - ID_CARD_MRZ_BIRTHDATE_INDEX + ID_CARD_MRZ_YEAR_OF_BIRTH_LENGTH, - ) -} - -/// Get the document number from the MRZ -/// -/// Conditionally calls the correct function based on the type of document -pub fn get_document_number_from_mrz(dg1: DG1Data) -> MRZDocumentNumber { - let mrz = get_mrz_from_dg1(dg1); - if is_id_card(dg1) { - get_document_number_id_card(mrz) - } else { - get_document_number_passport(mrz) - } -} - -/// Get the document number from the MRZ for a passport -pub fn get_document_number_passport(mrz: MRZData) -> MRZDocumentNumber { - get_array_slice( - mrz, - PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX, - PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX + PASSPORT_MRZ_DOCUMENT_NUMBER_LENGTH, - ) -} - -/// Get the document number from the MRZ for an ID card -pub fn get_document_number_id_card(mrz: MRZData) -> MRZDocumentNumber { - get_array_slice( - mrz, - ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX, - ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX + ID_CARD_MRZ_DOCUMENT_NUMBER_LENGTH, - ) -} - -/// Get the expiry date from the MRZ -/// -/// Conditionally calls the correct function based on the type of document -pub fn get_expiry_date_from_mrz(dg1: DG1Data) -> MRZExpiryDate { - let mrz = get_mrz_from_dg1(dg1); - if is_id_card(dg1) { - get_expiry_date_id_card(mrz) - } else { - get_expiry_date_passport(mrz) - } -} - -/// Get the expiry date from the MRZ for a passport -pub fn get_expiry_date_passport(mrz: MRZData) -> MRZExpiryDate { - get_array_slice( - mrz, - PASSPORT_MRZ_EXPIRY_DATE_INDEX, - PASSPORT_MRZ_EXPIRY_DATE_INDEX + 6, - ) -} - -/// Get the expiry date from the MRZ for an ID card -pub fn get_expiry_date_id_card(mrz: MRZData) -> MRZExpiryDate { - get_array_slice( - mrz, - ID_CARD_MRZ_EXPIRY_DATE_INDEX, - ID_CARD_MRZ_EXPIRY_DATE_INDEX + 6, - ) -} - -/// Returns total TLV length (tag + length field + content) for any -/// ASN.1 element using DER/BER **definite-length** encoding with a -/// single-byte tag (tag number field < 31) -pub unconstrained fn unsafe_get_asn1_element_length(asn1: [u8; N]) -> u32 { - let tag: u8 = asn1[0]; - let elem_len: u8 = asn1[1]; - - // Need at least tag(1) + length(1) - assert(N >= 2, "TLV too short"); - // Only support single-byte tag number (no high-tag-number 0x1F) - assert((tag & 0x1F) < 0x1F, "High-tag-number form not supported"); - // BER indefinite-length (0x80) is not supported here - assert(elem_len != 0x80, "Indefinite length not supported"); - - // Short form: content length is in low 7 bits - if (elem_len & 0x80) == 0 { - let content_len: u32 = (elem_len & 0x7F) as u32; - let total: u32 = 2 + content_len; - assert(total <= N, "TLV exceeds buffer"); - total - } - // Long form: low 7 bits = number of following length bytes - else { - let nlen: u32 = (elem_len & 0x7F) as u32; - assert(nlen > 0, "Zero length-of-length"); - assert(nlen <= 4, "Length field too large"); - assert(2 + nlen <= N, "Length bytes exceed buffer"); - // Parse big-endian content length - let mut content_len: u32 = 0; - for i in 0..nlen { - content_len = content_len * 256 + (asn1[2 + i] as u32); - } - let total: u32 = 2 + nlen + content_len; - assert(total <= N, "TLV exceeds buffer"); - total - } -} - -/// Find the index of the first occurrence of the needle in the haystack -/// Returns the index of the first occurrence of the needle in the haystack -/// Returns HAYSTACK_SIZE if the needle is not found -pub fn find_subarray_index( - needle: [u8; NEEDLE_SIZE], - haystack: [u8; HAYSTACK_SIZE], -) -> u32 { - // Safety: This is safe because the offset is only used as a starting point - // to verify the substring exists - let offsetUnchecked = unsafe { find_subarray_index_unsafe(needle, haystack) }; - let mut offset = offsetUnchecked; - // Check if offset is valid before attempting verification - if (offsetUnchecked < HAYSTACK_SIZE) & (offsetUnchecked + NEEDLE_SIZE <= HAYSTACK_SIZE) { - for i in 0..NEEDLE_SIZE { - if haystack[i + offsetUnchecked] != needle[i] { - offset = HAYSTACK_SIZE; - } - } - } else { - // If offset is out of bounds, needle was not found - offset = HAYSTACK_SIZE; - } - offset -} - -pub fn is_subarray_in_array( - needle: [u8; NEEDLE_SIZE], - haystack: [u8; HAYSTACK_SIZE], -) -> bool { - find_subarray_index(needle, haystack) < HAYSTACK_SIZE -} - -/// Safety: This is safe because the offset is only used as a starting point -/// to verify the substring exists -pub unconstrained fn find_subarray_index_unsafe( - needle: [u8; NEEDLE_SIZE], - haystack: [u8; HAYSTACK_SIZE], -) -> u32 { - let mut result = HAYSTACK_SIZE; // Default to "not found" value - // Handle edge cases - if NEEDLE_SIZE == 0 { - result = 0; - } else if NEEDLE_SIZE <= HAYSTACK_SIZE { - // Search for the needle in the haystack - for i in 0..(HAYSTACK_SIZE - NEEDLE_SIZE + 1) { - let mut found = true; - for j in 0..NEEDLE_SIZE { - if haystack[i + j] != needle[j] { - found = false; - break; - } - } - if found { - result = i; - break; - } - } - } - result -} \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/shared-utils/compare/age/Nargo.toml b/noir-examples/noir-passport-examples/utils/compare/age/Nargo.toml similarity index 53% rename from noir-examples/noir-passport-examples/shared-utils/compare/age/Nargo.toml rename to noir-examples/noir-passport-examples/utils/compare/age/Nargo.toml index 6008487a4..f15c9af23 100644 --- a/noir-examples/noir-passport-examples/shared-utils/compare/age/Nargo.toml +++ b/noir-examples/noir-passport-examples/utils/compare/age/Nargo.toml @@ -7,6 +7,3 @@ compiler_version = ">=1.0.0" [dependencies] date = { tag = "v0.5.4", git = "https://github.com/madztheo/noir-date.git" } utils = { path = "../../utils" } -# noir_native_sha256 = { path = "../../../noir_native_sha256" } -sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } -poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport-examples/shared-utils/compare/age/src/lib.nr b/noir-examples/noir-passport-examples/utils/compare/age/src/lib.nr similarity index 58% rename from noir-examples/noir-passport-examples/shared-utils/compare/age/src/lib.nr rename to noir-examples/noir-passport-examples/utils/compare/age/src/lib.nr index 2eafa31d6..c0bc5a228 100644 --- a/noir-examples/noir-passport-examples/shared-utils/compare/age/src/lib.nr +++ b/noir-examples/noir-passport-examples/utils/compare/age/src/lib.nr @@ -1,10 +1,8 @@ use date::Date; -use poseidon::poseidon2::Poseidon2; use utils::{ get_array_slice, get_mrz_from_dg1, ID_CARD_MRZ_BIRTHDATE_INDEX, is_id_card, - PASSPORT_MRZ_BIRTHDATE_INDEX, PROOF_TYPE_AGE, + PASSPORT_MRZ_BIRTHDATE_INDEX, }; -use sha256::sha256_var; fn get_birthdate(dg1: [u8; 95], timestamp: u64) -> Date { let mut birthdate_bytes = [0 as u8; 6]; @@ -72,59 +70,3 @@ pub fn compare_age(dg1: [u8; 95], min_age: u8, max_age: u8, timestamp: u64) { ); } } - -/// Calculate the commitment of the current date, min age and max age using Poseidon2 -/// -/// This is less demanding on the prover but much more demanding on EVM verifiers -/// -/// # Arguments -/// -/// * `current_date`: The current date -/// * `min_age_required`: The minimum age required -/// * `max_age_required`: The maximum age required -/// -/// # Returns -/// -/// * `commitment`: The commitment of the current date, min age and max age -pub fn calculate_param_commitment( - timestamp: u64, - min_age_required: u8, - max_age_required: u8, -) -> Field { - let mut params = [0 as Field; 4]; - params[0] = PROOF_TYPE_AGE as Field; - params[1] = timestamp as Field; - params[2] = min_age_required as Field; - params[3] = max_age_required as Field; - Poseidon2::hash(params, 4) -} - -/// Calculate the commitment of the current date, min age and max age using SHA2-256 -/// -/// This is more demanding on the prover but less demanding on EVM verifiers -/// -/// # Arguments -/// -/// * `current_date`: The current date -/// * `min_age_required`: The minimum age required -/// * `max_age_required`: The maximum age required -/// -/// # Returns -/// -/// * `commitment`: The commitment of the current date, min age and max age -pub fn calculate_param_commitment_sha2( - timestamp: u64, - min_age_required: u8, - max_age_required: u8, -) -> Field { - let mut params = [0 as u8; 11]; - params[0] = PROOF_TYPE_AGE; - let timestamp_bytes: [u8; 8] = (timestamp as Field).to_be_bytes(); - for i in 1..9 { - params[i] = timestamp_bytes[i - 1]; - } - params[9] = min_age_required; - params[10] = max_age_required; - let hash = sha256_var(params, 11); - utils::pack_be_bytes_into_field::<32, 31>(hash) -} diff --git a/noir-examples/noir-passport-examples/shared-utils/data-check/expiry/Nargo.toml b/noir-examples/noir-passport-examples/utils/data-check/expiry/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/data-check/expiry/Nargo.toml rename to noir-examples/noir-passport-examples/utils/data-check/expiry/Nargo.toml diff --git a/noir-examples/noir-passport-examples/shared-utils/data-check/expiry/src/lib.nr b/noir-examples/noir-passport-examples/utils/data-check/expiry/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/data-check/expiry/src/lib.nr rename to noir-examples/noir-passport-examples/utils/data-check/expiry/src/lib.nr diff --git a/noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/Nargo.toml b/noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/data-check/tbs-pubkey/Nargo.toml rename to noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/src/lib.nr new file mode 100644 index 000000000..2565c4397 --- /dev/null +++ b/noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/src/lib.nr @@ -0,0 +1,13 @@ +pub fn verify_rsa_pubkey_in_tbs( + dsc_pubkey: [u8; DSC_KEY_SIZE], + tbs_certificate: [u8; TBS_CERT_SIZE], + pubkey_offset: u32, +) { + // Check that the public key of the DSC is the same as the one in the TBS certificate. + // And since the TBS certificate is the data signed by the private key of the CSCA certificate + // we can make sure the DSC, which signed the data of the passport, has been signed by the + // root certificate of the issuing State (i.e. CSCA certificate) by verifying the signature below + for i in 0..DSC_KEY_SIZE { + assert(tbs_certificate[i + pubkey_offset] == dsc_pubkey[i]); + } +} diff --git a/noir-examples/noir-passport-examples/shared-utils/sig-check/common/Nargo.toml b/noir-examples/noir-passport-examples/utils/sig-check/common/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/sig-check/common/Nargo.toml rename to noir-examples/noir-passport-examples/utils/sig-check/common/Nargo.toml diff --git a/noir-examples/noir-passport-examples/shared-utils/sig-check/common/src/lib.nr b/noir-examples/noir-passport-examples/utils/sig-check/common/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/sig-check/common/src/lib.nr rename to noir-examples/noir-passport-examples/utils/sig-check/common/src/lib.nr diff --git a/noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport-examples/utils/sig-check/rsa/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/Nargo.toml rename to noir-examples/noir-passport-examples/utils/sig-check/rsa/Nargo.toml diff --git a/noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport-examples/utils/sig-check/rsa/src/lib.nr similarity index 75% rename from noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/src/lib.nr rename to noir-examples/noir-passport-examples/utils/sig-check/rsa/src/lib.nr index 6f6128d96..86a8c03d5 100644 --- a/noir-examples/noir-passport-examples/shared-utils/sig-check/rsa/src/lib.nr +++ b/noir-examples/noir-passport-examples/utils/sig-check/rsa/src/lib.nr @@ -70,29 +70,3 @@ pub fn verify_signature( - pubkey_bytes: [u8; SIG_BYTES], - sig_bytes: [u8; (((SIG_BYTES * 8) + 7) / 8)], - redc_param_bytes: [u8; SIG_BYTES + 1], - exponent: u32, - msg_hash: [u8; 32] // Pre-computed SHA256 hash -) -> bool { - assert( - (SIG_BYTES == 768) - | (SIG_BYTES == 512) - | (SIG_BYTES == 384) - | (SIG_BYTES == 256) - | (SIG_BYTES == 128), - "Only modulus of bit size 1024, 2048, 3072, 4096 and 6144 are supported", - ); - - let pubkey = - utils::pack_be_bytes_into_u128s::(pubkey_bytes); - let redc_param = utils::pack_be_bytes_into_u128s::(redc_param_bytes); - let params = BigNumParams::new(false, pubkey, redc_param); - - let signature = RuntimeBigNum::from_be_bytes(params, sig_bytes); - verify_sha256_pkcs1v15::<_, SIG_BYTES * 8>(msg_hash, signature, exponent) -} diff --git a/noir-examples/noir-passport-examples/shared-utils/utils/Nargo.toml b/noir-examples/noir-passport-examples/utils/utils/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/shared-utils/utils/Nargo.toml rename to noir-examples/noir-passport-examples/utils/utils/Nargo.toml diff --git a/noir-examples/noir-passport-examples/shared-utils/utils/src/constants.nr b/noir-examples/noir-passport-examples/utils/utils/src/constants.nr similarity index 54% rename from noir-examples/noir-passport-examples/shared-utils/utils/src/constants.nr rename to noir-examples/noir-passport-examples/utils/utils/src/constants.nr index 0e613aa41..9732da4ac 100644 --- a/noir-examples/noir-passport-examples/shared-utils/utils/src/constants.nr +++ b/noir-examples/noir-passport-examples/utils/utils/src/constants.nr @@ -1,8 +1,3 @@ -pub global SHA256_DIGEST_LENGTH: u32 = 32; -pub global PASSPORT_DG1_LENGTH: u32 = 93; -pub global ID_CARD_DG1_LENGTH: u32 = 95; -pub global YYMMDD_DATE_LENGTH: u32 = 6; - // Nullifier types pub global NON_SALTED_NULLIFIER: Field = 0; pub global SALTED_NULLIFIER: Field = 1; diff --git a/noir-examples/noir-passport-examples/utils/utils/src/lib.nr b/noir-examples/noir-passport-examples/utils/utils/src/lib.nr new file mode 100644 index 000000000..5b60b92dd --- /dev/null +++ b/noir-examples/noir-passport-examples/utils/utils/src/lib.nr @@ -0,0 +1,227 @@ +/** +* The standards for passports and any other travel documents, electronic or not, +* are defined in the ICAO (International Civil Aviation Organization) 9303 document available here: +* https://www.icao.int/publications/pages/publication.aspx?docnum=9303 +*/ +pub mod tests; +pub mod types; +pub mod constants; + +/** +* The structure of the MRZ is well defined and standardized by the ICAO +* so the index will always be the same for every passport +* c.f. ICAO 9303-4, Appendix B +*/ + +use types::{DG1Data, MRZData, MRZIssuingCountry}; + +// Index for the country of issuance of the passport +pub global PASSPORT_MRZ_COUNTRY_INDEX: u32 = 2; +// Length of the country code in the MRZ +pub global PASSPORT_MRZ_COUNTRY_LENGTH: u32 = 3; +// Index for the date of expiry (YYMMDD) +pub global PASSPORT_MRZ_EXPIRY_DATE_INDEX: u32 = 65; +// Index for the date of birth (YYMMDD) in TD1 (i.e. passport) MRZ +pub global PASSPORT_MRZ_BIRTHDATE_INDEX: u32 = 57; + +// Index for the date of expiry (YYMMDD) +pub global ID_CARD_MRZ_EXPIRY_DATE_INDEX: u32 = 38; +// Index for the date of birth (YYMMDD) in TD3 (i.e. ID cards) MRZ +pub global ID_CARD_MRZ_BIRTHDATE_INDEX: u32 = 30; + +// Proof type to identify the circuit used for a given parameter commitment +pub global PROOF_TYPE_AGE: u8 = 1; + +// D<< +global GERMANY_PASSPORT_CODE: [u8; 3] = [68, 60, 60]; +// DEU +global GERMANY_ISO_CODE: [u8; 3] = [68, 69, 85]; + +/// Offset of the MRZ in the DG1 +pub global DG1_TO_MRZ_OFFSET: u32 = 5; + +pub fn get_array_slice(arr: [u8; N], start: u32, end: u32) -> [u8; M] { + let mut slice = [0 as u8; M]; + for i in start..end { + slice[i - start] = arr[i]; + } + slice +} + +pub fn is_id_card(dg1: DG1Data) -> bool { + // For passport, the last two bytes are 0 + // since the real length is 93 for passports + // while it is 95 for ID cards + (dg1[93] != 0) & (dg1[94] != 0) +} + +pub fn pack_be_bytes_into_field( + x: [u8; NBytes], +) -> Field { + let mut result: Field = 0; + for i in 0..MAX_FIELD_SIZE { + result *= 256; + result += x[i] as Field; + } + std::as_witness(result); + result +} + +pub fn pack_be_bytes_into_u128s( + x: [u8; NBytes], +) -> [u128; N] { + let mut result = [0 as u128; N]; + + let mut limb: Field = 0; + let mut k = 0; + for _j in 0..(MAX_FIELD_SIZE - (N * MAX_FIELD_SIZE - NBytes)) { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + + result[N - 1] = limb as u128; + + for i in 1..N { + let mut limb: Field = 0; + for _j in 0..MAX_FIELD_SIZE { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + result[N - i - 1] = limb as u128; + } + + result +} + +pub fn pack_be_bytes_into_fields( + x: [u8; NBytes], +) -> [Field; N] { + let mut result = [0 as Field; N]; + + let mut limb: Field = 0; + let mut k = 0; + for _j in 0..(MAX_FIELD_SIZE - (N * MAX_FIELD_SIZE - NBytes)) { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + + result[N - 1] = limb; + + for i in 1..N { + let mut limb: Field = 0; + for _j in 0..MAX_FIELD_SIZE { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + result[N - i - 1] = limb; + } + + result +} + +pub fn get_mrz_from_dg1(dg1: DG1Data) -> MRZData { + let mut mrz: MRZData = [0 as u8; 90]; + for i in 0..90 { + mrz[i] = dg1[i + DG1_TO_MRZ_OFFSET]; + } + mrz +} + +pub fn check_zero_padding(padded_array: [T; N], len: u32) +where + T: Eq, + T: Default, +{ + for i in 0..N { + if i >= len { + assert_eq(padded_array[i], T::default()); + } + } +} + +pub fn get_issuing_country_from_mrz(dg1: DG1Data) -> MRZIssuingCountry { + let mrz = get_mrz_from_dg1(dg1); + // No need to check if it's an ID card since the issuing country + // is always at the same index for both passports and ID cards + let mut country_bytes = get_array_slice( + mrz, + PASSPORT_MRZ_COUNTRY_INDEX, + PASSPORT_MRZ_COUNTRY_INDEX + PASSPORT_MRZ_COUNTRY_LENGTH, + ); + + // Handle the special case of Germany + if (country_bytes == GERMANY_PASSPORT_CODE) { + country_bytes = GERMANY_ISO_CODE; + } + + country_bytes +} + +/// Find the index of the first occurrence of the needle in the haystack +/// Returns the index of the first occurrence of the needle in the haystack +/// Returns HAYSTACK_SIZE if the needle is not found +pub fn find_subarray_index( + needle: [u8; NEEDLE_SIZE], + haystack: [u8; HAYSTACK_SIZE], +) -> u32 { + // Safety: This is safe because the offset is only used as a starting point + // to verify the substring exists + let offsetUnchecked = unsafe { find_subarray_index_unsafe(needle, haystack) }; + let mut offset = offsetUnchecked; + // Check if offset is valid before attempting verification + if (offsetUnchecked < HAYSTACK_SIZE) & (offsetUnchecked + NEEDLE_SIZE <= HAYSTACK_SIZE) { + for i in 0..NEEDLE_SIZE { + if haystack[i + offsetUnchecked] != needle[i] { + offset = HAYSTACK_SIZE; + } + } + } else { + // If offset is out of bounds, needle was not found + offset = HAYSTACK_SIZE; + } + offset +} + +pub fn is_subarray_in_array( + needle: [u8; NEEDLE_SIZE], + haystack: [u8; HAYSTACK_SIZE], +) -> bool { + find_subarray_index(needle, haystack) < HAYSTACK_SIZE +} + +/// Safety: This is safe because the offset is only used as a starting point +/// to verify the substring exists +pub unconstrained fn find_subarray_index_unsafe( + needle: [u8; NEEDLE_SIZE], + haystack: [u8; HAYSTACK_SIZE], +) -> u32 { + let mut result = HAYSTACK_SIZE; // Default to "not found" value + // Handle edge cases + if NEEDLE_SIZE == 0 { + result = 0; + } else if NEEDLE_SIZE <= HAYSTACK_SIZE { + // Search for the needle in the haystack + for i in 0..(HAYSTACK_SIZE - NEEDLE_SIZE + 1) { + let mut found = true; + for j in 0..NEEDLE_SIZE { + if haystack[i + j] != needle[j] { + found = false; + break; + } + } + if found { + result = i; + break; + } + } + } + result +} diff --git a/noir-examples/noir-passport-examples/shared-utils/utils/src/tests.nr b/noir-examples/noir-passport-examples/utils/utils/src/tests.nr similarity index 55% rename from noir-examples/noir-passport-examples/shared-utils/utils/src/tests.nr rename to noir-examples/noir-passport-examples/utils/utils/src/tests.nr index 007f0e6a5..ad2af3b25 100644 --- a/noir-examples/noir-passport-examples/shared-utils/utils/src/tests.nr +++ b/noir-examples/noir-passport-examples/utils/utils/src/tests.nr @@ -1,117 +1,4 @@ -use crate::{ - find_subarray_index, pack_be_bytes_into_fields, pack_be_bytes_into_u128s, - unsafe_get_asn1_element_length, -}; - -use super::{ - DG1_TO_MRZ_OFFSET, get_mrz_from_dg1, get_name_from_mrz, ID_CARD_MRZ_BIRTHDATE_INDEX, - ID_CARD_MRZ_BIRTHDATE_LENGTH, ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX, - ID_CARD_MRZ_DOCUMENT_NUMBER_LENGTH, ID_CARD_MRZ_NAME_INDEX, ID_CARD_MRZ_NAME_LENGTH, - ID_CARD_MRZ_NATIONALITY_INDEX, PASSPORT_MRZ_BIRTHDATE_INDEX, PASSPORT_MRZ_BIRTHDATE_LENGTH, - PASSPORT_MRZ_COUNTRY_INDEX, PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX, - PASSPORT_MRZ_DOCUMENT_NUMBER_LENGTH, PASSPORT_MRZ_NAME_INDEX, PASSPORT_MRZ_NAME_LENGTH, - PASSPORT_MRZ_NATIONALITY_INDEX, -}; -use super::types::{ - DG1Data, MRZData, MRZDOB, MRZDocumentNumber, MRZName, MRZNameIdCard, MRZNationality, -}; - -// Testing utilities - -/// DG1 Builder -/// Usage: -/// ```nr -/// let dg1 = DG1Builder::new([0; 95]) -/// .with_document_number([68, 60, 60, etc...]) -/// .with_name([68, 60, 60]) -/// .with_dob([68, 60, 60]) -/// .build(); -pub struct DG1Builder { - dg1: DG1Data, -} - -impl DG1Builder { - pub fn new(dg1: DG1Data) -> Self { - Self { dg1 } - } - - pub fn build(mut self: Self) -> DG1Data { - self.dg1 - } - - pub fn build_mrz(mut self: Self) -> MRZData { - get_mrz_from_dg1(self.dg1) - } - - pub fn is_id_card(mut self: Self) -> Self { - // Set the last two bytes to NON 0 to indicate an ID card - self.dg1[93] = 1; - self.dg1[94] = 1; - self - } - - pub fn with_country_code(mut self: Self, country_code: MRZNationality) -> Self { - for i in 0..3 { - // + 5 as it goes through an mrz decoding - self.dg1[PASSPORT_MRZ_NATIONALITY_INDEX + i + DG1_TO_MRZ_OFFSET] = country_code[i]; - self.dg1[PASSPORT_MRZ_COUNTRY_INDEX + i + DG1_TO_MRZ_OFFSET] = country_code[i]; - } - self - } - - pub fn with_country_code_id_card(mut self: Self, country_code: MRZNationality) -> Self { - for i in 0..3 { - self.dg1[ID_CARD_MRZ_NATIONALITY_INDEX + i + DG1_TO_MRZ_OFFSET] = country_code[i]; - } - self - } - - pub fn with_document_number(mut self: Self, document_number: MRZDocumentNumber) -> Self { - for i in 0..PASSPORT_MRZ_DOCUMENT_NUMBER_LENGTH { - self.dg1[PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX + i + 5] = document_number[i]; - } - self - } - - pub fn with_document_number_id_card( - mut self: Self, - document_number: MRZDocumentNumber, - ) -> Self { - for i in 0..ID_CARD_MRZ_DOCUMENT_NUMBER_LENGTH { - self.dg1[ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX + i + DG1_TO_MRZ_OFFSET] = - document_number[i]; - } - self - } - - pub fn with_name(mut self: Self, name: MRZName) -> Self { - for i in 0..PASSPORT_MRZ_NAME_LENGTH { - self.dg1[PASSPORT_MRZ_NAME_INDEX + i + DG1_TO_MRZ_OFFSET] = name[i]; - } - self - } - - pub fn with_name_id_card(mut self: Self, name: MRZNameIdCard) -> Self { - for i in 0..ID_CARD_MRZ_NAME_LENGTH { - self.dg1[ID_CARD_MRZ_NAME_INDEX + i + DG1_TO_MRZ_OFFSET] = name[i]; - } - self - } - - pub fn with_dob(mut self: Self, dob: MRZDOB) -> Self { - for i in 0..PASSPORT_MRZ_BIRTHDATE_LENGTH { - self.dg1[PASSPORT_MRZ_BIRTHDATE_INDEX + i + DG1_TO_MRZ_OFFSET] = dob[i]; - } - self - } - - pub fn with_dob_id_card(mut self: Self, dob: MRZDOB) -> Self { - for i in 0..ID_CARD_MRZ_BIRTHDATE_LENGTH { - self.dg1[ID_CARD_MRZ_BIRTHDATE_INDEX + i + DG1_TO_MRZ_OFFSET] = dob[i]; - } - self - } -} +use crate::{find_subarray_index, pack_be_bytes_into_fields, pack_be_bytes_into_u128s}; #[test] fn test_pack_be_bytes_into_u128() { @@ -262,59 +149,6 @@ global TEST_BYTES: [u8; 512] = [ 0x93, 0xa9, 0x06, 0xa6, 0xbf, 0x52, 0xc2, 0xd3, 0xb6, 0xdc, 0xc3, 0xe5, 0x3e, 0x8d, 0xf2, 0xc2, ]; -#[test] -fn test_unsafe_get_asn1_element_length() { - let long_form_asn1_seq: [u8; _] = [ - 0x30, 0x82, 0x01, 0xc8, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x09, 0xba, 0xc5, 0xe1, - 0xbc, 0x40, 0x1a, 0xd9, 0xd4, 0x53, 0x95, 0xbc, 0x38, 0x1a, 0x08, 0x54, 0x30, 0x0a, 0x06, - 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x03, 0x30, 0x52, 0x31, 0x26, 0x30, 0x24, - 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1d, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x41, 0x70, - 0x70, 0x20, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x52, - 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, - 0x0c, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x13, 0x30, - 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, - 0x6e, 0x69, 0x61, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x33, 0x31, 0x38, 0x31, 0x38, - 0x33, 0x39, 0x35, 0x35, 0x5a, 0x17, 0x0d, 0x33, 0x30, 0x30, 0x33, 0x31, 0x33, 0x30, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x5a, 0x30, 0x4f, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, - 0x03, 0x0c, 0x1a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x41, 0x70, 0x70, 0x20, 0x41, 0x74, - 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x43, 0x41, 0x20, 0x31, 0x31, - 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, - 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, - 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x30, 0x76, 0x30, 0x10, - 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, - 0x22, 0x03, 0x62, 0x00, 0x04, 0xae, 0x5b, 0x37, 0xa0, 0x77, 0x4d, 0x79, 0xb2, 0x35, 0x8f, - 0x40, 0xe7, 0xd1, 0xf2, 0x26, 0x26, 0xf1, 0xc2, 0x5f, 0xef, 0x17, 0x80, 0x2d, 0xea, 0xb3, - 0x82, 0x6a, 0x59, 0x87, 0x4f, 0xf8, 0xd2, 0xad, 0x15, 0x25, 0x78, 0x9a, 0xa2, 0x66, 0x04, - 0x19, 0x12, 0x48, 0xb6, 0x3c, 0xb9, 0x67, 0x06, 0x9e, 0x98, 0xd3, 0x63, 0xbd, 0x5e, 0x37, - 0x0f, 0xbf, 0xa0, 0x8e, 0x32, 0x9e, 0x80, 0x73, 0xa9, 0x85, 0xe7, 0x74, 0x6e, 0xa3, 0x59, - 0xa2, 0xf6, 0x6f, 0x29, 0xdb, 0x32, 0xaf, 0x45, 0x5e, 0x21, 0x16, 0x58, 0xd5, 0x67, 0xaf, - 0x9e, 0x26, 0x7e, 0xb2, 0x61, 0x4d, 0xc2, 0x1a, 0x66, 0xce, 0x99, 0xa3, 0x66, 0x30, 0x64, - 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, - 0x01, 0xff, 0x02, 0x01, 0x00, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, - 0x16, 0x80, 0x14, 0xac, 0x91, 0x10, 0x53, 0x33, 0xbd, 0xbe, 0x68, 0x41, 0xff, 0xa7, 0x0c, - 0xa9, 0xe5, 0xfa, 0xea, 0xe5, 0xe5, 0x8a, 0xa1, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, - 0x04, 0x16, 0x04, 0x14, 0x3e, 0xe3, 0x5d, 0x1c, 0x04, 0x19, 0xa9, 0xc9, 0xb4, 0x31, 0xf8, - 0x84, 0x74, 0xd6, 0xe1, 0xe1, 0x57, 0x72, 0xe3, 0x9b, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, - 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - ]; - // 0x30 0x03 = SEQUENCE with 3 bytes of content - // Total length should be 5 (tag + length + content) - let short_form_asn1_seq: [u8; 10] = - [0x30, 0x03, 0x01, 0x01, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00]; - - // Test with a long form example - // Safety: - let len = unsafe { unsafe_get_asn1_element_length(long_form_asn1_seq) }; - assert(len == 460); - // Test with a short form example - // Safety: - let short_parsed_length = unsafe { unsafe_get_asn1_element_length(short_form_asn1_seq) }; - assert(short_parsed_length == 5); -} - #[test] fn test_find_substring_index_various_cases() { // Test case 1: Basic substring at index 3 @@ -377,49 +211,3 @@ fn test_find_substring_index_various_cases() { let index10 = find_subarray_index(needle10, haystack10); assert_eq(index10, haystack10.len()); // Should equal haystack size } - -pub fn verify_substring_in_string( - needle: [u8; NEEDLE_SIZE], - haystack: [u8; HAYSTACK_SIZE], -) { - let offset = find_subarray_index(needle, haystack); - assert(offset < HAYSTACK_SIZE, "Needle not found in haystack") -} - -#[test] -fn test_verify_substring_in_string() { - let needle = [0x04, 0x05, 0x06]; - let haystack = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a]; - verify_substring_in_string(needle, haystack); -} - -#[test] -fn test_get_name_passport() { - // name = 'Doe<; -pub type Alpha2CountryCode = str<2>; // Hash digest types -pub type SHA1Digest = [u8; 20]; -pub type SHA224Digest = [u8; 28]; pub type SHA256Digest = [u8; 32]; -pub type SHA384Digest = [u8; 48]; -pub type SHA512Digest = [u8; 64]; // eContent and SignedAttrs types pub type EContentData = [u8; 200]; @@ -141,4 +130,4 @@ impl SaltedValue<[u8; N]> { Poseidon2::hash([self.salt].concat(packed_value), (N + 30) / 31 + 1) } } -} \ No newline at end of file +} diff --git a/noir-examples/partial_sha256/Nargo.toml b/noir-examples/partial_sha256/Nargo.toml index 348383312..e1a7418bf 100644 --- a/noir-examples/partial_sha256/Nargo.toml +++ b/noir-examples/partial_sha256/Nargo.toml @@ -4,6 +4,6 @@ type = "lib" compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../noir-passport-examples/zkpassport_libs/utils" } +utils = { path = "../noir-passport-examples/utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } From 10cc9635181912e7de89bbf65170fab02ea5b431 Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 01:01:49 +0530 Subject: [PATCH 03/15] updated readme --- .../fragmented/merkle_age_check/README.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md index 73808dd87..16d356833 100644 --- a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md +++ b/noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md @@ -39,3 +39,37 @@ The `t_attest` circuit provides fast, repeatable proofs: - Proves Merkle tree membership - Verifies age requirements - Generates service-scoped nullifiers for Sybil resistance + +## Usage + +Benchmark inputs have already been generated and are available in the `benchmark-inputs` directory. + +Scripts are provided separately for Case 1 (4-circuit chain) and Case 2 (5-circuit chain). Navigate to the scripts directory and run the appropriate sequence: + +```bash +cd scripts +``` + +### For Case 1 (TBS < 720 bytes): +```bash +# 1. Compile circuits +./case1/compile.sh + +# 2. Prepare proving artifacts +./case1/prepare.sh + +# 3. Generate proofs +./case1/prove.sh +``` + +### For Case 2 (TBS >= 720 bytes): +```bash +# 1. Compile circuits +./case2/compile.sh + +# 2. Prepare proving artifacts +./case2/prepare.sh + +# 3. Generate proofs +./case2/prove.sh +``` \ No newline at end of file From 8a42e8b94abffac0c7d4c1ce86e4799cc341e58f Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 01:29:50 +0530 Subject: [PATCH 04/15] ci checks --- .github/workflows/circuit_keys.yml | 81 ++++++++++++++++++++++-------- .github/workflows/end-to-end.yml | 49 ++++++++++++++---- 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/.github/workflows/circuit_keys.yml b/.github/workflows/circuit_keys.yml index 3c4914bdc..09b1b8166 100644 --- a/.github/workflows/circuit_keys.yml +++ b/.github/workflows/circuit_keys.yml @@ -5,9 +5,9 @@ on: env: BUCKET_NAME: "provekit" - CIRCUIT_NAME: "complete_age_check" - CIRCUIT_DIR: "noir-examples/noir-passport-examples/complete_age_check" + CIRCUIT_DIR: "noir-examples/noir-passport-examples/fragmented/merkle_age_check" KEYS_NAME: "agecheck" + CIRCUITS: "t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest" permissions: @@ -45,19 +45,46 @@ jobs: with: toolchain: v1.0.0-beta.11 - - name: Compile and execute Nargo circuit + - name: Compile Nargo circuits working-directory: ${{ env.CIRCUIT_DIR }} run: | - nargo compile --skip-brillig-constraints-check --force + for circuit in ${{ env.CIRCUITS }}; do + echo "Compiling $circuit" + nargo compile --force --print-acir --package "$circuit" + echo "Compiled $circuit" + done - - name: Generate Gnark inputs + - name: Prepare circuits (generate proving artifacts) working-directory: ${{ env.CIRCUIT_DIR }} run: | - cargo run --release --bin provekit-cli prepare ./target/${{ env.CIRCUIT_NAME }}.json -p ./noir-provekit-prover.pkp -v ./noir-provekit-verifier.pkv - cargo run --release --bin provekit-cli prove ./noir-provekit-prover.pkp ./Prover.toml -o ./noir-proof.np - cargo run --release --bin provekit-cli generate-gnark-inputs ./noir-provekit-prover.pkp ./noir-proof.np + for circuit in ${{ env.CIRCUITS }}; do + echo "Preparing $circuit" + cargo run --release --bin provekit-cli prepare ./target/$circuit.json \ + --pkp ./benchmark-inputs/$circuit-prover.pkp \ + --pkv ./benchmark-inputs/$circuit-verifier.pkv + echo "Prepared $circuit" + done + + - name: Generate proofs for all circuits + working-directory: ${{ env.CIRCUIT_DIR }} + run: | + for circuit in ${{ env.CIRCUITS }}; do + echo "Proving $circuit" + cargo run --release --bin provekit-cli prove \ + ./benchmark-inputs/$circuit-prover.pkp \ + ./benchmark-inputs/case1/$circuit.toml \ + -o ./benchmark-inputs/$circuit-proof.np + echo "Proved $circuit" + done + + - name: Generate Gnark inputs (t_attest only) + working-directory: ${{ env.CIRCUIT_DIR }} + run: | + cargo run --release --bin provekit-cli generate-gnark-inputs \ + ./benchmark-inputs/t_attest-prover.pkp \ + ./benchmark-inputs/t_attest-proof.np - - name: Run Gnark verifier + - name: Run Gnark verifier working-directory: recursive-verifier run: | go run cmd/cli/main.go --config "../${{ env.CIRCUIT_DIR }}/params_for_recursive_verifier" --r1cs "../${{ env.CIRCUIT_DIR }}/r1cs.json" --saveKeys "./keys" @@ -67,28 +94,42 @@ jobs: run: | ls -la ./keys/*.bin || echo "No keys" - - name: Upload keys to gcp + - name: Upload keys to gcp working-directory: recursive-verifier run: | + # Upload Gnark verifier keys for t_attest PK_FILE=$(ls -t ./keys/pk_*.bin 2>/dev/null | head -1) VK_FILE=$(ls -t ./keys/vk_*.bin 2>/dev/null | head -1) if [ -z "$PK_FILE" ] || [ -z "$VK_FILE" ]; then - echo "Error: Could not find keys" + echo "Error: Could not find Gnark keys" exit 1 fi - + echo "Found PK file: $PK_FILE" echo "Found VK file: $VK_FILE" - AGE_CHECK_PK_NAME="${{ env.KEYS_NAME }}_$(basename "$PK_FILE")" - AGE_CHECK_VK_NAME="${{ env.KEYS_NAME }}_$(basename "$VK_FILE")" - - echo "Uploading PK as: $AGE_CHECK_PK_NAME" - echo "Uploading VK as: $AGE_CHECK_VK_NAME" - - gsutil cp "$PK_FILE" "gs://${{ env.BUCKET_NAME }}/$AGE_CHECK_PK_NAME" - gsutil cp "$VK_FILE" "gs://${{ env.BUCKET_NAME }}/$AGE_CHECK_VK_NAME" + ATTEST_PK_NAME="${{ env.KEYS_NAME }}_t_attest_$(basename "$PK_FILE")" + ATTEST_VK_NAME="${{ env.KEYS_NAME }}_t_attest_$(basename "$VK_FILE")" + + echo "Uploading PK as: $ATTEST_PK_NAME" + echo "Uploading VK as: $ATTEST_VK_NAME" + + gsutil cp "$PK_FILE" "gs://${{ env.BUCKET_NAME }}/$ATTEST_PK_NAME" + gsutil cp "$VK_FILE" "gs://${{ env.BUCKET_NAME }}/$ATTEST_VK_NAME" + + # Upload Noir prover/verifier keys for all 4 circuits + cd "../${{ env.CIRCUIT_DIR }}" + for circuit in ${{ env.CIRCUITS }}; do + if [ -f "./benchmark-inputs/${circuit}-prover.pkp" ]; then + echo "Uploading ${circuit} prover key" + gsutil cp "./benchmark-inputs/${circuit}-prover.pkp" "gs://${{ env.BUCKET_NAME }}/${{ env.KEYS_NAME }}_${circuit}-prover.pkp" + fi + if [ -f "./benchmark-inputs/${circuit}-verifier.pkv" ]; then + echo "Uploading ${circuit} verifier key" + gsutil cp "./benchmark-inputs/${circuit}-verifier.pkv" "gs://${{ env.BUCKET_NAME }}/${{ env.KEYS_NAME }}_${circuit}-verifier.pkv" + fi + done - name: Cleanup local files working-directory: recursive-verifier diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 6023f4904..fecdd0d6e 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -43,19 +43,46 @@ jobs: with: go-version: 1.24 - - name: Compile and execute Nargo circuit - working-directory: noir-examples/noir-passport-examples/complete_age_check + - name: Compile Nargo circuits + working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check run: | - nargo compile --skip-brillig-constraints-check --force + for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do + echo "Compiling $circuit" + nargo compile --force --print-acir --package "$circuit" + echo "Compiled $circuit" + done - - name: Generate Gnark inputs - working-directory: noir-examples/noir-passport-examples/complete_age_check + - name: Prepare circuits + working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check run: | - cargo run --release --bin provekit-cli prepare ./target/complete_age_check.json -p ./noir-provekit-prover.pkp -v ./noir-provekit-verifier.pkv - cargo run --release --bin provekit-cli prove ./noir-provekit-prover.pkp ./Prover.toml -o ./noir-proof.np - cargo run --release --bin provekit-cli generate-gnark-inputs ./noir-provekit-prover.pkp ./noir-proof.np + for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do + echo "Preparing $circuit" + cargo run --release --bin provekit-cli prepare ./target/$circuit.json \ + --pkp ./benchmark-inputs/$circuit-prover.pkp \ + --pkv ./benchmark-inputs/$circuit-verifier.pkv + echo "Prepared $circuit" + done + + - name: Generate proofs for all circuits + working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check + run: | + for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do + echo "Proving $circuit" + cargo run --release --bin provekit-cli prove \ + ./benchmark-inputs/$circuit-prover.pkp \ + ./benchmark-inputs/case1/$circuit.toml \ + -o ./benchmark-inputs/$circuit-proof.np + echo "Proved $circuit" + done + + - name: Generate Gnark inputs + working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check + run: | + cargo run --release --bin provekit-cli generate-gnark-inputs \ + ./benchmark-inputs/t_attest-prover.pkp \ + ./benchmark-inputs/t_attest-proof.np - - name: Run Gnark verifier + - name: Run Gnark verifier working-directory: recursive-verifier run: | go build -o gnark-verifier cmd/cli/main.go @@ -84,8 +111,8 @@ jobs: ) & MONITOR_PID=$! - # Run the main process - ./gnark-verifier --config "../noir-examples/noir-passport-examples/complete_age_check/params_for_recursive_verifier" --r1cs "../noir-examples/noir-passport-examples/complete_age_check/r1cs.json" + # Run the main process + ./gnark-verifier --config "../noir-examples/noir-passport-examples/fragmented/merkle_age_check/params_for_recursive_verifier" --r1cs "../noir-examples/noir-passport-examples/fragmented/merkle_age_check/r1cs.json" # Stop monitoring kill $MONITOR_PID \ No newline at end of file From 2b485e4dd3d7b4607dc2f93c23803db188e799c2 Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 01:51:47 +0530 Subject: [PATCH 05/15] renamed directories to noir-passport and noir-passport-monolithic --- .github/workflows/circuit_keys.yml | 2 +- .github/workflows/end-to-end.yml | 10 +- .../monolithic/complete_age_check/Nargo.toml | 0 .../monolithic/complete_age_check/Prover.toml | 0 .../complete_age_check/scripts/compile.sh | 0 .../monolithic/complete_age_check/src/main.nr | 0 .../utils/passport_validity_check/Nargo.toml | 0 .../utils/passport_validity_check/src/lib.nr | 0 .../utils/compare/age/Nargo.toml | 0 .../utils/compare/age/src/lib.nr | 0 .../utils/data-check/expiry/Nargo.toml | 0 .../utils/data-check/expiry/src/lib.nr | 0 .../utils/data-check/tbs-pubkey/Nargo.toml | 0 .../utils/data-check/tbs-pubkey/src/lib.nr | 0 .../utils/sig-check/common/Nargo.toml | 0 .../utils/sig-check/common/src/lib.nr | 0 .../utils/sig-check/rsa/Nargo.toml | 0 .../utils/sig-check/rsa/src/lib.nr | 0 .../utils/utils/Nargo.toml | 0 .../utils/utils/src/constants.nr | 0 .../utils/utils/src/lib.nr | 0 .../utils/utils/src/tests.nr | 0 .../utils/utils/src/types.nr | 0 .../fragmented/merkle_age_check/Nargo.toml | 0 .../fragmented/merkle_age_check/README.md | 0 .../benchmark-inputs/case1/t_add_dsc_720.toml | 0 .../case1/t_add_id_data_720.toml | 0 .../case1/t_add_integrity_commit.toml | 0 .../benchmark-inputs/case1/t_attest.toml | 0 .../case2/t_add_dsc_hash_1300.toml | 0 .../case2/t_add_dsc_verify_1300.toml | 0 .../case2/t_add_id_data_1300.toml | 0 .../case2/t_add_integrity_commit.toml | 0 .../benchmark-inputs/case2/t_attest.toml | 0 .../scripts/case1/compile-circuits.sh | 0 .../scripts/case1/prepare-circuits.sh | 0 .../scripts/case1/prove-circuits.sh | 0 .../scripts/case2/compile-circuits.sh | 0 .../scripts/case2/prepare-circuits.sh | 0 .../scripts/case2/prove-circuits.sh | 0 .../merkle_age_check/t_add_dsc_720/Nargo.toml | 0 .../t_add_dsc_720/src/main.nr | 0 .../t_add_dsc_hash_1300/Nargo.toml | 0 .../t_add_dsc_hash_1300/src/main.nr | 0 .../t_add_dsc_verify_1300/Nargo.toml | 0 .../t_add_dsc_verify_1300/src/main.nr | 0 .../t_add_id_data_1300/Nargo.toml | 0 .../t_add_id_data_1300/src/main.nr | 0 .../t_add_id_data_720/Nargo.toml | 0 .../t_add_id_data_720/src/main.nr | 0 .../t_add_integrity_commit/Nargo.toml | 0 .../t_add_integrity_commit/src/main.nr | 0 .../merkle_age_check/t_attest/Nargo.toml | 0 .../merkle_age_check/t_attest/src/main.nr | 0 .../utils/commitment/common/Nargo.toml | 0 .../utils/commitment/common/src/lib.nr | 0 .../utils/commitment/dsc-to-id/Nargo.toml | 0 .../utils/commitment/dsc-to-id/src/lib.nr | 0 .../commitment/scoped-nullifier/Nargo.toml | 0 .../commitment/scoped-nullifier/src/lib.nr | 0 .../utils/data-check/integrity/Nargo.toml | 0 .../utils/data-check/integrity/src/lib.nr | 0 .../fragmented/utils/sig-check/rsa/Nargo.toml | 0 .../fragmented/utils/sig-check/rsa/src/lib.nr | 0 .../utils/compare/age/Nargo.toml | 9 + .../utils/compare/age/src/lib.nr | 72 ++++++ .../utils/data-check/expiry/Nargo.toml | 10 + .../utils/data-check/expiry/src/lib.nr | 36 +++ .../utils/data-check/tbs-pubkey/Nargo.toml | 8 + .../utils/data-check/tbs-pubkey/src/lib.nr | 13 + .../utils/sig-check/common/Nargo.toml | 12 + .../utils/sig-check/common/src/lib.nr | 70 ++++++ .../utils/sig-check/rsa/Nargo.toml | 11 + .../utils/sig-check/rsa/src/lib.nr | 72 ++++++ .../noir-passport/utils/utils/Nargo.toml | 8 + .../utils/utils/src/constants.nr | 5 + .../noir-passport/utils/utils/src/lib.nr | 227 ++++++++++++++++++ .../noir-passport/utils/utils/src/tests.nr | 213 ++++++++++++++++ .../noir-passport/utils/utils/src/types.nr | 133 ++++++++++ noir-examples/partial_sha256/Nargo.toml | 2 +- scripts/run_all.sh | 2 +- tooling/provekit-bench/tests/compiler.rs | 2 +- 82 files changed, 908 insertions(+), 9 deletions(-) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/monolithic/complete_age_check/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/monolithic/complete_age_check/Prover.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/monolithic/complete_age_check/scripts/compile.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/monolithic/complete_age_check/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/monolithic/utils/passport_validity_check/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/monolithic/utils/passport_validity_check/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/compare/age/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/compare/age/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/data-check/expiry/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/data-check/expiry/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/data-check/tbs-pubkey/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/data-check/tbs-pubkey/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/sig-check/common/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/sig-check/common/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/sig-check/rsa/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/sig-check/rsa/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/utils/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/utils/src/constants.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/utils/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/utils/src/tests.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport-monolithic}/utils/utils/src/types.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/README.md (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_attest/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/merkle_age_check/t_attest/src/main.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/commitment/common/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/commitment/common/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/commitment/dsc-to-id/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/commitment/dsc-to-id/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/commitment/scoped-nullifier/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/commitment/scoped-nullifier/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/data-check/integrity/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/data-check/integrity/src/lib.nr (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/sig-check/rsa/Nargo.toml (100%) rename noir-examples/{noir-passport-examples => noir-passport}/fragmented/utils/sig-check/rsa/src/lib.nr (100%) create mode 100644 noir-examples/noir-passport/utils/compare/age/Nargo.toml create mode 100644 noir-examples/noir-passport/utils/compare/age/src/lib.nr create mode 100644 noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml create mode 100644 noir-examples/noir-passport/utils/data-check/expiry/src/lib.nr create mode 100644 noir-examples/noir-passport/utils/data-check/tbs-pubkey/Nargo.toml create mode 100644 noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr create mode 100644 noir-examples/noir-passport/utils/sig-check/common/Nargo.toml create mode 100644 noir-examples/noir-passport/utils/sig-check/common/src/lib.nr create mode 100644 noir-examples/noir-passport/utils/sig-check/rsa/Nargo.toml create mode 100644 noir-examples/noir-passport/utils/sig-check/rsa/src/lib.nr create mode 100644 noir-examples/noir-passport/utils/utils/Nargo.toml create mode 100644 noir-examples/noir-passport/utils/utils/src/constants.nr create mode 100644 noir-examples/noir-passport/utils/utils/src/lib.nr create mode 100644 noir-examples/noir-passport/utils/utils/src/tests.nr create mode 100644 noir-examples/noir-passport/utils/utils/src/types.nr diff --git a/.github/workflows/circuit_keys.yml b/.github/workflows/circuit_keys.yml index 09b1b8166..d3ad59d3c 100644 --- a/.github/workflows/circuit_keys.yml +++ b/.github/workflows/circuit_keys.yml @@ -5,7 +5,7 @@ on: env: BUCKET_NAME: "provekit" - CIRCUIT_DIR: "noir-examples/noir-passport-examples/fragmented/merkle_age_check" + CIRCUIT_DIR: "noir-examples/noir-passport/fragmented/merkle_age_check" KEYS_NAME: "agecheck" CIRCUITS: "t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest" diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index fecdd0d6e..fdd759d46 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -44,7 +44,7 @@ jobs: go-version: 1.24 - name: Compile Nargo circuits - working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/fragmented/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Compiling $circuit" @@ -53,7 +53,7 @@ jobs: done - name: Prepare circuits - working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/fragmented/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Preparing $circuit" @@ -64,7 +64,7 @@ jobs: done - name: Generate proofs for all circuits - working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/fragmented/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Proving $circuit" @@ -76,7 +76,7 @@ jobs: done - name: Generate Gnark inputs - working-directory: noir-examples/noir-passport-examples/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/fragmented/merkle_age_check run: | cargo run --release --bin provekit-cli generate-gnark-inputs \ ./benchmark-inputs/t_attest-prover.pkp \ @@ -112,7 +112,7 @@ jobs: MONITOR_PID=$! # Run the main process - ./gnark-verifier --config "../noir-examples/noir-passport-examples/fragmented/merkle_age_check/params_for_recursive_verifier" --r1cs "../noir-examples/noir-passport-examples/fragmented/merkle_age_check/r1cs.json" + ./gnark-verifier --config "../noir-examples/noir-passport/fragmented/merkle_age_check/params_for_recursive_verifier" --r1cs "../noir-examples/noir-passport/fragmented/merkle_age_check/r1cs.json" # Stop monitoring kill $MONITOR_PID \ No newline at end of file diff --git a/noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml b/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/monolithic/complete_age_check/Nargo.toml rename to noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Nargo.toml diff --git a/noir-examples/noir-passport-examples/monolithic/complete_age_check/Prover.toml b/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Prover.toml similarity index 100% rename from noir-examples/noir-passport-examples/monolithic/complete_age_check/Prover.toml rename to noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Prover.toml diff --git a/noir-examples/noir-passport-examples/monolithic/complete_age_check/scripts/compile.sh b/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/scripts/compile.sh similarity index 100% rename from noir-examples/noir-passport-examples/monolithic/complete_age_check/scripts/compile.sh rename to noir-examples/noir-passport-monolithic/monolithic/complete_age_check/scripts/compile.sh diff --git a/noir-examples/noir-passport-examples/monolithic/complete_age_check/src/main.nr b/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/monolithic/complete_age_check/src/main.nr rename to noir-examples/noir-passport-monolithic/monolithic/complete_age_check/src/main.nr diff --git a/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml b/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/Nargo.toml rename to noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/Nargo.toml diff --git a/noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/src/lib.nr b/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/monolithic/utils/passport_validity_check/src/lib.nr rename to noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/compare/age/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/compare/age/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/utils/compare/age/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/compare/age/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/compare/age/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/compare/age/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/compare/age/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/compare/age/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/data-check/expiry/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/data-check/expiry/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/utils/data-check/expiry/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/data-check/expiry/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/data-check/expiry/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/data-check/expiry/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/data-check/expiry/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/data-check/expiry/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/data-check/tbs-pubkey/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/sig-check/common/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/sig-check/common/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/utils/sig-check/common/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/sig-check/common/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/sig-check/common/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/sig-check/common/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/sig-check/common/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/sig-check/common/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/sig-check/rsa/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/utils/sig-check/rsa/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/sig-check/rsa/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/sig-check/rsa/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/sig-check/rsa/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/sig-check/rsa/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/utils/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/utils/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/utils/utils/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/utils/Nargo.toml diff --git a/noir-examples/noir-passport-examples/utils/utils/src/constants.nr b/noir-examples/noir-passport-monolithic/utils/utils/src/constants.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/utils/src/constants.nr rename to noir-examples/noir-passport-monolithic/utils/utils/src/constants.nr diff --git a/noir-examples/noir-passport-examples/utils/utils/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/utils/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/utils/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/utils/src/lib.nr diff --git a/noir-examples/noir-passport-examples/utils/utils/src/tests.nr b/noir-examples/noir-passport-monolithic/utils/utils/src/tests.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/utils/src/tests.nr rename to noir-examples/noir-passport-monolithic/utils/utils/src/tests.nr diff --git a/noir-examples/noir-passport-examples/utils/utils/src/types.nr b/noir-examples/noir-passport-monolithic/utils/utils/src/types.nr similarity index 100% rename from noir-examples/noir-passport-examples/utils/utils/src/types.nr rename to noir-examples/noir-passport-monolithic/utils/utils/src/types.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/README.md rename to noir-examples/noir-passport/fragmented/merkle_age_check/README.md diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/Nargo.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr b/noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/src/main.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/merkle_age_check/t_attest/src/main.nr rename to noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/src/main.nr diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/Nargo.toml b/noir-examples/noir-passport/fragmented/utils/commitment/common/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/commitment/common/Nargo.toml rename to noir-examples/noir-passport/fragmented/utils/commitment/common/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/common/src/lib.nr b/noir-examples/noir-passport/fragmented/utils/commitment/common/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/commitment/common/src/lib.nr rename to noir-examples/noir-passport/fragmented/utils/commitment/common/src/lib.nr diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml b/noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/Nargo.toml rename to noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/src/lib.nr b/noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/commitment/dsc-to-id/src/lib.nr rename to noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/src/lib.nr diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml b/noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/Nargo.toml rename to noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr b/noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/commitment/scoped-nullifier/src/lib.nr rename to noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/src/lib.nr diff --git a/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/Nargo.toml b/noir-examples/noir-passport/fragmented/utils/data-check/integrity/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/Nargo.toml rename to noir-examples/noir-passport/fragmented/utils/data-check/integrity/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/src/lib.nr b/noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/data-check/integrity/src/lib.nr rename to noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr diff --git a/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport/fragmented/utils/sig-check/rsa/Nargo.toml similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/Nargo.toml rename to noir-examples/noir-passport/fragmented/utils/sig-check/rsa/Nargo.toml diff --git a/noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport/fragmented/utils/sig-check/rsa/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-examples/fragmented/utils/sig-check/rsa/src/lib.nr rename to noir-examples/noir-passport/fragmented/utils/sig-check/rsa/src/lib.nr diff --git a/noir-examples/noir-passport/utils/compare/age/Nargo.toml b/noir-examples/noir-passport/utils/compare/age/Nargo.toml new file mode 100644 index 000000000..f15c9af23 --- /dev/null +++ b/noir-examples/noir-passport/utils/compare/age/Nargo.toml @@ -0,0 +1,9 @@ +[package] +name = "compare_age_lib" +type = "lib" +authors = ["Theo Madzou", "Michael Elliot"] +compiler_version = ">=1.0.0" + +[dependencies] +date = { tag = "v0.5.4", git = "https://github.com/madztheo/noir-date.git" } +utils = { path = "../../utils" } diff --git a/noir-examples/noir-passport/utils/compare/age/src/lib.nr b/noir-examples/noir-passport/utils/compare/age/src/lib.nr new file mode 100644 index 000000000..c0bc5a228 --- /dev/null +++ b/noir-examples/noir-passport/utils/compare/age/src/lib.nr @@ -0,0 +1,72 @@ +use date::Date; +use utils::{ + get_array_slice, get_mrz_from_dg1, ID_CARD_MRZ_BIRTHDATE_INDEX, is_id_card, + PASSPORT_MRZ_BIRTHDATE_INDEX, +}; + +fn get_birthdate(dg1: [u8; 95], timestamp: u64) -> Date { + let mut birthdate_bytes = [0 as u8; 6]; + let mrz = get_mrz_from_dg1(dg1); + + // Get the slice of the MRZ representing the birthdate + if is_id_card(dg1) { + birthdate_bytes = get_array_slice( + mrz, + ID_CARD_MRZ_BIRTHDATE_INDEX, + ID_CARD_MRZ_BIRTHDATE_INDEX + 6, + ); + } else { + // Otherwise it's an ID card + birthdate_bytes = get_array_slice( + mrz, + PASSPORT_MRZ_BIRTHDATE_INDEX, + PASSPORT_MRZ_BIRTHDATE_INDEX + 6, + ); + } + + let current_date = Date::from_timestamp(timestamp); + + // Create a Date object from the birthdate using the current date as + // the pivot year to differentiate between 20th and 21st centuries + // as the format is "YYMMDD" + Date::from_bytes_short_year(birthdate_bytes, current_date) +} + +pub fn compare_age(dg1: [u8; 95], min_age: u8, max_age: u8, timestamp: u64) { + // Restrict the age to be less than 100 as the dg1 birthdate only encodes + // two digits for the year + // TODO: Add support for dg11 to support 100+ + assert((max_age < 100) & (min_age < 100), "Age must be less than 100"); + + let birthdate: Date = get_birthdate(dg1, timestamp); + + let current_date = Date::from_timestamp(timestamp); + + assert((min_age != 0) | (max_age != 0), "Either min or max age must be non-zero"); + + if (min_age != 0) & (max_age == 0) { + // Check if age is above min age + // The minimum age is more likely to be inclusive, so we use gte + assert( + current_date.gte(birthdate.add_years(min_age as u32)), + "Age is not above or equal to min age", + ); + } else if (max_age != 0) & (min_age == 0) { + // Check if age is below max age + // The maximum age is more likely to be exclusive, so we use lt + assert(current_date.lt(birthdate.add_years(max_age as u32)), "Age is not below max age"); + } else { + assert(min_age <= max_age, "Min age must be less than or equal to max age"); + + assert( + current_date.gte(birthdate.add_years(min_age as u32)), + "Age is not above or equal to min age", + ); + // This way if max_age = min_age, the proof will be valid whenever the age + // is equal to min_age = max_age + assert( + current_date.lt(birthdate.add_years((max_age + 1) as u32)), + "Age is not below max age", + ); + } +} diff --git a/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml b/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml new file mode 100644 index 000000000..cc7ca6b49 --- /dev/null +++ b/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml @@ -0,0 +1,10 @@ +[package] +name = "data_check_expiry_lib" +type = "lib" +authors = ["Theo Madzou"] +compiler_version = ">=0.22.0" + +[dependencies] +date = { tag = "v0.5.2", git = "https://github.com/madztheo/noir-date.git" } +utils = { path = "../../utils" } +age = {path = "../../compare/age"} \ No newline at end of file diff --git a/noir-examples/noir-passport/utils/data-check/expiry/src/lib.nr b/noir-examples/noir-passport/utils/data-check/expiry/src/lib.nr new file mode 100644 index 000000000..48eab1617 --- /dev/null +++ b/noir-examples/noir-passport/utils/data-check/expiry/src/lib.nr @@ -0,0 +1,36 @@ +use date::Date; +use utils::{ + get_array_slice, get_mrz_from_dg1, ID_CARD_MRZ_EXPIRY_DATE_INDEX, is_id_card, + PASSPORT_MRZ_EXPIRY_DATE_INDEX, +}; + +pub fn check_expiry(dg1: [u8; 95], current_date_timestamp: u64) { + let current_date = Date::from_timestamp(current_date_timestamp); + + let mrz = get_mrz_from_dg1(dg1); + + // We base the threshold year for the expiry date on the current date plus 30 years + // As most documents will have a 10 year validity (and some maybe 15 years?) + // So with 30 years we should be safe + let threshold_year = current_date.add_years(30); + + let mut expiry_date_bytes = [0 as u8; 6]; + + if is_id_card(dg1) { + expiry_date_bytes = get_array_slice( + mrz, + ID_CARD_MRZ_EXPIRY_DATE_INDEX, + ID_CARD_MRZ_EXPIRY_DATE_INDEX + 6, + ); + } else { + expiry_date_bytes = get_array_slice( + mrz, + PASSPORT_MRZ_EXPIRY_DATE_INDEX, + PASSPORT_MRZ_EXPIRY_DATE_INDEX + 6, + ); + } + + let expiry_date = Date::from_bytes_short_year(expiry_date_bytes, threshold_year); + + assert(current_date.lt(expiry_date), "Document is expired"); +} diff --git a/noir-examples/noir-passport/utils/data-check/tbs-pubkey/Nargo.toml b/noir-examples/noir-passport/utils/data-check/tbs-pubkey/Nargo.toml new file mode 100644 index 000000000..a0b4d4c7d --- /dev/null +++ b/noir-examples/noir-passport/utils/data-check/tbs-pubkey/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "data_check_integrity_lib" +type = "lib" +authors = ["Theo Madzou"] +compiler_version = ">=0.22.0" + +[dependencies] +utils = { path = "../../utils" } \ No newline at end of file diff --git a/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr new file mode 100644 index 000000000..2565c4397 --- /dev/null +++ b/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr @@ -0,0 +1,13 @@ +pub fn verify_rsa_pubkey_in_tbs( + dsc_pubkey: [u8; DSC_KEY_SIZE], + tbs_certificate: [u8; TBS_CERT_SIZE], + pubkey_offset: u32, +) { + // Check that the public key of the DSC is the same as the one in the TBS certificate. + // And since the TBS certificate is the data signed by the private key of the CSCA certificate + // we can make sure the DSC, which signed the data of the passport, has been signed by the + // root certificate of the issuing State (i.e. CSCA certificate) by verifying the signature below + for i in 0..DSC_KEY_SIZE { + assert(tbs_certificate[i + pubkey_offset] == dsc_pubkey[i]); + } +} diff --git a/noir-examples/noir-passport/utils/sig-check/common/Nargo.toml b/noir-examples/noir-passport/utils/sig-check/common/Nargo.toml new file mode 100644 index 000000000..8f69d0f2d --- /dev/null +++ b/noir-examples/noir-passport/utils/sig-check/common/Nargo.toml @@ -0,0 +1,12 @@ +[package] +name = "sig_check_common" +type = "lib" +authors = ["Theo Madzou", "Michael Elliot"] +compiler_version = ">=1.0.0" + +[dependencies] +utils = { path = "../../utils" } +sha512 = { tag = "master", git = "https://github.com/zkpassport/sha512" } +# noir_native_sha256 = { path = "../../../noir_native_sha256" } +sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } +sha1 = { tag = "v0.11", git = "https://github.com/zac-williamson/sha1" } \ No newline at end of file diff --git a/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr b/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr new file mode 100644 index 000000000..0c4d8fabc --- /dev/null +++ b/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr @@ -0,0 +1,70 @@ +use sha1::sha1; +use sha256::{sha224_var, sha256_var}; +use sha512::{sha384, sha512}; +use utils::check_zero_padding; + +pub fn sha1_and_check_data_to_sign( + data_to_sign: [u8; DATA_TO_SIGN_MAX_LEN], + data_to_sign_len: u32, +) -> [u8; 20] { + // Ensure all bytes beyond data_to_sign_len are zero to prevent them + // from being used by the prover + check_zero_padding(data_to_sign, data_to_sign_len); + // Calculate the hash of data_to_sign up to data_to_sign_len + let data_to_sign_vec = BoundedVec::from_parts(data_to_sign, data_to_sign_len); + + sha1::sha1_var(data_to_sign_vec) +} + +pub fn sha224_and_check_data_to_sign( + data_to_sign: [u8; DATA_TO_SIGN_MAX_LEN], + data_to_sign_len: u32, +) -> [u8; 28] { + // Ensure all bytes beyond data_to_sign_len are zero to prevent them + // from being used by the prover + check_zero_padding(data_to_sign, data_to_sign_len); + // Calculate the hash of data_to_sign up to data_to_sign_len + sha224_var(data_to_sign, data_to_sign_len as u64) +} + +pub fn sha256_and_check_data_to_sign( + data_to_sign: [u8; DATA_TO_SIGN_MAX_LEN], + data_to_sign_len: u32, +) -> [u8; 32] { + // Ensure all bytes beyond data_to_sign_len are zero to prevent them + // from being used by the prover + check_zero_padding(data_to_sign, data_to_sign_len); + // Calculate the hash of data_to_sign up to data_to_sign_len + // sha256_var(data_to_sign, data_to_sign_len as u64) + + // Hash the entire buffer to match the signature created on the fixed-size message + // `data_to_sign_len` is still checked above to ensure trailing bytes are zero, + let ret = + sha256_var(data_to_sign, data_to_sign_len as u64); + + ret +} + +pub fn sha384_and_check_data_to_sign( + data_to_sign: [u8; DATA_TO_SIGN_MAX_LEN], + data_to_sign_len: u32, +) -> [u8; 48] { + // Ensure all bytes beyond data_to_sign_len are zero to prevent them + // from being used by the prover + check_zero_padding(data_to_sign, data_to_sign_len); + // Calculate the hash of data_to_sign up to data_to_sign_len + let data_to_sign_vec = BoundedVec::from_parts(data_to_sign, data_to_sign_len); + sha384::sha384_var(data_to_sign_vec) +} + +pub fn sha512_and_check_data_to_sign( + data_to_sign: [u8; DATA_TO_SIGN_MAX_LEN], + data_to_sign_len: u32, +) -> [u8; 64] { + // Ensure all bytes beyond data_to_sign_len are zero to prevent them + // from being used by the prover + check_zero_padding(data_to_sign, data_to_sign_len); + // Calculate the hash of data_to_sign up to data_to_sign_len + let data_to_sign_vec = BoundedVec::from_parts(data_to_sign, data_to_sign_len); + sha512::sha512_var(data_to_sign_vec) +} diff --git a/noir-examples/noir-passport/utils/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport/utils/sig-check/rsa/Nargo.toml new file mode 100644 index 000000000..48f80911a --- /dev/null +++ b/noir-examples/noir-passport/utils/sig-check/rsa/Nargo.toml @@ -0,0 +1,11 @@ +[package] +name = "sig_check_rsa" +type = "lib" +authors = ["Theo Madzou", "Michael Elliot"] +compiler_version = ">=1.0.0" + +[dependencies] +rsa = { git = "https://github.com/zkpassport/noir_rsa", tag = "v0.9.2" } +bignum = { git = "https://github.com/noir-lang/noir-bignum", tag = "v0.8.0"} +utils = { path = "../../utils" } +common = { path = "../common" } diff --git a/noir-examples/noir-passport/utils/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport/utils/sig-check/rsa/src/lib.nr new file mode 100644 index 000000000..86a8c03d5 --- /dev/null +++ b/noir-examples/noir-passport/utils/sig-check/rsa/src/lib.nr @@ -0,0 +1,72 @@ +use bignum::{params::BigNumParams, RuntimeBigNum}; +use common::{ + sha1_and_check_data_to_sign, sha256_and_check_data_to_sign, sha384_and_check_data_to_sign, + sha512_and_check_data_to_sign, +}; +use rsa::rsa::{ + verify_sha1_pkcs1v15, verify_sha1_pss, verify_sha256_pkcs1v15, verify_sha256_pss, + verify_sha384_pkcs1v15, verify_sha384_pss, verify_sha512_pkcs1v15, verify_sha512_pss, +}; + +pub fn verify_signature( + pubkey_bytes: [u8; SIG_BYTES], + // This is equivalent to sig_bytes: [u8; SIG_BYTES] but because of + // an issue with the expected type for from_be_bytes we need to do it like this + sig_bytes: [u8; (((SIG_BYTES * 8) + 7) / 8)], + redc_param_bytes: [u8; SIG_BYTES + 1], + exponent: u32, + data_to_sign: [u8; DATA_TO_SIGN_MAX_LEN], + data_to_sign_len: u32, + pss_salt_len: u32, +) -> bool { + assert( + (SIG_BYTES == 768) + | (SIG_BYTES == 512) + | (SIG_BYTES == 384) + | (SIG_BYTES == 256) + | (SIG_BYTES == 128), + "Only modulus of bit size 1024, 2048, 3072, 4096 and 6144 are supported", + ); + + let pubkey = + utils::pack_be_bytes_into_u128s::(pubkey_bytes); + let redc_param = utils::pack_be_bytes_into_u128s::(redc_param_bytes); + let params = BigNumParams::new(false, pubkey, redc_param); + + let signature = RuntimeBigNum::from_be_bytes(params, sig_bytes); + + if (IS_PSS == 1) { + if (HASH_BYTE_SIZE == 20) { + let msg_hash = sha1_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha1_pss::<_, SIG_BYTES * 8>(msg_hash, signature, exponent, pss_salt_len) + } else if (HASH_BYTE_SIZE == 32) { + let msg_hash = sha256_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha256_pss::<_, SIG_BYTES * 8>(msg_hash, signature, exponent, pss_salt_len) + } else if (HASH_BYTE_SIZE == 48) { + let msg_hash = sha384_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha384_pss::<_, SIG_BYTES * 8>(msg_hash, signature, exponent, pss_salt_len) + } else if (HASH_BYTE_SIZE == 64) { + let msg_hash = sha512_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha512_pss::<_, SIG_BYTES * 8>(msg_hash, signature, exponent, pss_salt_len) + } else { + false + } + } else { + if (HASH_BYTE_SIZE == 20) { + let msg_hash = sha1_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha1_pkcs1v15::<_, SIG_BYTES * 8>(msg_hash, signature, exponent) + } else if (HASH_BYTE_SIZE == 32) { + let msg_hash = sha256_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha256_pkcs1v15::<_, SIG_BYTES * 8>(msg_hash, signature, exponent) + } else if (HASH_BYTE_SIZE == 48) { + let msg_hash = sha384_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha384_pkcs1v15::<_, SIG_BYTES * 8>(msg_hash, signature, exponent) + } else if (HASH_BYTE_SIZE == 64) { + let msg_hash = sha512_and_check_data_to_sign(data_to_sign, data_to_sign_len); + verify_sha512_pkcs1v15::<_, SIG_BYTES * 8>(msg_hash, signature, exponent) + } else { + false + } + } +} + diff --git a/noir-examples/noir-passport/utils/utils/Nargo.toml b/noir-examples/noir-passport/utils/utils/Nargo.toml new file mode 100644 index 000000000..a4b211a2f --- /dev/null +++ b/noir-examples/noir-passport/utils/utils/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "utils" +type = "lib" +authors = ["Theo Madzou", "Michael Elliot"] +compiler_version = ">=1.0.0" + +[dependencies] +poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/utils/utils/src/constants.nr b/noir-examples/noir-passport/utils/utils/src/constants.nr new file mode 100644 index 000000000..9732da4ac --- /dev/null +++ b/noir-examples/noir-passport/utils/utils/src/constants.nr @@ -0,0 +1,5 @@ +// Nullifier types +pub global NON_SALTED_NULLIFIER: Field = 0; +pub global SALTED_NULLIFIER: Field = 1; +pub global NON_SALTED_MOCK_NULLIFIER: Field = 2; +pub global SALTED_MOCK_NULLIFIER: Field = 3; diff --git a/noir-examples/noir-passport/utils/utils/src/lib.nr b/noir-examples/noir-passport/utils/utils/src/lib.nr new file mode 100644 index 000000000..5b60b92dd --- /dev/null +++ b/noir-examples/noir-passport/utils/utils/src/lib.nr @@ -0,0 +1,227 @@ +/** +* The standards for passports and any other travel documents, electronic or not, +* are defined in the ICAO (International Civil Aviation Organization) 9303 document available here: +* https://www.icao.int/publications/pages/publication.aspx?docnum=9303 +*/ +pub mod tests; +pub mod types; +pub mod constants; + +/** +* The structure of the MRZ is well defined and standardized by the ICAO +* so the index will always be the same for every passport +* c.f. ICAO 9303-4, Appendix B +*/ + +use types::{DG1Data, MRZData, MRZIssuingCountry}; + +// Index for the country of issuance of the passport +pub global PASSPORT_MRZ_COUNTRY_INDEX: u32 = 2; +// Length of the country code in the MRZ +pub global PASSPORT_MRZ_COUNTRY_LENGTH: u32 = 3; +// Index for the date of expiry (YYMMDD) +pub global PASSPORT_MRZ_EXPIRY_DATE_INDEX: u32 = 65; +// Index for the date of birth (YYMMDD) in TD1 (i.e. passport) MRZ +pub global PASSPORT_MRZ_BIRTHDATE_INDEX: u32 = 57; + +// Index for the date of expiry (YYMMDD) +pub global ID_CARD_MRZ_EXPIRY_DATE_INDEX: u32 = 38; +// Index for the date of birth (YYMMDD) in TD3 (i.e. ID cards) MRZ +pub global ID_CARD_MRZ_BIRTHDATE_INDEX: u32 = 30; + +// Proof type to identify the circuit used for a given parameter commitment +pub global PROOF_TYPE_AGE: u8 = 1; + +// D<< +global GERMANY_PASSPORT_CODE: [u8; 3] = [68, 60, 60]; +// DEU +global GERMANY_ISO_CODE: [u8; 3] = [68, 69, 85]; + +/// Offset of the MRZ in the DG1 +pub global DG1_TO_MRZ_OFFSET: u32 = 5; + +pub fn get_array_slice(arr: [u8; N], start: u32, end: u32) -> [u8; M] { + let mut slice = [0 as u8; M]; + for i in start..end { + slice[i - start] = arr[i]; + } + slice +} + +pub fn is_id_card(dg1: DG1Data) -> bool { + // For passport, the last two bytes are 0 + // since the real length is 93 for passports + // while it is 95 for ID cards + (dg1[93] != 0) & (dg1[94] != 0) +} + +pub fn pack_be_bytes_into_field( + x: [u8; NBytes], +) -> Field { + let mut result: Field = 0; + for i in 0..MAX_FIELD_SIZE { + result *= 256; + result += x[i] as Field; + } + std::as_witness(result); + result +} + +pub fn pack_be_bytes_into_u128s( + x: [u8; NBytes], +) -> [u128; N] { + let mut result = [0 as u128; N]; + + let mut limb: Field = 0; + let mut k = 0; + for _j in 0..(MAX_FIELD_SIZE - (N * MAX_FIELD_SIZE - NBytes)) { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + + result[N - 1] = limb as u128; + + for i in 1..N { + let mut limb: Field = 0; + for _j in 0..MAX_FIELD_SIZE { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + result[N - i - 1] = limb as u128; + } + + result +} + +pub fn pack_be_bytes_into_fields( + x: [u8; NBytes], +) -> [Field; N] { + let mut result = [0 as Field; N]; + + let mut limb: Field = 0; + let mut k = 0; + for _j in 0..(MAX_FIELD_SIZE - (N * MAX_FIELD_SIZE - NBytes)) { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + + result[N - 1] = limb; + + for i in 1..N { + let mut limb: Field = 0; + for _j in 0..MAX_FIELD_SIZE { + limb *= 256; + limb += x[k] as Field; + k += 1; + } + std::as_witness(limb); + result[N - i - 1] = limb; + } + + result +} + +pub fn get_mrz_from_dg1(dg1: DG1Data) -> MRZData { + let mut mrz: MRZData = [0 as u8; 90]; + for i in 0..90 { + mrz[i] = dg1[i + DG1_TO_MRZ_OFFSET]; + } + mrz +} + +pub fn check_zero_padding(padded_array: [T; N], len: u32) +where + T: Eq, + T: Default, +{ + for i in 0..N { + if i >= len { + assert_eq(padded_array[i], T::default()); + } + } +} + +pub fn get_issuing_country_from_mrz(dg1: DG1Data) -> MRZIssuingCountry { + let mrz = get_mrz_from_dg1(dg1); + // No need to check if it's an ID card since the issuing country + // is always at the same index for both passports and ID cards + let mut country_bytes = get_array_slice( + mrz, + PASSPORT_MRZ_COUNTRY_INDEX, + PASSPORT_MRZ_COUNTRY_INDEX + PASSPORT_MRZ_COUNTRY_LENGTH, + ); + + // Handle the special case of Germany + if (country_bytes == GERMANY_PASSPORT_CODE) { + country_bytes = GERMANY_ISO_CODE; + } + + country_bytes +} + +/// Find the index of the first occurrence of the needle in the haystack +/// Returns the index of the first occurrence of the needle in the haystack +/// Returns HAYSTACK_SIZE if the needle is not found +pub fn find_subarray_index( + needle: [u8; NEEDLE_SIZE], + haystack: [u8; HAYSTACK_SIZE], +) -> u32 { + // Safety: This is safe because the offset is only used as a starting point + // to verify the substring exists + let offsetUnchecked = unsafe { find_subarray_index_unsafe(needle, haystack) }; + let mut offset = offsetUnchecked; + // Check if offset is valid before attempting verification + if (offsetUnchecked < HAYSTACK_SIZE) & (offsetUnchecked + NEEDLE_SIZE <= HAYSTACK_SIZE) { + for i in 0..NEEDLE_SIZE { + if haystack[i + offsetUnchecked] != needle[i] { + offset = HAYSTACK_SIZE; + } + } + } else { + // If offset is out of bounds, needle was not found + offset = HAYSTACK_SIZE; + } + offset +} + +pub fn is_subarray_in_array( + needle: [u8; NEEDLE_SIZE], + haystack: [u8; HAYSTACK_SIZE], +) -> bool { + find_subarray_index(needle, haystack) < HAYSTACK_SIZE +} + +/// Safety: This is safe because the offset is only used as a starting point +/// to verify the substring exists +pub unconstrained fn find_subarray_index_unsafe( + needle: [u8; NEEDLE_SIZE], + haystack: [u8; HAYSTACK_SIZE], +) -> u32 { + let mut result = HAYSTACK_SIZE; // Default to "not found" value + // Handle edge cases + if NEEDLE_SIZE == 0 { + result = 0; + } else if NEEDLE_SIZE <= HAYSTACK_SIZE { + // Search for the needle in the haystack + for i in 0..(HAYSTACK_SIZE - NEEDLE_SIZE + 1) { + let mut found = true; + for j in 0..NEEDLE_SIZE { + if haystack[i + j] != needle[j] { + found = false; + break; + } + } + if found { + result = i; + break; + } + } + } + result +} diff --git a/noir-examples/noir-passport/utils/utils/src/tests.nr b/noir-examples/noir-passport/utils/utils/src/tests.nr new file mode 100644 index 000000000..ad2af3b25 --- /dev/null +++ b/noir-examples/noir-passport/utils/utils/src/tests.nr @@ -0,0 +1,213 @@ +use crate::{find_subarray_index, pack_be_bytes_into_fields, pack_be_bytes_into_u128s}; + +#[test] +fn test_pack_be_bytes_into_u128() { + let packed1 = pack_be_bytes_into_u128s::<512, _, 15>(TEST_BYTES); + assert( + packed1 + == [ + 0xa906a6bf52c2d3b6dcc3e53e8df2c2, + 0xa0a652bc1a96ef6fa85aaaac8a2793, + 0xd2aa634a40e786072d1a84a726ee35, + 0x20deee9d92dd32e9d1661cad3fd748, + 0x59c58bff771bcb1007ab5292034b01, + 0xb105cd7c3f8bdffffa8976a1d6712b, + 0x7f04e817f0861ba18ffdc4e9656bd2, + 0xca6ad55f4dc9e1437ae528bff4440b, + 0x0cdf23c048109f118dbc4f062526ec, + 0xc57749fc145d2a6f68c95a0bf1345a, + 0x1744b7ad88a820d428b0f1c79a6660, + 0x21a17ae68fddadbb6d54c97ecbe1e3, + 0x3596b41957a1a78af81fbe9f418d92, + 0x5398a2f749a773190f5d838013b898, + 0xef83111bf9b7819fd12b33ff682590, + 0x56989a6176dfd100ae89dd7936e9f0, + 0x4f3d7ab2e41ba2cb404c3d6cef8740, + 0xc81a370e672704f5f31450f9156d93, + 0x2c9ad440424450b81c303c51d405d3, + 0x5d3aaebc67b2ba64a2f9546349fb9e, + 0xdced3dbea6d67fe49c3f31562ffba7, + 0xa67a19f7fcecb81235e7706b20ecc4, + 0x2fb5c8f5d8ddac8df1c6917eb31bad, + 0xd9478e0dcd3f2ab125ccc6a68c4447, + 0x2ef19aff06bf67ab4226a331ffa737, + 0x5e9ea156076a09e78b919d8c5dee0f, + 0x0b427e9391893f58968fc2d96a2775, + 0x432d27b533c103f1509b4f4fc43ac7, + 0xe0e6d9598280b0aa0f2902b0aa3b3a, + 0xa04da3f98c5cfe8d4d8f9e1fb4e89c, + 0x7e463b5ebaf81c1485efeb44e634f9, + 0xae87ec4262fcfd075f5554475547a3, + 0xfb2297b7ffc0deeb3a1b27effc6b6c, + 0xd3b801cbc8e237620d8dd9adc29551, + 0x405d, + ], + ); +} + +#[test] +fn test_pack_be_bytes_into_fields() { + let packed1 = pack_be_bytes_into_fields::<512, _, 15>(TEST_BYTES); + assert( + packed1 + == [ + 0xa906a6bf52c2d3b6dcc3e53e8df2c2, + 0xa0a652bc1a96ef6fa85aaaac8a2793, + 0xd2aa634a40e786072d1a84a726ee35, + 0x20deee9d92dd32e9d1661cad3fd748, + 0x59c58bff771bcb1007ab5292034b01, + 0xb105cd7c3f8bdffffa8976a1d6712b, + 0x7f04e817f0861ba18ffdc4e9656bd2, + 0xca6ad55f4dc9e1437ae528bff4440b, + 0x0cdf23c048109f118dbc4f062526ec, + 0xc57749fc145d2a6f68c95a0bf1345a, + 0x1744b7ad88a820d428b0f1c79a6660, + 0x21a17ae68fddadbb6d54c97ecbe1e3, + 0x3596b41957a1a78af81fbe9f418d92, + 0x5398a2f749a773190f5d838013b898, + 0xef83111bf9b7819fd12b33ff682590, + 0x56989a6176dfd100ae89dd7936e9f0, + 0x4f3d7ab2e41ba2cb404c3d6cef8740, + 0xc81a370e672704f5f31450f9156d93, + 0x2c9ad440424450b81c303c51d405d3, + 0x5d3aaebc67b2ba64a2f9546349fb9e, + 0xdced3dbea6d67fe49c3f31562ffba7, + 0xa67a19f7fcecb81235e7706b20ecc4, + 0x2fb5c8f5d8ddac8df1c6917eb31bad, + 0xd9478e0dcd3f2ab125ccc6a68c4447, + 0x2ef19aff06bf67ab4226a331ffa737, + 0x5e9ea156076a09e78b919d8c5dee0f, + 0x0b427e9391893f58968fc2d96a2775, + 0x432d27b533c103f1509b4f4fc43ac7, + 0xe0e6d9598280b0aa0f2902b0aa3b3a, + 0xa04da3f98c5cfe8d4d8f9e1fb4e89c, + 0x7e463b5ebaf81c1485efeb44e634f9, + 0xae87ec4262fcfd075f5554475547a3, + 0xfb2297b7ffc0deeb3a1b27effc6b6c, + 0xd3b801cbc8e237620d8dd9adc29551, + 0x405d, + ], + ); + + let packed2 = pack_be_bytes_into_fields::<512, _, 31>(TEST_BYTES); + assert( + packed2 + == [ + 0x35a0a652bc1a96ef6fa85aaaac8a2793a906a6bf52c2d3b6dcc3e53e8df2c2, + 0x4b0120deee9d92dd32e9d1661cad3fd748d2aa634a40e786072d1a84a726ee, + 0x656bd2b105cd7c3f8bdffffa8976a1d6712b59c58bff771bcb1007ab529203, + 0x062526ecca6ad55f4dc9e1437ae528bff4440b7f04e817f0861ba18ffdc4e9, + 0xf1c79a6660c57749fc145d2a6f68c95a0bf1345a0cdf23c048109f118dbc4f, + 0x1fbe9f418d9221a17ae68fddadbb6d54c97ecbe1e31744b7ad88a820d428b0, + 0xd12b33ff6825905398a2f749a773190f5d838013b8983596b41957a1a78af8, + 0xcb404c3d6cef874056989a6176dfd100ae89dd7936e9f0ef83111bf9b7819f, + 0x50b81c303c51d405d3c81a370e672704f5f31450f9156d934f3d7ab2e41ba2, + 0xd67fe49c3f31562ffba75d3aaebc67b2ba64a2f9546349fb9e2c9ad4404244, + 0xd8ddac8df1c6917eb31bada67a19f7fcecb81235e7706b20ecc4dced3dbea6, + 0xff06bf67ab4226a331ffa737d9478e0dcd3f2ab125ccc6a68c44472fb5c8f5, + 0x7e9391893f58968fc2d96a27755e9ea156076a09e78b919d8c5dee0f2ef19a, + 0xe6d9598280b0aa0f2902b0aa3b3a432d27b533c103f1509b4f4fc43ac70b42, + 0x7e463b5ebaf81c1485efeb44e634f9a04da3f98c5cfe8d4d8f9e1fb4e89ce0, + 0x51fb2297b7ffc0deeb3a1b27effc6b6cae87ec4262fcfd075f5554475547a3, + 0x405dd3b801cbc8e237620d8dd9adc295, + ], + ); +} + +global TEST_BYTES: [u8; 512] = [ + 0x40, 0x5d, 0xd3, 0xb8, 0x01, 0xcb, 0xc8, 0xe2, 0x37, 0x62, 0x0d, 0x8d, 0xd9, 0xad, 0xc2, 0x95, + 0x51, 0xfb, 0x22, 0x97, 0xb7, 0xff, 0xc0, 0xde, 0xeb, 0x3a, 0x1b, 0x27, 0xef, 0xfc, 0x6b, 0x6c, + 0xae, 0x87, 0xec, 0x42, 0x62, 0xfc, 0xfd, 0x07, 0x5f, 0x55, 0x54, 0x47, 0x55, 0x47, 0xa3, 0x7e, + 0x46, 0x3b, 0x5e, 0xba, 0xf8, 0x1c, 0x14, 0x85, 0xef, 0xeb, 0x44, 0xe6, 0x34, 0xf9, 0xa0, 0x4d, + 0xa3, 0xf9, 0x8c, 0x5c, 0xfe, 0x8d, 0x4d, 0x8f, 0x9e, 0x1f, 0xb4, 0xe8, 0x9c, 0xe0, 0xe6, 0xd9, + 0x59, 0x82, 0x80, 0xb0, 0xaa, 0x0f, 0x29, 0x02, 0xb0, 0xaa, 0x3b, 0x3a, 0x43, 0x2d, 0x27, 0xb5, + 0x33, 0xc1, 0x03, 0xf1, 0x50, 0x9b, 0x4f, 0x4f, 0xc4, 0x3a, 0xc7, 0x0b, 0x42, 0x7e, 0x93, 0x91, + 0x89, 0x3f, 0x58, 0x96, 0x8f, 0xc2, 0xd9, 0x6a, 0x27, 0x75, 0x5e, 0x9e, 0xa1, 0x56, 0x07, 0x6a, + 0x09, 0xe7, 0x8b, 0x91, 0x9d, 0x8c, 0x5d, 0xee, 0x0f, 0x2e, 0xf1, 0x9a, 0xff, 0x06, 0xbf, 0x67, + 0xab, 0x42, 0x26, 0xa3, 0x31, 0xff, 0xa7, 0x37, 0xd9, 0x47, 0x8e, 0x0d, 0xcd, 0x3f, 0x2a, 0xb1, + 0x25, 0xcc, 0xc6, 0xa6, 0x8c, 0x44, 0x47, 0x2f, 0xb5, 0xc8, 0xf5, 0xd8, 0xdd, 0xac, 0x8d, 0xf1, + 0xc6, 0x91, 0x7e, 0xb3, 0x1b, 0xad, 0xa6, 0x7a, 0x19, 0xf7, 0xfc, 0xec, 0xb8, 0x12, 0x35, 0xe7, + 0x70, 0x6b, 0x20, 0xec, 0xc4, 0xdc, 0xed, 0x3d, 0xbe, 0xa6, 0xd6, 0x7f, 0xe4, 0x9c, 0x3f, 0x31, + 0x56, 0x2f, 0xfb, 0xa7, 0x5d, 0x3a, 0xae, 0xbc, 0x67, 0xb2, 0xba, 0x64, 0xa2, 0xf9, 0x54, 0x63, + 0x49, 0xfb, 0x9e, 0x2c, 0x9a, 0xd4, 0x40, 0x42, 0x44, 0x50, 0xb8, 0x1c, 0x30, 0x3c, 0x51, 0xd4, + 0x05, 0xd3, 0xc8, 0x1a, 0x37, 0x0e, 0x67, 0x27, 0x04, 0xf5, 0xf3, 0x14, 0x50, 0xf9, 0x15, 0x6d, + 0x93, 0x4f, 0x3d, 0x7a, 0xb2, 0xe4, 0x1b, 0xa2, 0xcb, 0x40, 0x4c, 0x3d, 0x6c, 0xef, 0x87, 0x40, + 0x56, 0x98, 0x9a, 0x61, 0x76, 0xdf, 0xd1, 0x00, 0xae, 0x89, 0xdd, 0x79, 0x36, 0xe9, 0xf0, 0xef, + 0x83, 0x11, 0x1b, 0xf9, 0xb7, 0x81, 0x9f, 0xd1, 0x2b, 0x33, 0xff, 0x68, 0x25, 0x90, 0x53, 0x98, + 0xa2, 0xf7, 0x49, 0xa7, 0x73, 0x19, 0x0f, 0x5d, 0x83, 0x80, 0x13, 0xb8, 0x98, 0x35, 0x96, 0xb4, + 0x19, 0x57, 0xa1, 0xa7, 0x8a, 0xf8, 0x1f, 0xbe, 0x9f, 0x41, 0x8d, 0x92, 0x21, 0xa1, 0x7a, 0xe6, + 0x8f, 0xdd, 0xad, 0xbb, 0x6d, 0x54, 0xc9, 0x7e, 0xcb, 0xe1, 0xe3, 0x17, 0x44, 0xb7, 0xad, 0x88, + 0xa8, 0x20, 0xd4, 0x28, 0xb0, 0xf1, 0xc7, 0x9a, 0x66, 0x60, 0xc5, 0x77, 0x49, 0xfc, 0x14, 0x5d, + 0x2a, 0x6f, 0x68, 0xc9, 0x5a, 0x0b, 0xf1, 0x34, 0x5a, 0x0c, 0xdf, 0x23, 0xc0, 0x48, 0x10, 0x9f, + 0x11, 0x8d, 0xbc, 0x4f, 0x06, 0x25, 0x26, 0xec, 0xca, 0x6a, 0xd5, 0x5f, 0x4d, 0xc9, 0xe1, 0x43, + 0x7a, 0xe5, 0x28, 0xbf, 0xf4, 0x44, 0x0b, 0x7f, 0x04, 0xe8, 0x17, 0xf0, 0x86, 0x1b, 0xa1, 0x8f, + 0xfd, 0xc4, 0xe9, 0x65, 0x6b, 0xd2, 0xb1, 0x05, 0xcd, 0x7c, 0x3f, 0x8b, 0xdf, 0xff, 0xfa, 0x89, + 0x76, 0xa1, 0xd6, 0x71, 0x2b, 0x59, 0xc5, 0x8b, 0xff, 0x77, 0x1b, 0xcb, 0x10, 0x07, 0xab, 0x52, + 0x92, 0x03, 0x4b, 0x01, 0x20, 0xde, 0xee, 0x9d, 0x92, 0xdd, 0x32, 0xe9, 0xd1, 0x66, 0x1c, 0xad, + 0x3f, 0xd7, 0x48, 0xd2, 0xaa, 0x63, 0x4a, 0x40, 0xe7, 0x86, 0x07, 0x2d, 0x1a, 0x84, 0xa7, 0x26, + 0xee, 0x35, 0xa0, 0xa6, 0x52, 0xbc, 0x1a, 0x96, 0xef, 0x6f, 0xa8, 0x5a, 0xaa, 0xac, 0x8a, 0x27, + 0x93, 0xa9, 0x06, 0xa6, 0xbf, 0x52, 0xc2, 0xd3, 0xb6, 0xdc, 0xc3, 0xe5, 0x3e, 0x8d, 0xf2, 0xc2, +]; + +#[test] +fn test_find_substring_index_various_cases() { + // Test case 1: Basic substring at index 3 + let needle1 = [0x04, 0x05, 0x06]; + let haystack1 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a]; + let index1 = find_subarray_index(needle1, haystack1); + assert_eq(index1, 3); + + // Test case 2: Substring at the beginning + let needle2 = [0x01, 0x02]; + let haystack2 = [0x01, 0x02, 0x03, 0x04, 0x05]; + let index2 = find_subarray_index(needle2, haystack2); + assert_eq(index2, 0); + + // Test case 3: Substring at the end + let needle3 = [0x04, 0x05]; + let haystack3 = [0x01, 0x02, 0x03, 0x04, 0x05]; + let index3 = find_subarray_index(needle3, haystack3); + assert_eq(index3, 3); + + // Test case 4: Single byte needle + let needle4 = [0x03]; + let haystack4 = [0x01, 0x02, 0x03, 0x04, 0x05]; + let index4 = find_subarray_index(needle4, haystack4); + assert_eq(index4, 2); + + // Test case 5: Empty needle (should return 0) + let needle5: [u8; 0] = []; + let haystack5 = [0x01, 0x02, 0x03, 0x04, 0x05]; + let index5 = find_subarray_index(needle5, haystack5); + assert_eq(index5, 0); + + // Test case 6: Needle not found - completely different bytes + let needle6 = [0xff, 0xee, 0xdd]; + let haystack6 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a]; + let index6 = find_subarray_index(needle6, haystack6); + assert_eq(index6, haystack6.len()); // Should equal haystack size + + // Test case 7: Needle larger than haystack + let needle7 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06]; + let haystack7 = [0x01, 0x02, 0x03]; + let index7 = find_subarray_index(needle7, haystack7); + assert_eq(index7, haystack7.len()); // Should equal haystack size + + // Test case 8: Partial match at the end but incomplete + let needle8 = [0x09, 0x0a, 0x0b]; + let haystack8 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a]; + let index8 = find_subarray_index(needle8, haystack8); + assert_eq(index8, haystack8.len()); // Should equal haystack size + + // Test case 9: Multiple false matches (partial matches) + let needle9 = [0x01, 0x01, 0x02]; + let haystack9 = [0x01, 0x03, 0x01, 0x04, 0x01, 0x01, 0x03, 0x05, 0x06, 0x07]; + let index9 = find_subarray_index(needle9, haystack9); + assert_eq(index9, haystack9.len()); // Should equal haystack size + + // Test case 10: Needle appears to match but fails verification + let needle10 = [0x02, 0x03, 0x04]; + let haystack10 = [0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08, 0x09]; + let index10 = find_subarray_index(needle10, haystack10); + assert_eq(index10, haystack10.len()); // Should equal haystack size +} diff --git a/noir-examples/noir-passport/utils/utils/src/types.nr b/noir-examples/noir-passport/utils/utils/src/types.nr new file mode 100644 index 000000000..9181d49a5 --- /dev/null +++ b/noir-examples/noir-passport/utils/utils/src/types.nr @@ -0,0 +1,133 @@ +use poseidon::poseidon2::Poseidon2; +use crate::pack_be_bytes_into_fields; + +// DG1 types +pub type DG1Data = [u8; 95]; +pub type MRZData = [u8; 90]; + +// Dates +pub type YYMMDDDate = [u8; 6]; +pub type MRZExpiryDate = YYMMDDDate; + +// MRZ types +pub type MRZIssuingCountry = [u8; 3]; + +// Country code types +pub type Alpha3CountryCode = str<3>; + +// Hash digest types +pub type SHA256Digest = [u8; 32]; + +// eContent and SignedAttrs types +pub type EContentData = [u8; 200]; +pub type SignedAttrsData = [u8; 200]; + +/// This struct acts as a wrapper around a value, so it can be specified as either a clear value with +/// a provided salt for hashing or only as its salted hash if its clear value is not needed inside the circuit +pub struct SaltedValue { + pub salt: Field, + pub value: T, + pub hash: Field, +} + +impl Default for SaltedValue +where + T: Default, +{ + fn default() -> Self { + Self { salt: 0, value: T::default(), hash: 0 } + } +} + +impl SaltedValue +where + T: Default, + T: Eq, +{ + /// When the clear value is needed inside the circuit, use this method to create a salted value + pub fn from_value(salt: Field, value: T) -> Self { + assert(salt != 0, "Salt cannot be 0 when creating a salted value from a clear value"); + assert( + value != T::default(), + "Value cannot be the default value when creating a salted value from a clear value", + ); + Self { salt, value, hash: 0 } + } + + /// When the clear value is not needed and is better hidden, use this method to specify the hash only + pub fn from_hash(hash: Field) -> Self { + assert(hash != 0, "Hash cannot be 0 when creating a salted value from a hash"); + Self { salt: 0, value: T::default(), hash } + } +} + +impl SaltedValue { + /// Gets the salted hash of the value + /// If the hash is already specified, it will return the hash directly + /// Otherwise, it will compute the hash from the salt and value + pub fn get_hash(self) -> Field { + if self.hash != 0 { + assert_eq(self.salt, 0, "Salt must be 0 when hash is already specified"); + assert_eq(self.value, 0, "Value must be 0 when hash is already specified"); + self.hash + } else { + assert( + self.value != 0, + "Value must be non-zero when computing the hash from a clear value and its salt", + ); + assert( + self.salt != 0, + "Salt must be non-zero when computing the hash from a clear value and its salt", + ); + Poseidon2::hash([self.salt, self.value as Field], 2) + } + } +} + +impl SaltedValue { + /// Gets the salted hash of the value + /// If the hash is already specified, it will return the hash directly + /// Otherwise, it will compute the hash from the salt and value + pub fn get_hash(self) -> Field { + if self.hash != 0 { + assert_eq(self.salt, 0, "Salt must be 0 when hash is already specified"); + assert_eq(self.value, 0, "Value must be 0 when hash is already specified"); + self.hash + } else { + assert( + self.value != 0, + "Value must be non-zero when computing the hash from a clear value and its salt", + ); + assert( + self.salt != 0, + "Salt must be non-zero when computing the hash from a clear value and its salt", + ); + Poseidon2::hash([self.salt, self.value], 2) + } + } +} + +impl SaltedValue<[u8; N]> { + /// Gets the salted hash of the value + /// If the hash is already specified, it will return the hash directly + /// Otherwise, it will compute the hash from the salt and value + pub fn get_hash(self) -> Field { + if self.hash != 0 { + assert_eq(self.salt, 0, "Salt must be 0 when hash is already specified"); + assert_eq(self.value, [0; N], "Value must be zeroed when hash is already specified"); + self.hash + } else { + assert( + self.value != [0; N], + "Value must be non-zeroed when computing the hash from a clear value and its salt", + ); + assert( + self.salt != 0, + "Salt must be non-zero when computing the hash from a clear value and its salt", + ); + let packed_value: [Field; (N + 30) / 31] = + pack_be_bytes_into_fields::(self.value); + Poseidon2::hash([self.salt].concat(packed_value), (N + 30) / 31 + 1) + } + } +} diff --git a/noir-examples/partial_sha256/Nargo.toml b/noir-examples/partial_sha256/Nargo.toml index e1a7418bf..c396ebd5d 100644 --- a/noir-examples/partial_sha256/Nargo.toml +++ b/noir-examples/partial_sha256/Nargo.toml @@ -4,6 +4,6 @@ type = "lib" compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../noir-passport-examples/utils/utils" } +utils = { path = "../noir-passport/utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } diff --git a/scripts/run_all.sh b/scripts/run_all.sh index 555e8baf2..78f9e9538 100644 --- a/scripts/run_all.sh +++ b/scripts/run_all.sh @@ -1,6 +1,6 @@ # Run this in the `noir-r1cs` directory! -for file in noir-passport-examples/*.json; do +for file in noir-passport-monolithic/*.json; do echo "$file" cargo run --bin circuit_stats -- "$file" noir-examples/basic/target/basic.gz done \ No newline at end of file diff --git a/tooling/provekit-bench/tests/compiler.rs b/tooling/provekit-bench/tests/compiler.rs index ef484f065..8643bcfba 100644 --- a/tooling/provekit-bench/tests/compiler.rs +++ b/tooling/provekit-bench/tests/compiler.rs @@ -82,7 +82,7 @@ pub fn compile_workspace(workspace_path: impl AsRef) -> Result #[test_case("../../noir-examples/noir-r1cs-test-programs/small-sha")] #[test_case("../../noir-examples/noir-r1cs-test-programs/bounded-vec")] #[test_case("../../noir-examples/noir-r1cs-test-programs/brillig-unconstrained")] -#[test_case("../../noir-examples/noir-passport-examples/complete_age_check"; "complete_age_check")] +#[test_case("../../noir-examples/noir-passport-monolithic/complete_age_check"; "complete_age_check")] fn case(path: &str) { test_compiler(path); } From 3ee3ef5f637f203e1570d8d0fb293af94d0cb80f Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 19:05:34 +0530 Subject: [PATCH 06/15] better names --- .github/workflows/circuit_keys.yml | 2 +- .github/workflows/end-to-end.yml | 2 +- .../fragmented/merkle_age_check/README.md | 34 +- .../case2/t_add_integrity_commit.toml | 28 - .../t_add_dsc_hash_1300.toml | 0 .../t_add_dsc_verify_1300.toml | 0 .../t_add_id_data_1300.toml | 0 .../tbs_1300/t_add_integrity_commit.toml | 526 ++++++++++++++++++ .../{case2 => tbs_1300}/t_attest.toml | 0 .../{case1 => tbs_720}/t_add_dsc_720.toml | 0 .../{case1 => tbs_720}/t_add_id_data_720.toml | 0 .../t_add_integrity_commit.toml | 0 .../{case1 => tbs_720}/t_attest.toml | 0 .../{case2 => tbs_1300}/compile-circuits.sh | 2 +- .../{case2 => tbs_1300}/prepare-circuits.sh | 2 +- .../{case2 => tbs_1300}/prove-circuits.sh | 4 +- .../{case1 => tbs_720}/compile-circuits.sh | 2 +- .../{case1 => tbs_720}/prepare-circuits.sh | 2 +- .../{case1 => tbs_720}/prove-circuits.sh | 4 +- 19 files changed, 555 insertions(+), 53 deletions(-) delete mode 100644 noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case2 => tbs_1300}/t_add_dsc_hash_1300.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case2 => tbs_1300}/t_add_dsc_verify_1300.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case2 => tbs_1300}/t_add_id_data_1300.toml (100%) create mode 100644 noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case2 => tbs_1300}/t_attest.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case1 => tbs_720}/t_add_dsc_720.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case1 => tbs_720}/t_add_id_data_720.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case1 => tbs_720}/t_add_integrity_commit.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/{case1 => tbs_720}/t_attest.toml (100%) rename noir-examples/noir-passport/fragmented/merkle_age_check/scripts/{case2 => tbs_1300}/compile-circuits.sh (89%) rename noir-examples/noir-passport/fragmented/merkle_age_check/scripts/{case2 => tbs_1300}/prepare-circuits.sh (91%) rename noir-examples/noir-passport/fragmented/merkle_age_check/scripts/{case2 => tbs_1300}/prove-circuits.sh (65%) rename noir-examples/noir-passport/fragmented/merkle_age_check/scripts/{case1 => tbs_720}/compile-circuits.sh (88%) rename noir-examples/noir-passport/fragmented/merkle_age_check/scripts/{case1 => tbs_720}/prepare-circuits.sh (91%) rename noir-examples/noir-passport/fragmented/merkle_age_check/scripts/{case1 => tbs_720}/prove-circuits.sh (63%) diff --git a/.github/workflows/circuit_keys.yml b/.github/workflows/circuit_keys.yml index d3ad59d3c..b67628b5a 100644 --- a/.github/workflows/circuit_keys.yml +++ b/.github/workflows/circuit_keys.yml @@ -72,7 +72,7 @@ jobs: echo "Proving $circuit" cargo run --release --bin provekit-cli prove \ ./benchmark-inputs/$circuit-prover.pkp \ - ./benchmark-inputs/case1/$circuit.toml \ + ./benchmark-inputs/tbs_720/$circuit.toml \ -o ./benchmark-inputs/$circuit-proof.np echo "Proved $circuit" done diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index fdd759d46..c61b130e3 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -70,7 +70,7 @@ jobs: echo "Proving $circuit" cargo run --release --bin provekit-cli prove \ ./benchmark-inputs/$circuit-prover.pkp \ - ./benchmark-inputs/case1/$circuit.toml \ + ./benchmark-inputs/tbs_720/$circuit.toml \ -o ./benchmark-inputs/$circuit-proof.np echo "Proved $circuit" done diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md index 16d356833..dbf5a4078 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md @@ -44,32 +44,36 @@ The `t_attest` circuit provides fast, repeatable proofs: Benchmark inputs have already been generated and are available in the `benchmark-inputs` directory. -Scripts are provided separately for Case 1 (4-circuit chain) and Case 2 (5-circuit chain). Navigate to the scripts directory and run the appropriate sequence: +Scripts are provided separately for tbs_700 (4-circuit chain) and tbs_1300 (5-circuit chain). Navigate to the scripts directory and run the appropriate sequence: ```bash cd scripts ``` -### For Case 1 (TBS < 720 bytes): +### For tbs_720 (TBS < 720 bytes): ```bash -# 1. Compile circuits -./case1/compile.sh +cd tbs_720 -# 2. Prepare proving artifacts -./case1/prepare.sh +# 1. Compile circuits: Generates compiled artifacts inside merkle_age_check/target/ for all 4 circuits +./compile-circuits.sh -# 3. Generate proofs -./case1/prove.sh +# 2. Prepare proving artifacts: Generates proving keys and verification keys for all 4 circuits, stored in merkle_age_check/benchmark-inputs/ +./prepare-circuits.sh + +# 3. Generate proofs: Generates proofs for all 4 circuits using the prepared artifacts and benchmark inputs, stored in merkle_age_check/benchmark-inputs/ +./prove-circuits.sh ``` -### For Case 2 (TBS >= 720 bytes): +### For tbs_1300 (TBS >= 720 bytes): ```bash -# 1. Compile circuits -./case2/compile.sh +cd tbs_1300 + +# 1. Compile circuits: Generates compiled artifacts inside merkle_age_check/target/ for all 5 circuits +./compile.sh -# 2. Prepare proving artifacts -./case2/prepare.sh +# 2. Prepare proving artifacts: Generates proving keys and verification keys for all 5 circuits, stored in merkle_age_check/benchmark-inputs/ +./prepare.sh -# 3. Generate proofs -./case2/prove.sh +# 3. Generate proofs: Generates proofs for all 5 circuits using the prepared artifacts and benchmark inputs, stored in merkle_age_check/benchmark-inputs/ +./prove.sh ``` \ No newline at end of file diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml deleted file mode 100644 index d7d192482..000000000 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_integrity_commit.toml +++ /dev/null @@ -1,28 +0,0 @@ -# t_add_integrity_commit Prover inputs -# Verifies data integrity and generates Merkle leaf -# Generated from fragmented_age_check/benchmark-inputs/case1/data_check_integrity_sa_prover.toml - -# Public input - commitment from t_add_id_data_720 -comm_in = "0x00c2be911a2957a80fb3384012b08dc81bc24ae0fd1ecafe9aacc7177b7411a3" -# Private inputs -salt_in = "0x3" - -# DG1 - Machine Readable Zone (95 bytes) -dg1 = [60, 60, 60, 60, 60, 60, 60, 65, 85, 83, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 48, 55, 48, 49, 48, 49, 60, 60, 51, 50, 48, 49, 48, 49, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 0, 0] -dg1_padded_length = 95 -dg1_hash_offset = 0 - -# SignedAttributes (200 bytes) -signed_attributes = [211, 193, 250, 21, 235, 80, 39, 78, 193, 183, 135, 72, 121, 250, 28, 5, 52, 114, 247, 226, 239, 85, 157, 215, 111, 196, 53, 0, 194, 221, 150, 136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] -signed_attributes_size = 32 - -# eContent (200 bytes) -e_content = [253, 51, 11, 117, 232, 161, 148, 187, 21, 27, 187, 140, 18, 92, 136, 34, 182, 250, 146, 125, 141, 230, 22, 147, 205, 153, 108, 117, 179, 69, 32, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] -e_content_len = 32 - -# Private nullifier - Poseidon2(DG1, eContent, SOD sig) -private_nullifier = "0x0e54c7a27d1b06d06f8aa014ad75a9c9fae9b79c84097d0650caa544828062e1" - -# Random blinding factor for Poseidon commitment to DG1 -# This must be remembered and used in t_attest -r_dg1 = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_hash_1300.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_dsc_verify_1300.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_add_id_data_1300.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml new file mode 100644 index 000000000..02747db5a --- /dev/null +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml @@ -0,0 +1,526 @@ +# t_add_integrity_commit Prover inputs +# Verifies data integrity and generates Merkle leaf +# Generated from fragmented_age_check/benchmark-inputs/tbs_720/data_check_integrity_sa_prover.toml + +# Public input - commitment from t_add_id_data_720 +comm_in = "0x00c2be911a2957a80fb3384012b08dc81bc24ae0fd1ecafe9aacc7177b7411a3" +# Private inputs +salt_in = "0x3" + +# DG1 - Machine Readable Zone (95 bytes) +dg1 = [ + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 65, + 85, + 83, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 48, + 55, + 48, + 49, + 48, + 49, + 60, + 60, + 51, + 50, + 48, + 49, + 48, + 49, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 60, + 0, + 0, +] +dg1_padded_length = 95 +dg1_hash_offset = 0 + +# SignedAttributes (200 bytes) +signed_attributes = [ + 211, + 193, + 250, + 21, + 235, + 80, + 39, + 78, + 193, + 183, + 135, + 72, + 121, + 250, + 28, + 5, + 52, + 114, + 247, + 226, + 239, + 85, + 157, + 215, + 111, + 196, + 53, + 0, + 194, + 221, + 150, + 136, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] +signed_attributes_size = 32 + +# eContent (200 bytes) +e_content = [ + 253, + 51, + 11, + 117, + 232, + 161, + 148, + 187, + 21, + 27, + 187, + 140, + 18, + 92, + 136, + 34, + 182, + 250, + 146, + 125, + 141, + 230, + 22, + 147, + 205, + 153, + 108, + 117, + 179, + 69, + 32, + 173, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +] +e_content_len = 32 + +# Private nullifier - Poseidon2(DG1, eContent, SOD sig) +private_nullifier = "0x0e54c7a27d1b06d06f8aa014ad75a9c9fae9b79c84097d0650caa544828062e1" + +# Random blinding factor for Poseidon commitment to DG1 +# This must be remembered and used in t_attest +r_dg1 = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case2/t_attest.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_dsc_720.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_id_data_720.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_add_integrity_commit.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/case1/t_attest.toml rename to noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/compile-circuits.sh similarity index 89% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/compile-circuits.sh index 29f163e30..99f64a856 100755 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/compile-circuits.sh +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/compile-circuits.sh @@ -5,7 +5,7 @@ CIRCUITS=( "t_add_integrity_commit" "t_attest" ) -LOG_DIR="../../benchmark-inputs/logs/compile/case2" +LOG_DIR="../../benchmark-inputs/logs/compile/tbs_1300" mkdir -p "$LOG_DIR" # Function to strip ANSI escape codes (works on macOS) diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh similarity index 91% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh index f8fe144df..75f95a030 100755 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prepare-circuits.sh +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh @@ -5,7 +5,7 @@ CIRCUITS=( "t_add_integrity_commit" "t_attest" ) -LOG_DIR="../../benchmark-inputs/logs/prepare/case2" +LOG_DIR="../../benchmark-inputs/logs/prepare/tbs_1300" mkdir -p "$LOG_DIR" # Function to strip ANSI escape codes (works on macOS) diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prove-circuits.sh similarity index 65% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prove-circuits.sh index 821019510..72ea114d8 100755 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case2/prove-circuits.sh +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prove-circuits.sh @@ -5,7 +5,7 @@ CIRCUITS=( "t_add_integrity_commit" "t_attest" ) -LOG_DIR="../../benchmark-inputs/logs/prove/case2" +LOG_DIR="../../benchmark-inputs/logs/prove/tbs_1300" mkdir -p "$LOG_DIR" # Function to strip ANSI escape codes (works on macOS) @@ -15,6 +15,6 @@ strip_ansi() { for circuit in "${CIRCUITS[@]}"; do echo "Proving $circuit" - cargo run --release --bin provekit-cli prove ../../benchmark-inputs/$circuit-prover.pkp ../../benchmark-inputs/case2/"$circuit".toml -o ../../benchmark-inputs/$circuit-proof.np 2>&1 | strip_ansi | tee "$LOG_DIR/$circuit.log" + cargo run --release --bin provekit-cli prove ../../benchmark-inputs/$circuit-prover.pkp ../../benchmark-inputs/tbs_1300/"$circuit".toml -o ../../benchmark-inputs/$circuit-proof.np 2>&1 | strip_ansi | tee "$LOG_DIR/$circuit.log" echo "Proved $circuit" done diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/compile-circuits.sh similarity index 88% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/compile-circuits.sh index b6be3c924..726fb2181 100755 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/compile-circuits.sh +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/compile-circuits.sh @@ -4,7 +4,7 @@ CIRCUITS=( "t_add_integrity_commit" "t_attest" ) -LOG_DIR="../../benchmark-inputs/logs/compile/case1" +LOG_DIR="../../benchmark-inputs/logs/compile/tbs_720" mkdir -p "$LOG_DIR" # Function to strip ANSI escape codes (works on macOS) diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prepare-circuits.sh similarity index 91% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prepare-circuits.sh index 622df8ac3..84dd1ef38 100755 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prepare-circuits.sh +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prepare-circuits.sh @@ -4,7 +4,7 @@ CIRCUITS=( "t_add_integrity_commit" "t_attest" ) -LOG_DIR="../../benchmark-inputs/logs/prepare/case1" +LOG_DIR="../../benchmark-inputs/logs/prepare/tbs_720" mkdir -p "$LOG_DIR" # Function to strip ANSI escape codes (works on macOS) diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prove-circuits.sh similarity index 63% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh rename to noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prove-circuits.sh index d02320189..4b5c9beca 100755 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/case1/prove-circuits.sh +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prove-circuits.sh @@ -4,7 +4,7 @@ CIRCUITS=( "t_add_integrity_commit" "t_attest" ) -LOG_DIR="../../benchmark-inputs/logs/prove/case1" +LOG_DIR="../../benchmark-inputs/logs/prove/tbs_720" mkdir -p "$LOG_DIR" # Function to strip ANSI escape codes (works on macOS) @@ -14,6 +14,6 @@ strip_ansi() { for circuit in "${CIRCUITS[@]}"; do echo "Proving $circuit" - cargo run --release --bin provekit-cli prove ../../benchmark-inputs/$circuit-prover.pkp ../../benchmark-inputs/case1/"$circuit".toml -o ../../benchmark-inputs/$circuit-proof.np 2>&1 | strip_ansi | tee "$LOG_DIR/$circuit.log" + cargo run --release --bin provekit-cli prove ../../benchmark-inputs/$circuit-prover.pkp ../../benchmark-inputs/tbs_720/"$circuit".toml -o ../../benchmark-inputs/$circuit-proof.np 2>&1 | strip_ansi | tee "$LOG_DIR/$circuit.log" echo "Proved $circuit" done From 2c81a40ff7388bc4335974b6920d745ceba6e6b2 Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 19:43:47 +0530 Subject: [PATCH 07/15] added verification to ci --- .github/workflows/circuit_keys.yml | 23 ++++++++++++++++------- .github/workflows/end-to-end.yml | 13 ++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.github/workflows/circuit_keys.yml b/.github/workflows/circuit_keys.yml index b67628b5a..8c89d0e6b 100644 --- a/.github/workflows/circuit_keys.yml +++ b/.github/workflows/circuit_keys.yml @@ -45,7 +45,7 @@ jobs: with: toolchain: v1.0.0-beta.11 - - name: Compile Nargo circuits + - name: Compile Nargo circuits working-directory: ${{ env.CIRCUIT_DIR }} run: | for circuit in ${{ env.CIRCUITS }}; do @@ -77,6 +77,17 @@ jobs: echo "Proved $circuit" done + - name: Verify proofs for all circuits + working-directory: ${{ env.CIRCUIT_DIR }} + run: | + for circuit in ${{ env.CIRCUITS }}; do + echo "Verifying $circuit" + cargo run --release --bin provekit-cli verify \ + ./benchmark-inputs/$circuit-verifier.pkv \ + ./benchmark-inputs/$circuit-proof.np + echo "Verified $circuit" + done + - name: Generate Gnark inputs (t_attest only) working-directory: ${{ env.CIRCUIT_DIR }} run: | @@ -84,7 +95,7 @@ jobs: ./benchmark-inputs/t_attest-prover.pkp \ ./benchmark-inputs/t_attest-proof.np - - name: Run Gnark verifier + - name: Run Gnark verifier working-directory: recursive-verifier run: | go run cmd/cli/main.go --config "../${{ env.CIRCUIT_DIR }}/params_for_recursive_verifier" --r1cs "../${{ env.CIRCUIT_DIR }}/r1cs.json" --saveKeys "./keys" @@ -94,18 +105,17 @@ jobs: run: | ls -la ./keys/*.bin || echo "No keys" - - name: Upload keys to gcp + - name: Upload keys to gcp working-directory: recursive-verifier run: | - # Upload Gnark verifier keys for t_attest PK_FILE=$(ls -t ./keys/pk_*.bin 2>/dev/null | head -1) VK_FILE=$(ls -t ./keys/vk_*.bin 2>/dev/null | head -1) if [ -z "$PK_FILE" ] || [ -z "$VK_FILE" ]; then - echo "Error: Could not find Gnark keys" + echo "Error: Could not find keys" exit 1 fi - + echo "Found PK file: $PK_FILE" echo "Found VK file: $VK_FILE" @@ -118,7 +128,6 @@ jobs: gsutil cp "$PK_FILE" "gs://${{ env.BUCKET_NAME }}/$ATTEST_PK_NAME" gsutil cp "$VK_FILE" "gs://${{ env.BUCKET_NAME }}/$ATTEST_VK_NAME" - # Upload Noir prover/verifier keys for all 4 circuits cd "../${{ env.CIRCUIT_DIR }}" for circuit in ${{ env.CIRCUITS }}; do if [ -f "./benchmark-inputs/${circuit}-prover.pkp" ]; then diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index c61b130e3..c8e802054 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -75,7 +75,18 @@ jobs: echo "Proved $circuit" done - - name: Generate Gnark inputs + - name: Verify proofs for all circuits + working-directory: noir-examples/noir-passport/fragmented/merkle_age_check + run: | + for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do + echo "Verifying $circuit" + cargo run --release --bin provekit-cli verify \ + ./benchmark-inputs/$circuit-verifier.pkv \ + ./benchmark-inputs/$circuit-proof.np + echo "Verified $circuit" + done + + - name: Generate Gnark inputs working-directory: noir-examples/noir-passport/fragmented/merkle_age_check run: | cargo run --release --bin provekit-cli generate-gnark-inputs \ From 13861ca991c5b4a173107ec9e99c8637ffc9cd02 Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 19:54:20 +0530 Subject: [PATCH 08/15] typo fix --- .../noir-passport/fragmented/merkle_age_check/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md index dbf5a4078..406eec6dd 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md @@ -44,7 +44,7 @@ The `t_attest` circuit provides fast, repeatable proofs: Benchmark inputs have already been generated and are available in the `benchmark-inputs` directory. -Scripts are provided separately for tbs_700 (4-circuit chain) and tbs_1300 (5-circuit chain). Navigate to the scripts directory and run the appropriate sequence: +Scripts are provided separately for tbs_720 (4-circuit chain) and tbs_1300 (5-circuit chain). Navigate to the scripts directory and run the appropriate sequence: ```bash cd scripts From 1ce1d713ea070fb5907bea18b386e7e71ca7f6ca Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 20:20:47 +0530 Subject: [PATCH 09/15] compiler test path fix --- tooling/provekit-bench/tests/compiler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/provekit-bench/tests/compiler.rs b/tooling/provekit-bench/tests/compiler.rs index 8643bcfba..e15e46113 100644 --- a/tooling/provekit-bench/tests/compiler.rs +++ b/tooling/provekit-bench/tests/compiler.rs @@ -82,7 +82,7 @@ pub fn compile_workspace(workspace_path: impl AsRef) -> Result #[test_case("../../noir-examples/noir-r1cs-test-programs/small-sha")] #[test_case("../../noir-examples/noir-r1cs-test-programs/bounded-vec")] #[test_case("../../noir-examples/noir-r1cs-test-programs/brillig-unconstrained")] -#[test_case("../../noir-examples/noir-passport-monolithic/complete_age_check"; "complete_age_check")] +#[test_case("../../noir-examples/noir-passport-monolithic/monolithic/complete_age_check"; "complete_age_check")] fn case(path: &str) { test_compiler(path); } From d31bb1652562028de3b876d0410b8e151fea413e Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Tue, 10 Feb 2026 20:41:54 +0530 Subject: [PATCH 10/15] addressed copilot changes --- .../utils/passport_validity_check/src/lib.nr | 19 +++++++++++++++---- .../utils/utils/src/lib.nr | 1 + .../t_add_dsc_verify_1300/Nargo.toml | 1 - .../utils/data-check/integrity/src/lib.nr | 9 ++++----- .../utils/compare/age/src/lib.nr | 2 +- .../utils/data-check/expiry/Nargo.toml | 3 +-- .../noir-passport/utils/utils/src/lib.nr | 1 + 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr b/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr index 80b7793c0..173df0a21 100644 --- a/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr +++ b/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr @@ -81,7 +81,7 @@ pub fn check_passport_validity(passport_validity_contents: PassportValidityConte passport_validity_contents.dsc_rsa_exponent, passport_validity_contents.signed_attributes, passport_validity_contents.signed_attributes_size as u32, - 0 + 0, )); // --- DSC certificate signature check --- @@ -102,7 +102,7 @@ pub fn check_passport_validity(passport_validity_contents: PassportValidityConte passport_validity_contents.csc_rsa_exponent, passport_validity_contents.dsc_cert, // This is `data_to_sign`, i.e. the message passport_validity_contents.dsc_cert_len, - 0 + 0, )); } @@ -118,10 +118,15 @@ pub fn check_integrity_of_sod_within_sod_cert( // Check zero padding for signed_attributes check_zero_padding(signed_attributes, signed_attributes_size); + // Bounds check: ensure econtent_hash_offset + 32 doesn't exceed signed_attributes_size + assert( + econtent_hash_offset + 32 <= signed_attributes_size, + "econtent_hash_offset out of bounds", + ); + // Clearly the SOD itself is supposed to be hashed and then concatenated with some other "stuff" // That "stuff" is the thing which is actually signed - let econtent_hash = - sha256_var(econtent, econtent_len as u64); + let econtent_hash = sha256_var(econtent, econtent_len as u64); for i in 0..32 { assert(econtent_hash[i] == signed_attributes[econtent_hash_offset + i]); @@ -140,6 +145,12 @@ pub fn check_dg1_hash_within_sod( // Check zero padding for econtent check_zero_padding(econtent, econtent_len); + // Bounds check: ensure dg1_hash_offset + 32 doesn't exceed econtent_len + assert(dg1_hash_offset + 32 <= econtent_len, "dg1_hash_offset out of bounds"); + + // Ensure dg1_padded_length doesn't exceed the actual array size + assert(dg1_padded_length <= 95, "dg1_padded_length out of bounds"); + let dg1_hash = sha256_var(dg1, dg1_padded_length); // The DG1 hash is located at the start of the SOD diff --git a/noir-examples/noir-passport-monolithic/utils/utils/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/utils/src/lib.nr index 5b60b92dd..ff87118e0 100644 --- a/noir-examples/noir-passport-monolithic/utils/utils/src/lib.nr +++ b/noir-examples/noir-passport-monolithic/utils/utils/src/lib.nr @@ -140,6 +140,7 @@ where T: Eq, T: Default, { + assert(len <= N, "check_zero_padding: len exceeds array size"); for i in 0..N { if i >= len { assert_eq(padded_array[i], T::default()); diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml index a459a092f..63f043955 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml @@ -5,7 +5,6 @@ compiler_version = ">=1.0.0" [dependencies] partial_sha256 = { path = "../../../../partial_sha256" } -sig_check_rsa = { path = "../../../utils/sig-check/rsa" } fragmented_sig_check_rsa = { path = "../../utils/sig-check/rsa" } utils = { path = "../../../utils/utils" } commitment = { path = "../../utils/commitment/common" } diff --git a/noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr b/noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr index 5e13f7b90..e5e783073 100644 --- a/noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr +++ b/noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr @@ -1,9 +1,5 @@ use sha256::sha256_var; -use utils::{ - check_zero_padding, - is_subarray_in_array, - types::EContentData, -}; +use utils::{check_zero_padding, is_subarray_in_array, types::EContentData}; pub fn check_dg1_hash_within_sod( dg1: [u8; 95], @@ -18,6 +14,9 @@ pub fn check_dg1_hash_within_sod( // Bounds check: ensure dg1_hash_offset + 32 doesn't exceed econtent_len assert(dg1_hash_offset + 32 <= econtent_len, "dg1_hash_offset out of bounds"); + // Ensure dg1_padded_length doesn't exceed the actual array size + assert(dg1_padded_length <= 95, "dg1_padded_length out of bounds"); + let dg1_hash = sha256_var(dg1, dg1_padded_length); // The DG1 hash is located at the start of the SOD diff --git a/noir-examples/noir-passport/utils/compare/age/src/lib.nr b/noir-examples/noir-passport/utils/compare/age/src/lib.nr index c0bc5a228..c22ac72cd 100644 --- a/noir-examples/noir-passport/utils/compare/age/src/lib.nr +++ b/noir-examples/noir-passport/utils/compare/age/src/lib.nr @@ -16,7 +16,7 @@ fn get_birthdate(dg1: [u8; 95], timestamp: u64) -> Date { ID_CARD_MRZ_BIRTHDATE_INDEX + 6, ); } else { - // Otherwise it's an ID card + // Otherwise it's a passport birthdate_bytes = get_array_slice( mrz, PASSPORT_MRZ_BIRTHDATE_INDEX, diff --git a/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml b/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml index cc7ca6b49..ddeffcd26 100644 --- a/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml +++ b/noir-examples/noir-passport/utils/data-check/expiry/Nargo.toml @@ -6,5 +6,4 @@ compiler_version = ">=0.22.0" [dependencies] date = { tag = "v0.5.2", git = "https://github.com/madztheo/noir-date.git" } -utils = { path = "../../utils" } -age = {path = "../../compare/age"} \ No newline at end of file +utils = { path = "../../utils" } \ No newline at end of file diff --git a/noir-examples/noir-passport/utils/utils/src/lib.nr b/noir-examples/noir-passport/utils/utils/src/lib.nr index 5b60b92dd..ff87118e0 100644 --- a/noir-examples/noir-passport/utils/utils/src/lib.nr +++ b/noir-examples/noir-passport/utils/utils/src/lib.nr @@ -140,6 +140,7 @@ where T: Eq, T: Default, { + assert(len <= N, "check_zero_padding: len exceeds array size"); for i in 0..N { if i >= len { assert_eq(padded_array[i], T::default()); From 8dd99c9eff7b5e63c2214c85dc4ff85b032a696a Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Wed, 11 Feb 2026 01:47:23 +0530 Subject: [PATCH 11/15] copilot comments --- .../utils/data-check/tbs-pubkey/src/lib.nr | 4 ++++ .../fragmented/merkle_age_check/README.md | 6 +++--- .../utils/data-check/tbs-pubkey/src/lib.nr | 4 ++++ .../noir-passport/utils/sig-check/common/src/lib.nr | 12 +++--------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/src/lib.nr index 2565c4397..90543f752 100644 --- a/noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/src/lib.nr +++ b/noir-examples/noir-passport-monolithic/utils/data-check/tbs-pubkey/src/lib.nr @@ -7,6 +7,10 @@ pub fn verify_rsa_pubkey_in_tbs( // And since the TBS certificate is the data signed by the private key of the CSCA certificate // we can make sure the DSC, which signed the data of the passport, has been signed by the // root certificate of the issuing State (i.e. CSCA certificate) by verifying the signature below + assert( + pubkey_offset + DSC_KEY_SIZE <= TBS_CERT_SIZE, + "pubkey_offset + DSC_KEY_SIZE exceeds TBS certificate size", + ); for i in 0..DSC_KEY_SIZE { assert(tbs_certificate[i + pubkey_offset] == dsc_pubkey[i]); } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md index 406eec6dd..333ac3b0e 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md +++ b/noir-examples/noir-passport/fragmented/merkle_age_check/README.md @@ -69,11 +69,11 @@ cd tbs_720 cd tbs_1300 # 1. Compile circuits: Generates compiled artifacts inside merkle_age_check/target/ for all 5 circuits -./compile.sh +./compile-circuits.sh # 2. Prepare proving artifacts: Generates proving keys and verification keys for all 5 circuits, stored in merkle_age_check/benchmark-inputs/ -./prepare.sh +./prepare-circuits.sh # 3. Generate proofs: Generates proofs for all 5 circuits using the prepared artifacts and benchmark inputs, stored in merkle_age_check/benchmark-inputs/ -./prove.sh +./prove-circuits.sh ``` \ No newline at end of file diff --git a/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr b/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr index 2565c4397..90543f752 100644 --- a/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr +++ b/noir-examples/noir-passport/utils/data-check/tbs-pubkey/src/lib.nr @@ -7,6 +7,10 @@ pub fn verify_rsa_pubkey_in_tbs( // And since the TBS certificate is the data signed by the private key of the CSCA certificate // we can make sure the DSC, which signed the data of the passport, has been signed by the // root certificate of the issuing State (i.e. CSCA certificate) by verifying the signature below + assert( + pubkey_offset + DSC_KEY_SIZE <= TBS_CERT_SIZE, + "pubkey_offset + DSC_KEY_SIZE exceeds TBS certificate size", + ); for i in 0..DSC_KEY_SIZE { assert(tbs_certificate[i + pubkey_offset] == dsc_pubkey[i]); } diff --git a/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr b/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr index 0c4d8fabc..84f53cfd9 100644 --- a/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr +++ b/noir-examples/noir-passport/utils/sig-check/common/src/lib.nr @@ -34,15 +34,9 @@ pub fn sha256_and_check_data_to_sign( // Ensure all bytes beyond data_to_sign_len are zero to prevent them // from being used by the prover check_zero_padding(data_to_sign, data_to_sign_len); - // Calculate the hash of data_to_sign up to data_to_sign_len - // sha256_var(data_to_sign, data_to_sign_len as u64) - - // Hash the entire buffer to match the signature created on the fixed-size message - // `data_to_sign_len` is still checked above to ensure trailing bytes are zero, - let ret = - sha256_var(data_to_sign, data_to_sign_len as u64); - - ret + // Calculate the hash of data_to_sign up to data_to_sign_len. + // Zero-padding is verified above to ensure trailing bytes cannot be manipulated. + sha256_var(data_to_sign, data_to_sign_len as u64) } pub fn sha384_and_check_data_to_sign( From 4b38c4d4cb3cfa780e8b44c639da3e3f0ed56a3a Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Wed, 11 Feb 2026 02:14:36 +0530 Subject: [PATCH 12/15] moved one dir level down --- .github/workflows/circuit_keys.yml | 2 +- .github/workflows/end-to-end.yml | 12 ++++++------ .../{monolithic => }/complete_age_check/Nargo.toml | 4 ++-- .../{monolithic => }/complete_age_check/Prover.toml | 0 .../complete_age_check/scripts/compile.sh | 0 .../{monolithic => }/complete_age_check/src/main.nr | 0 .../utils/passport_validity_check/Nargo.toml | 6 +++--- .../utils/passport_validity_check/src/lib.nr | 0 .../merkle_age_check/t_add_id_data_1300/Nargo.toml | 10 ---------- .../merkle_age_check/t_add_id_data_720/Nargo.toml | 10 ---------- .../{fragmented => }/merkle_age_check/Nargo.toml | 0 .../{fragmented => }/merkle_age_check/README.md | 0 .../tbs_1300/t_add_dsc_hash_1300.toml | 0 .../tbs_1300/t_add_dsc_verify_1300.toml | 0 .../tbs_1300/t_add_id_data_1300.toml | 0 .../tbs_1300/t_add_integrity_commit.toml | 0 .../benchmark-inputs/tbs_1300/t_attest.toml | 0 .../benchmark-inputs/tbs_720/t_add_dsc_720.toml | 0 .../benchmark-inputs/tbs_720/t_add_id_data_720.toml | 0 .../tbs_720/t_add_integrity_commit.toml | 0 .../benchmark-inputs/tbs_720/t_attest.toml | 0 .../scripts/tbs_1300/compile-circuits.sh | 0 .../scripts/tbs_1300/prepare-circuits.sh | 0 .../scripts/tbs_1300/prove-circuits.sh | 0 .../scripts/tbs_720/compile-circuits.sh | 0 .../scripts/tbs_720/prepare-circuits.sh | 0 .../scripts/tbs_720/prove-circuits.sh | 0 .../merkle_age_check/t_add_dsc_720/Nargo.toml | 4 ++-- .../merkle_age_check/t_add_dsc_720/src/main.nr | 0 .../merkle_age_check/t_add_dsc_hash_1300/Nargo.toml | 2 +- .../merkle_age_check/t_add_dsc_hash_1300/src/main.nr | 0 .../t_add_dsc_verify_1300/Nargo.toml | 6 +++--- .../t_add_dsc_verify_1300/src/main.nr | 0 .../merkle_age_check/t_add_id_data_1300/Nargo.toml | 10 ++++++++++ .../merkle_age_check/t_add_id_data_1300/src/main.nr | 0 .../merkle_age_check/t_add_id_data_720/Nargo.toml | 10 ++++++++++ .../merkle_age_check/t_add_id_data_720/src/main.nr | 0 .../t_add_integrity_commit/Nargo.toml | 2 +- .../t_add_integrity_commit/src/main.nr | 0 .../merkle_age_check/t_attest/Nargo.toml | 6 +++--- .../merkle_age_check/t_attest/src/main.nr | 0 .../utils/commitment/common/Nargo.toml | 4 ++-- .../utils/commitment/common/src/lib.nr | 0 .../utils/commitment/dsc-to-id/Nargo.toml | 3 +-- .../utils/commitment/dsc-to-id/src/lib.nr | 0 .../utils/commitment/scoped-nullifier/Nargo.toml | 2 +- .../utils/commitment/scoped-nullifier/src/lib.nr | 0 .../utils/data-check/integrity/Nargo.toml | 2 +- .../utils/data-check/integrity/src/lib.nr | 0 .../sig-check/fragmented-rsa}/Nargo.toml | 2 +- .../sig-check/fragmented-rsa}/src/lib.nr | 0 51 files changed, 48 insertions(+), 49 deletions(-) rename noir-examples/noir-passport-monolithic/{monolithic => }/complete_age_check/Nargo.toml (59%) rename noir-examples/noir-passport-monolithic/{monolithic => }/complete_age_check/Prover.toml (100%) rename noir-examples/noir-passport-monolithic/{monolithic => }/complete_age_check/scripts/compile.sh (100%) rename noir-examples/noir-passport-monolithic/{monolithic => }/complete_age_check/src/main.nr (100%) rename noir-examples/noir-passport-monolithic/{monolithic => }/utils/passport_validity_check/Nargo.toml (50%) rename noir-examples/noir-passport-monolithic/{monolithic => }/utils/passport_validity_check/src/lib.nr (100%) delete mode 100644 noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml delete mode 100644 noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/Nargo.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/README.md (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/scripts/tbs_1300/compile-circuits.sh (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/scripts/tbs_1300/prove-circuits.sh (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/scripts/tbs_720/compile-circuits.sh (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/scripts/tbs_720/prepare-circuits.sh (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/scripts/tbs_720/prove-circuits.sh (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_dsc_720/Nargo.toml (69%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_dsc_720/src/main.nr (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml (62%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_dsc_hash_1300/src/main.nr (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml (57%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_dsc_verify_1300/src/main.nr (100%) create mode 100644 noir-examples/noir-passport/merkle_age_check/t_add_id_data_1300/Nargo.toml rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_id_data_1300/src/main.nr (100%) create mode 100644 noir-examples/noir-passport/merkle_age_check/t_add_id_data_720/Nargo.toml rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_id_data_720/src/main.nr (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_integrity_commit/Nargo.toml (87%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_add_integrity_commit/src/main.nr (100%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_attest/Nargo.toml (63%) rename noir-examples/noir-passport/{fragmented => }/merkle_age_check/t_attest/src/main.nr (100%) rename noir-examples/noir-passport/{fragmented => }/utils/commitment/common/Nargo.toml (76%) rename noir-examples/noir-passport/{fragmented => }/utils/commitment/common/src/lib.nr (100%) rename noir-examples/noir-passport/{fragmented => }/utils/commitment/dsc-to-id/Nargo.toml (79%) rename noir-examples/noir-passport/{fragmented => }/utils/commitment/dsc-to-id/src/lib.nr (100%) rename noir-examples/noir-passport/{fragmented => }/utils/commitment/scoped-nullifier/Nargo.toml (82%) rename noir-examples/noir-passport/{fragmented => }/utils/commitment/scoped-nullifier/src/lib.nr (100%) rename noir-examples/noir-passport/{fragmented => }/utils/data-check/integrity/Nargo.toml (81%) rename noir-examples/noir-passport/{fragmented => }/utils/data-check/integrity/src/lib.nr (100%) rename noir-examples/noir-passport/{fragmented/utils/sig-check/rsa => utils/sig-check/fragmented-rsa}/Nargo.toml (84%) rename noir-examples/noir-passport/{fragmented/utils/sig-check/rsa => utils/sig-check/fragmented-rsa}/src/lib.nr (100%) diff --git a/.github/workflows/circuit_keys.yml b/.github/workflows/circuit_keys.yml index 8c89d0e6b..4d5f291f9 100644 --- a/.github/workflows/circuit_keys.yml +++ b/.github/workflows/circuit_keys.yml @@ -5,7 +5,7 @@ on: env: BUCKET_NAME: "provekit" - CIRCUIT_DIR: "noir-examples/noir-passport/fragmented/merkle_age_check" + CIRCUIT_DIR: "noir-examples/noir-passport/merkle_age_check" KEYS_NAME: "agecheck" CIRCUITS: "t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest" diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index c8e802054..dda73638a 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -44,7 +44,7 @@ jobs: go-version: 1.24 - name: Compile Nargo circuits - working-directory: noir-examples/noir-passport/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Compiling $circuit" @@ -53,7 +53,7 @@ jobs: done - name: Prepare circuits - working-directory: noir-examples/noir-passport/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Preparing $circuit" @@ -64,7 +64,7 @@ jobs: done - name: Generate proofs for all circuits - working-directory: noir-examples/noir-passport/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Proving $circuit" @@ -76,7 +76,7 @@ jobs: done - name: Verify proofs for all circuits - working-directory: noir-examples/noir-passport/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/merkle_age_check run: | for circuit in t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest; do echo "Verifying $circuit" @@ -87,7 +87,7 @@ jobs: done - name: Generate Gnark inputs - working-directory: noir-examples/noir-passport/fragmented/merkle_age_check + working-directory: noir-examples/noir-passport/merkle_age_check run: | cargo run --release --bin provekit-cli generate-gnark-inputs \ ./benchmark-inputs/t_attest-prover.pkp \ @@ -123,7 +123,7 @@ jobs: MONITOR_PID=$! # Run the main process - ./gnark-verifier --config "../noir-examples/noir-passport/fragmented/merkle_age_check/params_for_recursive_verifier" --r1cs "../noir-examples/noir-passport/fragmented/merkle_age_check/r1cs.json" + ./gnark-verifier --config "../noir-examples/noir-passport/merkle_age_check/params_for_recursive_verifier" --r1cs "../noir-examples/noir-passport/merkle_age_check/r1cs.json" # Stop monitoring kill $MONITOR_PID \ No newline at end of file diff --git a/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Nargo.toml b/noir-examples/noir-passport-monolithic/complete_age_check/Nargo.toml similarity index 59% rename from noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Nargo.toml rename to noir-examples/noir-passport-monolithic/complete_age_check/Nargo.toml index a71792971..10df72565 100644 --- a/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Nargo.toml +++ b/noir-examples/noir-passport-monolithic/complete_age_check/Nargo.toml @@ -4,6 +4,6 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -compare_age = { path = "../../utils/compare/age" } -data_check_expiry = { path = "../../utils/data-check/expiry" } +compare_age = { path = "../utils/compare/age" } +data_check_expiry = { path = "../utils/data-check/expiry" } passport_validity_check = { path = "../utils/passport_validity_check" } diff --git a/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Prover.toml b/noir-examples/noir-passport-monolithic/complete_age_check/Prover.toml similarity index 100% rename from noir-examples/noir-passport-monolithic/monolithic/complete_age_check/Prover.toml rename to noir-examples/noir-passport-monolithic/complete_age_check/Prover.toml diff --git a/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/scripts/compile.sh b/noir-examples/noir-passport-monolithic/complete_age_check/scripts/compile.sh similarity index 100% rename from noir-examples/noir-passport-monolithic/monolithic/complete_age_check/scripts/compile.sh rename to noir-examples/noir-passport-monolithic/complete_age_check/scripts/compile.sh diff --git a/noir-examples/noir-passport-monolithic/monolithic/complete_age_check/src/main.nr b/noir-examples/noir-passport-monolithic/complete_age_check/src/main.nr similarity index 100% rename from noir-examples/noir-passport-monolithic/monolithic/complete_age_check/src/main.nr rename to noir-examples/noir-passport-monolithic/complete_age_check/src/main.nr diff --git a/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/Nargo.toml b/noir-examples/noir-passport-monolithic/utils/passport_validity_check/Nargo.toml similarity index 50% rename from noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/Nargo.toml rename to noir-examples/noir-passport-monolithic/utils/passport_validity_check/Nargo.toml index 448ded780..5f177b136 100644 --- a/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/Nargo.toml +++ b/noir-examples/noir-passport-monolithic/utils/passport_validity_check/Nargo.toml @@ -4,7 +4,7 @@ type = "lib" compiler_version = ">=1.0.0" [dependencies] -sig_check_rsa = { path = "../../../utils/sig-check/rsa" } -utils = { path = "../../../utils/utils" } -data_check_tbs_pubkey = { path = "../../../utils/data-check/tbs-pubkey" } +sig_check_rsa = { path = "../sig-check/rsa" } +utils = { path = "../utils" } +data_check_tbs_pubkey = { path = "../data-check/tbs-pubkey" } sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } diff --git a/noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr b/noir-examples/noir-passport-monolithic/utils/passport_validity_check/src/lib.nr similarity index 100% rename from noir-examples/noir-passport-monolithic/monolithic/utils/passport_validity_check/src/lib.nr rename to noir-examples/noir-passport-monolithic/utils/passport_validity_check/src/lib.nr diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml deleted file mode 100644 index cdc2f9b24..000000000 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/Nargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "t_add_id_data_1300" -type = "bin" -compiler_version = ">=1.0.0" - -[dependencies] -sig_check_rsa = { path = "../../../utils/sig-check/rsa" } -utils = { path = "../../../utils/utils" } -data_check_tbs_pubkey = { path = "../../../utils/data-check/tbs-pubkey" } -commitment = { path = "../../utils/commitment/dsc-to-id" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml b/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml deleted file mode 100644 index b34b902c6..000000000 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/Nargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "t_add_id_data_720" -type = "bin" -compiler_version = ">=1.0.0" - -[dependencies] -sig_check_rsa = { path = "../../../utils/sig-check/rsa" } -utils = { path = "../../../utils/utils" } -data_check_tbs_pubkey = { path = "../../../utils/data-check/tbs-pubkey" } -commitment = { path = "../../utils/commitment/dsc-to-id" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/Nargo.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/Nargo.toml rename to noir-examples/noir-passport/merkle_age_check/Nargo.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/README.md b/noir-examples/noir-passport/merkle_age_check/README.md similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/README.md rename to noir-examples/noir-passport/merkle_age_check/README.md diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_hash_1300.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_dsc_verify_1300.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_id_data_1300.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_1300/t_attest.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_add_dsc_720.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_add_id_data_720.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_add_integrity_commit.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml b/noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml rename to noir-examples/noir-passport/merkle_age_check/benchmark-inputs/tbs_720/t_attest.toml diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/compile-circuits.sh b/noir-examples/noir-passport/merkle_age_check/scripts/tbs_1300/compile-circuits.sh similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/compile-circuits.sh rename to noir-examples/noir-passport/merkle_age_check/scripts/tbs_1300/compile-circuits.sh diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh b/noir-examples/noir-passport/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh rename to noir-examples/noir-passport/merkle_age_check/scripts/tbs_1300/prepare-circuits.sh diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prove-circuits.sh b/noir-examples/noir-passport/merkle_age_check/scripts/tbs_1300/prove-circuits.sh similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_1300/prove-circuits.sh rename to noir-examples/noir-passport/merkle_age_check/scripts/tbs_1300/prove-circuits.sh diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/compile-circuits.sh b/noir-examples/noir-passport/merkle_age_check/scripts/tbs_720/compile-circuits.sh similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/compile-circuits.sh rename to noir-examples/noir-passport/merkle_age_check/scripts/tbs_720/compile-circuits.sh diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prepare-circuits.sh b/noir-examples/noir-passport/merkle_age_check/scripts/tbs_720/prepare-circuits.sh similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prepare-circuits.sh rename to noir-examples/noir-passport/merkle_age_check/scripts/tbs_720/prepare-circuits.sh diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prove-circuits.sh b/noir-examples/noir-passport/merkle_age_check/scripts/tbs_720/prove-circuits.sh similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/scripts/tbs_720/prove-circuits.sh rename to noir-examples/noir-passport/merkle_age_check/scripts/tbs_720/prove-circuits.sh diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_720/Nargo.toml similarity index 69% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml rename to noir-examples/noir-passport/merkle_age_check/t_add_dsc_720/Nargo.toml index 27a26e4f8..4069a1a85 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/Nargo.toml +++ b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_720/Nargo.toml @@ -4,7 +4,7 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -sig_check_rsa = { path = "../../../utils/sig-check/rsa" } -utils = { path = "../../../utils/utils" } +sig_check_rsa = { path = "../../utils/sig-check/rsa" } +utils = { path = "../../utils/utils" } commitment = { path = "../../utils/commitment/common" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_720/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_720/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_add_dsc_720/src/main.nr diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml similarity index 62% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml rename to noir-examples/noir-passport/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml index baa071e67..67321b8fb 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml +++ b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_hash_1300/Nargo.toml @@ -4,4 +4,4 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -partial_sha256 = { path = "../../../../partial_sha256" } +partial_sha256 = { path = "../../../partial_sha256" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_hash_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_hash_1300/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_add_dsc_hash_1300/src/main.nr diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml similarity index 57% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml rename to noir-examples/noir-passport/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml index 63f043955..5037fa836 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml +++ b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_verify_1300/Nargo.toml @@ -4,8 +4,8 @@ type = "bin" compiler_version = ">=1.0.0" [dependencies] -partial_sha256 = { path = "../../../../partial_sha256" } -fragmented_sig_check_rsa = { path = "../../utils/sig-check/rsa" } -utils = { path = "../../../utils/utils" } +partial_sha256 = { path = "../../../partial_sha256" } +fragmented_sig_check_rsa = { path = "../../utils/sig-check/fragmented-rsa" } +utils = { path = "../../utils/utils" } commitment = { path = "../../utils/commitment/common" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_add_dsc_verify_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_dsc_verify_1300/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_add_dsc_verify_1300/src/main.nr diff --git a/noir-examples/noir-passport/merkle_age_check/t_add_id_data_1300/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_add_id_data_1300/Nargo.toml new file mode 100644 index 000000000..7f28b4b7d --- /dev/null +++ b/noir-examples/noir-passport/merkle_age_check/t_add_id_data_1300/Nargo.toml @@ -0,0 +1,10 @@ +[package] +name = "t_add_id_data_1300" +type = "bin" +compiler_version = ">=1.0.0" + +[dependencies] +sig_check_rsa = { path = "../../utils/sig-check/rsa" } +utils = { path = "../../utils/utils" } +data_check_tbs_pubkey = { path = "../../utils/data-check/tbs-pubkey" } +commitment = { path = "../../utils/commitment/dsc-to-id" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_add_id_data_1300/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_1300/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_add_id_data_1300/src/main.nr diff --git a/noir-examples/noir-passport/merkle_age_check/t_add_id_data_720/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_add_id_data_720/Nargo.toml new file mode 100644 index 000000000..b223b94b2 --- /dev/null +++ b/noir-examples/noir-passport/merkle_age_check/t_add_id_data_720/Nargo.toml @@ -0,0 +1,10 @@ +[package] +name = "t_add_id_data_720" +type = "bin" +compiler_version = ">=1.0.0" + +[dependencies] +sig_check_rsa = { path = "../../utils/sig-check/rsa" } +utils = { path = "../../utils/utils" } +data_check_tbs_pubkey = { path = "../../utils/data-check/tbs-pubkey" } +commitment = { path = "../../utils/commitment/dsc-to-id" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_add_id_data_720/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_id_data_720/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_add_id_data_720/src/main.nr diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_add_integrity_commit/Nargo.toml similarity index 87% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml rename to noir-examples/noir-passport/merkle_age_check/t_add_integrity_commit/Nargo.toml index eed10146f..df5f2a907 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/Nargo.toml +++ b/noir-examples/noir-passport/merkle_age_check/t_add_integrity_commit/Nargo.toml @@ -6,5 +6,5 @@ compiler_version = ">=1.0.0" [dependencies] data_check_integrity = { path = "../../utils/data-check/integrity" } common = { path = "../../utils/commitment/common" } -utils = { path = "../../../utils/utils" } +utils = { path = "../../utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_add_integrity_commit/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_add_integrity_commit/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_add_integrity_commit/src/main.nr diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/Nargo.toml b/noir-examples/noir-passport/merkle_age_check/t_attest/Nargo.toml similarity index 63% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/Nargo.toml rename to noir-examples/noir-passport/merkle_age_check/t_attest/Nargo.toml index d944dae79..d25a5d50a 100644 --- a/noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/Nargo.toml +++ b/noir-examples/noir-passport/merkle_age_check/t_attest/Nargo.toml @@ -5,8 +5,8 @@ compiler_version = ">=1.0.0" [dependencies] common = { path = "../../utils/commitment/common" } -compare_age_lib = { path = "../../../utils/compare/age" } -data_check_expiry = { path = "../../../utils/data-check/expiry" } +compare_age_lib = { path = "../../utils/compare/age" } +data_check_expiry = { path = "../../utils/data-check/expiry" } scoped_nullifier = { path = "../../utils/commitment/scoped-nullifier" } -utils = { path = "../../../utils/utils" } +utils = { path = "../../utils/utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/src/main.nr b/noir-examples/noir-passport/merkle_age_check/t_attest/src/main.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/merkle_age_check/t_attest/src/main.nr rename to noir-examples/noir-passport/merkle_age_check/t_attest/src/main.nr diff --git a/noir-examples/noir-passport/fragmented/utils/commitment/common/Nargo.toml b/noir-examples/noir-passport/utils/commitment/common/Nargo.toml similarity index 76% rename from noir-examples/noir-passport/fragmented/utils/commitment/common/Nargo.toml rename to noir-examples/noir-passport/utils/commitment/common/Nargo.toml index 5c7f3591f..fa7c95a83 100644 --- a/noir-examples/noir-passport/fragmented/utils/commitment/common/Nargo.toml +++ b/noir-examples/noir-passport/utils/commitment/common/Nargo.toml @@ -5,5 +5,5 @@ authors = ["Theo Madzou"] compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../../../../utils/utils" } -poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } \ No newline at end of file +utils = { path = "../../utils" } +poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/fragmented/utils/commitment/common/src/lib.nr b/noir-examples/noir-passport/utils/commitment/common/src/lib.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/utils/commitment/common/src/lib.nr rename to noir-examples/noir-passport/utils/commitment/common/src/lib.nr diff --git a/noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/Nargo.toml b/noir-examples/noir-passport/utils/commitment/dsc-to-id/Nargo.toml similarity index 79% rename from noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/Nargo.toml rename to noir-examples/noir-passport/utils/commitment/dsc-to-id/Nargo.toml index 158fe3cbd..af6149d76 100644 --- a/noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/Nargo.toml +++ b/noir-examples/noir-passport/utils/commitment/dsc-to-id/Nargo.toml @@ -5,6 +5,5 @@ authors = ["Theo Madzou", "Michael Elliot"] compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../../../../utils/utils" } +utils = { path = "../../utils" } common = { path = "../common" } - diff --git a/noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/src/lib.nr b/noir-examples/noir-passport/utils/commitment/dsc-to-id/src/lib.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/utils/commitment/dsc-to-id/src/lib.nr rename to noir-examples/noir-passport/utils/commitment/dsc-to-id/src/lib.nr diff --git a/noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/Nargo.toml b/noir-examples/noir-passport/utils/commitment/scoped-nullifier/Nargo.toml similarity index 82% rename from noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/Nargo.toml rename to noir-examples/noir-passport/utils/commitment/scoped-nullifier/Nargo.toml index 1e7a99feb..11e7eddc9 100644 --- a/noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/Nargo.toml +++ b/noir-examples/noir-passport/utils/commitment/scoped-nullifier/Nargo.toml @@ -5,5 +5,5 @@ authors = ["Theo Madzou", "Michael Elliot"] compiler_version = ">=1.0.0" [dependencies] -utils = { path = "../../../../utils/utils" } +utils = { path = "../../utils" } poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" } diff --git a/noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/src/lib.nr b/noir-examples/noir-passport/utils/commitment/scoped-nullifier/src/lib.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/utils/commitment/scoped-nullifier/src/lib.nr rename to noir-examples/noir-passport/utils/commitment/scoped-nullifier/src/lib.nr diff --git a/noir-examples/noir-passport/fragmented/utils/data-check/integrity/Nargo.toml b/noir-examples/noir-passport/utils/data-check/integrity/Nargo.toml similarity index 81% rename from noir-examples/noir-passport/fragmented/utils/data-check/integrity/Nargo.toml rename to noir-examples/noir-passport/utils/data-check/integrity/Nargo.toml index a7ed10cbc..885fd8b90 100644 --- a/noir-examples/noir-passport/fragmented/utils/data-check/integrity/Nargo.toml +++ b/noir-examples/noir-passport/utils/data-check/integrity/Nargo.toml @@ -5,5 +5,5 @@ authors = ["Theo Madzou"] compiler_version = ">=0.22.0" [dependencies] -utils = { path = "../../../../utils/utils" } +utils = { path = "../../utils" } sha256 = { tag = "v0.2.1", git = "https://github.com/noir-lang/sha256" } diff --git a/noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr b/noir-examples/noir-passport/utils/data-check/integrity/src/lib.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/utils/data-check/integrity/src/lib.nr rename to noir-examples/noir-passport/utils/data-check/integrity/src/lib.nr diff --git a/noir-examples/noir-passport/fragmented/utils/sig-check/rsa/Nargo.toml b/noir-examples/noir-passport/utils/sig-check/fragmented-rsa/Nargo.toml similarity index 84% rename from noir-examples/noir-passport/fragmented/utils/sig-check/rsa/Nargo.toml rename to noir-examples/noir-passport/utils/sig-check/fragmented-rsa/Nargo.toml index abafd4773..3f79f5522 100644 --- a/noir-examples/noir-passport/fragmented/utils/sig-check/rsa/Nargo.toml +++ b/noir-examples/noir-passport/utils/sig-check/fragmented-rsa/Nargo.toml @@ -6,4 +6,4 @@ compiler_version = ">=1.0.0" [dependencies] rsa = { git = "https://github.com/zkpassport/noir_rsa", tag = "v0.9.2" } bignum = { git = "https://github.com/noir-lang/noir-bignum", tag = "v0.8.0" } -utils = { path = "../../../../utils/utils" } +utils = { path = "../../utils" } diff --git a/noir-examples/noir-passport/fragmented/utils/sig-check/rsa/src/lib.nr b/noir-examples/noir-passport/utils/sig-check/fragmented-rsa/src/lib.nr similarity index 100% rename from noir-examples/noir-passport/fragmented/utils/sig-check/rsa/src/lib.nr rename to noir-examples/noir-passport/utils/sig-check/fragmented-rsa/src/lib.nr From a26f16d73d3816adebe879081794b917bc50595a Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Wed, 11 Feb 2026 12:00:12 +0530 Subject: [PATCH 13/15] compiler test fix --- tooling/provekit-bench/tests/compiler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/provekit-bench/tests/compiler.rs b/tooling/provekit-bench/tests/compiler.rs index e15e46113..8643bcfba 100644 --- a/tooling/provekit-bench/tests/compiler.rs +++ b/tooling/provekit-bench/tests/compiler.rs @@ -82,7 +82,7 @@ pub fn compile_workspace(workspace_path: impl AsRef) -> Result #[test_case("../../noir-examples/noir-r1cs-test-programs/small-sha")] #[test_case("../../noir-examples/noir-r1cs-test-programs/bounded-vec")] #[test_case("../../noir-examples/noir-r1cs-test-programs/brillig-unconstrained")] -#[test_case("../../noir-examples/noir-passport-monolithic/monolithic/complete_age_check"; "complete_age_check")] +#[test_case("../../noir-examples/noir-passport-monolithic/complete_age_check"; "complete_age_check")] fn case(path: &str) { test_compiler(path); } From f65d8820ea34a4d0219ee21ecc07bbb0fe54f42b Mon Sep 17 00:00:00 2001 From: x-senpai-x Date: Wed, 11 Feb 2026 18:26:50 +0530 Subject: [PATCH 14/15] removed circuit_keys.yml --- .github/workflows/circuit_keys.yml | 79 ++++++------------------------ 1 file changed, 14 insertions(+), 65 deletions(-) diff --git a/.github/workflows/circuit_keys.yml b/.github/workflows/circuit_keys.yml index 4d5f291f9..dee1ffc10 100644 --- a/.github/workflows/circuit_keys.yml +++ b/.github/workflows/circuit_keys.yml @@ -5,9 +5,9 @@ on: env: BUCKET_NAME: "provekit" - CIRCUIT_DIR: "noir-examples/noir-passport/merkle_age_check" + CIRCUIT_NAME: "complete_age_check" + CIRCUIT_DIR: "noir-examples/noir-passport-monolithic/complete_age_check" KEYS_NAME: "agecheck" - CIRCUITS: "t_add_dsc_720 t_add_id_data_720 t_add_integrity_commit t_attest" permissions: @@ -45,55 +45,17 @@ jobs: with: toolchain: v1.0.0-beta.11 - - name: Compile Nargo circuits + - name: Compile and execute Nargo circuit working-directory: ${{ env.CIRCUIT_DIR }} run: | - for circuit in ${{ env.CIRCUITS }}; do - echo "Compiling $circuit" - nargo compile --force --print-acir --package "$circuit" - echo "Compiled $circuit" - done + nargo compile --skip-brillig-constraints-check --force - - name: Prepare circuits (generate proving artifacts) + - name: Generate Gnark inputs working-directory: ${{ env.CIRCUIT_DIR }} run: | - for circuit in ${{ env.CIRCUITS }}; do - echo "Preparing $circuit" - cargo run --release --bin provekit-cli prepare ./target/$circuit.json \ - --pkp ./benchmark-inputs/$circuit-prover.pkp \ - --pkv ./benchmark-inputs/$circuit-verifier.pkv - echo "Prepared $circuit" - done - - - name: Generate proofs for all circuits - working-directory: ${{ env.CIRCUIT_DIR }} - run: | - for circuit in ${{ env.CIRCUITS }}; do - echo "Proving $circuit" - cargo run --release --bin provekit-cli prove \ - ./benchmark-inputs/$circuit-prover.pkp \ - ./benchmark-inputs/tbs_720/$circuit.toml \ - -o ./benchmark-inputs/$circuit-proof.np - echo "Proved $circuit" - done - - - name: Verify proofs for all circuits - working-directory: ${{ env.CIRCUIT_DIR }} - run: | - for circuit in ${{ env.CIRCUITS }}; do - echo "Verifying $circuit" - cargo run --release --bin provekit-cli verify \ - ./benchmark-inputs/$circuit-verifier.pkv \ - ./benchmark-inputs/$circuit-proof.np - echo "Verified $circuit" - done - - - name: Generate Gnark inputs (t_attest only) - working-directory: ${{ env.CIRCUIT_DIR }} - run: | - cargo run --release --bin provekit-cli generate-gnark-inputs \ - ./benchmark-inputs/t_attest-prover.pkp \ - ./benchmark-inputs/t_attest-proof.np + cargo run --release --bin provekit-cli prepare ./target/${{ env.CIRCUIT_NAME }}.json -p ./noir-provekit-prover.pkp -v ./noir-provekit-verifier.pkv + cargo run --release --bin provekit-cli prove ./noir-provekit-prover.pkp ./Prover.toml -o ./noir-proof.np + cargo run --release --bin provekit-cli generate-gnark-inputs ./noir-provekit-prover.pkp ./noir-proof.np - name: Run Gnark verifier working-directory: recursive-verifier @@ -119,30 +81,17 @@ jobs: echo "Found PK file: $PK_FILE" echo "Found VK file: $VK_FILE" - ATTEST_PK_NAME="${{ env.KEYS_NAME }}_t_attest_$(basename "$PK_FILE")" - ATTEST_VK_NAME="${{ env.KEYS_NAME }}_t_attest_$(basename "$VK_FILE")" + AGE_CHECK_PK_NAME="${{ env.KEYS_NAME }}_$(basename "$PK_FILE")" + AGE_CHECK_VK_NAME="${{ env.KEYS_NAME }}_$(basename "$VK_FILE")" - echo "Uploading PK as: $ATTEST_PK_NAME" - echo "Uploading VK as: $ATTEST_VK_NAME" + echo "Uploading PK as: $AGE_CHECK_PK_NAME" + echo "Uploading VK as: $AGE_CHECK_VK_NAME" - gsutil cp "$PK_FILE" "gs://${{ env.BUCKET_NAME }}/$ATTEST_PK_NAME" - gsutil cp "$VK_FILE" "gs://${{ env.BUCKET_NAME }}/$ATTEST_VK_NAME" - - cd "../${{ env.CIRCUIT_DIR }}" - for circuit in ${{ env.CIRCUITS }}; do - if [ -f "./benchmark-inputs/${circuit}-prover.pkp" ]; then - echo "Uploading ${circuit} prover key" - gsutil cp "./benchmark-inputs/${circuit}-prover.pkp" "gs://${{ env.BUCKET_NAME }}/${{ env.KEYS_NAME }}_${circuit}-prover.pkp" - fi - if [ -f "./benchmark-inputs/${circuit}-verifier.pkv" ]; then - echo "Uploading ${circuit} verifier key" - gsutil cp "./benchmark-inputs/${circuit}-verifier.pkv" "gs://${{ env.BUCKET_NAME }}/${{ env.KEYS_NAME }}_${circuit}-verifier.pkv" - fi - done + gsutil cp "$PK_FILE" "gs://${{ env.BUCKET_NAME }}/$AGE_CHECK_PK_NAME" + gsutil cp "$VK_FILE" "gs://${{ env.BUCKET_NAME }}/$AGE_CHECK_VK_NAME" - name: Cleanup local files working-directory: recursive-verifier run: | echo "Cleaning up local keys..." rm -f ./keys/*.bin - From cb33e39317aed798533ce5c18c4b912c948ec231 Mon Sep 17 00:00:00 2001 From: ashpect Date: Sun, 15 Feb 2026 09:53:57 +0530 Subject: [PATCH 15/15] chore: add license back --- .../noir-passport-monolithic/utils/LICENSE | 202 ++++++++++++++++++ noir-examples/noir-passport/utils/LICENSE | 202 ++++++++++++++++++ 2 files changed, 404 insertions(+) create mode 100644 noir-examples/noir-passport-monolithic/utils/LICENSE create mode 100644 noir-examples/noir-passport/utils/LICENSE diff --git a/noir-examples/noir-passport-monolithic/utils/LICENSE b/noir-examples/noir-passport-monolithic/utils/LICENSE new file mode 100644 index 000000000..7a4a3ea24 --- /dev/null +++ b/noir-examples/noir-passport-monolithic/utils/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/noir-examples/noir-passport/utils/LICENSE b/noir-examples/noir-passport/utils/LICENSE new file mode 100644 index 000000000..7a4a3ea24 --- /dev/null +++ b/noir-examples/noir-passport/utils/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file