Build circom circuits and generate their constraints and verification keys and proving keys files in the build/ directory.
Also export smart contract verifiers to be deployed with Unirep and Unirep Social smart contract.
yarnbuild
Test
Test all cli commands
yarntest-cli
Integration test
yarntest
Example cli commands workflow
1. Run a testing net
We use hardhat here as a blockchain developing environment.
NOTE: a list of default accounts will be printed, choose one of them to be user's account and one to be attester's. User's and attester's private key will be referred to as deployerPrivateKey and attesterPrivateKey respectively.
Then we use the Unirep Social contract's address to interact with.
Unirep Social contract will sign up as the an attester with attester ID1.
When users spend reputation to publish a post or leave a comment, Unirep Social contract will perform as an attester to give users negative reputation.
3. Generate user's identity and identity commitment
npxts-nodecli/index.tsgenUnirepIdentity
NOTE: base64url encoded identity and identity commitment will be printed, For example,
NOTE:-d is attester's private key, this private key is to be used only by this attester hereafter
NOTE: Though user signs up requires a private key, private key is used to interact with smart contract but not link identity commitment and the account.
However, attesterSignupbind the account with attester id. Whenever the user wants to attest others, the user has to use the account he has registered for as an attester.
Therefore, users can sign up their identity commitments and their attester ids with different accounts to enjoy more privacy protection.
6. User generates epoch key and epoch key proof
The user can generate an epoch key with his identity and nonce.
NOTE: -id is user's identity and -n is epoch key nonce which should be less than the system parameter maxEpochKeyNonce
NOTE: epoch key and base64url encoded epoch key proof will be printed and they should be handed to attester to be verified, for example:
Epoch key of epoch 1 and nonce 0: 69
Unirep.epkProof.WyIxNjA4MjU3MzE4NTE4MzU0NjcyNTQ5Mjc1Njg1NDMwMDkwMTEwMjUxNDU0NTAwODQ2NjQ1MTk5Mjg5MzY3NjgwNTI4ODc1MDQ2MjY5NiIsIjE0MzE1OTI5OTQzMDI4NTY5MjA4OTQ3NTYyMTI0MDA5MzUwMjgxMzM3MDQyMjk0MTMxODEzMjI4Mzc5NjY5NzgwNTM5NTQwMzgxNjkyIiwiMTI3NzA1NjIzMTA4OTE1MTEyNDEzOTU3ODQ2NjM0MTE1MDA0OTI4MjMwMDA1NjkzNjEwMjI0MzI1MTY5NjA0NzAzMTgxNzc4MDU0NTEiLCIxMDcwNDAyMTI0MzMwNzkwNzEyMTAxNzY0OTMyMjgwNzkyODgyNzMzNzkwODI1NjQ1NTc5NDAwOTA2OTgwMTc3NTA2OTQ4NzU0MzQyMyIsIjIxNjY5MzkzNjExNTY1MTY2MDU4MDkwMDQzMzYzMDk1MjE4ODY2NTMzOTU3MDY3NDk3NDI3NzU3NzU2NTc1MzExNzU0NzM3NjA1ODQ5IiwiNjE0NDg1NzE0MDQyODMwMTM5ODMxODk1MjI2OTIyODI4NzE2MDg5OTQ3OTAzNDE5MTQwMDA2MjM0MDQ3MDIwOTM1NTgyNDcxOTgzMiIsIjE1MTUxNDE2MDg2NTYxMzU3Njc4MjYzMjg2MDI4NzA2NjA1MTkyNjIyMjM4Mzk5NjkwNzY4MTc4MjE0MjQ3MTE0OTk0NzU5ODY3ODI0IiwiMTExMjE2Mzc3NTAyNTA5OTk1MjEwODUwMTAyNjMzMTIwNDMwOTgzOTE0OTM5NzU0Nzg4OTI0MTQ0NDMzNTk1NjA4NzU2MDA4NzM2MjYiXQ
NOTE:-epk is user's epoch key and -pf is the epoch key proof
8. User publish a post with an epoch key and proof
When a user wants to publish a post, he has to generate his reputation proof to prove that he has enough reputation to make a post. The proof also validate the epoch key.
NOTE:-nis an epoch key nonce, and it will generate the user's epoch key with the nonce to this epoch, which should be less than the system parameter maxEpochKeyNonce
Epoch key and post ID will be printed
Post ID: 608a36e71764bcce46a2a4bb
Epoch key of epoch 1 and nonce 0: 69
Unirep.reputationProof.WyI3NzIzMzE4MTUzOTYzMzg2NDA2MzA3MTExMTk1ODY0NzA3Mzc3MzExODY4MzQ1MDExMjA1MTg2MDU3NTQ5NTc0NDcyMjI5OTAxMjQ5IiwiMjEzNzE1MzA2NTU3Nzg5NDMxNjE5NzAwMTU3ODM1MDQyMjU0Njk1ODQ0MTg0NTk5Njk2NTMwMjQ3NDEzODEyMTY1MDY5MjU3MTM5ODEiLCI2NjgwNDc3MzQ3ODQwMTE4OTU5NzQ0MDQ0Mzg3OTQ0MDA2MTA5NDY5NTgyMDc0NjYwMTcyNjcwODkzNjU4MDA3ODgyMzMzNTE4MjQxIiwiMTA0NTA0MTM3MDExMjQ2NTUyMzg0NjkyMzkyNzk3MjE3NjUxMTc3Njk2ODMzODAxNzE0NjY5Nzk5MTEyNDA3NDk5NjAzNjk0MjQwOTEiLCIyMDYxMTY2NTkzOTA4NDEzNTc2NzIxODk0MzczODkzNTEzMjg2NzcwMDQ1MjExNDkxODQwODE3MjAxNjk2NDU0ODk4MzAxNzI2NzAyMCIsIjQwMzkwNDg1Mjc2NjcxNTg1NjYxMDM5OTY0NTExMjYyNjI0NDUwOTU0MzM4MjYwNTUyNjQ2NTgwNTQ0NjgxNDQzNjI3NjE4MTkxNjkiLCIxOTc1MDE3NjEzODg3ODIzODk1MzA0MDI2ODkyMDgwMTg4MDQ0MTk3NDM2MTY0MjA2NTIzNDc0ODg5NjA0MzE4NTU4Nzk4ODk5NDgzMiIsIjIwNzI5NDY3MDMxMDYyMjAzNzIwNDg5MjM3OTczMTc0MDAyNTkwNDQxOTc1MTQzOTg4NTEyODUxMDE1MDE5MDQ3NzI2MTI2OTI3MjQiXQ
Transaction hash: 0xc4d5e343bbf1f90e75e1a61099358df1506ad6588b84f0546d99b7ea4bef7477
9. Verify reputation proof of certain transaction
Users can use the reputation proof with the transaction hash to obtain snark circuit and its public inputs. Then user can call the on-chain verifier to verify the proof.
NOTE:-epk is user's epoch key and
-pf is the epoch key proof
-this the transaction hash
The verification result will be printed
Verify reputation proof of epoch key 69 with 10 reputation
spent in 0xc4d5e343bbf1f90e75e1a61099358df1506ad6588b84f0546d99b7ea4bef7477 transaction
and minimum reputation 0, succeed
10. Attester upvotes to epoch key
To upvote an epoch key, we need another user with different identity. So we generate an identity and sign up the second user in the same way.
NOTE:-epk is the epoch key the user wants to give reputation to
-uv is the upvote value (-dv is the downvote value)
-id is the attester's identity
-n is the epoch key nonce where the attester has to give a negative reputation to oneself
-gf is the graffiti for the reputation given to the user
-d is the attester's private key
Attesting to epoch key 69 with pos rep 3, neg rep 0 and graffiti 176ff05d9c7c4528b04553217098a71cd076d52623dab894a7f7ee34116ca170 (overwrite graffit: true)
Transaction hash: 0xb621c0debde8a4d3e0edb5aeeb7a43b2d97687d055d7ee99e5742cc0574ecbe9
The proof can also be verified with verifyReputationProoffunction
NOTE:-a is attester's id
-mp is the minimum positive reputation score, i.e, user wants to prove that the attester gave the user a positive reputation score that's larger than the minimum positive reputation score
-mn is the maximum negative reputation score, i.e, user wants to prove that the attester gave the user a negative reputation score that's less than the maximum negative reputation score
-md is the minimum difference between positive and negative reputation scores
-gp is the pre-image of the graffiti for the reputation
NOTE:gp in this case, 0 being the hash pre-image of 176ff05d9c7c4528b04553217098a71cd076d52623dab894a7f7ee34116ca170
Proof will be printed and it should be handed to the receiver of this proof, for example,
Proof is correct
Proof of reputation from attester 2:
Unirep.reputationProofFromAttester.WyIxNTIzOTA2NTM1NjEyMDU2MTMzNzI0NzkyNDA2ODMyMzE1MTc4NTI0NTcwMjA0MjAwMjQzNTM1MTAxNjc4NzY4OTkyMzMzNDE3Njk2MSIsIjE5Nzc0MTk5NTEyMDExMzkwNTM4MDU2OTMxMTA4ODkwMTg5Nzc3MTMwOTA1ODA4MzI5NzkyMDU3MDEwMTI0MDIxNTMwMDgwMzUxMTY1IiwiMzgzMTU4MzY0NDY5MzMxNzcxODc3NzE4MjE5OTExMTYwMjI3MDI0MTcwODY0Mjg3Mzc0NTczMDA4MzU0OTE2ODA2OTkxMzU5MDc0MSIsIjE1NDkwNzIyODk0NTk0NTE2OTI4ODgwNjA5MDE3MTgzMDg4MDk0MjM4MTgxNDE1ODM1ODU1MDg0NDgwNTAyNjI1NjI1MDY4NjY0Mjk0IiwiMTExMjQ3ODA3MTI3MjQyNTgwMjkyMjM4OTc0OTg2NDQxOTE1NDQyNzIyOTg0MTE1MDk4OTUyMTYxNDk0Njg2NjQwNDk1ODk0Mjg4NjYiLCI3NzU3NzUwMzIzMjI2NDM2MDMwMDM3MTAyMDY5MzQxODMyNDcxNTEyOTQ5NjgwODQzMzE4OTk2NDc5ODI4NTAzOTE2MDU0NDA3NDIyIiwiMTk4OTUyODA4NzUwNjM2Mjg3MjEwNjY0NTgxMTIxNzM2MTg5NDEyNjMxNjA5NjU1OTQzNDkxMzkzMjEwMzkyMjc1MjY1NDg0NzUwOTQiLCIxNjg4NTA1MjIzNjU4NjI1MDM2ODM4MTc3ODAyMjM0OTk2MTE0ODgzMzg2Mzg2OTE1MTA0MzgwODI2MzY1NzYyMzE1ODI1NTA3MDc1Il0
14. Verify the reputation proof
Every user with the reputation proof can verify the proof and its claim.
Verify reputation proof from attester 2 with min pos rep 2, max neg rep 1 and graffiti pre-image 0, succeed
User can optionally choose to prove among -mp, -mn, -md or -gp
But the inputs of verification should be identical with the claim of which user uses to generate the proof.