Skip to content

Commit 31b9da1

Browse files
authored
Merge pull request #42 from rarimo/fix/readme
Fixed readme and deps
2 parents 8767f37 + c95eaa4 commit 31b9da1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+479
-333
lines changed

.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ typechain-types
2626
generated-types
2727
artifacts
2828
cache
29-
tests/tests/inputs/*
29+
test/tests/inputs/*
3030
temp_asn1.der
31-
tests/tests/__pycache__
32-
!tests/tests/*.py
33-
!tests/tests/inputs/credValidExceedsPassportInput.json
34-
!tests/tests/inputs/passportExpiredInput.json
35-
!tests/tests/inputs/isNotAdultInput.json
36-
!tests/tests/inputs/validInput.json
31+
test/tests/__pycache__
32+
!test/tests/*.py
33+
!test/tests/inputs/credValidExceedsPassportInput.json
34+
!test/tests/inputs/passportExpiredInput.json
35+
!test/tests/inputs/isNotAdultInput.json
36+
!test/tests/inputs/validInput.json

.mocharc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": "hardhat/register",
3-
"timeout": 40000,
3+
"timeout": 100000,
44
"_": ["test/**/*.ts"]
5-
}
5+
}

README.md

Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
# passport-zk-circuits
1+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
22

3-
Circuits for a voting system based on the passport scanning
3+
# Passport ZK Circuits
44

5-
Install the `circomlib` package before running the circuits.
5+
**Circuits for a voting system based on biometric passports scanning.**
66

7-
```console
8-
npm install circomlib
9-
```
10-
11-
**scripts** directory contains scripts to simplify interaction with circuits.
12-
13-
- ***compile-circuit*** - compiles circom circuit (receive *R1CS*, *WASM* & *CPP* for witness generation); Usage: ```compile-circuit <circuit_name>```
14-
15-
- ***trusted-setup*** - *Powers-of-Tau* ceremony for trusted setup generation. Usage: ```trusted-setup <power>```
16-
17-
- ***export-keys*** - generates proving and verification keys. Do not forget to perform a trusted setup first. Usage: ```export-keys <circuit_name> <power>```
7+
## Usage
188

19-
- ***gen-witness*** - generates witness. Can be done without a trusted setup. Do not forget to compile circuit first. Usage: ```gen-witness <circuit_name> <inputs>```
9+
The repository leverages `hardhat-zkit` environment to carry out the management of circuits. There are several scripts available:
2010

21-
- ***prove*** - generates witness and proof. Do not forget to compile the circuit and export keys first. Usage: ```prove <circuit_name> <inputs>```
11+
- `npm run zkit-make`, to compile and set up the keys for the circuits.
12+
- `npm run zkit-compile`, to compile just compile the circuits (witness testing).
13+
- `npm run zkit-verifiers`, to generate Solidity (or Vyper) smart contract verifiers.
2214

23-
- ***verify*** - verifies the proof. Usage: ```verify <circuit_name>```
15+
> [!NOTE]
16+
> Install the necessary packages via `npm install` before proceeding with the circuits.
2417
2518
##
2619

