Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Dsc whitelisting #348

Open
wants to merge 240 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
240 commits
Select commit Hold shift + click to select a range
e8dbc7a
add rsa dsc instances
seshanthS Jan 21, 2025
10e2036
add dsc rsapss instances
seshanthS Jan 21, 2025
ee2a6a7
rename circuits && add test files
seshanthS Jan 21, 2025
e5ea14f
format
seshanthS Jan 21, 2025
75cebea
add ecdsa dsc instances
seshanthS Jan 21, 2025
05683da
Merge branch 'dev' into feat/dsc-ecdsa
seshanthS Jan 21, 2025
9985b56
Merge branch 'dev' into feat/dsc-rsa
seshanthS Jan 21, 2025
f1bdf24
Merge branch 'feat/dsc-rsa' into feat/dsc-rsapss
seshanthS Jan 21, 2025
9d4b3a6
comment unrelated tests
seshanthS Jan 21, 2025
4239143
update import
seshanthS Jan 22, 2025
c54b642
Merge branch 'feat/dsc-rsa' into feat/dsc-ecdsa
seshanthS Jan 22, 2025
0244614
Merge branch 'feat/dsc-rsa' into feat/dsc-rsapss
seshanthS Jan 22, 2025
3822288
fix bits
seshanthS Jan 22, 2025
b1113a6
update register.circom
remicolin Jan 24, 2025
806ffda
use packBytesAndPoseidon in register.circom
remicolin Jan 24, 2025
28cef86
add ecdsa with rsa
seshanthS Jan 24, 2025
1ef16ea
add oid check
seshanthS Jan 24, 2025
695af17
add eContentHash into computeCommitment ts funciton — refactor
remicolin Jan 24, 2025
8b8a17d
move to another branch
motemotech Jan 24, 2025
f2a0253
update instance params
seshanthS Jan 24, 2025
76154bc
add ecdsa mock certificate signed with rsa
seshanthS Jan 24, 2025
3fb7bb1
Merge pull request #314 from zk-passport/feat/dsc-rsa
remicolin Jan 24, 2025
bd79a8e
Merge branch 'feat/dsc-rsa' into feat/dsc-ecdsa
seshanthS Jan 24, 2025
1fee0bf
add ecdsa instances
seshanthS Jan 24, 2025
12137a2
fix dsc pubkey length check
seshanthS Jan 24, 2025
42e91d1
bring new commitment to register and disclose circuist
remicolin Jan 25, 2025
e813b75
add kscaled in glue - update csca tree logic
remicolin Jan 25, 2025
6b0bbd7
format and clean
remicolin Jan 25, 2025
a737cb6
rename for generateCircuitInputsVCandDisclose
remicolin Jan 25, 2025
616f09f
rename for getPassportSignatureInfos
remicolin Jan 25, 2025
8a721c4
format common
remicolin Jan 25, 2025
8a2c132
remove comments
remicolin Jan 25, 2025
25078b7
update vc_and_disclose
remicolin Jan 25, 2025
586c72d
refactor common
remicolin Jan 25, 2025
00dae30
refactor passportVerifier
remicolin Jan 25, 2025
2649cd0
remove ShaBytesStatic - add constraints on majority input
remicolin Jan 25, 2025
e7efa79
add generateNullifier and fix pad function
remicolin Jan 25, 2025
146f8bc
add nullifier assertion in register.test.ts
remicolin Jan 25, 2025
ad4bed0
check nullifier in test_cases
remicolin Jan 25, 2025
6dd498c
add glue tests
seshanthS Jan 25, 2025
00c30db
add generateGlue
remicolin Jan 25, 2025
fe62980
add NatSpec
remicolin Jan 25, 2025
6b36667
Merge branch 'feat/passport-circuits' of https://github.com/zk-passpo…
remicolin Jan 25, 2025
c77c59e
bring back SplitBytesToWords
remicolin Jan 25, 2025
7a400b4
fix imports in glue.test.ts
remicolin Jan 25, 2025
f361b91
cleanups
0xturboblitz Jan 26, 2025
2c58e40
check offsets refer to valid ranges
0xturboblitz Jan 26, 2025
6a5c42a
refactor dsc.circom
seshanthS Jan 26, 2025
8db5891
clean circuits and add natspec
remicolin Jan 26, 2025
d72ea65
check forbidden country list packed in tests
remicolin Jan 26, 2025
263ad3c
added tests except vc and disclose
motemotech Jan 26, 2025
fab61b4
refactor register.circom
seshanthS Jan 26, 2025
f1f2a06
Merge branch 'feat/passport-circuits' of github.com:openpassport-org/…
seshanthS Jan 26, 2025
2f7e1b8
integrate circuits update
motemotech Jan 26, 2025
4266738
Merge branch 'feat/passport-circuits' into test/upgradeable-contracts
motemotech Jan 26, 2025
b3289dd
updates
seshanthS Jan 26, 2025
ea4ac2b
updates
motemotech Jan 26, 2025
be1cad4
update glue test
seshanthS Jan 26, 2025
9f30d6b
fix dsc_pubkey_length_bytes of ecdsa in register
seshanthS Jan 26, 2025
99cdb57
add fuzz testing in glue.test.ts
remicolin Jan 26, 2025
beae9b2
reduce fuzz tests by default
remicolin Jan 26, 2025
3ab96e7
Merge branch 'feat/passport-circuits' into feat/dsc-ecdsa
seshanthS Jan 27, 2025
44610c7
Merge branch 'feat/passport-circuits' into feat/dsc-rsapss
seshanthS Jan 27, 2025
cbb9219
Merge branch 'feat/passport-circuits' into test/upgradeable-contracts
motemotech Jan 27, 2025
6ede58e
refactor generateCircuitInputsDSC()
seshanthS Jan 27, 2025
d97e444
add scripts to generate certificate chain
remicolin Jan 27, 2025
f654f6d
fix imports in rsaPkcs1v1_5.test.ts
remicolin Jan 27, 2025
073c672
fix imports
remicolin Jan 27, 2025
56daa6b
add README in mock_certificates
remicolin Jan 27, 2025
c19469d
remove logs
remicolin Jan 27, 2025
8594b5c
Merge branch 'feat/passport-circuits' into feat/dsc-rsapss
seshanthS Jan 27, 2025
f3988b2
rename dsc instances and use passportData to retrieve circuit name
remicolin Jan 27, 2025
4732ea9
remove signatureAlgorithm from glue
0xturboblitz Jan 27, 2025
1e42e60
cleanup register.test.ts
0xturboblitz Jan 27, 2025
5ff853b
almost done for test code except libraries
motemotech Jan 27, 2025
df9e0f0
update dsc.test.ts
seshanthS Jan 27, 2025
98342ec
increase coverage
motemotech Jan 27, 2025
70f3e12
added example airdrop
motemotech Jan 27, 2025
77dbb5c
Merge branch 'feat/passport-circuits' of https://github.com/zk-passpo…
remicolin Jan 27, 2025
5b9e040
update certificates - improve scripts
remicolin Jan 27, 2025
63a2b3b
rename instances
remicolin Jan 27, 2025
5396f68
Merge branch 'feat/dsc-rsapss' of https://github.com/zk-passport/open…
remicolin Jan 27, 2025
368c40e
Merge pull request #315 from zk-passport/feat/dsc-rsapss
remicolin Jan 27, 2025
39865ec
Merge branch 'feat/passport-circuits' of https://github.com/zk-passpo…
remicolin Jan 28, 2025
235abc6
update certificates
remicolin Jan 28, 2025
76fb0b6
rename instances - improve genCircuitsInputsDsc
remicolin Jan 28, 2025
b9abe70
Merge pull request #323 from zk-passport/feat/dsc-ecdsa
remicolin Jan 28, 2025
0e1acf0
fix dsc inputs generation
remicolin Jan 28, 2025
3acd769
Started working on DSC circuit with new architure
0xturboblitz Jan 28, 2025
1f7558f
saving possible getLeafCSCA alternative
0xturboblitz Jan 28, 2025
3f1e6f4
Merge branch 'feat/passport-circuits' into dsc-whitelisting
0xturboblitz Jan 28, 2025
06eb082
remove GetKLengthBytes
0xturboblitz Jan 28, 2025
fce16ba
remove unused code
seshanthS Jan 28, 2025
0396bd9
parse x,y ecdsa
seshanthS Jan 28, 2025
35d1078
add comments
seshanthS Jan 28, 2025
f8d865c
Merge branch 'feat/passport-circuits' of https://github.com/zk-passpo…
remicolin Jan 28, 2025
0d80211
add new dsc/csca merkle tree
remicolin Jan 28, 2025
0313a1b
update generateInputs.ts
remicolin Jan 28, 2025
8a566e1
Merge pull request #334 from zk-passport/dsc-whitelisting-tree
remicolin Jan 28, 2025
9351fcc
uncomment tree inclusion
remicolin Jan 28, 2025
7f3b51d
pubkey extraction and equality check working for all rsa key sizes an…
0xturboblitz Jan 28, 2025
ee540df
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
0xturboblitz Jan 28, 2025
177a662
uncomment merkle root inclusion proof in dsc circuit
0xturboblitz Jan 28, 2025
45d32d1
bump max_csca_bytes to 1800
0xturboblitz Jan 28, 2025
b91d7a1
add merkle inclusion proof in generateInputsRegister
remicolin Jan 28, 2025
6638020
add imports to register.test.ts
remicolin Jan 28, 2025
5930a3f
comment rsapss register test_cases
remicolin Jan 28, 2025
9f3e39a
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
remicolin Jan 28, 2025
a584d67
Merge pull request #335 from zk-passport/dsc-whitelisting-tree
remicolin Jan 28, 2025
ae9a1c9
parse dsc masterlist
remicolin Jan 28, 2025
aaf7387
Merge pull request #336 from zk-passport/dsc-whitelisting-tree
remicolin Jan 28, 2025
d9a3365
set max_dsc_bytes and max_csca_bytes to 1792
0xturboblitz Jan 29, 2025
f465e2e
note which dsc test cases have no corresponding certificates
0xturboblitz Jan 29, 2025
a4b695e
cleanups
0xturboblitz Jan 29, 2025
2874fd4
register circuit
0xturboblitz Jan 29, 2025
a428694
fix hash order in dsc circuit
0xturboblitz Jan 29, 2025
bd9c728
adapt disclose circuit to new identity commitment
0xturboblitz Jan 29, 2025
a96be50
note some register circuits that don't exist
0xturboblitz Jan 29, 2025
e58553b
documentation
0xturboblitz Jan 29, 2025
ae69444
Merge branch 'feat/passport-circuits' into test/upgradeable-contracts
motemotech Jan 29, 2025
f2c044d
Merge branch 'dsc-whitelisting' into test/upgradeable-contracts
motemotech Jan 29, 2025
8e52073
improve tree generation
remicolin Jan 29, 2025
178118c
add icao download section to .gitignore
remicolin Jan 29, 2025
7be858d
Merge pull request #337 from zk-passport/dsc-whitelisting-tree
remicolin Jan 29, 2025
388af11
formatting dsc impls and uncomment merkle root being public
0xturboblitz Jan 29, 2025
1469756
making merkle_root public in register circuits
0xturboblitz Jan 29, 2025
51fa8ab
tmp done for contract
motemotech Jan 29, 2025
a0fa5e2
Merge branch 'dsc-whitelisting' into test/upgradeable-contracts
motemotech Jan 29, 2025
0fec7dc
compiled
motemotech Jan 29, 2025
79cdb3f
added view functions for dsc key commitment tree
motemotech Jan 29, 2025
53f9cde
done for impl and finished registry unit test
motemotech Jan 30, 2025
b9ca83b
add dev functions for dsc key commitment
motemotech Jan 30, 2025
e51ee8f
checking dsc key imt
motemotech Jan 30, 2025
260ffec
add missing certifictes
remicolin Jan 30, 2025
c716c19
update instances
remicolin Jan 30, 2025
cea52fd
add missing signatureAlgorithms in circuits
remicolin Jan 30, 2025
76972a6
add new sigAlgs
remicolin Jan 30, 2025
0bd5cc9
update certificate artefacts
remicolin Jan 30, 2025
a3f13f7
done for vc and disclose and readable parsers
motemotech Jan 30, 2025
1e328bf
fix findStartPubKeyIndex()
seshanthS Jan 30, 2025
cc1c397
done except airdrop and commitment register
motemotech Jan 30, 2025
03e88dd
uncomment tests in dsc.test.ts
remicolin Jan 30, 2025
dbf0c63
clean and fix imports
remicolin Jan 30, 2025
e8bb71d
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
remicolin Jan 30, 2025
0bf951e
finished test code except commitment registration
motemotech Jan 30, 2025
5a58fcd
Merge branch 'dsc-whitelisting' into test/upgradeable-contracts
motemotech Jan 30, 2025
2c4b58b
delete unused changes
motemotech Jan 30, 2025
8832b81
add signature algorithms
remicolin Jan 31, 2025
774fcfd
gen new certificates
remicolin Jan 31, 2025
2e3c143
fix typos
remicolin Jan 31, 2025
c8b0010
update instances
remicolin Jan 31, 2025
826424b
update circuits parameters
remicolin Jan 31, 2025
dad33de
restore testSuite
remicolin Jan 31, 2025
a853306
update register test_cases
remicolin Jan 31, 2025
037fb1d
improve curves support — fix rsapss mask hash function generation - f…
remicolin Jan 31, 2025
f85f8f7
feat: add sha512 secp521r1 support
Nesopie Jan 31, 2025
93caa7e
chore: remove secp521r1 from sig algs
Nesopie Jan 31, 2025
99c1688
Merge pull request #338 from zk-passport/feat/secp521r1
remicolin Jan 31, 2025
62ab33c
switch dsc tree from imt to lean-imt
remicolin Jan 31, 2025
a71a4ec
merge test/upgradeable-contracts into dsc-whitelisting
remicolin Jan 31, 2025
92d8f76
clean logs - comments
remicolin Jan 31, 2025
63aed43
implement csca root tree retrieving function
remicolin Jan 31, 2025
c4f3f0c
update contracts readme
motemotech Jan 31, 2025
4ebcc5a
Merge pull request #339 from zk-passport/dsc-whitelisting-contract-re…
remicolin Jan 31, 2025
c97ba17
increase test performance and add registration test
motemotech Jan 31, 2025
d88d8e1
Merge pull request #340 from zk-passport/test/contracts-commitment-re…
remicolin Jan 31, 2025
803c9b3
update register instances
remicolin Jan 31, 2025
bfb6355
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
remicolin Jan 31, 2025
594842b
add shortcut to build dsc/csca trees
remicolin Jan 31, 2025
1cb6861
add ascii tree
remicolin Jan 31, 2025
344100c
update register flow test
motemotech Feb 1, 2025
929f3e0
delete unused import from disclose test
motemotech Feb 1, 2025
2a7cb0c
update disclose test
motemotech Feb 1, 2025
e6a3b68
increased coverage for hub
motemotech Feb 1, 2025
dc5908d
increased formatter coverage
motemotech Feb 1, 2025
8b79a83
update register
motemotech Feb 1, 2025
aef0276
increase airdrop test coverage
motemotech Feb 1, 2025
d9fe887
chmod 777 scripts
remicolin Feb 1, 2025
9e9917d
update circuit handler coverage
motemotech Feb 1, 2025
0194a3d
Merge branch 'test/increase-coverage' of https://github.com/zk-passpo…
motemotech Feb 1, 2025
80d24ee
increase registry coverage
motemotech Feb 1, 2025
bd81877
increased hub coverage
motemotech Feb 1, 2025
a6b900f
100 % except hub
motemotech Feb 1, 2025
1dea0ce
clean code
motemotech Feb 1, 2025
1c0ba90
Merge pull request #342 from zk-passport/test/increase-coverage
remicolin Feb 1, 2025
9259587
dsc circuit range check and tests
0xturboblitz Feb 1, 2025
ae79bd7
register circuit test cases
0xturboblitz Feb 1, 2025
bc9a444
add sha224 - secp224r1 to genMockPassportData
remicolin Feb 1, 2025
4068b7c
update sigAlgs
remicolin Feb 2, 2025
a148e86
csca_pubKey_actual_size and dsc_pubKey_actual_size range checks
0xturboblitz Feb 2, 2025
b073d54
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
0xturboblitz Feb 2, 2025
870eb6b
regenerate pss certificates
remicolin Feb 2, 2025
cd4f859
add pss certificate
remicolin Feb 2, 2025
ac54b69
update circuit name
remicolin Feb 2, 2025
cf43407
add sha224 secp224r1 in signature Verifier
remicolin Feb 2, 2025
44b650c
merge 'dsc-whitelisting' into dsc-whitelisting
remicolin Feb 2, 2025
4611500
update build script to detect os
motemotech Feb 2, 2025
bf190a0
remove commentout
motemotech Feb 2, 2025
1621605
include actual csca size in csca tree and constrain it in dsc.circom
0xturboblitz Feb 2, 2025
191d278
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
0xturboblitz Feb 2, 2025
0636ec7
add dsc actual size in dsc leaf, range check pubkey positions accurately
0xturboblitz Feb 2, 2025
2bea03c
fix inaccurate naming in ShaBytesDynamic
0xturboblitz Feb 2, 2025
bbd50ec
check raw_dsc is padded with 0s after the sha padding
0xturboblitz Feb 2, 2025
a811301
update documentation
0xturboblitz Feb 2, 2025
188e03c
add root timestamp verification
motemotech Feb 2, 2025
6f0819f
Merge branch 'update/build-script-to-detect-os' into dsc-whitelisting
motemotech Feb 2, 2025
1a52fe4
Merge pull request #343 from zk-passport/update/build-script-to-detec…
remicolin Feb 2, 2025
779a647
Merge pull request #344 from zk-passport/update/add-timestamp-verific…
remicolin Feb 2, 2025
a49553f
update commitment tree size
remicolin Feb 2, 2025
8eec663
add end to end test
motemotech Feb 2, 2025
0100acf
update build script
motemotech Feb 2, 2025
c438f86
add formatter and circuit attribute handler ts script
motemotech Feb 2, 2025
2f375a2
Merge branch 'dsc-whitelisting' of https://github.com/zk-passport/ope…
motemotech Feb 2, 2025
3228b33
Merge branch 'dsc-whitelisting' into fix/small-contract-changes
motemotech Feb 2, 2025
8649158
add valuables to airdrop root constructor
motemotech Feb 2, 2025
2ec112e
yarn format
remicolin Feb 2, 2025
77dbaa0
clean unused templates
remicolin Feb 3, 2025
69a7ddb
verify passport validity
remicolin Feb 3, 2025
a4fde82
clean file
remicolin Feb 3, 2025
6fca057
update airdrop contract
motemotech Feb 3, 2025
af2bf8e
add tests shortcut
remicolin Feb 3, 2025
72b5956
Merge pull request #346 from zk-passport/fix/small-contract-changes
motemotech Feb 3, 2025
f04d116
cleanup vc_and_disclose.test.ts
0xturboblitz Feb 3, 2025
ef25a10
fix signatureAlgorithm indexes not managed by SignatureVerifier
0xturboblitz Feb 3, 2025
4625deb
- fix RSAPSS salt length check to support sha512
0xturboblitz Feb 3, 2025
0d2ad71
fix MAX_ECONTENT_PADDED_LEN for register circuit using sha1 for DG1
0xturboblitz Feb 3, 2025
7272b2b
Merge pull request #349 from zk-passport/fix/circuit-fixes
0xturboblitz Feb 3, 2025
f54d1ad
added nat spec half of the contracts
motemotech Feb 3, 2025
fc1115a
Merge branch 'dsc-whitelisting' into fix/passport-airdrop-root-constr…
motemotech Feb 3, 2025
1948850
delete console.log
motemotech Feb 3, 2025
fb17923
change file name
motemotech Feb 3, 2025
46f7e2b
Merge pull request #350 from zk-passport/fix/passport-airdrop-root-co…
motemotech Feb 3, 2025
780fd60
Merge branch 'dsc-whitelisting' into add/contracts-natspec
motemotech Feb 3, 2025
9aa8bce
add nat spec to airdrop related codes
motemotech Feb 3, 2025
b5a0d76
add nat spec to constants
motemotech Feb 3, 2025
d2891c5
add nat spec to libraries
motemotech Feb 3, 2025
e40e5ab
add nat spec to interfaces
motemotech Feb 3, 2025
b3a616b
Merge pull request #351 from zk-passport/add/contracts-natspec
motemotech Feb 3, 2025
5bca8c3
remove console
motemotech Feb 3, 2025
b85ba0d
Merge pull request #352 from zk-passport/fix/remove-console.log
motemotech Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions app/src/screens/ProveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Progress, Spinner, Text, XStack, YStack } from 'tamagui';

