Browse Source

Clean up some stuff in script/research

parazyd 3 years ago
parent
commit
b5be76738a
31 changed files with 4 additions and 3448 deletions
  1. 3 3
      Cargo.toml
  2. 0 338
      script/research/crypsinous/zk/plonk-by-hand/Cargo.lock
  3. 0 12
      script/research/crypsinous/zk/plonk-by-hand/Cargo.toml
  4. 0 334
      script/research/crypsinous/zk/plonk-by-hand/plonk.ipynb
  5. 0 401
      script/research/crypsinous/zk/plonk-by-hand/src/main.rs
  6. 0 2
      script/research/crypsinous_playground/.gitignore
  7. 0 36
      script/research/crypsinous_playground/Cargo.toml
  8. 0 16
      script/research/crypsinous_playground/crypsinous_playground_config.toml
  9. 0 137
      script/research/crypsinous_playground/src/main.rs
  10. 0 2
      script/research/merkletree_null_benchmark/.gitignore
  11. 0 19
      script/research/merkletree_null_benchmark/Cargo.toml
  12. 0 9
      script/research/merkletree_null_benchmark/benchmarks.md
  13. 0 402
      script/research/merkletree_null_benchmark/deserial_merkle_time.json
  14. 0 402
      script/research/merkletree_null_benchmark/deserial_null_time.json
  15. 0 42
      script/research/merkletree_null_benchmark/main.py
  16. BIN
      script/research/merkletree_null_benchmark/serial_desrial_merkle_time.png
  17. BIN
      script/research/merkletree_null_benchmark/serial_desrial_null_time.png
  18. 0 402
      script/research/merkletree_null_benchmark/serial_merkle_time.json
  19. 0 402
      script/research/merkletree_null_benchmark/serial_null_time.json
  20. 0 134
      script/research/merkletree_null_benchmark/src/main.rs
  21. 0 2
      script/research/pasta/.gitignore
  22. 0 18
      script/research/pasta/Cargo.toml
  23. 0 39
      script/research/pasta/main.rs
  24. 0 22
      script/research/pasta/vesta.sage
  25. 0 2
      script/research/rpc_client_notifications/.gitignore
  26. 0 15
      script/research/rpc_client_notifications/Cargo.toml
  27. 0 79
      script/research/rpc_client_notifications/src/main.rs
  28. 0 2
      script/research/state_usage_analyser/.gitignore
  29. 0 20
      script/research/state_usage_analyser/Cargo.toml
  30. 0 155
      script/research/state_usage_analyser/src/main.rs
  31. 1 1
      script/research/x3dh/Cargo.toml

+ 3 - 3
Cargo.toml

@@ -115,9 +115,9 @@ halo2_gadgets = {version = "0.2.0", optional = true}
 
 # Smart contract runtime
 darkfi-sdk = {path = "src/sdk", optional = true}
-wasmer = {version = "3.0.2", optional = true}
-wasmer-compiler-singlepass = {version = "3.0.2", optional = true}
-wasmer-middlewares = {version = "3.0.2", optional = true}
+wasmer = {version = "3.1.0", optional = true}
+wasmer-compiler-singlepass = {version = "3.1.0", optional = true}
+wasmer-middlewares = {version = "3.1.0", optional = true}
 
 # Wallet management
 libsqlite3-sys = {version = "0.24.2", features = ["bundled-sqlcipher"],  optional = true }

+ 0 - 338
script/research/crypsinous/zk/plonk-by-hand/Cargo.lock