2720
[![hardhat-zkit](https://github.com/user-attachments/assets/f5e9a69a-93cb-4044-88fc-b9f9cadd29a7)](https://github.com/dl-solarity/hardhat-zkit)
2821

2922
## Biometric Passport Authentication
3023

31-
Data in a passport is separated into data groups. Not all of them are required to be present in the passport. Document Security Object (SOD) has **encapculated content** field that contains hashes of all datagroups. During passive authentication verification party hashes data from the datagroups and compare it with hashes stored in the **encapculated content** with *ASN1* encoding. The hash of the **encapculated content** itself is stored in the **signed attributes** field, which is also *ASN1* encoded.
24+
Data in a passport is separated into data groups. Not all of them are required to be present in the passport. Document Security Object (SOD) has **encapsulated content** field that contains hashes of all datagroups. During passive authentication verification party hashes data from the datagroups and compare it with hashes stored in the **encapsulated content** with *ASN1* encoding. The hash of the **encapsulated content** itself is stored in the **signed attributes** field, which is also *ASN1* encoded.
3225
To verify **signed attributes**, verification party uses the passport signature, which is also stored in the **SOD**. To confirm that the passport is authenticated by a legitimate authority (ensuring the signer's public key is genuinely owned by a passport-issuing entity), the corresponding **PKI x509** certificate is stored in the **SOD**. Utilizing a Public Key Infrastructure (PKI) allows for the establishment of a verification path to a trusted anchor. This trusted anchor should be a publicly recognized list of master certificates. Specifically, a *Master List* comprises *Country Signing Certification Authority (CSCA)* certificates that have been issued and digitally signed by the respective issuing State, providing a robust framework for ensuring the authenticity and integrity of passport data.
3326

3427
## Circuits
@@ -43,74 +36,49 @@ The Merkle Tree is built upon participants registration. After proving that the
4336

4437
By using the knowledge of the commitment preimage and generating the corresponding proof, users can express their votes.
4538

46-
#### Circuit parameter
47-
48-
**depth** - depth of a Merkle Tree used to prove leaf inclusion.
49-
50-
#### Inputs
51-
52-
- ***root***: *public*; Poseidon Hash is used for tree hashing;
39+
#### Circuit parameters
5340

54-
- ***nullifierHash***: *public*; Poseidon Hash is used for the *nullifier* hashing;
41+
- **depth** - depth of a Merkle Tree used to prove leaf inclusion.
5542

56-
- ***vote***: *public*; not taking part in any computations; binds the vote to the proof
43+
#### Circuit public inputs
5744

58-
- ***nullifier***: *private*
45+
- [0] **root** - Poseidon Hash is used for tree hashing;
46+
- [1] **nullifierHash** - Poseidon Hash is used for the *nullifier* hashing;
47+
- [2] **vote** - not taking part in any computations; binds the vote to the proof
5948

60-
- ***secret***: *private*
49+
#### Circuit private inputs
6150

62-
- ***pathElements[levels]***: *private*; Merkle Branch
63-
64-
- ***pathIndices[levels]***: *private*; `0` - left, `1` - right
51+
- **nullifier**
52+
- **secret**
53+
- **pathElements[levels]** - Merkle Branch
54+
- **pathIndices[levels]** - `0` - left, `1` - right
6555

6656
### Passport Verification circuits
6757

6858
Passport Verification circuits are used to prove that user is eligible to vote. Currently following checks are made:
6959

7060
- Date of passport expiracy is less than the current date;
71-
7261
- Current date is after date of birth + **18** years; (for now **18** years is a constant);
73-
7462
- Passport issuer code is used as an output signal;
7563

76-
### Circuit public inputs
77-
78-
- **currentDateYear**
79-
80-
- **currentDateMonth**
81-
82-
- **currentDateDay**
64+
#### Circuit public inputs
8365

84-
- **credValidYear**
66+
- [0] **currentDateYear**
67+
- [1] **currentDateMonth**
68+
- [2] **currentDateDay**
69+
- [3] **credValidYear**
70+
- [4] **credValidMonth**
71+
- [5] **credValidDay**
72+
- [6] **ageLowerbound** - age limit for voting rights. The circuit verifies that the passport owner is older than *ageLowerbound* years at the *currentDate*.
8573

86-
- **credValidMonth**
87-
88-
- **credValidDay**
89-
90-
- **ageLowerbound** - age limit for voting rights. The circuit verifies that the passport owner is older than *ageLowerbound* years at the *currentDate*.
91-
92-
### Circuits private inputs
74+
#### Circuits private inputs
9375

9476
- **in** - passport **DG1** serialized in binary.
9577

9678
The current date is needed to timestamp the date of proof generation. The circuit proves that at this date, the user is eligible to vote (and will be eligible by the protocol rules at least until the credValid date).
9779

9880
Passport data is separated into *DataGroups*. The hashes of these datagroups are stored in **SOD** *(Security Object of the Document)*. All neccesary data is stored in *Data Group 1 (DG1)*. Currently, **SHA1** and **SHA256** hashes are supported (```passportDG1VerificationSHA256``` and ```passportDG1VerificationSHA256```).
9981

100-
### Testing
101-
102-
To run tests enter ***tests*** directory and run:
103-
104-
```mocha -p -r ts-node/register 'passportTests.js'```
105-
106-
Inputs are not provided, as they contain personal data. May be mocked later.
107-
108-
To test query circuits:
109-
```mocha -p -r ts-node/register 'queryIdentityTests.js'```
110-
111-
To test identity registration circuits:
112-
```mocha -p -r ts-node/register 'registerIdentityTests'.js'```
113-
11482
### Identity platform
11583

11684
To enhance user experience and eliminate the repetitive need for passport rescanning, we have implemented a user identity management platform. This platform streamlines the process, making it easier and more efficient for users to verify their identity.
@@ -202,7 +170,7 @@ Poseidon(SHA256(signed_attributes\[:252bits])), while `dg15PubKeyHash` will be s
202170
- [1] **output** passportHash;
203171
- [2] **output** dg1Commitment;
204172
- [3] **output** pkIdentityHash;
205-
- [4] **input** slaveMerkleRoot; // public
173+
- [4] **input** slaveMerkleRoot;
206174

207175
#### Query circuit
208176

@@ -242,9 +210,8 @@ The query circuit allows you to prove arbitrary data from a passport.
242210
}
243211
```
244212

245-
***IMPORTANT!***
246-
247-
If date input is **NOT** used, put “0x303030303030” (52983525027888 - decimal). This is equal to “000000” in UTF-8 encoding, which is used to encode date in the passport. Otherwise date verification constraints will fail.
213+
> [!IMPORTANT]
214+
> If date input is **NOT** used, put “0x303030303030” (52983525027888 - decimal). This is equal to “000000” in UTF-8 encoding, which is used to encode date in the passport. Otherwise date verification constraints will fail.
248215
249216
#### Query circuit public signals
250217

@@ -315,6 +282,7 @@ By applying the selector, we can use the same circuit for any set of revealed an
315282

316283
```markdown
317284
QUERY SELECTOR:
285+
318286
0 - nullifier (+)
319287
1 - birth date (+)
320288
2 - expiration date (+)

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import "@nomicfoundation/hardhat-toolbox";
33
import "tsconfig-paths/register";
44

55
import "@solarity/hardhat-zkit";
6+
import "@solarity/chai-zkit";
67

78
import { HardhatUserConfig } from "hardhat/config";
89

@@ -24,7 +25,6 @@ const config: HardhatUserConfig = {
2425
},
2526
zkit: {
2627
circuitsDir: "circuits",
27-
nativeCompiler: true,
2828
compilationSettings: {
2929
c: true,
3030
onlyFiles: ["participationProof.circom"],

0 commit comments

Comments
 (0)