Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

refactor for v1.1 #4

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ The high-level goal for **UniRep** is to be a base layer on top of which anyone

UniRep is originally proposed by BarryWhiteHat in [this ethresear.ch post](https://ethresear.ch/t/anonymous-reputation-risking-and-burning/3926)

### v1.1

Version 1.1 of the protocol reduces the complexity of user proofs to constant time. Users can receive unlimited attestations while keeping the proving time constant.

v1.1 also changes the tree structure, removing the user state tree completely. The global state tree and epoch tree are replaced by a state tree and epoch tree for each attester. As a result each attester can set their own epoch length. Users also execute a user state transition per attester, instead of 1 global transition.

Read the description [here](https://github.com/unirep/unirep/issues/134).

### Quick Links

* [Protocol introduction](introduction.md)
Expand Down
74 changes: 21 additions & 53 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,46 @@

* [👏 Welcome](README.md)
* [🧩 Introduction](introduction.md)
* [🎮 Getting Started](getting-started/README.md)
* [Install & build 🛠](getting-started/install-and-build.md)
* [Start with cli commands 🔌](getting-started/start-with-cli-commands/README.md)
* [0. Install and build](getting-started/start-with-cli-commands/0.-install-and-build.md)
* [1. Spin up the testing chain](getting-started/start-with-cli-commands/1.-spin-up-the-testing-chain.md)
* [2. Deploy Unirep contract](getting-started/start-with-cli-commands/2.-deploy-unirep-contract.md)
* [3. User generates semaphore identity](getting-started/start-with-cli-commands/3.-user-generates-semaphore-identity.md)
* [4. User signs up](getting-started/start-with-cli-commands/4.-user-signs-up.md)
* [5. Attester signs up](getting-started/start-with-cli-commands/5.-attester-signs-up.md)
* [6. User generates epoch key and epoch key proof](getting-started/start-with-cli-commands/6.-user-generates-epoch-key-and-epoch-key-proof.md)
* [7. Attesters/Users verify epoch key proof](getting-started/start-with-cli-commands/7.-attesters-users-verify-epoch-key-proof.md)
* [8. Submit epoch key proof to Unirep smart contract](getting-started/start-with-cli-commands/8.-submit-epoch-key-proof-to-unirep-smart-contract.md)
* [9. Attester attest to epoch key](getting-started/start-with-cli-commands/9.-attester-attest-to-epoch-key.md)
* [10. Epoch transition](getting-started/start-with-cli-commands/10.-epoch-transition.md)
* [11. User state transition](getting-started/start-with-cli-commands/11.-user-state-transition.md)
* [12. User generates reputation proof](getting-started/start-with-cli-commands/12.-user-generates-reputation-proof.md)
* [13. Attesters/ Users verify the reputation proof](getting-started/start-with-cli-commands/13.-attesters-users-verify-the-reputation-proof.md)
* [14. User generates sign up proof](getting-started/start-with-cli-commands/14.-user-generates-sign-up-proof.md)
* [15. Attesters/ Users verify the sign up proof](getting-started/start-with-cli-commands/15.-attesters-users-verify-the-sign-up-proof.md)
* [Start with Typescript 📠](getting-started/start-with-typescript.md)
* [0. Install packages](getting-started/start-with-typescript/0.-install-packages.md)
* [1. deploy](getting-started/start-with-typescript/1.-deploy.md)
* [2. User signs up](getting-started/start-with-typescript/2.-user-signs-up.md)
* [3. Attester signs up](getting-started/start-with-typescript/3.-attester-signs-up.md)
* [4. Epoch key proof](getting-started/start-with-typescript/4.-epoch-key-proof.md)
* [5. Attest](getting-started/start-with-typescript/5.-attest.md)
* [6. Epoch transition](getting-started/start-with-typescript/6.-epoch-transition.md)
* [7. User state transition](getting-started/start-with-typescript/7.-user-state-transition.md)
* [8. Reputation proof](getting-started/start-with-typescript/8.-reputation-proof.md)
* [Computation happens off-chain ℹ️](getting-started/computation-happens-off-chain.md)

## ☀ Protocol

* [Glossary](protocol/glossary/README.md)
* [Attestations](protocol/glossary/attestation.md)
* [Users and Attesters](protocol/glossary/users-and-attesters.md)
* [Epoch](protocol/glossary/epoch.md)
* [Epoch Key](protocol/glossary/epoch-key.md)
* [Reputation](protocol/glossary/reputation.md)
* [Trees](protocol/glossary/trees.md)
* [Nullifiers](protocol/glossary/nullifiers.md)
* [Epoch Transition](protocol/glossary/epoch-transition.md)
* [User State Transition](protocol/glossary/user-state-transition.md)
* [Circuits](protocol/circuits/README.md)
* [Epoch Key Proof](circuits/epoch-key-proof.md)
* [Reputation Proof](circuits/reputation-proof.md)
* [User Sign Up Proof](circuits/user-sign-up-proof.md)
* [User State Transition Proof](circuits/user-state-transition-proof.md)
* [Contract](protocol/contract/README.md)
* [Sign up](protocol/contract/sign-up.md)
* [Attestations](protocol/contract/attestations.md)
* [Epoch transition](protocol/contract/epoch-transition.md)
* [User state transition](protocol/contract/user-state-transition.md)
* [Verify proofs](protocol/contract/verify-proofs.md)

## 🌈 Package usage <a href="#package" id="package"></a>
## 🌈 API <a href="#package" id="package"></a>

* [@unirep/crypto](package/crypto.md)
* [hash\*()](./api/crypto-hashes.md#hashes)
* [genEpochKey](./api/crypto-hashes.md#genEpochKey)
* [genEpochNullifier()](./api/crypto-hashes.md#genEpochNullifier)
* [genStateTreeLeaf()](./api/crypto-hashes.md#genStateTreeLeaf)
* [IncrementalMerkleTree](./api/crypto-incremental-tree.md)
* [constructor()](./api/crypto-incremental-tree.md#constructor)
* [insert()](./api/crypto-incremental-tree.md#insert)
* [update()](./api/crypto-incremental-tree.md#update)
* [delete()](./api/crypto-incremental-tree.md#delete)
* [createProof()](./api/crypto-incremental-tree.md#createProof)
* [verifyProof()](./api/crypto-incremental-tree.md#verifyProof)
* [SparseMerkleTree](./api/crypto-sparse-tree.md)
* [constructor()](./api/crypto-sparse-tree.md#constructor)
* [height](./api/crypto-sparse-tree.md#height)
* [root](./api/crypto-sparse-tree.md#root)
* [insert()](./api/crypto-sparse-tree.md#insert)
* [update()](./api/crypto-sparse-tree.md#update)
* [createProof()](./api/crypto-sparse-tree.md#createProof)
* [verifyProof()](./api/crypto-sparse-tree.md#verifyProof)
* [@unirep/circuits](package/circuits.md)
* [@unirep/contracts](package/contracts.md)
* [@unirep/core](package/core.md)
* [@unirep/subgraph](package/subgraph.md)
* [cli](package/cli/README.md)
* [Deploy Unirep Contract](cli/deploy-unirep-contract.md)
* [User Identity](cli/user-identity.md)
* [User Sign Up](cli/user-sign-up.md)
* [Epoch Key And Proof](cli/epoch-key-and-proof.md)
* [Attestation](cli/attestation.md)
* [Epoch transition](cli/epoch-transition.md)
* [User state transition](cli/user-state-transition.md)
* [Reputation Proof](cli/reputation-proof.md)
* [Airdrop Reputation](cli/airdrop-reputation.md)
* [Spend Reputation](cli/spend-reputation.md)

## 🌻 Applications

Expand Down
59 changes: 59 additions & 0 deletions api/crypto-hashes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
### Usage

Import these functions like so:

```js
import { hash1, genStateTreeLeaf } from '@unirep/crypto'
```

Any functions documented here will be maintained according to semver.

##### Hashes

Poseidon hash of variable number of items.
```ts
hash1(items: any[]): bigint
hash2(items: any[]): bigint
hash3(items: any[]): bigint
...
hash8(items: any[]): bigint
```

##### genEpochKey

Calculate an epoch key. `maxEpochKey` is the maximum value for a key. The hash will be modded by this value, e.g. `H(...) % maxEpochKey`. For a binary tree this should be `2**depth`.
```ts
genEpochKey(
identityNullifier: bigint,
attesterId: bigint,
epoch: bigint | number,
nonce: bigint | number,
maxEpochKey: bigint | number
): bigint
```

##### genEpochNullifier

Calculate a user state transition nullifier. TODO: update name
```ts
genEpochNullifier(
identityNullifier: bigint,
attesterId: bigint | string,
epoch: number | bigint
): bigint
```

##### genStateTreeLeaf

Calculate a state tree leaf for a user.
```ts
genStateTreeLeaf(
idNullifier: bigint,
attesterId: bigint | string,
epoch: bigint | number,
posRep: bigint | number,
negRep: bigint | number,
graffiti: bigint | number,
timestamp: bigint | number
): bigint
```
70 changes: 70 additions & 0 deletions api/crypto-incremental-tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
### Usage

Import this class like so:

```js
import { IncrementalMerkleTree } from '@unirep/crypto'
```

Any functions documented here will be maintained according to semver.

### `class IncrementalMerkleTree`

##### constructor

Get a new tree instance.
```ts
constructor(
depth: number,
zeroValue: number = 0,
arity: number = 2
): IncrementalMerkleTree
```

##### insert

Insert a new leaf in the next free index.
```ts
this.insert(leaf: bigint)
```

##### update

Update a leaf in the tree by index.
```ts
this.update(index: number, leaf: bigint)
```

##### delete

Delete (set to zero value) a leaf in the tree.
```ts
this.delete(index: number)
```

##### Proof

A struct for representing merkle proofs.

```ts
type Proof = {
root: bigint,
leaf: bigint,
pathIndices: number[],
siblings: bigint[][]
}
```

##### createProof

Get a merkle inclusion proof for an index.
```ts
this.createProof(index: number): Proof
```

##### verifyProof

Verify a merkle proof in the tree.
```ts
this.verifyProof(proof: Proof): boolean
```
63 changes: 63 additions & 0 deletions api/crypto-sparse-tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
### Usage

Import this class like so:

```js
import { SparseMerkleTree } from '@unirep/crypto'
```

Any functions documented here will be maintained according to semver.

### `class SparseMerkleTree`

##### constructor

Get a new tree instance.
```ts
constructor(
height: number,
zeroValue: bigint = 0
): SparseMerkleTree
```

##### height

Get the number of levels in the tree. (getter)
```ts
this.height
```

##### root

Get the current root of the tree. (getter)
```ts
this.root
```

##### insert

Insert a new leaf in the next free index.
```ts
this.insert(leaf: bigint)
```

##### update

Update a leaf in the tree.
```ts
this.update(index: bigint, value: bigint)
```

##### createProof

Create a merkle inclusion proof for a leaf.
```ts
this.createProof(index: bigint): bigint[]
```

##### verifyProof

Verify a merkle inclusion proof.
```ts
this.verifyProof(index: bigint, proof: bigint[]): boolean
```
55 changes: 0 additions & 55 deletions circuits/epoch-key-proof.md

This file was deleted.

Loading