@@ -1,338 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 3
-
-[[package]]
-name = "arrayref"
-version = "0.3.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
-
-[[package]]
-name = "arrayvec"
-version = "0.7.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
-
-[[package]]
-name = "autocfg"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
-
-[[package]]
-name = "bitvec"
-version = "0.22.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527"
-dependencies = [
- "funty",
- "radium",
- "tap",
- "wyz",
-]
-
-[[package]]
-name = "blake2b_simd"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127"
-dependencies = [
- "arrayref",
- "arrayvec",
- "constant_time_eq",
-]
-
-[[package]]
-name = "byteorder"
-version = "1.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
-
-[[package]]
-name = "cfg-if"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-
-[[package]]
-name = "constant_time_eq"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
-
-[[package]]
-name = "crossbeam-channel"
-version = "0.5.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
-dependencies = [
- "cfg-if",
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-deque"
-version = "0.8.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
-dependencies = [
- "cfg-if",
- "crossbeam-epoch",
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-epoch"
-version = "0.9.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
-dependencies = [
- "autocfg",
- "cfg-if",
- "crossbeam-utils",
- "lazy_static",
- "memoffset",
- "scopeguard",
-]
-
-[[package]]
-name = "crossbeam-utils"
-version = "0.8.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
-dependencies = [
- "cfg-if",
- "lazy_static",
-]
-
-[[package]]
-name = "either"
-version = "1.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
-
-[[package]]
-name = "ff"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2958d04124b9f27f175eaeb9a9f383d026098aa837eadd8ba22c11f13a05b9e"
-dependencies = [
- "bitvec",
- "rand_core",
- "subtle",
-]
-
-[[package]]
-name = "funty"
-version = "1.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e"
-
-[[package]]
-name = "getrandom"
-version = "0.2.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
-dependencies = [
- "cfg-if",
- "libc",
- "wasi",
-]
-
-[[package]]
-name = "group"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89"
-dependencies = [
- "byteorder",
- "ff",
- "rand_core",
- "subtle",
-]
-
-[[package]]
-name = "halo2"
-version = "0.1.0-beta.1"
-dependencies = [
- "blake2b_simd",
- "ff",
- "group",
- "pasta_curves",
- "rand",
- "rayon",
-]
-
-[[package]]
-name = "hermit-abi"
-version = "0.1.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
-dependencies = [
- "libc",
-]
-
-[[package]]
-name = "lazy_static"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
-
-[[package]]
-name = "libc"
-version = "0.2.121"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
-
-[[package]]
-name = "memoffset"
-version = "0.6.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
-dependencies = [
- "autocfg",
-]
-
-[[package]]
-name = "num_cpus"
-version = "1.13.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
-dependencies = [
- "hermit-abi",
- "libc",
-]
-
-[[package]]
-name = "pasta_curves"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "82b6fc4f73033f6aa52fdde0c38f1f570e7f2c244f22e441f62a144556891b8c"
-dependencies = [
- "blake2b_simd",
- "ff",
- "group",
- "lazy_static",
- "rand",
- "static_assertions",
- "subtle",
-]
-
-[[package]]
-name = "plonkbyhand"
-version = "0.1.0"
-dependencies = [
- "halo2",
-]
-
-[[package]]
-name = "ppv-lite86"
-version = "0.2.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
-
-[[package]]
-name = "radium"
-version = "0.6.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb"
-
-[[package]]
-name = "rand"
-version = "0.8.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
-dependencies = [
- "libc",
- "rand_chacha",
- "rand_core",
-]
-
-[[package]]
-name = "rand_chacha"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
-dependencies = [
- "ppv-lite86",
- "rand_core",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.6.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
-dependencies = [
- "getrandom",
-]
-
-[[package]]
-name = "rayon"
-version = "1.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
-dependencies = [
- "autocfg",
- "crossbeam-deque",
- "either",
- "rayon-core",
-]
-
-[[package]]
-name = "rayon-core"
-version = "1.9.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
-dependencies = [
- "crossbeam-channel",
- "crossbeam-deque",
- "crossbeam-utils",
- "lazy_static",
- "num_cpus",
-]
-
-[[package]]
-name = "scopeguard"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
-
-[[package]]
-name = "static_assertions"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
-
-[[package]]
-name = "subtle"
-version = "2.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
-
-[[package]]
-name = "tap"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
-
-[[package]]
-name = "wasi"
-version = "0.10.2+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
-
-[[package]]
-name = "wyz"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188"
-dependencies = [
- "tap",
-]
-
-[[patch.unused]]
-name = "halo2"
-version = "0.1.0-beta.2"
-source = "git+https://github.com/zcash/halo2?branch=main#084ecf185a89827fb68a8e4ef6e0e6a7aaac391f"

+ 0 - 12
script/research/crypsinous/zk/plonk-by-hand/Cargo.toml

@@ -1,12 +0,0 @@
-[package]
-name = "plonkbyhand"
-version = "0.3.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2021"
-
-[dependencies]
-halo2 = { path = "/opt/halo2" }
-
-[patch.crates-io]
-halo2 =  {git = "https://github.com/zcash/halo2", branch = "main"}

+ 0 - 334
script/research/crypsinous/zk/plonk-by-hand/plonk.ipynb

@@ -1,334 +0,0 @@
-{
- "cells": [
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# setup \n"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 41,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "# simple 101 group\n",
-    "F101 = IntegerModRing(101)"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 42,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "# define elliptic curve with coefficient 0(degree 1), 3(degree 0)\n",
-    "E = EllipticCurve(F101, [0,3])"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 43,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "# define polynomial ring on F101, then extended in Galois field\n",
-    "R.<X> = PolynomialRing(F101)\n",
-    "K.<X> = GF(101**2, modulus = x^2+2)\n",
-    "E2 = EllipticCurve(K, [0,3])\n",
-    "# EC generator at  (1,2)\n",
-    "G=E2([1,2])"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 44,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "# the order of G is r=17, the embedding degree it's the smallest k such that r|p^k -1, thus k=2\n",
-    "## if you keep adding G to itself, it would get only 17 unique values r=17\n",
-    "## group base p=101\n",
-    "G2 = E2([36,31*X])\n",
-    "# structured reference string SRS\n",
-    "## in kate commitment, here you create SRS, and release the toxic waste\n",
-    "## for random value rand=2\n",
-    "rand=2\n",
-    "G1_SRS = [(rand**i)*G for i in range(7)]\n",
-    "G2_SRS = [rand**i*G2 for i in range(2)]"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 45,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "N=G.order()\n",
-    "F17=Integers(N)\n",
-    "F17.square_roots_of_one()\n",
-    "# witness values for random [1,4,-1,-4]\n",
-    "w = vector(F17, [1,4,-1,-4])\n",
-    "w\n",
-    "k1=2; k2=3\n",
-    "k1*w\n",
-    "k2*w\n",
-    "A = matrix(F17, [[1**i for i in range (4)], [4**i for i in range (4)], [16**i for i in range(4)], [13**i for i in range(4)]])\n",
-    "Ai = A.inverse()"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 46,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "s=2\n",
-    "zeta=5\n",
-    "beta=12\n",
-    "gamma=13\n",
-    "vega=12\n",
-    "alpha = 15\n",
-    "ql_coef = [0,0,1,0] # multiplication a1*b1 : q left mulitplication coefficient for l+ r + m + c  = rhs\n",
-    "qr_coef = [0,0,1,0] # multiplication a2*b2'\n",
-    "qm_coef = [1,1,0,0] # addition gate a3+b3\n",
-    "qo_coef = [-1,-1,0,0] # ??\n",
-    "qc_coef = [0,0,-30,0] #??\n",
-    "P.<x> = F17[];x=P.0\n",
-    "ql = P(list(Ai*vector(F17, ql_coef)))\n",
-    "qr = P(list(Ai*vector(F17, qr_coef)))\n",
-    "qm = P(list(Ai*vector(F17, qm_coef)))\n",
-    "qo = P(list(Ai*vector(F17, qo_coef)))\n",
-    "qc = P(list(Ai*vector(F17, qc_coef)))\n",
-    "#public setup polynomials SRS are ql,qr,qm,qo,qc\n",
-    "ql,qr,qm,qo,qc\n",
-    "#\n",
-    "# equality constraints ??\n",
-    "sa = P(list(Ai*vector(F17, [2,3,12,13]))) # ??\n",
-    "sb = P(list(Ai*vector(F17, [1,15,8,9]))) # ??\n",
-    "sc = P(list(Ai*vector(F17, [4,16,14,5]))) # ?? \n",
-    "sa,sb,sc\n",
-    "# blinding values bld1-bld9\n",
-    "bld1=7\n",
-    "bld2=4\n",
-    "bld3=11\n",
-    "bld4=12\n",
-    "bld5=16\n",
-    "bld6=2\n",
-    "bld7=14\n",
-    "bld8=2\n",
-    "bld9=11"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# proving"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 57,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "def proving():\n",
-    "        ## for root 3, the following toxic waste coefficient are:\n",
-    "        a_coef = [3,9,27,0] # the left operands: a1,a2,a3,a5 \n",
-    "        b_coef = [3,3,3,0] # the right operands: b1,b2,b3,b5\n",
-    "        c_coef = [9,27,0,0] # the output: c1,c2,c3,c5\n",
-    "        fa = P(list(Ai*vector(F17, a_coef)))\n",
-    "        fb = P(list(Ai*vector(F17, b_coef)))\n",
-    "        fc = P(list(Ai*vector(F17, c_coef)))\n",
-    "        # solution polynomials are fa,fb,fc\n",
-    "        # round 1\n",
-    "        # target polynomial that vanishes at root of unity \n",
-    "        Z = x**4-1\n",
-    "        # random blinding values b1-b9 = [7,4,11,12,16,2]\n",
-    "        a = (bld1*x+bld2)*Z+fa\n",
-    "        b = (bld3*x+bld4)*Z+fb\n",
-    "        c = (bld5*x+bld6)*Z+fc\n",
-    "        ### choose s=2\n",
-    "        a_s = ZZ(a(s))*G\n",
-    "        b_s = ZZ(b(s))*G\n",
-    "        c_s = ZZ(c(s))*G\n",
-    "        p = (a_s,b_s,c_s)\n",
-    "        # round 2\n",
-    "        ### compute permutation challenges (beta,gamma) as hash of the transcript\n",
-    "        #for simplicity\n",
-    "        acc=1 #accumulator\n",
-    "        for i in range(4): #TODO parameterize number of gates\n",
-    "            nominator = ((a(w[i])+beta*w[i]+gamma)*(b(w[i])+beta*k1*w[i]+gamma)*(c(w[i])+beta*k2*w[i]+gamma))\n",
-    "            denominator = ((a(w[i])+beta*sa(w[i])+gamma)*(b(w[i])+beta*sb(w[i])+gamma)*(c(w[i])+beta*sc(w[i])+gamma))\n",
-    "            acc = acc*nominator/denominator\n",
-    "        acc=P(list(Ai*vector(F17,[1,12,10,1]))) #TODO parameterize\n",
-    "        Zx = (bld7*x**bld8+bld9*x+7)*Z+acc\n",
-    "        Z_s = ZZ(Zx(s))*G\n",
-    "        # round 3\n",
-    "        L=P(list(Ai*vector(F17, [1,0,0,0]))) #TODO parameterize\n",
-    "        t1Z = a*b*qm+a*ql+b*qr+c*qo+qc\n",
-    "        t2Z = (a+beta*x+gamma)*(b+k1*beta*x+gamma)*(c+k2*beta*x+gamma)*Zx*alpha\n",
-    "        Zw = Zx(w[1]*x)\n",
-    "        t3Z= -(a+beta*sa+gamma)*(b+beta*sb+gamma)*(c+beta*sc+gamma)*Zw*alpha\n",
-    "        t4Z = (Zx-1)*L*alpha**2\n",
-    "        tZ = t1Z+t2Z+t3Z+t4Z\n",
-    "        ## if everything goes well, then the following should divide without remainders\n",
-    "        t=P(tZ/Z)\n",
-    "        t_list = t.list()\n",
-    "        t_lo=t_list[0:6]\n",
-    "        t_mid=t_list[6:12]\n",
-    "        t_hi=t_list[12:]\n",
-    "        t_lo_s=ZZ(P(t_lo)(s))*G\n",
-    "        t_mid_s=ZZ(P(t_mid)(s))*G\n",
-    "        t_hi_s=ZZ(P(t_hi)(s))*G\n",
-    "        t_lo_s,t_mid_s,t_hi_s\n",
-    "        # Round 4\n",
-    "        a_=a(zeta)\n",
-    "        b_=b(zeta)\n",
-    "        c_=c(zeta)\n",
-    "        sa_=sa(zeta)\n",
-    "        sb_=sb(zeta)\n",
-    "        t_=t(zeta)\n",
-    "        zw_=Zx(zeta*w[1])\n",
-    "        l_=L(zeta)\n",
-    "        r1 = a_*b_*qm+a_*ql+b_*qr+c_*qo+qc\n",
-    "        r2 = ((a_+beta*zeta+gamma)*(b_+beta*k1*zeta+gamma)*(c_+beta*k2*zeta+gamma)*Zx)*alpha\n",
-    "        r3=-(a_+beta*sa_+gamma)*(b_+beta*sb_+gamma)*beta*zw_*sc*alpha\n",
-    "        r4=Zx*l_*alpha**2\n",
-    "        r=r1+r2+r3+r4\n",
-    "        r_=r(zeta)\n",
-    "        # Round 5\n",
-    "        v1 = P(t_lo)\n",
-    "        v2=zeta**6*P(t_mid)\n",
-    "        v3=zeta**12*P(t_hi)\n",
-    "        v4=-t_\n",
-    "        v5 = vega*(r-r_)+vega**2*(a-a_)+vega**3*(b-b_)+vega**4*(c-c_)+vega**5*(sa-sa_)+vega**6*(sb-sb_)\n",
-    "        W=v1+v2+v3+v4+v5\n",
-    "        ## opening proof polynomial\n",
-    "        Wz=W/(x-zeta)\n",
-    "        Wzw=(Zx-zw_)/(x-zeta*w[1])\n",
-    "        Wz_s=ZZ(Wz(s))*G\n",
-    "        Wzw_s=ZZ(Wzw(s))*G\n",
-    "        Wz_s,Wzw_s\n",
-    "        proof = (a_s,b_s,c_s,Z_s,t_lo_s,t_mid_s,t_hi_s,Wz_s,Wzw_s,a_,b_,c_,sa_,sb_,r_,zw_)\n",
-    "        return proof"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 58,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "a_s,b_s,c_s,Z_s,t_lo_s,t_mid_s,t_hi_s,Wz_s,Wzw_s,a_,b_,c_,sa_,sb_,r_,zw_ = proving()"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# verification"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 61,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "def verify():\n",
-    "    ## TODO (1) verify that all those points are in the curve G1\n",
-    "    ## TODO (2) verify that the bar values are part of Fp^7 group\n",
-    "    ## TODO (3) validate that w_i (roots of unity) are in F_p^l\n",
-    "    ### verifier processed input\n",
-    "    qm_s = ZZ(qm(s))*G\n",
-    "    ql_s = ZZ(ql(s))*G\n",
-    "    qr_s = ZZ(qr(s))*G\n",
-    "    qo_s = ZZ(qo(s))*G\n",
-    "    qc_s = ZZ(qc(s))*G\n",
-    "    sa_s = ZZ(sa(s))*G\n",
-    "    sb_s = ZZ(sb(s))*G\n",
-    "    sc_s = ZZ(sc(s))*G\n",
-    "    ## (4) compute challenges beta, gamma, alpha, zeta, veta, upsilon as in prover description from the common inputs, public input, and elements of zk-snark\n",
-    "    epsilon=4 # only this is missing\n",
-    "    ## (5) ZERO POLYNOMIAL EVALUATION\n",
-    "    Z_z=F17(zeta**4-1)\n",
-    "    ## (6) lagrange polynomial evaluation \n",
-    "    L1_z=F17((zeta**4-1)/(4*(zeta-1)))\n",
-    "    ## TODO(7) public input polynomial evaluation \n",
-    "    ## quotient polynomial evaluation\n",
-    "    t_=(r_-((a_+beta*sa_+gamma)*(b_+beta*sb_+gamma)*(c_+gamma)*zw_)*alpha-L1_z*alpha**2)/Z_z;t_\n",
-    "    ## (9) part of batched opynomimal commitment\n",
-    "    d1=ZZ(a_*b_*vega)*qm_s+ZZ(a_*vega)*ql_s+ZZ(b_*vega)*qr_s+ZZ(c_*vega)*qo_s+vega*qc_s\n",
-    "    d2=ZZ(((a_+beta*zeta+gamma)*(b_+beta*k1*zeta+gamma)*(c_+beta*k2*zeta+gamma)*alpha*vega)+L1_z*alpha**2*vega+F17(epsilon))*Z_s\n",
-    "    d3=-ZZ((a_+beta*sa_+gamma)*(b_+beta*sb_+gamma)*alpha*vega*beta*zw_)*sc_s\n",
-    "    d=d1+d2+d3;d\n",
-    "    ## (10) full batched polynomial commitment [F]1\n",
-    "    f=t_lo_s+zeta**6*t_mid_s+zeta**12*t_hi_s+d+vega**2*a_s+vega**3*b_s+vega**4*c_s+vega**5*sa_s+vega**6*sb_s\n",
-    "    ## (11) group-encoded batch evaluation [E]1\n",
-    "    e=ZZ((t_+vega*r_+vega**2*a_+vega**3*b_+vega**4*c_+vega**5*sa_+vega**6*sb_+epsilon*zw_))*G\n",
-    "    ## (12)\n",
-    "    x1=Wz_s+epsilon*Wzw_s\n",
-    "    x2=s*G2\n",
-    "    y1=zeta*Wz_s+ZZ(epsilon*zeta*w[1])*Wzw_s+f-e\n",
-    "    y2=G2\n",
-    "    x1_=E2(x1)\n",
-    "    x2_=E2(x2)\n",
-    "    y1_=E2(y1)\n",
-    "    y2_=E2(y2)\n",
-    "    return x1_.weil_pairing(x2_,17)==y1_.weil_pairing(y2_,17)\n"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 62,
-   "metadata": {},
-   "outputs": [],
-   "source": [
-    "assert(verify())"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "### references\n",
-    "[1] https://eprint.iacr.org/2019/953.pdf\n",
-    "\n",
-    "[2] https://research.metastate.dev/plonk-by-hand-part-1/\n",
-    "\n",
-    "[3] https://research.metastate.dev/plonk-by-hand-part-2-the-proof/\n"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": null,
-   "metadata": {},
-   "outputs": [],
-   "source": []
-  }
- ],
- "metadata": {
-  "kernelspec": {
-   "display_name": "SageMath 9.3",
-   "language": "sage",
-   "name": "sagemath"
-  },
-  "language_info": {
-   "codemirror_mode": {
-    "name": "ipython",
-    "version": 3
-   },
-   "file_extension": ".py",
-   "mimetype": "text/x-python",
-   "name": "python",
-   "nbconvert_exporter": "python",
-   "pygments_lexer": "ipython3",
-   "version": "3.7.10"
-  }
- },
- "nbformat": 4,
- "nbformat_minor": 4
-}

+ 0 - 401
script/research/crypsinous/zk/plonk-by-hand/src/main.rs

@@ -1,401 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use std::marker::PhantomData;
-
-use halo2::{
-    arithmetic::FieldExt,
-    circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner},
-    plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector},
-    poly::Rotation,
-};
-
-// ANCHOR: instructions
-trait NumericInstructions<F: FieldExt>: Chip<F> {
-    /// Variable representing a number.
-    type Num;
-
-    /// Loads a number into the circuit as a private input.
-    fn load_private(&self, layouter: impl Layouter<F>, a: Option<F>) -> Result<Self::Num, Error>;
-
-    /// Loads a number into the circuit as a fixed constant.
-    fn load_constant(&self, layouter: impl Layouter<F>, constant: F) -> Result<Self::Num, Error>;
-
-    /// Returns `c = a * b`.
-    fn mul(
-        &self,
-        layouter: impl Layouter<F>,
-        a: Self::Num,
-        b: Self::Num,
-    ) -> Result<Self::Num, Error>;
-
-    /// Returns `c = a + b`.
-    fn add(
-        &self,
-        layouter: impl Layouter<F>,
-        a: Self::Num,
-        b: Self::Num,
-    ) -> Result<Self::Num, Error>;
-
-    /// Exposes a number as a public input to the circuit.
-    fn expose_public(
-        &self,
-        layouter: impl Layouter<F>,
-        num: Self::Num,
-        row: usize,
-    ) -> Result<(), Error>;
-}
-// ANCHOR_END: instructions
-
-// ANCHOR: chip
-/// The chip that will implement our instructions! Chips store their own
-/// config, as well as type markers if necessary.
-struct FieldChip<F: FieldExt> {
-    config: FieldConfig,
-    _marker: PhantomData<F>,
-}
-// ANCHOR_END: chip
-
-// ANCHOR: chip-config
-/// Chip state is stored in a config struct. This is generated by the chip
-/// during configuration, and then stored inside the chip.
-#[derive(Clone, Debug)]
-struct FieldConfig {
-    /// For this chip, we will use two advice columns to implement our instructions.
-    /// These are also the columns through which we communicate with other parts of
-    /// the circuit.
-    advice: [Column<Advice>; 2],
-
-    /// This is the public input (instance) column.
-    instance: Column<Instance>,
-
-    // We need a selector to enable the multiplication gate, so that we aren't placing
-    // any constraints on cells where `NumericInstructions::mul` is not being used.
-    // This is important when building larger circuits, where columns are used by
-    // multiple sets of instructions.
-    s_mul: Selector,
-    s_add: Selector,
-}
-
-impl<F: FieldExt> FieldChip<F> {
-    fn construct(config: <Self as Chip<F>>::Config) -> Self {
-        Self {
-            config,
-            _marker: PhantomData,
-        }
-    }
-
-    fn configure(
-        meta: &mut ConstraintSystem<F>,
-        advice: [Column<Advice>; 2],
-        instance: Column<Instance>,
-        constant: Column<Fixed>,
-    ) -> <Self as Chip<F>>::Config {
-        meta.enable_equality(instance);
-        meta.enable_constant(constant);
-        for column in &advice {
-            meta.enable_equality(*column);
-        }
-        let s_mul = meta.selector();
-        let s_add = meta.selector();
-        // Define our multiplication gate!
-        meta.create_gate("mul", |meta| {
-            // To implement multiplication, we need three advice cells and a selector
-            // cell. We arrange them like so:
-            //
-            // | a0  | a1  | s_mul |
-            // |-----|-----|-------|
-            // | lhs | rhs | s_mul |
-            // | out |     |       |
-            //
-            // Gates may refer to any relative offsets we want, but each distinct
-            // offset adds a cost to the proof. The most common offsets are 0 (the
-            // current row), 1 (the next row), and -1 (the previous row), for which
-            // `Rotation` has specific constructors.
-            let lhs = meta.query_advice(advice[0], Rotation::cur());
-            let rhs = meta.query_advice(advice[1], Rotation::cur());
-            let out = meta.query_advice(advice[0], Rotation::next());
-            let s_mul = meta.query_selector(s_mul);
-
-            // Finally, we return the polynomial expressions that constrain this gate.
-            // For our multiplication gate, we only need a single polynomial constraint.
-            //
-            // The polynomial expressions returned from `create_gate` will be
-            // constrained by the proving system to equal zero. Our expression
-            // has the following properties:
-            // - When s_mul = 0, any value is allowed in lhs, rhs, and out.
-            // - When s_mul != 0, this constrains lhs * rhs = out.
-            vec![s_mul * (lhs * rhs - out)]
-        });
-
-
-        // Define our addition gate!
-        meta.create_gate("add", |meta| {
-            let lhs = meta.query_advice(advice[0], Rotation::cur());
-            let rhs = meta.query_advice(advice[1], Rotation::cur());
-            let out = meta.query_advice(advice[0], Rotation::next());
-            let s_add = meta.query_selector(s_add);
-
-            vec![s_add * (lhs + rhs - out)]
-        });
-
-        FieldConfig {
-            advice,
-            instance,
-            s_mul,
-            s_add,
-        }
-    }
-}
-// ANCHOR_END: chip-config
-
-// ANCHOR: chip-impl
-impl<F: FieldExt> Chip<F> for FieldChip<F> {
-    type Config = FieldConfig;
-    type Loaded = ();
-
-    fn config(&self) -> &Self::Config {
-        &self.config
-    }
-
-    fn loaded(&self) -> &Self::Loaded {
-        &()
-    }
-}
-// ANCHOR_END: chip-impl
-
-// ANCHOR: instructions-impl
-/// A variable representing a number.
-#[derive(Clone)]
-struct Number<F: FieldExt>(AssignedCell<F, F>);
-
-impl<F: FieldExt> NumericInstructions<F> for FieldChip<F> {
-    type Num = Number<F>;
-
-    fn load_private(
-        &self,
-        mut layouter: impl Layouter<F>,
-        value: Option<F>,
-    ) -> Result<Self::Num, Error> {
-        let config = self.config();
-
-        layouter.assign_region(
-            || "load private",
-            |mut region| {
-                region
-                    .assign_advice(
-                        || "private input",
-                        config.advice[0],
-                        0,
-                        || value.ok_or(Error::Synthesis),
-                    )
-                    .map(Number)
-            },
-        )
-    }
-
-    fn load_constant(
-        &self,
-        mut layouter: impl Layouter<F>,
-        constant: F,
-    ) -> Result<Self::Num, Error> {
-        let config = self.config();
-
-        layouter.assign_region(
-            || "load constant",
-            |mut region| {
-                region
-                    .assign_advice_from_constant(|| "constant value", config.advice[0], 0, constant)
-                    .map(Number)
-            },
-        )
-    }
-
-    fn mul(
-        &self,
-        mut layouter: impl Layouter<F>,
-        a: Self::Num,
-        b: Self::Num,
-    ) -> Result<Self::Num, Error> {
-        let config = self.config();
-
-        layouter.assign_region(
-            || "mul",
-            |mut region: Region<'_, F>| {
-                // We only want to use a single multiplication gate in this region,
-                // so we enable it at region offset 0; this means it will constrain
-                // cells at offsets 0 and 1.
-                config.s_mul.enable(&mut region, 0)?;
-
-                // The inputs we've been given could be located anywhere in the circuit,
-                // but we can only rely on relative offsets inside this region. So we
-                // assign new cells inside the region and constrain them to have the
-                // same values as the inputs.
-                a.0.copy_advice(|| "lhs", &mut region, config.advice[0], 0)?;
-                b.0.copy_advice(|| "rhs", &mut region, config.advice[1], 0)?;
-
-                // Now we can assign the multiplication result, which is to be assigned
-                // into the output position.
-                let value = a.0.value().and_then(|a| b.0.value().map(|b| *a * *b));
-
-                // Finally, we do the assignment to the output, returning a
-                // variable to be used in another part of the circuit.
-                region
-                    .assign_advice(
-                        || "lhs * rhs",
-                        config.advice[0],
-                        1,
-                        || value.ok_or(Error::Synthesis),
-                    )
-                    .map(Number)
-            },
-        )
-    }
-
-    fn add(
-        &self,
-        mut layouter: impl Layouter<F>,
-        a: Self::Num,
-        b: Self::Num,
-    ) -> Result<Self::Num, Error> {
-        let config = self.config();
-
-        layouter.assign_region(
-            || "add",
-            |mut region: Region<'_, F>| {
-                // We only want to use a single multiplication gate in this region
-                // so we enable it at region offset 0; this means it will constrain
-                // cells at offsets 0 and 1.
-                config.s_add.enable(&mut region, 0)?;
-
-                //
-                //The inputs we've been given could be located anywhere in the circuit,
-                // but we can only rely on relative offsets inside this region. So we
-                // assign new cells inside the region and constrain them to have the
-                // same values as the inputs.
-                a.0.copy_advice(|| "lhs", &mut region, config.advice[0], 0)?;
-                b.0.copy_advice(|| "rhs", &mut region, config.advice[1], 0)?;
-
-                // Now we can assign the multiplication result, which is to be assigned
-                // into the output position.
-                let value = a.0.value().and_then(|a| b.0.value().map(|b| *a + *b));
-
-                // Finally, we do the assignment to the output, returning a
-                // variable to be used in another part of the circuit.
-                region
-                    .assign_advice(
-                        || "lhs + rhs",
-                        config.advice[0],
-                        1,
-                        || value.ok_or(Error::Synthesis),
-                    )
-                    .map(Number)
-            },
-        )
-    }
-
-    fn expose_public(
-        &self,
-        mut layouter: impl Layouter<F>,
-        num: Self::Num,
-        row: usize,
-    ) -> Result<(), Error> {
-        let config = self.config();
-
-        layouter.constrain_instance(num.0.cell(), config.instance, row)
-    }
-}
-
-#[derive(Default)]
-struct MyCircuit<F: FieldExt> {
-    constant: F,
-    x:Option<F>,
-}
-
-
-impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
-    // Since we are using a single chip for everything, we can just reuse its config.
-    type Config = FieldConfig;
-    type FloorPlanner = SimpleFloorPlanner;
-
-    fn without_witnesses(&self) -> Self {
-        Self::default()
-    }
-
-    fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
-        // We create the two advice columns that FieldChip uses for I/O.
-        let advice = [meta.advice_column(), meta.advice_column()];
-
-        // We also need an instance column to store public inputs.
-        let instance = meta.instance_column();
-
-        // Create a fixed column to load constants.
-        let constant = meta.fixed_column();
-
-        FieldChip::configure(meta, advice, instance, constant)
-    }
-
-    fn synthesize(
-        &self,
-        config: Self::Config,
-        mut layouter: impl Layouter<F>,
-    ) -> Result<(), Error> {
-        let field_chip = FieldChip::<F>::construct(config);
-
-        // Load our private values into the circuit.
-        let x = field_chip.load_private(layouter.namespace(|| "load x"), self.x)?;
-
-        // Load the constant factor into the circuit.
-        let constant = field_chip.load_constant(layouter.namespace(|| "load constant"), self.constant)?;
-
-        let x2 = field_chip.mul(layouter.namespace(|| "x * x"), x.clone(), x.clone())?;
-        let x3 = field_chip.mul(layouter.namespace(|| "x * x * x"), x2, x.clone())?;
-        let x3x = field_chip.add(layouter.namespace(|| " x3+x"), x3.clone(), x.clone())?;
-        let c = field_chip.add(layouter.namespace(|| "x3 + x"), constant, x3x)?;
-
-        // Expose the result as a public input to the circuit.
-        field_chip.expose_public(layouter.namespace(|| "expose c"), c, 0)
-    }
-}
-// ANCHOR_END: circuit
-
-fn main() {
-    use halo2::{dev::MockProver, pasta::Fp};
-
-    let k = 4;
-    let x = Fp::from(3);
-    let constant = Fp::from(5);
-    //let c = x*x*x  - constant; // to be x^3+x-5=30 need to implement addition in the chip
-    let c = x*x*x + x + constant; // * constant; // to be x^3+x-5=30 need to implement addition in the chip
-    let circuit = MyCircuit {
-        constant,
-        x: Some(x),
-    };
-
-    // Arrange the public input. We expose the multiplication result in row 0
-    // of the instance column, so we position it there in our public inputs.
-    let mut public_inputs = vec![c];
-
-    // Given the correct public input, our circuit will verify.
-    let prover = MockProver::run(k, &circuit, vec![public_inputs.clone()]).unwrap();
-    assert_eq!(prover.verify(), Ok(()));
-
-    public_inputs[0]  += Fp::one();
-    let prover = MockProver::run(k, &circuit, vec![public_inputs]).unwrap();
-    assert!(prover.verify().is_err());
-}

