kskhasegawa / circom-rangeproof-for-vc

circom circuits for rangeproof of birthdate described in Verifiable credentials

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do not use this repository as it is for experimental purposes.

circom-rangeproof-for-vc

circom circuits for rangeproof of birthdate described in Verifiable credentials.

Verifiable credentials(VCs) can apply selective disclosure methods. It enable a credential holder to disclose only necessary information to a verifier.
For example, a holder can show only their date of birth and conceal any other information in their credentials. Selective disclosure methods are fundamental to enhancing a client's privacy.
However, even when using selective disclosure, a credential holder must present a date of birth for a verifier to confirm that it meets the age limit. Under traditional system environments, a verifier needs to know a client's personal information in order to verify its authenticity, confirm that it meets some condition, and decide to provide goods or services. They cannot perform these procedures if the information is concealed.

By combining zk-SNARK circuit with VCs, it is possible to build an attribute-based authentication scheme that ensures privacy preservation. Here we have created a circuit specific to the date of birth information. This circuit can prove that date of birth described in VC statement is older than specific target date. Therefore, for example, it is possible to prove that I am at least 20 years old without showing my actual date of birth.

To generate zk-SNARK proof, it need some data.
Birthdate statement, proof challenge, and blinding factor, which are used to create a commitment included in Verifiable presentation(VP) proof.

To use VCs, and extract those data, we use @kskhasegawa/jsonld-signatures-bbs (modified version of mattrglobal's) library.

Getting started

git clone https://github.com/kskhasegawa/circom-rangeproof-for-vc.git
cd circom-rangeproof-for-vc
npm install

circuit compile

circom circuits/hash_to_fr_to_commit_and_compare.circom --r1cs  --wasm -p bls12381
cd hash_to_fr_to_commit_and_compare_js
snarkjs powersoftau contribute pot16_0000.ptau pot16_0001.ptau --name="First contribution" -v
snarkjs powersoftau prepare phase2 pot16_0001.ptau pot16_final.ptau -v
snarkjs groth16 setup ../hash_to_fr_to_commit_and_compare.r1cs pot16_final.ptau hashAndCompare_0000.zkey
snarkjs zkey contribute hashAndCompare_0000.zkey hashAndCompare_0001.zkey --name="1st Contributor Name" -v
snarkjs zkey export verificationkey hashAndCompare_0001.zkey verification_key.json

input generation

node generate_input.js statement.json input.json

statement.json is like below.
Those values can be extracted from @kskhasegawa/jsonld-signatures-bbs when VP is created.
The value of "target" is an arbitrary date for which you want to prove that the date of birth described in the statement is older(or newer) than that date.

{
    "statement": "<did:example:b34ca6cd37bbf23> <http://schema.org/birthDate> \"1958-07-17\"^^<http://www.w3.org/2001/XMLSchema#dateTime> .",
    "proof_challenge": "07c15be749e0d9277b25b62ea2e02487822687644024f024a7e53ac43a449fe4",
    "blinding_factor": "2664991206cc6e6a144513f4c899a417ee516fa456ee3f9ec51c159ddca97c33",
    "target": [1990, 12, 31]
}

witness generation

cd hash_to_fr_to_commit_and_compare_js
node generate_witness.js hash_to_fr_to_commit_and_compare.wasm ../input.json witness.wtns

prove

snarkjs groth16 prove hashAndCompare_0001.zkey witness.wtns proof.json public.json

verify

Verify whether the birthdate described in the statement is older(or newer) than target or not, without showing plaintext of the statement.

snarkjs groth16 verify verification_key.json public.json proof.json

composit proof verify

return true if the value of the commitment generated by this circom circuits is the same as that included in VPdocument(proofValue).
This allows us to relate the zk-snark proof to the VP proof.

node /scripts check_commitment_in_proof.js example/VPdocument_example.json public.json

About

circom circuits for rangeproof of birthdate described in Verifiable credentials


Languages

Language:Circom 92.5%Language:JavaScript 7.5%