Bläddra i källkod

book: Fixups.

parazyd 4 år sedan
förälder
incheckning
2e6bddcf32
4 ändrade filer med 115 tillägg och 102 borttagningar
  1. 3 45
      README.md
  2. 42 20
      doc/src/architecture/anonymous_assets.md
  3. 3 3
      doc/src/learn/research.md
  4. 67 34
      doc/src/learn/zk_explainer.md

+ 3 - 45
README.md

@@ -2,7 +2,7 @@
 
 ![Build Status](https://img.shields.io/github/workflow/status/darkrenaissance/darkfi/CI%20Checks?style=flat-square)
 [![Web - dark.fi](https://img.shields.io/badge/Web-dark.fi-white?logo=firefox&logoColor=white&style=flat-square)](https://dark.fi)
-[![Manifesto - unsystem](https://img.shields.io/badge/Manifesto-unsystem-informational?logo=minutemailer&logoColor=white&style=flat-square)](https://lists.dyne.org/lurker/message/20211021.123016.3dccaf0c.en.html)
+[![Manifesto - unsystem](https://img.shields.io/badge/Manifesto-unsystem-informational?logo=minutemailer&logoColor=white&style=flat-square)](https://dark.fi/manifesto.html)
 [![Book - mdbook](https://img.shields.io/badge/Book-mdbook-orange?logo=gitbook&logoColor=white&style=flat-square)](https://darkrenaissance.github.io/darkfi)
 
 
@@ -40,7 +40,7 @@ to install the required dependencies:
 Alternatively users can use the automated script in
 `contrib/mac_setup.sh` by running. This script will install brew
 if it does not already exists on the system and then automatically
-install the dependencies
+install the dependencies:
 
 ```shell
 % bash contrib/mac_setup.sh
@@ -80,49 +80,7 @@ This will add the options auto completion of `drk` and `darkfid`.
 % echo source $(pwd)/contrib/auto-complete >> ~/.bashrc
 ```
 
-## Usage
-
-After the installation, you should have `drk` and `darkfid` binaries in
-`/usr/local`. Trying to run them once should place the configuration
-files in their respective path. Now we're ready to use the demo.
-
-In one terminal, start `darkfid`, which is the daemon that will
-communicate with the DarkFi network:
-
-```shell
-% darkfid -v
-```
-
-And in the other terminal, we can use the CLI interface to `darkfid`
-called `drk`:
-
-```
-% drk -h
-drk 0.2.0
-darkfi <dev@dark.fi>
-Anonymous. Uncensored. Sovereign.
-
-USAGE:
-    drk [OPTIONS] <SUBCOMMAND>
-
-OPTIONS:
-    -c, --config <CONFIG>    Sets a custom config file
-    -h, --help               Print help information
-    -v                       Increase verbosity
-    -V, --version            Print version information
-
-SUBCOMMANDS:
-    deposit     Deposit clear tokens for Dark tokens
-    features    Show what features the cashier supports
-    hello       Say hello to the RPC
-    help        Print this message or the help of the given subcommand(s)
-    id          Get hexidecimal ID for token symbol
-    transfer    Transfer Dark tokens to address
-    wallet      Wallet operations
-    withdraw    Withdraw Dark tokens for clear tokens
-```
-
-### Examples
+### Examples and usage
 
 See the [DarkFi book](https://darkrenaissance.github.io/darkfi)
 

+ 42 - 20
doc/src/architecture/anonymous_assets.md

@@ -1,20 +1,31 @@
 # Anonymous assets
 
-DarkFi network allows for the issuance and transfer of anonymous assets with an arbitrary number of parameters. These tokens are anonymous, relying on zero-knowledge proofs to ensure validity without revealing any other information.
+DarkFi network allows for the issuance and transfer of anonymous assets
+with an arbitrary number of parameters. These tokens are anonymous,
+relying on zero-knowledge proofs to ensure validity without revealing
+any other information.
 
-New tokens are created and destroyed every time you send an anonymous transaction. To send a transaction on DarkFi, you must first issue a credential that commits to some value you have in your wallet. This is called the **Mint** phase. Once the credential is spent, it destroys itself: what is called the **Burn.**
+New tokens are created and destroyed every time you send an anonymous
+transaction. To send a transaction on DarkFi, you must first issue a
+credential that commits to some value you have in your wallet. This is
+called the **Mint** phase. Once the credential is spent, it destroys
+itself: what is called the **Burn.**
 
 Through this process, the link between inputs and outputs is broken.
 
 ![](transaction.png)
 
-**Mint**
+## Mint
 
-During the **Mint** phase we create a new coin *C*, which is bound to the public key *P*. The coin *C* is publicly revealed on the blockchain and added to the merkle tree, which is stored locally on the DarkFi wallet.
+During the **Mint** phase we create a new coin $C$, which is bound
+to the public key $P$. The coin $C$ is publicly revealed on the
+blockchain and added to the merkle tree, which is stored locally on
+the DarkFi wallet.
 
 We do this using the following process:
 
-Let *v* be the coin's value. Generate random $r_C$, $r_V$ and serial $\rho$.
+Let $v$ be the coin's value. Generate random $r_C$, $r_V$ and serial
+$\rho$.
 
 Create a commitment to these parameters in zero-knowledge:
 
@@ -25,12 +36,15 @@ Check that the value commitment is constructed correctly:
 $$ v > 0 $$
 $$ V = v G_1 + r_V G_2 $$
 
-Reveal *C* and *V*. Add *C* to the merkle tree.  
+Reveal $C$ and $V$. Add $C$ to the Merkle tree.
 
-**Burn**
+## Burn
 
-When we spend the coin, we must ensure that the value of the coin cannot be double spent. We call this the *Burn* phase. The process relies on a *N* nullifier, which we create  using the secret key *x* for the public key *P*. Nullifier's are unique per coin and prevent double spending. 
-*R* is the merkle root. *v* is the coin's value.
+When we spend the coin, we must ensure that the value of the coin
+cannot be double spent. We call this the *Burn* phase. The process
+relies on a $N$ nullifier, which we create  using the secret key $x$
+for the public key $P$. Nullifiers are unique per coin and prevent
+double spending. $R$ is the Merkle root. $v$ is the coin's value.
 
 Generate a random number $r_V$.
 
@@ -40,32 +54,40 @@ Check that the secret key corresponds to a public key:
 
 $$ P = xG $$
 
-Check that the public key corresponds to a coin which is in the merkle tree *R*:
+Check that the public key corresponds to a coin which is in the merkle
+tree $R$:
 
 $$ C = H(P, v, \rho, r_C) $$
-$$ C \in R $$                                                                                                                                    
+$$ C \in R $$
 
 Check that the value commitment is constructed correctly:
 
 $$ v > 0 $$
 $$ V = v G_1 + r_V G_2 $$
 
-Reveal *N*, *V* and *R*. Check *R* is a valid merkle root. Check *N* does not exist in the nullifier set. 
+Reveal $N$, $V$ and $R$. Check $R$ is a valid Merkle root. Check $N$
+does not exist in the nullifier set.
 
-The zero-knowledge proof confirms that *N* binds to an unrevealed value *C*, and that this coin is in the merkle tree, without linking *N* to *C*.  Once the nullifier is produced the coin becomes unspendable.  
+The zero-knowledge proof confirms that $N$ binds to an unrevealed value
+$C$, and that this coin is in the Merkle tree, without linking $N$
+to $C$. Once the nullifier is produced the coin becomes unspendable.
 
-**Adding values**
+## Adding values
 
-Assets on DarkFi can have any number of values or attributes. This is achieved by creating a credential *C* and hashing any number of values and checking that they are valid in zero-knowledge.
+Assets on DarkFi can have any number of values or attributes. This
+is achieved by creating a credential $C$ and hashing any number of
+values and checking that they are valid in zero-knowledge.
 
-We check that the sum of the inputs equals the sum of the outputs. This means that:
+We check that the sum of the inputs equals the sum of the outputs. This
+means that:
 
 $$ B = \sum{V_{in}} - \sum{V_{out}} $$
 
-And that *B* is a valid point on the curve $G_2$.
+And that $B$ is a valid point on the curve $G_2$.
 
-This proves that $B = 0 G_1 + b G_2 = b G_2$ where *b* is a secret blinding factor for the amounts.
+This proves that $B = 0 G_1 + b G_2 = b G_2$ where $b$ is a secret
+blinding factor for the amounts.
 
-**Diagram**
+## Diagram
 
-![](diagram-dkzk.png)   
+![](diagram-dkzk.png)

+ 3 - 3
doc/src/learn/research.md

@@ -1,7 +1,8 @@
 # Research
 
-DarkFi maintains a public resource of zero-knowledge and math research at
-[script/research](../../../script/research).
+DarkFi maintains a public resource of zero-knowledge and math research
+in the [script/research](../../../script/research) directory of
+the repo.
 
 It features simple sage implementations of zero-knowledge algorithms
 and math primitives, including but not limited to:
@@ -12,4 +13,3 @@ and math primitives, including but not limited to:
 * [Bulletproofs](../../../script/research/bltprf)
 * [RSA accumulators](../../script/research/rsa_accum.sage)
 * [Finite fields](../../script/research/finite_fields)
-* [Pasta curves](../../script/research/pasta)

+ 67 - 34
doc/src/learn/zk_explainer.md

@@ -3,54 +3,67 @@
 We start with this algorithm as an example:
 
 ```python
-    def foo(w, a, b):
-        if w:
-            return a * b
-        else:
-            return a + b
+def foo(w, a, b):
+    if w:
+        return a * b
+    else:
+        return a + b
 ```
 
-ZK code consists of lines of constraints. It has no concept of branching conditionals or loops.
+ZK code consists of lines of constraints. It has no concept of
+branching conditionals or loops.
 
-So our first task is to flatten (convert) the above code to a linear equation that can be evaluated in ZK.
+So our first task is to flatten (convert) the above code to a linear
+equation that can be evaluated in ZK.
 
-Consider an interesting fact. For any value $\mathbb{x}$, then $(1 - w) = 0$ if and only if $x = 1$.
+Consider an interesting fact. For any value $\mathbb{x}$, then
+$(1 - w) = 0$ if and only if $x = 1$.
 
-In our code above $w$ is a binary value. It's value is either $1$ or $0$. We make use of this fact by the following:
+In our code above $w$ is a binary value. It's value is either $1$
+or $0$. We make use of this fact by the following:
 
 1. $w = 1$ when $w = 1$
 2. $(1 - w) = 1$ when $w = 0$. If $w = 1$ then the expression is $0$.
 
 So we can rewrite `foo(w, a, b)` as the mathematical function
+
 $$f(w, a, b) = w(ab) + (1 - w)(a + b)$$
 
 We now can convert this expression to a constraint system.
 
-ZK statements take the form of
+ZK statements take the form of:
 $$(c_{l,1} \cdot v_{l,1} + c_{a,2} \cdot v_{l,2} + \dots) \times (c_{b,1} \cdot v_{r,1} + c_{b,2} \cdot v_{r,2} + \dots) = (c_{o,1} \cdot v_{o,1} + c_{o,2} v_{o,2} + \dots)$$
-More succintly as
+
+More succintly as:
 $$\sum_{i = 1}^n c_{l,i} \cdot v_{l,i} \times \sum_{i = 1}^n c_{r,i} v_{r, i} = \sum_{i = 1}^n c_{o, i} v_{o, i}$$
-These statements are converted into polynomials of the form
+
+These statements are converted into polynomials of the form:
 $$L(x) \times R(x) - O(x) = t(x)h(x)$$
-$t(x)$ is the target polynomial and in our case will be $(x - 1)(x - 2)(x - 3)$. $h(x)$ is the cofactor polynomial. The statement says that the polynomial $L(x) \times R(x) - O(x)$ has roots (is equal to zero) at the points when $x \in {1, 2, 3}$.
 
-Earlier we wrote our mathematical statement which we will now convert to constraints.
+$t(x)$ is the target polynomial and in our case will be
+$(x - 1)(x - 2)(x - 3)$. $h(x)$ is the cofactor polynomial. The
+statement says that the polynomial $L(x) \times R(x) - O(x)$ has roots
+(is equal to zero) at the points when $x \in {1, 2, 3}$.
+
+Earlier we wrote our mathematical statement which we will now convert
+to constraints.
+
 $$f(w, a, b) = w(ab) + (1 - w)(a + b)$$
 
 Rearranging the equation, we note that:
-\begin{align*}
-v &= w(ab) + (1 - w)(a + b) \\
-  &= w(ab) + a + b - w(a + b) \\
-\end{align*}
 
-Swapping and rearranging, our final statement becomes $w(ab - a - b) = v - a - b$. Represented in ZK as:
-\begin{align*}
-ab &= m \\
-w(m - a - b) &= v - a - b \\
-w^2 &= w
-\end{align*}
+$$ v = w(ab) + (1 - w)(a + b) $$
+$$   = w(ab) + a + b - w(a + b) $$
 
-The last line is a boolean constraint that $w$ is either $0$ or $1$ by enforcing that $w(w - 1) = 0$ (re-arranged this is $w \cdot w = w$).
+Swapping and rearranging, our final statement becomes
+$w(ab - a - b) = v - a - b$. Represented in ZK as:
+
+$$ ab = m $$
+$$ w(m - a - b) = v - a - b $$
+$$ w^2 = w $$
+
+The last line is a boolean constraint that $w$ is either $0$ or $1$ by
+enforcing that $w(w - 1) = 0$ (re-arranged this is $w \cdot w = w$).
 
 | Line      | L(x)               | R(x)                                        | O(x)                                        |
 |-----------|--------------------|---------------------------------------------|---------------------------------------------|
@@ -58,22 +71,42 @@ The last line is a boolean constraint that $w$ is either $0$ or $1$ by enforcing
 | 2         | $(1 \cdot w)$      | $(1 \cdot m + (-1) \cdot a + (-1) \cdot b)$ | $(1 \cdot v + (-1) \cdot a + (-1) \cdot b)$ |
 | 3         | $(1 \cdot w)$      | $(1 \cdot w)$                               | $(1 \cdot w)$                               |
 
-Because of how the polynomials are created during the setup phase, you must supply them with the correct variables that satisfy these constraints, so that $L(1) \times R(1) - O(1) = 0$ (line 1), $L(2) \times R(2) - O(2) = 0$ (line 2) and $L(3) \times R(3) - O(3) = 0$ (line 3).
+Because of how the polynomials are created during the setup phase, you
+must supply them with the correct variables that satisfy these
+constraints, so that $L(1) \times R(1) - O(1) = 0$ (line 1),
+$L(2) \times R(2) - O(2) = 0$ (line 2) and
+$L(3) \times R(3) - O(3) = 0$ (line 3).
 
-Each one of $L(x)$, $R(x)$ and $O(x)$ is supplied a list of (constant coefficient, variable value) pairs.
+Each one of $L(x)$, $R(x)$ and $O(x)$ is supplied a list of
+(constant coefficient, variable value) pairs.
 
-In bellman library, the constant is a fixed value of type `Scalar`. The variable is a type called `Variable`. These are the values fed into `lc0` (the 'left' polynomial), `lc1` (the 'right' polynomial), and `lc2` (the 'out' polynomial).
+In bellman library, the constant is a fixed value of type `Scalar`.
+The variable is a type called `Variable`. These are the values fed
+into `lc0` (the 'left' polynomial), `lc1` (the 'right' polynomial),
+and `lc2` (the 'out' polynomial).
 
-In our example we had a function $f(w, a, b)$ where for example $f(1, 4, 2) = 8$. The verifier does not know the variables $w = 1$, $a = 4$ and $b = 2$ which are *allocated* by the prover as *variables*. However the verifier does know the coefficients (which are of the `Scalar` type) shown in the table above. In our example they only either $1$ or $-1$, but can also be other constant values.
+In our example we had a function $f(w, a, b)$ where for example $f(1, 4, 2) = 8$.
+The verifier does not know the variables $w = 1$, $a = 4$
+and $b = 2$ which are *allocated* by the prover as *variables*. However
+the verifier does know the coefficients (which are of the `Scalar`
+type) shown in the table above. In our example they only either $1$
+or $-1$, but can also be other constant values.
 
 ```rust
 pub struct LinearCombination<Scalar: PrimeField>(Vec<(Variable, Scalar)>);
 ```
 
-It is important to note that each one of the left, right and out registers is simply a list of tuples of (constant coefficient, variable value).
-
-When we wish to add a constant value, we use the variable called `~one` (which is always the first automatically allocated variable in bellman at index 0). Therefore we end up adding our constant $c$ to the `LinearCombination` as `(c, ~one)`.
-
-Any other non-constant value, we wish to add to our constaint system *must* be allocated as a variable. Then the variable is added to the `LinearCombination`. So in our example, we will allocate $w, a, b, m, v$, getting back `Variable` objects which we then add to the left lc, right lc or output lc.
+It is important to note that each one of the left, right and out
+registers is simply a list of tuples of (constant coefficient,
+variable value).
 
+When we wish to add a constant value, we use the variable called
+`~one` (which is always the first automatically allocated variable in
+bellman at index 0). Therefore we end up adding our constant $c$ to
+the `LinearCombination` as `(c, ~one)`.
 
+Any other non-constant value, we wish to add to our constaint system
+*must* be allocated as a variable. Then the variable is added to the
+`LinearCombination`. So in our example, we will allocate
+$w, a, b, m, v$, getting back `Variable` objects which we then add to
+the left lc, right lc or output lc.