+ 0 - 2
script/research/crypsinous_playground/.gitignore

@@ -1,2 +0,0 @@
-/target
-Cargo.lock

+ 0 - 36
script/research/crypsinous_playground/Cargo.toml

@@ -1,36 +0,0 @@
-[package]
-name = "crypsinous_playground"
-version = "0.1.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2021"
-
-[workspace]
-
-[dependencies]
-darkfi = {path = "../../../", features = ["crypto", "node"]}
-darkfi-sdk = {path = "../../../src/sdk"}
-dashu = { version = "0.2.0", git = "https://github.com/ertosns/dashu" }
-halo2_gadgets = "0.2.0"
-halo2_proofs = "0.2.0"
-incrementalmerkletree = "0.3.0"
-pasta_curves = "0.4.1"
-
-# Async
-async-std = "1.12.0"
-async-trait = "0.1.59"
-ctrlc = { version = "3.2.4", features = ["termination"] }
-easy-parallel = "3.2.0"
-smol = "1.3.0"
-
-# Argument parsing
-serde = "1.0.150"
-serde_derive = "1.0.150"
-structopt = "0.3.26"
-structopt-toml = "0.5.1"
-
-# Misc
-blake3 = "1.3.3"
-log = "0.4.17"
-simplelog = "0.12.0"
-rand = "0.8.5"

