Skip to content

Commit 4fbd23d

Browse files
authored
Merge pull request #111 from hyperledger-labs/docs
Move content from README to docs
2 parents 5b7a9dd + 7449b1b commit 4fbd23d

40 files changed

+1205
-168
lines changed

.github/workflows/docs.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Docs Site
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'doc-site/docs/**'
9+
pull_request:
10+
paths:
11+
- 'doc-site/docs/**'
12+
release:
13+
types: [released]
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
env:
18+
LATEST_TAG: ''
19+
permissions:
20+
contents: write
21+
steps:
22+
- name: Checkout source
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup Docs Deploy
28+
run: |
29+
git config --global user.name "GitHub Actions"
30+
git config --global user.email "noreply@github.com"
31+
32+
- name: Get the latest tag
33+
run: |
34+
git fetch --tags
35+
latest_tag=$(git tag -l | sort -V | grep -v "rc" | tail -n 1)
36+
echo "latest tag: $latest_tag"
37+
echo "LATEST_TAG=$latest_tag" >> $GITHUB_ENV
38+
39+
- name: Install docs dependencies
40+
working-directory: doc-site
41+
run: pip install -r requirements.txt
42+
43+
- name: Update doc site for release
44+
if: github.event.action == 'released' && github.ref_name != env.LATEST_TAG
45+
working-directory: doc-site
46+
run: mike deploy ${{ github.event.release.tag_name }} --push
47+
48+
- name: Update doc site for latest release
49+
if: github.event.action == 'released' && github.ref_name == env.LATEST_TAG
50+
working-directory: doc-site
51+
run: mike deploy ${{ github.event.release.tag_name }} latest -u --push
52+
53+
- name: Update doc site for `main` branch
54+
if: ${{ github.event_name == 'push' }}
55+
working-directory: doc-site
56+
run: mike deploy head --push
57+
58+
- name: Test building the doc site but do not deploy it
59+
if: ${{ github.event_name == 'pull_request' }}
60+
working-directory: doc-site
61+
run: mkdocs build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
.vscode/launch.json

README.md

Lines changed: 2 additions & 168 deletions
Large diffs are not rendered by default.

doc-site/.devcontainer/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Specify version of MkDocs Material
2+
FROM squidfunk/mkdocs-material:latest
3+
RUN pip install mike
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "MkDocs Material editor",
3+
"dockerFile": "Dockerfile",
4+
"workspaceMount": "source=${localWorkspaceFolder}/doc-site,target=/docs,type=bind",
5+
"workspaceFolder": "/docs",
6+
"customizations": {
7+
"vscode": {
8+
"settings": {
9+
"terminal.integrated.shell.linux": "/bin/sh"
10+
},
11+
"extensions": [
12+
"ms-vscode-remote.remote-containers"
13+
]
14+
}
15+
},
16+
"forwardPorts": [
17+
8001
18+
],
19+
"postStartCommand": "mkdocs serve -a localhost:8001",
20+
}

doc-site/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
venv
2+
site

