From 4bd5238acdad9ccf008b9c0d4c659266d126e169 Mon Sep 17 00:00:00 2001 From: BaldyAsh Date: Tue, 16 Jul 2019 22:02:25 +0300 Subject: [PATCH 1/5] removed old data restore --- Cargo.lock | 187 ------- Cargo.toml | 1 - core/data_restore/Cargo.toml | 21 - core/data_restore/src/accounts_state/mod.rs | 492 ------------------ core/data_restore/src/block_events/mod.rs | 397 -------------- core/data_restore/src/blocks/mod.rs | 34 -- core/data_restore/src/data_restore_driver.rs | 307 ----------- .../src/franklin_transaction/mod.rs | 88 ---- core/data_restore/src/helpers/mod.rs | 178 ------- core/data_restore/src/lib.rs | 62 --- 10 files changed, 1767 deletions(-) delete mode 100644 core/data_restore/Cargo.toml delete mode 100644 core/data_restore/src/accounts_state/mod.rs delete mode 100644 core/data_restore/src/block_events/mod.rs delete mode 100644 core/data_restore/src/blocks/mod.rs delete mode 100644 core/data_restore/src/data_restore_driver.rs delete mode 100644 core/data_restore/src/franklin_transaction/mod.rs delete mode 100644 core/data_restore/src/helpers/mod.rs delete mode 100644 core/data_restore/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 381489ee2f..16208c6172 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -236,11 +236,6 @@ name = "bitflags" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bitvec" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "blake2-rfc_bellman_edition" version = "0.0.1" @@ -516,42 +511,6 @@ name = "crunchy" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "data_restore" -version = "0.1.0" -dependencies = [ - "bigdecimal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bitvec 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "models 0.0.1", - "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "plasma 0.1.1", - "sapling-crypto_ce 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "web3 0.7.0 (git+https://github.com/tomusdrw/rust-web3)", -] - -[[package]] -name = "derive_more" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "diesel" version = "1.4.2" @@ -729,20 +688,6 @@ dependencies = [ "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethabi" -version = "7.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethbloom" version = "0.5.3" @@ -755,18 +700,6 @@ dependencies = [ "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethbloom" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethereum-tx-sign" version = "0.0.2" @@ -794,19 +727,6 @@ dependencies = [ "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethereum-types" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethereum-types-serialize" version = "0.2.2" @@ -869,18 +789,6 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "fixed-hash" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "flate2" version = "1.0.7" @@ -1108,22 +1016,6 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "impl-rlp" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "impl-serde" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "indexmap" version = "0.4.1" @@ -1187,18 +1079,6 @@ dependencies = [ "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "jsonrpc-core" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -2059,15 +1939,6 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rlp" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rust-crypto" version = "0.2.36" @@ -2381,11 +2252,6 @@ name = "stable_deref_trait" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "static_assertions" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "storage" version = "0.0.1" @@ -2881,17 +2747,6 @@ dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "uint" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "unicase" version = "1.4.2" @@ -3044,34 +2899,6 @@ dependencies = [ "websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "web3" -version = "0.7.0" -source = "git+https://github.com/tomusdrw/rust-web3#21cb38c7203a026f292d65059272b88e2050626e" -dependencies = [ - "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 11.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "websocket" version = "0.21.1" @@ -3189,7 +3016,6 @@ dependencies = [ "checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" -"checksum bitvec 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b67491e1cc6f37da6c4415cd743cb8d2e2c65388acc91ca3094a054cbf3cbd0c" "checksum blake2-rfc_bellman_edition 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fdc60350286c7c3db13b98e91dbe5c8b6830a6821bc20af5b0c310ce94d74915" "checksum bodyparser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f023abfa58aad6f6bc4ae0630799e24d5ee0ab8bb2e49f651d9b1f9aa4f52f30" "checksum brotli-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" @@ -3219,8 +3045,6 @@ dependencies = [ "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d24935ba50c4a8dc375a0fd1f8a2ba6bdbdc4125713126a74b965d6a01a06d7" "checksum diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62a27666098617d52c487a41f70de23d44a1dc1f3aa5877ceba2790fb1f1cab4" "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" @@ -3239,19 +3063,15 @@ dependencies = [ "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" "checksum error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6930e04918388a9a2e41d518c25cf679ccafe26733fb4127dbf21993f2575d46" "checksum ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eb362fde43ed0b50b258bb0c72b72b3dccfd29f8de9506295eaf9251c49ca31" -"checksum ethabi 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "be9a03ff8f3d495d9b73d59fd166acc91d0fd81779911b0b8b4c87b6024a670a" "checksum ethbloom 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6294da962646baa738414e8e718d1a1f0360a51d92de89ccbf91870418f5360" -"checksum ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3932e82d64d347a045208924002930dc105a138995ccdc1479d0f05f0359f17c" "checksum ethereum-tx-sign 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e52cd032ced69abdef1113b2862b4d12feddd87f86c6c5d9f711a1ec25cab94f" "checksum ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e742184dc63a01c8ea0637369f8faa27c40f537949908a237f95c05e68d2c96" -"checksum ethereum-types 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b054df51e53f253837ea422681215b42823c02824bde982699d0dceecf6165a1" "checksum ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1873d77b32bc1891a79dad925f2acbc318ee942b38b9110f9dbc5fbeffcea350" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f6edceb5dc64db5e46acb519af5d994b004bc150230498527c3f9e55c94c842" "checksum ff_derive_ce 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "189b37f93ec30f72d7420f1e6f2f07031ed0245073ab46c02b57fba696f4365a" "checksum fixed-hash 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7afe6ce860afb14422711595a7b26ada9ed7de2f43c0b2ab79d09ee196287273" -"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" "checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" @@ -3276,15 +3096,12 @@ dependencies = [ "checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum im 12.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "de38d1511a0ce7677538acb1e31b5df605147c458e061b2cdb89858afb1cd182" -"checksum impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f39b9963cf5f12fcc4ae4b30a6927ed67d6b4ea4cbe7d17a41131163b401303b" -"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum indexmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7164c96d6e18ccc3ce43f3dedac996c21a220670a106c275b96ad92110401362" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum ipconfig 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "08f7eadeaf4b52700de180d147c4805f199854600b36faa963d91114827b2ffc" "checksum iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8e17268922834707e1c29e8badbf9c712c9c43378e1b6a3388946baff10be2" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" -"checksum jsonrpc-core 11.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97b83fdc5e0218128d0d270f2f2e7a5ea716f3240c8518a58bc89e6716ba8581" "checksum jsonrpc-core 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf83704f4e79979a424d1082dd2c1e52683058056c9280efa19ac5f6bc9033c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" @@ -3370,7 +3187,6 @@ dependencies = [ "checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" "checksum rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "524c5ad554859785dfc8469df3ed5e0b5784d4d335877ed47c8d90fc0eb238fe" "checksum rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d1effe9845d54f90e7be8420ee49e5c94623140b97ee4bc6fb5bfddb745720" -"checksum rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b0d56c1450bfbef1181fdeb78b902dc1d23178de77c23d705317508e03d1b7c" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" @@ -3405,7 +3221,6 @@ dependencies = [ "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum socket2 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "4e626972d3593207547f14bf5fc9efa4d0e7283deb73fef1dff313dae9ab8878" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" -"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum string 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0bbfb8937e38e34c3444ff00afb28b0811d9554f15c5ad64d12b0308d1d1995" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)" = "641e117d55514d6d918490e47102f7e08d096fdde360247e4a10f7a91a8478d3" @@ -3448,7 +3263,6 @@ dependencies = [ "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" -"checksum uint 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "082df6964410f6aa929a61ddfafc997e4f32c62c22490e439ac351cec827f436" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a84e5511b2a947f3ae965dcb29b13b7b1691b6e7332cf5dbc1744138d5acb7f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" @@ -3466,7 +3280,6 @@ dependencies = [ "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" "checksum web3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "deff75304fe1d0aadb0debac42722c4e63a168619e71e077bc2def73c250db4e" -"checksum web3 0.7.0 (git+https://github.com/tomusdrw/rust-web3)" = "" "checksum websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c9faed2bff8af2ea6b9f8b917d3d00b467583f6781fe3def174a9e33c879703" "checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/Cargo.toml b/Cargo.toml index 5e20a5d6b7..fdee66631a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "core/data_restore", "core/key_generator", "core/merkle_tree", "core/eth_client", diff --git a/core/data_restore/Cargo.toml b/core/data_restore/Cargo.toml deleted file mode 100644 index 149ea9413b..0000000000 --- a/core/data_restore/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "data_restore" -version = "0.1.0" -edition = "2018" - -[dependencies] -bigdecimal = { version = "0.1.0", features = ["serde"]} -futures = "0.1.26" -web3 = { git = "https://github.com/tomusdrw/rust-web3" } -tiny-keccak = "1.4.2" -ethabi = "7.0.0" -hex = "0.3.2" -sapling-crypto = { package = "sapling-crypto_ce", version = "0.0.5" } -ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } -pairing = { package = "pairing_ce", version = "0.17.0" } -tokio = "0.1" -bitvec = "0.11" -log = "0.4" - -plasma = { path = "../plasma" } -models = { path = "../models" } diff --git a/core/data_restore/src/accounts_state/mod.rs b/core/data_restore/src/accounts_state/mod.rs deleted file mode 100644 index 206fbc7635..0000000000 --- a/core/data_restore/src/accounts_state/mod.rs +++ /dev/null @@ -1,492 +0,0 @@ -use std::cmp::Ordering; -use std::collections::{HashMap, HashSet}; -use std::convert::TryInto; - -use ff::{Field, PrimeField, PrimeFieldRepr}; -use sapling_crypto::jubjub::{edwards, Unknown}; -use web3::futures::Future; -use web3::types::{BlockNumber, Filter, FilterBuilder, H256, U256}; - -use bigdecimal::{BigDecimal, Num, Zero}; - -use models::plasma::params; -use models::plasma::tx::{DepositTx, ExitTx, TransferTx, TxSignature}; -use models::plasma::{Account, AccountId}; -use models::plasma::{Engine, Fr}; -use plasma::state::PlasmaState; -use web3::types::Log; - -use crate::franklin_transaction::{FranklinTransaction, FranklinTransactionType}; -use crate::helpers::*; - -pub struct FranklinAccountsStates { - pub config: DataRestoreConfig, - pub plasma_state: PlasmaState, -} - -impl FranklinAccountsStates { - pub fn new(config: DataRestoreConfig) -> Self { - Self { - config, - plasma_state: PlasmaState::empty(), - } - } - - pub fn update_accounts_states_from_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - let tx_type = transaction.franklin_transaction_type; - match tx_type { - FranklinTransactionType::Deposit => { - Ok(self.update_accounts_states_from_deposit_transaction(transaction)?) - } - FranklinTransactionType::FullExit => { - Ok(self.update_accounts_states_from_full_exit_transaction(transaction)?) - } - FranklinTransactionType::Transfer => { - Ok(self.update_accounts_states_from_transfer_transaction(transaction)?) - } - _ => Err(DataRestoreError::WrongType), - } - } - - pub fn get_accounts(&self) -> Vec<(u32, Account)> { - self.plasma_state.get_accounts() - } - - pub fn root_hash(&self) -> Fr { - self.plasma_state.root_hash() - } - - pub fn get_account(&self, account_id: AccountId) -> Option { - self.plasma_state.get_account(account_id) - } - - fn update_accounts_states_from_transfer_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - // debug!("tx: {:?}", transaction.ethereum_transaction.hash); - let transfer_txs_block = self - .get_all_transactions_from_transfer_block(transaction) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - for tx in transfer_txs_block { - if let Some(mut from) = self.plasma_state.balance_tree.items.get(&tx.from).cloned() { - let mut transacted_amount = BigDecimal::zero(); - // debug!("amount tx: {:?}", &tx.amount); - transacted_amount += &tx.amount; - transacted_amount += &tx.fee; - - if from.balance < transacted_amount { - return Err(DataRestoreError::WrongAmount); - } - - let mut to = Account::default(); - if let Some(existing_to) = self.plasma_state.balance_tree.items.get(&tx.to) { - to = existing_to.clone(); - } - - from.balance -= transacted_amount; - - from.nonce += 1; - if tx.to != 0 { - to.balance += &tx.amount; - } - - self.plasma_state.balance_tree.insert(tx.from, from); - self.plasma_state.balance_tree.insert(tx.to, to); - } else { - return Err(DataRestoreError::NonexistentAccount); - } - } - Ok(()) - } - - fn update_accounts_states_from_deposit_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - let batch_number = self.get_batch_number(transaction); - // let block_number = self.get_block_number_from_deposit(transaction); - let deposit_txs_block = self - .get_all_transactions_from_deposit_batch(batch_number) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - for tx in deposit_txs_block { - let mut account = self - .plasma_state - .balance_tree - .items - .remove(&tx.account) - .unwrap_or_else(|| { - let mut new_account = Account::default(); - new_account.public_key_x = tx.pub_x; - new_account.public_key_y = tx.pub_y; - new_account.balance = BigDecimal::zero(); - new_account - }); - account.balance += tx.amount; - self.plasma_state.balance_tree.insert(tx.account, account); - } - Ok(()) - } - - fn update_accounts_states_from_full_exit_transaction( - &mut self, - transaction: &FranklinTransaction, - ) -> Result<(), DataRestoreError> { - let batch_number = self.get_batch_number(transaction); - // let block_number = self.get_block_number_from_full_exit(transaction); - let exit_txs_block = self - .get_all_transactions_from_full_exit_batch(batch_number) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - for tx in exit_txs_block { - let _acc = self - .plasma_state - .balance_tree - .items - .get(&tx.account) - .cloned(); - if _acc.is_none() { - return Err(DataRestoreError::NonexistentAccount); - } - self.plasma_state.balance_tree.delete(tx.account); - } - Ok(()) - } - - fn get_batch_number(&self, transaction: &FranklinTransaction) -> U256 { - U256::from(&transaction.commitment_data[0..32]) - } - - // fn get_block_number_from_deposit(&self, transaction: &FranklinTransaction) -> U256 { - // let block_vec = transaction.commitment_data[64..96].to_vec(); - // let block_slice = block_vec.as_slice(); - // U256::from(block_slice) - // } - - // fn get_block_number_from_full_exit(&self, transaction: &FranklinTransaction) -> U256 { - // let block_vec = transaction.commitment_data[64..96].to_vec(); - // let block_slice = block_vec.as_slice(); - // U256::from(block_slice) - // } - - pub fn get_all_transactions_from_transfer_block( - &self, - transaction: &FranklinTransaction, - ) -> Result, DataRestoreError> { - let mut tx_data_vec = transaction.commitment_data.clone(); - // debug!("tx_data_vec: {:?}", tx_data_vec); - // let block_number = &transaction.commitment_data.clone()[0..32]; - // debug!("block_number: {:?}", block_number); - let tx_data_len = tx_data_vec.len(); - // debug!("tx_data_len: {:?}", tx_data_len); - tx_data_vec.reverse(); - tx_data_vec.truncate(tx_data_len - 160); - tx_data_vec.reverse(); - // debug!("tx_data_vec final: {:?}", tx_data_vec); - // tx_data_len = tx_data_vec.len(); - // debug!("tx_data_len final: {:?}", tx_data_len); - let txs = tx_data_vec.chunks(9); - - let mut transfers: Vec = vec![]; - for (i, tx) in txs.enumerate() { - // if tx != [0, 0, 2, 0, 0, 0, 0, 0, 0] { - // let from = U256::from(&tx[0..3]); - // let to = U256::from(&tx[3..6]); - // let amount = U256::from(&tx[6..8]); - // let fee = U256::from(tx[8]); - // let transfer_tx = TransferTx { - // from: from.as_u32(), - // to: to.as_u32(), - // amount: BigDecimal::from_str_radix(&format!("{}", amount), 10).unwrap(), - // fee: BigDecimal::from_str_radix(&format!("{}", fee), 10).unwrap(), - // nonce: 0, - // good_until_block: 0, - // signature: TxSignature::default(), - // cached_pub_key: None, - // }; - // transfers.push(transfer_tx); - // } - let from = U256::from(&tx[0..3]).as_u32(); - let to = U256::from(&tx[3..6]).as_u32(); - let amount = amount_bytes_slice_to_big_decimal(&tx[6..8]); - let fee = fee_bytes_slice_to_big_decimal(tx[8]); - let transfer_tx = TransferTx { - from, - to, - amount: amount.clone(), //BigDecimal::from_str_radix("0", 10).unwrap(), - fee, //BigDecimal::from_str_radix("0", 10).unwrap(), - nonce: i.try_into().unwrap(), - good_until_block: 0, - signature: TxSignature::default(), - cached_pub_key: None, - }; - info!( - "Transaction from account {:?} to account {:?}, amount = {:?}", - from, to, amount - ); - transfers.push(transfer_tx); - } - - Ok(transfers) - } - - fn load_sorted_events( - &self, - action_filter: Filter, - cancel_filter: Filter, - ) -> Result, DataRestoreError> { - let (_eloop, transport) = web3::transports::Http::new(self.config.web3_endpoint.as_str()) - .map_err(|_| DataRestoreError::WrongEndpoint)?; - let web3 = web3::Web3::new(transport); - let action_events = web3 - .eth() - .logs(action_filter) - .wait() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let cancel_events = web3 - .eth() - .logs(cancel_filter) - .wait() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - - // now we have to merge and apply - let mut all_events = vec![]; - all_events.extend(action_events.into_iter()); - all_events.extend(cancel_events.into_iter()); - - all_events = all_events - .into_iter() - .filter(|el| !el.is_removed()) - .collect(); - - // sort by index - let mut error_flag = false; - all_events.sort_by(|l, r| { - let l_block = l.block_number.unwrap(); - let r_block = r.block_number.unwrap(); - - let l_index = l.log_index.unwrap(); - let r_index = r.log_index.unwrap(); - - let ordering = l_block.cmp(&r_block).then(l_index.cmp(&r_index)); - if ordering == Ordering::Equal { - error_flag = true; - } - ordering - }); - if error_flag { - return Err(DataRestoreError::Unknown( - "Logs can not have same indexes".to_string(), - )); - } - Ok(all_events) - } - - pub fn get_all_transactions_from_deposit_batch( - &self, - batch_number: U256, - ) -> Result, DataRestoreError> { - let deposit_event = self - .config - .franklin_contract - .event("LogDepositRequest") - .unwrap() - .clone(); - let deposit_event_topic = deposit_event.signature(); - - let deposit_canceled_event = self - .config - .franklin_contract - .event("LogCancelDepositRequest") - .unwrap() - .clone(); - let deposit_canceled_topic = deposit_canceled_event.signature(); - - let deposits_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![deposit_event_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - let cancels_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![deposit_canceled_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - - let all_events = self.load_sorted_events(deposits_filter, cancels_filter)?; - - let mut this_batch: HashMap = HashMap::new(); - - for event in all_events { - let topic = event.topics[0]; - match () { - () if topic == deposit_event_topic => { - let data_bytes: Vec = event.data.0; - let account_id = U256::from(event.topics[2]); - let public_key = U256::from(event.topics[3]); - let deposit_amount = U256::from_big_endian(&data_bytes); - let _existing_record = this_batch.get(&account_id).cloned(); - if let Some(record) = _existing_record { - let mut existing_balance = record.0; - existing_balance += deposit_amount; - this_batch.insert(account_id, (existing_balance, record.1)); - } else { - this_batch.insert(account_id, (deposit_amount, public_key)); - } - continue; - } - () if topic == deposit_canceled_topic => { - let account_id = U256::from(event.topics[2]); - let _existing_record = this_batch - .get(&account_id) - .cloned() - .ok_or("existing_record not found for deposits")?; - this_batch.remove(&account_id); - continue; - } - _ => return Err(DataRestoreError::Unknown("unexpected topic".to_string())), - } - } - - let mut all_deposits = vec![]; - for (k, v) in this_batch.iter() { - info!( - "Into account {:?} with public key {:x}, deposit amount = {:?}", - k, v.1, v.0 - ); - let mut public_key_bytes = vec![0u8; 32]; - v.1.to_big_endian(&mut public_key_bytes); - let x_sign = public_key_bytes[0] & 0x80 > 0; - public_key_bytes[0] &= 0x7f; - let mut fe_repr = Fr::zero().into_repr(); - fe_repr - .read_be(public_key_bytes.as_slice()) - .expect("read public key point"); - let y = Fr::from_repr(fe_repr); - if y.is_err() { - return Err(DataRestoreError::WrongPubKey); - } - let public_key_point = edwards::Point::::get_for_y( - y.unwrap(), - x_sign, - ¶ms::JUBJUB_PARAMS, - ); - if public_key_point.is_none() { - return Err(DataRestoreError::WrongPubKey); - } - - let (pub_x, pub_y) = public_key_point.unwrap().into_xy(); - - let tx: DepositTx = DepositTx { - account: k.as_u32(), - amount: BigDecimal::from_str_radix(&format!("{}", v.0), 10).unwrap(), - pub_x, - pub_y, - }; - all_deposits.push(tx); - } - Ok(all_deposits) - } - - pub fn get_all_transactions_from_full_exit_batch( - &self, - batch_number: U256, - ) -> Result, DataRestoreError> { - let exit_event = self - .config - .franklin_contract - .event("LogExitRequest") - .unwrap() - .clone(); - let exit_event_topic = exit_event.signature(); - - let exit_canceled_event = self - .config - .franklin_contract - .event("LogCancelExitRequest") - .unwrap() - .clone(); - let exit_canceled_topic = exit_canceled_event.signature(); - - let exits_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![exit_event_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - - let cancels_filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(BlockNumber::Earliest) - .to_block(BlockNumber::Latest) - .topics( - Some(vec![exit_canceled_topic]), - Some(vec![H256::from(batch_number)]), - None, - None, - ) - .build(); - - let all_events = self.load_sorted_events(exits_filter, cancels_filter)?; - - let mut this_batch: HashSet = HashSet::new(); - - for event in all_events { - let topic = event.topics[0]; - match () { - () if topic == exit_event_topic => { - let account_id = U256::from(event.topics[2]); - let existing_record = this_batch.get(&account_id).cloned(); - if existing_record.is_some() { - return Err(DataRestoreError::DoubleExit); - } else { - this_batch.insert(account_id); - } - continue; - } - () if topic == exit_canceled_topic => { - let account_id = U256::from(event.topics[2]); - this_batch - .get(&account_id) - .cloned() - .ok_or_else(|| "existing_record fetch failed".to_owned())?; - this_batch.remove(&account_id); - continue; - } - _ => return Err(DataRestoreError::Unknown("unexpected topic".to_string())), - } - } - - let mut all_exits = vec![]; - for k in this_batch.iter() { - info!("Exit from account {:?}", k); - - let tx: ExitTx = ExitTx { - account: k.as_u32(), - amount: BigDecimal::zero(), - }; - all_exits.push(tx); - } - - Ok(all_exits) - } -} diff --git a/core/data_restore/src/block_events/mod.rs b/core/data_restore/src/block_events/mod.rs deleted file mode 100644 index a96e8f5f4d..0000000000 --- a/core/data_restore/src/block_events/mod.rs +++ /dev/null @@ -1,397 +0,0 @@ -// use std::rc::Rc; - -use web3::futures::Future; -use web3::types::{BlockNumber, FilterBuilder, Log, H256, U256}; -// use tokio_core::reactor::Core; - -use crate::blocks::{BlockType, LogBlockData}; -use crate::helpers::*; - -type ComAndVerBlocksVecs = (Vec, Vec); -type BlockNumber256 = U256; - -#[derive(Debug, Clone)] -pub struct BlockEventsFranklin { - pub config: DataRestoreConfig, - pub committed_blocks: Vec, - pub verified_blocks: Vec, - pub last_watched_block_number: BlockNumber256, -} - -// Set new -// Get last block -// Get blocks till last - delta, set last watching block -// Subscribe on new blocks -// New blocks -> last watching block ++ -// Check if txs in last watching block -impl BlockEventsFranklin { - pub fn new(config: DataRestoreConfig) -> Self { - Self { - // ws_endpoint_string: ws_infura_endpoint_string, - config, - committed_blocks: vec![], - verified_blocks: vec![], - last_watched_block_number: U256::from(0), - } - } - - pub fn get_past_state_from_genesis_with_blocks_delta( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - ) -> Result { - let mut this = BlockEventsFranklin::new(config); - let (blocks, to_block_number): (ComAndVerBlocksVecs, BlockNumber256) = this - .get_sorted_past_logs_from_genesis(genesis_block, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - this.committed_blocks = blocks.0; - this.verified_blocks = blocks.1; - this.last_watched_block_number = U256::from(to_block_number.as_u64()); - Ok(this) - } - - pub fn update_state_from_last_watched_block_with_blocks_delta_and_return_new_blocks( - &mut self, - blocks_delta: U256, - ) -> Result { - let (blocks, to_block_number): (ComAndVerBlocksVecs, BlockNumber256) = self - .get_sorted_past_logs_from_last_watched_block(blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let blocks_for_return = blocks.clone(); - self.committed_blocks.extend(blocks.0); - self.verified_blocks.extend(blocks.1); - self.last_watched_block_number = U256::from(to_block_number.as_u64()); - Ok(blocks_for_return) - } - - pub fn get_only_verified_committed_blocks( - &self, - verified_blocks: &[LogBlockData], - ) -> Vec<&LogBlockData> { - let iter_ver_blocks = verified_blocks.iter(); - // let committed_blocks_iter = &mut self.com_blocks.iter(); - let mut ver_com_blocks = vec![]; - for block in iter_ver_blocks { - let find_com_block = self.check_committed_block_with_same_number_as_verified(block); - if find_com_block.is_none() { - continue; - } - ver_com_blocks.push(find_com_block.unwrap()) - } - ver_com_blocks.sort_by_key(|&x| x.block_num); - ver_com_blocks - } - - // pub fn get_only_verified_committed_blocks(&self) -> Vec<&LogBlockData> { - // let ver_blocks = &mut self.verified_blocks.iter(); - // // let committed_blocks_iter = &mut self.com_blocks.iter(); - // let mut ver_com_blocks = vec![]; - // for block in ver_blocks { - // let find_com_block = self.check_committed_block_with_same_number_as_verified(block); - // if find_com_block.is_none() { - // continue; - // } - // ver_com_blocks.push(find_com_block.unwrap()) - // } - // ver_com_blocks.sort_by_key(|&x| x.block_num); - // ver_com_blocks - // } - - pub fn check_committed_block_with_same_number_as_verified( - &self, - verified_block: &LogBlockData, - ) -> Option<&LogBlockData> { - let committed_blocks_iter = &mut self.committed_blocks.iter(); - committed_blocks_iter.find(|&&x| x.block_num == verified_block.block_num) - } - - pub fn get_committed_blocks(&self) -> &Vec { - &self.committed_blocks - } - - pub fn get_verified_blocks(&self) -> &Vec { - &self.verified_blocks - } - - pub fn get_last_block_number(&mut self) -> Result { - let (_eloop, transport) = web3::transports::Http::new(self.config.web3_endpoint.as_str()) - .map_err(|_| DataRestoreError::WrongEndpoint)?; - let web3 = web3::Web3::new(transport); - let last_block_number = web3 - .eth() - .block_number() - .wait() - .map_err(|e| DataRestoreError::Unknown(e.to_string()))?; - Ok(last_block_number) - } - - // returns (committed blocks logs, verified blocks logs) - fn sort_logs(&mut self, logs: &[Log]) -> Result { - if logs.is_empty() { - return Err(DataRestoreError::NoData("No logs in list".to_string())); - } - let mut committed_blocks: Vec = vec![]; - let mut verified_blocks: Vec = vec![]; - let block_verified_topic = "BlockVerified(uint32)"; - let block_committed_topic = "BlockCommitted(uint32)"; - let block_verified_topic_h256: H256 = get_topic_keccak_hash(block_verified_topic); - let block_committed_topic_h256: H256 = get_topic_keccak_hash(block_committed_topic); - for log in logs { - let mut block: LogBlockData = LogBlockData { - block_num: 0, - transaction_hash: H256::zero(), - block_type: BlockType::Unknown, - }; - // Log data - let tx_hash = log.transaction_hash; - let topic = log.topics[0]; - let block_num = log.topics[1]; - - match tx_hash { - Some(hash) => { - block.block_num = U256::from(block_num).as_u32(); - block.transaction_hash = hash; - - if topic == block_verified_topic_h256 { - block.block_type = BlockType::Verified; - verified_blocks.push(block); - // let result = self.check_committed_block_with_same_number_as_verified(&block); - // debug!("Block exists: {:?}", result); - // let tx = result.unwrap().clone().transaction_hash; - // debug!("--- Starting getting tx"); - // let data = FranklinTransaction::get_transaction(InfuraEndpoint::Rinkeby, &tx); - // debug!("TX data committed: {:?}", data); - } else if topic == block_committed_topic_h256 { - block.block_type = BlockType::Committed; - committed_blocks.push(block); - } - } - None => warn!("No tx hash"), - }; - } - committed_blocks.sort_by_key(|x| x.block_num); - verified_blocks.sort_by_key(|x| x.block_num); - Ok((committed_blocks, verified_blocks)) - } - - fn get_logs( - &mut self, - from_block_number: BlockNumber, - to_block_number: BlockNumber, - ) -> Result, DataRestoreError> { - // let contract = Contract::new(web3.eth(), franklin_address.clone(), franklin_contract.clone()); - - // Events topics - let block_verified_topic = "BlockVerified(uint32)"; - let block_committed_topic = "BlockCommitted(uint32)"; - let block_verified_topic_h256: H256 = get_topic_keccak_hash(block_verified_topic); - let block_committed_topic_h256: H256 = get_topic_keccak_hash(block_committed_topic); - - let topics_vec_h256: Vec = - vec![block_verified_topic_h256, block_committed_topic_h256]; - - // Filter - let filter = FilterBuilder::default() - .address(vec![self.config.franklin_contract_address]) - .from_block(from_block_number) - .to_block(to_block_number) - .topics(Some(topics_vec_h256), None, None, None) - .build(); - - // Filter result - let (_eloop, transport) = web3::transports::Http::new(self.config.web3_endpoint.as_str()) - .map_err(|_| DataRestoreError::WrongEndpoint)?; - let web3 = web3::Web3::new(transport); - let result = web3 - .eth() - .logs(filter) - .wait() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - if result.is_empty() { - return Err(DataRestoreError::NoData("No logs in list".to_string())); - } - Ok(result) - } - - pub fn get_sorted_logs_in_block( - &mut self, - block_number: BlockNumber256, - ) -> Result { - let block_to_get_logs = BlockNumber::Number(block_number.as_u64()); - let logs = self - .get_logs(block_to_get_logs, block_to_get_logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let result = self - .sort_logs(&logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok(result) - } - - fn get_past_logs( - &mut self, - from_block_number: U256, - blocks_delta: U256, - ) -> Result<(Vec, BlockNumber256), DataRestoreError> { - // Set web3 - let last_block_number = self - .get_last_block_number() - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let to_block_numer_256 = last_block_number - blocks_delta; - to_block_numer_256 - .checked_sub(from_block_number) - .ok_or_else(|| DataRestoreError::NoData("No new blocks".to_string()))?; - let to_block_number = BlockNumber::Number(to_block_numer_256.as_u64()); - let from_block_number = BlockNumber::Number(from_block_number.as_u64()); - - let logs = self - .get_logs(from_block_number, to_block_number) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok((logs, to_block_numer_256)) - } - - // returns (committed blocks logs, verified blocks logs) from genesis to (last block minus delta) - fn get_sorted_past_logs_from_last_watched_block( - &mut self, - blocks_delta: U256, - ) -> Result<(ComAndVerBlocksVecs, BlockNumber256), DataRestoreError> { - let from_block_number = self.last_watched_block_number + 1; - let (logs, to_block_number) = self - .get_past_logs(from_block_number, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let sorted_logs = self - .sort_logs(&logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok((sorted_logs, to_block_number)) - } - - // returns (committed blocks logs, verified blocks logs) from genesis to (last block minus delta) - fn get_sorted_past_logs_from_genesis( - &mut self, - genesis_block: U256, - blocks_delta: U256, - ) -> Result<(ComAndVerBlocksVecs, BlockNumber256), DataRestoreError> { - let from_block_number = genesis_block; - let (logs, to_block_number) = self - .get_past_logs(from_block_number, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - let sorted_logs = self - .sort_logs(&logs) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - Ok((sorted_logs, to_block_number)) - } - - // // - Get new block - // // - Need to watch block + 1 - // // - Get events from need to watch block - // // - Sort them to committed and verified - // // - Write to committed_blocks and verified_blocks - // pub fn make_new_sorted_logs_subscription(&mut self, eloop: &mut Core) { - // // Setup loop and web3 - // // let mut eloop = Core::new().unwrap(); - // let handle = eloop.handle(); - // let web3_endpoint = Rc::new(web3::Web3::new( - // web3::transports::WebSocket::with_event_loop(self.ws_endpoint_string.as_str(), &handle) - // .unwrap(), - // )); - - // // Subscription - // debug!("subscribing to new blocks"); - - // let future = web3_endpoint.eth_subscribe() - // .subscribe_new_heads() - // .and_then(|sub| { - // sub.for_each(|log| { - // debug!("---"); - // debug!("Got block number {:?}", log.number); - // let number_to_watch = self.last_watched_block_number + 1; - // self.last_watched_block_number = number_to_watch; - // debug!("Block to watch {:?}", &number_to_watch); - // match self.get_sorted_logs_in_block(number_to_watch) { - // Ok(mut result) => { - // debug!("Old committed blocks array len: {:?}", &self.committed_blocks.len()); - // debug!("Old verified blocks array len: {:?}", &self.verified_blocks.len()); - // debug!("Got sorted logs"); - // debug!("Committed: {:?}", &result.0); - // debug!("Verified: {:?}", &result.1); - // self.committed_blocks.append(&mut result.0); - // self.verified_blocks.append(&mut result.1); - // debug!("New committed blocks array len: {:?}", &self.committed_blocks.len()); - // debug!("New verified blocks array len: {:?}", &self.verified_blocks.len()); - - // }, - // Err(_) => { - // debug!("No new blocks"); - // } - // }; - // Ok(()) - // }) - // }) - // .map_err(|e| error!("franklin log err: {}", e)); - - // // Run eloop - // if let Err(_err) = eloop.run(future) { - // error!("Cant run eloop"); - // } - // } - - // pub fn subscribe_to_logs(&mut self) { - - // // Get topic keccak hash - // let block_verified_topic = "BlockVerified(uint32)"; - // let block_committed_topic = "BlockCommitted(uint32)"; - // let block_verified_topic_h256: H256 = helpers::get_topic_keccak_hash(block_verified_topic); - // let block_committed_topic_h256: H256 = helpers::get_topic_keccak_hash(block_committed_topic); - - // let topics_vec_h256: Vec = vec![block_verified_topic_h256, block_committed_topic_h256]; - - // // Setup loop and web3 - // let mut eloop = Core::new().unwrap(); - // let handle = eloop.handle(); - // let w3 = Rc::new(web3::Web3::new( - // web3::transports::WebSocket::with_event_loop(self.ws_endpoint_string.as_str(), &handle) - // .unwrap(), - // )); - - // // Subscription - // debug!("subscribing to franklin logs {:?} {:?}...", block_verified_topic, block_committed_topic); - - // let filter = FilterBuilder::default() - // .address(vec![self.franklin_contract_address.clone()]) - // .topics( - // Some(topics_vec_h256), - // None, - // None, - // None, - // ) - // .build(); - - // let future = w3.eth_subscribe() - // .subscribe_logs(filter) - // .and_then(|sub| { - // sub.for_each(|log| { - // debug!("---"); - // debug!("got log from subscription: {:?}", log); - - // let mut sorted_blocks = self.sort_logs(&vec![log]).unwrap(); - // self.committed_blocks.append(&mut sorted_blocks.0); - // self.verified_blocks.append(&mut sorted_blocks.1); - // // let result = self.check_committed_block_with_same_number_as_verified(&block); - // // debug!("Block exists: {:?}", result); - // // let tx = result.unwrap().clone().transaction_hash; - // // debug!("--- Starting getting tx"); - // // let data = FranklinTransaction::get_transaction(InfuraEndpoint::Rinkeby, &tx); - // // debug!("TX data committed: {:?}", data); - - // debug!("Verified blocks in storage: {:?}", self.verified_blocks); - // debug!("Committed blocks in storage: {:?}", self.committed_blocks); - // Ok(()) - // }) - // }) - // .map_err(|e| error!("franklin log err: {}", e)); - - // // Run eloop - // if let Err(_err) = eloop.run(future) { - // error!("ERROR"); - // } - // } -} diff --git a/core/data_restore/src/blocks/mod.rs b/core/data_restore/src/blocks/mod.rs deleted file mode 100644 index 5ae1d60e0d..0000000000 --- a/core/data_restore/src/blocks/mod.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::cmp::Ordering; -use web3::types::H256; - -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum BlockType { - Committed, - Verified, - Unknown, -} - -#[derive(Debug, Copy, Clone, Eq)] -pub struct LogBlockData { - pub block_num: u32, - pub transaction_hash: H256, - pub block_type: BlockType, -} - -impl PartialOrd for LogBlockData { - fn partial_cmp(&self, other: &LogBlockData) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for LogBlockData { - fn cmp(&self, other: &LogBlockData) -> Ordering { - self.block_num.cmp(&other.block_num) - } -} - -impl PartialEq for LogBlockData { - fn eq(&self, other: &LogBlockData) -> bool { - self.block_num == other.block_num - } -} diff --git a/core/data_restore/src/data_restore_driver.rs b/core/data_restore/src/data_restore_driver.rs deleted file mode 100644 index a2d687dd14..0000000000 --- a/core/data_restore/src/data_restore_driver.rs +++ /dev/null @@ -1,307 +0,0 @@ -use crate::accounts_state::FranklinAccountsStates; -use crate::block_events::BlockEventsFranklin; -use crate::blocks::LogBlockData; -use crate::franklin_transaction::FranklinTransaction; -use crate::helpers::*; -use models::plasma::Fr; -use std::sync::mpsc::Sender; -use web3::types::U256; - -#[allow(dead_code)] -pub struct ProtoAccountsState { - errored: bool, - root_hash: Fr, -} - -pub struct DataRestoreDriver { - pub channel: Option>, - pub config: DataRestoreConfig, - pub genesis_block: U256, - pub blocks_delta: U256, - pub run_updates: bool, - pub block_events: BlockEventsFranklin, - pub account_states: FranklinAccountsStates, -} - -impl DataRestoreDriver { - pub fn new( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - channel: Option>, - ) -> Self { - Self { - channel, - config: config.clone(), - genesis_block, - blocks_delta, - run_updates: false, - block_events: BlockEventsFranklin::new(config.clone()), - account_states: FranklinAccountsStates::new(config.clone()), - } - } - - pub fn load_past_state(&mut self) -> Result<(), DataRestoreError> { - info!("Loading past state"); - let states = DataRestoreDriver::get_past_franklin_blocks_events_and_accounts_tree_state( - self.config.clone(), - self.genesis_block, - self.blocks_delta, - ) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - self.block_events = states.0; - self.account_states = states.1; - - // let accs = &self.account_states.get_accounts(); - // debug!("Accs: {:?}", accs); - let root = self.account_states.root_hash(); - debug!("Root: {:?}", &root); - debug!("______________"); - - if let Some(ref _channel) = self.channel { - let state = ProtoAccountsState { - errored: false, - root_hash: root, - }; - let _send_result = _channel.send(state); - if _send_result.is_err() { - return Err(DataRestoreError::StateUpdate( - "Cant send last state".to_string(), - )); - } - } - debug!("Finished loading past state"); - Ok(()) - } - - pub fn stop_state_updates(&mut self) { - self.run_updates = false - } - - pub fn run_state_updates(&mut self) -> Option { - info!("Start state updates"); - self.run_updates = true; - let mut err: Option = None; - while self.run_updates { - // match DataRestoreDriver::update_franklin_blocks_events_and_accounts_tree_state(self) { - // Err(error) => { - // error!("Something goes wrong: {:?}", error); - // self.run_updates = false; - // err = Some(DataRestoreError::StateUpdate(format!( - // "Error occured: {:?}", - // error - // ))); - // } - // Ok(()) => { - // // debug!("Updated, last watched ethereum block: {:?}", &self.block_events.last_watched_block_number); - // // debug!("Committed franklin blocks count: {:?}", &self.block_events.committed_blocks.len()); - // // debug!("Last committed franklin block: {:?}", &self.block_events.committed_blocks.last()); - // // debug!("Verified franklin blocks count: {:?}", &self.block_events.verified_blocks.len()); - // // debug!("Last verified franklin block: {:?}", &self.block_events.verified_blocks.last()); - // // let accs = self.account_states.get_accounts(); - // // let root = self.account_states.root_hash(); - // // debug!("Accs: {:?}", accs); - // // debug!("Root: {:?}", &root); - // } - // }; - if let Err(error) = - DataRestoreDriver::update_franklin_blocks_events_and_accounts_tree_state(self) - { - error!("Something goes wrong: {:?}", error); - self.run_updates = false; - err = Some(DataRestoreError::StateUpdate(format!( - "Error occured: {:?}", - error - ))); - } - let root = self.account_states.root_hash(); - debug!("New root: {:?}", root); - debug!("______________"); - if let Some(ref _channel) = self.channel { - let state = ProtoAccountsState { - errored: !self.run_updates, - root_hash: root, - }; - let _send_result = _channel.send(state); - if _send_result.is_err() { - self.run_updates = false; - err = Some(DataRestoreError::StateUpdate( - "Cant send last state".to_string(), - )); - } - } - } - debug!("Stopped state updates"); - err - } - - fn get_past_franklin_blocks_events_and_accounts_tree_state( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - ) -> Result<(BlockEventsFranklin, FranklinAccountsStates), DataRestoreError> { - let events_state = - DataRestoreDriver::get_past_blocks_state(config.clone(), genesis_block, blocks_delta) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - // debug!("Last watched block: {:?}", events_state.last_watched_block_number); - let verified_blocks = events_state.verified_blocks.clone(); - let txs = DataRestoreDriver::get_verified_committed_blocks_transactions_from_blocks_state( - &events_state, - &verified_blocks, - ); - let sorted_txs = DataRestoreDriver::sort_transactions_by_block_number(txs); - // debug!("Transactions: {:?}", sorted_txs); - - let mut accounts_state = FranklinAccountsStates::new(config.clone()); - DataRestoreDriver::update_accounts_state_from_transactions( - &mut accounts_state, - &sorted_txs, - ) - .map_err(|e| DataRestoreError::StateUpdate(e.to_string()))?; - info!("Accounts and events state finished update"); - Ok((events_state, accounts_state)) - } - - fn get_past_blocks_state( - config: DataRestoreConfig, - genesis_block: U256, - blocks_delta: U256, - ) -> Result { - let events = BlockEventsFranklin::get_past_state_from_genesis_with_blocks_delta( - config, - genesis_block, - blocks_delta, - ) - .map_err(|e| DataRestoreError::NoData(e.to_string()))?; - debug!( - "Got past events state till ethereum block: {:?}", - &events.last_watched_block_number - ); - debug!( - "Committed franklin blocks count: {:?}", - &events.committed_blocks.len() - ); - debug!( - "Last committed franklin block: {:?}", - &events.committed_blocks.last() - ); - debug!( - "Verified franklin blocks count: {:?}", - &events.verified_blocks.len() - ); - debug!( - "Last verified franklin block: {:?}", - &events.verified_blocks.last() - ); - Ok(events) - } - - fn get_verified_committed_blocks_transactions_from_blocks_state( - block_events_state: &BlockEventsFranklin, - verified_blocks: &[LogBlockData], - ) -> Vec { - let committed_blocks = - block_events_state.get_only_verified_committed_blocks(verified_blocks); - // debug!("Committed verified blocks: {:?}", committed_blocks); - let mut transactions = vec![]; - for block in committed_blocks { - let tx = FranklinTransaction::get_transaction(&block_events_state.config, &block); - if tx.is_none() { - continue; - } - transactions.push(tx.unwrap()); - } - debug!("Transactions sorted: only verified commited"); - transactions - } - - fn sort_transactions_by_block_number( - transactions: Vec, - ) -> Vec { - let mut sorted_transactions = transactions; - sorted_transactions.sort_by_key(|x| x.block_number); - debug!("Transactions sorted: by number"); - sorted_transactions - } - - fn update_accounts_state_from_transactions( - state: &mut FranklinAccountsStates, - transactions: &[FranklinTransaction], - ) -> Result<(), DataRestoreError> { - // let mut state = accounts_state::FranklinAccountsStates::new(config); - debug!("Start accounts state updating"); - for transaction in transactions { - state - .update_accounts_states_from_transaction(&transaction) - .map_err(|e| DataRestoreError::StateUpdate(e.to_string()))?; - } - debug!("Finished accounts state updating"); - Ok(()) - } - - fn update_franklin_blocks_events_and_accounts_tree_state( - data_restore_driver: &mut DataRestoreDriver, - ) -> Result<(), DataRestoreError> { - let mut new_events: (Vec, Vec) = (vec![], vec![]); - while data_restore_driver.run_updates { - let ne = data_restore_driver - .block_events - .update_state_from_last_watched_block_with_blocks_delta_and_return_new_blocks( - data_restore_driver.blocks_delta, - ); - match ne { - Ok(result) => new_events = result, - Err(error) => { - debug!("Got no events: {:?}", error); - continue; - } - } - if new_events.1.is_empty() { - debug!("No new verified blocks"); - continue; - // return Err(DataRestoreError::NoData("No verified blocks".to_string())) - } else { - debug!( - "Got new events state till ethereum block: {:?}", - &data_restore_driver.block_events.last_watched_block_number - ); - debug!( - "Committed franklin blocks count: {:?}", - &data_restore_driver.block_events.committed_blocks.len() - ); - debug!( - "Last committed franklin block: {:?}", - &data_restore_driver.block_events.committed_blocks.last() - ); - debug!( - "Verified franklin blocks count: {:?}", - &data_restore_driver.block_events.verified_blocks.len() - ); - debug!( - "Last verified franklin block: {:?}", - &data_restore_driver.block_events.verified_blocks.last() - ); - break; - } - } - if !data_restore_driver.run_updates { - return Err(DataRestoreError::StateUpdate( - "Stopped getting new blocks".to_string(), - )); - } - let verified_blocks = &new_events.1; - let txs = DataRestoreDriver::get_verified_committed_blocks_transactions_from_blocks_state( - &data_restore_driver.block_events, - &verified_blocks, - ); - let sorted_txs = DataRestoreDriver::sort_transactions_by_block_number(txs); - - DataRestoreDriver::update_accounts_state_from_transactions( - &mut data_restore_driver.account_states, - &sorted_txs, - ) - .map_err(|e| DataRestoreError::StateUpdate(e.to_string()))?; - - Ok(()) - } -} diff --git a/core/data_restore/src/franklin_transaction/mod.rs b/core/data_restore/src/franklin_transaction/mod.rs deleted file mode 100644 index 995fe32513..0000000000 --- a/core/data_restore/src/franklin_transaction/mod.rs +++ /dev/null @@ -1,88 +0,0 @@ -use web3::futures::Future; -use web3::types::{Transaction, TransactionId, H256}; - -use crate::blocks::LogBlockData; -use crate::helpers::*; - -#[derive(Debug, Copy, Clone)] -pub enum FranklinTransactionType { - Deposit, - Transfer, - FullExit, - Unknown, -} - -#[derive(Debug, Clone)] -pub struct FranklinTransaction { - pub franklin_transaction_type: FranklinTransactionType, - pub block_number: u32, - pub ethereum_transaction: Transaction, - pub commitment_data: Vec, -} - -impl FranklinTransaction { - pub fn get_transaction( - config: &DataRestoreConfig, - franklin_block: &LogBlockData, - ) -> Option { - let transaction = FranklinTransaction::get_ethereum_transaction( - config, - &franklin_block.transaction_hash, - )?; - let input_data = - FranklinTransaction::get_input_data_from_ethereum_transaction(&transaction); - let tx_type = FranklinTransaction::get_transaction_type(&input_data); - let commitment_data = - FranklinTransaction::get_commitment_data_from_input_data(&input_data)?; - let this = Self { - franklin_transaction_type: tx_type, - block_number: franklin_block.block_num, - ethereum_transaction: transaction, - commitment_data, - }; - Some(this) - } - - fn get_ethereum_transaction( - config: &DataRestoreConfig, - &transaction_hash: &H256, - ) -> Option { - let tx_id = TransactionId::Hash(transaction_hash); - let (_eloop, transport) = - web3::transports::Http::new(config.web3_endpoint.as_str()).ok()?; - let web3 = web3::Web3::new(transport); - let web3_transaction = web3.eth().transaction(tx_id).wait(); - match web3_transaction { - Ok(tx) => tx, - Err(_) => None, - } - } - - fn get_input_data_from_ethereum_transaction(transaction: &Transaction) -> Vec { - transaction.clone().input.0 - } - - fn get_commitment_data_from_input_data(input_data: &[u8]) -> Option> { - if input_data.len() > 4 { - Some(input_data[4..input_data.len()].to_vec()) - } else { - None - } - } - - fn get_transaction_type(input_data: &[u8]) -> FranklinTransactionType { - if input_data.len() <= 4 { - return FranklinTransactionType::Unknown; - } - let deposit_method_bytes: Vec = vec![83, 61, 227, 10]; - let transaction_method_bytes: Vec = vec![244, 135, 178, 142]; - let full_exit_method_bytes: Vec = vec![121, 178, 173, 112]; - let method_bytes: Vec = input_data[0..4].to_vec(); - match method_bytes { - _ if method_bytes == deposit_method_bytes => FranklinTransactionType::Deposit, - _ if method_bytes == transaction_method_bytes => FranklinTransactionType::Transfer, - _ if method_bytes == full_exit_method_bytes => FranklinTransactionType::FullExit, - _ => FranklinTransactionType::Unknown, - } - } -} diff --git a/core/data_restore/src/helpers/mod.rs b/core/data_restore/src/helpers/mod.rs deleted file mode 100644 index 13e84a8b6b..0000000000 --- a/core/data_restore/src/helpers/mod.rs +++ /dev/null @@ -1,178 +0,0 @@ -use bigdecimal::BigDecimal; -use bitvec::prelude::*; -use ethabi::Contract; -use models::abi::{PROD_PLASMA, TEST_PLASMA_ALWAYS_VERIFY}; -use models::config::RuntimeConfig; -use models::plasma::params as plasma_constants; -use sapling_crypto::circuit::float_point::parse_float_to_u128; -use tiny_keccak::keccak256; -use web3::types::{Address, H256}; - -/// Configuratoin of DataRestore driver -#[derive(Debug, Clone)] -pub struct DataRestoreConfig { - /// Web3 endpoint url string - pub web3_endpoint: String, - /// Provides Ethereum Franklin contract unterface - pub franklin_contract: Contract, - /// Ethereum Franklin contract address is type of H160 - pub franklin_contract_address: Address, -} - -impl DataRestoreConfig { - /// Return the configuration for setted Infura web3 endpoint - /// - /// # Arguments - /// - /// * `network` - Infura web3 endpoint - /// - pub fn new(network: InfuraEndpoint) -> Self { - let config = RuntimeConfig::new(); - match network { - InfuraEndpoint::Mainnet => { - Self { - web3_endpoint: config.mainnet_http_endpoint_string, //"https://rinkeby.infura.io/".to_string(), - franklin_contract: ethabi::Contract::load(PROD_PLASMA.0).unwrap(), - franklin_contract_address: config - .mainnet_franklin_contract_address - .as_str() - .parse() - .unwrap(), //"4fbf331db438c88a83b1316d072b7d73d8366367".parse().unwrap() - } - } - InfuraEndpoint::Rinkeby => { - Self { - web3_endpoint: config.rinkeby_http_endpoint_string, //"https://rinkeby.infura.io/".to_string() - franklin_contract: ethabi::Contract::load(TEST_PLASMA_ALWAYS_VERIFY.0).unwrap(), - franklin_contract_address: config - .rinkeby_franklin_contract_address - .as_str() - .parse() - .unwrap(), //"4fbf331db438c88a83b1316d072b7d73d8366367".parse().unwrap() - } - } - } - } -} - -/// Infura web3 endpoint -#[derive(Debug, Copy, Clone)] -pub enum InfuraEndpoint { - Mainnet, - Rinkeby, -} - -/// Returns bytes vec of keccak256 hash from bytes -/// -/// # Arguments -/// -/// * `bytes` - ref to bytes array -/// -pub fn keccak256_hash(bytes: &[u8]) -> Vec { - keccak256(bytes).iter().cloned().collect() -} - -/// Returns keccak256 topic hash (H256) from topic str -/// -/// # Arguments -/// -/// * `topic` - indexed func name and args, represented in ref to str -/// -pub fn get_topic_keccak_hash(topic: &str) -> web3::types::H256 { - let topic_data: Vec = From::from(topic); - let topic_data_vec: &[u8] = topic_data.as_slice(); - let topic_keccak_data: Vec = keccak256_hash(topic_data_vec); - let topic_keccak_data_vec: &[u8] = topic_keccak_data.as_slice(); - H256::from_slice(topic_keccak_data_vec) -} - -/// Returns BigDecimal repr of amount bytes slice -/// -/// # Arguments -/// -/// * `bytes` - amount bytes slice -/// -pub fn amount_bytes_slice_to_big_decimal(bytes: &[u8]) -> BigDecimal { - let vec = bytes.to_vec(); - let bit_vec: BitVec = vec.into(); - let mut bool_vec: Vec = vec![]; - for i in bit_vec { - bool_vec.push(i); - } - let amount_u128: u128 = parse_float_to_u128( - bool_vec, - plasma_constants::AMOUNT_EXPONENT_BIT_WIDTH, - plasma_constants::AMOUNT_MANTISSA_BIT_WIDTH, - 10, - ) - .unwrap_or(0); - let amount_u64 = amount_u128 as u64; - // amount_f64 = amount_f64 / f64::from(1000000); - BigDecimal::from(amount_u64) -} - -/// Returns BigDecimal repr of fee bytes slice -/// -/// # Arguments -/// -/// * `bytes` - fee bytes slice -/// -pub fn fee_bytes_slice_to_big_decimal(byte: u8) -> BigDecimal { - let bit_vec: BitVec = BitVec::from_element(byte); - let mut bool_vec: Vec = vec![]; - for i in bit_vec { - bool_vec.push(i); - } - let fee_u128: u128 = parse_float_to_u128( - bool_vec, - plasma_constants::FEE_EXPONENT_BIT_WIDTH, - plasma_constants::FEE_MANTISSA_BIT_WIDTH, - 10, - ) - .unwrap_or(0); - let fee_u64 = fee_u128 as u64; - // fee_f64 = fee_f64 / f64::from(1000000); - BigDecimal::from(fee_u64) -} - -/// Specific errors that may occure during data restoring -#[derive(Debug, Clone)] -pub enum DataRestoreError { - Unknown(String), - WrongType, - NoData(String), - NonexistentAccount, - WrongAmount, - WrongEndpoint, - WrongPubKey, - DoubleExit, - StateUpdate(String), -} - -impl std::string::ToString for DataRestoreError { - fn to_string(&self) -> String { - match self { - DataRestoreError::Unknown(text) => format!("Unknown {}", text), - DataRestoreError::WrongType => "Wrong type".to_owned(), - DataRestoreError::NoData(text) => format!("No data {}", text), - DataRestoreError::NonexistentAccount => "Nonexistent account".to_owned(), - DataRestoreError::WrongAmount => "Wrong amount".to_owned(), - DataRestoreError::WrongEndpoint => "Wrong endpoint".to_owned(), - DataRestoreError::WrongPubKey => "Wrong pubkey".to_owned(), - DataRestoreError::DoubleExit => "Double exit".to_owned(), - DataRestoreError::StateUpdate(text) => format!("Error during state update {}", text), - } - } -} - -impl std::convert::From<&str> for DataRestoreError { - fn from(a: &str) -> Self { - DataRestoreError::Unknown(a.to_string()) - } -} - -impl std::convert::From for DataRestoreError { - fn from(a: String) -> Self { - DataRestoreError::Unknown(a) - } -} diff --git a/core/data_restore/src/lib.rs b/core/data_restore/src/lib.rs deleted file mode 100644 index 972015ebde..0000000000 --- a/core/data_restore/src/lib.rs +++ /dev/null @@ -1,62 +0,0 @@ -#[macro_use] -extern crate log; - -pub mod accounts_state; -pub mod block_events; -pub mod blocks; -pub mod data_restore_driver; -pub mod franklin_transaction; -pub mod helpers; - -use crate::data_restore_driver::{DataRestoreDriver, ProtoAccountsState}; -use std::sync::mpsc::Sender; -use web3::types::U256; - -pub fn create_new_data_restore_driver( - config: helpers::DataRestoreConfig, - from: U256, - delta: U256, - channel: Option>, -) -> DataRestoreDriver { - DataRestoreDriver::new(config, from, delta, channel) -} - -pub fn load_past_state_for_data_restore_driver(driver: &mut DataRestoreDriver) { - driver.load_past_state().expect("Cant get past state"); -} - -pub fn load_new_states_for_data_restore_driver(driver: &'static mut DataRestoreDriver) { - std::thread::Builder::new() - .name("data_restore".to_string()) - .spawn(move || { - driver.run_state_updates().expect("Cant update state"); - }) - .expect("Load new states for data restore thread"); -} - -pub fn start_data_restore_driver(driver: &'static mut DataRestoreDriver) { - std::thread::Builder::new() - .name("data_restore".to_string()) - .spawn(move || { - driver.load_past_state().expect("Cant get past state"); - driver.run_state_updates().expect("Cant update state"); - }) - .expect("Data restore driver thread"); -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_complete_task() { - let config = helpers::DataRestoreConfig::new(helpers::InfuraEndpoint::Rinkeby); - let from = U256::from(0); - let delta = U256::from(15); - let mut data_restore_driver = create_new_data_restore_driver(config, from, delta, None); - data_restore_driver - .load_past_state() - .expect("Cant get past state"); - data_restore_driver.run_state_updates(); - } -} From 255d37a16b5b12cb63966aa4995d5b76066c5072 Mon Sep 17 00:00:00 2001 From: Alex Gluchowski Date: Tue, 20 Aug 2019 12:36:24 +0200 Subject: [PATCH 2/5] envsubst added to doc --- docs/setup-dev.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/setup-dev.md b/docs/setup-dev.md index e492a06406..a030a356fc 100644 --- a/docs/setup-dev.md +++ b/docs/setup-dev.md @@ -38,6 +38,13 @@ jq is used to work with json when managing DigitalOcean. ```brew install jq``` +# envsubst + +```bash +brew install gettext +brew link --force gettext +``` + # PSQL Install `psql` CLI tool to interact with postgres. From ee3216c0a3a05507ad032e2b2c630331ac48f662 Mon Sep 17 00:00:00 2001 From: TymurKhrushchov Date: Thu, 29 Aug 2019 13:27:34 +0300 Subject: [PATCH 3/5] ignore irrelevant tests --- .../src/witness/close_account.rs | 14 +++++------ core/franklincircuit/src/witness/deposit.rs | 24 +++++++++---------- core/franklincircuit/src/witness/noop.rs | 4 ++-- .../src/witness/partial_exit.rs | 2 ++ core/franklincircuit/src/witness/signature.rs | 1 + core/franklincircuit/src/witness/transfer.rs | 1 + .../src/witness/transfer_to_new.rs | 3 ++- core/storage/src/lib.rs | 7 ++++++ 8 files changed, 33 insertions(+), 23 deletions(-) diff --git a/core/franklincircuit/src/witness/close_account.rs b/core/franklincircuit/src/witness/close_account.rs index 9066bb8e9d..3813061c2b 100644 --- a/core/franklincircuit/src/witness/close_account.rs +++ b/core/franklincircuit/src/witness/close_account.rs @@ -165,12 +165,13 @@ mod test { use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; use franklinmodels::circuit::account::{ - CircuitAccount, CircuitAccountTree, CircuitBalanceTree, + CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; use franklinmodels::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] + #[ignore] fn test_close_account_franklin_empty_leaf() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; @@ -188,12 +189,11 @@ mod test { let sender_pub_key_hash = pub_key_hash(&sender_pk, &phasher); let (sender_x, sender_y) = sender_pk.0.into_xy(); let sender_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), - nonce: Fr::zero(), - pub_key_hash: sender_pub_key_hash - // pub_x: validator_x.clone(), - // pub_y: validator_y.clone(), - }; + subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + nonce: Fr::zero(), + pub_key_hash: sender_pub_key_hash, // pub_x: validator_x.clone(), + // pub_y: validator_y.clone(), + }; println!("zero root_hash equals: {}", sender_leaf.subtree.root_hash()); // give some funds to sender and make zero balance for recipient diff --git a/core/franklincircuit/src/witness/deposit.rs b/core/franklincircuit/src/witness/deposit.rs index 3a4489e639..a87a9e0800 100644 --- a/core/franklincircuit/src/witness/deposit.rs +++ b/core/franklincircuit/src/witness/deposit.rs @@ -288,35 +288,33 @@ mod test { use crate::witness::utils::public_data_commitment; use bellman::groth16::generate_random_parameters; - use bellman::groth16::{ - create_random_proof, prepare_verifying_key, verify_proof, - }; + use bellman::groth16::{create_random_proof, prepare_verifying_key, verify_proof}; use crate::circuit::FranklinCircuit; use bellman::Circuit; use ff::{BitIterator, Field, PrimeField}; use franklin_crypto::alt_babyjubjub::AltJubjubBn256; - use franklinmodels::primitives::{GetBits}; + use franklinmodels::primitives::GetBits; use franklin_crypto::circuit::test::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; use franklinmodels::circuit::account::{ - CircuitAccount, CircuitAccountTree, CircuitBalanceTree, + CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; use franklinmodels::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] + #[ignore] fn test_deposit_franklin_in_empty_leaf() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; let validator_address_number = 7; let validator_address = Fr::from_str(&validator_address_number.to_string()).unwrap(); let block_number = Fr::from_str("1").unwrap(); - let rng = - &mut XorShiftRng::from_seed([0x3dbe_6258, 0x8d31_3d76, 0x3237_db17, 0xe5bc_0654]); + let rng = &mut XorShiftRng::from_seed([0x3dbe_6258, 0x8d31_3d76, 0x3237_db17, 0xe5bc_0654]); let phasher = PedersenHasher::::default(); let mut tree: CircuitAccountTree = @@ -327,12 +325,11 @@ mod test { let sender_pub_key_hash = pub_key_hash(&sender_pk, &phasher); let (sender_x, sender_y) = sender_pk.0.into_xy(); let sender_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), - nonce: Fr::zero(), - pub_key_hash: sender_pub_key_hash - // pub_x: validator_x.clone(), - // pub_y: validator_y.clone(), - }; + subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + nonce: Fr::zero(), + pub_key_hash: sender_pub_key_hash, // pub_x: validator_x.clone(), + // pub_y: validator_y.clone(), + }; println!("zero root_hash equals: {}", sender_leaf.subtree.root_hash()); // give some funds to sender and make zero balance for recipient @@ -439,6 +436,7 @@ mod test { } #[test] + #[ignore] fn test_deposit_franklin_proof() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; diff --git a/core/franklincircuit/src/witness/noop.rs b/core/franklincircuit/src/witness/noop.rs index 08a29fb80e..4890822e9d 100644 --- a/core/franklincircuit/src/witness/noop.rs +++ b/core/franklincircuit/src/witness/noop.rs @@ -103,6 +103,7 @@ mod test { use franklinmodels::merkle_tree::PedersenHasher; #[test] + #[ignore] fn test_noop_franklin() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; @@ -182,8 +183,7 @@ mod test { &sender_x, &sender_y, ); - let (_, validator_account_witness) = - apply_fee(&mut tree, validator_address_number, 0, 0); + let (_, validator_account_witness) = apply_fee(&mut tree, validator_address_number, 0, 0); let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( diff --git a/core/franklincircuit/src/witness/partial_exit.rs b/core/franklincircuit/src/witness/partial_exit.rs index 970e3d0227..08ebd57888 100644 --- a/core/franklincircuit/src/witness/partial_exit.rs +++ b/core/franklincircuit/src/witness/partial_exit.rs @@ -286,6 +286,7 @@ mod test { use franklinmodels::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] + #[ignore] fn test_partial_exit_franklin() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; @@ -422,6 +423,7 @@ mod test { } #[test] + #[ignore] fn test_full_exit_franklin() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; diff --git a/core/franklincircuit/src/witness/signature.rs b/core/franklincircuit/src/witness/signature.rs index 20e731393f..f507a68a43 100644 --- a/core/franklincircuit/src/witness/signature.rs +++ b/core/franklincircuit/src/witness/signature.rs @@ -48,6 +48,7 @@ impl Circuit for SmallCircuit { } #[test] +#[ignore] fn test_small_circuit_franklin() { use super::utils::public_data_commitment; diff --git a/core/franklincircuit/src/witness/transfer.rs b/core/franklincircuit/src/witness/transfer.rs index 000b3a2741..9b1c8d6a16 100644 --- a/core/franklincircuit/src/witness/transfer.rs +++ b/core/franklincircuit/src/witness/transfer.rs @@ -320,6 +320,7 @@ mod test { use franklinmodels::merkle_tree::PedersenHasher; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] + #[ignore] fn test_transfer() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; diff --git a/core/franklincircuit/src/witness/transfer_to_new.rs b/core/franklincircuit/src/witness/transfer_to_new.rs index ab1aab1582..b9e5e183c9 100644 --- a/core/franklincircuit/src/witness/transfer_to_new.rs +++ b/core/franklincircuit/src/witness/transfer_to_new.rs @@ -74,7 +74,7 @@ impl TransferToNewWitness { &self.args.fee.unwrap(), franklin_constants::FEE_MANTISSA_BIT_WIDTH + franklin_constants::FEE_EXPONENT_BIT_WIDTH, ); - pubdata_bits.resize(40*8, false); + pubdata_bits.resize(40 * 8, false); pubdata_bits } } @@ -403,6 +403,7 @@ mod test { use franklinmodels::merkle_tree::PedersenHasher; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] + #[ignore] fn test_transfer_to_new() { let params = &AltJubjubBn256::new(); let p_g = FixedGenerators::SpendingKeyGenerator; diff --git a/core/storage/src/lib.rs b/core/storage/src/lib.rs index 4ad76ce296..b1d9c95d48 100644 --- a/core/storage/src/lib.rs +++ b/core/storage/src/lib.rs @@ -1418,6 +1418,7 @@ mod test { use diesel::Connection; #[test] + #[ignore] fn test_store_proof() { let pool = ConnectionPool::new(); let conn = pool.access_storage().unwrap(); @@ -1542,6 +1543,7 @@ mod test { } #[test] + #[ignore] fn test_commit_rewind() { let _ = env_logger::try_init(); @@ -1678,6 +1680,7 @@ mod test { // } #[test] + #[ignore] fn test_store_txs() { unimplemented!() // let pool = ConnectionPool::new(); @@ -1768,6 +1771,7 @@ mod test { } #[test] + #[ignore] fn test_store_proof_reqs() { unimplemented!() // let pool = ConnectionPool::new(); @@ -1817,6 +1821,7 @@ mod test { } #[test] + #[ignore] fn test_store_helpers() { unimplemented!() // let pool = ConnectionPool::new(); @@ -1866,6 +1871,7 @@ mod test { } #[test] + #[ignore] fn test_store_txs_2() { unimplemented!() // let pool = ConnectionPool::new(); @@ -1965,6 +1971,7 @@ mod test { } #[test] + #[ignore] fn test_nonce_fast_forward() { let pool = ConnectionPool::new(); let conn = pool.access_storage().unwrap(); From 1f1afd79dd869f6ad0ed30017a94e3084b2d3b1a Mon Sep 17 00:00:00 2001 From: TymurKhrushchov Date: Thu, 29 Aug 2019 17:13:22 +0300 Subject: [PATCH 4/5] lint fixes --- Cargo.lock | 512 ++--- Cargo.toml | 8 +- Makefile | 2 +- bin/gen-keys | 2 +- clippy.toml | 2 + contracts/contracts/VerificationKey.sol | 38 +- core/{franklincircuit => circuit}/Cargo.toml | 4 +- .../src/account.rs | 6 +- .../src/allocated_structures.rs | 49 +- .../src/circuit.rs | 57 +- .../src/element.rs | 10 +- core/{franklincircuit => circuit}/src/lib.rs | 0 .../src/operation.rs | 0 .../{franklincircuit => circuit}/src/utils.rs | 24 +- .../src/witness/close_account.rs | 46 +- .../src/witness/deposit.rs | 134 +- .../src/witness/mod.rs | 0 .../src/witness/noop.rs | 44 +- .../src/witness/partial_exit.rs | 120 +- .../src/witness/signature.rs | 6 +- .../src/witness/transfer.rs | 80 +- .../src/witness/transfer_to_new.rs | 96 +- .../src/witness/utils.rs | 25 +- core/eth_client/Cargo.toml | 2 +- core/franklin_key_generator/Cargo.toml | 23 - core/franklin_key_generator/src/main.rs | 13 - .../src/vk_contract_generator.rs | 98 - core/franklin_prover/Cargo.toml | 39 - core/franklin_prover/src/lib.rs | 584 ------ core/franklin_prover/src/main.rs | 57 - core/key_generator/Cargo.toml | 3 +- .../FranklinVerificationKey.sol | 0 core/key_generator/src/depositor_key.rs | 99 - core/key_generator/src/exitor_key.rs | 96 - .../src/franklin_key.rs | 14 +- core/key_generator/src/main.rs | 34 +- core/key_generator/src/read_write_keys.rs | 483 ----- core/key_generator/src/transactor_key.rs | 103 - .../src/vk_contract_generator.rs | 196 +- core/{franklinmodels => models}/Cargo.toml | 2 +- core/{franklinmodels => models}/src/abi.rs | 0 .../src/circuit/account.rs | 4 +- .../src/circuit/mod.rs | 0 core/{franklinmodels => models}/src/lib.rs | 0 .../src/merkle_tree/account_tree.rs | 0 .../src/merkle_tree/hasher.rs | 0 .../src/merkle_tree/mod.rs | 0 .../src/merkle_tree/parallel_smt.rs | 0 .../src/merkle_tree/pedersen_hasher.rs | 0 .../src/merkle_tree/sequential_smt.rs | 0 .../src/node/account.rs | 2 +- .../src/node/block.rs | 0 .../src/node/config.rs | 1 - .../src/node/mod.rs | 0 .../src/node/operations.rs | 0 .../{franklinmodels => models}/src/node/tx.rs | 0 core/{franklinmodels => models}/src/params.rs | 26 +- .../src/primitives.rs | 0 core/plasma/Cargo.toml | 2 +- core/prover/Cargo.toml | 4 +- core/prover/src/bin/dummy_prover.rs | 24 - core/prover/src/lib.rs | 1817 ++++++----------- core/prover/src/main.rs | 116 +- core/server/Cargo.toml | 2 +- core/server/src/api_server.rs | 8 +- core/server/src/eth_watch.rs | 11 +- core/storage/Cargo.toml | 2 +- core/storage/src/lib.rs | 74 +- etc/env/dev.env.example | 2 +- 69 files changed, 1481 insertions(+), 3725 deletions(-) create mode 100644 clippy.toml rename core/{franklincircuit => circuit}/Cargo.toml (88%) rename core/{franklincircuit => circuit}/src/account.rs (90%) rename core/{franklincircuit => circuit}/src/allocated_structures.rs (85%) rename core/{franklincircuit => circuit}/src/circuit.rs (97%) rename core/{franklincircuit => circuit}/src/element.rs (98%) rename core/{franklincircuit => circuit}/src/lib.rs (100%) rename core/{franklincircuit => circuit}/src/operation.rs (100%) rename core/{franklincircuit => circuit}/src/utils.rs (92%) rename core/{franklincircuit => circuit}/src/witness/close_account.rs (87%) rename core/{franklincircuit => circuit}/src/witness/deposit.rs (84%) rename core/{franklincircuit => circuit}/src/witness/mod.rs (100%) rename core/{franklincircuit => circuit}/src/witness/noop.rs (84%) rename core/{franklincircuit => circuit}/src/witness/partial_exit.rs (84%) rename core/{franklincircuit => circuit}/src/witness/signature.rs (96%) rename core/{franklincircuit => circuit}/src/witness/transfer.rs (90%) rename core/{franklincircuit => circuit}/src/witness/transfer_to_new.rs (88%) rename core/{franklincircuit => circuit}/src/witness/utils.rs (91%) delete mode 100644 core/franklin_key_generator/Cargo.toml delete mode 100644 core/franklin_key_generator/src/main.rs delete mode 100644 core/franklin_key_generator/src/vk_contract_generator.rs delete mode 100644 core/franklin_prover/Cargo.toml delete mode 100644 core/franklin_prover/src/lib.rs delete mode 100644 core/franklin_prover/src/main.rs rename core/{franklin_key_generator => key_generator}/FranklinVerificationKey.sol (100%) delete mode 100644 core/key_generator/src/depositor_key.rs delete mode 100644 core/key_generator/src/exitor_key.rs rename core/{franklin_key_generator => key_generator}/src/franklin_key.rs (91%) delete mode 100644 core/key_generator/src/read_write_keys.rs delete mode 100644 core/key_generator/src/transactor_key.rs rename core/{franklinmodels => models}/Cargo.toml (96%) rename core/{franklinmodels => models}/src/abi.rs (100%) rename core/{franklinmodels => models}/src/circuit/account.rs (93%) rename core/{franklinmodels => models}/src/circuit/mod.rs (100%) rename core/{franklinmodels => models}/src/lib.rs (100%) rename core/{franklinmodels => models}/src/merkle_tree/account_tree.rs (100%) rename core/{franklinmodels => models}/src/merkle_tree/hasher.rs (100%) rename core/{franklinmodels => models}/src/merkle_tree/mod.rs (100%) rename core/{franklinmodels => models}/src/merkle_tree/parallel_smt.rs (100%) rename core/{franklinmodels => models}/src/merkle_tree/pedersen_hasher.rs (100%) rename core/{franklinmodels => models}/src/merkle_tree/sequential_smt.rs (100%) rename core/{franklinmodels => models}/src/node/account.rs (99%) rename core/{franklinmodels => models}/src/node/block.rs (100%) rename core/{franklinmodels => models}/src/node/config.rs (99%) rename core/{franklinmodels => models}/src/node/mod.rs (100%) rename core/{franklinmodels => models}/src/node/operations.rs (100%) rename core/{franklinmodels => models}/src/node/tx.rs (100%) rename core/{franklinmodels => models}/src/params.rs (57%) rename core/{franklinmodels => models}/src/primitives.rs (100%) delete mode 100644 core/prover/src/bin/dummy_prover.rs diff --git a/Cargo.lock b/Cargo.lock index a100045890..63ea00904e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,7 +75,7 @@ dependencies = [ "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -87,7 +87,7 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -133,7 +133,7 @@ name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -155,17 +155,17 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.34" +version = "0.3.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", @@ -189,7 +189,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "safemem 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -224,7 +224,7 @@ dependencies = [ "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -254,7 +254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -295,7 +295,7 @@ name = "c2-chacha" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -318,10 +318,25 @@ dependencies = [ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "circuit" +version = "0.1.1" +dependencies = [ + "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.33.0" @@ -332,7 +347,7 @@ dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -346,7 +361,7 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -378,8 +393,8 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "publicsuffix 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "publicsuffix 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -455,7 +470,7 @@ dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -474,7 +489,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -623,7 +638,7 @@ name = "error-chain" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -631,7 +646,7 @@ name = "error-chain" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -642,14 +657,14 @@ dependencies = [ "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-tx-sign 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "franklinmodels 0.0.1", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", + "reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "secp256k1 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "web3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -662,8 +677,8 @@ dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -676,7 +691,7 @@ dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -688,8 +703,8 @@ dependencies = [ "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "secp256k1 0.11.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -703,7 +718,7 @@ dependencies = [ "ethbloom 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -712,7 +727,7 @@ name = "ethereum-types-serialize" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -720,7 +735,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -755,7 +770,7 @@ dependencies = [ "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -810,98 +825,11 @@ dependencies = [ "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "franklin_key_generator" -version = "0.1.1" -dependencies = [ - "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", - "franklincircuit 0.1.1", - "franklinmodels 0.0.1", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "franklin_prover" -version = "0.0.1" -dependencies = [ - "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bigdecimal 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", - "franklincircuit 0.1.1", - "franklinmodels 0.0.1", - "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "plasma 0.1.1", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", - "signal-hook 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "storage 0.0.1", - "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "franklincircuit" -version = "0.1.1" -dependencies = [ - "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", - "franklinmodels 0.0.1", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "franklinmodels" -version = "0.0.1" -dependencies = [ - "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "bigdecimal 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", - "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "web3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -945,12 +873,12 @@ name = "generic-array" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "getrandom" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -968,7 +896,7 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", - "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "indexmap 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -980,7 +908,7 @@ name = "heapsize" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1100,6 +1028,16 @@ dependencies = [ "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "im" version = "12.3.4" @@ -1107,7 +1045,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "sized-chunks 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1117,7 +1055,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "indexmap" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1137,7 +1075,7 @@ dependencies = [ "error-chain 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1161,8 +1099,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1180,12 +1118,13 @@ name = "key_generator" version = "0.1.1" dependencies = [ "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "circuit 0.1.1", "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", - "franklinmodels 0.0.1", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1199,7 +1138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1364,17 +1303,41 @@ dependencies = [ "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "models" +version = "0.0.1" +dependencies = [ + "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bigdecimal 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", + "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "web3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "native-tls" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.24 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.48 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1388,7 +1351,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1419,7 +1382,7 @@ name = "num-integer" version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1428,7 +1391,7 @@ name = "num-traits" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1447,9 +1410,9 @@ dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.48 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1459,10 +1422,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl-sys" -version = "0.9.48" +version = "0.9.49" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1486,8 +1449,8 @@ dependencies = [ "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1529,7 +1492,7 @@ dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1544,7 +1507,7 @@ dependencies = [ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1558,7 +1521,7 @@ dependencies = [ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1566,6 +1529,11 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pkg-config" version = "0.3.15" @@ -1578,8 +1546,8 @@ dependencies = [ "bigdecimal 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "franklinmodels 0.0.1", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", ] [[package]] @@ -1611,16 +1579,54 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "prover" +version = "0.0.1" +dependencies = [ + "bellman_ce 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bigdecimal 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "circuit 0.1.1", + "diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", + "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "plasma 0.1.1", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "signal-hook 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "storage 0.0.1", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "publicsuffix" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1636,6 +1642,14 @@ dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "r2d2" version = "0.8.5" @@ -1664,7 +1678,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1676,7 +1690,7 @@ dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1684,7 +1698,7 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1694,7 +1708,7 @@ dependencies = [ "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1702,10 +1716,10 @@ name = "rand" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1714,7 +1728,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1724,7 +1738,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1742,10 +1756,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand_core" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "getrandom 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1761,7 +1775,7 @@ name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1779,7 +1793,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1792,7 +1806,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1800,7 +1814,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1830,7 +1844,7 @@ dependencies = [ "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1868,12 +1882,12 @@ name = "remove_dir_all" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "reqwest" -version = "0.9.19" +version = "0.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1890,7 +1904,7 @@ dependencies = [ "mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1919,7 +1933,7 @@ version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1992,7 +2006,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "safemem" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2000,8 +2014,8 @@ name = "schannel" version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2070,10 +2084,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2081,17 +2095,17 @@ name = "serde_bytes" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2101,7 +2115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2111,7 +2125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2132,13 +2146,13 @@ dependencies = [ "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "franklin-crypto 0.0.5 (git+ssh://git@github.com/matter-labs/franklin-crypto.git)", - "franklinmodels 0.0.1", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.33 (registry+https://github.com/rust-lang/crates.io-index)", "im 12.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2148,9 +2162,9 @@ dependencies = [ "rayon 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "signal-hook 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "storage 0.0.1", @@ -2190,7 +2204,7 @@ name = "sized-chunks" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2216,7 +2230,7 @@ dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2235,10 +2249,10 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "ff_ce 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "franklinmodels 0.0.1", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "models 0.0.1", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "web3 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2276,6 +2290,16 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "synstructure" version = "0.10.2" @@ -2297,7 +2321,7 @@ dependencies = [ "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2305,7 +2329,7 @@ name = "termcolor" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2313,7 +2337,7 @@ name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2321,7 +2345,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2331,7 +2355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2361,7 +2385,7 @@ dependencies = [ "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-udp 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2448,7 +2472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2472,7 +2496,7 @@ dependencies = [ "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2545,7 +2569,7 @@ dependencies = [ [[package]] name = "tokio-udp" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2612,7 +2636,7 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2622,7 +2646,7 @@ dependencies = [ "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-udp 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2635,7 +2659,7 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2645,7 +2669,7 @@ dependencies = [ "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-udp 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2658,7 +2682,7 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "ipconfig 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2687,7 +2711,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "typenum" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2735,7 +2759,7 @@ dependencies = [ [[package]] name = "unicode-width" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2743,6 +2767,11 @@ name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "untrusted" version = "0.6.2" @@ -2759,6 +2788,16 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "url" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "uuid" version = "0.7.4" @@ -2843,8 +2882,8 @@ dependencies = [ "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2887,7 +2926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2909,7 +2948,7 @@ name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2919,10 +2958,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wincolor" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2931,7 +2970,7 @@ name = "winreg" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2939,7 +2978,7 @@ name = "winreg" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2947,7 +2986,7 @@ name = "winutil" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2970,8 +3009,8 @@ dependencies = [ "checksum arc-swap 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "854ede29f7a0ce90519fb2439d030320c6201119b87dab0ee96044603e1130b9" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" -"checksum autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "22130e92352b948e7e82a49cdb0aa94f2211761117f29e052dd397c1ac33542b" -"checksum backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b5164d292487f037ece34ec0de2fcede2faa162f085dd96d2385ab81b12765ba" +"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" +"checksum backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "1371048253fa3bac6704bfd6bbfc922ee9bdcee8881330d40f308b81cc5adc55" "checksum backtrace-sys 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "5b3a000b9c543553af61bc01cbfc403b04b5caa9e421033866f2e98061eb3e61" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" @@ -2992,7 +3031,7 @@ dependencies = [ "checksum chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "77d81f58b7301084de3b958691458a53c3f7e0b1d702f77e550b6a88e3a88abe" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum cookie 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "99be24cfcf40d56ed37fd11c2123be833959bbc5bddecb46e1c2e442e15fa3e0" "checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" "checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" @@ -3047,7 +3086,7 @@ dependencies = [ "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" -"checksum getrandom 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2512b3191f22e2763a5db387f1c9409379772e2050841722eb4a8c4f497bf096" +"checksum getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "fc344b02d3868feb131e8b5fe2b9b0a1cc42942679af493061fc13b853243872" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" @@ -3060,9 +3099,10 @@ dependencies = [ "checksum hyper 0.12.33 (registry+https://github.com/rust-lang/crates.io-index)" = "7cb44cbce9d8ee4fb36e4c0ad7b794ac44ebaad924b9c8291a63215bb44c2c8f" "checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum im 12.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "de38d1511a0ce7677538acb1e31b5df605147c458e061b2cdb89858afb1cd182" "checksum indexmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7164c96d6e18ccc3ce43f3dedac996c21a220670a106c275b96ad92110401362" -"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" +"checksum indexmap 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4d6d89e0948bf10c08b9ecc8ac5b83f07f857ebe2c0cbe38de15b4e4f510356" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum ipconfig 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "08f7eadeaf4b52700de180d147c4805f199854600b36faa963d91114827b2ffc" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" @@ -3070,7 +3110,7 @@ dependencies = [ "checksum jsonrpc-core 8.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf83704f4e79979a424d1082dd2c1e52683058056c9280efa19ac5f6bc9033c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" -"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" @@ -3101,7 +3141,7 @@ dependencies = [ "checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" "checksum openssl 0.10.24 (registry+https://github.com/rust-lang/crates.io-index)" = "8152bb5a9b5b721538462336e3bef9a539f892715e5037fda0f984577311af15" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-sys 0.9.48 (registry+https://github.com/rust-lang/crates.io-index)" = "b5ba300217253bcc5dc68bed23d782affa45000193866e025329aa8a7a9f05b8" +"checksum openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)" = "f4fad9e54bd23bd4cbbe48fdc08a1b8091707ac869ef8508edea2fec77dcc884" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum pairing_ce 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cce626fb8f97e304423451d63e29b7f5882de5cfe79925ffc4a32cf4c243f40f" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" @@ -3111,14 +3151,17 @@ dependencies = [ "checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" +"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c1d2cfa5a714db3b5f24f0915e74fcdf91d09d496ba61329705dda7774d2af" "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" "checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda" "checksum priority-queue 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "12c349103858e4f8dd8eca2788f6d7b2f351ce77517d0227e6ea698f2a6110d2" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum publicsuffix 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5afecba86dcf1e4fd610246f89899d1924fe12e1e89f555eb7c7f710f3c5ad1d" +"checksum proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5c2380ae88876faae57698be9e9775e3544decad214599c3a6266cca6ac802" +"checksum publicsuffix 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9bf259a81de2b2eb9850ec990ec78e6a25319715584fd7652b9b26f96fcb1510" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum r2d2 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bc42ce75d9f4447fb2a04bbe1ed5d18dd949104572850ec19b164e274919f81b" "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" @@ -3129,7 +3172,7 @@ dependencies = [ "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -"checksum rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "615e683324e75af5d43d8f7a39ffe3ee4a9dc42c5c701167a71dc59c3a493aca" +"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" @@ -3144,7 +3187,7 @@ dependencies = [ "checksum regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88c3d9193984285d544df4a30c23a4e62ead42edf70a4452ceb76dac1ce05c26" "checksum regex-syntax 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b143cceb2ca5e56d5671988ef8b15615733e7ee16cd348e064333b251b89343f" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum reqwest 0.9.19 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0777154c2c3eb54f5c480db01de845652d941e47191277cc673634c3853939" +"checksum reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0f6d896143a583047512e59ac54a215cb203c29cc941917343edea3be8df9c78" "checksum resolv-conf 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b263b4aa1b5de9ffc0054a2386f96992058bb6870aab516f8cdeb8a667d56dcb" "checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a" "checksum rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "524c5ad554859785dfc8469df3ed5e0b5784d4d335877ed47c8d90fc0eb238fe" @@ -3156,7 +3199,7 @@ dependencies = [ "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" -"checksum safemem 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e133ccc4f4d1cd4f89cc8a7ff618287d56dc7f638b8e38fc32c5fdcadc339dd5" +"checksum safemem 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d2b08423011dae9a5ca23f07cf57dac3857f5c885d352b76f6d95f4aea9434d0" "checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339" "checksum scheduled-thread-pool 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bd07742e081ff6c077f5f6b283f12f32b9e7cc765b316160d66289b74546fbb3" "checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" @@ -3167,9 +3210,9 @@ dependencies = [ "checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5626ac617da2f2d9c48af5515a21d5a480dbd151e01bb1c355e26a3e68113" +"checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f" "checksum serde_bytes 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "45af0182ff64abaeea290235eb67da3825a576c5d53e642c4d5b652e12e6effc" -"checksum serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)" = "01e69e1b8a631f245467ee275b8c757b818653c6d704cdbcaeb56b56767b529c" +"checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425" "checksum serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704" "checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" @@ -3185,6 +3228,7 @@ dependencies = [ "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" @@ -3208,7 +3252,7 @@ dependencies = [ "checksum tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6131e780037787ff1b3f8aad9da83bca02438b72277850dd6ad0d455e0e20efc" "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" "checksum tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c" -"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" +"checksum tokio-udp 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "56775b287cda0fd8ca0c5d2f5b1d0646afbd360101e2eef91cd89365fcfc2f5f" "checksum tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "65ae5d255ce739e8537221ed2942e0445f4b3b813daebac1c0050ddaaa3587f9" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" "checksum tower-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b32f72af77f1bfe3d3d4da8516a238ebe7039b51dd8637a09841ac7f16d2c987" @@ -3219,16 +3263,18 @@ dependencies = [ "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" -"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" +"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" "checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a84e5511b2a947f3ae965dcb29b13b7b1691b6e7332cf5dbc1744138d5acb7f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" "checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum v_escape 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "660b101c07b5d0863deb9e7fb3138777e858d6d2a79f9e6049a27d1cc77c6da6" "checksum v_escape_derive 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "75b2dc50d1c14d7b4488bf34263140a3827d8ca4f4265411e4784ac262382276" @@ -3242,12 +3288,12 @@ dependencies = [ "checksum websocket 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c9faed2bff8af2ea6b9f8b917d3d00b467583f6781fe3def174a9e33c879703" "checksum widestring 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7157704c2e12e3d2189c507b7482c52820a16dfa4465ba91add92f266667cadb" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" +"checksum wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" "checksum winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" "checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" diff --git a/Cargo.toml b/Cargo.toml index f55beab39c..eafa16c781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ members = [ "core/plasma", "core/server", "core/storage", - "core/franklincircuit", - "core/franklinmodels", - "core/franklin_prover", - "core/franklin_key_generator", + "core/circuit", + "core/models", + "core/prover", + "core/key_generator", ] diff --git a/Makefile b/Makefile index 06d5a404ae..54d2c86deb 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ dummy-prover: cargo run --bin dummy_prover prover: - @cargo run --release --bin franklin_prover + @cargo run --release --bin prover server: @cargo run --bin server --release diff --git a/bin/gen-keys b/bin/gen-keys index 65dff8bc85..7be52035b1 100755 --- a/bin/gen-keys +++ b/bin/gen-keys @@ -6,6 +6,6 @@ FRANKLIN_HOME=`dirname $0`/.. mkdir -p $FRANKLIN_HOME/$KEY_DIR/$BLOCK_SIZE_CHUNKS -cargo run --bin franklin_key_generator --release +cargo run --bin key_generator --release cp $FRANKLIN_HOME/$KEY_DIR/$BLOCK_SIZE_CHUNKS/VerificationKey.sol $FRANKLIN_HOME/contracts/contracts diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..aa09258fc3 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,2 @@ +too-many-arguments-threshold = 12 +cognitive-complexity-threshold = 30 \ No newline at end of file diff --git a/contracts/contracts/VerificationKey.sol b/contracts/contracts/VerificationKey.sol index 04f0942a47..02ee8215d0 100644 --- a/contracts/contracts/VerificationKey.sol +++ b/contracts/contracts/VerificationKey.sol @@ -9,27 +9,27 @@ contract VerificationKey { function getVk() external pure returns (uint256[14] memory vk, uint256[] memory gammaABC) { - - vk[0] = 0x04fd4747ce83ae7d2db0556352df19a3dff711b2765fc12a7ec6e38ca537b30f; - vk[1] = 0x25f6674d526af9b4152cac6b092f8b762ea88e53036c5345b19c0f87f4d90ff4; - vk[2] = 0x2651e0fe1abe71aff4111dbbf76f1f6e5cde291dc2094f26ed8be7d742f48740; - vk[3] = 0x12369507d22dfe13a8f17be39d05daf541a79bb2930fa5ffd94a7f584749ec3b; - vk[4] = 0x0987978c96491b608f776be7e645171a8103e746aa3a37eb6b8f9654689b2367; - vk[5] = 0x197bb4c59e37176e381fd098dcc1771581dbc5655018c64b7d6391e69618f73b; - vk[6] = 0x029427c8ac578458581eab3ddfe18029bf949cf63bf7b557709837f10258664f; - vk[7] = 0x2fa701fc17e85495118d477cfcb82530b1dae4c548f5742b0fd29b145bd7ea0b; - vk[8] = 0x20d5aa37aab29ab9593dd5c5f46c223c6baeb50bba6dc2b1e71b377d76256ef5; - vk[9] = 0x08d6b12bb7bf6a3dcce9bc2ad091930ad9f32e4f1198a4d63fe199992e27dc8e; - vk[10] = 0x08aef144f52bee1ff0d1795ec394e54ccc38fff086011c5a8adde92a17f5fb05; - vk[11] = 0x2fd4fc94a99ecdfe5cd70e51e5a428128360ff9afb26fe8b2d356ad3b7f81fcb; - vk[12] = 0x2c92b22594eb05a44fad2382d423ccf35fbafbf4415f151f6f67429197b34657; - vk[13] = 0x11d5dbb95c59d0805a6aef8e54690a04ec5af61b287e1001c99b9eaf6a3ac517; + + vk[0] = 0x1fd5370a139ba6db51d728dd2168621a045e0aa226d0321c4a9c1f63da988824; + vk[1] = 0x105747c6929375b00ec56929ceee08f9c27e975d175e04fcca2d03feb31be5bd; + vk[2] = 0x1dad0551ea9948d3627fe8abd8ab014d344509c39e94ece95462aabb28b09924; + vk[3] = 0x0a79734b0d868600ae0ada99bb2f9959a5d40a7c34e1f92ff247492b948a82f7; + vk[4] = 0x2ac1d35580e2dd08a32dbe536acb8e41335023f168b2799fb9ecb201936016f2; + vk[5] = 0x113a4d416716e73f2953b4038a3cdc333078938f01a1027d477a8e6dc4b47b4d; + vk[6] = 0x1cf77c5ac233c387c652b347a1099fc491628dd917c1f6ec776d6dcf28c42375; + vk[7] = 0x209700d026c240a19de578ab924f63165a0092b946c8c7e479091c47133fc82f; + vk[8] = 0x0062b7689366129df28302abff7dd25ee6e58b5894c8bd1dead3aa5c0faeea70; + vk[9] = 0x13c017802d8b29437c25f6791bd2ca51dbf4cac709d6f5ae631fa028d18a8888; + vk[10] = 0x28fc4fac85df6c5cb774f9d72f224a063f48000b8082b079e9a3c4ac901afbf6; + vk[11] = 0x2c79053e312e87bfef9f8f16acb70ca8ac8d27b9b3a288dc5e0c00b75dbd4235; + vk[12] = 0x1db6c5ed3f3c896919e22e05b77c4fb300d78878b74f7dd22b714829d3189e2d; + vk[13] = 0x2d73868653fbb3680ed35239cc27465c781fb0a0c778a7a65c2555cff9fa18b7; gammaABC = new uint256[](4); - gammaABC[0] = 0x1091e7cd0419999907e5c15abe9e8810eaa12fd01d612a6f5f206717378d3a50; - gammaABC[1] = 0x016355b67d6767ac3ca085bc1345ebebca0a3188dea8e95a09304466e8970146; - gammaABC[2] = 0x11d8852d862cda43dc1d867fc8e8e305bcd34d2dae733c1e65bb475ad3e78c50; - gammaABC[3] = 0x1e9ba665d9e8ba166687b163b135b9e782616d3c3921757b8ca5697199c33946; + gammaABC[0] = 0x24fd20a87d4f3e3be60fc5a0ae86613f8247ef59abca51e13360477581f3a07e; + gammaABC[1] = 0x0a8c3e87042ed108bf0860aca987ed00d0e1994c0cdec56b6fc735cddd6b007d; + gammaABC[2] = 0x0ceba5279240dfbd0101f639e822e7c056f58681842d197abfcc1688b2790a13; + gammaABC[3] = 0x0a517f73b51d2f2531403cbfde9d18edfd739d45cbd873422861aae94e2041b2; } diff --git a/core/franklincircuit/Cargo.toml b/core/circuit/Cargo.toml similarity index 88% rename from core/franklincircuit/Cargo.toml rename to core/circuit/Cargo.toml index 8d9f6f7b8e..78cf1ff822 100644 --- a/core/franklincircuit/Cargo.toml +++ b/core/circuit/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "franklincircuit" +name = "circuit" version = "0.1.1" edition = "2018" @@ -9,7 +9,7 @@ authors = [ ] [dependencies] -franklinmodels = { path = "../franklinmodels" } +models = { path = "../models" } pairing = { package = "pairing_ce", version = "0.17.0" } bellman = { package = "bellman_ce", version = "0.3.0" } franklin_crypto = { package = "franklin-crypto", git = "ssh://git@github.com/matter-labs/franklin-crypto.git", branch="master"} diff --git a/core/franklincircuit/src/account.rs b/core/circuit/src/account.rs similarity index 90% rename from core/franklincircuit/src/account.rs rename to core/circuit/src/account.rs index 5789a54694..819f3665c9 100644 --- a/core/franklincircuit/src/account.rs +++ b/core/circuit/src/account.rs @@ -1,5 +1,5 @@ use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::params as franklin_constants; +use models::params as franklin_constants; use crate::element::CircuitElement; use bellman::{ConstraintSystem, SynthesisError}; @@ -32,8 +32,8 @@ impl AccountContent { )?; Ok(Self { - nonce: nonce, - pub_key_hash: pub_key_hash, + nonce, + pub_key_hash, }) } } diff --git a/core/franklincircuit/src/allocated_structures.rs b/core/circuit/src/allocated_structures.rs similarity index 85% rename from core/franklincircuit/src/allocated_structures.rs rename to core/circuit/src/allocated_structures.rs index dd86b20f22..928b6268b4 100644 --- a/core/franklincircuit/src/allocated_structures.rs +++ b/core/circuit/src/allocated_structures.rs @@ -5,7 +5,7 @@ use crate::operation::{Operation, OperationBranch}; use crate::utils; use bellman::{ConstraintSystem, SynthesisError}; use franklin_crypto::circuit::float_point::parse_with_exponent_le; -use franklinmodels::params as franklin_constants; +use models::params as franklin_constants; use franklin_crypto::circuit::boolean::Boolean; use franklin_crypto::circuit::num::AllocatedNum; @@ -56,7 +56,7 @@ impl AllocatedOperationBranch { let token = CircuitElement::from_fe_strict( cs.namespace(|| "token"), || Ok(operation_branch.token.grab()?), - *franklin_constants::BALANCE_TREE_DEPTH, + franklin_constants::BALANCE_TREE_DEPTH, )?; let balance_audit_path = utils::allocate_audit_path( cs.namespace(|| "balance_audit_path"), @@ -64,16 +64,16 @@ impl AllocatedOperationBranch { )?; assert_eq!( balance_audit_path.len(), - *franklin_constants::BALANCE_TREE_DEPTH + franklin_constants::BALANCE_TREE_DEPTH ); Ok(AllocatedOperationBranch { - account: account, - account_audit_path: account_audit_path, - account_address: account_address, - balance: balance, - token: token, - balance_audit_path: balance_audit_path, + account, + account_audit_path, + account_address, + balance, + token, + balance_audit_path, }) } } @@ -129,16 +129,16 @@ impl AllocatedOperationData { let amount_parsed = parse_with_exponent_le( cs.namespace(|| "parse amount"), &amount_packed.get_bits_le(), - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, )?; let fee_parsed = parse_with_exponent_le( cs.namespace(|| "parse fee"), &fee_packed.get_bits_le(), - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, )?; let amount = CircuitElement::from_number( @@ -151,10 +151,7 @@ impl AllocatedOperationData { fee_parsed, franklin_constants::BALANCE_BIT_WIDTH, )?; - // println!( - // "fee_parsed in allocated_operation_data equals {}", - // fee.get_number().get_value().grab()? - // ); + let sig_msg = CircuitElement::from_fe_strict( cs.namespace(|| "signature_message_x"), || op.sig_msg.grab(), @@ -186,16 +183,16 @@ impl AllocatedOperationData { )?; Ok(AllocatedOperationData { - ethereum_key: ethereum_key, + ethereum_key, signer_pubkey: sig_pubkey, - amount_packed: amount_packed, - fee_packed: fee_packed, - fee: fee, - amount: amount, - sig_msg: sig_msg, - new_pubkey_hash: new_pubkey_hash, - a: a, - b: b, + amount_packed, + fee_packed, + fee, + amount, + sig_msg, + new_pubkey_hash, + a, + b, }) } } diff --git a/core/franklincircuit/src/circuit.rs b/core/circuit/src/circuit.rs similarity index 97% rename from core/franklincircuit/src/circuit.rs rename to core/circuit/src/circuit.rs index cc4e70a2bd..eae215ee5e 100644 --- a/core/franklincircuit/src/circuit.rs +++ b/core/circuit/src/circuit.rs @@ -17,8 +17,8 @@ use franklin_crypto::circuit::pedersen_hash; use franklin_crypto::circuit::polynomial_lookup::{do_the_lookup, generate_powers}; use franklin_crypto::circuit::Assignment; use franklin_crypto::jubjub::{FixedGenerators, JubjubEngine, JubjubParams}; -use franklinmodels::params as franklin_constants; -use franklinmodels::circuit::account::CircuitAccount; +use models::circuit::account::CircuitAccount; +use models::params as franklin_constants; const DIFFERENT_TRANSACTIONS_TYPE_NUMBER: usize = 6; #[derive(Clone)] @@ -95,7 +95,7 @@ impl<'a, E: JubjubEngine> Circuit for FranklinCircuit<'a, E> { )?; assert_eq!( validator_balances.len(), - (1 << *franklin_constants::BALANCE_TREE_DEPTH) as usize + (1 << franklin_constants::BALANCE_TREE_DEPTH) as usize ); let validator_audit_path = allocate_audit_path( @@ -121,7 +121,7 @@ impl<'a, E: JubjubEngine> Circuit for FranklinCircuit<'a, E> { // declare vector of fees, that will be collected during block processing let mut fees = vec![]; - let fees_len = 1 << *franklin_constants::BALANCE_TREE_DEPTH; + let fees_len = 1 << franklin_constants::BALANCE_TREE_DEPTH; for _ in 0..fees_len { fees.push(zero.clone()); } @@ -139,7 +139,7 @@ impl<'a, E: JubjubEngine> Circuit for FranklinCircuit<'a, E> { let (next_chunk, chunk_data) = self.verify_correct_chunking( &operation, - &mut next_chunk_number, + &next_chunk_number, cs.namespace(|| "verify_correct_chunking"), )?; @@ -365,7 +365,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { let tx_type = CircuitElement::from_fe_strict( cs.namespace(|| "tx_type"), || op.tx_type.grab(), - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, )?; let max_chunks_powers = generate_powers( @@ -414,8 +414,8 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { next_chunk_number, AllocatedChunkData { chunk_number: operation_chunk_number, - is_chunk_last: is_chunk_last, - tx_type: tx_type, + is_chunk_last, + tx_type, }, )) } @@ -722,9 +722,12 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { &op_valid, &Boolean::constant(true), )?; - - for i in 0..(1 << *franklin_constants::BALANCE_TREE_DEPTH as u32) { - let sum = Expression::from(&fees[i]) + Expression::from(&op_data.fee.get_number()); + for (i, fee) in fees + .iter_mut() + .enumerate() + .take(1 << franklin_constants::BALANCE_TREE_DEPTH) + { + let sum = Expression::from(&fee.clone()) + Expression::from(&op_data.fee.get_number()); let is_token_correct = Boolean::from(Expression::equals( cs.namespace(|| format!("is token equal to number {}", i)), @@ -736,10 +739,10 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { &is_token_correct, &chunk_data.is_chunk_last.clone(), )?; - fees[i] = Expression::conditionally_select( + *fee = Expression::conditionally_select( cs.namespace(|| format!("update fee number {}", i)), sum, - &fees[i], + &fee.clone(), &should_update, )?; } @@ -761,7 +764,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { let mut pubdata_bits = vec![]; let mut pub_token_bits = cur.token.get_bits_le().clone(); pub_token_bits.resize( - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, Boolean::constant(false), ); pub_token_bits.reverse(); @@ -955,7 +958,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { let mut pubdata_bits = vec![]; let mut pub_token_bits = cur.token.get_bits_le().clone(); pub_token_bits.resize( - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, Boolean::constant(false), ); pub_token_bits.reverse(); @@ -1079,7 +1082,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { pubdata_bits.extend(chunk_data.tx_type.get_bits_be()); //TX_TYPE_BIT_WIDTH=8 pubdata_bits.extend(cur.account_address.get_bits_be()); //ACCOUNT_TREE_DEPTH=24 pubdata_bits.resize( - 1 * franklin_constants::CHUNK_BIT_WIDTH, + franklin_constants::CHUNK_BIT_WIDTH, Boolean::constant(false), ); @@ -1112,9 +1115,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { let are_balances_empty = Boolean::from(Expression::equals( cs.namespace(|| "are_balances_empty"), &subtree_root.get_number(), - Expression::constant::( - empty_root, - ), //This is precalculated root_hash of subtree with empty balances + Expression::constant::(empty_root), //This is precalculated root_hash of subtree with empty balances )?); is_valid_flags.push(are_balances_empty); let tx_valid = multi_and(cs.namespace(|| "is_tx_valid"), &is_valid_flags)?; @@ -1149,7 +1150,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { //construct pubdata (it's all 0 for noop) let mut pubdata_bits = vec![]; pubdata_bits.resize( - 1 * franklin_constants::CHUNK_BIT_WIDTH, + franklin_constants::CHUNK_BIT_WIDTH, Boolean::constant(false), ); @@ -1194,7 +1195,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { let mut pubdata_bits = vec![]; let mut pub_token_bits = lhs.token.get_bits_le().clone(); pub_token_bits.resize( - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, Boolean::constant(false), ); pub_token_bits.reverse(); @@ -1351,7 +1352,7 @@ impl<'a, E: JubjubEngine> FranklinCircuit<'a, E> { let mut pubdata_bits = vec![]; let mut pub_token_bits = lhs.token.get_bits_le().clone(); pub_token_bits.resize( - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, Boolean::constant(false), ); pub_token_bits.reverse(); @@ -1584,7 +1585,7 @@ fn allocate_merkle_root>( let mut cur_hash = account_leaf_hash.get_x().clone(); // Ascend the merkle tree authentication path - for (i, direction_bit) in index.clone().into_iter().enumerate() { + for (i, direction_bit) in index.iter().enumerate() { let cs = &mut cs.namespace(|| format!("from merkle tree hash {}", i)); // "direction_bit" determines if the current subtree @@ -1731,9 +1732,9 @@ fn calculate_root_from_full_representation_fees], params: &E::Params, ) -> Result, SynthesisError> { - assert_eq!(fees.len(), 1 << *franklin_constants::BALANCE_TREE_DEPTH); + assert_eq!(fees.len(), 1 << franklin_constants::BALANCE_TREE_DEPTH); let mut fee_hashes = vec![]; - for (index, fee) in fees.into_iter().enumerate() { + for (index, fee) in fees.iter().enumerate() { let cs = &mut cs.namespace(|| format!("fee hashing index number {}", index)); let mut fee_bits = fee.into_bits_le(cs.namespace(|| "fee_bits"))?; fee_bits.truncate(franklin_constants::BALANCE_BIT_WIDTH); @@ -1747,7 +1748,7 @@ fn calculate_root_from_full_representation_fees() -> Vec { let y = E::Fr::from_str("1").unwrap(); points.push((x, y)); } - for i in &[1,3] { + for i in &[1, 3] { //deposit, partial exit let x = E::Fr::from_str(&i.to_string()).unwrap(); let y = E::Fr::from_str("3").unwrap(); points.push((x, y)); } - for i in &[ 2] { + for i in &[2] { //transfer_to_new let x = E::Fr::from_str(&i.to_string()).unwrap(); let y = E::Fr::from_str("4").unwrap(); diff --git a/core/franklincircuit/src/element.rs b/core/circuit/src/element.rs similarity index 98% rename from core/franklincircuit/src/element.rs rename to core/circuit/src/element.rs index c1f68c2523..7a9663521a 100644 --- a/core/franklincircuit/src/element.rs +++ b/core/circuit/src/element.rs @@ -6,7 +6,7 @@ use franklin_crypto::circuit::expression::Expression; use franklin_crypto::circuit::num::AllocatedNum; use franklin_crypto::circuit::pedersen_hash; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::params as franklin_constants; +use models::params as franklin_constants; #[derive(Clone)] pub struct CircuitElement { @@ -42,7 +42,7 @@ impl CircuitElement { let mut bits = number.into_bits_le(cs.namespace(|| "into_bits_le_fixed"))?; bits.truncate(max_length); Ok(CircuitElement { - number: number, + number, bits_le: bits, length: max_length, }) @@ -56,7 +56,7 @@ impl CircuitElement { let bits = number.into_bits_le_fixed(cs.namespace(|| "into_bits_le_fixed"), max_length)?; let ce = CircuitElement { - number: number, + number, bits_le: bits, length: max_length, }; @@ -73,7 +73,7 @@ impl CircuitElement { bits.resize(256, Boolean::constant(false)); let ce = CircuitElement { - number: number, + number, bits_le: bits, length: 256, }; @@ -104,7 +104,7 @@ impl CircuitElement { num_bits.truncate(max_length); let number = pack_bits_to_element(cs.namespace(|| "pack_truncated_bits"), &bits)?; Ok(CircuitElement { - number: number, + number, bits_le: num_bits, length: max_length, }) diff --git a/core/franklincircuit/src/lib.rs b/core/circuit/src/lib.rs similarity index 100% rename from core/franklincircuit/src/lib.rs rename to core/circuit/src/lib.rs diff --git a/core/franklincircuit/src/operation.rs b/core/circuit/src/operation.rs similarity index 100% rename from core/franklincircuit/src/operation.rs rename to core/circuit/src/operation.rs diff --git a/core/franklincircuit/src/utils.rs b/core/circuit/src/utils.rs similarity index 92% rename from core/franklincircuit/src/utils.rs rename to core/circuit/src/utils.rs index 4a3f7b9472..de5f3ba1f4 100644 --- a/core/franklincircuit/src/utils.rs +++ b/core/circuit/src/utils.rs @@ -8,7 +8,7 @@ use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::{FixedGenerators, JubjubEngine}; use crate::operation::TransactionSignature; -use franklinmodels::params as franklin_constants; +use models::params as franklin_constants; pub fn sign( msg_data: &[bool], @@ -150,7 +150,7 @@ where CS: ConstraintSystem, { let mut allocated = vec![]; - for (i, e) in audit_path.into_iter().enumerate() { + for (i, e) in audit_path.iter().enumerate() { let path_element = AllocatedNum::alloc(cs.namespace(|| format!("path element{}", i)), || { Ok(*e.get()?) @@ -188,7 +188,7 @@ pub fn append_be_fixed_width(content: &mut Vec, x: &P, widt content.extend(token_bits.clone()); } -pub fn le_bit_vector_into_field_element(bits: &Vec) -> P { +pub fn le_bit_vector_into_field_element(bits: &[bool]) -> P { // double and add let mut fe = P::zero(); let mut base = P::one(); @@ -226,7 +226,7 @@ pub fn le_bit_vector_into_field_element(bits: &Vec) -> P { // field_element } -pub fn be_bit_vector_into_bytes(bits: &Vec) -> Vec { +pub fn be_bit_vector_into_bytes(bits: &[bool]) -> Vec { let mut bytes: Vec = vec![]; let byte_chunks = bits.chunks(8); @@ -234,7 +234,7 @@ pub fn be_bit_vector_into_bytes(bits: &Vec) -> Vec { for byte_chunk in byte_chunks { let mut byte = 0u8; // pack just in order - for (i, bit) in byte_chunk.into_iter().enumerate() { + for (i, bit) in byte_chunk.iter().enumerate() { if *bit { byte |= 1 << (7 - i); } @@ -245,7 +245,7 @@ pub fn be_bit_vector_into_bytes(bits: &Vec) -> Vec { bytes } -pub fn le_bit_vector_into_bytes(bits: &Vec) -> Vec { +pub fn le_bit_vector_into_bytes(bits: &[bool]) -> Vec { let mut bytes: Vec = vec![]; let byte_chunks = bits.chunks(8); @@ -253,7 +253,7 @@ pub fn le_bit_vector_into_bytes(bits: &Vec) -> Vec { for byte_chunk in byte_chunks { let mut byte = 0u8; // pack just in order - for (i, bit) in byte_chunk.into_iter().enumerate() { + for (i, bit) in byte_chunk.iter().enumerate() { if *bit { byte |= 1 << i; } @@ -268,16 +268,12 @@ pub fn encode_fs_into_fr(input: E::Fs) -> E::Fr { let mut fs_le_bits: Vec = BitIterator::new(input.into_repr()).collect(); fs_le_bits.reverse(); - let converted = le_bit_vector_into_field_element::(&fs_le_bits); - - converted + le_bit_vector_into_field_element::(&fs_le_bits) } pub fn encode_fr_into_fs(input: E::Fr) -> E::Fs { let mut fr_le_bits: Vec = BitIterator::new(input.into_repr()).collect(); fr_le_bits.reverse(); - let converted = le_bit_vector_into_field_element::(&fr_le_bits); - - converted -} \ No newline at end of file + le_bit_vector_into_field_element::(&fr_le_bits) +} diff --git a/core/franklincircuit/src/witness/close_account.rs b/core/circuit/src/witness/close_account.rs similarity index 87% rename from core/franklincircuit/src/witness/close_account.rs rename to core/circuit/src/witness/close_account.rs index 3813061c2b..1aeb1147c9 100644 --- a/core/franklincircuit/src/witness/close_account.rs +++ b/core/circuit/src/witness/close_account.rs @@ -5,9 +5,9 @@ use crate::utils::*; use ff::{Field, PrimeField}; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::circuit::account::CircuitAccountTree; -use franklinmodels::node::operations::CloseOp; -use franklinmodels::params as franklin_constants; +use models::circuit::account::CircuitAccountTree; +use models::node::operations::CloseOp; +use models::params as franklin_constants; use pairing::bn256::*; pub struct CloseAccountData { @@ -27,7 +27,7 @@ impl CloseAccountWitness { append_be_fixed_width( &mut pubdata_bits, &self.tx_type.unwrap(), - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_be_fixed_width( @@ -133,14 +133,14 @@ pub fn calculate_close_account_operations_from_witness( .map(|x| le_bit_vector_into_field_element(&x.to_vec())) .collect(); let operation_zero = Operation { - new_root: close_account_witness.after_root.clone(), + new_root: close_account_witness.after_root, tx_type: close_account_witness.tx_type, chunk: Some(Fr::from_str("0").unwrap()), pubdata_chunk: Some(pubdata_chunks[0]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: close_account_witness.args.clone(), lhs: close_account_witness.before.clone(), rhs: close_account_witness.before.clone(), @@ -153,7 +153,7 @@ pub fn calculate_close_account_operations_from_witness( mod test { use super::*; use crate::witness::utils::public_data_commitment; - use franklinmodels::merkle_tree::PedersenHasher; + use models::merkle_tree::PedersenHasher; use crate::circuit::FranklinCircuit; use bellman::Circuit; @@ -164,10 +164,8 @@ mod test { use franklin_crypto::circuit::test::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ - CircuitAccount, CircuitAccountTree, CircuitBalanceTree, - }; - use franklinmodels::params as franklin_constants; + use models::circuit::account::{CircuitAccount, CircuitAccountTree, CircuitBalanceTree}; + use models::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] @@ -189,7 +187,7 @@ mod test { let sender_pub_key_hash = pub_key_hash(&sender_pk, &phasher); let (sender_x, sender_y) = sender_pk.0.into_xy(); let sender_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: sender_pub_key_hash, // pub_x: validator_x.clone(), // pub_y: validator_y.clone(), @@ -202,13 +200,13 @@ mod test { let validator_pub_key_hash = pub_key_hash(&validator_pk, &phasher); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -217,12 +215,8 @@ mod test { account_address %= tree.capacity(); //-------------- Start applying changes to state - let close_account_witness = apply_close_account( - &mut tree, - &CloseAccountData { - account_address: account_address, - }, - ); + let close_account_witness = + apply_close_account(&mut tree, &CloseAccountData { account_address }); let sig_msg = Fr::from_str("2").unwrap(); //dummy sig msg cause skipped on close_account proof let mut sig_bits: Vec = BitIterator::new(sig_msg.into_repr()).collect(); @@ -246,7 +240,7 @@ mod test { let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, 0, 0); println!("test root after fees {}", root_after_fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &close_account_witness.get_pubdata(), @@ -264,13 +258,13 @@ mod test { params, old_root: close_account_witness.before_root, new_root: Some(root_after_fee), - operations: operations, + operations, pub_data_commitment: Some(public_data_commitment), block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; instance.synthesize(&mut cs).unwrap(); diff --git a/core/franklincircuit/src/witness/deposit.rs b/core/circuit/src/witness/deposit.rs similarity index 84% rename from core/franklincircuit/src/witness/deposit.rs rename to core/circuit/src/witness/deposit.rs index a87a9e0800..a1d4a6f206 100644 --- a/core/franklincircuit/src/witness/deposit.rs +++ b/core/circuit/src/witness/deposit.rs @@ -7,10 +7,10 @@ use num_traits::cast::ToPrimitive; use franklin_crypto::circuit::float_point::{convert_to_float, parse_float_to_u128}; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::circuit::account::CircuitAccountTree; +use models::circuit::account::CircuitAccountTree; -use franklinmodels::node::DepositOp; -use franklinmodels::params as franklin_constants; +use models::node::DepositOp; +use models::params as franklin_constants; use pairing::bn256::*; pub struct DepositData { @@ -34,7 +34,7 @@ impl DepositWitness { append_be_fixed_width( &mut pubdata_bits, &self.tx_type.unwrap(), - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_be_fixed_width( @@ -45,7 +45,7 @@ impl DepositWitness { append_be_fixed_width( &mut pubdata_bits, &self.before.token.unwrap(), - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, ); append_be_fixed_width( &mut pubdata_bits, @@ -79,8 +79,8 @@ pub fn apply_deposit_tx( let deposit_data = DepositData { amount: deposit.tx.amount.to_u128().unwrap(), fee: deposit.tx.fee.to_u128().unwrap(), - token: deposit.tx.token as u32, - account_address: deposit.account_id as u32, + token: u32::from(deposit.tx.token), + account_address: deposit.account_id, new_pub_key_hash: alt_new_pubkey_hash, }; apply_deposit(tree, &deposit_data) @@ -103,15 +103,15 @@ pub fn apply_deposit( let amount_bits = convert_to_float( deposit.amount, - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); let reparsed_amount = parse_float_to_u128( amount_bits.clone(), - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -123,15 +123,15 @@ pub fn apply_deposit( let fee_bits = convert_to_float( deposit.fee, - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); let reparsed_fee = parse_float_to_u128( fee_bits.clone(), - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -139,8 +139,8 @@ pub fn apply_deposit( let fee_encoded: Fr = le_bit_vector_into_field_element(&fee_bits); //calculate a and b - let a = amount_as_field_element.clone(); - let b = fee_as_field_element.clone(); + let a = amount_as_field_element; + let b = fee_as_field_element; //applying deposit let (account_witness_before, account_witness_after, balance_before, balance_after) = @@ -218,56 +218,56 @@ pub fn calculate_deposit_operations_from_witness( deposit_witness.before.witness.balance_subtree_path.len() ); let operation_zero = Operation { - new_root: deposit_witness.after_root.clone(), + new_root: deposit_witness.after_root, tx_type: deposit_witness.tx_type, chunk: Some(Fr::from_str("0").unwrap()), pubdata_chunk: Some(pubdata_chunks[0]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: deposit_witness.args.clone(), lhs: deposit_witness.before.clone(), rhs: deposit_witness.before.clone(), }; let operation_one = Operation { - new_root: deposit_witness.after_root.clone(), + new_root: deposit_witness.after_root, tx_type: deposit_witness.tx_type, chunk: Some(Fr::from_str("1").unwrap()), pubdata_chunk: Some(pubdata_chunks[1]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: deposit_witness.args.clone(), lhs: deposit_witness.after.clone(), rhs: deposit_witness.after.clone(), }; let operation_two = Operation { - new_root: deposit_witness.after_root.clone(), + new_root: deposit_witness.after_root, tx_type: deposit_witness.tx_type, chunk: Some(Fr::from_str("2").unwrap()), pubdata_chunk: Some(pubdata_chunks[2]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: deposit_witness.args.clone(), lhs: deposit_witness.after.clone(), rhs: deposit_witness.after.clone(), }; let operation_three = Operation { - new_root: deposit_witness.after_root.clone(), + new_root: deposit_witness.after_root, tx_type: deposit_witness.tx_type, chunk: Some(Fr::from_str("3").unwrap()), pubdata_chunk: Some(pubdata_chunks[3]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: deposit_witness.args.clone(), lhs: deposit_witness.after.clone(), rhs: deposit_witness.after.clone(), @@ -284,7 +284,7 @@ pub fn calculate_deposit_operations_from_witness( #[cfg(test)] mod test { use super::*; - use franklinmodels::merkle_tree::PedersenHasher; + use models::merkle_tree::PedersenHasher; use crate::witness::utils::public_data_commitment; use bellman::groth16::generate_random_parameters; @@ -294,15 +294,13 @@ mod test { use bellman::Circuit; use ff::{BitIterator, Field, PrimeField}; use franklin_crypto::alt_babyjubjub::AltJubjubBn256; - use franklinmodels::primitives::GetBits; + use models::primitives::GetBits; use franklin_crypto::circuit::test::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ - CircuitAccount, CircuitAccountTree, CircuitBalanceTree, - }; - use franklinmodels::params as franklin_constants; + use models::circuit::account::{CircuitAccount, CircuitAccountTree, CircuitBalanceTree}; + use models::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; @@ -325,7 +323,7 @@ mod test { let sender_pub_key_hash = pub_key_hash(&sender_pk, &phasher); let (sender_x, sender_y) = sender_pk.0.into_xy(); let sender_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: sender_pub_key_hash, // pub_x: validator_x.clone(), // pub_y: validator_y.clone(), @@ -338,7 +336,7 @@ mod test { let validator_pub_key_hash = pub_key_hash(&validator_pk, &phasher); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; @@ -352,7 +350,7 @@ mod test { ); let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -367,10 +365,10 @@ mod test { let deposit_witness = apply_deposit( &mut tree, &DepositData { - amount: amount, - fee: fee, - token: token, - account_address: account_address, + amount, + fee, + token, + account_address, new_pub_key_hash: sender_pub_key_hash, }, ); @@ -397,7 +395,7 @@ mod test { let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, token, fee); println!("test root after fees {}", root_after_fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &deposit_witness.get_pubdata(), @@ -414,13 +412,13 @@ mod test { let instance = FranklinCircuit { operation_batch_size: 10, params, - old_root: deposit_witness.before_root.clone(), - new_root: Some(root_after_fee.clone()), + old_root: deposit_witness.before_root, + new_root: Some(root_after_fee), operations: operations.clone(), - pub_data_commitment: Some(public_data_commitment.clone()), - block_number: Some(block_number.clone()), + pub_data_commitment: Some(public_data_commitment), + block_number: Some(block_number), validator_account: validator_account_witness.clone(), - validator_address: Some(validator_address.clone()), + validator_address: Some(validator_address), validator_balances: validator_balances.clone(), validator_audit_path: validator_audit_path.clone(), }; @@ -455,7 +453,7 @@ mod test { let sender_pub_key_hash = pub_key_hash(&sender_pk, &phasher); let (sender_x, sender_y) = sender_pk.0.into_xy(); let sender_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: sender_pub_key_hash, }; @@ -467,13 +465,13 @@ mod test { let validator_pub_key_hash = pub_key_hash(&validator_pk, &phasher); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -488,10 +486,10 @@ mod test { let deposit_witness = apply_deposit( &mut tree, &DepositData { - amount: amount, - fee: fee, - token: token, - account_address: account_address, + amount, + fee, + token, + account_address, new_pub_key_hash: sender_pub_key_hash, }, ); @@ -518,7 +516,7 @@ mod test { let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, token, fee); println!("test root after fees {}", root_after_fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &deposit_witness.get_pubdata(), @@ -533,13 +531,13 @@ mod test { let instance = FranklinCircuit { operation_batch_size: 10, params, - old_root: deposit_witness.before_root.clone(), - new_root: Some(root_after_fee.clone()), + old_root: deposit_witness.before_root, + new_root: Some(root_after_fee), operations: operations.clone(), - pub_data_commitment: Some(public_data_commitment.clone()), - block_number: Some(block_number.clone()), + pub_data_commitment: Some(public_data_commitment), + block_number: Some(block_number), validator_account: validator_account_witness.clone(), - validator_address: Some(validator_address.clone()), + validator_address: Some(validator_address), validator_balances: validator_balances.clone(), validator_audit_path: validator_audit_path.clone(), }; @@ -551,13 +549,13 @@ mod test { params, old_root: deposit_witness.before_root, new_root: Some(root_after_fee), - operations: operations, + operations, pub_data_commitment: Some(public_data_commitment), block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; let proof = create_random_proof(instance, &tmp_cirtuit_params, &mut rng); diff --git a/core/franklincircuit/src/witness/mod.rs b/core/circuit/src/witness/mod.rs similarity index 100% rename from core/franklincircuit/src/witness/mod.rs rename to core/circuit/src/witness/mod.rs diff --git a/core/franklincircuit/src/witness/noop.rs b/core/circuit/src/witness/noop.rs similarity index 84% rename from core/franklincircuit/src/witness/noop.rs rename to core/circuit/src/witness/noop.rs index 4890822e9d..f1f6db496c 100644 --- a/core/franklincircuit/src/witness/noop.rs +++ b/core/circuit/src/witness/noop.rs @@ -7,7 +7,7 @@ use ff::{Field, PrimeField}; use crate::account::AccountWitness; -use franklinmodels::circuit::account::CircuitAccountTree; +use models::circuit::account::CircuitAccountTree; use pairing::bn256::*; @@ -24,7 +24,7 @@ pub fn noop_operation( let token_fe = Fr::zero(); let balance_value = match acc.subtree.get(0) { None => Fr::zero(), - Some(bal) => bal.value.clone(), + Some(bal) => bal.value, }; let pubdata = vec![false; 64]; let pubdata_chunks: Vec<_> = pubdata @@ -38,10 +38,10 @@ pub fn noop_operation( tx_type: Some(Fr::from_str("0").unwrap()), chunk: Some(Fr::from_str("0").unwrap()), pubdata_chunk: Some(pubdata_chunks[0]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: OperationArguments { ethereum_key: Some(Fr::zero()), @@ -56,11 +56,11 @@ pub fn noop_operation( token: Some(token_fe), witness: OperationBranchWitness { account_witness: AccountWitness { - nonce: Some(acc.nonce.clone()), - pub_key_hash: Some(acc.pub_key_hash.clone()), + nonce: Some(acc.nonce), + pub_key_hash: Some(acc.pub_key_hash), }, account_path: audit_account.clone(), - balance_value: Some(balance_value.clone()), + balance_value: Some(balance_value), balance_subtree_path: audit_balance.clone(), }, }, @@ -69,11 +69,11 @@ pub fn noop_operation( token: Some(token_fe), witness: OperationBranchWitness { account_witness: AccountWitness { - nonce: Some(acc.nonce.clone()), - pub_key_hash: Some(acc.pub_key_hash.clone()), + nonce: Some(acc.nonce), + pub_key_hash: Some(acc.pub_key_hash), }, account_path: audit_account.clone(), - balance_value: Some(balance_value.clone()), + balance_value: Some(balance_value), balance_subtree_path: audit_balance.clone(), }, }, @@ -93,14 +93,14 @@ mod test { use franklin_crypto::circuit::test::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ + use models::circuit::account::{ Balance, CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; - use franklinmodels::params as franklin_constants; + use models::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; - use franklinmodels::merkle_tree::PedersenHasher; + use models::merkle_tree::PedersenHasher; #[test] #[ignore] @@ -129,13 +129,13 @@ mod test { let (validator_x, validator_y) = validator_pk.0.into_xy(); println!("x = {}, y = {}", validator_x, validator_y); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -150,7 +150,7 @@ mod test { Fr::from_str(&sender_balance_before.to_string()).unwrap(); let mut sender_balance_tree = - CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32); + CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32); sender_balance_tree.insert( token, Balance { @@ -161,7 +161,7 @@ mod test { let sender_leaf_initial = CircuitAccount:: { subtree: sender_balance_tree, nonce: Fr::zero(), - pub_key_hash: sender_pub_key_hash.clone(), + pub_key_hash: sender_pub_key_hash, }; tree.insert(account_address, sender_leaf_initial); @@ -184,10 +184,10 @@ mod test { &sender_y, ); let (_, validator_account_witness) = apply_fee(&mut tree, validator_address_number, 0, 0); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( - &vec![false; 64], + &[false; 64], Some(tree.root_hash()), Some(tree.root_hash()), Some(validator_address), @@ -206,8 +206,8 @@ mod test { block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; instance.synthesize(&mut cs).unwrap(); diff --git a/core/franklincircuit/src/witness/partial_exit.rs b/core/circuit/src/witness/partial_exit.rs similarity index 84% rename from core/franklincircuit/src/witness/partial_exit.rs rename to core/circuit/src/witness/partial_exit.rs index 08ebd57888..256bec411b 100644 --- a/core/franklincircuit/src/witness/partial_exit.rs +++ b/core/circuit/src/witness/partial_exit.rs @@ -7,11 +7,11 @@ use ff::{Field, PrimeField}; use franklin_crypto::circuit::float_point::convert_to_float; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::circuit::account::CircuitAccountTree; +use models::circuit::account::CircuitAccountTree; use num_traits::cast::ToPrimitive; -use franklinmodels::node::PartialExitOp; -use franklinmodels::params as franklin_constants; +use models::node::PartialExitOp; +use models::params as franklin_constants; use pairing::bn256::*; pub struct PartialExitData { @@ -35,7 +35,7 @@ impl PartialExitWitness { append_be_fixed_width( &mut pubdata_bits, &self.tx_type.unwrap(), - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_be_fixed_width( @@ -46,7 +46,7 @@ impl PartialExitWitness { append_be_fixed_width( &mut pubdata_bits, &self.before.token.unwrap(), - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, ); append_be_fixed_width( &mut pubdata_bits, @@ -77,8 +77,8 @@ pub fn apply_partial_exit_tx( let transfer_data = PartialExitData { amount: partial_exit.tx.amount.to_u128().unwrap(), fee: partial_exit.tx.fee.to_u128().unwrap(), - token: partial_exit.tx.token as u32, - account_address: partial_exit.account_id as u32, + token: u32::from(partial_exit.tx.token), + account_address: partial_exit.account_id, ethereum_key: Fr::from_hex(&format!("{:x}", &partial_exit.tx.eth_address)).unwrap(), }; // le_bit_vector_into_field_element() @@ -102,8 +102,8 @@ pub fn apply_partial_exit( let amount_bits = convert_to_float( partial_exit.amount, - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -114,8 +114,8 @@ pub fn apply_partial_exit( let fee_bits = convert_to_float( partial_exit.fee, - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -149,8 +149,8 @@ pub fn apply_partial_exit( let (audit_path_after, audit_balance_path_after) = get_audits(tree, partial_exit.account_address, partial_exit.token); - let a = balance_before.clone(); - let mut b = amount_as_field_element.clone(); + let a = balance_before; + let mut b = amount_as_field_element; b.add_assign(&fee_as_field_element); PartialExitWitness { @@ -201,58 +201,56 @@ pub fn calculate_partial_exit_operations_from_witness( .collect(); let operation_zero = Operation { - new_root: partial_exit_witness.after_root.clone(), + new_root: partial_exit_witness.after_root, tx_type: partial_exit_witness.tx_type, chunk: Some(Fr::from_str("0").unwrap()), pubdata_chunk: Some(pubdata_chunks[0]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: partial_exit_witness.args.clone(), lhs: partial_exit_witness.before.clone(), rhs: partial_exit_witness.before.clone(), }; - println!("pubdata_chunk number {} is {}", 1, pubdata_chunks[1]); let operation_one = Operation { - new_root: partial_exit_witness.after_root.clone(), + new_root: partial_exit_witness.after_root, tx_type: partial_exit_witness.tx_type, chunk: Some(Fr::from_str("1").unwrap()), pubdata_chunk: Some(pubdata_chunks[1]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: partial_exit_witness.args.clone(), lhs: partial_exit_witness.after.clone(), rhs: partial_exit_witness.after.clone(), }; - println!("pubdata_chunk number {} is {}", 2, pubdata_chunks[2]); let operation_two = Operation { - new_root: partial_exit_witness.after_root.clone(), + new_root: partial_exit_witness.after_root, tx_type: partial_exit_witness.tx_type, chunk: Some(Fr::from_str("2").unwrap()), pubdata_chunk: Some(pubdata_chunks[2]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: partial_exit_witness.args.clone(), lhs: partial_exit_witness.after.clone(), rhs: partial_exit_witness.after.clone(), }; let operation_three = Operation { - new_root: partial_exit_witness.after_root.clone(), + new_root: partial_exit_witness.after_root, tx_type: partial_exit_witness.tx_type, chunk: Some(Fr::from_str("3").unwrap()), pubdata_chunk: Some(pubdata_chunks[3]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: partial_exit_witness.args.clone(), lhs: partial_exit_witness.after.clone(), rhs: partial_exit_witness.after.clone(), @@ -279,11 +277,11 @@ mod test { use franklin_crypto::circuit::test::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ + use models::circuit::account::{ Balance, CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; - use franklinmodels::merkle_tree::PedersenHasher; - use franklinmodels::params as franklin_constants; + use models::merkle_tree::PedersenHasher; + use models::params as franklin_constants; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] #[ignore] @@ -312,13 +310,13 @@ mod test { let (validator_x, validator_y) = validator_pk.0.into_xy(); println!("x = {}, y = {}", validator_x, validator_y); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), - pub_key_hash: validator_pub_key_hash.clone(), + pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -336,7 +334,7 @@ mod test { Fr::from_str(&sender_balance_before.to_string()).unwrap(); let mut sender_balance_tree = - CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32); + CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32); sender_balance_tree.insert( token, Balance { @@ -347,7 +345,7 @@ mod test { let sender_leaf_initial = CircuitAccount:: { subtree: sender_balance_tree, nonce: Fr::zero(), - pub_key_hash: sender_pub_key_hash.clone(), + pub_key_hash: sender_pub_key_hash, }; tree.insert(account_address, sender_leaf_initial); @@ -355,11 +353,11 @@ mod test { let partial_exit_witness = apply_partial_exit( &mut tree, &PartialExitData { - amount: amount, - fee: fee, - token: token, - account_address: account_address, - ethereum_key: ethereum_key, + amount, + fee, + token, + account_address, + ethereum_key, }, ); @@ -383,7 +381,7 @@ mod test { let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, token, fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &partial_exit_witness.get_pubdata(), @@ -400,13 +398,13 @@ mod test { params, old_root: partial_exit_witness.before_root, new_root: Some(root_after_fee), - operations: operations, + operations, pub_data_commitment: Some(public_data_commitment), block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; instance.synthesize(&mut cs).unwrap(); @@ -449,13 +447,13 @@ mod test { let (validator_x, validator_y) = validator_pk.0.into_xy(); println!("x = {}, y = {}", validator_x, validator_y); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -473,7 +471,7 @@ mod test { Fr::from_str(&sender_balance_before.to_string()).unwrap(); let mut sender_balance_tree = - CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32); + CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32); sender_balance_tree.insert( token, Balance { @@ -484,7 +482,7 @@ mod test { let sender_leaf_initial = CircuitAccount:: { subtree: sender_balance_tree, nonce: Fr::zero(), - pub_key_hash: sender_pub_key_hash.clone(), + pub_key_hash: sender_pub_key_hash, }; tree.insert(account_address, sender_leaf_initial); @@ -492,11 +490,11 @@ mod test { let partial_exit_witness = apply_partial_exit( &mut tree, &PartialExitData { - amount: amount, - fee: fee, - token: token, - account_address: account_address, - ethereum_key: ethereum_key, + amount, + fee, + token, + account_address, + ethereum_key, }, ); @@ -520,7 +518,7 @@ mod test { let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, token, fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &partial_exit_witness.get_pubdata(), @@ -537,13 +535,13 @@ mod test { params, old_root: partial_exit_witness.before_root, new_root: Some(root_after_fee), - operations: operations, + operations, pub_data_commitment: Some(public_data_commitment), block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; instance.synthesize(&mut cs).unwrap(); diff --git a/core/franklincircuit/src/witness/signature.rs b/core/circuit/src/witness/signature.rs similarity index 96% rename from core/franklincircuit/src/witness/signature.rs rename to core/circuit/src/witness/signature.rs index f507a68a43..ebbc10d6c2 100644 --- a/core/franklincircuit/src/witness/signature.rs +++ b/core/circuit/src/witness/signature.rs @@ -21,7 +21,7 @@ use franklin_crypto::circuit::pedersen_hash; use franklin_crypto::circuit::polynomial_lookup::{do_the_lookup, generate_powers}; use franklin_crypto::circuit::Assignment; use franklin_crypto::jubjub::{FixedGenerators, JubjubEngine, JubjubParams}; -use franklinmodels::params as franklin_constants; +use models::params as franklin_constants; #[derive(Clone)] pub struct SmallCircuit { @@ -63,10 +63,10 @@ fn test_small_circuit_franklin() { use franklin_crypto::circuit::test::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ + use models::circuit::account::{ Balance, CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; - use franklinmodels::params as franklin_constants; + use models::params as franklin_constants; use pairing::bn256::*; use rand::{Rng, SeedableRng, XorShiftRng}; diff --git a/core/franklincircuit/src/witness/transfer.rs b/core/circuit/src/witness/transfer.rs similarity index 90% rename from core/franklincircuit/src/witness/transfer.rs rename to core/circuit/src/witness/transfer.rs index 9b1c8d6a16..40939ac6c4 100644 --- a/core/franklincircuit/src/witness/transfer.rs +++ b/core/circuit/src/witness/transfer.rs @@ -4,12 +4,12 @@ use crate::utils::*; use ff::{Field, PrimeField}; use franklin_crypto::circuit::float_point::convert_to_float; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::circuit::account::CircuitAccountTree; -use franklinmodels::params as franklin_constants; +use models::circuit::account::CircuitAccountTree; +use models::params as franklin_constants; use num_traits::cast::ToPrimitive; use pairing::bn256::*; -use franklinmodels::node::TransferOp; +use models::node::TransferOp; pub struct TransferData { pub amount: u128, @@ -38,7 +38,7 @@ impl TransferWitness { append_be_fixed_width( &mut pubdata_bits, &self.tx_type.unwrap(), - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_be_fixed_width( @@ -49,7 +49,7 @@ impl TransferWitness { append_be_fixed_width( &mut pubdata_bits, &self.from_before.token.unwrap(), - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, ); append_be_fixed_width( &mut pubdata_bits, @@ -79,9 +79,9 @@ pub fn apply_transfer_tx( let transfer_data = TransferData { amount: transfer.tx.amount.to_u128().unwrap(), fee: transfer.tx.fee.to_u128().unwrap(), - token: transfer.tx.token as u32, - from_account_address: transfer.from as u32, - to_account_address: transfer.to as u32, + token: u32::from(transfer.tx.token), + from_account_address: transfer.from, + to_account_address: transfer.to, }; // le_bit_vector_into_field_element() apply_transfer(tree, &transfer_data) @@ -108,8 +108,8 @@ pub fn apply_transfer( let amount_bits = convert_to_float( transfer.amount, - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -120,8 +120,8 @@ pub fn apply_transfer( let fee_bits = convert_to_float( transfer.fee, - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -176,8 +176,8 @@ pub fn apply_transfer( get_audits(tree, transfer.to_account_address, transfer.token); //calculate a and b - let a = balance_from_before.clone(); - let mut b = amount_as_field_element.clone(); + let a = balance_from_before; + let mut b = amount_as_field_element; b.add_assign(&fee_as_field_element); TransferWitness { @@ -274,10 +274,10 @@ pub fn calculate_transfer_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("0").unwrap()), pubdata_chunk: Some(pubdata_chunks[0]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_before.clone(), rhs: transfer_witness.to_before.clone(), @@ -288,10 +288,10 @@ pub fn calculate_transfer_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("1").unwrap()), pubdata_chunk: Some(pubdata_chunks[1]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_intermediate.clone(), rhs: transfer_witness.to_intermediate.clone(), @@ -302,7 +302,7 @@ pub fn calculate_transfer_operations_from_witness( mod test { use super::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; - use franklinmodels::params as franklin_constants; + use models::params as franklin_constants; use crate::circuit::FranklinCircuit; use bellman::Circuit; @@ -313,11 +313,11 @@ mod test { use franklin_crypto::circuit::float_point::convert_to_float; use franklin_crypto::circuit::test::*; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ + use models::circuit::account::{ Balance, CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; - use franklinmodels::merkle_tree::hasher::Hasher; - use franklinmodels::merkle_tree::PedersenHasher; + use models::merkle_tree::hasher::Hasher; + use models::merkle_tree::PedersenHasher; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] #[ignore] @@ -387,13 +387,13 @@ mod test { let validator_pub_key_hash = le_bit_vector_into_field_element(&validator_pub_key_hash_bits); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -422,8 +422,8 @@ mod test { let transfer_amount_bits = convert_to_float( transfer_amount, - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -436,8 +436,8 @@ mod test { let fee_bits = convert_to_float( fee, - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -449,9 +449,9 @@ mod test { let block_number = Fr::from_str("1").unwrap(); // prepare state, so that we could make transfer let mut from_balance_tree = - CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32); + CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32); let mut to_balance_tree = - CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32); + CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32); from_balance_tree.insert( token, Balance { @@ -483,8 +483,8 @@ mod test { &mut tree, &TransferData { amount: transfer_amount, - fee: fee, - token: token, + fee, + token, from_account_address: from_leaf_number, to_account_address: to_leaf_number, }, @@ -500,7 +500,7 @@ mod test { append_le_fixed_width( &mut sig_bits, &transfer_tx_type, - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_le_fixed_width( &mut sig_bits, @@ -511,7 +511,7 @@ mod test { append_le_fixed_width( &mut sig_bits, &token_fe, - *franklin_constants::BALANCE_TREE_DEPTH, + franklin_constants::BALANCE_TREE_DEPTH, ); append_le_fixed_width( &mut sig_bits, @@ -563,7 +563,7 @@ mod test { let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, token, fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &transfer_witness.get_pubdata(), transfer_witness.before_root, @@ -580,13 +580,13 @@ mod test { params, old_root: transfer_witness.before_root, new_root: Some(root_after_fee), - operations: operations, + operations, pub_data_commitment: Some(public_data_commitment), block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; instance.synthesize(&mut cs).unwrap(); diff --git a/core/franklincircuit/src/witness/transfer_to_new.rs b/core/circuit/src/witness/transfer_to_new.rs similarity index 88% rename from core/franklincircuit/src/witness/transfer_to_new.rs rename to core/circuit/src/witness/transfer_to_new.rs index b9e5e183c9..48c2524b66 100644 --- a/core/franklincircuit/src/witness/transfer_to_new.rs +++ b/core/circuit/src/witness/transfer_to_new.rs @@ -4,9 +4,9 @@ use crate::utils::*; use ff::{Field, PrimeField}; use franklin_crypto::circuit::float_point::convert_to_float; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::circuit::account::CircuitAccountTree; -use franklinmodels::node::TransferToNewOp; -use franklinmodels::params as franklin_constants; +use models::circuit::account::CircuitAccountTree; +use models::node::TransferToNewOp; +use models::params as franklin_constants; use num_traits::cast::ToPrimitive; use pairing::bn256::*; @@ -37,7 +37,7 @@ impl TransferToNewWitness { append_be_fixed_width( &mut pubdata_bits, &self.tx_type.unwrap(), - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_be_fixed_width( @@ -48,7 +48,7 @@ impl TransferToNewWitness { append_be_fixed_width( &mut pubdata_bits, &self.from_before.token.unwrap(), - *franklin_constants::TOKEN_EXT_BIT_WIDTH, + franklin_constants::TOKEN_EXT_BIT_WIDTH, ); append_be_fixed_width( @@ -87,9 +87,9 @@ pub fn apply_transfer_to_new_tx( let transfer_data = TransferToNewData { amount: transfer_to_new.tx.amount.to_u128().unwrap(), fee: transfer_to_new.tx.fee.to_u128().unwrap(), - token: transfer_to_new.tx.token as u32, - from_account_address: transfer_to_new.from as u32, - to_account_address: transfer_to_new.to as u32, + token: u32::from(transfer_to_new.tx.token), + from_account_address: transfer_to_new.from, + to_account_address: transfer_to_new.to, new_pub_key_hash: new_pubkey_hash, }; // le_bit_vector_into_field_element() @@ -125,8 +125,8 @@ pub fn apply_transfer_to_new( let amount_bits = convert_to_float( transfer_to_new.amount, - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -141,8 +141,8 @@ pub fn apply_transfer_to_new( ); let fee_bits = convert_to_float( transfer_to_new.fee, - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -212,8 +212,8 @@ pub fn apply_transfer_to_new( ); //calculate a and b - let a = balance_from_before.clone(); - let mut b = amount_as_field_element.clone(); + let a = balance_from_before; + let mut b = amount_as_field_element; b.add_assign(&fee_as_field_element); TransferToNewWitness { from_before: OperationBranch { @@ -309,10 +309,10 @@ pub fn calculate_transfer_to_new_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("0").unwrap()), pubdata_chunk: Some(pubdata_chunks[0]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_before.clone(), rhs: transfer_witness.to_before.clone(), @@ -323,10 +323,10 @@ pub fn calculate_transfer_to_new_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("1").unwrap()), pubdata_chunk: Some(pubdata_chunks[1]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_intermediate.clone(), rhs: transfer_witness.to_intermediate.clone(), @@ -337,10 +337,10 @@ pub fn calculate_transfer_to_new_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("2").unwrap()), pubdata_chunk: Some(pubdata_chunks[2]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_after.clone(), rhs: transfer_witness.to_after.clone(), @@ -351,10 +351,10 @@ pub fn calculate_transfer_to_new_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("3").unwrap()), pubdata_chunk: Some(pubdata_chunks[3]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_after.clone(), rhs: transfer_witness.to_after.clone(), @@ -365,10 +365,10 @@ pub fn calculate_transfer_to_new_operations_from_witness( tx_type: transfer_witness.tx_type, chunk: Some(Fr::from_str("4").unwrap()), pubdata_chunk: Some(pubdata_chunks[4]), - sig_msg: Some(sig_msg.clone()), + sig_msg: Some(*sig_msg), signature: signature.clone(), - signer_pub_key_x: Some(signer_pub_key_x.clone()), - signer_pub_key_y: Some(signer_pub_key_y.clone()), + signer_pub_key_x: Some(*signer_pub_key_x), + signer_pub_key_y: Some(*signer_pub_key_y), args: transfer_witness.args.clone(), lhs: transfer_witness.from_after.clone(), rhs: transfer_witness.to_after.clone(), @@ -385,7 +385,7 @@ pub fn calculate_transfer_to_new_operations_from_witness( mod test { use super::*; use franklin_crypto::eddsa::{PrivateKey, PublicKey}; - use franklinmodels::params as franklin_constants; + use models::params as franklin_constants; use crate::circuit::FranklinCircuit; use bellman::Circuit; @@ -396,11 +396,11 @@ mod test { use franklin_crypto::circuit::float_point::convert_to_float; use franklin_crypto::circuit::test::*; use franklin_crypto::jubjub::FixedGenerators; - use franklinmodels::circuit::account::{ + use models::circuit::account::{ Balance, CircuitAccount, CircuitAccountTree, CircuitBalanceTree, }; - use franklinmodels::merkle_tree::hasher::Hasher; - use franklinmodels::merkle_tree::PedersenHasher; + use models::merkle_tree::hasher::Hasher; + use models::merkle_tree::PedersenHasher; use rand::{Rng, SeedableRng, XorShiftRng}; #[test] #[ignore] @@ -438,13 +438,13 @@ mod test { let (validator_x, validator_y) = validator_pk.0.into_xy(); println!("x = {}, y = {}", validator_x, validator_y); let validator_leaf = CircuitAccount:: { - subtree: CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32), + subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), pub_key_hash: validator_pub_key_hash, }; let mut validator_balances = vec![]; - for _ in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { + for _ in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { validator_balances.push(Some(Fr::zero())); } tree.insert(validator_address_number, validator_leaf); @@ -468,8 +468,8 @@ mod test { let transfer_amount_bits = convert_to_float( transfer_amount, - *franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, - *franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, + franklin_constants::AMOUNT_EXPONENT_BIT_WIDTH, + franklin_constants::AMOUNT_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -480,8 +480,8 @@ mod test { let fee_bits = convert_to_float( fee, - *franklin_constants::FEE_EXPONENT_BIT_WIDTH, - *franklin_constants::FEE_MANTISSA_BIT_WIDTH, + franklin_constants::FEE_EXPONENT_BIT_WIDTH, + franklin_constants::FEE_MANTISSA_BIT_WIDTH, 10, ) .unwrap(); @@ -493,7 +493,7 @@ mod test { let block_number = Fr::from_str("1").unwrap(); // prepare state, so that we could make transfer let mut from_balance_tree = - CircuitBalanceTree::new(*franklin_constants::BALANCE_TREE_DEPTH as u32); + CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32); from_balance_tree.insert( token, Balance { @@ -513,8 +513,8 @@ mod test { &mut tree, &TransferToNewData { amount: transfer_amount, - fee: fee, - token: token, + fee, + token, from_account_address: from_leaf_number, to_account_address: to_leaf_number, new_pub_key_hash: to_pub_key_hash, @@ -527,7 +527,7 @@ mod test { append_le_fixed_width( &mut sig_bits, &transfer_tx_type, - *franklin_constants::TX_TYPE_BIT_WIDTH, + franklin_constants::TX_TYPE_BIT_WIDTH, ); append_le_fixed_width( &mut sig_bits, @@ -537,7 +537,7 @@ mod test { append_le_fixed_width( &mut sig_bits, &token_fe, - *franklin_constants::BALANCE_TREE_DEPTH, + franklin_constants::BALANCE_TREE_DEPTH, ); append_le_fixed_width( &mut sig_bits, @@ -586,7 +586,7 @@ mod test { ); let (root_after_fee, validator_account_witness) = apply_fee(&mut tree, validator_address_number, token, fee); - let (validator_audit_path, _) = get_audits(&mut tree, validator_address_number, 0); + let (validator_audit_path, _) = get_audits(&tree, validator_address_number, 0); let public_data_commitment = public_data_commitment::( &transfer_witness.get_pubdata(), @@ -603,13 +603,13 @@ mod test { params, old_root: transfer_witness.before_root, new_root: transfer_witness.after_root, - operations: operations, + operations, pub_data_commitment: Some(public_data_commitment), block_number: Some(block_number), validator_account: validator_account_witness, validator_address: Some(validator_address), - validator_balances: validator_balances, - validator_audit_path: validator_audit_path, + validator_balances, + validator_audit_path, }; instance.synthesize(&mut cs).unwrap(); diff --git a/core/franklincircuit/src/witness/utils.rs b/core/circuit/src/witness/utils.rs similarity index 91% rename from core/franklincircuit/src/witness/utils.rs rename to core/circuit/src/witness/utils.rs index 312732776b..67e211716e 100644 --- a/core/franklincircuit/src/witness/utils.rs +++ b/core/circuit/src/witness/utils.rs @@ -11,9 +11,9 @@ use franklin_crypto::eddsa::PrivateKey; use franklin_crypto::eddsa::PublicKey; use franklin_crypto::jubjub::FixedGenerators; use franklin_crypto::jubjub::JubjubEngine; -use franklinmodels::circuit::account::{Balance, CircuitAccount, CircuitAccountTree}; -use franklinmodels::merkle_tree::hasher::Hasher; -use franklinmodels::params as franklin_constants; +use models::circuit::account::{Balance, CircuitAccount, CircuitAccountTree}; +use models::merkle_tree::hasher::Hasher; +use models::params as franklin_constants; use pairing::bn256::*; use rand::{Rng, SeedableRng, XorShiftRng}; @@ -51,8 +51,7 @@ pub fn pub_key_hash>( &pub_key_hash, franklin_constants::NEW_PUBKEY_HASH_WIDTH, ); - let pub_key_hash = le_bit_vector_into_field_element(&pub_key_hash_bits); - pub_key_hash + le_bit_vector_into_field_element(&pub_key_hash_bits) } pub fn public_data_commitment( pubdata_bits: &[bool], @@ -148,8 +147,7 @@ pub fn public_data_commitment( repr.read_be(&hash_result[..]) .expect("pack hash as field element"); - let public_data_commitment = E::Fr::from_repr(repr).unwrap(); - public_data_commitment + E::Fr::from_repr(repr).unwrap() } pub fn get_audits( @@ -197,9 +195,9 @@ pub fn apply_leaf_operation< .subtree .remove(token) .unwrap_or(Balance { value: Fr::zero() }); - let balance_before = balance.value.clone(); + let balance_before = balance.value; fb(&mut balance); - let balance_after = balance.value.clone(); + let balance_after = balance.value; account.subtree.insert(token, balance.clone()); fa(&mut account); @@ -228,14 +226,11 @@ pub fn apply_fee( .remove(validator_address) .expect("validator_leaf not empty"); let validator_account_witness = AccountWitness { - nonce: Some(validator_leaf.nonce.clone()), - pub_key_hash: Some(validator_leaf.pub_key_hash.clone()), + nonce: Some(validator_leaf.nonce), + pub_key_hash: Some(validator_leaf.pub_key_hash), }; - let mut balance = validator_leaf - .subtree - .remove(token) - .unwrap_or(Balance::default()); + let mut balance = validator_leaf.subtree.remove(token).unwrap_or_default(); balance.value.add_assign(&fee_fe); validator_leaf.subtree.insert(token, balance); diff --git a/core/eth_client/Cargo.toml b/core/eth_client/Cargo.toml index 2091d9ac09..a3c441732e 100644 --- a/core/eth_client/Cargo.toml +++ b/core/eth_client/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [dependencies] -models = { package = "franklinmodels", path = "../franklinmodels" } +models = { package = "models", path = "../models" } serde = "1.0.90" serde_derive = "1.0.90" ethereum-types = "0.4.0" diff --git a/core/franklin_key_generator/Cargo.toml b/core/franklin_key_generator/Cargo.toml deleted file mode 100644 index 05763838b6..0000000000 --- a/core/franklin_key_generator/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "franklin_key_generator" -version = "0.1.1" -edition = "2018" - -authors = [ - "Alex Gluchowski ", - "Alex Vlasov " -] - -[dependencies] -rand = "0.4" -time = "0.1" -pairing = { package = "pairing_ce", version = "0.17.0" } -franklin_crypto = { package = "franklin-crypto", git = "ssh://git@github.com/matter-labs/franklin-crypto.git"} -bellman = { package = "bellman_ce", version = "0.3.0" } -franklinmodels = { path = "../franklinmodels" } -franklincircuit= { path = "../franklincircuit" } -hex = "0.3.2" -rust-crypto = "0.2" -ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } -log = "0.4" -env_logger = "0.6" diff --git a/core/franklin_key_generator/src/main.rs b/core/franklin_key_generator/src/main.rs deleted file mode 100644 index dc6899c7da..0000000000 --- a/core/franklin_key_generator/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[macro_use] -extern crate log; - -pub mod franklin_key; -pub mod vk_contract_generator; - -use franklin_key::make_franklin_key; - -fn main() { - env_logger::init(); - - make_franklin_key(); -} diff --git a/core/franklin_key_generator/src/vk_contract_generator.rs b/core/franklin_key_generator/src/vk_contract_generator.rs deleted file mode 100644 index 93920b0a2c..0000000000 --- a/core/franklin_key_generator/src/vk_contract_generator.rs +++ /dev/null @@ -1,98 +0,0 @@ -// Library to generate a EVM verifier contract - -use bellman::groth16; -use pairing::{CurveAffine, Engine}; - -// fn unpack(t: &T) -> Vec -// { -// t.into_uncompressed().as_ref().chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect() -// } - -fn unpack_g1(point: &E::G1Affine) -> Vec { - let uncompressed = point.into_uncompressed(); - let uncompressed_slice = uncompressed.as_ref(); - - uncompressed_slice - .chunks(32) - .map(|c| "0x".to_owned() + &hex::encode(c)) - .collect() -} - -fn unpack_g2(point: &E::G2Affine) -> Vec { - let uncompressed = point.into_uncompressed(); - let uncompressed_slice = uncompressed.as_ref(); - uncompressed_slice - .chunks(32) - .map(|c| "0x".to_owned() + &hex::encode(c)) - .collect() - - // let to_reorder: Vec = uncompressed_slice.chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect(); - - // vec![to_reorder[1].clone(), to_reorder[0].clone(), to_reorder[3].clone(), to_reorder[2].clone()] -} - -const SHIFT: &str = " "; - -fn render_array(name: &str, allocate: bool, values: &[Vec]) -> String { - let mut out = String::new(); - out.push('\n'); - let flattened: Vec<&String> = values.iter().flatten().collect(); - if allocate { - out.push_str(&format!( - "{}{} = new uint256[]({});\n", - SHIFT, - name, - flattened.len() - )); - } - for (i, s) in flattened.iter().enumerate() { - out.push_str(&format!("{}{}[{}] = {};\n", SHIFT, name, i, s)); - } - out -} - -pub fn hardcode_vk(vk: &groth16::VerifyingKey) -> String { - let mut out = String::new(); - - let values = &[ - unpack_g1::(&vk.alpha_g1), - unpack_g2::(&vk.beta_g2), - unpack_g2::(&vk.gamma_g2), - unpack_g2::(&vk.delta_g2), - ]; - out.push_str(&render_array("vk", false, values)); - - let ic: Vec> = vk.ic.iter().map(unpack_g1::).collect(); - out.push_str(&render_array("gammaABC", true, ic.as_slice())); - - out -} - -pub fn generate_vk_contract( - vk: &groth16::VerifyingKey, - contract_name: String, - function_name: String, -) -> String { - format!( - r#" -// This contract is generated programmatically - -pragma solidity ^0.5.1; - - -// Hardcoded constants to avoid accessing store -contract {contract_name} {{ - - function {function_name}() external pure returns (uint256[14] memory vk, uint256[] memory gammaABC) {{ - - {vk} - - }} - -}} -"#, - vk = hardcode_vk(&vk), - contract_name = contract_name, - function_name = function_name, - ) -} diff --git a/core/franklin_prover/Cargo.toml b/core/franklin_prover/Cargo.toml deleted file mode 100644 index 0d1e8e906f..0000000000 --- a/core/franklin_prover/Cargo.toml +++ /dev/null @@ -1,39 +0,0 @@ -[package] -name = "franklin_prover" -version = "0.0.1" -edition = "2018" - -[dependencies] -plasma = { path = "../plasma" } -models = { package = "franklinmodels", path = "../franklinmodels" } -storage = { path = "../storage" } -circuit = { package = "franklincircuit", path = "../franklincircuit"} - -ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } -pairing = { package = "pairing_ce", version = "0.17.0" } -bellman = { package = "bellman_ce", version = "0.3.0" } -franklin_crypto = { package = "franklin-crypto", git = "ssh://git@github.com/matter-labs/franklin-crypto.git"} - -# ff = { path = "../ff" } -# pairing = { path = "../pairing" } -# bellman = { path = "../bellman" } -# sapling-crypto = { path = "../sapling-crypto" } - -rand = "0.4" -rust-crypto = "0.2" -rustc-hex = "2.0.1" - -signal-hook = "0.1.8" -tokio = "0.1.18" -futures = "0.1.28" - -fnv = "1.0.6" -serde = "1.0.90" -serde_derive = "1.0.90" -serde_json = "1.0.39" -diesel = { version = "1.4.2", features = ["postgres", "serde_json", "r2d2", "chrono"] } -bigdecimal = { version = "0.0.14", features = ["serde"]} -chrono = { version = "0.4", features = ["serde", "rustc-serialize"] } -log = "0.4" -env_logger = "0.6" -num-traits = "0.2" \ No newline at end of file diff --git a/core/franklin_prover/src/lib.rs b/core/franklin_prover/src/lib.rs deleted file mode 100644 index 72aefa6027..0000000000 --- a/core/franklin_prover/src/lib.rs +++ /dev/null @@ -1,584 +0,0 @@ -#[macro_use] -extern crate log; - -use rand::OsRng; -use std::fmt; -use std::iter::Iterator; -use std::sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, - Arc, -}; -use std::thread; -use std::time::Duration; - -use bellman::groth16::{ - create_random_proof, prepare_verifying_key, verify_proof, Parameters, Proof, -}; -use circuit::account::AccountWitness; -use circuit::circuit::FranklinCircuit; -use circuit::witness::close_account::*; -use circuit::witness::deposit::*; -use circuit::witness::noop::noop_operation; -use circuit::witness::partial_exit::*; -use circuit::witness::transfer::*; -use circuit::witness::transfer_to_new::*; -use circuit::witness::utils::*; -use ff::{Field, PrimeField}; -use franklin_crypto::alt_babyjubjub::AltJubjubBn256; -use franklin_crypto::jubjub::JubjubEngine; -use models::circuit::account::CircuitAccount; -use models::circuit::CircuitAccountTree; -use models::node::Account; -use models::node::*; -use models::params as franklin_constants; -use models::primitives::pack_bits_into_bytes_in_order; -use models::EncodedProof; -use plasma::state::PlasmaState; -use tokio::prelude::*; -use tokio::runtime::current_thread::Handle; -use tokio::sync::oneshot::Sender; -use tokio::timer; - -use num_traits::cast::ToPrimitive; -// use models::circuit::encoder; -// use models::config::{ -// DEPOSIT_BATCH_SIZE, EXIT_BATCH_SIZE, PROVER_CYCLE_WAIT, PROVER_TIMEOUT, PROVER_TIMER_TICK, -// RUNTIME_CONFIG, -// }; -use storage::StorageProcessor; - -use models::primitives::{serialize_g1_for_ethereum, serialize_g2_for_ethereum}; - -pub struct Prover { - pub operation_batch_size: usize, - pub current_block_number: BlockNumber, - pub accounts_tree: CircuitAccountTree, - pub parameters: BabyParameters, - pub jubjub_params: E::Params, - pub worker: String, - pub prover_id: i32, - pub current_job: Arc, -} - -pub type BabyProof = Proof; -pub type BabyParameters = Parameters; -pub type BabyProver = Prover; - -#[derive(Debug)] -pub enum BabyProverErr { - InvalidAmountEncoding, - InvalidFeeEncoding, - InvalidSender, - InvalidRecipient, - InvalidTransaction(String), - IoError(std::io::Error), - Other(String), -} - -impl BabyProverErr { - fn description(&self) -> String { - match *self { - BabyProverErr::InvalidAmountEncoding => { - "transfer amount is malformed or too large".to_owned() - } - BabyProverErr::InvalidFeeEncoding => { - "transfer fee is malformed or too large".to_owned() - } - BabyProverErr::InvalidSender => "sender account is unknown".to_owned(), - BabyProverErr::InvalidRecipient => "recipient account is unknown".to_owned(), - BabyProverErr::InvalidTransaction(ref reason) => format!("invalid tx data: {}", reason), - BabyProverErr::IoError(_) => "encountered an I/O error".to_owned(), - BabyProverErr::Other(ref reason) => format!("Prover error: {}", reason), - } - } -} - -impl fmt::Display for BabyProverErr { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - if let BabyProverErr::IoError(ref e) = *self { - write!(f, "I/O error: ")?; - e.fmt(f) - } else { - write!(f, "{}", self.description()) - } - } -} - -#[derive(Debug)] -pub struct FullBabyProof { - proof: BabyProof, - inputs: [Fr; 1], - public_data: Vec, -} - -fn read_parameters(file_name: &str) -> Result { - use std::fs::File; - use std::io::BufReader; - - let f_r = File::open(file_name); - if f_r.is_err() { - return Err(BabyProverErr::IoError(f_r.err().unwrap())); - } - let mut r = BufReader::new(f_r.unwrap()); - let circuit_params = BabyParameters::read(&mut r, true); - - if circuit_params.is_err() { - return Err(BabyProverErr::IoError(circuit_params.err().unwrap())); - } - - Ok(circuit_params.unwrap()) -} - -fn extend_accounts>( - tree: &mut CircuitAccountTree, - accounts: I, -) { - for e in accounts { - let acc_number = e.0; - let leaf_copy = CircuitAccount::from(e.1.clone()); - tree.insert(acc_number, leaf_copy); - } -} - -// IMPORTANT: prover does NOT care about some ordering of the transactions, so blocks supplied here MUST be ordered -// for the application layer - -impl BabyProver { - // Outputs - // - 8 uint256 for encoding of the field elements - // - one uint256 for new root hash - // - uint256 block number - // - uint256 total fees - // - Bytes public data - // - // Old root is available to take from the storage of the smart-contract - pub fn encode_proof(proof: &FullBabyProof) -> Result { - // proof - // pub a: E::G1Affine, - // pub b: E::G2Affine, - // pub c: E::G1Affine - - let (a_x, a_y) = serialize_g1_for_ethereum(proof.proof.a); - - let ((b_x_0, b_x_1), (b_y_0, b_y_1)) = serialize_g2_for_ethereum(proof.proof.b); - - let (c_x, c_y) = serialize_g1_for_ethereum(proof.proof.c); - - // let new_root = serialize_fe_for_ethereum(proof.inputs[1]); - - // let total_fees = serialize_fe_for_ethereum(proof.total_fees); - - // let block_number = serialize_fe_for_ethereum(proof.block_number); - - // let public_data = proof.public_data.clone(); - - let p = [a_x, a_y, b_x_0, b_x_1, b_y_0, b_y_1, c_x, c_y]; - - // EncodedProof{ - // groth_proof: [a_x, a_y, b_x_0, b_x_1, b_y_0, b_y_1, c_x, c_y], - // //block_number: block_number, - // }; - - Ok(p) - } - - pub fn create(worker: String) -> Result { - let storage = - StorageProcessor::establish_connection().expect("db connection failed for prover"); - let (last_block, accounts) = storage - .load_verified_state() - .expect("db must be functional"); - info!("Last block is: {}", last_block); - debug!("Accounts: {:?}", accounts); - let initial_state = PlasmaState::new(accounts, last_block); - - info!("Reading proving key, may take a while"); - - let path = { - let mut key_file_path = std::path::PathBuf::new(); - key_file_path.push(&std::env::var("KEY_DIR").expect("KEY_DIR not set")); - key_file_path.push(&format!("{}", franklin_constants::BLOCK_SIZE_CHUNKS)); - key_file_path.push(franklin_constants::KEY_FILENAME); - key_file_path - }; - debug!("Reading key from {}", path.to_str().unwrap()); - let franklin_circuit_params = read_parameters(&path.to_str().unwrap()); - if franklin_circuit_params.is_err() { - return Err(franklin_circuit_params.err().unwrap()); - } - - debug!("Done reading franklin key"); - - info!("Copying states to balance tree"); - - // TODO: replace with .clone() by moving PedersenHasher to static context - let mut tree = CircuitAccountTree::new(franklin_constants::ACCOUNT_TREE_DEPTH as u32); - extend_accounts(&mut tree, initial_state.get_accounts().into_iter()); - - let root = tree.root_hash(); - - let state_block_number = initial_state.block_number; - - info!( - "Initial root hash is {} for block {}", - root, state_block_number - ); - - let supplied_root = initial_state.root_hash(); - info!("supplied_root is: {}", supplied_root); - if root != supplied_root { - return Err(BabyProverErr::Other("root did not change".to_owned())); - } - - let jubjub_params = AltJubjubBn256::new(); - - let prover_id = storage - .register_prover(&worker) - .expect("getting prover id failed"); - - Ok(Self { - operation_batch_size: franklin_constants::BLOCK_SIZE_CHUNKS, - current_block_number: state_block_number, - accounts_tree: tree, - parameters: franklin_circuit_params.unwrap(), - jubjub_params, - current_job: Arc::new(AtomicUsize::new(0)), - worker, - prover_id, - }) - } -} - -type Err = BabyProverErr; - -impl BabyProver { - fn rewind_state( - &mut self, - storage: &StorageProcessor, - expected_current_block: BlockNumber, - ) -> Result<(), String> { - info!( - "rewinding the state from block #{} to #{}", - self.current_block_number, expected_current_block - ); - let (_, new_accounts) = storage - .load_committed_state(Some(expected_current_block)) - .map_err(|e| format!("load_state_diff failed: {}", e))?; - - let mut tree = CircuitAccountTree::new(franklin_constants::ACCOUNT_TREE_DEPTH as u32); - extend_accounts(&mut tree, new_accounts.into_iter()); - - self.accounts_tree = tree; - self.current_block_number = expected_current_block; - Ok(()) - } - - fn make_proving_attempt(&mut self) -> Result<(), String> { - let storage = StorageProcessor::establish_connection() - .map_err(|e| format!("establish_connection failed: {}", e))?; - let job = storage - .fetch_prover_job(&self.worker, config::PROVER_TIMEOUT) - .map_err(|e| format!("fetch_prover_job failed: {}", e))?; - - if let Some(job) = job { - let block_number = job.block_number as BlockNumber; - info!( - "prover {} got a new job for block {}", - &self.worker, block_number - ); - self.current_job.store(job.id as usize, Ordering::Relaxed); - - // load state delta self.current_block_number => block_number (can go both forwards and backwards) - let expected_current_block = block_number - 1; - if self.current_block_number != expected_current_block { - self.rewind_state(&storage, expected_current_block)?; - } - let initial_root = self.accounts_tree.root_hash(); - - for (index, item) in &self.accounts_tree.items { - info!("index: {}, item: {}", index, item.pub_key_hash); - } - let block = storage - .load_committed_block(block_number) - .ok_or("load_committed_block failed")?; - let ops = storage.get_block_operations(block.block_number).unwrap(); - - drop(storage); - let mut operations = vec![]; - let mut pub_data = vec![]; - let mut fees = vec![]; - for op in ops { - match op { - FranklinOp::Deposit(deposit) => { - let deposit_witness = apply_deposit_tx(&mut self.accounts_tree, &deposit); - - //assert!(tree.verify_proof(sender_leaf_number, sender_leaf.clone(), tree.merkle_path(sender_leaf_number))); - let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); - let deposit_operations = calculate_deposit_operations_from_witness( - &deposit_witness, - &sig_msg, - signature, - &sender_x, - &sender_y, - ); - operations.extend(deposit_operations); - fees.push((deposit.tx.fee, deposit.tx.token)); - pub_data.extend(deposit_witness.get_pubdata()); - } - FranklinOp::Transfer(transfer) => { - let transfer_witness = - apply_transfer_tx(&mut self.accounts_tree, &transfer); - let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); - let transfer_operations = calculate_transfer_operations_from_witness( - &transfer_witness, - &sig_msg, - signature, - &sender_x, - &sender_y, - ); - operations.extend(transfer_operations); - fees.push((transfer.tx.fee, transfer.tx.token)); - pub_data.extend(transfer_witness.get_pubdata()); - } - FranklinOp::TransferToNew(transfer_to_new) => { - let transfer_to_new_witness = - apply_transfer_to_new_tx(&mut self.accounts_tree, &transfer_to_new); - let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); - let transfer_to_new_operations = - calculate_transfer_to_new_operations_from_witness( - &transfer_to_new_witness, - &sig_msg, - signature, - &sender_x, - &sender_y, - ); - operations.extend(transfer_to_new_operations); - fees.push((transfer_to_new.tx.fee, transfer_to_new.tx.token)); - pub_data.extend(transfer_to_new_witness.get_pubdata()); - } - FranklinOp::PartialExit(partial_exit) => { - let partial_exit_witness = - apply_partial_exit_tx(&mut self.accounts_tree, &partial_exit); - let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); - let partial_exit_operations = - calculate_partial_exit_operations_from_witness( - &partial_exit_witness, - &sig_msg, - signature, - &sender_x, - &sender_y, - ); - operations.extend(partial_exit_operations); - fees.push((partial_exit.tx.fee, partial_exit.tx.token)); - pub_data.extend(partial_exit_witness.get_pubdata()); - } - FranklinOp::Close(close) => { - let close_account_witness = - apply_close_account_tx(&mut self.accounts_tree, &close); - let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); - let close_account_operations = - calculate_close_account_operations_from_witness( - &close_account_witness, - &sig_msg, - signature, - &sender_x, - &sender_y, - ); - operations.extend(close_account_operations); - pub_data.extend(close_account_witness.get_pubdata()); - } - } - } - if operations.len() < franklin_constants::BLOCK_SIZE_CHUNKS { - for _ in 0..franklin_constants::BLOCK_SIZE_CHUNKS - operations.len() { - let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); - operations.push(noop_operation( - &self.accounts_tree, - block.fee_account, - &sig_msg, - signature, - &sender_x, - &sender_y, - )); - pub_data.extend(vec![false; 64]); - } - } - assert_eq!(pub_data.len(), 64 * 10); - assert_eq!(operations.len(), 10); - - let validator_acc = self - .accounts_tree - .get(block.fee_account as u32) - .expect("fee_account is not empty"); - let mut validator_balances = vec![]; - for i in 0..1 << *franklin_constants::BALANCE_TREE_DEPTH { - // validator_balances.push(Some(validator_acc.subtree.get(i as u32).map(|s| s.clone()).unwrap_or(Balance::default()))); - let balance_value = match validator_acc.subtree.get(i as u32) { - None => Fr::zero(), - Some(bal) => bal.value.clone(), - }; - validator_balances.push(Some(balance_value)); - } - let mut root_after_fee: Fr = self.accounts_tree.root_hash(); - let mut validator_account_witness: AccountWitness = AccountWitness { - nonce: None, - pub_key_hash: None, - }; - for (fee, token) in fees { - info!("fee, token: {}, {}", fee, token); - let (root, acc_witness) = apply_fee( - &mut self.accounts_tree, - block.fee_account as u32, - token as u32, - fee.to_u128().unwrap(), - ); - root_after_fee = root; - validator_account_witness = acc_witness; - } - - info!("root after fees {}", root_after_fee); - info!("block new hash {}", block.new_root_hash); - assert_eq!(root_after_fee, block.new_root_hash); - let (validator_audit_path, _) = - get_audits(&mut self.accounts_tree, block.fee_account as u32, 0); - - info!("Data for public commitment. pub_data: {:x?}, initial_root: {}, final_root: {}, validator_address: {}, block_number: {}", - pack_bits_into_bytes_in_order(pub_data.clone()), initial_root.clone(), root_after_fee.clone(), Fr::from_str(&block.fee_account.to_string()).unwrap(), Fr::from_str(&(block_number + 1).to_string()).unwrap() - ); - let public_data_commitment = public_data_commitment::( - &pub_data, - Some(initial_root.clone()), - Some(root_after_fee.clone()), - Some(Fr::from_str(&block.fee_account.to_string()).unwrap()), - Some(Fr::from_str(&(block_number).to_string()).unwrap()), - ); - - let instance = FranklinCircuit { - params: &self.jubjub_params, - operation_batch_size: franklin_constants::BLOCK_SIZE_CHUNKS, - old_root: Some(initial_root), - new_root: Some(block.new_root_hash), - block_number: Fr::from_str(&(block_number).to_string()), - validator_address: Some(Fr::from_str(&block.fee_account.to_string()).unwrap()), - pub_data_commitment: Some(public_data_commitment.clone()), - operations: operations.clone(), - validator_balances: validator_balances.clone(), - validator_audit_path: validator_audit_path.clone(), - validator_account: validator_account_witness.clone(), - }; - - // { - // let inst = FranklinCircuit { - // params: &self.jubjub_params, - // operation_batch_size: franklin_constants::BLOCK_SIZE_CHUNKS, - // old_root: Some(initial_root), - // new_root: Some(block.new_root_hash), - // block_number: Fr::from_str(&(block_number + 1).to_string()), - // validator_address: Some(Fr::from_str(&block.fee_account.to_string()).unwrap()), - // pub_data_commitment: Some(public_data_commitment.clone()), - // operations: operations, - // validator_balances: validator_balances, - // validator_audit_path: validator_audit_path, - // validator_account: validator_account_witness, - // }; - // let mut cs = TestConstraintSystem::::new(); - // inst.synthesize(&mut cs).unwrap(); - - // warn!("unconstrained {}\n", cs.find_unconstrained()); - // warn!("inputs {}\n", cs.num_inputs()); - // warn!("num_constraints: {}\n", cs.num_constraints()); - // warn!("is satisfied: {}\n", cs.is_satisfied()); - // warn!("which is unsatisfied: {:?}\n", cs.which_is_unsatisfied()); - // } - - let mut rng = OsRng::new().unwrap(); - info!("Prover has started to work"); - // let tmp_cirtuit_params = generate_random_parameters(instance, &mut rng).unwrap(); - let proof = create_random_proof(instance, &self.parameters, &mut rng); - if proof.is_err() { - error!("proof can not be created: {}", proof.err().unwrap()); - return Err("proof can not be created".to_owned()); - // return Err(BabyProverErr::Other("proof.is_err()".to_owned())); - } - let p = proof.unwrap(); - - let pvk = prepare_verifying_key(&self.parameters.vk); - - info!( - "Made a proof for initial root = {}, final root = {}, public_data_commitment = {}", - initial_root, - root_after_fee, - public_data_commitment.to_hex() - ); - let success = verify_proof(&pvk, &p.clone(), &[public_data_commitment]); - if success.is_err() { - error!( - "Proof is verification failed with error {}", - success.err().unwrap() - ); - return Err("Proof verification has failed".to_owned()); - // return Err(BabyProverErr::Other( - // "Proof is verification failed".to_owned(), - // )); - } - if !success.unwrap() { - error!("Proof is invalid"); - return Err("Proof is invalid".to_owned()); - // return Err(BabyProverErr::Other("Proof is invalid".to_owned())); - } - - info!("Proof generation is complete"); - - let full_proof = FullBabyProof { - proof: p, - inputs: [public_data_commitment], - // public_data: pub_data, - public_data: vec![0 as u8; 10], - }; - - // Ok(full_proof) - - let encoded = Self::encode_proof(&full_proof).expect("proof encoding failed"); - let storage = StorageProcessor::establish_connection() - .map_err(|e| format!("establish_connection failed: {}", e))?; - storage - .store_proof(block_number, &encoded) - .map_err(|e| format!("store_proof failed: {}", e))?; - } else { - thread::sleep(Duration::from_secs(config::PROVER_CYCLE_WAIT)); - } - Ok(()) - } - - pub fn start_timer_interval(&self, rt: &Handle) { - let job_ref = self.current_job.clone(); - rt.spawn( - timer::Interval::new_interval(Duration::from_secs(config::PROVER_TIMER_TICK)) - .fold(job_ref, |job_ref, _| { - let job = job_ref.load(Ordering::Relaxed); - if job > 0 { - //debug!("prover is working on block {}", job); - if let Ok(storage) = StorageProcessor::establish_connection() { - let _ = storage.update_prover_job(job as i32); - } - } - Ok(job_ref) - }) - .map(|_| ()) - .map_err(|_| ()), - ) - .unwrap(); - } - - pub fn run(&mut self, shutdown_tx: Sender<()>, stop_signal: Arc) { - info!("prover is running"); - while !stop_signal.load(Ordering::SeqCst) { - if let Err(err) = self.make_proving_attempt() { - error!("Error: {}", err); - } - self.current_job.store(0, Ordering::Relaxed); - } - info!("prover stopped"); - shutdown_tx.send(()).unwrap(); - } -} diff --git a/core/franklin_prover/src/main.rs b/core/franklin_prover/src/main.rs deleted file mode 100644 index 9210eae062..0000000000 --- a/core/franklin_prover/src/main.rs +++ /dev/null @@ -1,57 +0,0 @@ -#[macro_use] -extern crate log; - -use franklin_prover::BabyProver; -use signal_hook::iterator::Signals; -use std::env; -use std::sync::{atomic::AtomicBool, Arc}; -use std::thread; -use storage::StorageProcessor; -use tokio::runtime::current_thread::Runtime; -use tokio::sync::oneshot; - -fn main() { - env_logger::init(); - - // handle ctrl+c - let stop_signal = Arc::new(AtomicBool::new(false)); - signal_hook::flag::register(signal_hook::SIGTERM, Arc::clone(&stop_signal)) - .expect("Error setting SIGTERM handler"); - signal_hook::flag::register(signal_hook::SIGINT, Arc::clone(&stop_signal)) - .expect("Error setting SIGINT handler"); - signal_hook::flag::register(signal_hook::SIGQUIT, Arc::clone(&stop_signal)) - .expect("Error setting SIGQUIT handler"); - - let worker = env::var("POD_NAME").unwrap_or_else(|_| "default".to_string()); - info!("creating prover, worker: {}", worker); - let mut prover = BabyProver::create(worker).unwrap(); - let prover_id = prover.prover_id; - - let mut rt = Runtime::new().unwrap(); - let (shutdown_tx, shutdown_rx) = oneshot::channel(); - prover.start_timer_interval(&rt.handle()); - - // Run tokio timeline in a new thread - thread::spawn(move || { - prover.run(shutdown_tx, stop_signal); - }); - - let signals = Signals::new(&[ - signal_hook::SIGTERM, - signal_hook::SIGINT, - signal_hook::SIGQUIT, - ]) - .expect("Signals::new() failed"); - thread::spawn(move || { - for _ in signals.forever() { - info!( - "Termination signal received. Prover will finish the job and shut down gracefully" - ); - let storage = - StorageProcessor::establish_connection().expect("db connection failed for prover"); - storage.record_prover_stop(prover_id).expect("db failed"); - } - }); - - rt.block_on(shutdown_rx).unwrap(); -} diff --git a/core/key_generator/Cargo.toml b/core/key_generator/Cargo.toml index daf8ab051d..b481453dbe 100644 --- a/core/key_generator/Cargo.toml +++ b/core/key_generator/Cargo.toml @@ -14,7 +14,8 @@ time = "0.1" pairing = { package = "pairing_ce", version = "0.17.0" } franklin_crypto = { package = "franklin-crypto", git = "ssh://git@github.com/matter-labs/franklin-crypto.git"} bellman = { package = "bellman_ce", version = "0.3.0" } -models = { package = "franklinmodels", path = "../franklinmodels" } +models = { path = "../models" } +circuit= { path = "../circuit" } hex = "0.3.2" rust-crypto = "0.2" ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } diff --git a/core/franklin_key_generator/FranklinVerificationKey.sol b/core/key_generator/FranklinVerificationKey.sol similarity index 100% rename from core/franklin_key_generator/FranklinVerificationKey.sol rename to core/key_generator/FranklinVerificationKey.sol diff --git a/core/key_generator/src/depositor_key.rs b/core/key_generator/src/depositor_key.rs deleted file mode 100644 index b7c4c59361..0000000000 --- a/core/key_generator/src/depositor_key.rs +++ /dev/null @@ -1,99 +0,0 @@ -//use bellman; -// -//use time::PreciseTime; -// -//use pairing::bn256::*; -//use rand::OsRng; -//use franklin_crypto::alt_babyjubjub::AltJubjubBn256; -// -//use bellman::groth16::generate_random_parameters; -// -//use crate::vk_contract_generator::generate_vk_contract; -// -//use circuit::deposit::circuit::{Deposit, DepositWitness}; -//use circuit::deposit::deposit_request::DepositRequest; -//use circuit::leaf::LeafWitness; -//use models::plasma::params as plasma_constants; -// -//const DEPOSIT_BATCH_SIZE: usize = 1; -//const FILENAME: &str = "deposit_pk.key"; -//const CONTRACT_FILENAME: &str = "DepositVerificationKey.sol"; -//const CONTRACT_NAME: &str = "DepositVerificationKey"; -//const CONTRACT_FUNCTION_NAME: &str = "getVkDepositCircuit"; -// -//pub fn make_depositor_key() { -// // let p_g = FixedGenerators::SpendingKeyGenerator; -// let params = &AltJubjubBn256::new(); -// // let rng = &mut XorShiftRng::from_seed([0x3dbe6258, 0x8d313d76, 0x3237db17, 0xe5bc0654]); -// let rng = &mut OsRng::new().unwrap(); -// -// let empty_request = DepositRequest { -// into: None, -// amount: None, -// public_key: None, -// }; -// -// let empty_leaf_witness = LeafWitness { -// balance: None, -// nonce: None, -// pub_x: None, -// pub_y: None, -// }; -// -// let empty_witness = DepositWitness { -// leaf: empty_leaf_witness.clone(), -// auth_path: vec![None; plasma_constants::BALANCE_TREE_DEPTH], -// leaf_is_empty: None, -// new_pub_x: None, -// new_pub_y: None, -// }; -// -// let instance_for_generation: Deposit<'_, Bn256> = Deposit { -// params, -// number_of_deposits: DEPOSIT_BATCH_SIZE, -// old_root: None, -// new_root: None, -// public_data_commitment: None, -// block_number: None, -// requests: vec![(empty_request, empty_witness); DEPOSIT_BATCH_SIZE], -// }; -// -// info!("generating setup..."); -// let start = PreciseTime::now(); -// let tmp_cirtuit_params = generate_random_parameters(instance_for_generation, rng).unwrap(); -// info!( -// "setup generated in {} s", -// start.to(PreciseTime::now()).num_milliseconds() as f64 / 1000.0 -// ); -// -// use std::fs::File; -// use std::io::{BufWriter, Write}; -// { -// let f = File::create(FILENAME).expect("Unable to create file"); -// let mut f = BufWriter::new(f); -// tmp_cirtuit_params -// .write(&mut f) -// .expect("Unable to write proving key"); -// } -// -// use std::io::BufReader; -// -// let f_r = File::open(FILENAME).expect("Unable to open file"); -// let mut r = BufReader::new(f_r); -// let circuit_params = bellman::groth16::Parameters::::read(&mut r, true) -// .expect("Unable to read proving key"); -// -// let contract_content = generate_vk_contract( -// &circuit_params.vk, -// CONTRACT_NAME.to_string(), -// CONTRACT_FUNCTION_NAME.to_string(), -// ); -// -// let f_cont = File::create(CONTRACT_FILENAME).expect("Unable to create file"); -// let mut f_cont = BufWriter::new(f_cont); -// f_cont -// .write_all(contract_content.as_bytes()) -// .expect("Unable to write contract"); -// -// info!("Done"); -//} diff --git a/core/key_generator/src/exitor_key.rs b/core/key_generator/src/exitor_key.rs deleted file mode 100644 index 975094a11e..0000000000 --- a/core/key_generator/src/exitor_key.rs +++ /dev/null @@ -1,96 +0,0 @@ -//use bellman; -// -//use time::PreciseTime; -// -//use pairing::bn256::*; -//use rand::OsRng; -//use franklin_crypto::alt_babyjubjub::AltJubjubBn256; -// -//use bellman::groth16::generate_random_parameters; -// -//use crate::vk_contract_generator::generate_vk_contract; -// -//use circuit::exit::circuit::{Exit, ExitWitness}; -//use circuit::exit::exit_request::ExitRequest; -//use circuit::leaf::LeafWitness; -//use models::plasma::params as plasma_constants; -// -//const EXIT_BATCH_SIZE: usize = 1; -//const FILENAME: &str = "exit_pk.key"; -//const CONTRACT_FILENAME: &str = "ExitVerificationKey.sol"; -//const CONTRACT_NAME: &str = "ExitVerificationKey"; -//const CONTRACT_FUNCTION_NAME: &str = "getVkExitCircuit"; -// -//pub fn make_exitor_key() { -// // let p_g = FixedGenerators::SpendingKeyGenerator; -// let params = &AltJubjubBn256::new(); -// // let rng = &mut XorShiftRng::from_seed([0x3dbe6258, 0x8d313d76, 0x3237db17, 0xe5bc0654]); -// let rng = &mut OsRng::new().unwrap(); -// -// let empty_request = ExitRequest { -// from: None, -// amount: None, -// }; -// -// let empty_leaf_witness = LeafWitness { -// balance: None, -// nonce: None, -// pub_x: None, -// pub_y: None, -// }; -// -// let empty_witness = ExitWitness { -// leaf: empty_leaf_witness.clone(), -// auth_path: vec![None; plasma_constants::BALANCE_TREE_DEPTH], -// }; -// -// let instance_for_generation: Exit<'_, Bn256> = Exit { -// params, -// number_of_exits: EXIT_BATCH_SIZE, -// old_root: None, -// new_root: None, -// public_data_commitment: None, -// empty_leaf_witness: empty_leaf_witness.clone(), -// block_number: None, -// requests: vec![(empty_request, empty_witness); EXIT_BATCH_SIZE], -// }; -// -// info!("generating setup..."); -// let start = PreciseTime::now(); -// let tmp_cirtuit_params = generate_random_parameters(instance_for_generation, rng).unwrap(); -// info!( -// "setup generated in {} s", -// start.to(PreciseTime::now()).num_milliseconds() as f64 / 1000.0 -// ); -// -// use std::fs::File; -// use std::io::{BufWriter, Write}; -// { -// let f = File::create(FILENAME).expect("Unable to create file"); -// let mut f = BufWriter::new(f); -// tmp_cirtuit_params -// .write(&mut f) -// .expect("Unable to write proving key"); -// } -// -// use std::io::BufReader; -// -// let f_r = File::open(FILENAME).expect("Unable to open file"); -// let mut r = BufReader::new(f_r); -// let circuit_params = bellman::groth16::Parameters::::read(&mut r, true) -// .expect("Unable to read proving key"); -// -// let contract_content = generate_vk_contract( -// &circuit_params.vk, -// CONTRACT_NAME.to_string(), -// CONTRACT_FUNCTION_NAME.to_string(), -// ); -// -// let f_cont = File::create(CONTRACT_FILENAME).expect("Unable to create file"); -// let mut f_cont = BufWriter::new(f_cont); -// f_cont -// .write_all(contract_content.as_bytes()) -// .expect("Unable to write contract"); -// -// info!("Done"); -//} diff --git a/core/franklin_key_generator/src/franklin_key.rs b/core/key_generator/src/franklin_key.rs similarity index 91% rename from core/franklin_key_generator/src/franklin_key.rs rename to core/key_generator/src/franklin_key.rs index 84fede4e9f..02c4b2861e 100644 --- a/core/franklin_key_generator/src/franklin_key.rs +++ b/core/key_generator/src/franklin_key.rs @@ -9,10 +9,10 @@ use rand::OsRng; use bellman::groth16::generate_random_parameters; use crate::vk_contract_generator::generate_vk_contract; -use franklincircuit::account::AccountWitness; -use franklincircuit::circuit::FranklinCircuit; -use franklincircuit::operation::*; -use franklinmodels::params as franklin_constants; +use circuit::account::AccountWitness; +use circuit::circuit::FranklinCircuit; +use circuit::operation::*; +use models::params as franklin_constants; use std::path::PathBuf; const CONTRACT_FILENAME: &str = "VerificationKey.sol"; @@ -78,7 +78,7 @@ pub fn make_franklin_key() { }, account_path: vec![None; franklin_constants::ACCOUNT_TREE_DEPTH], balance_value: None, - balance_subtree_path: vec![None; *franklin_constants::BALANCE_TREE_DEPTH], + balance_subtree_path: vec![None; franklin_constants::BALANCE_TREE_DEPTH], }, }, rhs: OperationBranch { @@ -91,7 +91,7 @@ pub fn make_franklin_key() { }, account_path: vec![None; franklin_constants::ACCOUNT_TREE_DEPTH], balance_value: None, - balance_subtree_path: vec![None; *franklin_constants::BALANCE_TREE_DEPTH], + balance_subtree_path: vec![None; franklin_constants::BALANCE_TREE_DEPTH], }, }, }; @@ -104,7 +104,7 @@ pub fn make_franklin_key() { validator_address: None, block_number: None, pub_data_commitment: None, - validator_balances: vec![None; (1 << *franklin_constants::BALANCE_TREE_DEPTH) as usize], + validator_balances: vec![None; (1 << franklin_constants::BALANCE_TREE_DEPTH) as usize], validator_audit_path: vec![None; franklin_constants::ACCOUNT_TREE_DEPTH], operations: vec![empty_operation; franklin_constants::BLOCK_SIZE_CHUNKS], validator_account: AccountWitness { diff --git a/core/key_generator/src/main.rs b/core/key_generator/src/main.rs index b8107eae6d..dc6899c7da 100644 --- a/core/key_generator/src/main.rs +++ b/core/key_generator/src/main.rs @@ -1,21 +1,13 @@ -//#[macro_use] -//extern crate log; -// -//pub mod depositor_key; -//pub mod exitor_key; -//pub mod read_write_keys; -//pub mod transactor_key; -//pub mod vk_contract_generator; -// -//use depositor_key::make_depositor_key; -//use exitor_key::make_exitor_key; -//use transactor_key::make_transactor_key; -// -//fn main() { -// env_logger::init(); -// -// make_depositor_key(); -// make_exitor_key(); -// make_transactor_key(); -//} -fn main() {} +#[macro_use] +extern crate log; + +pub mod franklin_key; +pub mod vk_contract_generator; + +use franklin_key::make_franklin_key; + +fn main() { + env_logger::init(); + + make_franklin_key(); +} diff --git a/core/key_generator/src/read_write_keys.rs b/core/key_generator/src/read_write_keys.rs deleted file mode 100644 index 1d157dd4b5..0000000000 --- a/core/key_generator/src/read_write_keys.rs +++ /dev/null @@ -1,483 +0,0 @@ -//use time::PreciseTime; -// -//use circuit::leaf::LeafWitness; -//use circuit::transfer::circuit::{TransactionWitness, Transfer}; -//use circuit::transfer::transaction::Transaction; -//use circuit::CircuitAccountTree; -//use crypto::digest::Digest; -//use crypto::sha2::Sha256; -//use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr}; -//use hex::encode; -//use pairing::bn256::*; -//use pairing::Engine; -//use rand::{Rng, SeedableRng, XorShiftRng}; -//use franklin_crypto::alt_babyjubjub::AltJubjubBn256; -//use franklin_crypto::circuit::test::*; -//use std::collections::HashMap; -// -//use crate::vk_contract_generator::hardcode_vk; -//use bellman::groth16::{ -// create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, -// VerifyingKey, -//}; -//use bellman::Circuit; -// -//use franklin_crypto::circuit::float_point::convert_to_float; -//use franklin_crypto::eddsa::{PrivateKey, PublicKey}; -//use franklin_crypto::jubjub::FixedGenerators; -// -//use models::plasma::circuit::account::CircuitAccount; -//use models::plasma::circuit::utils::{be_bit_vector_into_bytes, le_bit_vector_into_field_element}; -//use models::plasma::params as plasma_constants; -// -//const TXES_TO_TEST: usize = 128; -// -//#[allow(clippy::cognitive_complexity)] -//pub fn read_write_keys() { -// let p_g = FixedGenerators::SpendingKeyGenerator; -// let params = &AltJubjubBn256::new(); -// let rng = &mut XorShiftRng::from_seed([0x3dbe_6258, 0x8d31_3d76, 0x3237_db17, 0xe5bc_0654]); -// let tree_depth = plasma_constants::BALANCE_TREE_DEPTH as u32; -// -// let capacity: u32 = 1 << tree_depth; -// -// let mut existing_accounts: Vec<(u32, PrivateKey, PublicKey)> = vec![]; -// -// let mut tree = CircuitAccountTree::new(tree_depth); -// -// let number_of_accounts = 1000; -// -// let mut existing_account_hm = HashMap::::new(); -// -// let default_balance_string = "1000000"; -// let transfer_amount: u128 = 1000; -// let fee_amount: u128 = 0; -// -// for _ in 0..number_of_accounts { -// let mut leaf_number: u32 = rng.gen(); -// leaf_number %= capacity; -// if existing_account_hm.get(&leaf_number).is_some() { -// continue; -// } else { -// existing_account_hm.insert(leaf_number, true); -// } -// -// let sk = PrivateKey::(rng.gen()); -// let pk = PublicKey::from_private(&sk, p_g, params); -// let (x, y) = pk.0.into_xy(); -// -// existing_accounts.push((leaf_number, sk, pk)); -// -// let leaf = CircuitAccount { -// balance: Fr::from_str(default_balance_string).unwrap(), -// nonce: Fr::zero(), -// pub_x: x, -// pub_y: y, -// }; -// -// tree.insert(leaf_number, leaf.clone()); -// } -// -// let num_accounts = existing_accounts.len(); -// -// debug!("Inserted {} accounts", num_accounts); -// -// let initial_root = tree.root_hash(); -// -// let mut witnesses: Vec<(Transaction, TransactionWitness)> = vec![]; -// let mut public_data_vector: Vec = vec![]; -// -// let transfer_amount_as_field_element = Fr::from_str(&transfer_amount.to_string()).unwrap(); -// -// let transfer_amount_bits = convert_to_float( -// transfer_amount, -// plasma_constants::AMOUNT_EXPONENT_BIT_WIDTH, -// plasma_constants::AMOUNT_MANTISSA_BIT_WIDTH, -// 10, -// ) -// .unwrap(); -// -// let transfer_amount_encoded: Fr = le_bit_vector_into_field_element(&transfer_amount_bits); -// -// let fee_as_field_element = Fr::from_str(&fee_amount.to_string()).unwrap(); -// -// let fee_bits = convert_to_float( -// fee_amount, -// plasma_constants::FEE_EXPONENT_BIT_WIDTH, -// plasma_constants::FEE_MANTISSA_BIT_WIDTH, -// 10, -// ) -// .unwrap(); -// -// let fee_encoded: Fr = le_bit_vector_into_field_element(&fee_bits); -// -// let mut total_fees = Fr::zero(); -// -// for _ in 0..TXES_TO_TEST { -// let mut sender_account_number: usize = rng.gen(); -// sender_account_number %= num_accounts; -// let sender_account_info: &(u32, PrivateKey, PublicKey) = -// existing_accounts.get(sender_account_number).unwrap(); -// -// let mut recipient_account_number: usize = rng.gen(); -// recipient_account_number %= num_accounts; -// if recipient_account_number == sender_account_number { -// recipient_account_number += 1 % num_accounts; -// } -// let recipient_account_info: &(u32, PrivateKey, PublicKey) = -// existing_accounts.get(recipient_account_number).unwrap(); -// -// let sender_leaf_number = sender_account_info.0; -// let recipient_leaf_number = recipient_account_info.0; -// -// let items = tree.items.clone(); -// -// let sender_leaf = items.get(&sender_leaf_number).unwrap().clone(); -// let recipient_leaf = items.get(&recipient_leaf_number).unwrap().clone(); -// -// let path_from: Vec> = tree -// .merkle_path(sender_leaf_number) -// .into_iter() -// .map(|e| Some(e.0)) -// .collect(); -// let path_to: Vec> = tree -// .merkle_path(recipient_leaf_number) -// .into_iter() -// .map(|e| Some(e.0)) -// .collect(); -// -// // debug!("Making a transfer from {} to {}", sender_leaf_number, recipient_leaf_number); -// -// let from = Fr::from_str(&sender_leaf_number.to_string()); -// let to = Fr::from_str(&recipient_leaf_number.to_string()); -// -// let mut transaction: Transaction = Transaction { -// from, -// to, -// amount: Some(transfer_amount_encoded), -// fee: Some(fee_encoded), -// nonce: Some(sender_leaf.nonce), -// good_until_block: Some(Fr::one()), -// signature: None, -// }; -// -// let sender_sk = &sender_account_info.1; -// -// transaction.sign(&sender_sk, p_g, params, rng); -// -// assert!(transaction.signature.is_some()); -// -// //assert!(tree.verify_proof(sender_leaf_number, sender_leaf.clone(), tree.merkle_path(sender_leaf_number))); -// //assert!(tree.verify_proof(recipient_leaf_number, recipient_leaf.clone(), tree.merkle_path(recipient_leaf_number))); -// -// // debug!("Sender: balance: {}, nonce: {}, pub_x: {}, pub_y: {}", sender_leaf.balance, sender_leaf.nonce, sender_leaf.pub_x, sender_leaf.pub_y); -// // debug!("Recipient: balance: {}, nonce: {}, pub_x: {}, pub_y: {}", recipient_leaf.balance, recipient_leaf.nonce, recipient_leaf.pub_x, recipient_leaf.pub_y); -// -// let mut updated_sender_leaf = sender_leaf.clone(); -// let mut updated_recipient_leaf = recipient_leaf.clone(); -// -// updated_sender_leaf -// .balance -// .sub_assign(&transfer_amount_as_field_element); -// updated_sender_leaf -// .balance -// .sub_assign(&fee_as_field_element); -// -// updated_sender_leaf.nonce.add_assign(&Fr::one()); -// -// updated_recipient_leaf -// .balance -// .add_assign(&transfer_amount_as_field_element); -// -// total_fees.add_assign(&fee_as_field_element); -// -// // debug!("Updated sender: balance: {}, nonce: {}, pub_x: {}, pub_y: {}", updated_sender_leaf.balance, updated_sender_leaf.nonce, updated_sender_leaf.pub_x, updated_sender_leaf.pub_y); -// // debug!("Updated recipient: balance: {}, nonce: {}, pub_x: {}, pub_y: {}", updated_recipient_leaf.balance, updated_recipient_leaf.nonce, updated_recipient_leaf.pub_x, updated_recipient_leaf.pub_y); -// -// tree.insert(sender_leaf_number, updated_sender_leaf.clone()); -// tree.insert(recipient_leaf_number, updated_recipient_leaf.clone()); -// -// //assert!(tree.verify_proof(sender_leaf_number, updated_sender_leaf.clone(), tree.merkle_path(sender_leaf_number))); -// //assert!(tree.verify_proof(recipient_leaf_number, updated_recipient_leaf.clone(), tree.merkle_path(recipient_leaf_number))); -// -// let public_data = transaction.public_data_into_bits(); -// public_data_vector.extend(public_data.into_iter()); -// -// let leaf_witness_from = LeafWitness { -// balance: Some(sender_leaf.balance), -// nonce: Some(sender_leaf.nonce), -// pub_x: Some(sender_leaf.pub_x), -// pub_y: Some(sender_leaf.pub_y), -// }; -// -// let leaf_witness_to = LeafWitness { -// balance: Some(recipient_leaf.balance), -// nonce: Some(recipient_leaf.nonce), -// pub_x: Some(recipient_leaf.pub_x), -// pub_y: Some(recipient_leaf.pub_y), -// }; -// -// let transaction_witness = TransactionWitness { -// leaf_from: leaf_witness_from, -// auth_path_from: path_from, -// leaf_to: leaf_witness_to, -// auth_path_to: path_to, -// }; -// -// let witness = (transaction.clone(), transaction_witness); -// -// witnesses.push(witness); -// } -// -// let block_number = Fr::one(); -// -// debug!("Block number = {}", block_number.into_repr()); -// -// let final_root = tree.root_hash(); -// -// let final_root_string = format!( -// "{}", -// CircuitAccountTree::new(tree_depth).root_hash().into_repr() -// ); -// -// debug!("Final root = {}", final_root_string); -// -// let mut public_data_initial_bits = vec![]; -// -// // these two are BE encodings because an iterator is BE. This is also an Ethereum standard behavior -// -// let block_number_bits: Vec = BitIterator::new(block_number.into_repr()).collect(); -// for _ in 0..256 - block_number_bits.len() { -// public_data_initial_bits.push(false); -// } -// public_data_initial_bits.extend(block_number_bits.into_iter()); -// -// let total_fee_bits: Vec = BitIterator::new(total_fees.into_repr()).collect(); -// for _ in 0..256 - total_fee_bits.len() { -// public_data_initial_bits.push(false); -// } -// public_data_initial_bits.extend(total_fee_bits.into_iter()); -// -// assert_eq!(public_data_initial_bits.len(), 512); -// -// let mut h = Sha256::new(); -// -// let bytes_to_hash = be_bit_vector_into_bytes(&public_data_initial_bits); -// -// h.input(&bytes_to_hash); -// -// let mut hash_result = [0u8; 32]; -// h.result(&mut hash_result[..]); -// -// { -// let packed_transaction_data_bytes = be_bit_vector_into_bytes(&public_data_vector); -// -// let mut next_round_hash_bytes = vec![]; -// next_round_hash_bytes.extend(hash_result.iter()); -// next_round_hash_bytes.extend(packed_transaction_data_bytes.clone()); -// -// debug!("Public data = {}", encode(packed_transaction_data_bytes)); -// -// let mut h = Sha256::new(); -// -// h.input(&next_round_hash_bytes); -// -// // let mut hash_result = [0u8; 32]; -// h.result(&mut hash_result[..]); -// } -// -// // clip to fit into field element -// -// hash_result[0] &= 0x1f; // temporary solution -// -// let mut repr = Fr::zero().into_repr(); -// repr.read_be(&hash_result[..]) -// .expect("pack hash as field element"); -// -// let public_data_commitment = Fr::from_repr(repr).unwrap(); -// -// debug!("Total fees = {}", total_fees.into_repr()); -// -// debug!( -// "Final data commitment as field element = {}", -// public_data_commitment -// ); -// -// let instance_for_test_cs = Transfer { -// params, -// number_of_transactions: TXES_TO_TEST, -// old_root: Some(initial_root), -// new_root: Some(final_root), -// public_data_commitment: Some(public_data_commitment), -// block_number: Some(Fr::one()), -// total_fee: Some(total_fees), -// transactions: witnesses.clone(), -// }; -// -// { -// let mut cs = TestConstraintSystem::new(); -// -// instance_for_test_cs.synthesize(&mut cs).unwrap(); -// -// debug!("Total of {} constraints", cs.num_constraints()); -// debug!( -// "{} constraints per TX for {} transactions", -// cs.num_constraints() / TXES_TO_TEST, -// TXES_TO_TEST -// ); -// -// assert_eq!(cs.num_inputs(), 4); -// -// assert_eq!(cs.get_input(0, "ONE"), Fr::one()); -// assert_eq!( -// cs.get_input(1, "old root input/input variable"), -// initial_root -// ); -// assert_eq!(cs.get_input(2, "new root input/input variable"), final_root); -// assert_eq!( -// cs.get_input(3, "rolling hash input/input variable"), -// public_data_commitment -// ); -// -// let err = cs.which_is_unsatisfied(); -// if err.is_some() { -// panic!("ERROR satisfying in {}\n", err.unwrap()); -// } else { -// debug!("Test constraint system is satisfied"); -// } -// } -// -// let empty_transaction = Transaction { -// from: None, -// to: None, -// amount: None, -// fee: None, -// nonce: None, -// good_until_block: None, -// signature: None, -// }; -// -// let empty_leaf_witness = LeafWitness { -// balance: None, -// nonce: None, -// pub_x: None, -// pub_y: None, -// }; -// -// let empty_witness = TransactionWitness { -// leaf_from: empty_leaf_witness.clone(), -// auth_path_from: vec![None; plasma_constants::BALANCE_TREE_DEPTH], -// leaf_to: empty_leaf_witness, -// auth_path_to: vec![None; plasma_constants::BALANCE_TREE_DEPTH], -// }; -// -// let instance_for_generation: Transfer<'_, Bn256> = Transfer { -// params, -// number_of_transactions: TXES_TO_TEST, -// old_root: None, -// new_root: None, -// public_data_commitment: None, -// block_number: None, -// total_fee: None, -// transactions: vec![(empty_transaction, empty_witness); TXES_TO_TEST], -// }; -// -// debug!("generating setup..."); -// let start = PreciseTime::now(); -// let tmp_cirtuit_params = generate_random_parameters(instance_for_generation, rng).unwrap(); -// debug!( -// "setup generated in {} s", -// start.to(PreciseTime::now()).num_milliseconds() as f64 / 1000.0 -// ); -// -// use std::fs::File; -// use std::io::{BufWriter, Write}; -// { -// let f = File::create("pk.key").expect("Unable to create file"); -// let mut f = BufWriter::new(f); -// tmp_cirtuit_params -// .write(&mut f) -// .expect("Unable to write proving key"); -// } -// -// use std::io::BufReader; -// -// let f_r = File::open("pk.key").expect("Unable to open file"); -// let mut r = BufReader::new(f_r); -// let circuit_params = -// bellman::groth16::Parameters::read(&mut r, true).expect("Unable to read proving key"); -// -// let initial_root_string = format!( -// "{}", -// CircuitAccountTree::new(tree_depth).root_hash().into_repr() -// ); -// let contract_content = -// generate_vk_contract(&circuit_params.vk, initial_root_string.as_ref(), tree_depth); -// -// let f_cont = File::create("VerificationKeys.sol").expect("Unable to create file"); -// let mut f_cont = BufWriter::new(f_cont); -// f_cont -// .write_all(contract_content.as_bytes()) -// .expect("Unable to write contract"); -// -// let pvk = prepare_verifying_key(&circuit_params.vk); -// -// let instance_for_proof = Transfer { -// params, -// number_of_transactions: TXES_TO_TEST, -// old_root: Some(initial_root), -// new_root: Some(final_root), -// public_data_commitment: Some(public_data_commitment), -// block_number: Some(Fr::one()), -// total_fee: Some(total_fees), -// transactions: witnesses, -// }; -// -// debug!("creating proof..."); -// let start = PreciseTime::now(); -// let proof = create_random_proof(instance_for_proof, &circuit_params, rng).unwrap(); -// debug!( -// "proof created in {} s", -// start.to(PreciseTime::now()).num_milliseconds() as f64 / 1000.0 -// ); -// -// let success = verify_proof( -// &pvk, -// &proof, -// &[initial_root, final_root, public_data_commitment], -// ) -// .unwrap(); -// assert!(success); -//} -// -//fn generate_vk_contract( -// vk: &VerifyingKey, -// initial_root: &str, -// tree_depth: u32, -//) -> String { -// format!( -// r#" -//// This contract is generated programmatically -// -//pragma solidity ^0.4.24; -// -// -//// Hardcoded constants to avoid accessing store -//contract VerificationKeys {{ -// -// // For tree depth {tree_depth} -// bytes32 constant EMPTY_TREE_ROOT = {initial_root}; -// -// function getVkUpdateCircuit() internal pure returns (uint256[14] memory vk, uint256[] memory gammaABC) {{ -// -// {vk} -// -// }} -// -//}} -//"#, -// vk = hardcode_vk(&vk), -// initial_root = initial_root, -// tree_depth = tree_depth, -// ) -//} diff --git a/core/key_generator/src/transactor_key.rs b/core/key_generator/src/transactor_key.rs deleted file mode 100644 index 87ae9f1955..0000000000 --- a/core/key_generator/src/transactor_key.rs +++ /dev/null @@ -1,103 +0,0 @@ -//use bellman; -// -//use time::PreciseTime; -// -//use pairing::bn256::*; -//use rand::OsRng; -//use franklin_crypto::alt_babyjubjub::AltJubjubBn256; -// -//use bellman::groth16::generate_random_parameters; -// -//use crate::vk_contract_generator::generate_vk_contract; -// -//use circuit::leaf::LeafWitness; -//use circuit::transfer::circuit::{TransactionWitness, Transfer}; -//use circuit::transfer::transaction::Transaction; -//use models::plasma::params as plasma_constants; -// -//const TX_BATCH_SIZE: usize = 50; -//const FILENAME: &str = "transfer_pk.key"; -//const CONTRACT_FILENAME: &str = "TransferVerificationKey.sol"; -//const CONTRACT_NAME: &str = "TransferVerificationKey"; -//const CONTRACT_FUNCTION_NAME: &str = "getVkTransferCircuit"; -// -//pub fn make_transactor_key() { -// // let p_g = FixedGenerators::SpendingKeyGenerator; -// let params = &AltJubjubBn256::new(); -// // let rng = &mut XorShiftRng::from_seed([0x3dbe6258, 0x8d313d76, 0x3237db17, 0xe5bc0654]); -// let rng = &mut OsRng::new().unwrap(); -// -// let empty_transaction = Transaction { -// from: None, -// to: None, -// amount: None, -// fee: None, -// nonce: None, -// good_until_block: None, -// signature: None, -// }; -// -// let empty_leaf_witness = LeafWitness { -// balance: None, -// nonce: None, -// pub_x: None, -// pub_y: None, -// }; -// -// let empty_witness = TransactionWitness { -// leaf_from: empty_leaf_witness.clone(), -// auth_path_from: vec![None; plasma_constants::BALANCE_TREE_DEPTH], -// leaf_to: empty_leaf_witness, -// auth_path_to: vec![None; plasma_constants::BALANCE_TREE_DEPTH], -// }; -// -// let instance_for_generation: Transfer<'_, Bn256> = Transfer { -// params, -// number_of_transactions: TX_BATCH_SIZE, -// old_root: None, -// new_root: None, -// public_data_commitment: None, -// block_number: None, -// total_fee: None, -// transactions: vec![(empty_transaction, empty_witness); TX_BATCH_SIZE], -// }; -// -// info!("generating setup..."); -// let start = PreciseTime::now(); -// let tmp_cirtuit_params = generate_random_parameters(instance_for_generation, rng).unwrap(); -// info!( -// "setup generated in {} s", -// start.to(PreciseTime::now()).num_milliseconds() as f64 / 1000.0 -// ); -// -// use std::fs::File; -// use std::io::{BufWriter, Write}; -// { -// let f = File::create(FILENAME).expect("Unable to create file"); -// let mut f = BufWriter::new(f); -// tmp_cirtuit_params -// .write(&mut f) -// .expect("Unable to write proving key"); -// } -// -// use std::io::BufReader; -// -// let f_r = File::open(FILENAME).expect("Unable to open file"); -// let mut r = BufReader::new(f_r); -// let circuit_params = bellman::groth16::Parameters::::read(&mut r, true) -// .expect("Unable to read proving key"); -// -// let contract_content = generate_vk_contract( -// &circuit_params.vk, -// CONTRACT_NAME.to_string(), -// CONTRACT_FUNCTION_NAME.to_string(), -// ); -// -// let f_cont = File::create(CONTRACT_FILENAME).expect("Unable to create file"); -// let mut f_cont = BufWriter::new(f_cont); -// f_cont -// .write_all(contract_content.as_bytes()) -// .expect("Unable to write contract"); -// -// info!("Done"); -//} diff --git a/core/key_generator/src/vk_contract_generator.rs b/core/key_generator/src/vk_contract_generator.rs index b9e88e78d3..93920b0a2c 100644 --- a/core/key_generator/src/vk_contract_generator.rs +++ b/core/key_generator/src/vk_contract_generator.rs @@ -1,98 +1,98 @@ -//// Library to generate a EVM verifier contract -// -//use bellman::groth16; -//use pairing::{CurveAffine, Engine}; -// -//// fn unpack(t: &T) -> Vec -//// { -//// t.into_uncompressed().as_ref().chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect() -//// } -// -//fn unpack_g1(point: &E::G1Affine) -> Vec { -// let uncompressed = point.into_uncompressed(); -// let uncompressed_slice = uncompressed.as_ref(); -// -// uncompressed_slice -// .chunks(32) -// .map(|c| "0x".to_owned() + &hex::encode(c)) -// .collect() -//} -// -//fn unpack_g2(point: &E::G2Affine) -> Vec { -// let uncompressed = point.into_uncompressed(); -// let uncompressed_slice = uncompressed.as_ref(); -// uncompressed_slice -// .chunks(32) -// .map(|c| "0x".to_owned() + &hex::encode(c)) -// .collect() -// -// // let to_reorder: Vec = uncompressed_slice.chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect(); -// -// // vec![to_reorder[1].clone(), to_reorder[0].clone(), to_reorder[3].clone(), to_reorder[2].clone()] -//} -// -//const SHIFT: &str = " "; -// -//fn render_array(name: &str, allocate: bool, values: &[Vec]) -> String { -// let mut out = String::new(); -// out.push('\n'); -// let flattened: Vec<&String> = values.iter().flatten().collect(); -// if allocate { -// out.push_str(&format!( -// "{}{} = new uint256[]({});\n", -// SHIFT, -// name, -// flattened.len() -// )); -// } -// for (i, s) in flattened.iter().enumerate() { -// out.push_str(&format!("{}{}[{}] = {};\n", SHIFT, name, i, s)); -// } -// out -//} -// -//pub fn hardcode_vk(vk: &groth16::VerifyingKey) -> String { -// let mut out = String::new(); -// -// let values = &[ -// unpack_g1::(&vk.alpha_g1), -// unpack_g2::(&vk.beta_g2), -// unpack_g2::(&vk.gamma_g2), -// unpack_g2::(&vk.delta_g2), -// ]; -// out.push_str(&render_array("vk", false, values)); -// -// let ic: Vec> = vk.ic.iter().map(unpack_g1::).collect(); -// out.push_str(&render_array("gammaABC", true, ic.as_slice())); -// -// out -//} -// -//pub fn generate_vk_contract( -// vk: &groth16::VerifyingKey, -// contract_name: String, -// function_name: String, -//) -> String { -// format!( -// r#" -//// This contract is generated programmatically -// -//pragma solidity ^0.4.24; -// -// -//// Hardcoded constants to avoid accessing store -//contract {contract_name} {{ -// -// function {function_name}() internal pure returns (uint256[14] memory vk, uint256[] memory gammaABC) {{ -// -// {vk} -// -// }} -// -//}} -//"#, -// vk = hardcode_vk(&vk), -// contract_name = contract_name, -// function_name = function_name, -// ) -//} +// Library to generate a EVM verifier contract + +use bellman::groth16; +use pairing::{CurveAffine, Engine}; + +// fn unpack(t: &T) -> Vec +// { +// t.into_uncompressed().as_ref().chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect() +// } + +fn unpack_g1(point: &E::G1Affine) -> Vec { + let uncompressed = point.into_uncompressed(); + let uncompressed_slice = uncompressed.as_ref(); + + uncompressed_slice + .chunks(32) + .map(|c| "0x".to_owned() + &hex::encode(c)) + .collect() +} + +fn unpack_g2(point: &E::G2Affine) -> Vec { + let uncompressed = point.into_uncompressed(); + let uncompressed_slice = uncompressed.as_ref(); + uncompressed_slice + .chunks(32) + .map(|c| "0x".to_owned() + &hex::encode(c)) + .collect() + + // let to_reorder: Vec = uncompressed_slice.chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect(); + + // vec![to_reorder[1].clone(), to_reorder[0].clone(), to_reorder[3].clone(), to_reorder[2].clone()] +} + +const SHIFT: &str = " "; + +fn render_array(name: &str, allocate: bool, values: &[Vec]) -> String { + let mut out = String::new(); + out.push('\n'); + let flattened: Vec<&String> = values.iter().flatten().collect(); + if allocate { + out.push_str(&format!( + "{}{} = new uint256[]({});\n", + SHIFT, + name, + flattened.len() + )); + } + for (i, s) in flattened.iter().enumerate() { + out.push_str(&format!("{}{}[{}] = {};\n", SHIFT, name, i, s)); + } + out +} + +pub fn hardcode_vk(vk: &groth16::VerifyingKey) -> String { + let mut out = String::new(); + + let values = &[ + unpack_g1::(&vk.alpha_g1), + unpack_g2::(&vk.beta_g2), + unpack_g2::(&vk.gamma_g2), + unpack_g2::(&vk.delta_g2), + ]; + out.push_str(&render_array("vk", false, values)); + + let ic: Vec> = vk.ic.iter().map(unpack_g1::).collect(); + out.push_str(&render_array("gammaABC", true, ic.as_slice())); + + out +} + +pub fn generate_vk_contract( + vk: &groth16::VerifyingKey, + contract_name: String, + function_name: String, +) -> String { + format!( + r#" +// This contract is generated programmatically + +pragma solidity ^0.5.1; + + +// Hardcoded constants to avoid accessing store +contract {contract_name} {{ + + function {function_name}() external pure returns (uint256[14] memory vk, uint256[] memory gammaABC) {{ + + {vk} + + }} + +}} +"#, + vk = hardcode_vk(&vk), + contract_name = contract_name, + function_name = function_name, + ) +} diff --git a/core/franklinmodels/Cargo.toml b/core/models/Cargo.toml similarity index 96% rename from core/franklinmodels/Cargo.toml rename to core/models/Cargo.toml index 17d888547a..afee8537fe 100644 --- a/core/franklinmodels/Cargo.toml +++ b/core/models/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "franklinmodels" +name = "models" version = "0.0.1" edition = "2018" diff --git a/core/franklinmodels/src/abi.rs b/core/models/src/abi.rs similarity index 100% rename from core/franklinmodels/src/abi.rs rename to core/models/src/abi.rs diff --git a/core/franklinmodels/src/circuit/account.rs b/core/models/src/circuit/account.rs similarity index 93% rename from core/franklinmodels/src/circuit/account.rs rename to core/models/src/circuit/account.rs index 852e43c6f3..16148824b9 100644 --- a/core/franklinmodels/src/circuit/account.rs +++ b/core/models/src/circuit/account.rs @@ -39,7 +39,7 @@ impl GetBits for CircuitAccount { impl CircuitAccount{ //we temporary pass it as repr. TODO: return Fr, when we could provide proper trait bound pub fn empty_balances_root_hash() -> Vec{ - let balances_smt = CircuitBalanceTree::new(*params::BALANCE_TREE_DEPTH as u32); + let balances_smt = CircuitBalanceTree::new(params::BALANCE_TREE_DEPTH as u32); let mut tmp = [0u8; 32]; balances_smt.root_hash().into_repr().write_be(&mut tmp[..]).unwrap(); tmp.to_vec() @@ -55,7 +55,7 @@ impl std::default::Default for CircuitAccount { pub_key_hash: Fr::zero(), // pub_x: Fr::zero(), // pub_y: Fr::zero(), - subtree: SparseMerkleTree::new(*params::BALANCE_TREE_DEPTH as u32), + subtree: SparseMerkleTree::new(params::BALANCE_TREE_DEPTH as u32), } } } diff --git a/core/franklinmodels/src/circuit/mod.rs b/core/models/src/circuit/mod.rs similarity index 100% rename from core/franklinmodels/src/circuit/mod.rs rename to core/models/src/circuit/mod.rs diff --git a/core/franklinmodels/src/lib.rs b/core/models/src/lib.rs similarity index 100% rename from core/franklinmodels/src/lib.rs rename to core/models/src/lib.rs diff --git a/core/franklinmodels/src/merkle_tree/account_tree.rs b/core/models/src/merkle_tree/account_tree.rs similarity index 100% rename from core/franklinmodels/src/merkle_tree/account_tree.rs rename to core/models/src/merkle_tree/account_tree.rs diff --git a/core/franklinmodels/src/merkle_tree/hasher.rs b/core/models/src/merkle_tree/hasher.rs similarity index 100% rename from core/franklinmodels/src/merkle_tree/hasher.rs rename to core/models/src/merkle_tree/hasher.rs diff --git a/core/franklinmodels/src/merkle_tree/mod.rs b/core/models/src/merkle_tree/mod.rs similarity index 100% rename from core/franklinmodels/src/merkle_tree/mod.rs rename to core/models/src/merkle_tree/mod.rs diff --git a/core/franklinmodels/src/merkle_tree/parallel_smt.rs b/core/models/src/merkle_tree/parallel_smt.rs similarity index 100% rename from core/franklinmodels/src/merkle_tree/parallel_smt.rs rename to core/models/src/merkle_tree/parallel_smt.rs diff --git a/core/franklinmodels/src/merkle_tree/pedersen_hasher.rs b/core/models/src/merkle_tree/pedersen_hasher.rs similarity index 100% rename from core/franklinmodels/src/merkle_tree/pedersen_hasher.rs rename to core/models/src/merkle_tree/pedersen_hasher.rs diff --git a/core/franklinmodels/src/merkle_tree/sequential_smt.rs b/core/models/src/merkle_tree/sequential_smt.rs similarity index 100% rename from core/franklinmodels/src/merkle_tree/sequential_smt.rs rename to core/models/src/merkle_tree/sequential_smt.rs diff --git a/core/franklinmodels/src/node/account.rs b/core/models/src/node/account.rs similarity index 99% rename from core/franklinmodels/src/node/account.rs rename to core/models/src/node/account.rs index 8c7d6ee089..e703d22341 100644 --- a/core/franklinmodels/src/node/account.rs +++ b/core/models/src/node/account.rs @@ -111,7 +111,7 @@ impl From for CircuitAccount { .collect(); for (i, b) in balances.into_iter() { - circuit_account.subtree.insert(i as u32, b); + circuit_account.subtree.insert(u32::from(i), b); } circuit_account.nonce = Fr::from_str(&acc.nonce.to_string()).unwrap(); diff --git a/core/franklinmodels/src/node/block.rs b/core/models/src/node/block.rs similarity index 100% rename from core/franklinmodels/src/node/block.rs rename to core/models/src/node/block.rs diff --git a/core/franklinmodels/src/node/config.rs b/core/models/src/node/config.rs similarity index 99% rename from core/franklinmodels/src/node/config.rs rename to core/models/src/node/config.rs index 15ca73c5de..dc29763ddf 100644 --- a/core/franklinmodels/src/node/config.rs +++ b/core/models/src/node/config.rs @@ -28,7 +28,6 @@ impl RuntimeConfig { pub fn new() -> Self { let tx_batch_size_env = env::var("TX_BATCH_SIZE").expect("TX_BATCH_SIZE env missing"); let tx_size = usize::from_str_radix(&(tx_batch_size_env), 10) - .ok() .expect("TX_BATCH_SIZE invalid"); Self { diff --git a/core/franklinmodels/src/node/mod.rs b/core/models/src/node/mod.rs similarity index 100% rename from core/franklinmodels/src/node/mod.rs rename to core/models/src/node/mod.rs diff --git a/core/franklinmodels/src/node/operations.rs b/core/models/src/node/operations.rs similarity index 100% rename from core/franklinmodels/src/node/operations.rs rename to core/models/src/node/operations.rs diff --git a/core/franklinmodels/src/node/tx.rs b/core/models/src/node/tx.rs similarity index 100% rename from core/franklinmodels/src/node/tx.rs rename to core/models/src/node/tx.rs diff --git a/core/franklinmodels/src/params.rs b/core/models/src/params.rs similarity index 57% rename from core/franklinmodels/src/params.rs rename to core/models/src/params.rs index fb0e79e3ce..dd8e2ad2bf 100644 --- a/core/franklinmodels/src/params.rs +++ b/core/models/src/params.rs @@ -1,18 +1,18 @@ use crate::node::TokenId; /// Account tree depth -pub const TX_TYPE_BIT_WIDTH: &'static usize = &8; +pub const TX_TYPE_BIT_WIDTH: usize = 8; /// Account tree depth pub const ACCOUNT_TREE_DEPTH: usize = 24; //pub const ACCOUNT_TREE_DEPTH: usize = 4; /// Balance tree depth -pub const BALANCE_TREE_DEPTH: &'static usize = &10; +pub const BALANCE_TREE_DEPTH: usize = 10; //pub const BALANCE_TREE_DEPTH: &'static usize = &4; /// Account subtree hash width -pub const SUBTREE_HASH_WIDTH: &'static usize = &254; //seems to be equal to Bn256::NUM_BITS could be replaced +pub const SUBTREE_HASH_WIDTH: usize = 254; //seems to be equal to Bn256::NUM_BITS could be replaced /// balance bit width pub const BALANCE_BIT_WIDTH: usize = 128; @@ -21,33 +21,33 @@ pub const NEW_PUBKEY_HASH_WIDTH: usize = FR_ADDRESS_LEN * 8; /// Nonce bit width pub const NONCE_BIT_WIDTH: usize = 32; // -pub const TOKEN_EXT_BIT_WIDTH: &'static usize = &16; +pub const TOKEN_EXT_BIT_WIDTH: usize = 16; // pub const CHUNK_BIT_WIDTH: usize = 64; pub const ETHEREUM_KEY_BIT_WIDTH: usize = 160; /// Block number bit width -pub const BLOCK_NUMBER_BIT_WIDTH: &'static usize = &32; +pub const BLOCK_NUMBER_BIT_WIDTH: usize = 32; /// Amount bit widths -pub const AMOUNT_EXPONENT_BIT_WIDTH: &'static usize = &5; -pub const AMOUNT_MANTISSA_BIT_WIDTH: &'static usize = &19; +pub const AMOUNT_EXPONENT_BIT_WIDTH: usize = 5; +pub const AMOUNT_MANTISSA_BIT_WIDTH: usize = 19; /// Fee bit widths -pub const FEE_EXPONENT_BIT_WIDTH: &'static usize = &4; -pub const FEE_MANTISSA_BIT_WIDTH: &'static usize = &4; +pub const FEE_EXPONENT_BIT_WIDTH: usize = 4; +pub const FEE_MANTISSA_BIT_WIDTH: usize = 4; // Signature data -pub const SIGNATURE_S_BIT_WIDTH: &'static usize = &254; -pub const SIGNATURE_R_X_BIT_WIDTH: &'static usize = &254; -pub const SIGNATURE_R_Y_BIT_WIDTH: &'static usize = &254; +pub const SIGNATURE_S_BIT_WIDTH: usize = 254; +pub const SIGNATURE_R_X_BIT_WIDTH: usize = 254; +pub const SIGNATURE_R_Y_BIT_WIDTH: usize = 254; // Fr element encoding pub const FR_BIT_WIDTH: usize = 254; pub const FR_BIT_WIDTH_PADDED: usize = 256; /// Number of supported tokens. -pub const TOTAL_TOKENS: usize = 1 << *BALANCE_TREE_DEPTH; +pub const TOTAL_TOKENS: usize = 1 << BALANCE_TREE_DEPTH; pub const ETH_TOKEN_ID: TokenId = 0; pub const BLOCK_SIZE_CHUNKS: usize = 10; diff --git a/core/franklinmodels/src/primitives.rs b/core/models/src/primitives.rs similarity index 100% rename from core/franklinmodels/src/primitives.rs rename to core/models/src/primitives.rs diff --git a/core/plasma/Cargo.toml b/core/plasma/Cargo.toml index 4a975183c1..d74d8057a9 100644 --- a/core/plasma/Cargo.toml +++ b/core/plasma/Cargo.toml @@ -9,7 +9,7 @@ authors = [ ] [dependencies] -models = { package = "franklinmodels", path = "../franklinmodels" } +models = { package = "models", path = "../models" } bigdecimal = { version = "0.0.14", features = ["serde"]} log = "0.4" failure = "0.1" diff --git a/core/prover/Cargo.toml b/core/prover/Cargo.toml index 31be65ba27..02fd7be423 100644 --- a/core/prover/Cargo.toml +++ b/core/prover/Cargo.toml @@ -5,8 +5,9 @@ edition = "2018" [dependencies] plasma = { path = "../plasma" } -models = { package = "franklinmodels", path = "../franklinmodels" } +models = { package = "models", path = "../models" } storage = { path = "../storage" } +circuit = { package = "circuit", path = "../circuit"} ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } pairing = { package = "pairing_ce", version = "0.17.0" } @@ -35,3 +36,4 @@ bigdecimal = { version = "0.0.14", features = ["serde"]} chrono = { version = "0.4", features = ["serde", "rustc-serialize"] } log = "0.4" env_logger = "0.6" +num-traits = "0.2" \ No newline at end of file diff --git a/core/prover/src/bin/dummy_prover.rs b/core/prover/src/bin/dummy_prover.rs deleted file mode 100644 index 0f5554d105..0000000000 --- a/core/prover/src/bin/dummy_prover.rs +++ /dev/null @@ -1,24 +0,0 @@ -use log::info; -use models::node::config::{PROVER_CYCLE_WAIT, PROVER_TIMEOUT}; -use models::EncodedProof; -use std::time::Duration; -use storage::ConnectionPool; - -fn main() { - env_logger::init(); - - let pool = ConnectionPool::new(); - let worker = "dummy_worker"; - info!("Started prover"); - loop { - let storage = pool.access_storage().expect("Storage access"); - let job = storage - .fetch_prover_job(worker, PROVER_TIMEOUT) - .expect("prover job, db access"); - if let Some(job) = job { - info!("Received job for block: {}", job.block_number); - storage.store_proof(job.block_number as u32, &EncodedProof::default()); - } - std::thread::sleep(Duration::from_secs(PROVER_CYCLE_WAIT)); - } -} diff --git a/core/prover/src/lib.rs b/core/prover/src/lib.rs index 22d5c9404b..47ac21b4f2 100644 --- a/core/prover/src/lib.rs +++ b/core/prover/src/lib.rs @@ -1,1237 +1,584 @@ -//#[macro_use] -//extern crate log; -// -//use rand::OsRng; -//use std::fmt; -//use std::iter::Iterator; -//use std::sync::{ -// atomic::{AtomicBool, AtomicUsize, Ordering}, -// Arc, -//}; -//use std::thread; -//use std::time::Duration; -// -//use tokio::prelude::*; -//use tokio::runtime::current_thread::Handle; -//use tokio::sync::oneshot::Sender; -//use tokio::timer; -// -//use crypto::digest::Digest; -//use crypto::sha2::Sha256; -// -//use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr}; -//use franklin_crypto::alt_babyjubjub::AltJubjubBn256; -//use franklin_crypto::circuit::float_point::parse_float_to_u128; -//use franklin_crypto::jubjub::{edwards, JubjubEngine}; -// -//use rustc_hex::ToHex; -// -//use bellman::groth16::{ -// create_random_proof, prepare_verifying_key, verify_proof, Parameters, Proof, -//}; -// -//use models::plasma::block::Block; -//use models::plasma::block::BlockData; -//use models::plasma::circuit::account::CircuitAccount; -//use models::plasma::params; -//use models::plasma::tx::{DepositTx, ExitTx, TransferTx}; -//use models::plasma::{AccountId, BlockNumber, Engine, Fr}; -//use plasma::state::PlasmaState; -// -//use circuit::encoder; -//use models::config::{ +#[macro_use] +extern crate log; + +use rand::OsRng; +use std::fmt; +use std::iter::Iterator; +use std::sync::{ + atomic::{AtomicBool, AtomicUsize, Ordering}, + Arc, +}; +use std::thread; +use std::time::Duration; + +use bellman::groth16::{ + create_random_proof, prepare_verifying_key, verify_proof, Parameters, Proof, +}; +use circuit::account::AccountWitness; +use circuit::circuit::FranklinCircuit; +use circuit::witness::close_account::*; +use circuit::witness::deposit::*; +use circuit::witness::noop::noop_operation; +use circuit::witness::partial_exit::*; +use circuit::witness::transfer::*; +use circuit::witness::transfer_to_new::*; +use circuit::witness::utils::*; +use ff::{Field, PrimeField}; +use franklin_crypto::alt_babyjubjub::AltJubjubBn256; +use franklin_crypto::jubjub::JubjubEngine; +use models::circuit::account::CircuitAccount; +use models::circuit::CircuitAccountTree; +use models::node::Account; +use models::node::*; +use models::params as franklin_constants; +use models::primitives::pack_bits_into_bytes_in_order; +use models::EncodedProof; +use plasma::state::PlasmaState; +use tokio::prelude::*; +use tokio::runtime::current_thread::Handle; +use tokio::sync::oneshot::Sender; +use tokio::timer; + +use num_traits::cast::ToPrimitive; +// use models::circuit::encoder; +// use models::config::{ // DEPOSIT_BATCH_SIZE, EXIT_BATCH_SIZE, PROVER_CYCLE_WAIT, PROVER_TIMEOUT, PROVER_TIMER_TICK, // RUNTIME_CONFIG, -//}; -//use storage::StorageProcessor; -// -//use models::plasma::circuit::utils::be_bit_vector_into_bytes; -// -//use circuit::transfer::circuit::{TransactionWitness, Transfer}; -// -//use models::primitives::{ -// field_element_to_u32, serialize_g1_for_ethereum, serialize_g2_for_ethereum, -//}; -// -////pub struct Prover { -//// pub tx_batch_size: usize, -//// pub deposit_batch_size: usize, -//// pub exit_batch_size: usize, -//// pub current_block_number: BlockNumber, -//// pub accounts_tree: CircuitAccountTree, -//// pub transfer_parameters: BabyParameters, -//// pub deposit_parameters: BabyParameters, -//// pub exit_parameters: BabyParameters, -//// pub jubjub_params: E::Params, -//// pub worker: String, -//// pub prover_id: i32, -//// pub current_job: Arc, -////} -// -//pub type BabyProof = Proof; -//pub type BabyParameters = Parameters; -//pub type BabyProver = Prover; -// -//#[derive(Debug)] -//pub enum BabyProverErr { -// InvalidAmountEncoding, -// InvalidFeeEncoding, -// InvalidSender, -// InvalidRecipient, -// InvalidTransaction(String), -// IoError(std::io::Error), -// Other(String), -//} -// -//impl BabyProverErr { -// fn description(&self) -> String { -// match *self { -// BabyProverErr::InvalidAmountEncoding => { -// "transfer amount is malformed or too large".to_owned() -// } -// BabyProverErr::InvalidFeeEncoding => { -// "transfer fee is malformed or too large".to_owned() -// } -// BabyProverErr::InvalidSender => "sender account is unknown".to_owned(), -// BabyProverErr::InvalidRecipient => "recipient account is unknown".to_owned(), -// BabyProverErr::InvalidTransaction(ref reason) => format!("invalid tx data: {}", reason), -// BabyProverErr::IoError(_) => "encountered an I/O error".to_owned(), -// BabyProverErr::Other(ref reason) => format!("Prover error: {}", reason), -// } -// } -//} -// -//impl fmt::Display for BabyProverErr { -// fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { -// if let BabyProverErr::IoError(ref e) = *self { -// write!(f, "I/O error: ")?; -// e.fmt(f) -// } else { -// write!(f, "{}", self.description()) -// } -// } -//} -// -//#[derive(Debug)] -//pub struct FullBabyProof { -// proof: BabyProof, -// inputs: [Fr; 3], -// block_number: Fr, -// total_fees: Fr, -// public_data: Vec, -//} -// -//fn read_parameters(file_name: &str) -> Result { -// use std::fs::File; -// use std::io::BufReader; -// -// let f_r = File::open(file_name); -// if f_r.is_err() { -// return Err(BabyProverErr::IoError(f_r.err().unwrap())); -// } -// let mut r = BufReader::new(f_r.unwrap()); -// let circuit_params = BabyParameters::read(&mut r, true); -// -// if circuit_params.is_err() { -// return Err(BabyProverErr::IoError(circuit_params.err().unwrap())); -// } -// -// Ok(circuit_params.unwrap()) -//} -// -//fn extend_accounts>( -// tree: &mut CircuitAccountTree, -// accounts: I, -//) { -// for e in accounts { -// let acc_number = e.0; -// let leaf_copy = CircuitAccount::from(e.1.clone()); -// tree.insert(acc_number, leaf_copy); -// } -//} -// -//// IMPORTANT: prover does NOT care about some ordering of the transactions, so blocks supplied here MUST be ordered -//// for the application layer -// -//impl BabyProver { -// // Outputs -// // - 8 uint256 for encoding of the field elements -// // - one uint256 for new root hash -// // - uint256 block number -// // - uint256 total fees -// // - Bytes public data -// // -// // Old root is available to take from the storage of the smart-contract -// pub fn encode_proof(proof: &FullBabyProof) -> Result { -// // proof -// // pub a: E::G1Affine, -// // pub b: E::G2Affine, -// // pub c: E::G1Affine -// -// let (a_x, a_y) = serialize_g1_for_ethereum(proof.proof.a); -// -// let ((b_x_0, b_x_1), (b_y_0, b_y_1)) = serialize_g2_for_ethereum(proof.proof.b); -// -// let (c_x, c_y) = serialize_g1_for_ethereum(proof.proof.c); -// -// // let new_root = serialize_fe_for_ethereum(proof.inputs[1]); -// -// // let total_fees = serialize_fe_for_ethereum(proof.total_fees); -// -// // let block_number = serialize_fe_for_ethereum(proof.block_number); -// -// // let public_data = proof.public_data.clone(); -// -// let p = [a_x, a_y, b_x_0, b_x_1, b_y_0, b_y_1, c_x, c_y]; -// -// // EncodedProof{ -// // groth_proof: [a_x, a_y, b_x_0, b_x_1, b_y_0, b_y_1, c_x, c_y], -// // //block_number: block_number, -// // }; -// -// Ok(p) -// } -// -// pub fn create(worker: String) -> Result { -// let storage = -// StorageProcessor::establish_connection().expect("db connection failed for prover"); -// -// let (last_block, accounts) = storage -// .load_verified_state() -// .expect("db must be functional"); -// let initial_state = PlasmaState::new(accounts, last_block + 1); -// -// info!("Reading proving key, may take a while"); -// -// let keys_path = &RUNTIME_CONFIG.keys_path; -// -// let path = format!("{}/transfer_pk.key", keys_path); -// debug!("Reading key from {}", path); -// let transfer_circuit_params = read_parameters(&path); -// if transfer_circuit_params.is_err() { -// return Err(transfer_circuit_params.err().unwrap()); -// } -// -// debug!("Done reading transfer key"); -// -// let path = format!("{}/deposit_pk.key", keys_path); -// debug!("Reading key from {}", path); -// let deposit_circuit_params = read_parameters(&path); -// if deposit_circuit_params.is_err() { -// return Err(deposit_circuit_params.err().unwrap()); -// } -// -// debug!("Done reading deposit key"); -// -// let path = format!("{}/exit_pk.key", keys_path); -// debug!("Reading key from {}", path); -// let exit_circuit_params = read_parameters(&path); -// if exit_circuit_params.is_err() { -// return Err(exit_circuit_params.err().unwrap()); -// } -// -// debug!("Done reading exit key"); -// -// info!("Copying states to balance tree"); -// -// // TODO: replace with .clone() by moving PedersenHasher to static context -// let mut tree = CircuitAccountTree::new(params::BALANCE_TREE_DEPTH as u32); -// extend_accounts(&mut tree, initial_state.get_accounts().into_iter()); -// // { -// // let iter = initial_state.get_accounts().into_iter(); -// -// // for e in iter { -// // let acc_number = e.0; -// // let leaf_copy = Account::from(e.1.clone()); -// // tree.insert(acc_number, leaf_copy); -// // } -// // } -// -// let root = tree.root_hash(); -// -// let state_block_number = initial_state.block_number; -// -// info!( -// "Initial root hash is {} for block {}", -// root, state_block_number -// ); -// -// let supplied_root = initial_state.root_hash(); -// -// if root != supplied_root { -// return Err(BabyProverErr::Other("root did not change".to_owned())); -// } -// -// let jubjub_params = AltJubjubBn256::new(); -// -// let prover_id = storage -// .register_prover(&worker) -// .expect("getting prover id failed"); -// -// Ok(Self { -// tx_batch_size: RUNTIME_CONFIG.tx_batch_size, -// deposit_batch_size: DEPOSIT_BATCH_SIZE, -// exit_batch_size: EXIT_BATCH_SIZE, -// current_block_number: state_block_number, -// accounts_tree: tree, -// transfer_parameters: transfer_circuit_params.unwrap(), -// deposit_parameters: deposit_circuit_params.unwrap(), -// exit_parameters: exit_circuit_params.unwrap(), -// jubjub_params, -// current_job: Arc::new(AtomicUsize::new(0)), -// worker, -// prover_id, -// }) -// } -//} -// -//type Err = BabyProverErr; -// -//impl BabyProver { -// pub fn apply_and_prove(&mut self, block: &Block) -> Result { -// // match block.block_data { -// // BlockData::Deposit { -// // ref transactions, .. -// // } => self.apply_and_prove_deposit(&block, transactions), -// // BlockData::Exit { -// // ref transactions, .. -// // } => self.apply_and_prove_exit(&block, transactions), -// // BlockData::Transfer { -// // ref transactions, .. -// // } => self.apply_and_prove_transfer(&block, &transactions), -// // } -// unimplemented!() -// } -// -// // Apply transactions to the state while also making a witness for proof, then calculate proof -// pub fn apply_and_prove_transfer( -// &mut self, -// block: &Block, -// transactions: &[TransferTx], -// ) -> Result { -// let block_number = block.block_number; -// if block_number != self.current_block_number { -// debug!( -// "Transfer proof request is for block {}, while prover state is block {}", -// block_number, self.current_block_number -// ); -// return Err(BabyProverErr::Other("incorrect block".to_owned())); -// } -// let block_final_root = block.new_root_hash; -// -// let public_data: Vec = -// encoder::encode_transactions(&block).expect("encoding transactions failed"); -// -// //let transactions = &block.transactions; -// let num_txes = transactions.len(); -// -// if num_txes != self.tx_batch_size { -// return Err(BabyProverErr::Other( -// "num_txes != self.tx_batch_size".to_owned(), -// )); -// } -// -// let mut witnesses: Vec<(Transaction, TransactionWitness)> = vec![]; -// -// let mut total_fees = Fr::zero(); -// -// let initial_root = self.accounts_tree.root_hash(); -// -// for tx in transactions { -// let tx = circuit::CircuitTransferTx::try_from(tx) -// .map_err(|e| BabyProverErr::InvalidTransaction(e.to_string()))?; -// let sender_leaf_number = field_element_to_u32(tx.from); -// let recipient_leaf_number = field_element_to_u32(tx.to); -// -// let empty_account = CircuitAccount::default(); -// -// let tree = &mut self.accounts_tree; -// let items = tree.items.clone(); -// -// let sender_leaf = items.get(&sender_leaf_number); -// let mut recipient_leaf = items.get(&recipient_leaf_number); -// -// if sender_leaf.is_none() { -// return Err(BabyProverErr::InvalidSender); -// } -// -// // allow transfers to empty accounts -// if recipient_leaf.is_none() { -// recipient_leaf = Some(&empty_account); -// } -// -// // this is LE bits encoding of the transaction amount -// let mut amount_bits: Vec = BitIterator::new(tx.amount.into_repr()).collect(); -// amount_bits.reverse(); -// amount_bits -// .truncate(params::AMOUNT_EXPONENT_BIT_WIDTH + params::AMOUNT_MANTISSA_BIT_WIDTH); -// -// let parsed_transfer_amount = parse_float_to_u128( -// amount_bits, -// params::AMOUNT_EXPONENT_BIT_WIDTH, -// params::AMOUNT_MANTISSA_BIT_WIDTH, -// 10, -// ); -// -// // this is LE bits encoding of the transaction fee -// let mut fee_bits: Vec = BitIterator::new(tx.fee.into_repr()).collect(); -// fee_bits.reverse(); -// fee_bits.truncate(params::FEE_EXPONENT_BIT_WIDTH + params::FEE_MANTISSA_BIT_WIDTH); -// -// let parsed_fee = parse_float_to_u128( -// fee_bits, -// params::FEE_EXPONENT_BIT_WIDTH, -// params::FEE_MANTISSA_BIT_WIDTH, -// 10, -// ); -// -// if parsed_transfer_amount.is_err() || parsed_fee.is_err() { -// return Err(BabyProverErr::InvalidAmountEncoding); -// } -// -// let transfer_amount_as_field_element = -// Fr::from_str(&parsed_transfer_amount.unwrap().to_string()).unwrap(); -// let fee_as_field_element = Fr::from_str(&parsed_fee.unwrap().to_string()).unwrap(); -// -// let path_from: Vec> = tree -// .merkle_path(sender_leaf_number) -// .into_iter() -// .map(|e| Some(e.0)) -// .collect(); -// let path_to: Vec> = tree -// .merkle_path(recipient_leaf_number) -// .into_iter() -// .map(|e| Some(e.0)) -// .collect(); -// -// let transaction = Transaction { -// from: Some(tx.from), -// to: Some(tx.to), -// amount: Some(tx.amount), -// fee: Some(tx.fee), -// nonce: Some(tx.nonce), -// good_until_block: Some(tx.good_until_block), -// signature: Some(tx.signature.clone()), -// }; -// -// let mut updated_sender_leaf = sender_leaf.unwrap().clone(); -// let mut updated_recipient_leaf = recipient_leaf.unwrap().clone(); -// -// updated_sender_leaf -// .balance -// .sub_assign(&transfer_amount_as_field_element); -// updated_sender_leaf -// .balance -// .sub_assign(&fee_as_field_element); -// -// updated_sender_leaf.nonce.add_assign(&Fr::one()); -// -// if recipient_leaf_number != 0 { -// updated_recipient_leaf -// .balance -// .add_assign(&transfer_amount_as_field_element); -// } -// -// total_fees.add_assign(&fee_as_field_element); -// -// tree.insert(sender_leaf_number, updated_sender_leaf.clone()); -// tree.insert(recipient_leaf_number, updated_recipient_leaf.clone()); -// -// { -// let sender_leaf = sender_leaf.unwrap(); -// -// let recipient_leaf = recipient_leaf.unwrap(); -// -// let transaction_witness = TransactionWitness:: { -// auth_path_from: path_from, -// leaf_from: LeafWitness:: { -// balance: Some(sender_leaf.balance), -// nonce: Some(sender_leaf.nonce), -// pub_x: Some(sender_leaf.pub_x), -// pub_y: Some(sender_leaf.pub_y), -// }, -// auth_path_to: path_to, -// leaf_to: LeafWitness:: { -// balance: Some(recipient_leaf.balance), -// nonce: Some(recipient_leaf.nonce), -// pub_x: Some(recipient_leaf.pub_x), -// pub_y: Some(recipient_leaf.pub_y), -// }, -// }; -// -// let witness = (transaction.clone(), transaction_witness); -// -// witnesses.push(witness); -// } -// } -// -// let block_number = Fr::from_str(&block_number.to_string()).unwrap(); -// -// let final_root = self.accounts_tree.root_hash(); -// -// if initial_root == final_root { -// return Err(BabyProverErr::Other( -// "initial_root == final_root".to_owned(), -// )); -// } -// -// info!( -// "Prover final root = {}, final root from state keeper = {}", -// final_root, block_final_root -// ); -// -// if block_final_root != final_root { -// return Err(BabyProverErr::Other( -// "block_final_root != final_root".to_owned(), -// )); -// } -// -// self.current_block_number += 1; -// -// let mut public_data_initial_bits = vec![]; -// -// // these two are BE encodings because an iterator is BE. This is also an Ethereum standard behavior -// -// let block_number_bits: Vec = BitIterator::new(block_number.into_repr()).collect(); -// for _ in 0..256 - block_number_bits.len() { -// public_data_initial_bits.push(false); -// } -// public_data_initial_bits.extend(block_number_bits.into_iter()); -// -// let total_fee_bits: Vec = BitIterator::new(total_fees.into_repr()).collect(); -// for _ in 0..256 - total_fee_bits.len() { -// public_data_initial_bits.push(false); -// } -// public_data_initial_bits.extend(total_fee_bits.into_iter()); -// -// assert_eq!(public_data_initial_bits.len(), 512); -// -// let mut h = Sha256::new(); -// -// let bytes_to_hash = be_bit_vector_into_bytes(&public_data_initial_bits); -// -// // let hex_block_and_fee: String = bytes_to_hash.clone().to_hex(); -// // debug!("Packed initial hash information = {}", hex_block_and_fee); -// -// h.input(&bytes_to_hash); -// -// let mut hash_result = [0u8; 32]; -// h.result(&mut hash_result[..]); -// -// { -// let packed_transaction_data_bytes = public_data.clone(); -// -// // let hex: String = packed_transaction_data_bytes.clone().to_hex(); -// // debug!("Packed transfers information data = {}", hex); -// -// let mut next_round_hash_bytes = Vec::new(); -// next_round_hash_bytes.extend(hash_result.iter()); -// next_round_hash_bytes.extend(packed_transaction_data_bytes); -// -// let mut h = Sha256::new(); -// -// h.input(&next_round_hash_bytes); -// -// h.result(&mut hash_result[..]); -// } -// -// // clip to fit into field element -// -// hash_result[0] &= 0x1f; // temporary solution -// -// let mut repr = Fr::zero().into_repr(); -// repr.read_be(&hash_result[..]) -// .expect("pack hash as field element"); -// -// let public_data_commitment = Fr::from_repr(repr).unwrap(); -// -// let instance = Transfer { -// params: &self.jubjub_params, -// number_of_transactions: num_txes, -// old_root: Some(initial_root), -// new_root: Some(final_root), -// public_data_commitment: Some(public_data_commitment), -// block_number: Some(block_number), -// total_fee: Some(total_fees), -// transactions: witnesses.clone(), -// }; -// -// // { -// // let inst = Transfer { -// // params: &self.jubjub_params, -// // number_of_transactions: num_txes, -// // old_root: Some(initial_root), -// // new_root: Some(final_root), -// // public_data_commitment: Some(public_data_commitment), -// // block_number: Some(block_number), -// // total_fee: Some(total_fees), -// // transactions: witnesses.clone(), -// // }; -// -// // use franklin_crypto::circuit::test::*; -// // use bellman::Circuit; -// // let mut cs = TestConstraintSystem::::new(); -// // inst.synthesize(&mut cs).unwrap(); -// -// // print!("{}\n", cs.find_unconstrained()); -// -// // print!("{}\n", cs.num_constraints()); -// -// // assert_eq!(cs.num_inputs(), 4); -// -// // let err = cs.which_is_unsatisfied(); -// // if err.is_some() { -// // panic!("ERROR satisfying in {}\n", err.unwrap()); -// // } -// // debug!("CS is satisfied!"); -// // } -// -// let mut rng = OsRng::new().unwrap(); -// info!("Prover has started to work transfer"); -// let proof = create_random_proof(instance, &self.transfer_parameters, &mut rng); -// if proof.is_err() { -// return Err(BabyProverErr::Other("proof.is_err()".to_owned())); -// } -// -// let p = proof.unwrap(); -// -// let pvk = prepare_verifying_key(&self.transfer_parameters.vk); -// -// info!( -// "Made a proof for initial root = {}, final root = {}, public data = {}", -// initial_root, -// final_root, -// public_data_commitment.to_hex() -// ); -// let success = verify_proof( -// &pvk, -// &p.clone(), -// &[initial_root, final_root, public_data_commitment], -// ); -// if success.is_err() { -// error!( -// "Proof is verification failed with error {}", -// success.err().unwrap() -// ); -// return Err(BabyProverErr::Other( -// "Proof is verification failed".to_owned(), -// )); -// } -// if !success.unwrap() { -// error!("Proof is invalid"); -// return Err(BabyProverErr::Other("Proof is invalid".to_owned())); -// } -// -// info!("Proof generation is complete"); -// -// let full_proof = FullBabyProof { -// proof: p, -// inputs: [initial_root, final_root, public_data_commitment], -// total_fees, -// block_number, -// public_data, -// }; -// -// Ok(full_proof) -// } -// -// // expects accounts in block to be sorted already -// pub fn apply_and_prove_deposit( -// &mut self, -// block: &Block, -// transactions: &[DepositTx], -// ) -> Result { -// // debug!("block: {:?}", &block.block_data); -// // debug!("transactions: {:?}", &transactions); -// -// let block_number = block.block_number; -// if block_number != self.current_block_number { -// error!( -// "Deposit proof request is for block {}, while prover state is block {}", -// block_number, self.current_block_number -// ); -// return Err(BabyProverErr::Other( -// "block_number != self.current_block_number".to_owned(), -// )); -// } -// let block_final_root = block.new_root_hash; -// -// let public_data: Vec = -// encoder::encode_transactions(block).expect("prover: encoding failed"); -// -// //let transactions = &block.transactions; -// let num_txes = transactions.len(); -// -// if num_txes != self.deposit_batch_size { -// return Err(BabyProverErr::Other( -// "num_txes != self.deposit_batch_size".to_owned(), -// )); -// } -// -// let mut witnesses: Vec<(DepositRequest, DepositWitness)> = vec![]; -// -// let initial_root = self.accounts_tree.root_hash(); -// -// for tx in transactions { -// let tx = circuit::CircuitDepositRequest::try_from(tx) -// .map_err(|e| BabyProverErr::InvalidTransaction(e.to_string()))?; -// -// let into_leaf_number = field_element_to_u32(tx.into); -// -// let tree = &mut self.accounts_tree; -// let items = tree.items.clone(); -// -// let existing_leaf = items.get(&into_leaf_number); -// let mut leaf_is_empty = true; -// -// let (old_leaf, new_leaf) = if existing_leaf.is_none() { -// let mut new_leaf = CircuitAccount::default(); -// new_leaf.balance = tx.amount; -// new_leaf.pub_x = tx.pub_x; -// new_leaf.pub_y = tx.pub_y; -// -// (CircuitAccount::default(), new_leaf) -// } else { -// let old_leaf = existing_leaf.unwrap().clone(); -// let mut new_leaf = old_leaf.clone(); -// new_leaf.balance.add_assign(&tx.amount); -// leaf_is_empty = false; -// -// (old_leaf, new_leaf) -// }; -// -// let path: Vec> = tree -// .merkle_path(into_leaf_number) -// .into_iter() -// .map(|e| Some(e.0)) -// .collect(); -// -// let public_key = -// edwards::Point::from_xy(new_leaf.pub_x, new_leaf.pub_y, &self.jubjub_params); -// -// if public_key.is_none() { -// return Err(BabyProverErr::Other("public_key.is_none()".to_owned())); -// } -// -// let request = DepositRequest { -// into: Fr::from_str(&into_leaf_number.to_string()), -// amount: Some(tx.amount), -// public_key, -// }; -// -// tree.insert(into_leaf_number, new_leaf.clone()); -// -// { -// let deposit_witness = DepositWitness:: { -// auth_path: path, -// leaf: LeafWitness:: { -// balance: Some(old_leaf.balance), -// nonce: Some(old_leaf.nonce), -// pub_x: Some(old_leaf.pub_x), -// pub_y: Some(old_leaf.pub_y), -// }, -// -// leaf_is_empty: Some(leaf_is_empty), -// new_pub_x: Some(new_leaf.pub_x), -// new_pub_y: Some(new_leaf.pub_y), -// }; -// -// let witness = (request.clone(), deposit_witness); -// -// witnesses.push(witness); -// } -// } -// -// let block_number = Fr::from_str(&block_number.to_string()).unwrap(); -// -// let final_root = self.accounts_tree.root_hash(); -// -// info!( -// "Prover final root = {}, final root from state keeper = {}", -// final_root, block_final_root -// ); -// -// if initial_root == final_root { -// return Err(BabyProverErr::Other(format!( -// "initial_root == final_root, {:?}", -// initial_root -// ))); -// } -// -// if block_final_root != final_root { -// return Err(BabyProverErr::Other( -// "block_final_root != final_root".to_owned(), -// )); -// } -// -// self.current_block_number += 1; -// -// let mut public_data_initial_bits = vec![]; -// -// // these two are BE encodings because an iterator is BE. This is also an Ethereum standard behavior -// -// let block_number_bits: Vec = BitIterator::new(block_number.into_repr()).collect(); -// for _ in 0..256 - block_number_bits.len() { -// public_data_initial_bits.push(false); -// } -// public_data_initial_bits.extend(block_number_bits.into_iter()); -// -// assert_eq!(public_data_initial_bits.len(), 256); -// -// let mut h = Sha256::new(); -// -// let bytes_to_hash = be_bit_vector_into_bytes(&public_data_initial_bits); -// -// let hex_block_and_fee: String = bytes_to_hash.clone().to_hex(); -// debug!( -// "Packed initial hash information in deposit = {}", -// hex_block_and_fee -// ); -// -// h.input(&bytes_to_hash); -// -// let mut hash_result = [0u8; 32]; -// h.result(&mut hash_result[..]); -// -// let initial_hash: String = hash_result.to_hex(); -// debug!("Block number hash in deposit = {}", initial_hash); -// -// { -// let packed_transaction_data_bytes = public_data.clone(); -// -// let hex: String = packed_transaction_data_bytes.clone().to_hex(); -// debug!("Packed deposit information data in deposit = {}", hex); -// -// let mut next_round_hash_bytes = vec![]; -// next_round_hash_bytes.extend(hash_result.iter()); -// next_round_hash_bytes.extend(packed_transaction_data_bytes); -// -// let mut h = Sha256::new(); -// -// h.input(&next_round_hash_bytes); -// -// h.result(&mut hash_result[..]); -// } -// -// // clip to fit into field element -// -// hash_result[0] &= 0x1f; // temporary solution -// -// let mut repr = Fr::zero().into_repr(); -// repr.read_be(&hash_result[..]) -// .expect("pack hash as field element"); -// -// let public_data_commitment = Fr::from_repr(repr).unwrap(); -// -// let instance = Deposit { -// params: &self.jubjub_params, -// number_of_deposits: num_txes, -// old_root: Some(initial_root), -// new_root: Some(final_root), -// public_data_commitment: Some(public_data_commitment), -// block_number: Some(block_number), -// requests: witnesses.clone(), -// }; -// -// let mut rng = OsRng::new().unwrap(); -// debug!("Prover has started to work deposits"); -// let proof = create_random_proof(instance, &self.deposit_parameters, &mut rng); -// if proof.is_err() { -// return Err(BabyProverErr::Other("proof.is_err()".to_owned())); -// } -// -// let p = proof.unwrap(); -// -// let pvk = prepare_verifying_key(&self.deposit_parameters.vk); -// -// debug!( -// "Made an deposit proof for initial root = {}, final root = {}, public data = {}", -// initial_root, -// final_root, -// public_data_commitment.to_hex() -// ); -// let success = verify_proof( -// &pvk, -// &p.clone(), -// &[initial_root, final_root, public_data_commitment], -// ); -// -// if success.is_err() { -// error!( -// "Proof verification failed with error {}", -// success.err().unwrap() -// ); -// return Err(BabyProverErr::Other("Proof verification failed".to_owned())); -// } -// if !success.unwrap() { -// error!("Proof is invalid"); -// return Err(BabyProverErr::Other("Proof is invalid".to_owned())); -// } -// info!("Proof generation is complete"); -// -// let full_proof = FullBabyProof { -// proof: p, -// inputs: [initial_root, final_root, public_data_commitment], -// total_fees: Fr::zero(), -// block_number, -// public_data, -// }; -// -// Ok(full_proof) -// } -// -// // expects accounts in block to be sorted already -// pub fn apply_and_prove_exit( -// &mut self, -// block: &Block, -// transactions: &[ExitTx], -// ) -> Result { -// let block_number = block.block_number; -// if block_number != self.current_block_number { -// info!( -// "Exit proof request is for block {}, while prover state is block {}", -// block_number, self.current_block_number -// ); -// return Err(BabyProverErr::Other( -// "block_number != self.current_block_number".to_owned(), -// )); -// } -// let block_final_root = block.new_root_hash; -// -// //let transactions = &block.transactions; -// let num_txes = transactions.len(); -// -// if num_txes != self.deposit_batch_size { -// return Err(BabyProverErr::Other( -// "num_txes != self.deposit_batch_size".to_owned(), -// )); -// } -// -// let mut witnesses: Vec<(ExitRequest, ExitWitness)> = Vec::new(); -// -// let initial_root = self.accounts_tree.root_hash(); -// -// // we also need to create public data cause we need info from state -// let mut public_data: Vec = Vec::new(); -// -// for tx in transactions { -// let tx = circuit::CircuitExitRequest::try_from(tx) -// .map_err(|e| BabyProverErr::InvalidTransaction(e.to_string()))?; -// -// let from_leaf_number = field_element_to_u32(tx.from); -// -// let tree = &mut self.accounts_tree; -// let items = tree.items.clone(); -// -// let existing_leaf = items.get(&from_leaf_number); -// -// if existing_leaf.is_none() { -// return Err(BabyProverErr::Other("existing_leaf.is_none()".to_owned())); -// } -// -// let old_leaf = existing_leaf.unwrap(); -// -// let new_leaf = CircuitAccount::default(); -// -// let path: Vec> = tree -// .merkle_path(from_leaf_number) -// .into_iter() -// .map(|e| Some(e.0)) -// .collect(); -// -// let request = ExitRequest { -// from: Fr::from_str(&from_leaf_number.to_string()), -// amount: Some(old_leaf.balance), -// }; -// -// // we have the leaf info, so add it to the public data -// let tx_bits = request.public_data_into_bits(); -// let tx_encoding = be_bit_vector_into_bytes(&tx_bits); -// public_data.extend(tx_encoding.into_iter()); -// -// tree.insert(from_leaf_number, new_leaf.clone()); -// -// { -// let deposit_witness = ExitWitness:: { -// auth_path: path, -// leaf: LeafWitness:: { -// balance: Some(old_leaf.balance), -// nonce: Some(old_leaf.nonce), -// pub_x: Some(old_leaf.pub_x), -// pub_y: Some(old_leaf.pub_y), -// }, -// }; -// -// let witness = (request.clone(), deposit_witness); -// -// witnesses.push(witness); -// } -// } -// -// let block_number = Fr::from_str(&block_number.to_string()).unwrap(); -// -// let final_root = self.accounts_tree.root_hash(); -// -// if initial_root == final_root { -// return Err(BabyProverErr::Other( -// "initial_root == final_root".to_owned(), -// )); -// } -// -// debug!( -// "Prover final root = {}, final root from state keeper = {}", -// final_root, block_final_root -// ); -// -// if block_final_root != final_root { -// return Err(BabyProverErr::Other( -// "block_final_root != final_root".to_owned(), -// )); -// } -// -// self.current_block_number += 1; -// -// let mut public_data_initial_bits = vec![]; -// -// // these two are BE encodings because an iterator is BE. This is also an Ethereum standard behavior -// -// let block_number_bits: Vec = BitIterator::new(block_number.into_repr()).collect(); -// for _ in 0..256 - block_number_bits.len() { -// public_data_initial_bits.push(false); -// } -// public_data_initial_bits.extend(block_number_bits.into_iter()); -// -// assert_eq!(public_data_initial_bits.len(), 256); -// -// let mut h = Sha256::new(); -// -// let bytes_to_hash = be_bit_vector_into_bytes(&public_data_initial_bits); -// -// // let hex_block_and_fee: String = bytes_to_hash.clone().to_hex(); -// // debug!("Packed initial hash information in exit = {}", hex_block_and_fee); -// -// h.input(&bytes_to_hash); -// -// let mut hash_result = [0u8; 32]; -// h.result(&mut hash_result[..]); -// -// // let initial_hash: String = hash_result.clone().to_hex(); -// // debug!("Block number hash in exit = {}", initial_hash); -// -// { -// let packed_transaction_data_bytes = public_data.clone(); -// -// // let hex: String = packed_transaction_data_bytes.clone().to_hex(); -// // debug!("Packed transfers information data in exit= {}", hex); -// -// let mut next_round_hash_bytes = Vec::new(); -// next_round_hash_bytes.extend(hash_result.iter()); -// next_round_hash_bytes.extend(packed_transaction_data_bytes); -// -// // let hex_full: String = next_round_hash_bytes.clone().to_hex(); -// // debug!("Final hashable information data in exit= {}", hex_full); -// -// let mut h = Sha256::new(); -// -// h.input(&next_round_hash_bytes); -// -// h.result(&mut hash_result[..]); -// } -// -// // clip to fit into field element -// -// // let final_hash_hex: String = hash_result.clone().to_hex(); -// // debug!("Full public data commitment = {}", final_hash_hex); -// -// hash_result[0] &= 0x1f; // temporary solution -// -// let mut repr = Fr::zero().into_repr(); -// repr.read_be(&hash_result[..]) -// .expect("pack hash as field element"); -// -// let public_data_commitment = Fr::from_repr(repr).unwrap(); -// -// let empty_leaf_witness = LeafWitness:: { -// balance: Some(Fr::zero()), -// nonce: Some(Fr::zero()), -// pub_x: Some(Fr::zero()), -// pub_y: Some(Fr::zero()), -// }; -// -// let instance = Exit { -// params: &self.jubjub_params, -// number_of_exits: num_txes, -// old_root: Some(initial_root), -// new_root: Some(final_root), -// public_data_commitment: Some(public_data_commitment), -// empty_leaf_witness, -// block_number: Some(block_number), -// requests: witnesses.clone(), -// }; -// -// let mut rng = OsRng::new().unwrap(); -// debug!("Prover has started to work on exits"); -// let proof = create_random_proof(instance, &self.exit_parameters, &mut rng); -// if proof.is_err() { -// return Err(BabyProverErr::Other("proof.is_err()".to_owned())); -// } -// -// let p = proof.unwrap(); -// -// let pvk = prepare_verifying_key(&self.exit_parameters.vk); -// -// info!( -// "Made an exit proof for initial root = {}, final root = {}, public data = {}", -// initial_root, -// final_root, -// public_data_commitment.to_hex() -// ); -// let success = verify_proof( -// &pvk, -// &p.clone(), -// &[initial_root, final_root, public_data_commitment], -// ); -// -// if success.is_err() { -// error!( -// "Proof verification failed with error {}", -// success.err().unwrap() -// ); -// return Err(BabyProverErr::Other("Proof verification failed".to_owned())); -// } -// if !success.unwrap() { -// error!("Proof is invalid"); -// return Err(BabyProverErr::Other("Proof is invalid".to_owned())); -// } -// info!("Proof generation is complete"); -// -// let full_proof = FullBabyProof { -// proof: p, -// inputs: [initial_root, final_root, public_data_commitment], -// total_fees: Fr::zero(), -// block_number, -// public_data, -// }; -// -// Ok(full_proof) -// } -// -// fn rewind_state( -// &mut self, -// storage: &StorageProcessor, -// expected_current_block: BlockNumber, -// ) -> Result<(), String> { -// info!( -// "rewinding the state from block #{} to #{}", -// self.current_block_number, expected_current_block -// ); -// let (_, new_accounts) = storage -// .load_committed_state(Some(expected_current_block)) -// .map_err(|e| format!("load_state_diff failed: {}", e))?; -// -// let mut tree = CircuitAccountTree::new(params::BALANCE_TREE_DEPTH as u32); -// extend_accounts(&mut tree, new_accounts.into_iter()); -// -// self.accounts_tree = tree; -// self.current_block_number = expected_current_block; -// Ok(()) -// } -// -// fn make_proving_attempt(&mut self) -> Result<(), String> { -// let storage = StorageProcessor::establish_connection() -// .map_err(|e| format!("establish_connection failed: {}", e))?; -// let job = storage -// .fetch_prover_job(&self.worker, PROVER_TIMEOUT) -// .map_err(|e| format!("fetch_prover_job failed: {}", e))?; -// -// if let Some(job) = job { -// let block_number = job.block_number as BlockNumber; -// info!( -// "prover {} got a new job for block {}", -// &self.worker, block_number -// ); -// self.current_job.store(job.id as usize, Ordering::Relaxed); -// -// // load state delta self.current_block_number => block_number (can go both forwards and backwards) -// let expected_current_block = block_number; -// if self.current_block_number != expected_current_block { -// self.rewind_state(&storage, expected_current_block)?; -// } -// -// let block = storage -// .load_committed_block(block_number) -// .ok_or("load_committed_block failed")?; -// drop(storage); -// -// let proof = self -// .apply_and_prove(&block) -// .map_err(|e| format!("apply_and_prove failed: {}", e))?; -// let encoded = Self::encode_proof(&proof).expect("proof encoding failed"); -// -// let storage = StorageProcessor::establish_connection() -// .map_err(|e| format!("establish_connection failed: {}", e))?; -// storage -// .store_proof(block_number, &encoded) -// .map_err(|e| format!("store_proof failed: {}", e))?; -// } else { -// // no new job, so let's try to fast forward to the latest verified state for efficiency, and then sleep -// let last_verified_block = storage -// .get_last_verified_block() -// .map_err(|e| format!("get_last_verified_block failed: {}", e))?; -// if self.current_block_number < last_verified_block + 1 { -// self.rewind_state(&storage, last_verified_block + 1) -// .map_err(|e| format!("rewind_state failed: {}", e))?; -// } -// thread::sleep(Duration::from_secs(PROVER_CYCLE_WAIT)); -// } -// Ok(()) -// } -// -// pub fn start_timer_interval(&self, rt: &Handle) { -// let job_ref = self.current_job.clone(); -// rt.spawn( -// timer::Interval::new_interval(Duration::from_secs(PROVER_TIMER_TICK)) -// .fold(job_ref, |job_ref, _| { -// let job = job_ref.load(Ordering::Relaxed); -// if job > 0 { -// //debug!("prover is working on block {}", job); -// if let Ok(storage) = StorageProcessor::establish_connection() { -// let _ = storage.update_prover_job(job as i32); -// } -// } -// Ok(job_ref) -// }) -// .map(|_| ()) -// .map_err(|_| ()), -// ) -// .unwrap(); -// } -// -// pub fn run(&mut self, shutdown_tx: Sender<()>, stop_signal: Arc) { -// // info!("prover is running"); -// // while !stop_signal.load(Ordering::SeqCst) { -// // if let Err(err) = self.make_proving_attempt() { -// // error!("Error: {}", err); -// // } -// // self.current_job.store(0, Ordering::Relaxed); -// // } -// // info!("prover stopped"); -// // shutdown_tx.send(()).unwrap(); -// unimplemented!() -// } -//} -// -//// #[test] -// -//// fn test_exit_encoding() { -//// extern crate BigDecimal; -//// use models::plasma::ExitTx; -//// use self::BigDecimal::from_primitive; -//// let exit_tx = ExitTx { -//// account: 2, -//// amount: BigDecimal::from(1000), -//// } -//// let exitBlock = ExitBlock { -// -//// } -//// } +// }; +use storage::StorageProcessor; + +use models::primitives::{serialize_g1_for_ethereum, serialize_g2_for_ethereum}; + +pub struct Prover { + pub operation_batch_size: usize, + pub current_block_number: BlockNumber, + pub accounts_tree: CircuitAccountTree, + pub parameters: BabyParameters, + pub jubjub_params: E::Params, + pub worker: String, + pub prover_id: i32, + pub current_job: Arc, +} + +pub type BabyProof = Proof; +pub type BabyParameters = Parameters; +pub type BabyProver = Prover; + +#[derive(Debug)] +pub enum BabyProverErr { + InvalidAmountEncoding, + InvalidFeeEncoding, + InvalidSender, + InvalidRecipient, + InvalidTransaction(String), + IoError(std::io::Error), + Other(String), +} + +impl BabyProverErr { + fn description(&self) -> String { + match *self { + BabyProverErr::InvalidAmountEncoding => { + "transfer amount is malformed or too large".to_owned() + } + BabyProverErr::InvalidFeeEncoding => { + "transfer fee is malformed or too large".to_owned() + } + BabyProverErr::InvalidSender => "sender account is unknown".to_owned(), + BabyProverErr::InvalidRecipient => "recipient account is unknown".to_owned(), + BabyProverErr::InvalidTransaction(ref reason) => format!("invalid tx data: {}", reason), + BabyProverErr::IoError(_) => "encountered an I/O error".to_owned(), + BabyProverErr::Other(ref reason) => format!("Prover error: {}", reason), + } + } +} + +impl fmt::Display for BabyProverErr { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + if let BabyProverErr::IoError(ref e) = *self { + write!(f, "I/O error: ")?; + e.fmt(f) + } else { + write!(f, "{}", self.description()) + } + } +} + +#[derive(Debug)] +pub struct FullBabyProof { + proof: BabyProof, + inputs: [Fr; 1], + public_data: Vec, +} + +fn read_parameters(file_name: &str) -> Result { + use std::fs::File; + use std::io::BufReader; + + let f_r = File::open(file_name); + if f_r.is_err() { + return Err(BabyProverErr::IoError(f_r.err().unwrap())); + } + let mut r = BufReader::new(f_r.unwrap()); + let circuit_params = BabyParameters::read(&mut r, true); + + if circuit_params.is_err() { + return Err(BabyProverErr::IoError(circuit_params.err().unwrap())); + } + + Ok(circuit_params.unwrap()) +} + +fn extend_accounts>( + tree: &mut CircuitAccountTree, + accounts: I, +) { + for e in accounts { + let acc_number = e.0; + let leaf_copy = CircuitAccount::from(e.1.clone()); + tree.insert(acc_number, leaf_copy); + } +} + +// IMPORTANT: prover does NOT care about some ordering of the transactions, so blocks supplied here MUST be ordered +// for the application layer + +impl BabyProver { + // Outputs + // - 8 uint256 for encoding of the field elements + // - one uint256 for new root hash + // - uint256 block number + // - uint256 total fees + // - Bytes public data + // + // Old root is available to take from the storage of the smart-contract + pub fn encode_proof(proof: &FullBabyProof) -> Result { + // proof + // pub a: E::G1Affine, + // pub b: E::G2Affine, + // pub c: E::G1Affine + + let (a_x, a_y) = serialize_g1_for_ethereum(proof.proof.a); + + let ((b_x_0, b_x_1), (b_y_0, b_y_1)) = serialize_g2_for_ethereum(proof.proof.b); + + let (c_x, c_y) = serialize_g1_for_ethereum(proof.proof.c); + + // let new_root = serialize_fe_for_ethereum(proof.inputs[1]); + + // let total_fees = serialize_fe_for_ethereum(proof.total_fees); + + // let block_number = serialize_fe_for_ethereum(proof.block_number); + + // let public_data = proof.public_data.clone(); + + let p = [a_x, a_y, b_x_0, b_x_1, b_y_0, b_y_1, c_x, c_y]; + + // EncodedProof{ + // groth_proof: [a_x, a_y, b_x_0, b_x_1, b_y_0, b_y_1, c_x, c_y], + // //block_number: block_number, + // }; + + Ok(p) + } + + pub fn create(worker: String) -> Result { + let storage = + StorageProcessor::establish_connection().expect("db connection failed for prover"); + let (last_block, accounts) = storage + .load_verified_state() + .expect("db must be functional"); + info!("Last block is: {}", last_block); + debug!("Accounts: {:?}", accounts); + let initial_state = PlasmaState::new(accounts, last_block); + + info!("Reading proving key, may take a while"); + + let path = { + let mut key_file_path = std::path::PathBuf::new(); + key_file_path.push(&std::env::var("KEY_DIR").expect("KEY_DIR not set")); + key_file_path.push(&format!("{}", franklin_constants::BLOCK_SIZE_CHUNKS)); + key_file_path.push(franklin_constants::KEY_FILENAME); + key_file_path + }; + debug!("Reading key from {}", path.to_str().unwrap()); + let franklin_circuit_params = read_parameters(&path.to_str().unwrap()); + if franklin_circuit_params.is_err() { + return Err(franklin_circuit_params.err().unwrap()); + } + + debug!("Done reading franklin key"); + + info!("Copying states to balance tree"); + + // TODO: replace with .clone() by moving PedersenHasher to static context + let mut tree = CircuitAccountTree::new(franklin_constants::ACCOUNT_TREE_DEPTH as u32); + extend_accounts(&mut tree, initial_state.get_accounts().into_iter()); + + let root = tree.root_hash(); + + let state_block_number = initial_state.block_number; + + info!( + "Initial root hash is {} for block {}", + root, state_block_number + ); + + let supplied_root = initial_state.root_hash(); + info!("supplied_root is: {}", supplied_root); + if root != supplied_root { + return Err(BabyProverErr::Other("root did not change".to_owned())); + } + + let jubjub_params = AltJubjubBn256::new(); + + let prover_id = storage + .register_prover(&worker) + .expect("getting prover id failed"); + + Ok(Self { + operation_batch_size: franklin_constants::BLOCK_SIZE_CHUNKS, + current_block_number: state_block_number, + accounts_tree: tree, + parameters: franklin_circuit_params.unwrap(), + jubjub_params, + current_job: Arc::new(AtomicUsize::new(0)), + worker, + prover_id, + }) + } +} + +type Err = BabyProverErr; + +impl BabyProver { + fn rewind_state( + &mut self, + storage: &StorageProcessor, + expected_current_block: BlockNumber, + ) -> Result<(), String> { + info!( + "rewinding the state from block #{} to #{}", + self.current_block_number, expected_current_block + ); + let (_, new_accounts) = storage + .load_committed_state(Some(expected_current_block)) + .map_err(|e| format!("load_state_diff failed: {}", e))?; + + let mut tree = CircuitAccountTree::new(franklin_constants::ACCOUNT_TREE_DEPTH as u32); + extend_accounts(&mut tree, new_accounts.into_iter()); + + self.accounts_tree = tree; + self.current_block_number = expected_current_block; + Ok(()) + } + + fn make_proving_attempt(&mut self) -> Result<(), String> { + let storage = StorageProcessor::establish_connection() + .map_err(|e| format!("establish_connection failed: {}", e))?; + let job = storage + .fetch_prover_job(&self.worker, config::PROVER_TIMEOUT) + .map_err(|e| format!("fetch_prover_job failed: {}", e))?; + + if let Some(job) = job { + let block_number = job.block_number as BlockNumber; + info!( + "prover {} got a new job for block {}", + &self.worker, block_number + ); + self.current_job.store(job.id as usize, Ordering::Relaxed); + + // load state delta self.current_block_number => block_number (can go both forwards and backwards) + let expected_current_block = block_number - 1; + if self.current_block_number != expected_current_block { + self.rewind_state(&storage, expected_current_block)?; + } + let initial_root = self.accounts_tree.root_hash(); + + for (index, item) in &self.accounts_tree.items { + info!("index: {}, item: {}", index, item.pub_key_hash); + } + let block = storage + .load_committed_block(block_number) + .ok_or("load_committed_block failed")?; + let ops = storage.get_block_operations(block.block_number).unwrap(); + + drop(storage); + let mut operations = vec![]; + let mut pub_data = vec![]; + let mut fees = vec![]; + for op in ops { + match op { + FranklinOp::Deposit(deposit) => { + let deposit_witness = apply_deposit_tx(&mut self.accounts_tree, &deposit); + + //assert!(tree.verify_proof(sender_leaf_number, sender_leaf.clone(), tree.merkle_path(sender_leaf_number))); + let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); + let deposit_operations = calculate_deposit_operations_from_witness( + &deposit_witness, + &sig_msg, + signature, + &sender_x, + &sender_y, + ); + operations.extend(deposit_operations); + fees.push((deposit.tx.fee, deposit.tx.token)); + pub_data.extend(deposit_witness.get_pubdata()); + } + FranklinOp::Transfer(transfer) => { + let transfer_witness = + apply_transfer_tx(&mut self.accounts_tree, &transfer); + let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); + let transfer_operations = calculate_transfer_operations_from_witness( + &transfer_witness, + &sig_msg, + signature, + &sender_x, + &sender_y, + ); + operations.extend(transfer_operations); + fees.push((transfer.tx.fee, transfer.tx.token)); + pub_data.extend(transfer_witness.get_pubdata()); + } + FranklinOp::TransferToNew(transfer_to_new) => { + let transfer_to_new_witness = + apply_transfer_to_new_tx(&mut self.accounts_tree, &transfer_to_new); + let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); + let transfer_to_new_operations = + calculate_transfer_to_new_operations_from_witness( + &transfer_to_new_witness, + &sig_msg, + signature, + &sender_x, + &sender_y, + ); + operations.extend(transfer_to_new_operations); + fees.push((transfer_to_new.tx.fee, transfer_to_new.tx.token)); + pub_data.extend(transfer_to_new_witness.get_pubdata()); + } + FranklinOp::PartialExit(partial_exit) => { + let partial_exit_witness = + apply_partial_exit_tx(&mut self.accounts_tree, &partial_exit); + let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); + let partial_exit_operations = + calculate_partial_exit_operations_from_witness( + &partial_exit_witness, + &sig_msg, + signature, + &sender_x, + &sender_y, + ); + operations.extend(partial_exit_operations); + fees.push((partial_exit.tx.fee, partial_exit.tx.token)); + pub_data.extend(partial_exit_witness.get_pubdata()); + } + FranklinOp::Close(close) => { + let close_account_witness = + apply_close_account_tx(&mut self.accounts_tree, &close); + let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); + let close_account_operations = + calculate_close_account_operations_from_witness( + &close_account_witness, + &sig_msg, + signature, + &sender_x, + &sender_y, + ); + operations.extend(close_account_operations); + pub_data.extend(close_account_witness.get_pubdata()); + } + } + } + if operations.len() < franklin_constants::BLOCK_SIZE_CHUNKS { + for _ in 0..franklin_constants::BLOCK_SIZE_CHUNKS - operations.len() { + let (signature, sig_msg, sender_x, sender_y) = generate_dummy_sig_data(); + operations.push(noop_operation( + &self.accounts_tree, + block.fee_account, + &sig_msg, + signature, + &sender_x, + &sender_y, + )); + pub_data.extend(vec![false; 64]); + } + } + assert_eq!(pub_data.len(), 64 * 10); + assert_eq!(operations.len(), 10); + + let validator_acc = self + .accounts_tree + .get(block.fee_account as u32) + .expect("fee_account is not empty"); + let mut validator_balances = vec![]; + for i in 0..1 << franklin_constants::BALANCE_TREE_DEPTH { + // validator_balances.push(Some(validator_acc.subtree.get(i as u32).map(|s| s.clone()).unwrap_or(Balance::default()))); + let balance_value = match validator_acc.subtree.get(i as u32) { + None => Fr::zero(), + Some(bal) => bal.value, + }; + validator_balances.push(Some(balance_value)); + } + let mut root_after_fee: Fr = self.accounts_tree.root_hash(); + let mut validator_account_witness: AccountWitness = AccountWitness { + nonce: None, + pub_key_hash: None, + }; + for (fee, token) in fees { + info!("fee, token: {}, {}", fee, token); + let (root, acc_witness) = apply_fee( + &mut self.accounts_tree, + block.fee_account, + u32::from(token), + fee.to_u128().unwrap(), + ); + root_after_fee = root; + validator_account_witness = acc_witness; + } + + info!("root after fees {}", root_after_fee); + info!("block new hash {}", block.new_root_hash); + assert_eq!(root_after_fee, block.new_root_hash); + let (validator_audit_path, _) = + get_audits(&self.accounts_tree, block.fee_account as u32, 0); + + info!("Data for public commitment. pub_data: {:x?}, initial_root: {}, final_root: {}, validator_address: {}, block_number: {}", + pack_bits_into_bytes_in_order(pub_data.clone()), initial_root, root_after_fee, Fr::from_str(&block.fee_account.to_string()).unwrap(), Fr::from_str(&(block_number + 1).to_string()).unwrap() + ); + let public_data_commitment = public_data_commitment::( + &pub_data, + Some(initial_root), + Some(root_after_fee), + Some(Fr::from_str(&block.fee_account.to_string()).unwrap()), + Some(Fr::from_str(&(block_number).to_string()).unwrap()), + ); + + let instance = FranklinCircuit { + params: &self.jubjub_params, + operation_batch_size: franklin_constants::BLOCK_SIZE_CHUNKS, + old_root: Some(initial_root), + new_root: Some(block.new_root_hash), + block_number: Fr::from_str(&(block_number).to_string()), + validator_address: Some(Fr::from_str(&block.fee_account.to_string()).unwrap()), + pub_data_commitment: Some(public_data_commitment), + operations: operations.clone(), + validator_balances: validator_balances.clone(), + validator_audit_path: validator_audit_path.clone(), + validator_account: validator_account_witness.clone(), + }; + + // { + // let inst = FranklinCircuit { + // params: &self.jubjub_params, + // operation_batch_size: franklin_constants::BLOCK_SIZE_CHUNKS, + // old_root: Some(initial_root), + // new_root: Some(block.new_root_hash), + // block_number: Fr::from_str(&(block_number + 1).to_string()), + // validator_address: Some(Fr::from_str(&block.fee_account.to_string()).unwrap()), + // pub_data_commitment: Some(public_data_commitment.clone()), + // operations: operations, + // validator_balances: validator_balances, + // validator_audit_path: validator_audit_path, + // validator_account: validator_account_witness, + // }; + // let mut cs = TestConstraintSystem::::new(); + // inst.synthesize(&mut cs).unwrap(); + + // warn!("unconstrained {}\n", cs.find_unconstrained()); + // warn!("inputs {}\n", cs.num_inputs()); + // warn!("num_constraints: {}\n", cs.num_constraints()); + // warn!("is satisfied: {}\n", cs.is_satisfied()); + // warn!("which is unsatisfied: {:?}\n", cs.which_is_unsatisfied()); + // } + + let mut rng = OsRng::new().unwrap(); + info!("Prover has started to work"); + // let tmp_cirtuit_params = generate_random_parameters(instance, &mut rng).unwrap(); + let proof = create_random_proof(instance, &self.parameters, &mut rng); + if proof.is_err() { + error!("proof can not be created: {}", proof.err().unwrap()); + return Err("proof can not be created".to_owned()); + // return Err(BabyProverErr::Other("proof.is_err()".to_owned())); + } + let p = proof.unwrap(); + + let pvk = prepare_verifying_key(&self.parameters.vk); + + info!( + "Made a proof for initial root = {}, final root = {}, public_data_commitment = {}", + initial_root, + root_after_fee, + public_data_commitment.to_hex() + ); + let success = verify_proof(&pvk, &p.clone(), &[public_data_commitment]); + if success.is_err() { + error!( + "Proof is verification failed with error {}", + success.err().unwrap() + ); + return Err("Proof verification has failed".to_owned()); + // return Err(BabyProverErr::Other( + // "Proof is verification failed".to_owned(), + // )); + } + if !success.unwrap() { + error!("Proof is invalid"); + return Err("Proof is invalid".to_owned()); + // return Err(BabyProverErr::Other("Proof is invalid".to_owned())); + } + + info!("Proof generation is complete"); + + let full_proof = FullBabyProof { + proof: p, + inputs: [public_data_commitment], + // public_data: pub_data, + public_data: vec![0 as u8; 10], + }; + + // Ok(full_proof) + + let encoded = Self::encode_proof(&full_proof).expect("proof encoding failed"); + let storage = StorageProcessor::establish_connection() + .map_err(|e| format!("establish_connection failed: {}", e))?; + storage + .store_proof(block_number, &encoded) + .map_err(|e| format!("store_proof failed: {}", e))?; + } else { + thread::sleep(Duration::from_secs(config::PROVER_CYCLE_WAIT)); + } + Ok(()) + } + + pub fn start_timer_interval(&self, rt: &Handle) { + let job_ref = self.current_job.clone(); + rt.spawn( + timer::Interval::new_interval(Duration::from_secs(config::PROVER_TIMER_TICK)) + .fold(job_ref, |job_ref, _| { + let job = job_ref.load(Ordering::Relaxed); + if job > 0 { + //debug!("prover is working on block {}", job); + if let Ok(storage) = StorageProcessor::establish_connection() { + let _ = storage.update_prover_job(job as i32); + } + } + Ok(job_ref) + }) + .map(|_| ()) + .map_err(|_| ()), + ) + .unwrap(); + } + + pub fn run(&mut self, shutdown_tx: Sender<()>, stop_signal: Arc) { + info!("prover is running"); + while !stop_signal.load(Ordering::SeqCst) { + if let Err(err) = self.make_proving_attempt() { + error!("Error: {}", err); + } + self.current_job.store(0, Ordering::Relaxed); + } + info!("prover stopped"); + shutdown_tx.send(()).unwrap(); + } +} diff --git a/core/prover/src/main.rs b/core/prover/src/main.rs index ccc709d548..7f6c3d6b39 100644 --- a/core/prover/src/main.rs +++ b/core/prover/src/main.rs @@ -1,59 +1,57 @@ -//#[macro_use] -//extern crate log; -// -//use prover::BabyProver; -//use signal_hook::iterator::Signals; -//use std::env; -//use std::sync::{atomic::AtomicBool, Arc}; -//use std::thread; -//use storage::StorageProcessor; -//use tokio::runtime::current_thread::Runtime; -//use tokio::sync::oneshot; -// -//fn main() { -// env_logger::init(); -// -// // handle ctrl+c -// let stop_signal = Arc::new(AtomicBool::new(false)); -// signal_hook::flag::register(signal_hook::SIGTERM, Arc::clone(&stop_signal)) -// .expect("Error setting SIGTERM handler"); -// signal_hook::flag::register(signal_hook::SIGINT, Arc::clone(&stop_signal)) -// .expect("Error setting SIGINT handler"); -// signal_hook::flag::register(signal_hook::SIGQUIT, Arc::clone(&stop_signal)) -// .expect("Error setting SIGQUIT handler"); -// -// let worker = env::var("POD_NAME").unwrap_or_else(|_| "default".to_string()); -// info!("creating prover, worker: {}", worker); -// let mut prover = BabyProver::create(worker).unwrap(); -// let prover_id = prover.prover_id; -// -// let mut rt = Runtime::new().unwrap(); -// let (shutdown_tx, shutdown_rx) = oneshot::channel(); -// prover.start_timer_interval(&rt.handle()); -// -// // Run tokio timeline in a new thread -// thread::spawn(move || { -// prover.run(shutdown_tx, stop_signal); -// }); -// -// let signals = Signals::new(&[ -// signal_hook::SIGTERM, -// signal_hook::SIGINT, -// signal_hook::SIGQUIT, -// ]) -// .expect("Signals::new() failed"); -// thread::spawn(move || { -// for _ in signals.forever() { -// info!( -// "Termination signal received. Prover will finish the job and shut down gracefully" -// ); -// let storage = -// StorageProcessor::establish_connection().expect("db connection failed for prover"); -// storage.record_prover_stop(prover_id).expect("db failed"); -// } -// }); -// -// rt.block_on(shutdown_rx).unwrap(); -//} - -fn main() {} +#[macro_use] +extern crate log; + +use prover::BabyProver; +use signal_hook::iterator::Signals; +use std::env; +use std::sync::{atomic::AtomicBool, Arc}; +use std::thread; +use storage::StorageProcessor; +use tokio::runtime::current_thread::Runtime; +use tokio::sync::oneshot; + +fn main() { + env_logger::init(); + + // handle ctrl+c + let stop_signal = Arc::new(AtomicBool::new(false)); + signal_hook::flag::register(signal_hook::SIGTERM, Arc::clone(&stop_signal)) + .expect("Error setting SIGTERM handler"); + signal_hook::flag::register(signal_hook::SIGINT, Arc::clone(&stop_signal)) + .expect("Error setting SIGINT handler"); + signal_hook::flag::register(signal_hook::SIGQUIT, Arc::clone(&stop_signal)) + .expect("Error setting SIGQUIT handler"); + + let worker = env::var("POD_NAME").unwrap_or_else(|_| "default".to_string()); + info!("creating prover, worker: {}", worker); + let mut prover = BabyProver::create(worker).unwrap(); + let prover_id = prover.prover_id; + + let mut rt = Runtime::new().unwrap(); + let (shutdown_tx, shutdown_rx) = oneshot::channel(); + prover.start_timer_interval(&rt.handle()); + + // Run tokio timeline in a new thread + thread::spawn(move || { + prover.run(shutdown_tx, stop_signal); + }); + + let signals = Signals::new(&[ + signal_hook::SIGTERM, + signal_hook::SIGINT, + signal_hook::SIGQUIT, + ]) + .expect("Signals::new() failed"); + thread::spawn(move || { + for _ in signals.forever() { + info!( + "Termination signal received. Prover will finish the job and shut down gracefully" + ); + let storage = + StorageProcessor::establish_connection().expect("db connection failed for prover"); + storage.record_prover_stop(prover_id).expect("db failed"); + } + }); + + rt.block_on(shutdown_rx).unwrap(); +} diff --git a/core/server/Cargo.toml b/core/server/Cargo.toml index 1ddde97a5f..2d56d0240d 100644 --- a/core/server/Cargo.toml +++ b/core/server/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] eth_client = { path = "../eth_client" } plasma = { path = "../plasma" } -models = { package = "franklinmodels", path = "../franklinmodels" } +models = { package = "models", path = "../models" } storage = { path = "../storage" } ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } diff --git a/core/server/src/api_server.rs b/core/server/src/api_server.rs index e8435bc053..c478863fe9 100644 --- a/core/server/src/api_server.rs +++ b/core/server/src/api_server.rs @@ -221,9 +221,7 @@ fn handle_get_tokens(req: &HttpRequest) -> ActixResult { fn handle_get_testnet_config(req: &HttpRequest) -> ActixResult { let address = req.state().contract_address.clone(); - Ok(HttpResponse::Ok().json(TestnetConfigResponse { - address: format!("{}", address), - })) + Ok(HttpResponse::Ok().json(TestnetConfigResponse { address })) } // fn handle_get_network_status(req: &HttpRequest) -> ActixResult { @@ -473,7 +471,9 @@ fn handle_get_block_transactions(req: &HttpRequest) -> ActixResult, //} -fn handle_search(req: &HttpRequest) -> Box> { +fn handle_search( + req: &HttpRequest, +) -> Box> { let pool = req.state().connection_pool.clone(); let query = req.query().get("query").cloned().unwrap_or_default(); req.body() diff --git a/core/server/src/eth_watch.rs b/core/server/src/eth_watch.rs index 9804f36ba1..d27c98cea3 100644 --- a/core/server/src/eth_watch.rs +++ b/core/server/src/eth_watch.rs @@ -37,8 +37,8 @@ impl LockedBalance { fn from_event(event: OnchainDepositEvent, current_block: u64) -> Self { Self { amount: event.amount, - locked_until_block: event.locked_until_block as u64, - blocks_left_until_unlock: (event.locked_until_block as u64) + locked_until_block: u64::from(event.locked_until_block), + blocks_left_until_unlock: u64::from(event.locked_until_block) .saturating_sub(current_block), eth_address: event.address, } @@ -139,6 +139,11 @@ impl TryFrom for OnchainDepositEvent { }) } } +impl Default for EthWatch { + fn default() -> Self { + Self::new() + } +} impl EthWatch { pub fn new() -> Self { @@ -291,7 +296,7 @@ impl EthWatch { let res: Result<(U256, U256), _> = contract .query( "balances", - (Token::Address(v.eth_address), token as u64), + (Token::Address(v.eth_address), u64::from(token)), None, Default::default(), Some(BlockNumber::Number(last_block)), diff --git a/core/storage/Cargo.toml b/core/storage/Cargo.toml index bd6834f442..caac4ec52d 100644 --- a/core/storage/Cargo.toml +++ b/core/storage/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.1" edition = "2018" [dependencies] -models = { package = "franklinmodels", path = "../franklinmodels" } +models = { package = "models", path = "../models" } fnv = "1.0.6" serde = "1.0.90" serde_derive = "1.0.90" diff --git a/core/storage/src/lib.rs b/core/storage/src/lib.rs index b1d9c95d48..d549e02934 100644 --- a/core/storage/src/lib.rs +++ b/core/storage/src/lib.rs @@ -152,7 +152,7 @@ struct StoredExecutedTransaction { impl NewExecutedTransaction { fn prepare_stored_tx(exec_tx: &ExecutedTx, block: BlockNumber) -> Self { Self { - block_number: block as i64, + block_number: i64::from(block), tx_hash: exec_tx.tx.hash(), operation: exec_tx.op.clone().map(|o| serde_json::to_value(o).unwrap()), success: exec_tx.success, @@ -533,7 +533,7 @@ impl StorageProcessor { // see SQL migration code for `operations` table let stored: StoredOperation = diesel::insert_into(operations::table) .values(&NewOperation { - block_number: op.block.block_number as i64, + block_number: i64::from(op.block.block_number), action_type: op.action.to_string(), data: serde_json::to_value(&op).unwrap(), }) @@ -563,7 +563,7 @@ impl StorageProcessor { pub fn get_block_operations(&self, block: BlockNumber) -> QueryResult> { let executed_txs: Vec<_> = executed_transactions::table - .filter(executed_transactions::block_number.eq(block as i64)) + .filter(executed_transactions::block_number.eq(i64::from(block))) .load::(self.conn())?; Ok(executed_txs .into_iter() @@ -590,9 +590,9 @@ impl StorageProcessor { AccountUpdate::Create { ref address, nonce } => { diesel::insert_into(account_creates::table) .values(&StorageAccountCreation { - account_id: *id as i64, + account_id: i64::from(*id), is_create: true, - block_number: block_number as i64, + block_number: i64::from(block_number), address: address.data.to_vec(), nonce: i64::from(nonce), }) @@ -601,9 +601,9 @@ impl StorageProcessor { AccountUpdate::Delete { ref address, nonce } => { diesel::insert_into(account_creates::table) .values(&StorageAccountCreation { - account_id: *id as i64, + account_id: i64::from(*id), is_create: false, - block_number: block_number as i64, + block_number: i64::from(block_number), address: address.data.to_vec(), nonce: i64::from(nonce), }) @@ -616,9 +616,9 @@ impl StorageProcessor { } => { diesel::insert_into(account_balance_updates::table) .values(&StorageAccountUpdateInsert { - account_id: *id as i64, - block_number: block_number as i64, - coin_id: token as i32, + account_id: i64::from(*id), + block_number: i64::from(block_number), + coin_id: i32::from(token), old_balance: old_balance.clone(), new_balance: new_balance.clone(), old_nonce: i64::from(old_nonce), @@ -636,11 +636,11 @@ impl StorageProcessor { info!("Applying state update for block: {}", block_number); self.conn().transaction(|| { let account_balance_diff = account_balance_updates::table - .filter(account_balance_updates::block_number.eq(&(block_number as i64))) + .filter(account_balance_updates::block_number.eq(&(i64::from(block_number)))) .load::(self.conn())?; let account_creation_diff = account_creates::table - .filter(account_creates::block_number.eq(&(block_number as i64))) + .filter(account_creates::block_number.eq(&(i64::from(block_number)))) .load::(self.conn())?; let account_updates: Vec = { @@ -778,21 +778,23 @@ impl StorageProcessor { let account_balance_diff = account_balance_updates::table .filter( account_balance_updates::block_number - .gt(&(start_block as i64)) + .gt(&(i64::from(start_block))) .and( account_balance_updates::block_number - .le(&(end_block as i64)) + .le(&(i64::from(end_block))) .or(unbounded), ), ) .load::(self.conn())?; let account_creation_diff = account_creates::table .filter( - account_creates::block_number.gt(&(start_block as i64)).and( - account_creates::block_number - .le(&(end_block as i64)) - .or(unbounded), - ), + account_creates::block_number + .gt(&(i64::from(start_block))) + .and( + account_creates::block_number + .le(&(i64::from(end_block))) + .or(unbounded), + ), ) .load::(self.conn())?; @@ -868,7 +870,7 @@ impl StorageProcessor { ) t ) s", addr = sender, - current_nonce = current_nonce as i64 + current_nonce = i64::from(current_nonce) ) .as_str(), ) @@ -883,7 +885,7 @@ impl StorageProcessor { ) -> Option { use crate::schema::operations::dsl; dsl::operations - .filter(dsl::block_number.eq(block_number as i64)) + .filter(dsl::block_number.eq(i64::from(block_number))) .filter(dsl::action_type.eq(action_type.to_string().as_str())) .get_result(self.conn()) .ok() @@ -920,8 +922,8 @@ impl StorageProcessor { and action_type = 'Verify' order by committed.block_number desc ", - max_block = max_block as i64, - limit = limit as i64 + max_block = i64::from(max_block), + limit = i64::from(limit) ); diesel::sql_query(query).load(self.conn()) } @@ -965,7 +967,7 @@ impl StorageProcessor { order by committed.block_number desc limit 1 ", - block_number = block_number as i64 + block_number = block_number ); diesel::sql_query(sql_query) .bind::(query_with_prefix) @@ -1000,7 +1002,7 @@ impl StorageProcessor { use crate::schema::operations::dsl; self.conn().transaction(|| { let ops: Vec = dsl::operations - .filter(dsl::nonce.ge(current_nonce as i64)) // WHERE nonce >= current_nonce + .filter(dsl::nonce.ge(i64::from(current_nonce))) // WHERE nonce >= current_nonce .load(self.conn())?; ops.into_iter().map(|o| o.into_op(self)).collect() }) @@ -1066,7 +1068,7 @@ impl StorageProcessor { ) -> QueryResult<(i64, Option)> { self.conn().transaction(|| { if let Some(account) = accounts::table - .find(account_id as i64) + .find(i64::from(account_id)) .first::(self.conn()) .optional()? { @@ -1114,14 +1116,14 @@ impl StorageProcessor { let account_balance_diff: Vec = { account_balance_updates::table - .filter(account_balance_updates::account_id.eq(&(account_id as i64))) + .filter(account_balance_updates::account_id.eq(&(i64::from(account_id)))) .filter(account_balance_updates::block_number.gt(&last_block)) .load::(self.conn())? }; let account_creation_diff: Vec = { account_creates::table - .filter(account_creates::account_id.eq(&(account_id as i64))) + .filter(account_creates::account_id.eq(&(i64::from(account_id)))) .filter(account_creates::block_number.gt(&last_block)) .load::(self.conn())? }; @@ -1163,7 +1165,7 @@ impl StorageProcessor { pub fn count_outstanding_proofs(&self, after_block: BlockNumber) -> QueryResult { use crate::schema::executed_transactions::dsl::*; let count: i64 = executed_transactions - .filter(block_number.gt(after_block as i64)) + .filter(block_number.gt(i64::from(after_block))) .select(count_star()) .first(self.conn())?; Ok(count as u32) @@ -1234,13 +1236,13 @@ impl StorageProcessor { .map(|i| i.integer_value as BlockNumber); if let Some(block_number_) = job { // let to_store = NewProverRun{ - // block_number: block_number as i64, + // block_number: i64::from(block_number), // worker: worker.to_string(), // }; use crate::schema::prover_runs::dsl::*; let inserted: ProverRun = insert_into(prover_runs) .values(&vec![( - block_number.eq(block_number_ as i64), + block_number.eq(i64::from(block_number_) ), worker.eq(worker_.to_string()) )]) .get_result(self.conn())?; @@ -1286,7 +1288,7 @@ impl StorageProcessor { proof: &EncodedProof, ) -> QueryResult { let to_store = NewProof { - block_number: block_number as i64, + block_number: i64::from(block_number), proof: serde_json::to_value(proof).unwrap(), }; use crate::schema::proofs::dsl::proofs; @@ -1296,14 +1298,14 @@ impl StorageProcessor { pub fn load_proof(&self, block_number: BlockNumber) -> QueryResult { use crate::schema::proofs::dsl; let stored: StoredProof = dsl::proofs - .filter(dsl::block_number.eq(block_number as i64)) + .filter(dsl::block_number.eq(i64::from(block_number))) .get_result(self.conn())?; Ok(serde_json::from_value(stored.proof).unwrap()) } pub fn store_token(&self, id: TokenId, address: &str, symbol: Option<&str>) -> QueryResult<()> { let new_token = Token { - id: id as i32, + id: i32::from(id), address: address.to_string(), symbol: symbol.map(String::from), }; @@ -1367,7 +1369,9 @@ impl StorageProcessor { pub fn get_pending_txs(&self, address: &AccountAddress) -> QueryResult> { let (_, _, commited_state) = self.account_state_by_address(address)?; - let commited_nonce = commited_state.map(|a| a.nonce as i64).unwrap_or_default(); + let commited_nonce = commited_state + .map(|a| i64::from(a.nonce)) + .unwrap_or_default(); let pending_txs: Vec<_> = mempool::table .filter(mempool::primary_account_address.eq(address.data.to_vec())) diff --git a/etc/env/dev.env.example b/etc/env/dev.env.example index 8f847214cf..ef95c6b057 100755 --- a/etc/env/dev.env.example +++ b/etc/env/dev.env.example @@ -68,4 +68,4 @@ TREE_RESTORE_RINKEBY_CONTRACT_ADDR=4fbf331db438c88a83b1316d072b7d73d8366367 TREE_RESTORE_MAINNET_ENDPOINT=https://mainnet.infura.io/ TREE_RESTORE_MAINNET_CONTRACT_ADDR=4a89f998dce2453e96b795d47603c4b5a16144b0 -RUST_LOG=server=debug,prover=debug,plasma=info,eth_client=info,data_restore=info,franklin_prover=debug,dummy_prover=info,franklin_key_generator=info +RUST_LOG=server=debug,prover=debug,plasma=info,eth_client=info,data_restore=info,prover=debug,dummy_prover=info,key_generator=info From df9b5a5a836a3e8084c97e1bf52ccd3373f39e66 Mon Sep 17 00:00:00 2001 From: TymurKhrushchov Date: Fri, 30 Aug 2019 10:51:08 +0300 Subject: [PATCH 5/5] review fixes --- core/circuit/Cargo.toml | 2 +- core/circuit/clippy.toml | 1 + core/circuit/src/witness/close_account.rs | 6 +----- core/data_restore/Cargo.toml | 4 ++-- core/eth_client/Cargo.toml | 2 +- core/key_generator/Cargo.toml | 4 ++-- core/key_generator/src/vk_contract_generator.rs | 9 --------- core/plasma/Cargo.toml | 2 +- core/prover/Cargo.toml | 8 ++++---- clippy.toml => core/prover/clippy.toml | 1 - core/server/Cargo.toml | 8 ++++---- core/storage/Cargo.toml | 3 ++- 12 files changed, 19 insertions(+), 31 deletions(-) create mode 100644 core/circuit/clippy.toml rename clippy.toml => core/prover/clippy.toml (50%) diff --git a/core/circuit/Cargo.toml b/core/circuit/Cargo.toml index 78cf1ff822..737a277010 100644 --- a/core/circuit/Cargo.toml +++ b/core/circuit/Cargo.toml @@ -9,7 +9,7 @@ authors = [ ] [dependencies] -models = { path = "../models" } +models = { path = "../models", version = "0.0.1" } pairing = { package = "pairing_ce", version = "0.17.0" } bellman = { package = "bellman_ce", version = "0.3.0" } franklin_crypto = { package = "franklin-crypto", git = "ssh://git@github.com/matter-labs/franklin-crypto.git", branch="master"} diff --git a/core/circuit/clippy.toml b/core/circuit/clippy.toml new file mode 100644 index 0000000000..ddd33ae016 --- /dev/null +++ b/core/circuit/clippy.toml @@ -0,0 +1 @@ +too-many-arguments-threshold = 12 diff --git a/core/circuit/src/witness/close_account.rs b/core/circuit/src/witness/close_account.rs index 1aeb1147c9..da0be2ec8e 100644 --- a/core/circuit/src/witness/close_account.rs +++ b/core/circuit/src/witness/close_account.rs @@ -189,8 +189,7 @@ mod test { let sender_leaf = CircuitAccount:: { subtree: CircuitBalanceTree::new(franklin_constants::BALANCE_TREE_DEPTH as u32), nonce: Fr::zero(), - pub_key_hash: sender_pub_key_hash, // pub_x: validator_x.clone(), - // pub_y: validator_y.clone(), + pub_key_hash: sender_pub_key_hash, }; println!("zero root_hash equals: {}", sender_leaf.subtree.root_hash()); @@ -223,9 +222,7 @@ mod test { sig_bits.reverse(); sig_bits.truncate(80); - // println!(" capacity {}",::Fs::Capacity); let signature = sign(&sig_bits, &sender_sk, p_g, params, rng); - //assert!(tree.verify_proof(sender_leaf_number, sender_leaf.clone(), tree.merkle_path(sender_leaf_number))); let operations = calculate_close_account_operations_from_witness( &close_account_witness, @@ -276,7 +273,6 @@ mod test { if err.is_some() { panic!("ERROR satisfying in {}", err.unwrap()); } - // assert_eq!(cs.num_constraints(), 1) } } diff --git a/core/data_restore/Cargo.toml b/core/data_restore/Cargo.toml index 509829dbeb..fc1dbebaa7 100644 --- a/core/data_restore/Cargo.toml +++ b/core/data_restore/Cargo.toml @@ -17,5 +17,5 @@ tokio = "0.1" bitvec = "0.11" log = "0.4" -plasma = { path = "../plasma" } -models = { path = "../models" } +plasma = { path = "../plasma", version = "0.1.1" } +models = { path = "../models", version = "0.0.1" } diff --git a/core/eth_client/Cargo.toml b/core/eth_client/Cargo.toml index a3c441732e..c7d588fe2b 100644 --- a/core/eth_client/Cargo.toml +++ b/core/eth_client/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [dependencies] -models = { package = "models", path = "../models" } +models = { path = "../models", version = "0.0.1" } serde = "1.0.90" serde_derive = "1.0.90" ethereum-types = "0.4.0" diff --git a/core/key_generator/Cargo.toml b/core/key_generator/Cargo.toml index b481453dbe..f0cffb7589 100644 --- a/core/key_generator/Cargo.toml +++ b/core/key_generator/Cargo.toml @@ -14,8 +14,8 @@ time = "0.1" pairing = { package = "pairing_ce", version = "0.17.0" } franklin_crypto = { package = "franklin-crypto", git = "ssh://git@github.com/matter-labs/franklin-crypto.git"} bellman = { package = "bellman_ce", version = "0.3.0" } -models = { path = "../models" } -circuit= { path = "../circuit" } +models = { path = "../models", version = "0.0.1" } +circuit= { path = "../circuit", version = "0.1.1" } hex = "0.3.2" rust-crypto = "0.2" ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } diff --git a/core/key_generator/src/vk_contract_generator.rs b/core/key_generator/src/vk_contract_generator.rs index 93920b0a2c..6a9ba49e84 100644 --- a/core/key_generator/src/vk_contract_generator.rs +++ b/core/key_generator/src/vk_contract_generator.rs @@ -3,11 +3,6 @@ use bellman::groth16; use pairing::{CurveAffine, Engine}; -// fn unpack(t: &T) -> Vec -// { -// t.into_uncompressed().as_ref().chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect() -// } - fn unpack_g1(point: &E::G1Affine) -> Vec { let uncompressed = point.into_uncompressed(); let uncompressed_slice = uncompressed.as_ref(); @@ -25,10 +20,6 @@ fn unpack_g2(point: &E::G2Affine) -> Vec { .chunks(32) .map(|c| "0x".to_owned() + &hex::encode(c)) .collect() - - // let to_reorder: Vec = uncompressed_slice.chunks(32).map(|c| "0x".to_owned() + &hex::encode(c)).collect(); - - // vec![to_reorder[1].clone(), to_reorder[0].clone(), to_reorder[3].clone(), to_reorder[2].clone()] } const SHIFT: &str = " "; diff --git a/core/plasma/Cargo.toml b/core/plasma/Cargo.toml index d74d8057a9..aaea7622de 100644 --- a/core/plasma/Cargo.toml +++ b/core/plasma/Cargo.toml @@ -9,7 +9,7 @@ authors = [ ] [dependencies] -models = { package = "models", path = "../models" } +models = { path = "../models", version = "0.0.1" } bigdecimal = { version = "0.0.14", features = ["serde"]} log = "0.4" failure = "0.1" diff --git a/core/prover/Cargo.toml b/core/prover/Cargo.toml index 02fd7be423..82a99bf87d 100644 --- a/core/prover/Cargo.toml +++ b/core/prover/Cargo.toml @@ -4,10 +4,10 @@ version = "0.0.1" edition = "2018" [dependencies] -plasma = { path = "../plasma" } -models = { package = "models", path = "../models" } -storage = { path = "../storage" } -circuit = { package = "circuit", path = "../circuit"} +plasma = { path = "../plasma", version = "0.1.1" } +models = { path = "../models", version = "0.0.1" } +storage = { path = "../storage", version = "0.0.1" } +circuit = { path = "../circuit", version = "0.1.1"} ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } pairing = { package = "pairing_ce", version = "0.17.0" } diff --git a/clippy.toml b/core/prover/clippy.toml similarity index 50% rename from clippy.toml rename to core/prover/clippy.toml index aa09258fc3..08933bddaf 100644 --- a/clippy.toml +++ b/core/prover/clippy.toml @@ -1,2 +1 @@ -too-many-arguments-threshold = 12 cognitive-complexity-threshold = 30 \ No newline at end of file diff --git a/core/server/Cargo.toml b/core/server/Cargo.toml index 2d56d0240d..444f359ecd 100644 --- a/core/server/Cargo.toml +++ b/core/server/Cargo.toml @@ -4,10 +4,10 @@ version = "0.0.1" edition = "2018" [dependencies] -eth_client = { path = "../eth_client" } -plasma = { path = "../plasma" } -models = { package = "models", path = "../models" } -storage = { path = "../storage" } +eth_client = { path = "../eth_client", version = "0.1.0" } +plasma = { path = "../plasma", version = "0.1.1" } +models = { path = "../models", version = "0.0.1" } +storage = { path = "../storage", version = "0.0.1" } ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] } pairing = { package = "pairing_ce", version = "0.17.0" } diff --git a/core/storage/Cargo.toml b/core/storage/Cargo.toml index caac4ec52d..a7ccb750ef 100644 --- a/core/storage/Cargo.toml +++ b/core/storage/Cargo.toml @@ -4,7 +4,8 @@ version = "0.0.1" edition = "2018" [dependencies] -models = { package = "models", path = "../models" } +models = { path = "../models", version = "0.0.1" } + fnv = "1.0.6" serde = "1.0.90" serde_derive = "1.0.90"