+ 0 - 16
script/research/crypsinous_playground/crypsinous_playground_config.toml

@@ -1,16 +0,0 @@
-## crypsinous_playground configuration file
-##
-## Please make sure you go through all the settings so you can configure
-## your daemon properly.
-##
-## The default values are left commented. They can be overridden either by
-## uncommenting, or by using the command-line.
-
-# Path to the wallet database
-#wallet_path = "~/.config/darkfi/crypsinous_playground/wallet.db"
-
-# Password for the wallet database
-#wallet_pass = "changeme"
-
-# How many epochs to simulate
-#epochs = 1

+ 0 - 137
script/research/crypsinous_playground/src/main.rs

@@ -1,137 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use async_std::sync::Arc;
-use log::{error, info};
-use pasta_curves::pallas;
-use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
-
-use darkfi::{
-    async_daemonize, cli_desc,
-    consensus::coins,
-    crypto::{
-        lead_proof,
-        proof::{ProvingKey, VerifyingKey},
-    },
-    node::Client,
-    wallet::walletdb::init_wallet,
-    zk::circuit::LeadContract,
-    Result,
-};
-
-const CONFIG_FILE: &str = "crypsinous_playground_config.toml";
-const CONFIG_FILE_CONTENTS: &str = include_str!("../crypsinous_playground_config.toml");
-
-#[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
-#[serde(default)]
-#[structopt(name = "crypsinous_playground", about = cli_desc!())]
-struct Args {
-    #[structopt(short, long)]
-    /// Configuration file to use
-    config: Option<String>,
-
-    #[structopt(long, default_value = "~/.config/darkfi/crypsinous_playground/wallet.db")]
-    /// Path to wallet database
-    wallet_path: String,
-
-    #[structopt(long, default_value = "changeme")]
-    /// Password for the wallet database
-    wallet_pass: String,
-
-    #[structopt(short, default_value = "1")]
-    /// How many epochs to simulate
-    epochs: u64,
-
-    #[structopt(short, parse(from_occurrences))]
-    /// Increase verbosity (-vvv supported)
-    verbose: u8,
-}
-
-// The porpuse of this script is to simulate a staker actions through an epoch.
-// Main focus is the crypsinous lottery mechanism and the leader proof creation and validation.
-// Other flows that happen through a slot, like broadcasting blocks or syncing are out of scope.
-async_daemonize!(realmain);
-async fn realmain(args: Args, _ex: Arc<smol::Executor<'_>>) -> Result<()>  {
-
-    // Epochs sanity check
-    let epochs = args.epochs;
-    if epochs < 1 {
-        error!("Epochs must be a positive number.");
-        return Ok(());
-    }
-    info!("Simulation epochs: {}", epochs);
-
-    // Initialize wallet that holds coins for staking
-    let wallet = init_wallet(&args.wallet_path, &args.wallet_pass).await?;
-
-    // Initialize client
-    let client = Arc::new(Client::new(wallet.clone()).await?);
-
-    // Retrieving nodes wallet coins
-    let mut owned = client.get_own_coins().await?;
-    // If node holds no coins in its wallet, we generate some new staking coins
-    if owned.is_empty() {
-        info!("Node wallet is empty, generating new staking coins...");
-        owned = coins::generate_staking_coins(&wallet).await?;
-    }
-    // If we want to test what will happen if node holds 0 coins, uncomment the below line
-    // owned = vec![];
-    info!("Node coins: {:?}", owned);
-
-    // Generating leader proof keys
-    let k: u32 = 11; // Proof rows number
-    info!("Generating proof keys with k: {}", k);
-    let proving_key = ProvingKey::build(k, &LeadContract::default());
-    let verifying_key = VerifyingKey::build(k, &LeadContract::default());
-
-    // Simulating epochs with 10 slots
-    for epoch in 0..epochs {
-        info!("Epoch {} started!", epoch);
-        // Generating epoch coins
-        // TODO: Retrieve previous lead proof
-        let eta = pallas::Base::one();
-        let epoch_coins = coins::create_epoch_coins(eta, &owned, epoch, 0);
-        info!("Generated epoch_coins: {}", epoch_coins.len());
-        for slot in 0..10 {
-            // Checking if slot leader
-            info!("Slot {} started!", slot);
-            let (won, idx) = coins::is_leader(slot, &epoch_coins);
-            info!("Lottery outcome: {}", won);
-            if !won {
-                continue
-            }
-            // TODO: Generate rewards transaction
-            info!("Winning coin index: {}", idx);
-            // Generating leader proof
-            let coin = epoch_coins[slot as usize][idx];
-            let proof = lead_proof::create_lead_proof(&proving_key, coin);
-            if proof.is_err() {
-                error!("Error during leader proof creation: {}", proof.err().unwrap());
-                continue
-            }
-            //Verifying generated proof against winning coin public inputs
-            info!("Leader proof generated successfully, veryfing...");
-            match lead_proof::verify_lead_proof(&verifying_key, &proof.unwrap(), &coin.public_inputs()) {
-                Ok(_) => info!("Proof veryfied succsessfully!"),
-                Err(e) => error!("Error during leader proof verification: {}", e),
-            }
-        }
-    }
-
-    Ok(())
-}

+ 0 - 2
script/research/merkletree_null_benchmark/.gitignore

@@ -1,2 +0,0 @@
-/target
-Cargo.lock

+ 0 - 19
script/research/merkletree_null_benchmark/Cargo.toml

@@ -1,19 +0,0 @@
-[package]
-name = "merkletree_null_benchmark"
-version = "0.1.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2021"
-
-[workspace]
-
-[dependencies]
-darkfi = {path="../../../", features=["node"]}
-darkfi-sdk = {path="../../../src/sdk"}
-darkfi-serial = {path="../../../src/serial"}
-
-rand = "0.8.5"
-pasta_curves = "0.4.1"
-incrementalmerkletree = "0.3.0"
-
-serde_json = "1.0.89"

+ 0 - 9
script/research/merkletree_null_benchmark/benchmarks.md

@@ -1,9 +0,0 @@
-
-# Benchmarks
-
-# Merkle Tree
-![serialize desrialize merkle tree](./serial_desrial_merkle_time.png)
-
-# Nullifiers
-![serialize desrialize nullifiers](./serial_desrial_null_time.png)
-

+ 0 - 402
script/research/merkletree_null_benchmark/deserial_merkle_time.json