doc-site/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Zeto Documentation Site
2+
3+
This directory is based on the [Hyperledger documentation template](https://github.com/hyperledger-labs/documentation-template). The template utilizes MkDocs (documentation at [mkdocs.org](https://www.mkdocs.org)) and the theme Material for MkDocs (documentation at [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)). Material adds a number of extra features to MkDocs, and Hyperledger repositories can take advantage of the theme's [Insiders](https://squidfunk.github.io/mkdocs-material/insiders/) capabilities.
4+
5+
[Material for MkDocs]: https://squidfunk.github.io/mkdocs-material/
6+
[Mike]: https://github.com/jimporter/mike
7+
8+
## Prerequisites
9+
10+
To test the documents and update the published site, the following tools are needed:
11+
12+
- A Bash shell
13+
- git
14+
- Python 3
15+
- The [Material for Mkdocs] theme.
16+
- The [Mike] MkDocs plugin for publishing versions to gh-pages.
17+
- Not used locally, but referenced in the `mkdocs.yml` file and needed for
18+
deploying the site to gh-pages.
19+
20+
### git
21+
22+
`git` can be installed locally, as described in the [Install Git Guide from GitHub](https://github.com/git-guides/install-git).
23+
24+
### Python 3
25+
26+
`Python 3` can be installed locally, as described in the [Python Getting Started guide](https://www.python.org/about/gettingstarted/).
27+
28+
### Virtual environment
29+
30+
It is recommended to install your Python dependencies in a virtual environment in case you have other conflicting Python installations on your machine. This also removes the need to install these packages globally on your computer.
31+
32+
```bash
33+
cd doc-site
34+
python3 -m venv venv
35+
source venv/bin/activate
36+
```
37+
38+
### Mkdocs
39+
40+
The Mkdocs-related items can be installed locally, as described in the [Material
41+
for Mkdocs] installation instructions. The short, case-specific version of those
42+
instructions follow:
43+
44+
```bash
45+
pip install -r requirements.txt
46+
```
47+
48+
### Verify Setup
49+
50+
To verify your setup, check that you can run `mkdocs` by running the command `mkdocs --help` to see the help text.
51+
52+
## Useful MkDocs Commands
53+
54+
The commands you will usually use with `mkdocs` are:
55+
56+
- `mkdocs serve` - Start the live-reloading docs server.
57+
- `mkdocs build` - Build the documentation site.
58+
- `mkdocs -h` - Print help message and exit.
59+
60+
## Adding Content
61+
62+
The basic process for adding content to the site is:
63+
64+
- Create a new markdown file under the `docs` folder
65+
- Add the new file to the table of contents (`nav` section in the `mkdocs.yml` file)
66+
67+
If you are using this as a template for creating your own documentation, please see [the instructions for customization](./docs/index.md).
68+
69+
## Repository layout
70+
71+
mkdocs.yml # The configuration file.
72+
docs/
73+
index.md # The documentation homepage.
74+
... # Other markdown pages, images and other files.
1.8 KB
Loading
Lines changed: 15 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading

doc-site/docs/concepts/basics.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Basic Concepts
2+
3+
Zeto is built on the following fundamental concepts.
4+
5+
## Onchain state model: UTXO
6+
7+
The smart contract for a token economy must maintain states onchain. There are two ways to model states: account vs. UTXO.
8+
9+
- The account model is very popular in the existing token standards such as ERC20/721/1155 etc. Each account is an entry in a map that the smart contract maintains, with the value being the account's state such as current balance, or list of assets. A transaction updates the states of one or more accounts.
10+
- The UTXO model works very differently, by creating states that are independent to each other. Each UTXO state is in one of two modes: unspent or spent. A transaction consumes unspent states, at which point they become spent, and produces new (unspent) states. Each UTXO state specifies the spending rules that must be satisfied when a transaction attempts to spend it.
11+
12+
### UTXO for better parallel processing
13+
14+
The UTXO model is adopted for Zeto instead of the account model, for better support of parallel processing. Due to the necessity of maintaining private states offchain in order to achieve privacy, the client must continuously keep their private states in sync with the smart contract. Using an account model makes it more difficult to achieve this because incoming transfers from other parties would invalidate an account's state, making the account owner unable to spend from its account unless the private state has been sync'ed again. Solutions to this issue, often referred to as front-running, typically involve a spending window with a pending queue. One example of this is [Zether](https://eprint.iacr.org/2019/191), which describes an `epoch` construct with pending transaction queues to address the front-running problem. Using epochs results in limited parallel processing of transactions from the same spending account.
15+
16+
With a UTXO model, on the other hand, since each state is independent of the others, spending multiple UTXOs at the same time, even if they call come from the same owner, can be easily achieved.
17+
18+
### UTXO for better anonymity
19+
20+
With an account model, given that the states are mapped to the owning accounts in the onchain storage, there is an inherent challenge to anonymity, where checking which account was updated by a transaction would reveal the counterparties of a transaction. This could be mitigated by using anonymity sets, where more accounts besides the real sender and receiver of a transaction are updated with an encrypted zero value. However this increases the gas cost of transactions.
21+
22+
With the UTXO model, since each UTXO state describes its own ownership, in a masked form (`hash(value, owner public key, salt)`), there is no revelation of the owning account when a UTXO is spent or produced. Furthermore, the entitlement to spend the private UTXO token is demonstrated by the ZK proof, rather than the transaction signer (aka `msg.sender`). This allows Zeto transactions to be signed by any accounts. Zeto clients are encouraged to use one-time signing keys to submit transactions, such as those from an [HD wallet](https://en.bitcoin.it/wiki/BIP_0032).
23+
24+
## Commitments
25+
26+
Each UTXO is tracked by the smart contract as a hash of the following components: value (for fungible Zeto) or token Id (for non-fungible Zeto), owner public key and salt. These are called commitments. They serve several important purposes:
27+
28+
- Representing the existence of a Zeto token. A Zeto token's value is recognized only if it's commitment is known to the smart contract that maintains the token economy.
29+
- Hiding the secret information about a Zeto token. The value or token Id and the ownership information are hidden behind the secure hash string, which can not be reverse-engineered back to the secerts.
30+
- Acting as the public inputs for verifying ZK proofs. All Zeto transactions consume some existing UTXOs and produce some new UTXOs. For the smart contract to be convinced that a transaction is valid, a ZK proof must be provided that demonstrates a transaction proposal conforming to the policies of the specific token implementation. The commitment hashes are critical public inputs in almost all such ZK proof verifications.
31+
32+
## Finality
33+
34+
Each transaction's validity is verified by the smart contract before allowing the proposed input UTXOs to be nullified and the output UTXOs to come into existence. In other words, this is not an optimistic design and as such does not rely on a multi-day challenge period before a transaction is finalized. Every transaction is immediately finalized once it's mined into a block.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# How Zeto tokens work
2+
3+
![Zeto overview](../images/overview.jpg)
4+
5+
- Party A owns 3 Zeto tokens at the beginning: `#1, #2, #3`. The 3 tokens have been minted in the Zeto smart contract and represented by their commitments, aka `hash(value, owner public key, salt)`
6+
- As the owner of the tokens, party A also has access to the secrets that the commitments can be opened to, namely the value and salt. The secrets are represented as private states: `s1, s2, s3`
7+
- How party A obtained the secrets for the owned tokens, is dependent on the specific Zeto implementation. It can be from offchain channels or from onchain (encrypted) data
8+
- Party A sends transaction `Tx1` to transfer some value to party B. The transaction consumes 2 tokens `#1, #2` and produces 2 new tokens `#4, #5`. `#5` is the value to be transferred to party B. `#4` is the remainder value that goes back to party A
9+
- Even though party A knows the secrets of `#5`, they won't be able to spend the token because party A is not the owner of the token.
10+
- Ownership verification is enforced by the Zeto smart contract when it verifies the zero knowledge proofs. Each ZKP circuit ensures that the sender's private key is used as a private input signal to derive the public key, which is then hashed to calculate the commitments
11+
- Party B sends transaction `Tx2` to transfer some value to party C. This works the same as `Tx1`
12+
- All parties get the commitments, `#1, #2, ... #7`, from the onchain events
13+
14+
The above diagram illustrates that the secrets are transmitted from the sender to the receiver in an off-chain secure channel. Other means of sharing the secrets are avaiable in Zeto token implementations. For instance, the [Zeto_AnonEnc](https://github.com/hyperledger-labs/zeto/blob/main/solidity/contracts/zeto_anon_enc.sol) implementation includes encrypted secrets in the transaction input, and emits an event with the encrypted values. The encrypted values can only be decrypted by the receiver.
15+
16+
## EC Cryptography
17+
18+
Performing key pair operations, such as deriving the public key from the private key, in the ZKP circuit requires ZKP-friendly curves, for which we picked [Babyjubjub](https://docs.iden3.io/publications/pdfs/Baby-Jubjub.pdf) instead of the regular Ethereum curve (secp256k1).
19+
20+
## Transaction Signing
21+
22+
Another implication to the usage of ZKPs as transaction validity proof and the usage of the Babyjubjub curve, is that the signer of the transaction, eg. `msg.sender`, no longer bears the same significance as in other token implementations such as ERC20, ERC721, where the signer's EVM account address holds the actual assets. In Zeto tokens, it's the Babyjubjub public keys that hold the entitlement to spend the tokens. In fact, the applications are encouraged to use a different signing key for each transaction, to avoid leaking transaction behaviors and breaking anonymity.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Asking a Question
2+
3+
!!! tip
4+
5+
* check the [FAQs](../faqs.md) to see if your question has already been asked.
6+
* make sure you provide all relevant details.
7+
* include information about what you have already tried.
8+
* review [How to Ask Technical Questions to Get Quality Answers](https://opensource.com/life/16/10/how-ask-technical-questions) prior to asking your question.
9+
10+
## Chat
11+
12+
[Hyperledger’s Discord server](https://discord.gg/hyperledger) is the place to go for real-time chat about everything from quick help to involved discussions.
13+
14+
For general Zeto discussions, join the Discord server and visit _Labs/Zeto_.
15+
16+
## Mailing Lists
17+
18+
The Paladin mailing list is hosted by the Hyperledger Foundation: https://lists.lfdecentralizedtrust.org.

0 commit comments

Comments
 (0)