Getting Started

This tutorial will help you install Unirep and run examples

Download Unirep Social

Clone Unirep Social source code from github

git clone https://github.com/vivianjeng/Unirep-Social.git

Install packages

Install packages used in Unirep Social

yarn install

Build the Circom circuits

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.

yarn build

Test

Test all cli commands

yarn test-cli

Integration test

yarn test

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.

For example:

2. Deploy Unirep smart contract and its verifiers

If we choose the first account, we use 0xac097...ff80 as our deployerPrivateKeyparameter Open another terminal and run:

NOTE: -dis deployer's private key Then Unirep and Unirep Social contract's address will be printed. For example,

  • 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

NOTE: base64url encoded identity and identity commitment will be printed, For example,

4. User signs up

The user signs up with his identity commitment instead of his real identity.

NOTE: -x is the Unirep Social contract address and -c is user's identity commitment

5. Attester signs up

NOTE: -d is attester's private key, this private key is to be used only by this attester hereafter

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:

7. Attester verify epoch key proof

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

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

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: In genUnirepIdentity function, the output identity and its commitment is

Upvote or downvote will cost attester's reputation. Therefore, attester also generates his own epoch key to receive negative reputation.

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

11. Epoch transition

NOTE: -d private key could be anyone's private key and -t indicates it's testing environment so it will fast forward to the end of epoch

12. User state transition

The transition result will be printed

13. User generate reputation proof from certain attester

After user state transition, the user can generate a proof to prove that he has reputation from certain attester.

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,

14. Verify the reputation proof

Every user with the reputation proof can verify the proof and its claim.

The verification result will be printed

Last updated

Was this helpful?