@@ -1,402 +0,0 @@
-{
-  "1000": {
-    "nanos": 520,
-    "secs": 0
-  },
-  "10000": {
-    "nanos": 528,
-    "secs": 0
-  },
-  "100000": {
-    "nanos": 635,
-    "secs": 0
-  },
-  "11000": {
-    "nanos": 676,
-    "secs": 0
-  },
-  "12000": {
-    "nanos": 878,
-    "secs": 0
-  },
-  "13000": {
-    "nanos": 535,
-    "secs": 0
-  },
-  "14000": {
-    "nanos": 607,
-    "secs": 0
-  },
-  "15000": {
-    "nanos": 553,
-    "secs": 0
-  },
-  "16000": {
-    "nanos": 699,
-    "secs": 0
-  },
-  "17000": {
-    "nanos": 515,
-    "secs": 0
-  },
-  "18000": {
-    "nanos": 661,
-    "secs": 0
-  },
-  "19000": {
-    "nanos": 565,
-    "secs": 0
-  },
-  "2000": {
-    "nanos": 546,
-    "secs": 0
-  },
-  "20000": {
-    "nanos": 576,
-    "secs": 0
-  },
-  "21000": {
-    "nanos": 459,
-    "secs": 0
-  },
-  "22000": {
-    "nanos": 714,
-    "secs": 0
-  },
-  "23000": {
-    "nanos": 658,
-    "secs": 0
-  },
-  "24000": {
-    "nanos": 739,
-    "secs": 0
-  },
-  "25000": {
-    "nanos": 587,
-    "secs": 0
-  },
-  "26000": {
-    "nanos": 612,
-    "secs": 0
-  },
-  "27000": {
-    "nanos": 668,
-    "secs": 0
-  },
-  "28000": {
-    "nanos": 680,
-    "secs": 0
-  },
-  "29000": {
-    "nanos": 570,
-    "secs": 0
-  },
-  "3000": {
-    "nanos": 570,
-    "secs": 0
-  },
-  "30000": {
-    "nanos": 673,
-    "secs": 0
-  },
-  "31000": {
-    "nanos": 603,
-    "secs": 0
-  },
-  "32000": {
-    "nanos": 1231,
-    "secs": 0
-  },
-  "33000": {
-    "nanos": 758,
-    "secs": 0
-  },
-  "34000": {
-    "nanos": 528,
-    "secs": 0
-  },
-  "35000": {
-    "nanos": 542,
-    "secs": 0
-  },
-  "36000": {
-    "nanos": 613,
-    "secs": 0
-  },
-  "37000": {
-    "nanos": 471,
-    "secs": 0
-  },
-  "38000": {
-    "nanos": 606,
-    "secs": 0
-  },
-  "39000": {
-    "nanos": 507,
-    "secs": 0
-  },
-  "4000": {
-    "nanos": 588,
-    "secs": 0
-  },
-  "40000": {
-    "nanos": 619,
-    "secs": 0
-  },
-  "41000": {
-    "nanos": 437,
-    "secs": 0
-  },
-  "42000": {
-    "nanos": 497,
-    "secs": 0
-  },
-  "43000": {
-    "nanos": 684,
-    "secs": 0
-  },
-  "44000": {
-    "nanos": 657,
-    "secs": 0
-  },
-  "45000": {
-    "nanos": 650,
-    "secs": 0
-  },
-  "46000": {
-    "nanos": 675,
-    "secs": 0
-  },
-  "47000": {
-    "nanos": 653,
-    "secs": 0
-  },
-  "48000": {
-    "nanos": 729,
-    "secs": 0
-  },
-  "49000": {
-    "nanos": 672,
-    "secs": 0
-  },
-  "5000": {
-    "nanos": 483,
-    "secs": 0
-  },
-  "50000": {
-    "nanos": 604,
-    "secs": 0
-  },
-  "51000": {
-    "nanos": 619,
-    "secs": 0
-  },
-  "52000": {
-    "nanos": 636,
-    "secs": 0
-  },
-  "53000": {
-    "nanos": 551,
-    "secs": 0
-  },
-  "54000": {
-    "nanos": 631,
-    "secs": 0
-  },
-  "55000": {
-    "nanos": 663,
-    "secs": 0
-  },
-  "56000": {
-    "nanos": 676,
-    "secs": 0
-  },
-  "57000": {
-    "nanos": 705,
-    "secs": 0
-  },
-  "58000": {
-    "nanos": 594,
-    "secs": 0
-  },
-  "59000": {
-    "nanos": 649,
-    "secs": 0
-  },
-  "6000": {
-    "nanos": 599,
-    "secs": 0
-  },
-  "60000": {
-    "nanos": 670,
-    "secs": 0
-  },
-  "61000": {
-    "nanos": 589,
-    "secs": 0
-  },
-  "62000": {
-    "nanos": 585,
-    "secs": 0
-  },
-  "63000": {
-    "nanos": 637,
-    "secs": 0
-  },
-  "64000": {
-    "nanos": 753,
-    "secs": 0
-  },
-  "65000": {
-    "nanos": 745,
-    "secs": 0
-  },
-  "66000": {
-    "nanos": 543,
-    "secs": 0
-  },
-  "67000": {
-    "nanos": 549,
-    "secs": 0
-  },
-  "68000": {
-    "nanos": 568,
-    "secs": 0
-  },
-  "69000": {
-    "nanos": 903,
-    "secs": 0
-  },
-  "7000": {
-    "nanos": 570,
-    "secs": 0
-  },
-  "70000": {
-    "nanos": 625,
-    "secs": 0
-  },
-  "71000": {
-    "nanos": 551,
-    "secs": 0
-  },
-  "72000": {
-    "nanos": 635,
-    "secs": 0
-  },
-  "73000": {
-    "nanos": 568,
-    "secs": 0
-  },
-  "74000": {
-    "nanos": 475,
-    "secs": 0
-  },
-  "75000": {
-    "nanos": 635,
-    "secs": 0
-  },
-  "76000": {
-    "nanos": 619,
-    "secs": 0
-  },
-  "77000": {
-    "nanos": 592,
-    "secs": 0
-  },
-  "78000": {
-    "nanos": 603,
-    "secs": 0
-  },
-  "79000": {
-    "nanos": 584,
-    "secs": 0
-  },
-  "8000": {
-    "nanos": 665,
-    "secs": 0
-  },
-  "80000": {
-    "nanos": 702,
-    "secs": 0
-  },
-  "81000": {
-    "nanos": 638,
-    "secs": 0
-  },
-  "82000": {
-    "nanos": 489,
-    "secs": 0
-  },
-  "83000": {
-    "nanos": 535,
-    "secs": 0
-  },
-  "84000": {
-    "nanos": 533,
-    "secs": 0
-  },
-  "85000": {
-    "nanos": 494,
-    "secs": 0
-  },
-  "86000": {
-    "nanos": 1023,
-    "secs": 0
-  },
-  "87000": {
-    "nanos": 683,
-    "secs": 0
-  },
-  "88000": {
-    "nanos": 761,
-    "secs": 0
-  },
-  "89000": {
-    "nanos": 653,
-    "secs": 0
-  },
-  "9000": {
-    "nanos": 474,
-    "secs": 0
-  },
-  "90000": {
-    "nanos": 746,
-    "secs": 0
-  },
-  "91000": {
-    "nanos": 645,
-    "secs": 0
-  },
-  "92000": {
-    "nanos": 720,
-    "secs": 0
-  },
-  "93000": {
-    "nanos": 874,
-    "secs": 0
-  },
-  "94000": {
-    "nanos": 1234,
-    "secs": 0
-  },
-  "95000": {
-    "nanos": 654,
-    "secs": 0
-  },
-  "96000": {
-    "nanos": 796,
-    "secs": 0
-  },
-  "97000": {
-    "nanos": 695,
-    "secs": 0
-  },
-  "98000": {
-    "nanos": 1033,
-    "secs": 0
-  },
-  "99000": {
-    "nanos": 602,
-    "secs": 0
-  }
-}

+ 0 - 402
script/research/merkletree_null_benchmark/deserial_null_time.json

@@ -1,402 +0,0 @@
-{
-  "1000": {
-    "nanos": 55418,
-    "secs": 0
-  },
-  "10000": {
-    "nanos": 454002,
-    "secs": 0
-  },
-  "100000": {
-    "nanos": 4271029,
-    "secs": 0
-  },
-  "11000": {
-    "nanos": 466540,
-    "secs": 0
-  },
-  "12000": {
-    "nanos": 631768,
-    "secs": 0
-  },
-  "13000": {
-    "nanos": 563309,
-    "secs": 0
-  },
-  "14000": {
-    "nanos": 874443,
-    "secs": 0
-  },
-  "15000": {
-    "nanos": 703812,
-    "secs": 0
-  },
-  "16000": {
-    "nanos": 635922,
-    "secs": 0
-  },
-  "17000": {
-    "nanos": 698253,
-    "secs": 0
-  },
-  "18000": {
-    "nanos": 786894,
-    "secs": 0
-  },
-  "19000": {
-    "nanos": 1132017,
-    "secs": 0
-  },
-  "2000": {
-    "nanos": 122463,
-    "secs": 0
-  },
-  "20000": {
-    "nanos": 859992,
-    "secs": 0
-  },
-  "21000": {
-    "nanos": 832009,
-    "secs": 0
-  },
-  "22000": {
-    "nanos": 1064128,
-    "secs": 0
-  },
-  "23000": {
-    "nanos": 1370178,
-    "secs": 0
-  },
-  "24000": {
-    "nanos": 1153108,
-    "secs": 0
-  },
-  "25000": {
-    "nanos": 1104906,
-    "secs": 0
-  },
-  "26000": {
-    "nanos": 1147885,
-    "secs": 0
-  },
-  "27000": {
-    "nanos": 1128384,
-    "secs": 0
-  },
-  "28000": {
-    "nanos": 1148660,
-    "secs": 0
-  },
-  "29000": {
-    "nanos": 1210717,
-    "secs": 0
-  },
-  "3000": {
-    "nanos": 148279,
-    "secs": 0
-  },
-  "30000": {
-    "nanos": 1739851,
-    "secs": 0
-  },
-  "31000": {
-    "nanos": 1435411,
-    "secs": 0
-  },
-  "32000": {
-    "nanos": 1354423,
-    "secs": 0
-  },
-  "33000": {
-    "nanos": 1589283,
-    "secs": 0
-  },
-  "34000": {
-    "nanos": 1476268,
-    "secs": 0
-  },
-  "35000": {
-    "nanos": 1480049,
-    "secs": 0
-  },
-  "36000": {
-    "nanos": 1832580,
-    "secs": 0
-  },
-  "37000": {
-    "nanos": 1687130,
-    "secs": 0
-  },
-  "38000": {
-    "nanos": 1856885,
-    "secs": 0
-  },
-  "39000": {
-    "nanos": 1649066,
-    "secs": 0
-  },
-  "4000": {
-    "nanos": 237787,
-    "secs": 0
-  },
-  "40000": {
-    "nanos": 1687916,
-    "secs": 0
-  },
-  "41000": {
-    "nanos": 1784021,
-    "secs": 0
-  },
-  "42000": {
-    "nanos": 1939604,
-    "secs": 0
-  },
-  "43000": {
-    "nanos": 1982332,
-    "secs": 0
-  },
-  "44000": {
-    "nanos": 2043983,
-    "secs": 0
-  },
-  "45000": {
-    "nanos": 2103901,
-    "secs": 0
-  },
-  "46000": {
-    "nanos": 2006225,
-    "secs": 0
-  },
-  "47000": {
-    "nanos": 2275498,
-    "secs": 0
-  },
-  "48000": {
-    "nanos": 2416770,
-    "secs": 0
-  },
-  "49000": {
-    "nanos": 2570104,
-    "secs": 0
-  },
-  "5000": {
-    "nanos": 231111,
-    "secs": 0
-  },
-  "50000": {
-    "nanos": 2106829,
-    "secs": 0
-  },
-  "51000": {
-    "nanos": 2064148,
-    "secs": 0
-  },
-  "52000": {
-    "nanos": 2303774,
-    "secs": 0
-  },
-  "53000": {
-    "nanos": 2258760,
-    "secs": 0
-  },
-  "54000": {
-    "nanos": 2246807,
-    "secs": 0
-  },
-  "55000": {
-    "nanos": 2355410,
-    "secs": 0
-  },
-  "56000": {
-    "nanos": 2476287,
-    "secs": 0
-  },
-  "57000": {
-    "nanos": 2443953,
-    "secs": 0
-  },
-  "58000": {
-    "nanos": 2555899,
-    "secs": 0
-  },
-  "59000": {
-    "nanos": 2605292,
-    "secs": 0
-  },
-  "6000": {
-    "nanos": 269627,
-    "secs": 0
-  },
-  "60000": {
-    "nanos": 2464003,
-    "secs": 0
-  },
-  "61000": {
-    "nanos": 3048624,
-    "secs": 0
-  },
-  "62000": {
-    "nanos": 2830657,
-    "secs": 0
-  },
-  "63000": {
-    "nanos": 2880066,
-    "secs": 0
-  },
-  "64000": {
-    "nanos": 2941481,
-    "secs": 0
-  },
-  "65000": {
-    "nanos": 2889690,
-    "secs": 0
-  },
-  "66000": {
-    "nanos": 2840917,
-    "secs": 0
-  },
-  "67000": {
-    "nanos": 2829613,
-    "secs": 0
-  },
-  "68000": {
-    "nanos": 3127232,
-    "secs": 0
-  },
-  "69000": {
-    "nanos": 3181686,
-    "secs": 0
-  },
-  "7000": {
-    "nanos": 315260,
-    "secs": 0
-  },
-  "70000": {
-    "nanos": 3492396,
-    "secs": 0
-  },
-  "71000": {
-    "nanos": 3223275,
-    "secs": 0
-  },
-  "72000": {
-    "nanos": 2997916,
-    "secs": 0
-  },
-  "73000": {
-    "nanos": 3135957,
-    "secs": 0
-  },
-  "74000": {
-    "nanos": 3370823,
-    "secs": 0
-  },
-  "75000": {
-    "nanos": 3972228,
-    "secs": 0
-  },
-  "76000": {
-    "nanos": 3691130,
-    "secs": 0
-  },
-  "77000": {
-    "nanos": 3391621,
-    "secs": 0
-  },
-  "78000": {
-    "nanos": 3453784,
-    "secs": 0
-  },
-  "79000": {
-    "nanos": 3439870,
-    "secs": 0
-  },
-  "8000": {
-    "nanos": 354640,
-    "secs": 0
-  },
-  "80000": {
-    "nanos": 3736211,
-    "secs": 0
-  },
-  "81000": {
-    "nanos": 3760407,
-    "secs": 0
-  },
-  "82000": {
-    "nanos": 3943915,
-    "secs": 0
-  },
-  "83000": {
-    "nanos": 3792094,
-    "secs": 0
-  },
-  "84000": {
-    "nanos": 3473753,
-    "secs": 0
-  },
-  "85000": {
-    "nanos": 3839513,
-    "secs": 0
-  },
-  "86000": {
-    "nanos": 4154761,
-    "secs": 0
-  },
-  "87000": {
-    "nanos": 3901227,
-    "secs": 0
-  },
-  "88000": {
-    "nanos": 3717099,
-    "secs": 0
-  },
-  "89000": {
-    "nanos": 4305197,
-    "secs": 0
-  },
-  "9000": {
-    "nanos": 392102,
-    "secs": 0
-  },
-  "90000": {
-    "nanos": 3930301,
-    "secs": 0
-  },
-  "91000": {
-    "nanos": 4049443,
-    "secs": 0
-  },
-  "92000": {
-    "nanos": 3813621,
-    "secs": 0
-  },
-  "93000": {
-    "nanos": 3899017,
-    "secs": 0
-  },
-  "94000": {
-    "nanos": 4232925,
-    "secs": 0
-  },
-  "95000": {
-    "nanos": 4017195,
-    "secs": 0
-  },
-  "96000": {
-    "nanos": 4062076,
-    "secs": 0
-  },
-  "97000": {
-    "nanos": 4053742,
-    "secs": 0
-  },
-  "98000": {
-    "nanos": 4354866,
-    "secs": 0
-  },
-  "99000": {
-    "nanos": 4078394,
-    "secs": 0
-  }
-}