import {
DEVELOPMENT_MODE,
max_cert_bytes,
max_dsc_bytes,
} from '../../../common/src/constants/constants';
import {
DisclosureOptions,
Expand Down Expand Up @@ -193,7 +193,7 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
const cscaInputs = generateCircuitInputsDSC(
dscSecret as string,
passportData.dsc,
max_cert_bytes,
max_dsc_bytes,
selectedApp.devMode,
);
[dscProof, proof] = await Promise.all([
Expand Down
4 changes: 2 additions & 2 deletions app/src/utils/generateInputsInApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
OpenPassportApp,
} from '../../../common/src/utils/appType';
import {
generateCircuitInputsDisclose,
generateCircuitInputsVCandDisclose,
generateCircuitInputsProve,
} from '../../../common/src/utils/generateInputs';
import { fetchTreeFromUrl } from '../../../common/src/utils/pubkeyTree';
Expand Down Expand Up @@ -100,7 +100,7 @@ export const generateCircuitInputsInApp = async (
disclosureOptionsDisclose.excludedCountries.value.map(country =>
getCountryCode(country),
);
return generateCircuitInputsDisclose(
return generateCircuitInputsVCandDisclose(
secret,
PASSPORT_ATTESTATION_ID,
passportData,
Expand Down
113 changes: 82 additions & 31 deletions circuits/circuits/disclose/vc_and_disclose.circom
Original file line number Diff line number Diff line change
@@ -1,64 +1,115 @@
pragma circom 2.1.9;

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

template VC_AND_DISCLOSE(nLevels,FORBIDDEN_COUNTRIES_LIST_LENGTH) {

/// @title VC_AND_DISCLOSE
/// @notice Verify user's commitment is part of the merkle tree and optionally disclose data from DG1
/// @param nLevels Maximum number of levels in the merkle tree
/// @param MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH Maximum number of countries present in the forbidden countries list
/// @input secret Secret of the user — used to reconstruct commitment and generate nullifier
/// @input attestation_id Attestation ID of the credential used to generate the commitment
/// @input dg1 Data group 1 of the passport
/// @input eContent_shaBytes_packed_hash Hash of the eContent packed
/// @input dsc_tree_leaf Leaf of the DSC tree, to keep a record of the full CSCA and DSC that were used
/// @input merkle_root Root of the commitment merkle tree
/// @input leaf_depth Actual size of the merkle tree
/// @input path Path of the commitment in the merkle tree
/// @input siblings Siblings of the commitment in the merkle tree
/// @input selector_dg1 bitmap used which bytes from the dg1 are revealed
/// @input majority Majority user wants to prove he is older than: YY — ASCII
/// @input current_date Current date: YYMMDD — number
/// @input selector_older_than bitmap used to reveal the majority
/// @input forbidden_countries_list Forbidden countries list user wants to prove he is not from
/// @input smt_leaf_key value of the leaf of the smt corresponding to his path
/// @input smt_root root of the smt
/// @input smt_siblings siblings of the smt
/// @input selector_ofac bitmap used to reveal the OFAC verification result
/// @input scope Scope of the application users generates the proof for
/// @input user_identifier User identifier — address or UUID
/// @output revealedData_packed Packed revealed data
/// @output forbidden_countries_list_packed Packed forbidden countries list
/// @output nullifier Scope nullifier - not deterministic on the passport data
template VC_AND_DISCLOSE(nLevels, MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH) {
signal input secret;
signal input attestation_id;
signal input pubkey_leaf;
signal input dg1[93];
signal input dg2_hash[64];
signal input eContent_shaBytes_packed_hash;
signal input dsc_tree_leaf;

signal input merkle_root;
signal input merkletree_size;
signal input leaf_depth;
signal input path[nLevels];
signal input siblings[nLevels];

signal input selector_dg1[88]; // 88 for MRZ
signal input selector_dg1[88];

signal input majority[2];
signal input current_date[6];
signal input selector_older_than;
signal input scope;
signal input current_date[6]; // YYMMDD - num
signal input majority[2]; // YY - ASCII
signal input user_identifier;

// ofac check
signal input forbidden_countries_list[MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH * 3];

signal input smt_leaf_key;
signal input smt_root;
signal input smt_siblings[256];
signal input selector_ofac;
// forbidden countries list
signal input forbidden_countries_list[FORBIDDEN_COUNTRIES_LIST_LENGTH * 3];

signal input scope;
signal input user_identifier;

// verify commitment is part of the merkle tree
VERIFY_COMMITMENT(nLevels)(secret, attestation_id, pubkey_leaf, dg1, dg2_hash, merkle_root, merkletree_size, path, siblings);
VERIFY_COMMITMENT(nLevels)(
secret,
attestation_id,
dg1,
eContent_shaBytes_packed_hash,
dsc_tree_leaf,
merkle_root,
leaf_depth,
path,
siblings
);

// verify passport validity and disclose optional data
component disclose = DISCLOSE();
// verify passport validity
signal validity_ASCII[6];
for (var i = 0; i < 6; i++) {
validity_ASCII[i] <== dg1[70 +i];
}

IsValid()(current_date,validity_ASCII);

// disclose optional data
component disclose = DISCLOSE(10);
disclose.dg1 <== dg1;
disclose.selector_dg1 <== selector_dg1;
disclose.selector_older_than <== selector_older_than;
disclose.current_date <== current_date;
disclose.majority <== majority;

// generate scope nullifier
component poseidon_nullifier = Poseidon(2);
poseidon_nullifier.inputs[0] <== secret;
poseidon_nullifier.inputs[1] <== scope;
signal output nullifier <== poseidon_nullifier.out;
disclose.smt_leaf_key <== smt_leaf_key;
disclose.smt_root <== smt_root;
disclose.smt_siblings <== smt_siblings;
disclose.selector_ofac <== selector_ofac;
disclose.forbidden_countries_list <== forbidden_countries_list;

signal output revealedData_packed[3] <== disclose.revealedData_packed;
signal output older_than[2] <== disclose.older_than;

// COUNTRY IS IN LIST
signal output forbidden_countries_list_packed_disclosed[2] <== ProveCountryIsNotInList(FORBIDDEN_COUNTRIES_LIST_LENGTH)(dg1, forbidden_countries_list);
var chunkLength = computeIntChunkLength(MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH * 3);
signal output forbidden_countries_list_packed[chunkLength] <== disclose.forbidden_countries_list_packed;

// OFAC
signal ofacCheckResult <== OFAC_NAME()(dg1,smt_leaf_key,smt_root,smt_siblings);
signal ofacIntermediaryOutput <== ofacCheckResult * selector_ofac;
signal output ofac_result <== ofacIntermediaryOutput;
signal output nullifier <== Poseidon(2)([secret, scope]);
}

component main { public [ merkle_root, smt_root, scope, user_identifier, current_date, attestation_id] } = VC_AND_DISCLOSE(16,20);
component main {
public [
merkle_root,
smt_root,
scope,
user_identifier,
current_date,
attestation_id
]
} = VC_AND_DISCLOSE(33, 10);
139 changes: 107 additions & 32 deletions circuits/circuits/dsc/dsc.circom
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,132 @@ include "@zk-kit/binary-merkle-root.circom/src/binary-merkle-root.circom";
include "../utils/passport/customHashers.circom";
include "../utils/passport/signatureAlgorithm.circom";
include "../utils/passport/signatureVerifier.circom";
include "@openpassport/zk-email-circuits/utils/bytes.circom";
include "../utils/passport/checkPubkeysEqual.circom";
include "../utils/passport/constants.circom";
include "../utils/crypto/bitify/bytes.circom";
include "../utils/passport/BytesToNum.circom";

/// @title DSC
/// @notice Circuit for verifying DSC certificate signature using CSCA certificate
/// @param signatureAlgorithm Algorithm used for DSC signature verification - contains the information about the final hash algorithm
/// @param n_csca Number of bits per chunk the CSCA key is split into
/// @param k_csca Number of chunks the CSCA key is split into
/// @input raw_csca Raw CSCA certificate data
/// @input raw_csca_actual_length Actual length of CSCA certificate
/// @input csca_pubKey_offset Offset of CSCA public key in certificate
/// @input csca_pubKey_actual_size Actual size of CSCA public key in bytes
/// @input raw_dsc Raw DSC certificate data
/// @input raw_dsc_padded_length Actual length of DSC certificate
/// @input csca_pubKey CSCA public key for signature verification
/// @input signature DSC signature
/// @input merkle_root Root of CSCA Merkle tree
/// @input path Path indices for CSCA Merkle proof
/// @input siblings Sibling hashes for CSCA Merkle proof
/// @output dsc_tree_leaf Leaf to be added to the DSC Merkle tree
template DSC(
signatureAlgorithm,
n_csca,
k_csca
) {
var MAX_CSCA_LENGTH = getMaxCSCALength();
var MAX_DSC_LENGTH = getMaxDSCLength();
var nLevels = getMaxCSCALevels();

template DSC(signatureAlgorithm, n_dsc, k_dsc, n_csca, k_csca, max_cert_bytes, dscPubkeyBytesLength, nLevels) {

// variables verification
assert(max_cert_bytes % 64 == 0);
assert(n_csca * k_csca > max_cert_bytes);
assert(MAX_CSCA_LENGTH % 64 == 0);
assert(MAX_DSC_LENGTH % 64 == 0);
// assert(n_csca * k_csca > max_dsc_bytes); // not sure what this is for
assert(n_csca <= (255 \ 2));

var hashLength = getHashLength(signatureAlgorithm);
var minKeyLength = getMinKeyLength(signatureAlgorithm);
var kLengthFactor = getKLengthFactor(signatureAlgorithm);
var kScaled = k_csca * kLengthFactor;
var hashLength = getHashLength(signatureAlgorithm);

var MAX_CSCA_PUBKEY_LENGTH = n_csca * kScaled / 8;

signal input raw_csca[MAX_CSCA_LENGTH];
signal input raw_csca_actual_length;
signal input csca_pubKey_offset;
signal input csca_pubKey_actual_size;

signal input raw_dsc[MAX_DSC_LENGTH];
signal input raw_dsc_padded_length;

signal input raw_dsc_cert[max_cert_bytes];
signal input raw_dsc_cert_padded_bytes;
signal input csca_pubKey[kScaled];
signal input signature[kScaled];
signal input dsc_pubKey[k_dsc];
signal input dsc_pubKey_offset;
signal input secret;

signal input merkle_root;
signal input path[nLevels];
signal input siblings[nLevels];

// first, compute raw_dsc_actual_length
// by getting the values of the last 4 bytes of the padded length
// cf sha padding
signal last_four_bytes_of_padded_length[4] <== SelectSubArray(MAX_DSC_LENGTH, 4)(raw_dsc, raw_dsc_padded_length - 4, 4);
signal computed_length_bits <== BytesToNum()(last_four_bytes_of_padded_length);
signal raw_dsc_actual_length <== computed_length_bits / 8;

// leaf
signal leaf <== LeafHasher(kScaled)(csca_pubKey, signatureAlgorithm);
// sanity check: raw_dsc[raw_dsc_actual_length] should be 128
signal raw_dsc_at_actual_length <== ItemAtIndex(MAX_DSC_LENGTH)(raw_dsc, raw_dsc_actual_length);
signal isByte128 <== IsEqual()([raw_dsc_at_actual_length, 128]);
isByte128 === 1;

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

// verify certificate signature
signal hashedCertificate[hashLength] <== ShaBytesDynamic(hashLength, max_cert_bytes)(raw_dsc_cert, raw_dsc_cert_padded_bytes);
// check that raw_dsc is padded with 0s after the sha padding
// this should guarantee the dsc commitment is unique for each commitment
component byte_checks[MAX_DSC_LENGTH];
for (var i = 0; i < MAX_DSC_LENGTH; i++) {
byte_checks[i] = GreaterThan(12);
byte_checks[i].in[0] <== i;
byte_checks[i].in[1] <== raw_dsc_padded_length;

// If i >= raw_dsc_padded_length, the byte must be 0
raw_dsc[i] * byte_checks[i].out === 0;
}

SignatureVerifier(signatureAlgorithm, n_csca, k_csca)(hashedCertificate, csca_pubKey, signature);
// check csca_pubKey_actual_size is at least the minimum key length
signal csca_pubKey_actual_size_in_range <== GreaterEqThan(12)([
csca_pubKey_actual_size,
minKeyLength * kLengthFactor / 8
]);
csca_pubKey_actual_size_in_range === 1;

// verify DSC csca_pubKey
component shiftLeft = VarShiftLeft(max_cert_bytes, dscPubkeyBytesLength); // use select subarray for dscPubKey variable length
shiftLeft.in <== raw_dsc_cert;
shiftLeft.shift <== dsc_pubKey_offset;
component spbt_1 = SplitBytesToWords(dscPubkeyBytesLength, n_dsc, k_dsc);
spbt_1.in <== shiftLeft.out;
for (var i = 0; i < k_dsc; i++) {
dsc_pubKey[i] === spbt_1.out[i];
}
// check offsets refer to valid ranges
signal csca_pubKey_offset_in_range <== LessEqThan(12)([
csca_pubKey_offset + csca_pubKey_actual_size,
raw_csca_actual_length
]);
csca_pubKey_offset_in_range === 1;

// compute leaf in the CSCA Merkle tree and verify inclusion
signal csca_hash <== PackBytesAndPoseidon(MAX_CSCA_LENGTH)(raw_csca);
signal csca_tree_leaf <== Poseidon(2)([csca_hash, raw_csca_actual_length]);
signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(csca_tree_leaf, nLevels, path, siblings);
merkle_root === computed_merkle_root;

// blinded dsc commitment
signal pubkeyHash <== CustomHasher(k_dsc)(dsc_pubKey);
signal output blinded_dsc_commitment <== Poseidon(2)([secret, pubkeyHash]);
}
// get CSCA public key from the certificate
signal extracted_csca_pubKey[MAX_CSCA_PUBKEY_LENGTH] <== SelectSubArray(MAX_CSCA_LENGTH, MAX_CSCA_PUBKEY_LENGTH)(
raw_csca,
csca_pubKey_offset,
csca_pubKey_actual_size
);

// check if the CSCA public key is the same as the one in the certificate
// If we end up adding the pubkey in the CSCA leaf, we'll be able to remove this check
CheckPubkeysEqual(n_csca, kScaled, kLengthFactor, MAX_CSCA_PUBKEY_LENGTH)(
csca_pubKey,
extracted_csca_pubKey,
csca_pubKey_actual_size
);

// verify DSC signature
// raw_dsc_padded_length is constrained because an incorrect one
// would yield hashes that have not been signed
signal hashedCertificate[hashLength] <== ShaBytesDynamic(hashLength, MAX_DSC_LENGTH)(raw_dsc, raw_dsc_padded_length);
SignatureVerifier(signatureAlgorithm, n_csca, k_csca)(hashedCertificate, csca_pubKey, signature);

// generate DSC leaf as poseidon(dsc_hash_with_actual_length, csca_tree_leaf)
signal dsc_hash <== PackBytesAndPoseidon(MAX_DSC_LENGTH)(raw_dsc);
signal dsc_hash_with_actual_length <== Poseidon(2)([dsc_hash, raw_dsc_actual_length]);
signal output dsc_tree_leaf <== Poseidon(2)([dsc_hash_with_actual_length, csca_tree_leaf]);
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../dsc.circom";

component main { public [ merkle_root] } = DSC(36, 64, 4);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../dsc.circom";

component main { public [ merkle_root ] } = DSC(11, 120, 35);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../dsc.circom";

component main { public [ merkle_root] } = DSC(21, 64, 4);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../dsc.circom";

component main { public [ merkle_root] } = DSC(37, 64, 6);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.9;

include "../dsc.circom";

component main { public [ merkle_root] } = DSC(8, 64, 4);
Loading
Loading