diff --git a/.gitignore b/.gitignore index 6ba28372..183e0662 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/target/* **/*.rs.bk +phase1_final transcript challenge* response* diff --git a/Cargo.lock b/Cargo.lock index 3132a83e..032825e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,7 +36,7 @@ dependencies = [ "rpassword", "rust-embed", "scrypt", - "sha2", + "sha2 0.9.8", "subtle", "which", "wsl", @@ -57,7 +57,7 @@ dependencies = [ "nom", "rand 0.8.4", "secrecy", - "sha2", + "sha2 0.9.8", "tempfile", ] @@ -81,6 +81,58 @@ dependencies = [ "memchr", ] +[[package]] +name = "aleo-std" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "064ec11ce34a1748bbbae0fd9111e6cdcb2aa9eae714852da81eaa7cf864fc72" +dependencies = [ + "aleo-std-storage", + "aleo-std-time", + "aleo-std-timed", + "aleo-std-timer", +] + +[[package]] +name = "aleo-std-storage" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "503e2538d5158b869bc9c30c9754f9a23f4210987008014a9f118db99f22c217" +dependencies = [ + "dirs", +] + +[[package]] +name = "aleo-std-time" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7065e071b26763f3e5b1b5a587828227562365bee84fdd2629361ea0a08bfc8d" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "aleo-std-timed" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b85aed1b7ca965b6613d14ab243c746316180401cbb9ba3b2cb22bff16fc08f" +dependencies = [ + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", +] + +[[package]] +name = "aleo-std-timer" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23bed34621f0713d3e750b59acdd3961a8950650fa7615b7cb40e6bc062a1d0b" +dependencies = [ + "colored", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -101,9 +153,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.48" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62e1f47f7dc0422027a4e370dd4548d4d66b26782e513e98dca1e689e058a80e" +checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3" [[package]] name = "arrayref" @@ -117,6 +169,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "atty" version = "0.2.14" @@ -136,9 +194,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "base58" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" +checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" [[package]] name = "base64" @@ -174,7 +232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" dependencies = [ "crypto-mac 0.8.0", - "digest", + "digest 0.9.0", "opaque-debug", ] @@ -185,7 +243,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e461a7034e85b211a4acb57ee2e6730b32912b06c08cc242243c39fc21ae6a2" dependencies = [ "arrayref", - "arrayvec", + "arrayvec 0.5.2", + "constant_time_eq", +] + +[[package]] +name = "blake2s_simd" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" +dependencies = [ + "arrayref", + "arrayvec 0.7.2", "constant_time_eq", ] @@ -204,6 +273,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" +dependencies = [ + "generic-array", +] + [[package]] name = "bstr" version = "0.2.17" @@ -327,6 +405,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + [[package]] name = "console" version = "0.15.0" @@ -499,6 +588,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-common" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" +dependencies = [ + "generic-array", +] + [[package]] name = "crypto-mac" version = "0.8.0" @@ -588,7 +686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", - "digest", + "digest 0.9.0", "rand_core 0.5.1", "subtle", "zeroize", @@ -622,10 +720,10 @@ checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" dependencies = [ "fnv", "ident_case", - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", "strsim 0.9.3", - "syn", + "syn 1.0.82", ] [[package]] @@ -636,10 +734,10 @@ checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" dependencies = [ "fnv", "ident_case", - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", "strsim 0.10.0", - "syn", + "syn 1.0.82", ] [[package]] @@ -649,8 +747,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core 0.10.2", - "quote", - "syn", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -660,8 +758,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" dependencies = [ "darling_core 0.13.0", - "quote", - "syn", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -680,9 +778,9 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -692,10 +790,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" dependencies = [ "convert_case", - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", "rustc_version 0.3.3", - "syn", + "syn 1.0.82", ] [[package]] @@ -719,6 +817,37 @@ dependencies = [ "generic-array", ] +[[package]] +name = "digest" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" +dependencies = [ + "block-buffer 0.10.0", + "crypto-common", + "generic-array", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "egg-mode" version = "0.16.0" @@ -927,9 +1056,9 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89f17b21645bc4ed773c69af9c9a0effd4a3f1a3876eadd453469f8854e7fdd" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -1042,9 +1171,9 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "915ef07c710d84733522461de2a734d4d62a3fd39a4d4f404c2f385ef8618d05" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -1117,7 +1246,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01706d578d5c281058480e673ae4086a9f4710d8df1ad80a5b03e39ece5f886b" dependencies = [ - "digest", + "digest 0.9.0", "hmac", ] @@ -1128,7 +1257,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" dependencies = [ "crypto-mac 0.11.1", - "digest", + "digest 0.9.0", ] [[package]] @@ -1251,10 +1380,10 @@ dependencies = [ "i18n-embed", "lazy_static", "proc-macro-error", - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", "strsim 0.10.0", - "syn", + "syn 1.0.82", "unic-langid", ] @@ -1266,9 +1395,9 @@ checksum = "0db2330e035808eb064afb67e6743ddce353763af3e0f2bdfc2476e00ce76136" dependencies = [ "find-crate", "i18n-config", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -1317,6 +1446,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -1347,9 +1479,9 @@ checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "itertools" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" dependencies = [ "either", ] @@ -1654,9 +1786,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "oneshot" @@ -1743,6 +1875,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "paste" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" + [[package]] name = "pbkdf2" version = "0.9.0" @@ -1786,14 +1924,13 @@ dependencies = [ "rusty-hook", "serde", "setup-utils", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-ledger", - "snarkvm-marlin 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-polycommit 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-marlin", + "snarkvm-polycommit", + "snarkvm-r1cs", + "snarkvm-utilities", "tracing", ] @@ -1809,7 +1946,7 @@ dependencies = [ "rand 0.8.4", "rustc_version 0.4.0", "setup-utils", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-curves", "tracing", "tracing-subscriber", "wasm-bindgen-test", @@ -1836,7 +1973,7 @@ dependencies = [ "serde_with", "serial_test", "setup-utils", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-curves", "thiserror", "time 0.3.5", "tokio", @@ -1870,10 +2007,10 @@ dependencies = [ "serde_json", "setup-utils", "setup1-shared", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", + "snarkvm-curves", + "snarkvm-dpc", + "snarkvm-fields", + "snarkvm-utilities", "tracing", "tracing-subscriber", "wasm-bindgen", @@ -1890,7 +2027,7 @@ dependencies = [ "getrandom 0.2.3", "hex", "rand 0.8.4", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", + "snarkvm-dpc", "wasm-bindgen", ] @@ -1911,11 +2048,11 @@ dependencies = [ "rayon", "rusty-hook", "setup-utils", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-r1cs", + "snarkvm-utilities", "tracing", "tracing-subscriber", "wasm-bindgen", @@ -1938,9 +2075,9 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -2036,9 +2173,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", "version_check", ] @@ -2048,18 +2185,36 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", "version_check", ] +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", ] [[package]] @@ -2068,7 +2223,7 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.32", ] [[package]] @@ -2195,6 +2350,16 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" +dependencies = [ + "getrandom 0.2.3", + "redox_syscall", +] + [[package]] name = "regex" version = "1.5.4" @@ -2292,10 +2457,10 @@ version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f567ca01565c50c67b29e535f5f67b8ea8aeadaeed16a88f10792ab57438b957" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", "rust-embed-utils", - "syn", + "syn 1.0.82", "walkdir", ] @@ -2305,7 +2470,7 @@ version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6116e7ab9ea963f60f2f20291d8fcf6c7273192cdd7273b3c80729a9605c97b2" dependencies = [ - "sha2", + "sha2 0.9.8", "walkdir", ] @@ -2406,7 +2571,7 @@ dependencies = [ "hmac", "pbkdf2", "salsa20", - "sha2", + "sha2 0.9.8", ] [[package]] @@ -2473,9 +2638,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" dependencies = [ "serde_derive", ] @@ -2509,9 +2674,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692563b61324ae1568e2884c7a6385ab4b95f13063fd31a6b702d5cbc5c456df" dependencies = [ "darling 0.10.2", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -2526,13 +2691,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -2576,9 +2741,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12e47be9471c72889ebafb5e14d5ff930d89ae7a67bbdb5f8abb564f845a927e" dependencies = [ "darling 0.13.0", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -2598,9 +2763,9 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -2608,7 +2773,7 @@ name = "setup-utils" version = "0.3.0" dependencies = [ "blake2", - "blake2s_simd", + "blake2s_simd 0.5.11", "cfg-if", "criterion", "crossbeam", @@ -2622,12 +2787,12 @@ dependencies = [ "rayon", "rusty-hook", "serde", - "sha2", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "sha2 0.9.8", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-r1cs", + "snarkvm-utilities", "thiserror", "tracing", ] @@ -2643,7 +2808,7 @@ dependencies = [ "secrecy", "serde", "serde_json", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-dpc", "structopt", "unic-langid", ] @@ -2678,9 +2843,9 @@ dependencies = [ "serial_test", "setup-utils", "setup1-shared", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-curves", + "snarkvm-dpc", + "snarkvm-utilities", "structopt", "thiserror", "tokio", @@ -2700,7 +2865,7 @@ dependencies = [ "serde", "serde_json", "setup-utils", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-curves", "tokio", ] @@ -2724,10 +2889,10 @@ dependencies = [ "serde_json", "setup-utils", "setup1-shared", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-dpc", + "snarkvm-utilities", "structopt", "thiserror", "tokio", @@ -2750,15 +2915,17 @@ dependencies = [ "phase2", "rand 0.8.4", "rand_chacha 0.3.1", + "serde", "setup-utils", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-parameters 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-dpc", + "snarkvm-fields", + "snarkvm-parameters", + "snarkvm-r1cs", + "snarkvm-utilities", "thiserror", + "tracing", "tracing-subscriber", ] @@ -2768,10 +2935,10 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] @@ -2781,13 +2948,24 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] +[[package]] +name = "sha2" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900d964dd36bb15bcf2f2b35694c072feab74969a54f2bbeec7a2d725d2bdcb6" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.1", +] + [[package]] name = "sharded-slab" version = "0.1.4" @@ -2821,436 +2999,220 @@ checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" [[package]] name = "snarkvm-algorithms" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "anyhow", "blake2", - "blake2s_simd", + "blake2s_simd 1.0.0", "crossbeam-channel", "derivative", - "digest", - "itertools", - "lazy_static", - "once_cell", - "rand 0.8.4", - "rand_chacha 0.3.1", - "rayon", - "sha2", - "smallvec", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "thiserror", -] - -[[package]] -name = "snarkvm-algorithms" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" -dependencies = [ - "anyhow", - "blake2", - "blake2s_simd", - "crossbeam-channel", - "derivative", - "digest", + "digest 0.9.0", + "getrandom 0.2.3", + "hex", "itertools", "lazy_static", "once_cell", "rand 0.8.4", "rand_chacha 0.3.1", "rayon", - "sha2", - "smallvec", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "thiserror", -] - -[[package]] -name = "snarkvm-curves" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "derivative", - "rand 0.8.4", - "rand_xorshift", - "rustc_version 0.4.0", "serde", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", + "sha2 0.10.0", + "smallvec", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-profiler", + "snarkvm-r1cs", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-curves" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "derivative", "rand 0.8.4", - "rand_xorshift", "rustc_version 0.4.0", "serde", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-fields", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-derives" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "proc-macro-crate", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "snarkvm-derives" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "proc-macro-crate", "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] name = "snarkvm-dpc" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "anyhow", - "base58", - "bech32", - "bincode", - "blake2", - "derivative", - "hex", - "itertools", - "once_cell", - "rand 0.8.4", - "serde", - "sha2", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-marlin 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-parameters 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-polycommit 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "thiserror", -] - -[[package]] -name = "snarkvm-dpc" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "anyhow", "base58", "bech32", "bincode", "blake2", + "chrono", "derivative", "hex", "itertools", "once_cell", "rand 0.8.4", + "rayon", "serde", - "sha2", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-marlin 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-parameters 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-polycommit 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "thiserror", -] - -[[package]] -name = "snarkvm-fields" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "anyhow", - "bincode", - "derivative", - "rand 0.8.4", - "rand_xorshift", - "serde", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", + "serde_json", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-gadgets", + "snarkvm-marlin", + "snarkvm-parameters", + "snarkvm-polycommit", + "snarkvm-profiler", + "snarkvm-r1cs", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-fields" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "anyhow", - "bincode", "derivative", "rand 0.8.4", - "rand_xorshift", "serde", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-gadgets" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "derivative", - "digest", - "itertools", - "num-bigint", - "num-integer", - "num-traits", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "thiserror", -] - -[[package]] -name = "snarkvm-gadgets" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ + "anyhow", "derivative", - "digest", + "digest 0.9.0", "itertools", "num-bigint", "num-integer", "num-traits", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "thiserror", -] - -[[package]] -name = "snarkvm-ledger" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" -dependencies = [ - "anyhow", - "bincode", - "blake2", - "chrono", - "hex", - "once_cell", - "parking_lot", - "rand 0.8.4", - "serde", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-dpc 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-marlin 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-parameters 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-polycommit 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-r1cs", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-marlin" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "blake2", - "derivative", - "digest", - "hashbrown", - "rand 0.8.4", - "rand_chacha 0.3.1", - "rand_core 0.6.3", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-polycommit 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", -] - -[[package]] -name = "snarkvm-marlin" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ + "bincode", "blake2", "derivative", - "digest", + "digest 0.9.0", "hashbrown", "rand 0.8.4", "rand_chacha 0.3.1", "rand_core 0.6.3", "rayon", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-polycommit 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", -] - -[[package]] -name = "snarkvm-parameters" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "hex", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "thiserror", + "serde", + "smallvec", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-gadgets", + "snarkvm-polycommit", + "snarkvm-profiler", + "snarkvm-r1cs", + "snarkvm-utilities", ] [[package]] name = "snarkvm-parameters" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ + "aleo-std", + "anyhow", + "cfg-if", "curl", "hex", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "parking_lot", + "paste", + "reqwest", + "serde_json", + "snarkvm-algorithms", + "snarkvm-utilities", "thiserror", + "wasm-bindgen-futures", ] [[package]] name = "snarkvm-polycommit" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "derivative", - "digest", - "hashbrown", - "rand_core 0.6.3", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", -] - -[[package]] -name = "snarkvm-polycommit" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "derivative", - "digest", + "digest 0.9.0", "hashbrown", "rand_core 0.6.3", - "snarkvm-algorithms 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-gadgets 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-profiler 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-r1cs 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-algorithms", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-gadgets", + "snarkvm-profiler", + "snarkvm-r1cs", + "snarkvm-utilities", ] [[package]] name = "snarkvm-profiler" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" - -[[package]] -name = "snarkvm-profiler" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" - -[[package]] -name = "snarkvm-r1cs" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" -dependencies = [ - "anyhow", - "cfg-if", - "fxhash", - "indexmap", - "itertools", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "thiserror", -] +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" [[package]] name = "snarkvm-r1cs" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "anyhow", "cfg-if", "fxhash", "indexmap", "itertools", - "snarkvm-curves 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-fields 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", - "snarkvm-utilities 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-utilities" version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm#137b57a3bc0a3a5f3e8e8e8300f748990a77bdeb" +source = "git+https://github.com/AleoHQ/snarkVM.git?rev=092dfd2#092dfd2ae726339e1404ae3e3ce82a18d52f3114" dependencies = [ "anyhow", "bincode", "num-bigint", "rand 0.8.4", - "snarkvm-derives 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?branch=setup_wasm)", - "thiserror", -] - -[[package]] -name = "snarkvm-utilities" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c#fc997c3e99ecc42d30e31302b4550001ccf86f5a" -dependencies = [ - "anyhow", - "bincode", - "num-bigint", - "rand 0.8.4", - "snarkvm-derives 0.7.5 (git+https://github.com/AleoHQ/snarkVM.git?rev=fc997c)", + "serde", + "snarkvm-derives", "thiserror", ] @@ -3301,9 +3263,9 @@ checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ "heck", "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -3312,15 +3274,26 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + [[package]] name = "syn" version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.32", + "quote 1.0.10", + "unicode-xid 0.2.2", ] [[package]] @@ -3329,10 +3302,10 @@ version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", + "unicode-xid 0.2.2", ] [[package]] @@ -3383,9 +3356,9 @@ version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -3481,9 +3454,9 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -3569,9 +3542,9 @@ version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", ] [[package]] @@ -3706,6 +3679,12 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.2" @@ -3812,9 +3791,9 @@ dependencies = [ "bumpalo", "lazy_static", "log", - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", "wasm-bindgen-shared", ] @@ -3836,7 +3815,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ - "quote", + "quote 1.0.10", "wasm-bindgen-macro-support", ] @@ -3846,9 +3825,9 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3879,8 +3858,8 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688" dependencies = [ - "proc-macro2", - "quote", + "proc-macro2 1.0.32", + "quote 1.0.10", ] [[package]] @@ -3976,8 +3955,8 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65f1a51723ec88c66d5d1fe80c841f17f63587d6691901d66be9bec6c3b51f73" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", "synstructure", ] diff --git a/phase1-cli/Cargo.toml b/phase1-cli/Cargo.toml index d9b71c69..c5363b73 100644 --- a/phase1-cli/Cargo.toml +++ b/phase1-cli/Cargo.toml @@ -11,7 +11,8 @@ edition = "2018" [dependencies] phase1 = { path = "../phase1" } setup-utils = { path = "../setup-utils" } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } + +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } fs-err = "2.6" gumdrop = { version = "0.8.0" } diff --git a/phase1-cli/scripts/phase1_chunked.sh b/phase1-cli/scripts/phase1_chunked.sh index 35076ce9..93cf350d 100755 --- a/phase1-cli/scripts/phase1_chunked.sh +++ b/phase1-cli/scripts/phase1_chunked.sh @@ -4,7 +4,7 @@ rm -f challenge* response* new_challenge* new_response* new_new_challenge_* proc PROVING_SYSTEM=$1 POWER=10 -BATCH=64 +BATCH=512 CHUNK_SIZE=512 if [ "$PROVING_SYSTEM" == "groth16" ]; then MAX_CHUNK_INDEX=3 # we have 4 chunks, since we have a total of 2^11-1 powers @@ -14,7 +14,7 @@ fi CURVE="bls12_377" SEED1=`tr -dc 'A-F0-9' < /dev/random | head -c32` echo $SEED1 > seed1 -SEED2=`tr -dc 'A-F0-9' < /dev/random | head -c32` +SEED2=`tr -dc 'A-F0-9' < /dev/urandom | head -c32` echo $SEED2 > seed2 phase1_1="cargo run --release --bin phase1 --features cli -- --curve-kind $CURVE --batch-size $BATCH --contribution-mode chunked --chunk-size $CHUNK_SIZE --power $POWER --seed seed1 --proving-system $PROVING_SYSTEM" @@ -44,7 +44,7 @@ for i in $(seq $(($MAX_CHUNK_INDEX/2 + 1)) $MAX_CHUNK_INDEX); do echo new_response_$i >> response_list done -$phase1_combine combine --response-list-fname response_list --combined-fname combined +env RUST_LOG=debug RAYON_NUM_THREADS=1 $phase1_combine combine --response-list-fname response_list --combined-fname combined $phase1_full beacon --challenge-fname combined --response-fname response_beacon --beacon-hash 0000000000000000000a558a61ddc8ee4e488d647a747fe4dcc362fe2026c620 $phase1_full verify-and-transform-pok-and-correctness --challenge-fname combined --response-fname response_beacon --new-challenge-fname response_beacon_new_challenge $phase1_full verify-and-transform-ratios --response-fname response_beacon_new_challenge diff --git a/phase1-cli/scripts/phase1_chunked_prepare_phase2.sh b/phase1-cli/scripts/phase1_chunked_prepare_phase2.sh new file mode 100755 index 00000000..acd02c96 --- /dev/null +++ b/phase1-cli/scripts/phase1_chunked_prepare_phase2.sh @@ -0,0 +1,62 @@ +#!/bin/bash -e + +rm -f challenge* response* new_challenge* new_response* new_new_challenge_* processed* initial_ceremony* response_list* combined* seed* chunk* phase1 + +# export RUSTFLAGS="-C target-feature=+bmi2,+adx" +CARGO_VER="" +PROVING_SYSTEM=$1 +POWER=20 +BATCH=524288 +CHUNK_SIZE=524288 +if [ "$PROVING_SYSTEM" == "groth16" ]; then + MAX_CHUNK_INDEX=$((4-1)) # we have 4 chunks, since we have a total of 2^11-1 powers +else + MAX_CHUNK_INDEX=$((2-1)) # we have 2 chunks, since we have a total of 2^11-1 powers +fi +CURVE="bw6" +SEED1=$(tr -dc 'A-F0-9' < /dev/urandom | head -c32) +echo $SEED1 > seed1 +SEED2=$(tr -dc 'A-F0-9' < /dev/urandom | head -c32) +echo $SEED2 > seed2 + +function check_hash() { + test "`xxd -p -c 64 $1.hash`" = "`b2sum $1 | awk '{print $1}'`" +} + +phase1_1="cargo run --release --bin phase1 --features cli -- --curve-kind $CURVE --batch-size $BATCH --contribution-mode chunked --chunk-size $CHUNK_SIZE --power $POWER --seed seed1 --proving-system $PROVING_SYSTEM" +phase1_2="cargo run --release --bin phase1 --features cli -- --curve-kind $CURVE --batch-size $BATCH --contribution-mode chunked --chunk-size $CHUNK_SIZE --power $POWER --seed seed2 --proving-system $PROVING_SYSTEM" +phase1_combine="cargo run --release --bin phase1 --features cli -- --curve-kind $CURVE --batch-size $BATCH --contribution-mode chunked --chunk-size $CHUNK_SIZE --power $POWER --proving-system $PROVING_SYSTEM" +phase1_full="cargo run --release --bin phase1 --features cli -- --curve-kind $CURVE --batch-size $BATCH --contribution-mode full --power $POWER --proving-system $PROVING_SYSTEM" +prepare_phase2="cargo run --release --bin prepare_phase2 --features cli -- --curve-kind $CURVE --batch-size $BATCH --power $POWER --proving-system $PROVING_SYSTEM" + +####### Phase 1 + +for i in $(seq 0 $(($MAX_CHUNK_INDEX/2))); do + $phase1_1 --chunk-index $i new --challenge-fname challenge_$i + yes | $phase1_1 --chunk-index $i contribute --challenge-fname challenge_$i --response-fname response_$i + $phase1_1 --chunk-index $i verify-and-transform-pok-and-correctness --challenge-fname challenge_$i --response-fname response_$i --new-challenge-fname new_challenge_$i + yes | $phase1_2 --chunk-index $i contribute --challenge-fname new_challenge_$i --response-fname new_response_$i + $phase1_2 --chunk-index $i verify-and-transform-pok-and-correctness --challenge-fname new_challenge_$i --response-fname new_response_$i --new-challenge-fname new_new_challenge_$i + rm challenge_$i new_challenge_$i new_new_challenge_$i # no longer needed + echo new_response_$i >> response_list +done + +for i in $(seq $(($MAX_CHUNK_INDEX/2 + 1)) $MAX_CHUNK_INDEX); do + $phase1_1 --chunk-index $i new --challenge-fname challenge_$i + yes | $phase1_2 --chunk-index $i contribute --challenge-fname challenge_$i --response-fname response_$i + $phase1_1 --chunk-index $i verify-and-transform-pok-and-correctness --challenge-fname challenge_$i --response-fname response_$i --new-challenge-fname new_challenge_$i + yes | $phase1_1 --chunk-index $i contribute --challenge-fname new_challenge_$i --response-fname new_response_$i + $phase1_2 --chunk-index $i verify-and-transform-pok-and-correctness --challenge-fname new_challenge_$i --response-fname new_response_$i --new-challenge-fname new_new_challenge_$i + rm challenge_$i new_challenge_$i new_new_challenge_$i # no longer needed + echo new_response_$i >> response_list +done + +$phase1_combine combine --response-list-fname response_list --combined-fname combined +$phase1_full beacon --challenge-fname combined --response-fname response_beacon --beacon-hash 0000000000000000000a558a61ddc8ee4e488d647a747fe4dcc362fe2026c620 +$phase1_full verify-and-transform-pok-and-correctness --challenge-fname combined --response-fname response_beacon --new-challenge-fname response_beacon_new_challenge +$phase1_full verify-and-transform-ratios --response-fname response_beacon_new_challenge + +echo "Running prepare phase2..." +$prepare_phase2 --phase2-fname phase1 --response-fname response_beacon --phase2-size $POWER + +echo "Done!" diff --git a/phase1-cli/scripts/phase1_chunked_prepare_phase2_only.sh b/phase1-cli/scripts/phase1_chunked_prepare_phase2_only.sh new file mode 100755 index 00000000..0a9f773b --- /dev/null +++ b/phase1-cli/scripts/phase1_chunked_prepare_phase2_only.sh @@ -0,0 +1,34 @@ +#!/bin/bash -e + +rm -f phase1 round_1024 + +# export RUSTFLAGS="-C target-feature=+bmi2,+adx" +CARGO_VER="" +PROVING_SYSTEM=$1 +POWER=19 +BATCH=262144 +CHUNK_SIZE=262144 + +if [ "$PROVING_SYSTEM" == "groth16" ]; then + MAX_CHUNK_INDEX=$((4-1)) # we have 4 chunks, since we have a total of 2^11-1 powers +else + MAX_CHUNK_INDEX=$((2-1)) # we have 2 chunks, since we have a total of 2^11-1 powers +fi +CURVE="bw6" +SEED1=$(tr -dc 'A-F0-9' < /dev/urandom | head -c32) +echo $SEED1 > seed1 +SEED2=$(tr -dc 'A-F0-9' < /dev/urandom | head -c32) +echo $SEED2 > seed2 + +function check_hash() { + test "`xxd -p -c 64 $1.hash`" = "`b2sum $1 | awk '{print $1}'`" +} + + +prepare_phase2="cargo run --release --bin prepare_phase2 --features cli -- --curve-kind $CURVE --batch-size $BATCH --power $POWER --proving-system $PROVING_SYSTEM" + + +echo "Running prepare phase2..." +$prepare_phase2 --phase2-fname round_1024 --response-fname ~/round_1024.verified --phase2-size 19 + +echo "Done!" diff --git a/phase1-cli/src/bin/prepare_phase2.rs b/phase1-cli/src/bin/prepare_phase2.rs index b63ef26b..21fb0b8c 100644 --- a/phase1-cli/src/bin/prepare_phase2.rs +++ b/phase1-cli/src/bin/prepare_phase2.rs @@ -69,8 +69,8 @@ fn prepare_phase2(opts: &PreparePhase2Opts) -> Result<()> { // Deserialize the accumulator let current_accumulator = Phase1::deserialize( &response_readable_map, - UseCompression::Yes, - CheckForCorrectness::Full, + UseCompression::No, + CheckForCorrectness::No, ¶meters, ) .expect("unable to read uncompressed accumulator"); diff --git a/phase1-cli/src/combine.rs b/phase1-cli/src/combine.rs index 9d1fcec0..783fb73e 100644 --- a/phase1-cli/src/combine.rs +++ b/phase1-cli/src/combine.rs @@ -73,7 +73,7 @@ pub fn combine( .open(combined_filename) .expect("unable to create new combined file in this directory"); - println!("parameters for output: {:?}", parameters_for_output); + tracing::debug!("Parameters for output: {:?}", parameters_for_output); writer .set_len(parameters_for_output.accumulator_size as u64) @@ -94,6 +94,7 @@ pub fn combine( parameters.total_size_in_log2, parameters.batch_size, ); + tracing::debug!("Parameters for aggregation: {:?}", parameters); let res = Phase1::aggregation( &readers .iter() diff --git a/phase1-coordinator/Cargo.toml b/phase1-coordinator/Cargo.toml index 56e5a1d3..cd541fcb 100644 --- a/phase1-coordinator/Cargo.toml +++ b/phase1-coordinator/Cargo.toml @@ -16,7 +16,7 @@ required-features = ["parallel"] [dependencies] phase1 = { path = "../phase1" } setup-utils = { path = "../setup-utils" } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } anyhow = { version = "1.0.37" } fs-err = { version = "2.6.0" } diff --git a/phase1-wasm-keys/Cargo.toml b/phase1-wasm-keys/Cargo.toml index 12ecfc6b..7f646fec 100644 --- a/phase1-wasm-keys/Cargo.toml +++ b/phase1-wasm-keys/Cargo.toml @@ -12,7 +12,7 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", branch = "setup_wasm", default-features = false, features = [ "wasm" ] } +snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false, features = [ "wasm" ] } rand = { version = "0.8" } wasm-bindgen = { version = "0.2.69", features=["serde-serialize"] } getrandom = { version = "0.2", features = ["js", "wasm-bindgen"] } diff --git a/phase1-wasm-keys/src/lib.rs b/phase1-wasm-keys/src/lib.rs index 5d17a0df..7c9d94f5 100644 --- a/phase1-wasm-keys/src/lib.rs +++ b/phase1-wasm-keys/src/lib.rs @@ -1,13 +1,13 @@ use blake2::{Blake2s, Digest}; use rand::{CryptoRng, Rng}; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn generate_keys() -> Result { let mut rng = rand::thread_rng(); let private_key = PrivateKey::new(&mut rng); - let address = Address::from_private_key(&private_key).expect("Should have derived an Aleo address"); + let address = Address::from_private_key(&private_key); let (confirmation_key, new_private_key) = generate_confirmation_key(&address, &mut rng); Ok(JsValue::from_serde(&( @@ -20,9 +20,9 @@ pub fn generate_keys() -> Result { } fn generate_confirmation_key( - address: &Address, + address: &Address, rng: &mut R, -) -> (String, PrivateKey) { +) -> (String, PrivateKey) { let new_private_key = PrivateKey::new(rng); let concatenated = format!("{}{}", address.to_string(), new_private_key.to_string()); let mut hasher = Blake2s::new(); diff --git a/phase1-wasm/Cargo.toml b/phase1-wasm/Cargo.toml index fa7fe8d9..56340915 100644 --- a/phase1-wasm/Cargo.toml +++ b/phase1-wasm/Cargo.toml @@ -12,14 +12,14 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -http = "0.2" -phase1 = { path = "../phase1", default-features = false } +phase1 = { path = "../phase1" } setup-utils = { path = "../setup-utils", default-features = false } setup1-shared = { path = "../setup1-shared" } -snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", branch = "setup_wasm", default-features = false, features = [ "wasm" ], optional = true } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", branch = "setup_wasm", default-features = false, optional = true } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", default-features = false } -snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", default-features = false } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +http = "0.2" +snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false, features = [ "wasm" ], optional = true } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false, optional = true } blake2 = { version = "0.9", default-features = false } bytes = "1.1" diff --git a/phase1/Cargo.toml b/phase1/Cargo.toml index 6fbe9db0..475f4388 100644 --- a/phase1/Cargo.toml +++ b/phase1/Cargo.toml @@ -15,13 +15,14 @@ required-features = ["benchmark"] [dependencies] setup-utils = { path = "../setup-utils" } -snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", default-features = false } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } + +snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } + cfg-if = "1.0" -criterion = { version = "0.3", optional = true } derivative = { version = "2", features = [ "use_core" ] } itertools = "0.10" rand = { version = "0.8" } @@ -30,11 +31,11 @@ tracing = { version = "0.1.21" } serde = { version = "1.0", features = ["derive"] } [dev-dependencies] +criterion = { version = "0.3" } phase1 = { path = "./", features = ["testing"] } -snarkvm-marlin = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-polycommit = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-ledger = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } +snarkvm-marlin = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-polycommit = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } anyhow = { version = "1.0.37" } blake2 = { version = "0.9", default-features = false } @@ -49,7 +50,6 @@ cli = ["parallel", "setup-utils/cli"] parallel = ["rayon", "setup-utils/parallel", "snarkvm-algorithms/parallel"] wasm = ["setup-utils/wasm"] -benchmark = ["criterion"] testing = ["parallel"] [[test]] diff --git a/phase1/benches/phase1.rs b/phase1/benches/phase1.rs index 9f4f40da..f56503b3 100644 --- a/phase1/benches/phase1.rs +++ b/phase1/benches/phase1.rs @@ -6,7 +6,7 @@ use phase1::{ }; use setup_utils::*; -use zexe_algebra::Bls12_377; +use snarkvm_curves::bls12_377::Bls12_377; use criterion::{criterion_group, criterion_main, Criterion, Throughput}; use rand::thread_rng; @@ -15,8 +15,8 @@ use rand::thread_rng; // Parallel generation is strictly better fn benchmark_initialization(c: &mut Criterion) { // Iterate over all combinations of the following parameters - let compressions = &[UseCompression::Yes, UseCompression::No]; - let proving_system = &[ProvingSystem::Groth16, ProvingSystem::Marlin]; + let compressions = [UseCompression::Yes, UseCompression::No]; + let proving_system = [ProvingSystem::Groth16, ProvingSystem::Marlin]; let mut group = c.benchmark_group("initialization"); @@ -29,13 +29,13 @@ fn benchmark_initialization(c: &mut Criterion) { } let parameters = Phase1Parameters::::new_full(proof_system, power, power); - let expected_challenge_length = parameters.get_length(*compression); + let expected_challenge_length = parameters.get_length(compression); // count in `other` powers (G1 will be 2x that) group.throughput(Throughput::Elements(power as u64)); - group.bench_with_input(format!("{}", compression), &power, |b, _power| { + group.bench_with_input(format!("{:?}_{}", proof_system, compression), &power, |b, _power| { let mut output = vec![0; expected_challenge_length]; - b.iter(|| Phase1::initialization(&mut output, *compression, ¶meters)) + b.iter(|| Phase1::initialization(&mut output, compression, ¶meters)) }); } } @@ -58,7 +58,7 @@ fn benchmark_computation(c: &mut Criterion) { // We gather data on various sizes. for power in 4..8 { for proof_system in proving_system { - let parameters = Phase1Parameters::::new_full(proof_system, power, batch); + let parameters = Phase1Parameters::::new_full(*proof_system, power, batch); let (input, _) = generate_input(¶meters, compressed_input, correctness); let mut output = vec![0; parameters.get_length(compressed_output)]; @@ -71,7 +71,7 @@ fn benchmark_computation(c: &mut Criterion) { group.throughput(Throughput::Elements(power as u64)); group.bench_with_input( - format!("{}_{}", compressed_input, compressed_output), + format!("{:?}_{}_{}", proof_system, compressed_input, compressed_output), &power, |b, _size| { b.iter(|| { @@ -116,7 +116,7 @@ fn benchmark_verification(c: &mut Criterion) { for power in powers { for (compressed_input, compressed_output) in compression { for proof_system in proving_system { - let parameters = Phase1Parameters::::new_full(proof_system, power, batch); + let parameters = Phase1Parameters::::new_full(*proof_system, power, batch); let (input, output, pubkey, current_accumulator_hash) = setup_verify(*compressed_input, correctness, *compressed_output, ¶meters); diff --git a/phase1/src/aggregation.rs b/phase1/src/aggregation.rs index 20957cc2..f9be36f1 100644 --- a/phase1/src/aggregation.rs +++ b/phase1/src/aggregation.rs @@ -16,7 +16,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { let span = info_span!("phase1-aggregation"); let _enter = span.enter(); - info!("starting..."); + info!("Starting Aggregation"); for (chunk_index, (input, compressed_input)) in inputs.iter().enumerate() { let chunk_parameters = @@ -33,9 +33,10 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { let start = chunk_index * chunk_parameters.chunk_size; let end = (chunk_index + 1) * chunk_parameters.chunk_size; - debug!("combining chunk from {} to {}", start, end); + debug!("Combining chunk from {} to {}", start, end); + debug!("Chunk parameters: {:?}", chunk_parameters); - let span = info_span!("batch", start, end); + let span = info_span!("Batch", start, end); let _enter = span.enter(); match parameters.proving_system { @@ -53,16 +54,25 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { .write_batch(&elements, compressed_output) .expect("should have written batch"); - trace!("tau_g1 aggregation for chunk {} successful", chunk_index); + debug!( + "Tau G1 aggregation for chunk {} successful; {} G1 elements written", + chunk_index, + elements.len() + ); }); + debug!( + "`start = {}, chunk_parameters.powers_length = {}, start < chunk_parameters.powers_length = {}`", + start, + chunk_parameters.powers_length, + start < chunk_parameters.powers_length + ); if start < chunk_parameters.powers_length { rayon::scope(|t| { let _enter = span.enter(); t.spawn(|_| { let _enter = span.enter(); - let elements: Vec = in_tau_g2 .read_batch(compressed_input, CheckForCorrectness::No) .expect("should have read batch"); @@ -70,7 +80,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { .write_batch(&elements, compressed_output) .expect("should have written batch"); - trace!("tau_g2 aggregation for chunk {} successful", chunk_index); + debug!( + "Tau G2 aggregation for chunk {} successful; {} G2 elements written", + chunk_index, + elements.len() + ); }); t.spawn(|_| { @@ -83,7 +97,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { .write_batch(&elements, compressed_output) .expect("should have written batch"); - trace!("alpha_g1 aggregation for chunk {} successful", chunk_index); + debug!( + "alpha_g1 aggregation for chunk {} successful; {} G1 elements written", + chunk_index, + elements.len() + ); }); t.spawn(|_| { @@ -96,7 +114,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { .write_batch(&elements, compressed_output) .expect("should have written batch"); - trace!("beta_g1 aggregation for chunk {} successful", chunk_index); + debug!( + "beta_g1 aggregation for chunk {} successful; {} G1 elements written", + chunk_index, + elements.len() + ); }); }); } @@ -108,7 +130,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { beta_g2 .write_element(&element, compressed_output) .expect("should have written element"); - trace!("beta_g2 aggregation for chunk {} successful", chunk_index); + debug!("beta_g2 aggregation for chunk {} successful", chunk_index); } }); } diff --git a/phase1/src/computation.rs b/phase1/src/computation.rs index 1bdc4741..3ba4613f 100644 --- a/phase1/src/computation.rs +++ b/phase1/src/computation.rs @@ -20,7 +20,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { parameters: &'a Phase1Parameters, ) -> Result<()> { let span = info_span!("phase1-computation"); - let _ = span.enter(); + let _enter = span.enter(); info!("starting..."); @@ -31,6 +31,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { // Get mutable references of the outputs. let (tau_g1_outputs, tau_g2_outputs, alpha_g1_outputs, beta_g1_outputs, beta_g2_outputs) = split_mut(output, parameters, compressed_output); + info!("Parameters for contribution: {:?}", parameters); match parameters.proving_system { ProvingSystem::Groth16 => { @@ -50,7 +51,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { debug!("contributing to chunk from {} to {}", start, end); let span = info_span!("batch", start, end); - let _ = span.enter(); + let _enter = span.enter(); // Determine the chunk start and end indices based on the contribution mode. let (start_chunk, end_chunk) = match parameters.contribution_mode { @@ -62,10 +63,10 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { }; rayon_cfg::scope(|t| { - let _ = span.enter(); + let _enter = span.enter(); t.spawn(|_| { - let _ = span.enter(); + let _enter = span.enter(); // Generate powers from `start` to `end` (e.g. [0,4) then [4, 8) etc.) let powers = generate_powers_of_tau::(&key.tau, start, end); @@ -76,10 +77,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { // and write the updated value (without allocating) to the // output buffer rayon_cfg::scope(|t| { - let _ = span.enter(); + let _enter = span.enter(); + info!("Starting powers of Tau in G1"); t.spawn(|_| { - let _ = span.enter(); + let _enter = span.enter(); // Check that the chunk is of nonzero length. assert!(tau_g1_inputs.len() > 0); @@ -93,7 +95,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { ) .expect("could not apply powers of tau to tau_g1 elements"); - trace!("applied powers to tau_g1 elements"); + info!("Applied powers to tau_g1 elements"); }); if start < parameters.powers_length { // if the `end` would be out of bounds, then just process until @@ -118,10 +120,11 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { }; rayon_cfg::scope(|t| { - let _ = span.enter(); + let _enter = span.enter(); t.spawn(|_| { - let _ = span.enter(); + let _enter = span.enter(); + info!("Starting powers of Tau in G2"); // Check that the chunk is of nonzero length. assert!(tau_g2_inputs.len() > 0); @@ -135,11 +138,12 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { ) .expect("could not apply powers of tau to tau_g2 elements"); - trace!("applied powers to tau_g2 elements"); + trace!("Applied powers of Tau in G2"); }); t.spawn(|_| { - let _ = span.enter(); + let _enter = span.enter(); + info!("Starting Alpha G1 elements"); // Check that the chunk is of nonzero length. assert!(alpha_g1_inputs.len() > 0); @@ -153,11 +157,12 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { ) .expect("could not apply powers of tau to alpha_g1 elements"); - trace!("applied powers to alpha_g1 elements"); + info!("Applied powers to Alpha G1 elements"); }); t.spawn(|_| { - let _ = span.enter(); + info!("Starting beta G1 elements"); + let _enter = span.enter(); // Check that the chunk is of nonzero length. assert!(beta_g1_inputs.len() > 0); @@ -171,7 +176,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { ) .expect("could not apply powers of tau to beta_g1 elements"); - trace!("applied powers to beta_g1 elements"); + trace!("Applied powers to Beta G1 elements"); }); }); } @@ -249,7 +254,7 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { debug!("contributing to chunk from {} to {}", start, end); let span = info_span!("batch", start, end); - let _ = span.enter(); + let _enter = span.enter(); // Determine the chunk start and end indices based on the contribution mode. let (start_chunk, end_chunk) = match parameters.contribution_mode { @@ -261,10 +266,10 @@ impl<'a, E: PairingEngine + Sync> Phase1<'a, E> { }; rayon_cfg::scope(|t| { - let _ = span.enter(); + let _enter = span.enter(); t.spawn(|_| { - let _ = span.enter(); + let _enter = span.enter(); // Generate powers from `start` to `end` (e.g. [0,4) then [4, 8) etc.) let powers = generate_powers_of_tau::(&key.tau, start, end); diff --git a/phase1/src/helpers/accumulator.rs b/phase1/src/helpers/accumulator.rs index c6d3f291..2ef51a7a 100644 --- a/phase1/src/helpers/accumulator.rs +++ b/phase1/src/helpers/accumulator.rs @@ -307,6 +307,7 @@ pub fn deserialize( Ok((tau_g1, tau_g2, alpha_g1, beta_g1, beta_g2)) } +#[cfg(not(feature = "wasm"))] #[cfg(test)] mod tests { use super::*; diff --git a/phase1/src/helpers/buffers.rs b/phase1/src/helpers/buffers.rs index c78ebedf..b0e5a4a6 100644 --- a/phase1/src/helpers/buffers.rs +++ b/phase1/src/helpers/buffers.rs @@ -68,16 +68,17 @@ pub(crate) fn apply_powers( powers: &[C::ScalarField], coeff: Option<&C::ScalarField>, ) -> Result<()> { + tracing::debug!("Applying powers {} to {}", start, end); let in_size = buffer_size::(input_compressed); let out_size = buffer_size::(output_compressed); // Read the input - let mut elements = + let elements = &mut input[start * in_size..end * in_size].read_batch::(input_compressed, check_input_for_correctness)?; // calculate the powers - batch_exp(&mut elements, &powers[..end - start], coeff)?; + batch_exp(elements, &powers[..(end - start)], coeff)?; // write back - output[start * out_size..end * out_size].write_batch(&elements, output_compressed)?; + output[(start * out_size)..(end * out_size)].write_batch(elements, output_compressed)?; Ok(()) } diff --git a/phase1/src/objects/public_key.rs b/phase1/src/objects/public_key.rs index 651bad10..a71d375c 100644 --- a/phase1/src/objects/public_key.rs +++ b/phase1/src/objects/public_key.rs @@ -50,7 +50,7 @@ impl PublicKey { UseCompression::No => parameters.accumulator_size, }; // Write the public key after the provided position - self.serialize(&mut output_map[position..].as_mut())?; + CanonicalSerialize::serialize(self, &mut &mut output_map[position..])?; Ok(()) } diff --git a/phase2/Cargo.toml b/phase2/Cargo.toml index d83e2bda..026bce12 100644 --- a/phase2/Cargo.toml +++ b/phase2/Cargo.toml @@ -19,11 +19,12 @@ required-features = ["phase2/testing"] [dependencies] setup-utils = { path = "../setup-utils" } -snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", default-features = false, features = ["snark"] } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } +snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false, features = ["snark"] } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } + byteorder = { version = "1.3.4" } cfg-if = "1.0" diff --git a/phase2/src/chunked_groth16.rs b/phase2/src/chunked_groth16.rs index 5d5ef5f9..8d186569 100644 --- a/phase2/src/chunked_groth16.rs +++ b/phase2/src/chunked_groth16.rs @@ -383,7 +383,7 @@ fn mul_query( num_els: usize, ) -> Result<()> { let mut query = (0..num_els) - .map(|_| C::deserialize(buffer)) + .map(|_| CanonicalDeserialize::deserialize(buffer)) .collect::, _>>()?; // why can't we use the aliased error type here? batch_mul(&mut query, element)?; @@ -392,7 +392,7 @@ fn mul_query( buffer.seek(SeekFrom::Current(((num_els * C::SERIALIZED_SIZE) as i64).neg()))?; query .iter() - .map(|el| el.serialize(buffer)) + .map(|el: &C| CanonicalSerialize::serialize(el, buffer)) .collect::, _>>()?; Ok(()) @@ -493,10 +493,10 @@ fn read_batch( batch_size: usize, ) -> Result<(Vec, Vec)> { let els_before = (0..batch_size) - .map(|_| C::deserialize(before)) + .map(|_| CanonicalDeserialize::deserialize(before)) .collect::, _>>()?; let els_after = (0..batch_size) - .map(|_| C::deserialize(after)) + .map(|_| CanonicalDeserialize::deserialize(after)) .collect::, _>>()?; Ok((els_before, els_after)) } diff --git a/phase2/src/lib.rs b/phase2/src/lib.rs index d9b5d653..2dc0d04c 100644 --- a/phase2/src/lib.rs +++ b/phase2/src/lib.rs @@ -15,7 +15,7 @@ cfg_if! { use wasm_bindgen::prelude::*; use itertools::Itertools; use parameters::MPCParameters; - use zexe_algebra::{Bls12_377, BW6_761, PairingEngine}; + use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761, PairingEngine}; use setup_utils::{ get_rng, user_system_randomness }; macro_rules! log { diff --git a/phase2/src/parameters.rs b/phase2/src/parameters.rs index a9ea6721..2de2c24b 100644 --- a/phase2/src/parameters.rs +++ b/phase2/src/parameters.rs @@ -158,7 +158,9 @@ impl MPCParameters { phase1_size, phase2_size, )?; + tracing::info!("Read Groth16 parameters"); let assembly = circuit_to_qap::(circuit)?; + tracing::info!("Constructed QAP"); Self::new_chunked(assembly, params, chunk_size) } @@ -168,6 +170,7 @@ impl MPCParameters { params: Groth16Params, chunk_size: usize, ) -> Result<(MPCParameters, ProvingKey, Vec>)> { + tracing::info!("Evaluating over Lagrange coefficients"); let (a_g1, b_g1, b_g2, gamma_abc_g1, l) = eval::( // Lagrange coeffs for Tau, read in from Phase 1 ¶ms.coeffs_g1, @@ -181,6 +184,7 @@ impl MPCParameters { // Helper cs.num_public_variables, ); + tracing::info!("Finished evaluating over Lagrange coefficients"); // Reject unconstrained elements, so that // the L query is always fully dense. @@ -221,6 +225,7 @@ impl MPCParameters { l_query: vec![], }; let cs_hash = hash_params(¶ms)?; + tracing::info!("Hashed parameters"); let full_mpc = MPCParameters { params: params.clone(), cs_hash, @@ -258,7 +263,9 @@ impl MPCParameters { contributions: vec![], }; chunks.push(chunk_params); + tracing::info!("Constructed chunk {}", i); } + tracing::info!("Finished constructing parameters"); Ok((full_mpc, query_parameters, chunks)) } @@ -267,6 +274,89 @@ impl MPCParameters { &self.params } + pub fn read_fast( + mut reader: R, + compressed: UseCompression, + check_correctness: CheckForCorrectness, + check_subgroup_membership: bool, + ) -> Result> { + let params = Self::read_groth16_fast(&mut reader, compressed, check_correctness, check_subgroup_membership)?; + + let mut cs_hash = [0u8; 64]; + reader.read_exact(&mut cs_hash)?; + + let contributions = PublicKey::read_batch(&mut reader)?; + + let mpc_params = MPCParameters:: { + params, + cs_hash, + contributions, + }; + + Ok(mpc_params) + } + + pub fn read_groth16_fast( + mut reader: R, + compressed: UseCompression, + check_correctness: CheckForCorrectness, + check_subgroup_membership: bool, + ) -> Result> { + // vk + let alpha_g1: E::G1Affine = reader.read_element(compressed, check_correctness)?; + let beta_g2: E::G2Affine = reader.read_element(compressed, check_correctness)?; + let gamma_g2: E::G2Affine = reader.read_element(compressed, check_correctness)?; + let delta_g2: E::G2Affine = reader.read_element(compressed, check_correctness)?; + let gamma_abc_g1: Vec = read_vec(&mut reader, compressed, check_correctness)?; + + // rest of the parameters + let beta_g1: E::G1Affine = reader.read_element(compressed, check_correctness)?; + let delta_g1: E::G1Affine = reader.read_element(compressed, check_correctness)?; + + // a,b queries guaranteed to have infinity points for variables unused in left,right r1cs + // inputs respectively + let ab_query_correctness = match check_correctness { + CheckForCorrectness::Full => CheckForCorrectness::OnlyInGroup, + _ => check_correctness, + }; + let a_query: Vec = read_vec(&mut reader, compressed, ab_query_correctness)?; + let b_g1_query: Vec = read_vec(&mut reader, compressed, ab_query_correctness)?; + let b_g2_query: Vec = read_vec(&mut reader, compressed, ab_query_correctness)?; + let h_query: Vec = read_vec(&mut reader, compressed, check_correctness)?; + let l_query: Vec = read_vec(&mut reader, compressed, check_correctness)?; + + let params = ProvingKey:: { + vk: VerifyingKey:: { + alpha_g1, + beta_g2, + gamma_g2, + delta_g2, + gamma_abc_g1, + }, + beta_g1, + delta_g1, + a_query, + b_g1_query, + b_g2_query, + h_query, + l_query, + }; + + // In the Full mode, this is already checked + if check_subgroup_membership && check_correctness != CheckForCorrectness::Full { + check_subgroup(¶ms.a_query)?; + check_subgroup(¶ms.b_g1_query)?; + check_subgroup(¶ms.b_g2_query)?; + check_subgroup(¶ms.h_query)?; + check_subgroup(¶ms.l_query)?; + check_subgroup(¶ms.vk.gamma_abc_g1)?; + check_subgroup(&[params.beta_g1, params.delta_g1, params.vk.alpha_g1])?; + check_subgroup(&[params.vk.beta_g2, params.vk.delta_g2, params.vk.gamma_g2])?; + } + + Ok(params) + } + /// Contributes some randomness to the parameters. Only one /// contributor needs to be honest for the parameters to be /// secure. @@ -573,7 +663,7 @@ pub fn circuit_to_qap>(circuit Ok(assembly) } -#[cfg(test)] +#[cfg(all(test, not(feature = "wasm")))] mod tests { use super::*; use crate::{ diff --git a/phase2/src/polynomial.rs b/phase2/src/polynomial.rs index e8560ed6..097132b8 100644 --- a/phase2/src/polynomial.rs +++ b/phase2/src/polynomial.rs @@ -1,6 +1,7 @@ use snarkvm_curves::{AffineCurve, PairingEngine, ProjectiveCurve}; -use snarkvm_fields::Zero; +use snarkvm_fields::{PrimeField, Zero}; use snarkvm_r1cs::Index; +use snarkvm_utilities::BitIteratorBE; use rayon::prelude::*; @@ -90,20 +91,39 @@ fn dot_product_vec( /// `coeffs` vector offset by `num_inputs` #[allow(clippy::redundant_closure)] fn dot_product(input: &[(C::ScalarField, Index)], coeffs: &[C], num_inputs: usize) -> C::Projective { - input - .into_par_iter() - .fold( - || C::Projective::zero(), - |mut sum, &(coeff, lag)| { - let ind = match lag { + if input.len() > 10 { + let mut input = input + .par_iter() + .map(|(coeff, lag)| { + let ind = match *lag { Index::Public(i) => i, Index::Private(i) => num_inputs + i, }; - sum += coeffs[ind].mul(coeff).into_projective(); - sum - }, - ) - .reduce(|| C::Projective::zero(), |a, b| a + b) + (coeff, ind) + }) + .collect::>(); + input.sort_unstable_by(|a, b| a.1.cmp(&b.1)); + let input = input + .into_par_iter() + .map(|(coeff, _)| coeff.to_repr()) + .collect::>(); + snarkvm_algorithms::msm::variable_base::VariableBaseMSM::multi_scalar_mul(coeffs, &input) + } else { + input + .into_par_iter() + .fold( + || C::Projective::zero(), + |sum, &(coeff, lag)| { + let ind = match lag { + Index::Public(i) => i, + Index::Private(i) => num_inputs + i, + }; + let coeff = BitIteratorBE::new(coeff.to_repr()); + sum + coeffs[ind].mul_bits(coeff) + }, + ) + .reduce(|| C::Projective::zero(), |a, b| a + b) + } } #[cfg(test)] diff --git a/setup-utils/Cargo.toml b/setup-utils/Cargo.toml index c87ca8da..f1636b14 100644 --- a/setup-utils/Cargo.toml +++ b/setup-utils/Cargo.toml @@ -14,11 +14,11 @@ name = "math" harness = false [dependencies] -snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", default-features = false, features = ["fft", "hash_to_curve", "crypto_hash", "blake2"] } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", default-features = false } +snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false, features = ["fft", "hash_to_curve", "crypto_hash", "blake2"] } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", default-features = false } blake2 = "0.9" blake2s_simd = { version = "0.5.11" } diff --git a/setup-utils/src/elements.rs b/setup-utils/src/elements.rs index 25b0c6cb..13e38b68 100644 --- a/setup-utils/src/elements.rs +++ b/setup-utils/src/elements.rs @@ -1,8 +1,14 @@ -use serde::{Deserialize, Serialize}; +#[cfg(feature = "parallel")] +use rayon::prelude::*; +use snarkvm_curves::AffineCurve; +use snarkvm_fields::{FieldParameters, PrimeField, Zero}; +use snarkvm_utilities::{BitIteratorBE, CanonicalDeserialize, Read}; use std::fmt; +use crate::BatchDeserializer; + /// Determines if point compression should be used. -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub enum UseCompression { Yes, No, @@ -18,7 +24,7 @@ impl fmt::Display for UseCompression { } /// Determines if points should be checked to be infinity. -#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub enum CheckForCorrectness { Full, OnlyNonZero, @@ -59,3 +65,26 @@ impl fmt::Display for ElementType { } } } + +pub fn read_vec( + mut reader: R, + compressed: UseCompression, + check_for_correctness: CheckForCorrectness, +) -> Result, crate::Error> { + let size = match compressed { + UseCompression::Yes => G::SERIALIZED_SIZE, + UseCompression::No => G::UNCOMPRESSED_SIZE, + }; + let length = u64::deserialize(&mut reader)? as usize; + let mut bytes = vec![0u8; length * size]; + reader.read_exact(&mut bytes)?; + bytes.read_batch(compressed, check_for_correctness) +} + +pub fn check_subgroup(elements: &[C]) -> core::result::Result<(), crate::Error> { + let modulus = ::Parameters::MODULUS; + match snarkvm_algorithms::cfg_iter!(elements).all(|p| p.mul_bits(BitIteratorBE::new(modulus)).is_zero()) { + true => Ok(()), + false => Err(crate::Error::IncorrectSubgroup), + } +} diff --git a/setup-utils/src/groth16_utils.rs b/setup-utils/src/groth16_utils.rs index 64faa836..db58e1a6 100644 --- a/setup-utils/src/groth16_utils.rs +++ b/setup-utils/src/groth16_utils.rs @@ -175,15 +175,20 @@ impl Groth16Params { let mut reader = std::io::Cursor::new(reader); let alpha_g1 = reader.read_element(compressed, check_input_for_correctness)?; + debug!("Read alpha_g1"); let beta_g1 = reader.read_element(compressed, check_input_for_correctness)?; + debug!("Read beta_g1"); let beta_g2 = reader.read_element(compressed, check_input_for_correctness)?; + debug!("Read beta_g2"); let position = reader.position() as usize; - let reader = &mut &reader.get_mut()[position..]; + let reader = &reader.get_mut()[position..]; + debug!("Truncated reader"); // Split the transcript in the appropriate sections let (in_coeffs_g1, in_coeffs_g2, in_alpha_coeffs_g1, in_beta_coeffs_g1, in_h_g1) = split_transcript::(reader, phase1_size, num_constraints, compressed); + debug!("Split transcript"); info!("reading groth16 parameters..."); // Read all elements in parallel @@ -245,18 +250,23 @@ fn split_transcript( // N elements per coefficient let (coeffs_g1, others) = input.split_at(g1_size * size); let (_, others) = others.split_at((phase1_size - size) * g1_size); + debug!("Split coeffs_g1"); let (coeffs_g2, others) = others.split_at(g2_size * size); let (_, others) = others.split_at((phase1_size - size) * g2_size); + debug!("Split coeffs_g2"); let (alpha_coeffs_g1, others) = others.split_at(g1_size * size); let (_, others) = others.split_at((phase1_size - size) * g1_size); + debug!("Split alpha_coeffs_g1"); let (beta_coeffs_g1, others) = others.split_at(g1_size * size); let (_, others) = others.split_at((phase1_size - size) * g1_size); + debug!("Split beta_coeffs_g1"); // N-1 for the h coeffs let (h_coeffs, _) = others.split_at(g1_size * (size - 1)); + debug!("Split h_coeffs"); (coeffs_g1, coeffs_g2, alpha_coeffs_g1, beta_coeffs_g1, h_coeffs) } diff --git a/setup-utils/src/helpers.rs b/setup-utils/src/helpers.rs index dbe45a53..cd5d1eea 100644 --- a/setup-utils/src/helpers.rs +++ b/setup-utils/src/helpers.rs @@ -6,7 +6,13 @@ use crate::{ use snarkvm_algorithms::{cfg_into_iter, cfg_iter, cfg_iter_mut}; use snarkvm_curves::{AffineCurve, Group, PairingEngine, ProjectiveCurve}; use snarkvm_fields::{Field, One, PrimeField, Zero}; -use snarkvm_utilities::{biginteger::BigInteger, rand::UniformRand, CanonicalSerialize, ConstantSerializedSize}; +use snarkvm_utilities::{ + biginteger::BigInteger, + rand::UniformRand, + BitIteratorBE, + CanonicalSerialize, + ConstantSerializedSize, +}; use blake2::{Blake2b, Digest}; use rand::{rngs::OsRng, thread_rng, CryptoRng, Rng, SeedableRng}; @@ -14,7 +20,7 @@ use rand_chacha::ChaChaRng; use std::{ convert::TryInto, io::{self, Write}, - ops::{AddAssign, Mul}, + ops::AddAssign, sync::Arc, }; @@ -48,8 +54,9 @@ pub fn print_hash(hash: &[u8]) { /// Multiply a large number of points by a scalar pub fn batch_mul(bases: &mut [C], coeff: &C::ScalarField) -> Result<()> { + let coeff = coeff.to_repr(); let mut points: Vec<_> = cfg_iter!(bases) - .map(|base| base.into_projective().mul(*coeff)) + .map(|base| base.mul_bits(BitIteratorBE::new(coeff))) .collect(); C::Projective::batch_normalization(points.as_mut_slice()); cfg_iter_mut!(bases) @@ -79,11 +86,13 @@ pub fn batch_exp( .map(|(base, exp)| { // If a coefficient was provided, multiply the exponent // by that coefficient - let exp = if let Some(coeff) = coeff { exp.mul(coeff) } else { *exp }; - + let mut exp = *exp; + if let Some(coeff) = coeff { + exp *= coeff; + } // Raise the base to the exponent (additive notation so it is executed // via a multiplication) - base.mul(exp).into_projective() + base.mul_bits(BitIteratorBE::new(exp.to_repr())) }) .collect(); // we do not use batch_normalization_into_affine because it allocates @@ -252,6 +261,7 @@ pub fn from_slice(bytes: &[u8]) -> [u8; 32] { #[cfg(test)] mod tests { use super::*; + use core::ops::Mul; use snarkvm_curves::bls12_377::{Bls12_377, Fr, G1Affine, G2Affine}; #[test] @@ -417,6 +427,8 @@ fn dense_multiexp_inner( c: u32, handle_trivial: bool, ) -> ::Projective { + let zero = G::ScalarField::zero().to_repr(); + let one = G::ScalarField::one().to_repr(); use std::sync::Mutex; // Perform this region of the multiexp. We use a different strategy - go over region in parallel, // then over another region, etc. No Arc required @@ -433,8 +445,6 @@ fn dense_multiexp_inner( let mut buckets = vec![::Projective::zero(); (1 << c) - 1]; // Accumulate the result let mut acc = G::Projective::zero(); - let zero = G::ScalarField::zero().to_repr(); - let one = G::ScalarField::one().to_repr(); for (base, &exp) in base.iter().zip(exp.iter()) { // let index = (exp.as_ref()[0] & mask) as usize; @@ -464,13 +474,13 @@ fn dense_multiexp_inner( // buckets are filled with the corresponding accumulated value, now sum let mut running_sum = G::Projective::zero(); for exp in buckets.into_iter().rev() { - running_sum.add_assign(&exp); - acc.add_assign(&running_sum); + running_sum += &exp; + acc += &running_sum; } let mut guard = this_region_rwlock.lock().expect("poisoned"); - (*guard).add_assign(&acc); + *guard += &acc; }); } }) diff --git a/setup-utils/src/io/read.rs b/setup-utils/src/io/read.rs index 3901a871..81aae4eb 100644 --- a/setup-utils/src/io/read.rs +++ b/setup-utils/src/io/read.rs @@ -5,6 +5,7 @@ use snarkvm_curves::AffineCurve; #[cfg(feature = "parallel")] use rayon::prelude::*; +use snarkvm_utilities::CanonicalDeserialize; use std::io::Read; /// Used for reading 1 group element from a serialized buffer @@ -60,9 +61,9 @@ impl Deserializer for R { compression: UseCompression, check_for_correctness: CheckForCorrectness, ) -> Result { - let point = match compression { - UseCompression::Yes => G::deserialize(self)?, - UseCompression::No => G::deserialize_uncompressed(self)?, + let point: G = match compression { + UseCompression::Yes => CanonicalDeserialize::deserialize(self)?, + UseCompression::No => CanonicalDeserialize::deserialize_uncompressed(self)?, }; if (check_for_correctness == CheckForCorrectness::Full diff --git a/setup-utils/src/io/write.rs b/setup-utils/src/io/write.rs index e163fe25..65eacff0 100644 --- a/setup-utils/src/io/write.rs +++ b/setup-utils/src/io/write.rs @@ -3,6 +3,7 @@ use crate::{buffer_size, Result, UseCompression}; use snarkvm_algorithms::cfg_chunks_mut; use snarkvm_curves::AffineCurve; +use snarkvm_utilities::CanonicalSerialize; #[cfg(feature = "parallel")] use rayon::prelude::*; @@ -30,7 +31,7 @@ pub trait BatchSerializer { impl Serializer for W { fn write_element(&mut self, element: &impl AffineCurve, compression: UseCompression) -> Result<()> { match compression { - UseCompression::Yes => element.serialize(self)?, + UseCompression::Yes => CanonicalSerialize::serialize(element, self)?, UseCompression::No => element.serialize_uncompressed(self)?, }; Ok(()) diff --git a/setup-utils/src/lib.rs b/setup-utils/src/lib.rs index 398a72fd..b44146d6 100644 --- a/setup-utils/src/lib.rs +++ b/setup-utils/src/lib.rs @@ -12,7 +12,7 @@ mod groth16_utils; pub use groth16_utils::Groth16Params; mod elements; -pub use elements::{CheckForCorrectness, ElementType, UseCompression}; +pub use elements::{check_subgroup, read_vec, CheckForCorrectness, ElementType, UseCompression}; mod helpers; pub use helpers::*; diff --git a/setup1-cli-tools/Cargo.toml b/setup1-cli-tools/Cargo.toml index 85e52cfb..54c359c2 100644 --- a/setup1-cli-tools/Cargo.toml +++ b/setup1-cli-tools/Cargo.toml @@ -13,7 +13,7 @@ name = "view-key" path = "src/view_key.rs" [dependencies] -snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM", rev = "fc997c" } +snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM", rev = "092dfd2" } anyhow = "1.0.38" age = { version = "0.7", features = ["cli-common", "armor", "plugin"] } diff --git a/setup1-cli-tools/src/public_key_extractor.rs b/setup1-cli-tools/src/public_key_extractor.rs index 4708376b..e8bcc94d 100644 --- a/setup1-cli-tools/src/public_key_extractor.rs +++ b/setup1-cli-tools/src/public_key_extractor.rs @@ -1,4 +1,4 @@ -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; use age::Decryptor; use anyhow::{anyhow, Result}; @@ -39,7 +39,7 @@ fn decrypt(passphrase: &SecretString, encrypted: &str) -> Result> } } -fn read_private_key(keys_path: &str) -> Result> { +fn read_private_key(keys_path: &str) -> Result> { let file_contents = fs::read(&keys_path)?; let keys: AleoSetupKeys = serde_json::from_slice(&file_contents)?; let passphrase = age::cli_common::read_secret("Enter your Aleo setup passphrase", "Passphrase", None) @@ -58,8 +58,6 @@ fn main() { let private_key = read_private_key(&options.path).expect("Should read a private key"); - let address = Address::from_private_key(&private_key) - .expect("Should produce a public key out of a private key") - .to_string(); + let address = Address::from_private_key(&private_key).to_string(); println!("{}", address); } diff --git a/setup1-cli-tools/src/view_key.rs b/setup1-cli-tools/src/view_key.rs index 1783da04..0f944ba1 100644 --- a/setup1-cli-tools/src/view_key.rs +++ b/setup1-cli-tools/src/view_key.rs @@ -1,8 +1,7 @@ -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, PrivateKey, ViewKey}; +use snarkvm_dpc::{testnet2::Testnet2, PrivateKey}; fn main() { let mut rng = rand::thread_rng(); - let private_key = PrivateKey::::new(&mut rng); - let view_key = ViewKey::from_private_key(&private_key).expect("Unable to derive the view key from private key"); - print!("{}", view_key); + let private_key = PrivateKey::::new(&mut rng); + print!("Private key: {}", private_key); } diff --git a/setup1-contributor/Cargo.toml b/setup1-contributor/Cargo.toml index 5ad8509d..e2fe12f0 100644 --- a/setup1-contributor/Cargo.toml +++ b/setup1-contributor/Cargo.toml @@ -14,9 +14,10 @@ phase1-coordinator = { path = "../phase1-coordinator", features = ["operator", " setup1-shared = { path = "../setup1-shared", features = ["twitter", "proof-of-work"] } setup-utils = { path = "../setup-utils", features = ["parallel"] } -snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM", rev = "fc997c" } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } + +snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } age = { version = "0.7", features = [ "cli-common", "armor", "plugin" ] } anyhow = { version = "1.0.33" } diff --git a/setup1-contributor/src/commands/contribute.rs b/setup1-contributor/src/commands/contribute.rs index d7efc786..f0719cb5 100644 --- a/setup1-contributor/src/commands/contribute.rs +++ b/setup1-contributor/src/commands/contribute.rs @@ -23,7 +23,7 @@ use phase1_coordinator::{ use setup1_shared::structures::{ContributorStatus, LockResponse, PublicSettings, TwitterInfo}; use setup_utils::calculate_hash; use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761, PairingEngine}; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey, ViewKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey, ViewKey}; use age::DecryptError; use anyhow::{Context, Result}; @@ -65,8 +65,8 @@ pub struct Contribute { pub server_url: Url, /// Public key id for this contributor: e.g. /// `aleo1h7pwa3dh2egahqj7yvq7f7e533lr0ueysaxde2ktmtu2pxdjvqfqsj607a` - pub participant_id: Address, - pub private_key: PrivateKey, + pub participant_id: Address, + pub private_key: PrivateKey, seed: Arc>, pub environment: Environment, } @@ -75,7 +75,7 @@ impl Contribute { pub fn new( opts: &ContributeOptions, environment: &Environment, - private_key: PrivateKey, + private_key: PrivateKey, seed: SecretVec, ) -> Self { // TODO (raychu86): Pass in pipelining options from the CLI. @@ -618,10 +618,7 @@ fn initialize_progress_bar() -> ProgressBar { progress_bar } -async fn get_contributor_status( - server_url: &Url, - private_key: &PrivateKey, -) -> Result { +async fn get_contributor_status(server_url: &Url, private_key: &PrivateKey) -> Result { let endpoint = "/v1/contributor/status"; let ceremony_url = server_url.join(endpoint)?; @@ -672,7 +669,7 @@ fn get_non_contributed_chunks<'r>(ceremony: &'r Round, participant_id: &str) -> struct HeartbeatData { server_url: Url, - private_key: PrivateKey, + private_key: PrivateKey, } impl HeartbeatData { @@ -695,7 +692,7 @@ impl HeartbeatData { } } -fn initiate_heartbeat(server_url: Url, private_key: PrivateKey) { +fn initiate_heartbeat(server_url: Url, private_key: PrivateKey) { let private_key = private_key.to_string(); std::thread::spawn(move || { let heartbeat_data = HeartbeatData { @@ -742,7 +739,7 @@ fn decrypt(passphrase: &SecretString, encrypted: &str) -> Result> { fn read_keys>( keys_path: P, passphrase: &SecretString, -) -> Result<(SecretVec, PrivateKey)> { +) -> Result<(SecretVec, PrivateKey)> { let mut contents = String::new(); File::open(keys_path)?.read_to_string(&mut contents)?; let keys: AleoSetupKeys = serde_json::from_str(&contents)?; diff --git a/setup1-contributor/src/reliability/mod.rs b/setup1-contributor/src/reliability/mod.rs index 69406e69..aa451d31 100644 --- a/setup1-contributor/src/reliability/mod.rs +++ b/setup1-contributor/src/reliability/mod.rs @@ -10,7 +10,7 @@ use setup1_shared::reliability::{ CoordinatorMessageName, MAXIMUM_MESSAGE_SIZE, }; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, PrivateKey}; +use snarkvm_dpc::{testnet2::Testnet2, PrivateKey}; use tokio_tungstenite::{ connect_async_with_config, tungstenite::protocol::{Message, WebSocketConfig}, @@ -25,7 +25,7 @@ mod latency; /// Builds a request with authorization header to initialize /// a WebSocket handshake later -fn prepare_request(api_url: &Url, api_path: &str, private_key: &PrivateKey) -> Result> { +fn prepare_request(api_url: &Url, api_path: &str, private_key: &PrivateKey) -> Result> { let scheme = match api_url.scheme() { "http" => "ws", "https" => "wss", @@ -47,7 +47,7 @@ fn prepare_request(api_url: &Url, api_path: &str, private_key: &PrivateKey) -> Result<()> { +pub(crate) async fn check(api_base_url: &Url, private_key: &PrivateKey) -> Result<()> { let api_path = "/v1/contributor/reliability"; let request = prepare_request(api_base_url, api_path, private_key)?; diff --git a/setup1-contributor/src/setup_keys/mod.rs b/setup1-contributor/src/setup_keys/mod.rs index 858bc44b..03bda62a 100644 --- a/setup1-contributor/src/setup_keys/mod.rs +++ b/setup1-contributor/src/setup_keys/mod.rs @@ -9,7 +9,7 @@ use anyhow::Result; use rand::{rngs::OsRng, RngCore}; use secrecy::{ExposeSecret, SecretString, SecretVec}; use serde::{Deserialize, Serialize}; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; use crate::errors::ContributeError; @@ -25,7 +25,7 @@ pub struct AleoSetupKeys { struct UnencryptedKeys { seed: SecretVec, - private_key: PrivateKey, + private_key: PrivateKey, } fn encrypt(passphrase: SecretString, secret: &[u8]) -> Result { @@ -39,9 +39,7 @@ fn encrypt(passphrase: SecretString, secret: &[u8]) -> Result { } fn encrypt_keys(unencrypted: &UnencryptedKeys, passphrase: SecretString) -> AleoSetupKeys { - let address = Address::from_private_key(&unencrypted.private_key) - .expect("Should have derived an Aleo address") - .to_string(); + let address = Address::from_private_key(&unencrypted.private_key).to_string(); let encrypted_seed = encrypt(passphrase.clone(), unencrypted.seed.expose_secret()).expect("Should have encrypted Aleo seed"); let encrypted_private_key = diff --git a/setup1-contributor/src/utils.rs b/setup1-contributor/src/utils.rs index e1226aef..3522f0bd 100644 --- a/setup1-contributor/src/utils.rs +++ b/setup1-contributor/src/utils.rs @@ -5,7 +5,7 @@ use phase1_coordinator::{ }; use setup1_shared::structures::SetupKind; use snarkvm_curves::PairingEngine; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey, ViewKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; use snarkvm_utilities::ToBytes; use anyhow::Result; @@ -88,16 +88,15 @@ pub fn create_parameters_for_chunk( } pub fn get_authorization_value( - private_key: &PrivateKey, + private_key: &PrivateKey, method: &str, path: &str, rng: &mut R, ) -> Result { - let view_key = ViewKey::try_from(private_key)?; let address = Address::try_from(private_key)?.to_string(); let message = format!("{} {}", method.to_lowercase(), path.to_lowercase()); - let signature = hex::encode(&view_key.sign(message.as_bytes(), rng)?.to_bytes_le()?); + let signature = hex::encode(&private_key.sign(message.as_bytes(), rng)?.to_bytes_le()?); let authorization = format!("Aleo {}:{}", address, signature); Ok(authorization) @@ -116,8 +115,8 @@ pub fn sign_contribution_state( let contribution_state = ContributionState::new(challenge_hash, response_hash, next_challenge_hash); let message = contribution_state.signature_message()?; - let view_key = ViewKey::::from_str(signing_key)?; - let signature = hex::encode(&view_key.sign(message.as_bytes(), rng)?.to_bytes_le()?); + let private_key = PrivateKey::::from_str(signing_key)?; + let signature = hex::encode(&private_key.sign(message.as_bytes(), rng)?.to_bytes_le()?); let contribution_file_signature = ContributionFileSignature::new(signature, contribution_state)?; diff --git a/setup1-shared/Cargo.toml b/setup1-shared/Cargo.toml index ccab18f4..6fd44835 100644 --- a/setup1-shared/Cargo.toml +++ b/setup1-shared/Cargo.toml @@ -14,7 +14,7 @@ proof-of-work = ["phase1", "setup-utils", "snarkvm-curves"] phase1 = { path = "../phase1", features = ["parallel"], optional = true } setup-utils = { path = "../setup-utils", features = ["parallel"], optional = true } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c", optional = true } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", optional = true } egg-mode = { version = "0.16", optional = true } serde = { version = "1.0", features = ["derive"] } diff --git a/setup1-verifier/Cargo.toml b/setup1-verifier/Cargo.toml index 2e33c8e5..37372047 100644 --- a/setup1-verifier/Cargo.toml +++ b/setup1-verifier/Cargo.toml @@ -15,10 +15,11 @@ phase1-coordinator = { path = "../phase1-coordinator", features= ["operator", "p setup1-shared = { version = "0.1", path = "../setup1-shared" } setup-utils = { path = "../setup-utils", features = ["parallel"] } -snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM", rev = "fc997c", features = ["parallel"] } -snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM", rev = "fc997c" } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM", rev = "fc997c" } + +snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2", features = ["parallel"] } +snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } anyhow = { version = "1.0.32" } ctrlc = { version = "3.1.7" } diff --git a/setup1-verifier/src/coordinator_requests.rs b/setup1-verifier/src/coordinator_requests.rs index 12007c2f..72e06739 100644 --- a/setup1-verifier/src/coordinator_requests.rs +++ b/setup1-verifier/src/coordinator_requests.rs @@ -23,7 +23,7 @@ impl Verifier { info!("Verifier downloading a response file at {} ", path); - let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &path)?; + let authentication = AleoAuthentication::authenticate(&self.private_key, &method, &path)?; match Client::new() .get(coordinator_api_url.join(&path).expect("Should create a path")) .header("Authorization", authentication.to_string()) @@ -69,7 +69,7 @@ impl Verifier { info!("Verifier downloading a challenge file at {} ", path); - let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &path)?; + let authentication = AleoAuthentication::authenticate(&self.private_key, &method, &path)?; match Client::new() .get(coordinator_api_url.join(&path).expect("Should create a path")) .header("Authorization", authentication.to_string()) @@ -114,7 +114,7 @@ impl Verifier { let method = "post"; let path = format!("/v1/upload/challenge/{}/{}", chunk_id, contribution_id); - let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &path)?; + let authentication = AleoAuthentication::authenticate(&self.private_key, &method, &path)?; info!( "Verifier uploading a response with size {} to {} ", diff --git a/setup1-verifier/src/main.rs b/setup1-verifier/src/main.rs index c32d685d..776c3fb1 100644 --- a/setup1-verifier/src/main.rs +++ b/setup1-verifier/src/main.rs @@ -2,7 +2,7 @@ use std::{path::PathBuf, str::FromStr}; use phase1_coordinator::environment::{Development, Environment, Parameters, Production}; use setup1_shared::structures::{PublicSettings, SetupKind}; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, ViewKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; use structopt::StructOpt; use tracing::info; use url::Url; @@ -38,8 +38,8 @@ fn universal() -> Environment { #[derive(Debug, StructOpt)] #[structopt(name = "Aleo setup verifier")] struct Options { - #[structopt(long, help = "Path to a file containing verifier view key")] - view_key: PathBuf, + #[structopt(long, help = "Path to a file containing verifier private key")] + private_key: PathBuf, #[structopt(long, help = "Coordinator api url, for example http://localhost:9000")] api_url: Url, } @@ -75,14 +75,14 @@ async fn main() { SetupKind::Universal => universal(), }; - let raw_view_key = std::fs::read_to_string(options.view_key).expect("View key not found"); - let view_key = ViewKey::::from_str(&raw_view_key).expect("Invalid view key"); - let address = Address::from_view_key(&view_key).expect("Address not derived correctly"); + let raw_private_key = std::fs::read_to_string(options.private_key).expect("View key not found"); + let private_key = PrivateKey::::from_str(&raw_private_key).expect("Invalid view key"); + let address = Address::from_private_key(&private_key); // Initialize the verifier info!("Initializing verifier..."); - let verifier = - Verifier::new(options.api_url.clone(), view_key, address, environment).expect("Failed to initialize verifier"); + let verifier = Verifier::new(options.api_url.clone(), private_key, address, environment) + .expect("Failed to initialize verifier"); verifier.start_verifier().await; } diff --git a/setup1-verifier/src/utils/authentication.rs b/setup1-verifier/src/utils/authentication.rs index 31a32be8..98a087c8 100644 --- a/setup1-verifier/src/utils/authentication.rs +++ b/setup1-verifier/src/utils/authentication.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use rand::thread_rng; use serde::{Deserialize, Serialize}; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, ViewKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; #[cfg(test)] use snarkvm_utilities::FromBytes; use snarkvm_utilities::ToBytes; @@ -43,12 +43,12 @@ impl AleoAuthentication { /// Generate the authentication header with the request method, request path, and view key. /// Returns the authorization header "Aleo
:" pub fn authenticate( - view_key: &ViewKey, + private_key: &PrivateKey, method: &str, path: &str, ) -> Result { // Derive the Aleo address used to verify the signature. - let address = Address::from_view_key(&view_key)?; + let address = Address::from_private_key(&private_key); // Form the message that is signed let message = format!("{} {}", method.to_lowercase(), path.to_lowercase()); @@ -60,7 +60,7 @@ impl AleoAuthentication { ); // Construct the authentication signature. - let signature = Self::sign(&view_key, message)?; + let signature = Self::sign(&private_key, message)?; // Construct the authentication header. Ok(AuthenticationHeader::new( @@ -71,16 +71,16 @@ impl AleoAuthentication { } /// - /// Returns a signature created by signing a message with an Aleo view key. Otherwise, + /// Returns a signature created by signing a message with an Aleo private key. Otherwise, /// returns a `VerifierError`. /// - pub fn sign(view_key: &ViewKey, message: String) -> Result { + pub fn sign(private_key: &PrivateKey, message: String) -> Result { let rng = &mut thread_rng(); trace!("Signing message - (message: {})", message); // Construct the authentication signature. - let signature = hex::encode(view_key.sign(&message.into_bytes(), rng)?.to_bytes_le()?); + let signature = hex::encode(private_key.sign(&message.into_bytes(), rng)?.to_bytes_le()?); // Construct the authentication header. Ok(signature) @@ -90,15 +90,11 @@ impl AleoAuthentication { /// Returns `true` if the signature verifies for a given address and message. /// #[cfg(test)] - pub fn verify( - address: &Address, - signature: &str, - message: String, - ) -> Result { - let view_key_signature = FromBytes::from_bytes_le(&hex::decode(signature)?)?; + pub fn verify(address: &Address, signature: &str, message: String) -> Result { + let signature = FromBytes::from_bytes_le(&hex::decode(signature)?)?; // Check that the message verifies - Ok(address.verify_signature(&message.into_bytes(), &view_key_signature)?) + Ok(address.verify_signature(&message.into_bytes(), &signature)?) } /// Verify a request is authenticated by @@ -119,7 +115,7 @@ impl AleoAuthentication { trace!("Authentication for address {} message is: {:?}", address, message); - let aleo_address = &Address::::from_str(&address)?; + let aleo_address = &Address::::from_str(&address)?; AleoAuthentication::verify(aleo_address, signature, message) } @@ -133,34 +129,34 @@ mod authentication_tests { const PATH: &str = "/v1/queue/verifier/join"; // Example view key. - const TEST_VIEW_KEY: &str = "AViewKey1cWY7CaSDuwAEXoFki7Z1JELj7ksum8JxfZGpsPLHJACx"; + const TEST_PRIVATE_KEY: &str = "APrivateKey1cWY7CaSDuwAEXoFki7Z1JELj7ksum8JxfZGpsPLHJACx"; const TEST_ADDRESS: &str = "aleo1en3lu60j0gcetvnpscvzwcxgujj069tlr3qlrm7y5kcrncxu3y8qva8p7k"; #[test] fn test_aleo_account_signature_sanity_check() { // Start by confirming the account derivation in snarkVM has not changed. - let view_key = ViewKey::::from_str(&TEST_VIEW_KEY).unwrap(); - let address = Address::from_view_key(&view_key).unwrap(); + let private_key = PrivateKey::::from_str(&TEST_PRIVATE_KEY).unwrap(); + let address = Address::from_private_key(&private_key); assert_eq!(TEST_ADDRESS, address.to_string()); let message = "hello world".to_string(); let rng = &mut thread_rng(); // Check that the account signature scheme works correctly in snarkVM. - let expected_signature = view_key.sign(&message.clone().into_bytes(), rng).unwrap(); + let expected_signature = private_key.sign(&message.clone().into_bytes(), rng).unwrap(); let signature_string = hex::encode(expected_signature.to_bytes_le().unwrap()); let candidate_signature = FromBytes::from_bytes_le(&hex::decode(signature_string).unwrap()).unwrap(); assert_eq!(expected_signature, candidate_signature); // Check that AleoAuthentication uses the account signature scheme from snarkVM correctly. - let signature_string = AleoAuthentication::sign(&view_key, message.clone()).unwrap(); + let signature_string = AleoAuthentication::sign(&private_key, message.clone()).unwrap(); let is_valid_signature = AleoAuthentication::verify(&address, &signature_string, message.clone()).unwrap(); assert!(is_valid_signature); } #[test] fn test_request_authentication() { - let view_key = ViewKey::from_str(&TEST_VIEW_KEY).unwrap(); + let private_key = PrivateKey::from_str(&TEST_PRIVATE_KEY).unwrap(); // Mock request parameters let method = "Get"; @@ -168,7 +164,7 @@ mod authentication_tests { println!("Generating Authorization header."); - let auth_header = AleoAuthentication::authenticate(&view_key, &method.to_string(), &path).unwrap(); + let auth_header = AleoAuthentication::authenticate(&private_key, &method.to_string(), &path).unwrap(); println!("Verifying request authentication"); assert!(AleoAuthentication::verify_auth(&auth_header, method.to_string(), path.to_string()).unwrap()); @@ -176,7 +172,7 @@ mod authentication_tests { #[test] fn test_failed_request_authentication() { - let view_key = ViewKey::from_str(&TEST_VIEW_KEY).unwrap(); + let private_key = PrivateKey::from_str(&TEST_PRIVATE_KEY).unwrap(); // Create mock request parameters let method = "Get"; @@ -186,7 +182,7 @@ mod authentication_tests { let incorrect_method = "Post"; - let auth_header = AleoAuthentication::authenticate(&view_key, &incorrect_method.to_string(), &path).unwrap(); + let auth_header = AleoAuthentication::authenticate(&private_key, &incorrect_method.to_string(), &path).unwrap(); // Check that the request auth does not verify assert!(!AleoAuthentication::verify_auth(&auth_header, method.to_string(), path.to_string()).unwrap()); diff --git a/setup1-verifier/src/verifier.rs b/setup1-verifier/src/verifier.rs index 88765361..d9457757 100644 --- a/setup1-verifier/src/verifier.rs +++ b/setup1-verifier/src/verifier.rs @@ -14,7 +14,7 @@ use phase1_coordinator::{ }; use setup_utils::calculate_hash; use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761}; -use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, ViewKey}; +use snarkvm_dpc::{testnet2::Testnet2, Address, PrivateKey}; use serde::{Deserialize, Serialize}; use tracing::{debug, error, info}; @@ -61,7 +61,7 @@ pub struct Verifier { pub(crate) coordinator_api_url: Url, /// The view key that will be used for server authentication - pub(crate) view_key: ViewKey, + pub(crate) private_key: PrivateKey, /// The identity of the verifier pub(crate) verifier: Participant, @@ -70,13 +70,14 @@ pub struct Verifier { pub(crate) environment: Environment, } -// Manual implementation, since ViewKey doesn't implement Clone +// Manual implementation, since PrivateKey doesn't implement Clone impl Clone for Verifier { fn clone(&self) -> Self { - let view_key = ViewKey::from_str(&self.view_key.to_string()).expect("Error cloning the verifier ViewKey"); + let private_key = + PrivateKey::from_str(&self.private_key.to_string()).expect("Error cloning the verifier PrivateKey"); Self { coordinator_api_url: self.coordinator_api_url.clone(), - view_key, + private_key, verifier: self.verifier.clone(), environment: self.environment.clone(), } @@ -89,15 +90,15 @@ impl Verifier { /// pub fn new( coordinator_api_url: Url, - view_key: ViewKey, - address: Address, + private_key: PrivateKey, + address: Address, environment: Environment, ) -> Result { let verifier_id = address.to_string(); Ok(Self { coordinator_api_url, - view_key, + private_key, verifier: Participant::Verifier(verifier_id), environment, }) @@ -267,7 +268,7 @@ impl Verifier { let contribution_state = ContributionState::new(challenge_hash, response_hash, Some(next_challenge_hash)); let message = contribution_state.signature_message()?; - let signature = AleoAuthentication::sign(&self.view_key, message)?; + let signature = AleoAuthentication::sign(&self.private_key, message)?; let contribution_file_signature = ContributionFileSignature::new(signature, contribution_state)?; @@ -409,7 +410,7 @@ impl Verifier { // It's better to panic here and stop the verifier, because // such an error is unexpected and signals about // logic errors in authentication - let authentication = AleoAuthentication::authenticate(&self.view_key, &method, &path).expect(&format!( + let authentication = AleoAuthentication::authenticate(&self.private_key, &method, &path).expect(&format!( "Failed to authenticate with method: {}, path: {}", method, path )); @@ -462,7 +463,7 @@ mod tests { use rand_xorshift::XorShiftRng; use std::str::FromStr; - const TEST_VIEW_KEY: &str = "AViewKey1cWY7CaSDuwAEXoFki7Z1JELj7ksum8JxfZGpsPLHJACx"; + const TEST_VIEW_KEY: &str = "APrivateKey1cWY7CaSDuwAEXoFki7Z1JELj7ksum8JxfZGpsPLHJACx"; pub fn test_verifier() -> Verifier { let environment: Testing = Testing::from(Parameters::TestCustom { @@ -471,12 +472,12 @@ mod tests { batch_size: 512, }); - let view_key = ViewKey::from_str(TEST_VIEW_KEY).expect("Invalid view key"); - let address = Address::from_view_key(&view_key).expect("Address not derived correctly"); + let private_key = PrivateKey::from_str(TEST_VIEW_KEY).expect("Invalid view key"); + let address = Address::from_private_key(&private_key); Verifier::new( Url::from_str("http://test_coordinator_url").unwrap(), - view_key, + private_key, address, environment.into(), ) @@ -535,7 +536,7 @@ mod tests { let message = contribution_state.signature_message().unwrap(); // Derive the verifier address - let address = Address::from_view_key(&verifier.view_key).unwrap(); + let address = Address::from_private_key(&verifier.private_key); // Check that the signature verifies assert!(AleoAuthentication::verify(&address, signature, message).unwrap()) diff --git a/setup2/Cargo.toml b/setup2/Cargo.toml index f56ad302..18a0ac26 100644 --- a/setup2/Cargo.toml +++ b/setup2/Cargo.toml @@ -9,16 +9,16 @@ license = "GPL-3.0" edition = "2018" [dependencies] -phase2 = { path = "../phase2" } -setup-utils = { path = "../setup-utils" } +phase2 = { path = "../phase2", features = ["cli"] } +setup-utils = { path = "../setup-utils", features = [ "cli" ] } -snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-parameters = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } -snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" } +snarkvm-algorithms = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-dpc = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-fields = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-parameters = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-r1cs = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } +snarkvm-utilities = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "092dfd2" } anyhow = { version = "1.0.37" } cfg-if = "1.0" @@ -29,7 +29,9 @@ hex-literal = { version = "0.3.1", optional = true } memmap = { version = "0.7.0", optional = true } rand = { version = "0.8" } rand_chacha = { version = "0.3" } +serde = { version = "1.0", features = ["derive"] } thiserror = { version = "1.0.22" } +tracing = { version = "0.1.21" } tracing-subscriber = { version = "0.3", features = ["env-filter", "time"] } [features] @@ -37,3 +39,7 @@ default = ["cli"] parallel = ["phase2/parallel", "setup-utils/parallel"] cli = ["gumdrop", "hex-literal", "memmap", "parallel", "phase2/cli", "setup-utils/cli"] wasm = ["phase2/wasm", "setup-utils/wasm"] + +[[bin]] +name = "phase2" +required-features = ["cli"] \ No newline at end of file diff --git a/setup2/scripts/phase2_chunked.sh b/setup2/scripts/phase2_chunked.sh new file mode 100755 index 00000000..0ef47538 --- /dev/null +++ b/setup2/scripts/phase2_chunked.sh @@ -0,0 +1,67 @@ +#!/bin/bash -e + +rm -f challenge* response* new_challenge* new_response* new_new_challenge_* processed* initial_ceremony* response_list* combined* seed* chunk* + +# export RUSTFLAGS="-C target-feature=+bmi2,+adx" +CARGO_VER="" +PROVING_SYSTEM=groth16 +POWER=19 +BATCH=524288 +CHUNK_SIZE=524288 +CURVE="bw6" +PATH_PHASE1="../../phase1-cli/scripts/phase1_final" +SEED1=$(tr -dc 'A-F0-9' < /dev/urandom | head -c32) +echo $SEED1 > seed1 +SEED2=$(tr -dc 'A-F0-9' < /dev/urandom | head -c32) +echo $SEED2 > seed2 + +function check_hash() { + test "`xxd -p -c 64 $1.hash`" = "`b2sum $1 | awk '{print $1}'`" +} + +cargo $CARGO_VER build --release --bin setup2 + +phase2_new="cargo run --release --features cli -- --curve-type $CURVE --chunk-size $CHUNK_SIZE --batch-size $BATCH --contribution-mode full --is-inner false" +phase2_chunked="cargo run --release --bin setup2 --features cli -- --curve-type $CURVE --chunk-size $CHUNK_SIZE --batch-size $BATCH --contribution-mode full --proving-system $PROVING_SYSTEM" +phase2_1="cargo run --release --bin setup2 --features cli -- --curve-type $CURVE --batch-size $BATCH --contribution-mode chunked --chunk-size $CHUNK_SIZE --seed seed1 --proving-system $PROVING_SYSTEM" +phase2_2="cargo run --release --bin setup2 --features cli -- --curve-type $CURVE --batch-size $BATCH --contribution-mode chunked --chunk-size $CHUNK_SIZE --seed seed2 --proving-system $PROVING_SYSTEM" +####### Phase 2 + +# todo +MAX_CHUNK_INDEX=3 + +pwd + +ls $PATH_PHASE1 + +env RUST_LOG=trace $phase2_new new --challenge-fname challenge --challenge-hash-fname challenge.verified.hash --phase1-fname $PATH_PHASE1 --phase1-powers $POWER --num-validators 1 --num-epochs 1 for i in $(seq 0 $(($MAX_CHUNK_INDEX/2))); do + echo "Contributing and verifying chunk $i..." + $phase2_1 --chunk-index $i contribute --challenge-fname challenge.$i --challenge-hash-fname challenge.$i.hash --response-fname response_$i --response-hash-fname response_$i.hash + check_hash challenge.$i + check_hash response_$i + $phase2_1 --chunk-index $i verify --challenge-fname challenge.$i --challenge-hash-fname challenge_$i.verified.hash --response-fname response_$i --response-hash-fname response_$i.verified.hash + rm response_$i.hash + $phase2_2 --chunk-index $i contribute --challenge-fname response_$i --challenge-hash-fname response_$i.hash --response-fname new_response_$i --response-hash-fname new_response_$i.hash + check_hash new_response_$i + $phase2_2 --chunk-index $i verify --challenge-fname response_$i --challenge-hash-fname response_$i.verified.hash --response-fname new_response_$i --response-hash-fname new_response_$i.verified.hash + rm challenge.$i response_$i # no longer needed + echo new_response_$i >> response_list +done + +for i in $(seq $(($MAX_CHUNK_INDEX/2 + 1)) $MAX_CHUNK_INDEX); do + echo "Contributing and verifying chunk $i..." + $phase2_2 --chunk-index $i contribute --challenge-fname challenge.$i --challenge-hash-fname challenge.$i.hash --response-fname response_$i --response-hash-fname response_$i.hash + check_hash challenge.$i + check_hash response_$i + $phase2_2 --chunk-index $i verify --challenge-fname challenge.$i --challenge-hash-fname challenge_$i.verified.hash --response-fname response_$i --response-hash-fname response_$i.verified.hash + rm response_$i.hash + $phase2_1 --chunk-index $i contribute --challenge-fname response_$i --challenge-hash-fname response_$i.hash --response-fname new_response_$i --response-hash-fname new_response_$i.hash + check_hash new_response_$i + $phase2_1 --chunk-index $i verify --challenge-fname response_$i --challenge-hash-fname response_$i.verified.hash --response-fname new_response_$i --response-hash-fname new_response_$i.verified.hash + rm challenge.$i response_$i # no longer needed + echo new_response_$i >> response_list +done + +$phase2_chunked combine --response-list-fname response_list --initial-query-fname challenge.query --initial-full-fname challenge.full --combined-fname combined + +echo "Done!" diff --git a/setup2/src/bin/phase2.rs b/setup2/src/bin/phase2.rs new file mode 100644 index 00000000..2f94909a --- /dev/null +++ b/setup2/src/bin/phase2.rs @@ -0,0 +1,64 @@ +use setup2::*; + +use gumdrop::Options; +use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761}; +use std::{process, time::Instant}; +use tracing::{error, info}; +use tracing_subscriber::{ + filter::EnvFilter, + fmt::{time, Subscriber}, +}; + +fn execute_cmd(opts: Phase2Opts) { + let command = opts.clone().command.unwrap_or_else(|| { + error!("No command was provided."); + error!("{}", Phase2Opts::usage()); + process::exit(2) + }); + + let now = Instant::now(); + + match command { + Command::New(opt) => { + new(&opts, &opt).unwrap(); + } + Command::Contribute(opt) => { + let seed = hex::decode( + &std::fs::read_to_string(&opts.seed) + .expect("should have read seed") + .trim(), + ) + .expect("seed should be a hex string"); + let mut rng = setup_utils::derive_rng_from_seed(&seed); + contribute(&opts, &opt, &mut rng).unwrap(); + } + Command::Verify(opt) => { + verify(&opts, &opt).unwrap(); + } + Command::Combine(opt) => { + if opts.is_inner { + combine::(&opt); + } else { + combine::(&opt); + } + } + }; + + let new_now = Instant::now(); + info!("Executing {:?} took: {:?}", opts, new_now.duration_since(now)); +} + +fn main() { + Subscriber::builder() + .with_timer(time::UtcTime::rfc_3339()) + .with_env_filter(EnvFilter::from_default_env()) + .init(); + let opts = SNARKOpts::parse_args_default_or_exit(); + + let opts: Phase2Opts = Phase2Opts::parse_args_default_or_exit(); + + match opts.curve_kind { + CurveKind::Bls12_377 => execute_cmd(opts), + CurveKind::BW6 => execute_cmd(opts), + }; +} diff --git a/setup2/src/cli/contribute.rs b/setup2/src/cli/contribute.rs deleted file mode 100644 index ac8c42f2..00000000 --- a/setup2/src/cli/contribute.rs +++ /dev/null @@ -1,57 +0,0 @@ -use phase2::{chunked_groth16::contribute as chunked_contribute, keypair::PublicKey}; -use setup_utils::Result; - -use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761}; - -use fs_err::OpenOptions; -use gumdrop::Options; -use memmap::MmapOptions; -use rand::{CryptoRng, Rng}; - -#[derive(Debug, Options, Clone)] -pub struct ContributeOpts { - help: bool, - #[options( - help = "the previous contribution - the action will happen in place", - default = "challenge" - )] - pub data: String, - #[options(help = "the batches which can be loaded in memory", default = "50000")] - pub batch: usize, - #[options( - help = "the beacon hash to be used if running a beacon contribution", - default = "0000000000000000000a558a61ddc8ee4e488d647a747fe4dcc362fe2026c620" - )] - pub beacon_hash: String, - - #[options(help = "setup the inner or the outer circuit?")] - pub is_inner: bool, -} - -pub fn contribute(opts: &ContributeOpts, rng: &mut R) -> Result<()> { - let file = OpenOptions::new() - .read(true) - .write(true) - .open(&opts.data) - .expect("could not open file for writing the new MPC parameters "); - let metadata = file.metadata()?; - // extend the file by 1 pubkey - if opts.is_inner { - file.set_len(metadata.len() + PublicKey::::size() as u64)?; - } else { - file.set_len(metadata.len() + PublicKey::::size() as u64)?; - } - let mut file = unsafe { - MmapOptions::new() - .map_mut(file.file()) - .expect("unable to create a memory map for input") - }; - - if opts.is_inner { - chunked_contribute::(&mut file, rng, opts.batch)?; - } else { - chunked_contribute::(&mut file, rng, opts.batch)?; - } - - Ok(()) -} diff --git a/setup2/src/cli/mod.rs b/setup2/src/cli/mod.rs deleted file mode 100644 index c601eb02..00000000 --- a/setup2/src/cli/mod.rs +++ /dev/null @@ -1,32 +0,0 @@ -pub use new::{new, NewOpts}; -mod new; - -mod contribute; -pub use contribute::{contribute, ContributeOpts}; - -mod verify; -pub use verify::{verify, VerifyOpts}; - -use gumdrop::Options; - -// The supported commands -#[derive(Debug, Options, Clone)] -pub enum Command { - #[options(help = "creates new parameters for the ceremony which MUST be built upon")] - New(NewOpts), - #[options(help = "contribute to ceremony by transforming the circuit parameters")] - Contribute(ContributeOpts), - #[options(help = "contribute randomness via a random beacon (e.g. a bitcoin block header hash)")] - Beacon(ContributeOpts), - #[options(help = "verify the contributions so far")] - Verify(VerifyOpts), -} - -#[derive(Debug, Options, Clone)] -pub struct SNARKOpts { - help: bool, - // #[options(help = "the size of batches to process", default = "256")] - // pub batch_size: usize, - #[options(command)] - pub command: Option, -} diff --git a/setup2/src/cli/new.rs b/setup2/src/cli/new.rs deleted file mode 100644 index aca7c37d..00000000 --- a/setup2/src/cli/new.rs +++ /dev/null @@ -1,254 +0,0 @@ -use phase2::parameters::MPCParameters; -use setup_utils::{log_2, CheckForCorrectness, Groth16Params, UseCompression}; -use snarkvm_algorithms::{SNARK, SRS}; -use snarkvm_curves::PairingEngine; -use snarkvm_dpc::{ - parameters::testnet2::{Testnet2DPC, Testnet2Parameters}, - prelude::*, -}; -use snarkvm_fields::Field; -use snarkvm_r1cs::{ConstraintCounter, ConstraintSynthesizer}; - -use gumdrop::Options; -use memmap::MmapOptions; -use phase2::parameters::circuit_to_qap; -use rand::{RngCore, SeedableRng}; -use rand_chacha::ChaChaRng; -use std::fs::OpenOptions; - -type AleoInner = ::InnerCurve; -type AleoOuter = ::OuterCurve; - -const COMPRESSION: UseCompression = UseCompression::No; - -pub const SEED_LENGTH: usize = 32; -pub type Seed = [u8; SEED_LENGTH]; - -#[derive(Debug, Clone)] -pub enum CurveKind { - Bls12_377, - BW6, -} - -pub fn curve_from_str(src: &str) -> std::result::Result { - let curve = match src.to_lowercase().as_str() { - "bls12_377" => CurveKind::Bls12_377, - "bw6" => CurveKind::BW6, - _ => return Err("unsupported curve.".to_string()), - }; - Ok(curve) -} - -#[derive(Debug, Options, Clone)] -pub struct NewOpts { - help: bool, - #[options(help = "the path to the phase1 parameters", default = "phase1")] - pub phase1: String, - #[options(help = "the total number of coefficients (in powers of 2) which were created after processing phase 1")] - pub phase1_size: u32, - #[options(help = "the challenge file name to be created", default = "challenge")] - pub output: String, - - #[options( - help = "the elliptic curve to use", - default = "bls12_377", - parse(try_from_str = "curve_from_str") - )] - pub curve_type: CurveKind, - - #[options(help = "setup the inner or the outer circuit?")] - pub is_inner: bool, -} - -pub fn new(opt: &NewOpts) -> anyhow::Result<()> { - if opt.is_inner { - let circuit = InnerCircuit::::blank(); - generate_params::(opt, circuit) - } else { - let mut seed: Seed = [0; SEED_LENGTH]; - rand::thread_rng().fill_bytes(&mut seed[..]); - let rng = &mut ChaChaRng::from_seed(seed); - let dpc = Testnet2DPC::load(false)?; - - let noop_circuit = dpc - .noop_program - .find_circuit_by_index(0) - .ok_or(DPCError::MissingNoopCircuit)?; - let private_program_input = dpc.noop_program.execute_blank(noop_circuit.circuit_id())?; - - let inner_snark_parameters = ::InnerSNARK::setup( - &InnerCircuit::::blank(), - &mut SRS::CircuitSpecific(rng), - )?; - - let inner_snark_vk: <::InnerSNARK as SNARK>::VerifyingKey = - inner_snark_parameters.1.clone().into(); - let inner_snark_proof = ::InnerSNARK::prove( - &inner_snark_parameters.0, - &InnerCircuit::::blank(), - rng, - )?; - - let circuit = - OuterCircuit::::blank(inner_snark_vk, inner_snark_proof, private_program_input); - generate_params::(opt, circuit) - } -} - -pub fn new_challenge(opt: &NewOpts) -> anyhow::Result<()> { - if opt.is_inner { - let circuit = InnerCircuit::::blank(); - generate_params_chunked::(opt, circuit) - } else { - let mut seed: Seed = [0; SEED_LENGTH]; - rand::thread_rng().fill_bytes(&mut seed[..]); - let rng = &mut ChaChaRng::from_seed(seed); - let dpc = Testnet2DPC::load(false)?; - - let noop_circuit = dpc - .noop_program - .find_circuit_by_index(0) - .ok_or(DPCError::MissingNoopCircuit)?; - let private_program_input = dpc.noop_program.execute_blank(noop_circuit.circuit_id())?; - - let inner_snark_parameters = ::InnerSNARK::setup( - &InnerCircuit::::blank(), - &mut SRS::CircuitSpecific(rng), - )?; - - let inner_snark_vk: <::InnerSNARK as SNARK>::VerifyingKey = - inner_snark_parameters.1.clone().into(); - let inner_snark_proof = ::InnerSNARK::prove( - &inner_snark_parameters.0, - &InnerCircuit::::blank(), - rng, - )?; - - let circuit = - OuterCircuit::::blank(inner_snark_vk, inner_snark_proof, private_program_input); - generate_params_chunked::(opt, circuit) - } -} - -/// Returns the number of powers required for the Phase 2 ceremony -/// = log2(aux + inputs + constraints) -fn ceremony_size>(circuit: &C) -> usize { - let mut counter = ConstraintCounter { - num_public_variables: 0, - num_private_variables: 0, - num_constraints: 0, - }; - circuit - .clone() - .generate_constraints(&mut counter) - .expect("could not calculate number of required constraints"); - let phase2_size = std::cmp::max( - counter.num_constraints, - counter.num_private_variables + counter.num_public_variables + 1, - ); - let power = log_2(phase2_size) as u32; - - // get the nearest power of 2 - if phase2_size < 2usize.pow(power) { - 2usize.pow(power + 1) - } else { - phase2_size - } -} - -pub fn generate_params(opt: &NewOpts, circuit: C) -> anyhow::Result<()> -where - E: PairingEngine, - C: Clone + ConstraintSynthesizer, -{ - let phase1_transcript = OpenOptions::new() - .read(true) - .write(true) - .open(&opt.phase1) - .expect("could not read phase 1 transcript file"); - let mut phase1_transcript = unsafe { - MmapOptions::new() - .map_mut(&phase1_transcript) - .expect("unable to create a memory map for input") - }; - let mut output = OpenOptions::new() - .read(false) - .write(true) - .create_new(true) - .open(&opt.output) - .expect("could not open file for writing the MPC parameters "); - - let phase2_size = ceremony_size(&circuit); - let keypair = circuit_to_qap::(circuit)?; - // Read `num_constraints` Lagrange coefficients from the Phase1 Powers of Tau which were - // prepared for this step. This will fail if Phase 1 was too small. - let phase1 = Groth16Params::::read( - &mut phase1_transcript, - COMPRESSION, - CheckForCorrectness::No, // No need to check for correctness, since this has been processed by the coordinator. - 2usize.pow(opt.phase1_size), - phase2_size, - )?; - - // Generate the initial transcript - let mpc = MPCParameters::new(keypair, phase1)?; - mpc.write(&mut output)?; - - Ok(()) -} - -pub fn generate_params_chunked(opt: &NewOpts, circuit: C) -> anyhow::Result<()> -where - E: PairingEngine, - C: Clone + ConstraintSynthesizer, -{ - let phase1_transcript = OpenOptions::new() - .read(true) - .write(true) - .open(&opt.phase1) - .expect("could not read phase 1 transcript file"); - let mut phase1_transcript = unsafe { - MmapOptions::new() - .map_mut(&phase1_transcript) - .expect("unable to create a memory map for input") - }; - let mut output = OpenOptions::new() - .read(false) - .write(true) - .create_new(true) - .open(&opt.output) - .expect("could not open file for writing the MPC parameters "); - - let phase2_size = ceremony_size(&circuit); - // Read `num_constraints` Lagrange coefficients from the Phase1 Powers of Tau which were - // prepared for this step. This will fail if Phase 1 was too small. - let phase1 = Groth16Params::::read( - &mut phase1_transcript, - COMPRESSION, - CheckForCorrectness::No, // No need to check for correctness, since this has been processed by the coordinator. - 2usize.pow(opt.phase1_size), - phase2_size, - )?; - - let compressed = UseCompression::Yes; - let mut writer = vec![]; - phase1.write(&mut writer, compressed).unwrap(); - let chunk_size = phase2_size / 3; - - let (full_mpc_parameters, _, _) = MPCParameters::::new_from_buffer_chunked( - circuit, - writer.as_mut(), - UseCompression::No, - CheckForCorrectness::No, - 2usize.pow(opt.phase1_size), - phase2_size, - chunk_size, - ) - .unwrap(); - - // Generate the initial transcript - //let mpc = MPCParameters::new(keypair, phase1)?; - full_mpc_parameters.write(&mut output)?; - - Ok(()) -} diff --git a/setup2/src/combine.rs b/setup2/src/combine.rs new file mode 100644 index 00000000..529f8e87 --- /dev/null +++ b/setup2/src/combine.rs @@ -0,0 +1,79 @@ +use phase2::parameters::MPCParameters; +use setup_utils::{print_hash, CheckForCorrectness, UseCompression}; + +use snarkvm_curves::PairingEngine; +use snarkvm_utilities::CanonicalSerialize; + +use std::{ + fs::File, + io::{BufRead, BufReader}, +}; +use tracing::info; + +use crate::{CombineOpts, COMPRESS_CONTRIBUTE_OUTPUT}; + +pub fn combine(combine_opts: &CombineOpts) { + info!("Combining phase 2"); + + let response_list_reader = + BufReader::new(File::open(&combine_opts.response_list_fname).expect("should have opened the response list")); + + let full_contents = std::fs::read(&combine_opts.initial_full_fname).expect("should have initial full parameters"); + let full_parameters = MPCParameters::::read_fast( + full_contents.as_slice(), + UseCompression::No, + CheckForCorrectness::No, + false, + ) + .expect("should have read full parameters"); + + let mut query_contents = + std::io::Cursor::new(std::fs::read(&combine_opts.initial_query_fname).expect("should have read initial query")); + let query_parameters = + MPCParameters::::read_groth16_fast(&mut query_contents, UseCompression::No, CheckForCorrectness::No, false) + .expect("should have deserialized initial query params"); + + let parameters_compressed = COMPRESS_CONTRIBUTE_OUTPUT; + let mut all_parameters = vec![]; + for line in response_list_reader.lines() { + let line = line.expect("should have read line"); + let contents = std::fs::read(line).expect("should have read response"); + let parameters = MPCParameters::::read_fast( + contents.as_slice(), + parameters_compressed, + CheckForCorrectness::No, + false, + ) + .expect("should have read parameters"); + all_parameters.push(parameters); + } + + let combined = + MPCParameters::::combine(&query_parameters, &all_parameters).expect("should have combined parameters"); + + let contributions_hash = full_parameters + .verify(&combined) + .expect("should have verified successfully"); + + info!("Contributions hashes:"); + for contribution_hash in contributions_hash { + print_hash(&contribution_hash[..]); + } + + let mut combined_contents = vec![]; + combined + .write(&mut combined_contents) + .expect("should have written combined"); + std::fs::write(&combine_opts.combined_fname, &combined_contents).expect("should have written combined file"); + + let mut combined_parameters_contents = vec![]; + combined + .params + .serialize_uncompressed(&mut combined_parameters_contents) + .expect("should have serialized combined parameters"); + std::fs::write( + format!("{}.params", combine_opts.combined_fname), + &combined_parameters_contents, + ) + .expect("should have written combined parameters file"); +} diff --git a/setup2/src/contribute.rs b/setup2/src/contribute.rs new file mode 100644 index 00000000..68fd2cd3 --- /dev/null +++ b/setup2/src/contribute.rs @@ -0,0 +1,37 @@ +use crate::{ContributeOpts, Phase2Opts}; +use phase2::{chunked_groth16::contribute as chunked_contribute, keypair::PublicKey}; +use setup_utils::Result; + +use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761}; + +use fs_err::OpenOptions; +use memmap::MmapOptions; +use rand::{CryptoRng, Rng}; + +pub fn contribute(phase2_opts: &Phase2Opts, opts: &ContributeOpts, rng: &mut R) -> Result<()> { + let file = OpenOptions::new() + .read(true) + .write(true) + .open(&opts.data) + .expect("could not open file for writing the new MPC parameters "); + let metadata = file.metadata()?; + // extend the file by 1 pubkey + if phase2_opts.is_inner { + file.set_len(metadata.len() + PublicKey::::size() as u64)?; + } else { + file.set_len(metadata.len() + PublicKey::::size() as u64)?; + } + let mut file = unsafe { + MmapOptions::new() + .map_mut(file.file()) + .expect("unable to create a memory map for input") + }; + + if phase2_opts.is_inner { + chunked_contribute::(&mut file, rng, phase2_opts.batch_size)?; + } else { + chunked_contribute::(&mut file, rng, phase2_opts.batch_size)?; + } + + Ok(()) +} diff --git a/setup2/src/lib.rs b/setup2/src/lib.rs new file mode 100644 index 00000000..52d23430 --- /dev/null +++ b/setup2/src/lib.rs @@ -0,0 +1,166 @@ +pub use new::new; +use setup_utils::UseCompression; +mod new; + +mod combine; +pub use combine::combine; + +mod contribute; +pub use contribute::contribute; + +mod verify; +pub use verify::verify; + +use gumdrop::Options; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone)] +pub enum CurveKind { + Bls12_377, + BW6, +} + +#[derive(Clone, PartialEq, Eq, Debug, Copy, Serialize, Deserialize)] +pub enum ContributionMode { + Full, + Chunked, +} + +pub fn curve_from_str(src: &str) -> std::result::Result { + let curve = match src.to_lowercase().as_str() { + "bls12_377" => CurveKind::Bls12_377, + "bw6" => CurveKind::BW6, + _ => return Err("unsupported curve.".to_string()), + }; + Ok(curve) +} + +pub fn contribution_mode_from_str(src: &str) -> Result { + let mode = match src.to_lowercase().as_str() { + "full" => ContributionMode::Full, + "chunked" => ContributionMode::Chunked, + _ => return Err("unsupported contribution mode. Currently supported: full, chunked".to_string()), + }; + Ok(mode) +} + +pub const COMPRESS_CONTRIBUTE_INPUT: UseCompression = UseCompression::No; +pub const COMPRESS_CONTRIBUTE_OUTPUT: UseCompression = UseCompression::Yes; +pub const COMBINED_IS_COMPRESSED: UseCompression = UseCompression::No; + +#[derive(Debug, Options, Clone)] +pub struct Phase2Opts { + help: bool, + #[options(help = "the seed to derive private elements from")] + pub seed: String, + #[options( + help = "the contribution mode", + default = "chunked", + parse(try_from_str = "contribution_mode_from_str") + )] + pub contribution_mode: ContributionMode, + #[options(help = "the chunk index to process")] + pub chunk_index: usize, + #[options(help = "the chunk size")] + pub chunk_size: usize, + #[options( + help = "the elliptic curve to use", + default = "bls12_377", + parse(try_from_str = "curve_from_str") + )] + pub curve_kind: CurveKind, + #[options(help = "the size of batches to process", default = "16384")] + pub batch_size: usize, + #[options(command)] + pub command: Option, + #[options( + help = "whether to always check whether incoming challenges are in correct subgroup and non-zero", + default = "false" + )] + pub force_correctness_checks: bool, + #[options(help = "is this setup for the inner circuit?", default = "true")] + pub is_inner: bool, +} + +// The supported commands +#[derive(Debug, Options, Clone)] +pub enum Command { + // this creates a new challenge + #[options(help = "creates a new challenge for the ceremony")] + New(NewOpts), + #[options(help = "contribute to ceremony by producing a response to a challenge")] + Contribute(ContributeOpts), + #[options(help = "verify the contributions so far and generate a new challenge, for a single chunk")] + Verify(VerifyOpts), + #[options(help = "combine the contributions and verify the final parameters")] + Combine(CombineOpts), +} + +// Options for the Contribute command +#[derive(Debug, Options, Clone)] +pub struct NewOpts { + help: bool, + #[options(help = "the challenge file name to be created", default = "challenge")] + pub challenge_fname: String, + #[options(help = "the new challenge file hash", default = "challenge.verified.hash")] + pub challenge_hash_fname: String, + #[options(help = "the list of challenge files", default = "new_challenge_list")] + pub challenge_list_fname: String, + #[options(help = "phase 1 file name", default = "phase1")] + pub phase1_fname: String, + #[options(help = "phase 1 powers")] + pub phase1_powers: usize, + #[options(help = "number of validators")] + pub num_validators: usize, + #[options(help = "number of epochs")] + pub num_epochs: usize, + #[options(help = "circuit file name", default = "circuit.constraints")] + pub circuit_fname: String, +} + +// Options for the Contribute command +#[derive(Debug, Options, Clone)] +pub struct ContributeOpts { + help: bool, + #[options( + help = "the provided challenge file which will be read and to which the output will be written", + default = "challenge" + )] + pub data: String, + #[options( + help = "the beacon hash to be used if running a beacon contribution", + default = "0000000000000000000a558a61ddc8ee4e488d647a747fe4dcc362fe2026c620" + )] + pub beacon_hash: String, +} + +#[derive(Debug, Options, Clone)] +pub struct VerifyOpts { + help: bool, + #[options(help = "the provided challenge file", default = "challenge")] + pub before: String, + #[options(help = "the provided response file which will be verified", default = "response")] + pub after: String, +} + +#[derive(Debug, Options, Clone)] +pub struct CombineOpts { + help: bool, + #[options(help = "the provided query initial file", default = "challenge")] + pub initial_query_fname: String, + #[options(help = "the provided full initial file", default = "challenge")] + pub initial_full_fname: String, + #[options(help = "the response files which will be combined", default = "response_list")] + pub response_list_fname: String, + #[options(help = "the combined response file", default = "combined")] + pub combined_fname: String, +} + +#[derive(Debug, Options, Clone)] +pub struct SNARKOpts { + help: bool, + // #[options(help = "the size of batches to process", default = "256")] + // pub batch_size: usize, + #[options(command)] + pub command: Option, +} diff --git a/setup2/src/main.rs b/setup2/src/main.rs deleted file mode 100644 index 52281cb8..00000000 --- a/setup2/src/main.rs +++ /dev/null @@ -1,56 +0,0 @@ -use cfg_if::cfg_if; - -cfg_if! { - if #[cfg(not(feature = "wasm"))] { - mod cli; - use cli::*; - - use setup_utils::{beacon_randomness, from_slice, get_rng, user_system_randomness}; - - use gumdrop::Options; - use std::{process, time::Instant}; - use tracing_subscriber::{ - filter::EnvFilter, - fmt::{time, Subscriber}, - }; - - fn main() { - Subscriber::builder() - .with_timer(time::UtcTime::rfc_3339()) - .with_env_filter(EnvFilter::from_default_env()) - .init(); - let opts = SNARKOpts::parse_args_default_or_exit(); - - let command = opts.clone().command.unwrap_or_else(|| { - eprintln!("No command was provided."); - eprintln!("{}", SNARKOpts::usage()); - process::exit(2) - }); - - let now = Instant::now(); - let res = match command { - Command::New(ref opt) => new(&opt).unwrap(), - Command::Contribute(ref opt) => { - // contribute to the randomness - let mut rng = get_rng(&user_system_randomness()); - contribute(&opt, &mut rng).unwrap() - } - Command::Beacon(ref opt) => { - // use the beacon's randomness - let beacon_hash = hex::decode(&opt.beacon_hash).expect("could not hex decode beacon hash"); - let mut rng = get_rng(&beacon_randomness(from_slice(&beacon_hash))); - contribute(&opt, &mut rng).unwrap() - } - Command::Verify(ref opt) => verify(&opt).unwrap(), - }; - - let new_now = Instant::now(); - println!( - "Executing {:?} took: {:?}. Result {:?}", - opts, - new_now.duration_since(now), - res, - ); - } - } -} diff --git a/setup2/src/new.rs b/setup2/src/new.rs new file mode 100644 index 00000000..49ce4b1e --- /dev/null +++ b/setup2/src/new.rs @@ -0,0 +1,189 @@ +use phase2::parameters::MPCParameters; +use setup_utils::{log_2, CheckForCorrectness, UseCompression}; +use snarkvm_algorithms::{CRH, SNARK, SRS}; +use snarkvm_curves::PairingEngine; +use snarkvm_dpc::{ + network::testnet2::Testnet2, + traits::Network, + AleoLocator, + AleoObject, + Execution, + Function, + InnerCircuit, + Noop, + NoopPrivateVariables, + OuterCircuit, + ProgramPrivateVariables, + ProgramPublicVariables, +}; +use snarkvm_fields::Field; +use snarkvm_r1cs::{ConstraintCounter, ConstraintSynthesizer}; +use snarkvm_utilities::CanonicalSerialize; +use tracing::{debug, info}; + +use memmap::MmapOptions; +use rand::{RngCore, SeedableRng}; +use rand_chacha::ChaChaRng; +use setup_utils::calculate_hash; +use std::{fs::OpenOptions, io::Write}; + +use crate::{NewOpts, Phase2Opts}; + +type AleoInner = ::InnerCurve; +type AleoOuter = ::OuterCurve; + +const COMPRESSION: UseCompression = UseCompression::No; + +pub const SEED_LENGTH: usize = 32; +pub type Seed = [u8; SEED_LENGTH]; + +pub fn new(phase2_opts: &Phase2Opts, new_opts: &NewOpts) -> anyhow::Result<()> { + if phase2_opts.is_inner { + let circuit = InnerCircuit::::blank(); + generate_params_chunked::(phase2_opts, new_opts, circuit) + } else { + let mut seed: Seed = [0; SEED_LENGTH]; + rand::thread_rng().fill_bytes(&mut seed[..]); + let rng = &mut ChaChaRng::from_seed(seed); + + // Generate inner circuit parameters and proof for verification in the outer circuit. + let inner_circuit = InnerCircuit::::blank(); + let (inner_proving_key, inner_verifying_key) = + ::InnerSNARK::setup(&inner_circuit, &mut SRS::CircuitSpecific(rng)).unwrap(); + + let inner_proof = AleoObject::from( + ::InnerSNARK::prove(&inner_proving_key, &inner_circuit, rng).unwrap(), + ); + + let transition_id = AleoLocator::from(<::TransitionIDCRH as CRH>::Output::default()); + let noop_execution = Execution { + program_id: *Testnet2::noop_program_id(), + program_path: Testnet2::noop_program_path().clone(), + verifying_key: Testnet2::noop_circuit_verifying_key().clone(), + proof: Noop::::new() + .execute( + ProgramPublicVariables::new(transition_id), + &NoopPrivateVariables::::new_blank().unwrap(), + ) + .unwrap(), + }; + let outer_circuit = OuterCircuit::::blank(inner_verifying_key, inner_proof, noop_execution); + + generate_params_chunked::(phase2_opts, new_opts, outer_circuit) + } +} + +/// Returns the number of powers required for the Phase 2 ceremony +/// = log2(aux + inputs + constraints) +fn ceremony_size>(circuit: &C) -> usize { + let mut counter = ConstraintCounter { + num_public_variables: 0, + num_private_variables: 0, + num_constraints: 0, + }; + circuit + .clone() + .generate_constraints(&mut counter) + .expect("could not calculate number of required constraints"); + let phase2_size = std::cmp::max( + counter.num_constraints, + counter.num_private_variables + counter.num_public_variables + 1, + ); + debug!("Expected phase2_size: {}", phase2_size); + let power = log_2(phase2_size) as u32; + + // get the nearest power of 2 + if phase2_size < 2usize.pow(power) { + 2usize.pow(power + 1) + } else { + phase2_size + } +} + +pub fn generate_params_chunked(phase2_opts: &Phase2Opts, new_opts: &NewOpts, circuit: C) -> anyhow::Result<()> +where + E: PairingEngine, + C: Clone + ConstraintSynthesizer, +{ + let phase1_transcript = OpenOptions::new() + .read(true) + .write(true) + .open(&new_opts.phase1_fname) + .expect("could not read phase 1 transcript file"); + let mut phase1_transcript = unsafe { + MmapOptions::new() + .map_mut(&phase1_transcript) + .expect("unable to create a memory map for input") + }; + let phase2_size = ceremony_size(&circuit); + // Read `num_constraints` Lagrange coefficients from the Phase1 Powers of Tau which were + // prepared for this step. This will fail if Phase 1 was too small. + debug!("Expected phase2_size: {}", phase2_size); + + let (full_mpc_parameters, query_parameters, all_mpc_parameters) = MPCParameters::::new_from_buffer_chunked( + circuit, + &mut phase1_transcript, + UseCompression::No, + CheckForCorrectness::No, + 1 << new_opts.phase1_powers, + phase2_size, + phase2_opts.chunk_size, + ) + .unwrap(); + info!("Finished constructing MPC parameters"); + + let mut serialized_mpc_parameters = vec![]; + full_mpc_parameters.write(&mut serialized_mpc_parameters).unwrap(); + info!("Serialized `full_mpc_parameters`"); + + let mut serialized_query_parameters = vec![]; + match COMPRESSION { + UseCompression::No => query_parameters.serialize_uncompressed(&mut serialized_query_parameters), + UseCompression::Yes => query_parameters.serialize(&mut serialized_query_parameters), + } + .unwrap(); + info!("Serialized `query_parameters`"); + + let contribution_hash = { + std::fs::File::create(format!("{}.full", new_opts.challenge_fname)) + .expect("unable to open new challenge hash file") + .write_all(&serialized_mpc_parameters) + .expect("unable to write serialized mpc parameters"); + // Get the hash of the contribution, so the user can compare later + calculate_hash(&serialized_mpc_parameters) + }; + info!("Hashed `full_mpc_parameters`"); + + std::fs::File::create(format!("{}.query", new_opts.challenge_fname)) + .expect("unable to open new challenge hash file") + .write_all(&serialized_query_parameters) + .expect("unable to write serialized mpc parameters"); + info!("Wrote `query_parameters` to file {}.query", new_opts.challenge_fname); + + let mut challenge_list_file = std::fs::File::create("phase1").expect("unable to open new challenge list file"); + + for (i, chunk) in all_mpc_parameters.iter().enumerate() { + let mut serialized_chunk = vec![]; + chunk.write(&mut serialized_chunk).expect("unable to write chunk"); + std::fs::File::create(format!("{}.{}", new_opts.challenge_fname, i)) + .expect("unable to open new challenge hash file") + .write_all(&serialized_chunk) + .expect("unable to write serialized mpc parameters"); + info!( + "Output `mpc_parameter` chunk {} to file {}.{}", + i, new_opts.challenge_fname, i + ); + challenge_list_file + .write(format!("{}.{}\n", new_opts.challenge_fname, i).as_bytes()) + .expect("unable to write challenge list"); + } + + std::fs::File::create(format!("{}.{}\n", new_opts.challenge_hash_fname, "query")) + .expect("unable to open new challenge hash file") + .write_all(&contribution_hash) + .expect("unable to write new challenge hash"); + + println!("Wrote a fresh accumulator to challenge file"); + + Ok(()) +} diff --git a/setup2/src/cli/verify.rs b/setup2/src/verify.rs similarity index 55% rename from setup2/src/cli/verify.rs rename to setup2/src/verify.rs index dbd867ec..ff0c0cbf 100644 --- a/setup2/src/cli/verify.rs +++ b/setup2/src/verify.rs @@ -1,27 +1,13 @@ +use crate::{Phase2Opts, VerifyOpts}; use phase2::chunked_groth16::verify as chunked_verify; use setup_utils::Result; use snarkvm_curves::{bls12_377::Bls12_377, bw6_761::BW6_761}; use fs_err::OpenOptions; -use gumdrop::Options; use memmap::MmapOptions; -// Options for the Contribute command -#[derive(Debug, Options, Clone)] -pub struct VerifyOpts { - help: bool, - #[options(help = "a previous contribution", default = "challenge")] - pub before: String, - #[options(help = "the current contribution", default = "challenge")] - pub after: String, - #[options(help = "the batches which can be loaded in memory", default = "50000")] - pub batch: usize, - #[options(help = "setup the inner or the outer circuit?")] - pub is_inner: bool, -} - -pub fn verify(opts: &VerifyOpts) -> Result<()> { +pub fn verify(phase2_opts: &Phase2Opts, opts: &VerifyOpts) -> Result<()> { let before = OpenOptions::new() .read(true) .write(true) @@ -42,10 +28,10 @@ pub fn verify(opts: &VerifyOpts) -> Result<()> { .map_mut(after.file()) .expect("unable to create a memory map for input") }; - if opts.is_inner { - chunked_verify::(&mut before, &mut after, opts.batch)?; + if phase2_opts.is_inner { + chunked_verify::(&mut before, &mut after, phase2_opts.batch_size)?; } else { - chunked_verify::(&mut before, &mut after, opts.batch)?; + chunked_verify::(&mut before, &mut after, phase2_opts.batch_size)?; } Ok(()) }