+ 0 - 42
script/research/merkletree_null_benchmark/main.py

@@ -1,42 +0,0 @@
-import json
-import collections
-
-import matplotlib.pyplot as plt
-
-
-f = open("./serial_merkle_time.json")
-
-def load_data(path):
-    f = open(path)
-    
-    data = json.load(f)
-    data = {int(k):v for k,v in data.items()}
-    od = collections.OrderedDict(sorted(data.items()))
-    
-    
-    coins = list(od.keys()) 
-    seconds =  [ v.get("secs") + (v.get("nanos") / 1e9) for v in od.values()]
-
-    return coins, seconds
-
-plt.title(f"Serialize/Deserialize merkle tree benchmark")
-coins, seconds = load_data("./serial_merkle_time.json")
-plt.plot(coins, seconds, label='serializing')
-coins, seconds = load_data("./deserial_merkle_time.json")
-plt.plot(coins, seconds, label='deserializing')
-
-plt.legend()
-plt.ylabel(f"time in seconds")
-plt.xlabel("number of coins")
-plt.savefig("serial_desrial_merkle_time.png")
-
-#plt.title(f"Serialize/Deserialize nullifiers vector benchmark")
-#coins, seconds = load_data("./serial_null_time.json")
-#plt.plot(coins, seconds, label='serializing')
-#coins, seconds = load_data("./deserial_null_time.json")
-#plt.plot(coins, seconds, label='deserializing')
-#
-#plt.legend()
-#plt.ylabel(f"time in seconds")
-#plt.xlabel("number of coins")
-#plt.savefig("serial_desrial_null_time.png")

BIN
script/research/merkletree_null_benchmark/serial_desrial_merkle_time.png


BIN
script/research/merkletree_null_benchmark/serial_desrial_null_time.png


+ 0 - 402
script/research/merkletree_null_benchmark/serial_merkle_time.json

@@ -1,402 +0,0 @@
-{
-  "1000": {
-    "nanos": 436,
-    "secs": 0
-  },
-  "10000": {
-    "nanos": 402,
-    "secs": 0
-  },
-  "100000": {
-    "nanos": 503,
-    "secs": 0
-  },
-  "11000": {
-    "nanos": 492,
-    "secs": 0
-  },
-  "12000": {
-    "nanos": 495,
-    "secs": 0
-  },
-  "13000": {
-    "nanos": 434,
-    "secs": 0
-  },
-  "14000": {
-    "nanos": 492,
-    "secs": 0
-  },
-  "15000": {
-    "nanos": 423,
-    "secs": 0
-  },
-  "16000": {
-    "nanos": 540,
-    "secs": 0
-  },
-  "17000": {
-    "nanos": 428,
-    "secs": 0
-  },
-  "18000": {
-    "nanos": 865,
-    "secs": 0
-  },
-  "19000": {
-    "nanos": 459,
-    "secs": 0
-  },
-  "2000": {
-    "nanos": 902,
-    "secs": 0
-  },
-  "20000": {
-    "nanos": 489,
-    "secs": 0
-  },
-  "21000": {
-    "nanos": 833,
-    "secs": 0
-  },
-  "22000": {
-    "nanos": 900,
-    "secs": 0
-  },
-  "23000": {
-    "nanos": 549,
-    "secs": 0
-  },
-  "24000": {
-    "nanos": 1176,
-    "secs": 0
-  },
-  "25000": {
-    "nanos": 814,
-    "secs": 0
-  },
-  "26000": {
-    "nanos": 464,
-    "secs": 0
-  },
-  "27000": {
-    "nanos": 524,
-    "secs": 0
-  },
-  "28000": {
-    "nanos": 513,
-    "secs": 0
-  },
-  "29000": {
-    "nanos": 437,
-    "secs": 0
-  },
-  "3000": {
-    "nanos": 457,
-    "secs": 0
-  },
-  "30000": {
-    "nanos": 516,
-    "secs": 0
-  },
-  "31000": {
-    "nanos": 481,
-    "secs": 0
-  },
-  "32000": {
-    "nanos": 606,
-    "secs": 0
-  },
-  "33000": {
-    "nanos": 820,
-    "secs": 0
-  },
-  "34000": {
-    "nanos": 459,
-    "secs": 0
-  },
-  "35000": {
-    "nanos": 481,
-    "secs": 0
-  },
-  "36000": {
-    "nanos": 449,
-    "secs": 0
-  },
-  "37000": {
-    "nanos": 410,
-    "secs": 0
-  },
-  "38000": {
-    "nanos": 429,
-    "secs": 0
-  },
-  "39000": {
-    "nanos": 401,
-    "secs": 0
-  },
-  "4000": {
-    "nanos": 436,
-    "secs": 0
-  },
-  "40000": {
-    "nanos": 488,
-    "secs": 0
-  },
-  "41000": {
-    "nanos": 413,
-    "secs": 0
-  },
-  "42000": {
-    "nanos": 416,
-    "secs": 0
-  },
-  "43000": {
-    "nanos": 554,
-    "secs": 0
-  },
-  "44000": {
-    "nanos": 522,
-    "secs": 0
-  },
-  "45000": {
-    "nanos": 526,
-    "secs": 0
-  },
-  "46000": {
-    "nanos": 508,
-    "secs": 0
-  },
-  "47000": {
-    "nanos": 508,
-    "secs": 0
-  },
-  "48000": {
-    "nanos": 556,
-    "secs": 0
-  },
-  "49000": {
-    "nanos": 537,
-    "secs": 0
-  },
-  "5000": {
-    "nanos": 680,
-    "secs": 0
-  },
-  "50000": {
-    "nanos": 456,
-    "secs": 0
-  },
-  "51000": {
-    "nanos": 518,
-    "secs": 0
-  },
-  "52000": {
-    "nanos": 510,
-    "secs": 0
-  },
-  "53000": {
-    "nanos": 457,
-    "secs": 0
-  },
-  "54000": {
-    "nanos": 550,
-    "secs": 0
-  },
-  "55000": {
-    "nanos": 525,
-    "secs": 0
-  },
-  "56000": {
-    "nanos": 488,
-    "secs": 0
-  },
-  "57000": {
-    "nanos": 528,
-    "secs": 0
-  },
-  "58000": {
-    "nanos": 832,
-    "secs": 0
-  },
-  "59000": {
-    "nanos": 512,
-    "secs": 0
-  },
-  "6000": {
-    "nanos": 889,
-    "secs": 0
-  },
-  "60000": {
-    "nanos": 540,
-    "secs": 0
-  },
-  "61000": {
-    "nanos": 496,
-    "secs": 0
-  },
-  "62000": {
-    "nanos": 563,
-    "secs": 0
-  },
-  "63000": {
-    "nanos": 553,
-    "secs": 0
-  },
-  "64000": {
-    "nanos": 593,
-    "secs": 0
-  },
-  "65000": {
-    "nanos": 574,
-    "secs": 0
-  },
-  "66000": {
-    "nanos": 418,
-    "secs": 0
-  },
-  "67000": {
-    "nanos": 411,
-    "secs": 0
-  },
-  "68000": {
-    "nanos": 983,
-    "secs": 0
-  },
-  "69000": {
-    "nanos": 443,
-    "secs": 0
-  },
-  "7000": {
-    "nanos": 742,
-    "secs": 0
-  },
-  "70000": {
-    "nanos": 451,
-    "secs": 0
-  },
-  "71000": {
-    "nanos": 458,
-    "secs": 0
-  },
-  "72000": {
-    "nanos": 523,
-    "secs": 0
-  },
-  "73000": {
-    "nanos": 457,
-    "secs": 0
-  },
-  "74000": {
-    "nanos": 424,
-    "secs": 0
-  },
-  "75000": {
-    "nanos": 505,
-    "secs": 0
-  },
-  "76000": {
-    "nanos": 490,
-    "secs": 0
-  },
-  "77000": {
-    "nanos": 1190,
-    "secs": 0
-  },
-  "78000": {
-    "nanos": 448,
-    "secs": 0
-  },
-  "79000": {
-    "nanos": 433,
-    "secs": 0
-  },
-  "8000": {
-    "nanos": 479,
-    "secs": 0
-  },
-  "80000": {
-    "nanos": 517,
-    "secs": 0
-  },
-  "81000": {
-    "nanos": 488,
-    "secs": 0
-  },
-  "82000": {
-    "nanos": 653,
-    "secs": 0
-  },
-  "83000": {
-    "nanos": 432,
-    "secs": 0
-  },
-  "84000": {
-    "nanos": 444,
-    "secs": 0
-  },
-  "85000": {
-    "nanos": 388,
-    "secs": 0
-  },
-  "86000": {
-    "nanos": 580,
-    "secs": 0
-  },
-  "87000": {
-    "nanos": 503,
-    "secs": 0
-  },
-  "88000": {
-    "nanos": 572,
-    "secs": 0
-  },
-  "89000": {
-    "nanos": 548,
-    "secs": 0
-  },
-  "9000": {
-    "nanos": 389,
-    "secs": 0
-  },
-  "90000": {
-    "nanos": 539,
-    "secs": 0
-  },
-  "91000": {
-    "nanos": 533,
-    "secs": 0
-  },
-  "92000": {
-    "nanos": 542,
-    "secs": 0
-  },
-  "93000": {
-    "nanos": 499,
-    "secs": 0
-  },
-  "94000": {
-    "nanos": 545,
-    "secs": 0
-  },
-  "95000": {
-    "nanos": 474,
-    "secs": 0
-  },
-  "96000": {
-    "nanos": 579,
-    "secs": 0
-  },
-  "97000": {
-    "nanos": 555,
-    "secs": 0
-  },
-  "98000": {
-    "nanos": 604,
-    "secs": 0
-  },
-  "99000": {
-    "nanos": 435,
-    "secs": 0
-  }
-}

+ 0 - 402
script/research/merkletree_null_benchmark/serial_null_time.json

@@ -1,402 +0,0 @@
-{
-  "1000": {
-    "nanos": 25707,
-    "secs": 0
-  },
-  "10000": {
-    "nanos": 216642,
-    "secs": 0
-  },
-  "100000": {
-    "nanos": 2662667,
-    "secs": 0
-  },
-  "11000": {
-    "nanos": 233108,
-    "secs": 0
-  },
-  "12000": {
-    "nanos": 258893,
-    "secs": 0
-  },
-  "13000": {
-    "nanos": 277626,
-    "secs": 0
-  },
-  "14000": {
-    "nanos": 298115,
-    "secs": 0
-  },
-  "15000": {
-    "nanos": 316558,
-    "secs": 0
-  },
-  "16000": {
-    "nanos": 349252,
-    "secs": 0
-  },
-  "17000": {
-    "nanos": 309206,
-    "secs": 0
-  },
-  "18000": {
-    "nanos": 398314,
-    "secs": 0
-  },
-  "19000": {
-    "nanos": 412214,
-    "secs": 0
-  },
-  "2000": {
-    "nanos": 45835,
-    "secs": 0
-  },
-  "20000": {
-    "nanos": 435866,
-    "secs": 0
-  },
-  "21000": {
-    "nanos": 443708,
-    "secs": 0
-  },
-  "22000": {
-    "nanos": 465586,
-    "secs": 0
-  },
-  "23000": {
-    "nanos": 506836,
-    "secs": 0
-  },
-  "24000": {
-    "nanos": 505983,
-    "secs": 0
-  },
-  "25000": {
-    "nanos": 531944,
-    "secs": 0
-  },
-  "26000": {
-    "nanos": 571615,
-    "secs": 0
-  },
-  "27000": {
-    "nanos": 585129,
-    "secs": 0
-  },
-  "28000": {
-    "nanos": 562634,
-    "secs": 0
-  },
-  "29000": {
-    "nanos": 579645,
-    "secs": 0
-  },
-  "3000": {
-    "nanos": 76906,
-    "secs": 0
-  },
-  "30000": {
-    "nanos": 500443,
-    "secs": 0
-  },
-  "31000": {
-    "nanos": 520743,
-    "secs": 0
-  },
-  "32000": {
-    "nanos": 590317,
-    "secs": 0
-  },
-  "33000": {
-    "nanos": 597426,
-    "secs": 0
-  },
-  "34000": {
-    "nanos": 711377,
-    "secs": 0
-  },
-  "35000": {
-    "nanos": 665712,
-    "secs": 0
-  },
-  "36000": {
-    "nanos": 693867,
-    "secs": 0
-  },
-  "37000": {
-    "nanos": 722775,
-    "secs": 0
-  },
-  "38000": {
-    "nanos": 739728,
-    "secs": 0
-  },
-  "39000": {
-    "nanos": 742682,
-    "secs": 0
-  },
-  "4000": {
-    "nanos": 98782,
-    "secs": 0
-  },
-  "40000": {
-    "nanos": 760965,
-    "secs": 0
-  },
-  "41000": {
-    "nanos": 778431,
-    "secs": 0
-  },
-  "42000": {
-    "nanos": 809894,
-    "secs": 0
-  },
-  "43000": {
-    "nanos": 819735,
-    "secs": 0
-  },
-  "44000": {
-    "nanos": 860603,
-    "secs": 0
-  },
-  "45000": {
-    "nanos": 862725,
-    "secs": 0
-  },
-  "46000": {
-    "nanos": 884374,
-    "secs": 0
-  },
-  "47000": {
-    "nanos": 890589,
-    "secs": 0
-  },
-  "48000": {
-    "nanos": 954809,
-    "secs": 0
-  },
-  "49000": {
-    "nanos": 879739,
-    "secs": 0
-  },
-  "5000": {
-    "nanos": 125918,
-    "secs": 0
-  },
-  "50000": {
-    "nanos": 871705,
-    "secs": 0
-  },
-  "51000": {
-    "nanos": 911719,
-    "secs": 0
-  },
-  "52000": {
-    "nanos": 967166,
-    "secs": 0
-  },
-  "53000": {
-    "nanos": 976981,
-    "secs": 0
-  },
-  "54000": {
-    "nanos": 1046523,
-    "secs": 0
-  },
-  "55000": {
-    "nanos": 1019318,
-    "secs": 0
-  },
-  "56000": {
-    "nanos": 1103141,
-    "secs": 0
-  },
-  "57000": {
-    "nanos": 1055578,
-    "secs": 0
-  },
-  "58000": {
-    "nanos": 1109236,
-    "secs": 0
-  },
-  "59000": {
-    "nanos": 1120614,
-    "secs": 0
-  },
-  "6000": {
-    "nanos": 144705,
-    "secs": 0
-  },
-  "60000": {
-    "nanos": 1208080,
-    "secs": 0
-  },
-  "61000": {
-    "nanos": 1165978,
-    "secs": 0
-  },
-  "62000": {
-    "nanos": 1191259,
-    "secs": 0
-  },
-  "63000": {
-    "nanos": 1209839,
-    "secs": 0
-  },
-  "64000": {
-    "nanos": 1170322,
-    "secs": 0
-  },
-  "65000": {
-    "nanos": 1249531,
-    "secs": 0
-  },
-  "66000": {
-    "nanos": 1108637,
-    "secs": 0
-  },
-  "67000": {
-    "nanos": 1225433,
-    "secs": 0
-  },
-  "68000": {
-    "nanos": 1196818,
-    "secs": 0
-  },
-  "69000": {
-    "nanos": 1207728,
-    "secs": 0
-  },
-  "7000": {
-    "nanos": 159013,
-    "secs": 0
-  },
-  "70000": {
-    "nanos": 1279995,
-    "secs": 0
-  },
-  "71000": {
-    "nanos": 1300298,
-    "secs": 0
-  },
-  "72000": {
-    "nanos": 1349131,
-    "secs": 0
-  },
-  "73000": {
-    "nanos": 1368361,
-    "secs": 0
-  },
-  "74000": {
-    "nanos": 1379306,
-    "secs": 0
-  },
-  "75000": {
-    "nanos": 1416562,
-    "secs": 0
-  },
-  "76000": {
-    "nanos": 1522962,
-    "secs": 0
-  },
-  "77000": {
-    "nanos": 1528788,
-    "secs": 0
-  },
-  "78000": {
-    "nanos": 1532588,
-    "secs": 0
-  },
-  "79000": {
-    "nanos": 1557600,
-    "secs": 0
-  },
-  "8000": {
-    "nanos": 170707,
-    "secs": 0
-  },
-  "80000": {
-    "nanos": 1595893,
-    "secs": 0
-  },
-  "81000": {
-    "nanos": 1557007,
-    "secs": 0
-  },
-  "82000": {
-    "nanos": 1653833,
-    "secs": 0
-  },
-  "83000": {
-    "nanos": 1571937,
-    "secs": 0
-  },
-  "84000": {
-    "nanos": 1680081,
-    "secs": 0
-  },
-  "85000": {
-    "nanos": 1827453,
-    "secs": 0
-  },
-  "86000": {
-    "nanos": 1700669,
-    "secs": 0
-  },
-  "87000": {
-    "nanos": 1861765,
-    "secs": 0
-  },
-  "88000": {
-    "nanos": 1881227,
-    "secs": 0
-  },
-  "89000": {
-    "nanos": 1886907,
-    "secs": 0
-  },
-  "9000": {
-    "nanos": 197961,
-    "secs": 0
-  },
-  "90000": {
-    "nanos": 1935081,
-    "secs": 0
-  },
-  "91000": {
-    "nanos": 1901289,
-    "secs": 0
-  },
-  "92000": {
-    "nanos": 1904586,
-    "secs": 0
-  },
-  "93000": {
-    "nanos": 2173950,
-    "secs": 0
-  },
-  "94000": {
-    "nanos": 2054032,
-    "secs": 0
-  },
-  "95000": {
-    "nanos": 2152519,
-    "secs": 0
-  },
-  "96000": {
-    "nanos": 2054692,
-    "secs": 0
-  },
-  "97000": {
-    "nanos": 2154415,
-    "secs": 0
-  },
-  "98000": {
-    "nanos": 2272199,
-    "secs": 0
-  },
-  "99000": {
-    "nanos": 2506013,
-    "secs": 0
-  }
-}

+ 0 - 134
script/research/merkletree_null_benchmark/src/main.rs

@@ -1,134 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use std::{collections::HashMap, fs::write, time::Instant};
-
-use darkfi::crypto::coin::Coin;
-use darkfi_sdk::crypto::{constants::MERKLE_DEPTH, MerkleNode, Nullifier};
-use darkfi_serial::{deserialize, serialize};
-
-use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
-use pasta_curves::{group::ff::Field, pallas};
-use rand::rngs::OsRng;
-use serde_json::json;
-
-fn main() {
-    let mut serial_merkle_time = HashMap::new();
-
-    for i in 1..101 {
-        let mut tree: BridgeTree<MerkleNode, MERKLE_DEPTH> = BridgeTree::new(100);
-
-        let coins = 1000 * i; 
-
-        for _ in 0..coins {
-            let coin = Coin(pallas::Base::random(&mut OsRng));
-            tree.append(&MerkleNode::from(coin.0));
-        }
-
-        let start = Instant::now();
-        for _ in 0..100 {
-            serialize(&tree);
-        }
-        let elapsed = start.elapsed();
-
-        let result = elapsed / 100;
-        serial_merkle_time.insert(coins, result);
-    }
-
-    let mut deserial_merkle_time = HashMap::new();
-
-    for i in 1..101 {
-        let mut tree: BridgeTree<MerkleNode, MERKLE_DEPTH> = BridgeTree::new(100);
-
-        let coins = 1000 * i; 
-        for _ in 0..coins {
-            let coin = Coin(pallas::Base::random(&mut OsRng));
-            tree.append(&MerkleNode::from(coin.0));
-        }
-
-        let ser_tree = serialize(&tree);
-        let start = Instant::now();
-        for _ in 0..100 {
-            deserialize::<BridgeTree<MerkleNode, MERKLE_DEPTH>>(&ser_tree).unwrap();
-        }
-        let elapsed = start.elapsed();
-
-        let result = elapsed / 100;
-        deserial_merkle_time.insert(coins, result);
-    }
-
-    let mut serial_null_time = HashMap::new();
-
-    for i in 1..101 {
-        let mut nullifiers: Vec<Nullifier> = vec![];
-
-        let coins = 1000 * i; 
-        for _ in 0..coins {
-            let nullifier = Nullifier::from(pallas::Base::random(&mut OsRng));
-            nullifiers.push(nullifier);
-        }
-
-        let start = Instant::now();
-        for _ in 0..100 {
-            serialize(&nullifiers);
-        }
-        let elapsed = start.elapsed();
-
-        let result = elapsed / 100;
-        serial_null_time.insert(coins, result);
-    }
-
-    let mut deserial_null_time = HashMap::new();
-
-    for i in 1..101 {
-        let mut nullifiers: Vec<Nullifier> = vec![];
-
-        let coins = 1000 * i; 
-        for _ in 0..coins {
-            let nullifier = Nullifier::from(pallas::Base::random(&mut OsRng));
-            nullifiers.push(nullifier);
-        }
-
-        let ser_null = serialize(&nullifiers);
-        let start = Instant::now();
-        for _ in 0..100 {
-            deserialize::<Vec<Nullifier>>(&ser_null).unwrap();
-        }
-        let elapsed = start.elapsed();
-
-        let result = elapsed / 100;
-        deserial_null_time.insert(coins, result);
-    }
-
-    let serial_merkle_time = json!(serial_merkle_time);
-    let deserial_merkle_time = json!(deserial_merkle_time);
-    let serial_null_time = json!(serial_null_time);
-    let deserial_null_time = json!(deserial_null_time);
-
-    write("serial_merkle_time.json", serde_json::to_string_pretty(&serial_merkle_time).unwrap())
-        .unwrap();
-
-    write("deserial_merkle_time.json", serde_json::to_string_pretty(&deserial_merkle_time).unwrap())
-        .unwrap();
-
-    write("serial_null_time.json", serde_json::to_string_pretty(&serial_null_time).unwrap())
-        .unwrap();
-
-    write("deserial_null_time.json", serde_json::to_string_pretty(&deserial_null_time).unwrap())
-        .unwrap();
-}

+ 0 - 2
script/research/pasta/.gitignore

@@ -1,2 +0,0 @@
-target/*
-Cargo.lock

+ 0 - 18
script/research/pasta/Cargo.toml

@@ -1,18 +0,0 @@
-[package]
-name = "pasta"
-version = "0.3.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2018"
-
-[workspace]
-
-[dependencies]
-pasta_curves = "0.4.1"
-ff = "0.12.1"
-group = "0.12.1"
-rand = "0.8.5"
-
-[[bin]]
-name = "pasta"
-path = "main.rs"

+ 0 - 39
script/research/pasta/main.rs

@@ -1,39 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use pasta_curves as pasta;
-use group::{Group, Curve};
-use rand::rngs::OsRng;
-
-fn main() {
-    let g = pasta::vesta::Point::generator();
-    println!("G = {:?}", g.to_affine());
-    let x = pasta::vesta::Scalar::from(87u64);
-    println!("x = 87 = {:?}", x);
-    let b = g * x;
-    println!("B = xG = {:?}", b.to_affine());
-
-    let y = x - pasta::vesta::Scalar::from(90u64);
-    println!("y = x - 90 = {:?}", y);
-
-    let c = pasta::vesta::Point::random(&mut OsRng);
-    let d = pasta::vesta::Point::random(&mut OsRng);
-    println!("C = {:?}", c.to_affine());
-    println!("D = {:?}", d.to_affine());
-    println!("C + D = {:?}", (c + d).to_affine());
-}

+ 0 - 22
script/research/pasta/vesta.sage

@@ -1,22 +0,0 @@
-q = 0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001
-K = GF(q)
-a = K(0x00)
-b = K(0x05)
-E = EllipticCurve(K, (a, b))
-G = E(0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000, 0x02)
-E.set_order(0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001 * 0x01)
-p = 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001
-Scalar = GF(p)
-
-A = E(0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000, 0x0000000000000000000000000000000000000000000000000000000000000002)
-x = Scalar(0x0000000000000000000000000000000000000000000000000000000000000057)
-print(int(x))
-#print([hex(x) for x in (x * A).xy()])
-B = E(0x04cbd122b054187ff98f0726651096de7f55a213c233902764fe87d376eeb99c, 0x2d5c8c632b1f33eb42726cda0af9f95eaf3dfa8511e6a7b657713dbf62bb13a5)
-assert int(x) * A == B
-
-yy = Scalar(0x40000000000000000000000000000000224698fc094cf91b992d30ecfffffffe)
-y = x - Scalar(90)
-print(hex(int(y)))
-assert yy == y
-

+ 0 - 2
script/research/rpc_client_notifications/.gitignore

@@ -1,2 +0,0 @@
-/target
-Cargo.lock

+ 0 - 15
script/research/rpc_client_notifications/Cargo.toml

@@ -1,15 +0,0 @@
-[package]
-name = "rpc_client_notifications"
-version = "0.1.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2021"
-
-[workspace]
-
-[dependencies]
-async-std = "1.12.0"
-darkfi = {path = "../../../", features = ["rpc"]}
-futures = "0.3.25"
-serde_json = "1.0.89"
-url = {version = "2.3.1", features = ["serde"]}

+ 0 - 79
script/research/rpc_client_notifications/src/main.rs

@@ -1,79 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use darkfi::{
-    rpc::{
-        client::RpcClient,
-        jsonrpc::{JsonRequest, JsonResult},
-    },
-    system::{Subscriber, SubscriberPtr},
-    Result,
-};
-use futures::join;
-use serde_json::json;
-use url::Url;
-
-async fn listen(subscriber: SubscriberPtr<JsonResult>) -> Result<()> {
-    let subscription = subscriber.subscribe().await;
-    loop {
-        // Listen subscription for notifications
-        let notification = subscription.receive().await;
-        match notification {
-            JsonResult::Notification(n) => {
-                println!("Got notification: {:?}", n);
-            }
-            JsonResult::Error(e) => {
-                println!("Client returned an error: {}", serde_json::to_string(&e)?);
-                break
-            }
-            _ => {
-                println!("Client returned an unexpected reply.");
-                break
-            }
-        }
-    }
-    subscription.unsubscribe().await;
-
-    Ok(())
-}
-
-#[async_std::main]
-async fn main() -> Result<()> {
-    let endpoint = Url::parse("tcp://127.0.0.1:18927")?;
-    let notif_channel = "blockchain.notify_blocks";
-    println!("Creating subscriber for channel: {}", notif_channel);
-    let subscriber: SubscriberPtr<JsonResult> = Subscriber::new();
-
-    println!("Creating client for endpoint: {}", endpoint);
-    let rpc_client = RpcClient::new(endpoint).await?;
-    println!("Subscribing client");
-    let req = JsonRequest::new("blockchain.notify_blocks", json!([]));
-
-    println!("Starting listening");
-    let result = join!(listen(subscriber.clone()), rpc_client.subscribe(req, subscriber));
-    match result.0 {
-        Ok(_) => {}
-        Err(e) => println!("Listener failed: {}", e),
-    }
-    match result.1 {
-        Ok(_) => {}
-        Err(e) => println!("Subscriber failed: {}", e),
-    }
-
-    Ok(())
-}

+ 0 - 2
script/research/state_usage_analyser/.gitignore

@@ -1,2 +0,0 @@
-/target
-Cargo.lock

+ 0 - 20
script/research/state_usage_analyser/Cargo.toml

@@ -1,20 +0,0 @@
-[package]
-name = "state_usage_analyser"
-version = "0.3.0"
-authors = ["Dyne.org foundation <foundation@dyne.org>"]
-license = "AGPL-3.0-only"
-edition = "2021"
-
-[workspace]
-
-[dependencies]
-async-std = {version = "1.12.0", features = ["attributes"]}
-bincode = "2.0.0-rc.2"
-darkfi = {path = "../../../", features = ["blockchain"]}
-incrementalmerkletree = "0.3.0"
-lazy-init = "0.5.1"
-log = "0.4.17"
-pasta_curves = "0.4.1"
-rand = "0.8.5"
-serde = {version = "1.0.150", features = ["derive"]}
-sled = "0.34.7"

+ 0 - 155
script/research/state_usage_analyser/src/main.rs

@@ -1,155 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2022 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use async_std::sync::{Arc, Mutex};
-use incrementalmerkletree::bridgetree::BridgeTree;
-use lazy_init::Lazy;
-use pasta_curves::{group::ff::Field, pallas::Base};
-use rand::rngs::OsRng;
-use serde::ser::{Serialize, SerializeStruct, Serializer};
-
-use darkfi::{
-    blockchain::Blockchain,
-    consensus::{TESTNET_GENESIS_HASH_BYTES, TESTNET_GENESIS_TIMESTAMP},
-    crypto::{
-        constants::MERKLE_DEPTH,
-        keypair::{PublicKey, SecretKey},
-        merkle_node::MerkleNode,
-    },
-    node::{
-        state::{state_transition, ProgramState},
-        Client, MemoryState, State,
-    },
-    util::{cli::progress_bar, path::expand_path},
-    wallet::walletdb::init_wallet,
-};
-
-// Auxiliary struct to Serialize BridgeTree
-struct BridgeTreeWrapper {
-    tree: BridgeTree<MerkleNode, MERKLE_DEPTH>,
-}
-
-impl Serialize for BridgeTreeWrapper {
-    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
-    where
-        S: Serializer,
-    {
-        let mut state = serializer.serialize_struct("BridgeTreeWrapper", 1)?;
-        state.serialize_field("tree", &self.tree)?;
-        state.end()
-    }
-}
-
-pub fn bridge_tree_usage(prefix: &str, tree: BridgeTree<MerkleNode, MERKLE_DEPTH>) {
-    let wrapper = BridgeTreeWrapper { tree };
-    let encoded: Vec<u8> =
-        bincode::serde::encode_to_vec(&wrapper, bincode::config::legacy()).unwrap();
-    let size = ::std::mem::size_of_val(&*encoded);
-    println!("  {} size: {:?} Bytes", prefix, size);
-}
-
-#[async_std::main]
-async fn main() -> darkfi::Result<()> {
-    // Config
-    let folder = "~/.config/darkfi/merkle_testing";
-    let genesis_ts = *TESTNET_GENESIS_TIMESTAMP;
-    let genesis_data = *TESTNET_GENESIS_HASH_BYTES;
-    let pass = "changeme";
-
-    // Initialize
-    let pb = progress_bar("Initializing wallet...");
-    let path = folder.to_owned() + "/wallet.db";
-    let wallet = init_wallet(&path, &pass).await?;
-    let client = Arc::new(Client::new(wallet.clone()).await?);
-    let address = wallet.get_default_address().await?;
-    let pubkey = PublicKey::try_from(address)?;
-    pb.finish();
-
-    let pb = progress_bar("Initializing sled database...");
-    let path = folder.to_owned() + "/blockchain/testnet";
-    let db_path = expand_path(&path).unwrap();
-    let sled_db = sled::open(&db_path)?;
-    pb.finish();
-
-    let pb = progress_bar("Generating state machine...");
-    let blockchain = Blockchain::new(&sled_db, genesis_ts, genesis_data)?;
-    let state_machine = State {
-        tree: client.get_tree().await?,
-        merkle_roots: blockchain.merkle_roots.clone(),
-        nullifiers: blockchain.nullifiers.clone(),
-        cashier_pubkeys: vec![],
-        faucet_pubkeys: vec![pubkey.clone()],
-        mint_vk: Lazy::new(),
-        burn_vk: Lazy::new(),
-    };
-    pb.finish();
-
-    let pb = progress_bar("Creating zk proof verification keys...");
-    let _ = state_machine.mint_vk();
-    let _ = state_machine.burn_vk();
-    pb.finish();
-
-    let pb = progress_bar("Generating memory state and secret keys...");
-    let canon_state_clone = state_machine.clone();
-    let mut state = state_machine;
-    let mut mem_state = MemoryState::new(canon_state_clone);
-    let state_arc = Arc::new(Mutex::new(state.clone()));
-
-    let secret_keys: Vec<SecretKey> =
-        client.get_keypairs().await?.iter().map(|x| x.secret).collect();
-    pb.finish();
-
-    // Initial size
-    bridge_tree_usage("Original state", state.tree.clone());
-
-    // Create txs token
-    let token_id = Base::random(&mut OsRng);
-    let amount = 1;
-
-    // Generating and applying transactions
-    let txs = 5;
-    println!("  Applying {} transactions...", txs);
-    for i in 0..txs {
-        println!("    tx {}", i);
-        let tx =
-            match client.build_transaction(pubkey, amount, token_id, true, state_arc.clone()).await
-            {
-                Ok(v) => v,
-                Err(e) => {
-                    println!("Failed building transaction: {}", e);
-                    return Err(e.into())
-                }
-            };
-
-        let update = match state_transition(&mem_state, tx.clone()) {
-            Ok(v) => v,
-            Err(e) => {
-                println!("validate_state_transition(): Failed for tx {}: {}", i, e);
-                return Err(e.into())
-            }
-        };
-
-        mem_state.apply(update.clone());
-        state.apply(update, secret_keys.clone(), None, client.wallet.clone()).await?;
-    }
-
-    // Final size
-    bridge_tree_usage("Final state", state.tree);
-
-    Ok(())
-}

+ 1 - 1
script/research/x3dh/Cargo.toml

@@ -12,6 +12,6 @@ sha2 = "0.10.6"
 digest = "0.10.6"
 rand = "0.8.5"
 aes-gcm-siv = "0.11.1"
-curve25519-dalek = "4.0.0-pre.2"
+curve25519-dalek = {version = "4.0.0-pre.5", features = ["digest"]}
 ed25519-dalek = "1.0.1"
 x25519-dalek = "2.0.0-pre.1"