diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a3547681..7bec7e8e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,21 +46,11 @@ jobs: - name: Install solc run: (hash svm 2>/dev/null || cargo install --version 0.2.23 svm-rs) && svm install 0.8.20 && solc --version - - name: Test Zk Prover - run: | - cd zk_prover - cargo test --release --features dev-graph -- --nocapture - - name: Test KZG Prover run: | cd kzg_prover cargo test --release -- --nocapture - - name: Test Nova Prover - run: | - cd zk_prover - cargo run --release --example nova_incremental_verifier - - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 diff --git a/README.md b/README.md index a538529e..112dc7eb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A monorepo for Summa, zk proof of solvency protocol ### Subdirectories -- `zk_prover`: Halo2 based zk prover for Summa +- `kzg_prover`: Halo2 based zk prover and KZG polynomial interpolation for Summa - `contracts`: Solidity smart contracts for Summa - `backend` : Rust API to interact with Summa diff --git a/zk_prover/.gitignore b/zk_prover/.gitignore deleted file mode 100644 index 8d790640..00000000 --- a/zk_prover/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -/target -/ptau -/benches/csv -circuit_parameters_gen/generate_parameters_grain.sage.py -circuit_parameters_gen/__pycache__ -node_modules diff --git a/zk_prover/Cargo.lock b/zk_prover/Cargo.lock deleted file mode 100644 index 1f4e72c3..00000000 --- a/zk_prover/Cargo.lock +++ /dev/null @@ -1,4893 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "Inflector" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -dependencies = [ - "lazy_static", - "regex", -] - -[[package]] -name = "addchain" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2e69442aa5628ea6951fa33e24efe8313f4321a91bd729fc2f75bdfc858570" -dependencies = [ - "num-bigint 0.3.3", - "num-integer", - "num-traits", -] - -[[package]] -name = "addr2line" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "aes" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", -] - -[[package]] -name = "aho-corasick" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" -dependencies = [ - "memchr", -] - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "anyhow" -version = "1.0.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" - -[[package]] -name = "ark-std" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" -dependencies = [ - "colored", - "num-traits", - "rand 0.8.5", -] - -[[package]] -name = "arrayref" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - -[[package]] -name = "ascii-canvas" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" -dependencies = [ - "term", -] - -[[package]] -name = "async-trait" -version = "0.1.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2d0f03b3640e3a630367e40c468cb7f309529c708ed1d88597047b0e7c6ef7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "async_io_stream" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" -dependencies = [ - "futures", - "pharos", - "rustc_version 0.4.0", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - -[[package]] -name = "auto_impl" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fee3da8ef1276b0bee5dd1c7258010d8fffd31801447323115a25560e1327b89" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - -[[package]] -name = "base64" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" - -[[package]] -name = "base64ct" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a32fd6af2b5827bce66c29053ba0e7c42b9dcab01835835058558c10851a46b" - -[[package]] -name = "bech32" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" - -[[package]] -name = "bellperson" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93eaee4b4753554139ae52ecf0e8b8c128cbc561b32e1bfaa32f70cba8518c1f" -dependencies = [ - "bincode", - "blake2s_simd 1.0.1", - "blstrs", - "byteorder", - "crossbeam-channel", - "digest 0.10.7", - "ec-gpu", - "ec-gpu-gen", - "ff", - "group", - "log", - "memmap2", - "pairing", - "rand 0.8.5", - "rand_core 0.6.4", - "rayon", - "rustversion", - "serde", - "sha2 0.10.7", - "thiserror", -] - -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" - -[[package]] -name = "bitvec" -version = "0.17.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" -dependencies = [ - "either", - "radium 0.3.0", -] - -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium 0.7.0", - "tap", - "wyz", -] - -[[package]] -name = "blake2b_simd" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" -dependencies = [ - "arrayref", - "arrayvec 0.7.4", - "constant_time_eq 0.2.6", -] - -[[package]] -name = "blake2s_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e461a7034e85b211a4acb57ee2e6730b32912b06c08cc242243c39fc21ae6a2" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "constant_time_eq 0.1.5", -] - -[[package]] -name = "blake2s_simd" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" -dependencies = [ - "arrayref", - "arrayvec 0.7.4", - "constant_time_eq 0.2.6", -] - -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "block-padding", - "generic-array", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - -[[package]] -name = "blst" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c94087b935a822949d3291a9989ad2b2051ea141eda0fd4e478a75f6aa3e604b" -dependencies = [ - "cc", - "glob", - "threadpool", - "zeroize", -] - -[[package]] -name = "blstrs" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8a8ed6fefbeef4a8c7b460e4110e12c5e22a5b7cf32621aae6ad650c4dcf29" -dependencies = [ - "blst", - "byte-slice-cast", - "ff", - "group", - "pairing", - "rand_core 0.6.4", - "serde", - "subtle", -] - -[[package]] -name = "bs58" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" -dependencies = [ - "sha2 0.9.9", -] - -[[package]] -name = "bumpalo" -version = "3.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" - -[[package]] -name = "byte-slice-cast" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" - -[[package]] -name = "bytemuck" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" -dependencies = [ - "serde", -] - -[[package]] -name = "camino" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo-platform" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.15.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" -dependencies = [ - "camino", - "cargo-platform", - "semver 1.0.17", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - -[[package]] -name = "cc" -version = "1.0.79" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chrono" -version = "0.4.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "time", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", -] - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "bitflags 1.3.2", - "textwrap", - "unicode-width", -] - -[[package]] -name = "cmake" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" -dependencies = [ - "cc", -] - -[[package]] -name = "coins-bip32" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30a84aab436fcb256a2ab3c80663d8aec686e6bae12827bb05fef3e1e439c9f" -dependencies = [ - "bincode", - "bs58", - "coins-core", - "digest 0.10.7", - "getrandom", - "hmac", - "k256", - "lazy_static", - "serde", - "sha2 0.10.7", - "thiserror", -] - -[[package]] -name = "coins-bip39" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f4d04ee18e58356accd644896aeb2094ddeafb6a713e056cef0c0a8e468c15" -dependencies = [ - "bitvec 0.17.4", - "coins-bip32", - "getrandom", - "hmac", - "once_cell", - "pbkdf2 0.12.1", - "rand 0.8.5", - "sha2 0.10.7", - "thiserror", -] - -[[package]] -name = "coins-core" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b949a1c63fb7eb591eb7ba438746326aedf0ae843e51ec92ba6bec5bb382c4f" -dependencies = [ - "base64 0.21.2", - "bech32", - "bs58", - "digest 0.10.7", - "generic-array", - "hex", - "ripemd", - "serde", - "serde_derive", - "sha2 0.10.7", - "sha3 0.10.8", - "thiserror", -] - -[[package]] -name = "color_quant" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" - -[[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 = "const-cstr" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed3d0b5ff30645a68f35ece8cea4556ca14ef8a1651455f789a099a0513532a6" - -[[package]] -name = "const-oid" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" - -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - -[[package]] -name = "constant_time_eq" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" - -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "core-foundation" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" - -[[package]] -name = "core-graphics" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", - "foreign-types", - "libc", -] - -[[package]] -name = "core-graphics-types" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "libc", -] - -[[package]] -name = "core-text" -version = "19.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" -dependencies = [ - "core-foundation", - "core-graphics", - "foreign-types", - "libc", -] - -[[package]] -name = "cpufeatures" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "criterion" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" -dependencies = [ - "atty", - "cast", - "clap", - "criterion-plot", - "csv", - "itertools 0.10.5", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_cbor", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" -dependencies = [ - "cast", - "itertools 0.10.5", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - -[[package]] -name = "crypto-bigint" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "csv" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626ae34994d3d8d668f4269922248239db4ae42d538b14c398b74a52208e8086" -dependencies = [ - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher", -] - -[[package]] -name = "darling" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" -dependencies = [ - "darling_core", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "der" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56acb310e15652100da43d130af8d97b509e95af61aab1c5a7939ef24337ee17" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "derive_builder" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" -dependencies = [ - "darling", - "derive_builder_core", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "derive_builder_core" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 1.0.109", -] - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer 0.10.4", - "const-oid", - "crypto-common", - "subtle", -] - -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - -[[package]] -name = "dlib" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" -dependencies = [ - "libloading", -] - -[[package]] -name = "dunce" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" - -[[package]] -name = "dwrote" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439a1c2ba5611ad3ed731280541d36d2e9c4ac5e7fb818a27b604bdc5a6aa65b" -dependencies = [ - "lazy_static", - "libc", - "winapi", - "wio", -] - -[[package]] -name = "ec-gpu" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd63582de2b59ea1aa48d7c1941b5d87618d95484397521b3acdfa0e1e9f5e45" - -[[package]] -name = "ec-gpu-gen" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "892df2aa20abec5b816e15d5d6383892ca142077708efa3067dd3ac44b75c664" -dependencies = [ - "bitvec 1.0.1", - "crossbeam-channel", - "ec-gpu", - "execute", - "ff", - "group", - "hex", - "log", - "num_cpus", - "once_cell", - "rayon", - "sha2 0.10.7", - "thiserror", - "yastl", -] - -[[package]] -name = "ecc" -version = "0.1.0" -source = "git+https://github.com/privacy-scaling-explorations/halo2wrong?tag=v2023_04_20#f72db265aa3cebe297c9b9816e940d0e1d400886" -dependencies = [ - "integer", - "num-bigint 0.4.3", - "num-integer", - "num-traits", - "rand 0.8.5", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "either" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" - -[[package]] -name = "elliptic-curve" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core 0.6.4", - "sec1", - "subtle", - "zeroize", -] - -[[package]] -name = "ena" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" -dependencies = [ - "log", -] - -[[package]] -name = "encoding_rs" -version = "0.8.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "enr" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf56acd72bb22d2824e66ae8e9e5ada4d0de17a69c7fd35569dde2ada8ec9116" -dependencies = [ - "base64 0.13.1", - "bytes", - "hex", - "k256", - "log", - "rand 0.8.5", - "rlp", - "serde", - "sha3 0.10.8", - "zeroize", -] - -[[package]] -name = "enumn" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48016319042fb7c87b78d2993084a831793a897a5cd1a2a67cab9d1eeb4b7d76" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "equivalent" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" - -[[package]] -name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "eth-keystore" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fda3bf123be441da5260717e0661c25a2fd9cb2b2c1d20bf2e05580047158ab" -dependencies = [ - "aes", - "ctr", - "digest 0.10.7", - "hex", - "hmac", - "pbkdf2 0.11.0", - "rand 0.8.5", - "scrypt", - "serde", - "serde_json", - "sha2 0.10.7", - "sha3 0.10.8", - "thiserror", - "uuid", -] - -[[package]] -name = "ethabi" -version = "18.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" -dependencies = [ - "ethereum-types", - "hex", - "once_cell", - "regex", - "serde", - "serde_json", - "sha3 0.10.8", - "thiserror", - "uint", -] - -[[package]] -name = "ethbloom" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" -dependencies = [ - "crunchy", - "fixed-hash", - "impl-codec", - "impl-rlp", - "impl-serde", - "scale-info", - "tiny-keccak", -] - -[[package]] -name = "ethereum-types" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" -dependencies = [ - "ethbloom", - "fixed-hash", - "impl-codec", - "impl-rlp", - "impl-serde", - "primitive-types", - "scale-info", - "uint", -] - -[[package]] -name = "ethers" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a58ce802c65cf3d0756dee5a61094a92cde53c1583b246e9ee5b37226c7fc15" -dependencies = [ - "ethers-addressbook", - "ethers-contract", - "ethers-core", - "ethers-etherscan", - "ethers-middleware", - "ethers-providers", - "ethers-signers", - "ethers-solc", -] - -[[package]] -name = "ethers-addressbook" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b856b7b8ff5c961093cb8efe151fbcce724b451941ce20781de11a531ccd578" -dependencies = [ - "ethers-core", - "once_cell", - "serde", - "serde_json", -] - -[[package]] -name = "ethers-contract" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e066a0d9cfc70c454672bf16bb433b0243427420076dc5b2f49c448fb5a10628" -dependencies = [ - "ethers-contract-abigen", - "ethers-contract-derive", - "ethers-core", - "ethers-providers", - "futures-util", - "hex", - "once_cell", - "pin-project", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "ethers-contract-abigen" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c113e3e86b6bc16d98484b2c3bb2d01d6fed9f489fe2e592e5cc87c3024d616b" -dependencies = [ - "Inflector", - "dunce", - "ethers-core", - "eyre", - "hex", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "serde", - "serde_json", - "syn 2.0.22", - "toml", - "walkdir", -] - -[[package]] -name = "ethers-contract-derive" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3fb5adee25701c79ec58fcf2c63594cd8829bc9ad6037ff862d5a111101ed2" -dependencies = [ - "Inflector", - "ethers-contract-abigen", - "ethers-core", - "hex", - "proc-macro2", - "quote", - "serde_json", - "syn 2.0.22", -] - -[[package]] -name = "ethers-core" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6da5fa198af0d3be20c19192df2bd9590b92ce09a8421e793bec8851270f1b05" -dependencies = [ - "arrayvec 0.7.4", - "bytes", - "cargo_metadata", - "chrono", - "elliptic-curve", - "ethabi", - "generic-array", - "hex", - "k256", - "num_enum", - "once_cell", - "open-fastrlp", - "rand 0.8.5", - "rlp", - "serde", - "serde_json", - "strum", - "syn 2.0.22", - "tempfile", - "thiserror", - "tiny-keccak", - "unicode-xid", -] - -[[package]] -name = "ethers-etherscan" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ebb401ba97c6f5af278c2c9936c4546cad75dec464b439ae6df249906f4caa" -dependencies = [ - "ethers-core", - "ethers-solc", - "reqwest", - "semver 1.0.17", - "serde", - "serde_json", - "thiserror", - "tracing", -] - -[[package]] -name = "ethers-middleware" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740f4a773c19dd6d6a68c8c2e0996c096488d38997d524e21dc612c55da3bd24" -dependencies = [ - "async-trait", - "auto_impl", - "ethers-contract", - "ethers-core", - "ethers-etherscan", - "ethers-providers", - "ethers-signers", - "futures-channel", - "futures-locks", - "futures-util", - "instant", - "reqwest", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", - "tracing-futures", - "url", -] - -[[package]] -name = "ethers-providers" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56b498fd2a6c019d023e43e83488cd1fb0721f299055975aa6bac8dbf1e95f2c" -dependencies = [ - "async-trait", - "auto_impl", - "base64 0.21.2", - "bytes", - "enr", - "ethers-core", - "futures-core", - "futures-timer", - "futures-util", - "hashers", - "hex", - "http", - "instant", - "once_cell", - "pin-project", - "reqwest", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", - "tracing-futures", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "ws_stream_wasm", -] - -[[package]] -name = "ethers-signers" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c4b7e15f212fa7cc2e1251868320221d4ff77a3d48068e69f47ce1c491df2d" -dependencies = [ - "async-trait", - "coins-bip32", - "coins-bip39", - "elliptic-curve", - "eth-keystore", - "ethers-core", - "hex", - "rand 0.8.5", - "sha2 0.10.7", - "thiserror", - "tracing", -] - -[[package]] -name = "ethers-solc" -version = "2.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81c89f121595cf8959e746045bb8b25a6a38d72588561e1a3b7992fc213f674" -dependencies = [ - "cfg-if", - "dunce", - "ethers-core", - "glob", - "hex", - "home", - "md-5", - "num_cpus", - "once_cell", - "path-slash", - "rayon", - "regex", - "semver 1.0.17", - "serde", - "serde_json", - "solang-parser", - "thiserror", - "tiny-keccak", - "tokio", - "tracing", - "walkdir", - "yansi", -] - -[[package]] -name = "execute" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d9a9ea4c04632c16bc5c71a2fcc63d308481f7fc67eb1a1ce6315c44a426ae" -dependencies = [ - "execute-command-macro", - "execute-command-tokens", - "generic-array", -] - -[[package]] -name = "execute-command-macro" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5fbc65a0cf735106743f4c38c9a3671c1e734b5c2c20d21a3c93c696daa3157" -dependencies = [ - "execute-command-macro-impl", -] - -[[package]] -name = "execute-command-macro-impl" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55a9a55d1dab3b07854648d48e366f684aefe2ac78ae28cec3bf65e3cd53d9a3" -dependencies = [ - "execute-command-tokens", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "execute-command-tokens" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba569491c70ec8471e34aa7e9c0b9e82bb5d2464c0398442d17d3c4af814e5a" - -[[package]] -name = "eyre" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" -dependencies = [ - "indenter", - "once_cell", -] - -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - -[[package]] -name = "fdeflate" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" -dependencies = [ - "simd-adler32", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec 1.0.1", - "byteorder", - "ff_derive", - "rand_core 0.6.4", - "subtle", -] - -[[package]] -name = "ff_ce" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3a682c12d0cc98a32ab7540401a5ea1ed21d11571eea11d5829cd721f85ff0" -dependencies = [ - "byteorder", - "ff_derive_ce", - "hex", - "rand 0.4.6", -] - -[[package]] -name = "ff_derive" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f54704be45ed286151c5e11531316eaef5b8f5af7d597b806fdb8af108d84a" -dependencies = [ - "addchain", - "cfg-if", - "num-bigint 0.3.3", - "num-integer", - "num-traits", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ff_derive_ce" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c052fa6d4c2f12305ec364bfb8ef884836f3f61ea015b202372ff996d1ac4b" -dependencies = [ - "num-bigint 0.2.6", - "num-integer", - "num-traits", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "fixed-hash" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" -dependencies = [ - "byteorder", - "rand 0.8.5", - "rustc-hex", - "static_assertions", -] - -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - -[[package]] -name = "flate2" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "float-ord" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" - -[[package]] -name = "flume" -version = "0.10.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" -dependencies = [ - "spin 0.9.8", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "font-kit" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21fe28504d371085fae9ac7a3450f0b289ab71e07c8e57baa3fb68b9e57d6ce5" -dependencies = [ - "bitflags 1.3.2", - "byteorder", - "core-foundation", - "core-graphics", - "core-text", - "dirs-next", - "dwrote", - "float-ord", - "freetype", - "lazy_static", - "libc", - "log", - "pathfinder_geometry", - "pathfinder_simd", - "walkdir", - "winapi", - "yeslogic-fontconfig-sys", -] - -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "freetype" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee38378a9e3db1cc693b4f88d166ae375338a0ff75cb8263e1c601d51f35dc6" -dependencies = [ - "freetype-sys", - "libc", -] - -[[package]] -name = "freetype-sys" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37d4011c0cc628dfa766fcc195454f4b068d7afdc2adfd28861191d866e731a" -dependencies = [ - "cmake", - "libc", - "pkg-config", -] - -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-locks" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" -dependencies = [ - "futures-channel", - "futures-task", -] - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "futures-sink" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" - -[[package]] -name = "futures-task" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" - -[[package]] -name = "futures-timer" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" -dependencies = [ - "gloo-timers", - "send_wrapper 0.4.0", -] - -[[package]] -name = "futures-util" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", - "zeroize", -] - -[[package]] -name = "getrandom" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" -dependencies = [ - "cfg-if", - "js-sys", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", - "wasm-bindgen", -] - -[[package]] -name = "gif" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" -dependencies = [ - "color_quant", - "weezl", -] - -[[package]] -name = "gimli" -version = "0.27.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "gloo-timers" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand 0.8.5", - "rand_core 0.6.4", - "rand_xorshift", - "subtle", -] - -[[package]] -name = "h2" -version = "0.3.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap 1.9.3", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "half" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" - -[[package]] -name = "halo2_gadgets" -version = "0.2.0" -source = "git+https://github.com/privacy-scaling-explorations/halo2?tag=v2023_04_20#be955686f86eb618f55d2320c0e042485b313d22" -dependencies = [ - "arrayvec 0.7.4", - "bitvec 1.0.1", - "ff", - "group", - "halo2_proofs", - "halo2curves 0.3.2", - "lazy_static", - "rand 0.8.5", - "subtle", - "uint", -] - -[[package]] -name = "halo2_proofs" -version = "0.2.0" -source = "git+https://github.com/privacy-scaling-explorations/halo2?tag=v2023_04_20#be955686f86eb618f55d2320c0e042485b313d22" -dependencies = [ - "blake2b_simd", - "ff", - "group", - "halo2curves 0.3.2", - "plotters", - "rand_chacha", - "rand_core 0.6.4", - "rayon", - "sha3 0.9.1", - "tabbycat", - "tracing", -] - -[[package]] -name = "halo2curves" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b1142bd1059aacde1b477e0c80c142910f1ceae67fc619311d6a17428007ab" -dependencies = [ - "blake2b_simd", - "ff", - "group", - "lazy_static", - "num-bigint 0.4.3", - "num-traits", - "pasta_curves", - "paste", - "rand 0.8.5", - "rand_core 0.6.4", - "serde", - "serde_arrays", - "static_assertions", - "subtle", -] - -[[package]] -name = "halo2curves" -version = "0.3.2" -source = "git+https://github.com/privacy-scaling-explorations/halo2curves?tag=0.3.2#9f5c50810bbefe779ee5cf1d852b2fe85dc35d5e" -dependencies = [ - "ff", - "group", - "lazy_static", - "num-bigint 0.4.3", - "num-traits", - "pasta_curves", - "paste", - "rand 0.8.5", - "rand_core 0.6.4", - "serde", - "static_assertions", - "subtle", -] - -[[package]] -name = "halo2wrong" -version = "0.1.0" -source = "git+https://github.com/privacy-scaling-explorations/halo2wrong?tag=v2023_04_20#f72db265aa3cebe297c9b9816e940d0e1d400886" -dependencies = [ - "halo2_proofs", - "num-bigint 0.4.3", - "num-integer", - "num-traits", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hashbrown" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" - -[[package]] -name = "hashers" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" -dependencies = [ - "fxhash", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "hex-literal" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "home" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "http" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - -[[package]] -name = "hyper" -version = "0.14.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "image" -version = "0.24.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527909aa81e20ac3a44803521443a765550f09b5130c2c2fa1ea59c2f8f50a3a" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "jpeg-decoder", - "num-rational", - "num-traits", - "png", -] - -[[package]] -name = "impl-codec" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" -dependencies = [ - "parity-scale-codec", -] - -[[package]] -name = "impl-rlp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" -dependencies = [ - "rlp", -] - -[[package]] -name = "impl-serde" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" -dependencies = [ - "serde", -] - -[[package]] -name = "impl-trait-for-tuples" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - -[[package]] -name = "indexmap" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" -dependencies = [ - "equivalent", - "hashbrown 0.14.0", -] - -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "integer" -version = "0.1.0" -source = "git+https://github.com/privacy-scaling-explorations/halo2wrong?tag=v2023_04_20#f72db265aa3cebe297c9b9816e940d0e1d400886" -dependencies = [ - "maingate", - "num-bigint 0.4.3", - "num-integer", - "num-traits", - "rand 0.8.5", - "subtle", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys", -] - -[[package]] -name = "ipnet" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" - -[[package]] -name = "is-terminal" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" -dependencies = [ - "hermit-abi 0.3.1", - "rustix 0.38.11", - "windows-sys", -] - -[[package]] -name = "itertools" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" - -[[package]] -name = "jpeg-decoder" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" - -[[package]] -name = "js-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "k256" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.7", - "signature", -] - -[[package]] -name = "keccak" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" -dependencies = [ - "cpufeatures", -] - -[[package]] -name = "lalrpop" -version = "0.19.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" -dependencies = [ - "ascii-canvas", - "bit-set", - "diff", - "ena", - "is-terminal", - "itertools 0.10.5", - "lalrpop-util", - "petgraph", - "regex", - "regex-syntax 0.6.29", - "string_cache", - "term", - "tiny-keccak", - "unicode-xid", -] - -[[package]] -name = "lalrpop-util" -version = "0.19.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] - -[[package]] -name = "libc" -version = "0.2.147" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" - -[[package]] -name = "libloading" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d580318f95776505201b28cf98eb1fa5e4be3b689633ba6a3e6cd880ff22d8cb" -dependencies = [ - "cfg-if", - "windows-sys", -] - -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - -[[package]] -name = "linux-raw-sys" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" - -[[package]] -name = "lock_api" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" - -[[package]] -name = "maingate" -version = "0.1.0" -source = "git+https://github.com/privacy-scaling-explorations/halo2wrong?tag=v2023_04_20#f72db265aa3cebe297c9b9816e940d0e1d400886" -dependencies = [ - "halo2wrong", - "num-bigint 0.4.3", - "num-integer", - "num-traits", - "rand 0.8.5", - "subtle", -] - -[[package]] -name = "md-5" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memmap2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" -dependencies = [ - "libc", -] - -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", - "simd-adler32", -] - -[[package]] -name = "mio" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" -dependencies = [ - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", -] - -[[package]] -name = "neptune" -version = "10.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9a64337e6d214e2a48db5714ef18cf1e5a7bbff9043838fdf6e57ce5659335" -dependencies = [ - "bellperson", - "blake2s_simd 0.5.11", - "blstrs", - "byteorder", - "ff", - "generic-array", - "itertools 0.8.2", - "log", - "pasta_curves", - "serde", - "trait-set", -] - -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - -[[package]] -name = "nova-scotia" -version = "0.5.0" -source = "git+https://github.com/nalinbhardwaj/Nova-Scotia#00085ece0e16c29a12f61866fa3588649620d7f7" -dependencies = [ - "anyhow", - "bellperson", - "byteorder", - "ff", - "hex-literal 0.3.4", - "itertools 0.9.0", - "js-sys", - "nova-snark", - "num-bigint 0.4.3", - "num-traits", - "pasta_curves", - "rayon", - "serde", - "serde_json", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-rayon", -] - -[[package]] -name = "nova-snark" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e12911ac9672ad436acfc992f09e26a5960513bbe81d1572005cadd8c1be8f4" -dependencies = [ - "bellperson", - "bincode", - "bitvec 1.0.1", - "byteorder", - "digest 0.10.7", - "ff", - "flate2", - "generic-array", - "getrandom", - "halo2curves 0.1.0", - "itertools 0.11.0", - "neptune", - "num-bigint 0.4.3", - "num-integer", - "num-traits", - "pasta-msm", - "pasta_curves", - "rand_chacha", - "rand_core 0.6.4", - "rayon", - "serde", - "sha3 0.10.8", - "subtle", - "thiserror", -] - -[[package]] -name = "num" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" -dependencies = [ - "num-bigint 0.4.3", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", - "rand 0.8.5", - "serde", -] - -[[package]] -name = "num-complex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" -dependencies = [ - "autocfg", - "num-bigint 0.4.3", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi 0.2.6", - "libc", -] - -[[package]] -name = "num_enum" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "object" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "open-fastrlp" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" -dependencies = [ - "arrayvec 0.7.4", - "auto_impl", - "bytes", - "ethereum-types", - "open-fastrlp-derive", -] - -[[package]] -name = "open-fastrlp-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "003b2be5c6c53c1cfeb0a238b8a1c3915cd410feb684457a36c10038f764bb1c" -dependencies = [ - "bytes", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "parity-scale-codec" -version = "3.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2287753623c76f953acd29d15d8100bcab84d29db78fb6f352adb3c53e83b967" -dependencies = [ - "arrayvec 0.7.4", - "bitvec 1.0.1", - "byte-slice-cast", - "impl-trait-for-tuples", - "parity-scale-codec-derive", - "serde", -] - -[[package]] -name = "parity-scale-codec-derive" -version = "3.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b6937b5e67bfba3351b87b040d48352a2fcb6ad72f81855412ce97b45c8f110" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.3.5", - "smallvec", - "windows-targets", -] - -[[package]] -name = "pasta-msm" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e85d75eba3e7e9ee3bd11342b669185e194dadda3557934bc1000d9b87159d3" -dependencies = [ - "cc", - "pasta_curves", - "semolina", - "sppark", - "which", -] - -[[package]] -name = "pasta_curves" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" -dependencies = [ - "blake2b_simd", - "ff", - "group", - "hex", - "lazy_static", - "rand 0.8.5", - "serde", - "static_assertions", - "subtle", -] - -[[package]] -name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - -[[package]] -name = "path-slash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" - -[[package]] -name = "pathfinder_geometry" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b7e7b4ea703700ce73ebf128e1450eb69c3a8329199ffbfb9b2a0418e5ad3" -dependencies = [ - "log", - "pathfinder_simd", -] - -[[package]] -name = "pathfinder_simd" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39fe46acc5503595e5949c17b818714d26fdf9b4920eacf3b2947f0199f4a6ff" -dependencies = [ - "rustc_version 0.3.3", -] - -[[package]] -name = "pbkdf2" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "pbkdf2" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ca0b5a68607598bf3bad68f32227a8164f6254833f84eafaac409cd6746c31" -dependencies = [ - "digest 0.10.7", - "hmac", -] - -[[package]] -name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pest" -version = "2.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" -dependencies = [ - "thiserror", - "ucd-trie", -] - -[[package]] -name = "petgraph" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" -dependencies = [ - "fixedbitset", - "indexmap 1.9.3", -] - -[[package]] -name = "pharos" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" -dependencies = [ - "futures", - "rustc_version 0.4.0", -] - -[[package]] -name = "phf" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" -dependencies = [ - "phf_macros", - "phf_shared 0.11.2", -] - -[[package]] -name = "phf_generator" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" -dependencies = [ - "phf_shared 0.11.2", - "rand 0.8.5", -] - -[[package]] -name = "phf_macros" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" -dependencies = [ - "phf_generator", - "phf_shared 0.11.2", - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - -[[package]] -name = "phf_shared" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" -dependencies = [ - "siphasher", -] - -[[package]] -name = "pin-project" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "pkg-config" -version = "0.3.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" - -[[package]] -name = "plotters" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" -dependencies = [ - "chrono", - "font-kit", - "image", - "lazy_static", - "num-traits", - "pathfinder_geometry", - "plotters-backend", - "plotters-bitmap", - "plotters-svg", - "ttf-parser", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" - -[[package]] -name = "plotters-bitmap" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cebbe1f70205299abc69e8b295035bb52a6a70ee35474ad10011f0a4efb8543" -dependencies = [ - "gif", - "image", - "plotters-backend", -] - -[[package]] -name = "plotters-svg" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" -dependencies = [ - "plotters-backend", -] - -[[package]] -name = "png" -version = "0.17.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59871cc5b6cce7eaccca5a802b4173377a1c2ba90654246789a8fa2334426d11" -dependencies = [ - "bitflags 1.3.2", - "crc32fast", - "fdeflate", - "flate2", - "miniz_oxide", -] - -[[package]] -name = "poseidon" -version = "0.2.0" -source = "git+https://github.com/privacy-scaling-explorations/poseidon.git?tag=v2023_04_20#807f8f555313f726ca03bdf941f798098f488ba4" -dependencies = [ - "halo2curves 0.3.2", - "subtle", -] - -[[package]] -name = "poseidon-rs" -version = "0.0.10" -source = "git+https://github.com/arnaucube/poseidon-rs#f4ba1f7c32905cd2ae5a71e7568564bb150a9862" -dependencies = [ - "ff_ce", - "rand 0.4.6", - "serde_json", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "prettyplease" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9825a04601d60621feed79c4e6b56d65db77cdca55cef43b46b0de1096d1c282" -dependencies = [ - "proc-macro2", - "syn 2.0.22", -] - -[[package]] -name = "primitive-types" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" -dependencies = [ - "fixed-hash", - "impl-codec", - "impl-rlp", - "impl-serde", - "scale-info", - "uint", -] - -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radium" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" - -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_xorshift" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" -dependencies = [ - "rand_core 0.6.4", -] - -[[package]] -name = "rayon" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall 0.2.16", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax 0.7.2", -] - -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - -[[package]] -name = "regex-syntax" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" - -[[package]] -name = "reqwest" -version = "0.11.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" -dependencies = [ - "base64 0.21.2", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "ipnet", - "js-sys", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project-lite", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - -[[package]] -name = "revm" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f293f351c4c203d321744e54ed7eed3d2b6eef4c140228910dde3ac9a5ea8031" -dependencies = [ - "auto_impl", - "revm-interpreter", - "revm-precompile", -] - -[[package]] -name = "revm-interpreter" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a53980a26f9b5a66d13511c35074d4b53631e157850a1d7cf1af4efc2c2b72c9" -dependencies = [ - "derive_more", - "enumn", - "revm-primitives", - "sha3 0.10.8", -] - -[[package]] -name = "revm-precompile" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41320af3bd6a65153d38eb1d3638ba89104cc9513c7feedb2d8510e8307dab29" -dependencies = [ - "k256", - "num", - "once_cell", - "revm-primitives", - "ripemd", - "secp256k1", - "sha2 0.10.7", - "sha3 0.10.8", - "substrate-bn", -] - -[[package]] -name = "revm-primitives" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "304d998f466ffef72d76c7f20b05bf08a96801736a6fb1fdef47d49a292618df" -dependencies = [ - "auto_impl", - "bitvec 1.0.1", - "bytes", - "derive_more", - "enumn", - "fixed-hash", - "hashbrown 0.13.2", - "hex", - "hex-literal 0.4.1", - "primitive-types", - "rlp", - "ruint", - "sha3 0.10.8", -] - -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "rlp" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" -dependencies = [ - "bytes", - "rlp-derive", - "rustc-hex", -] - -[[package]] -name = "rlp-derive" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ruint" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d470e29e933dac4101180fd6574971892315c414cf2961a192729089687cc9b" -dependencies = [ - "derive_more", - "primitive-types", - "rlp", - "ruint-macro", - "rustc_version 0.4.0", - "thiserror", -] - -[[package]] -name = "ruint-macro" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62cc5760263ea229d367e7dff3c0cbf09e4797a125bd87059a6c095804f3b2d1" - -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - -[[package]] -name = "rustc-hex" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" - -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver 1.0.17", -] - -[[package]] -name = "rustix" -version = "0.37.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8818fa822adcc98b18fedbb3632a6a33213c070556b5aa7c4c8cc21cff565c4c" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys", -] - -[[package]] -name = "rustix" -version = "0.38.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" -dependencies = [ - "bitflags 2.4.0", - "errno", - "libc", - "linux-raw-sys 0.4.3", - "windows-sys", -] - -[[package]] -name = "rustversion" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc31bd9b61a32c31f9650d18add92aa83a49ba979c143eefd27fe7177b05bd5f" - -[[package]] -name = "ryu" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" - -[[package]] -name = "salsa20" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" -dependencies = [ - "cipher", -] - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "scale-info" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad560913365790f17cbf12479491169f01b9d46d29cfc7422bf8c64bdc61b731" -dependencies = [ - "cfg-if", - "derive_more", - "parity-scale-codec", - "scale-info-derive", -] - -[[package]] -name = "scale-info-derive" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19df9bd9ace6cc2fe19387c96ce677e823e07d017ceed253e7bb3d1d1bd9c73b" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "scrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" -dependencies = [ - "hmac", - "pbkdf2 0.11.0", - "salsa20", - "sha2 0.10.7", -] - -[[package]] -name = "sec1" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - -[[package]] -name = "secp256k1" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" -dependencies = [ - "secp256k1-sys", -] - -[[package]] -name = "secp256k1-sys" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" -dependencies = [ - "cc", -] - -[[package]] -name = "semolina" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0111fd4fa831becb0606b9a2285ef3bee3c6a70d690209b8ae9514e9befe23" -dependencies = [ - "cc", - "glob", -] - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" -dependencies = [ - "serde", -] - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - -[[package]] -name = "send_wrapper" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" - -[[package]] -name = "send_wrapper" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" - -[[package]] -name = "serde" -version = "1.0.164" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_arrays" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38636132857f68ec3d5f3eb121166d2af33cb55174c4d5ff645db6165cbef0fd" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half", - "serde", -] - -[[package]] -name = "serde_derive" -version = "1.0.164" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "serde_json" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_spanned" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sha2" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "keccak", - "opaque-debug", -] - -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest 0.10.7", - "keccak", -] - -[[package]] -name = "signature" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" -dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", -] - -[[package]] -name = "simd-adler32" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f" - -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - -[[package]] -name = "slab" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" -dependencies = [ - "autocfg", -] - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "snark-verifier" -version = "0.1.0" -source = "git+https://github.com/privacy-scaling-explorations/snark-verifier#5ea36197d76ecb93b6a9458ab18e16f9d1d99e9b" -dependencies = [ - "ecc", - "halo2_proofs", - "halo2curves 0.3.2", - "hex", - "itertools 0.10.5", - "lazy_static", - "num-bigint 0.4.3", - "num-integer", - "num-traits", - "poseidon", - "rand 0.8.5", - "revm", - "serde", - "sha3 0.10.8", -] - -[[package]] -name = "snark-verifier-sdk" -version = "0.1.1" -source = "git+https://github.com/privacy-scaling-explorations/snark-verifier#5ea36197d76ecb93b6a9458ab18e16f9d1d99e9b" -dependencies = [ - "ark-std", - "bincode", - "ecc", - "ethereum-types", - "halo2_proofs", - "halo2curves 0.3.2", - "hex", - "itertools 0.10.5", - "lazy_static", - "num-bigint 0.4.3", - "num-integer", - "num-traits", - "poseidon", - "rand 0.8.5", - "rand_chacha", - "serde", - "serde_json", - "snark-verifier", -] - -[[package]] -name = "socket2" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "solang-parser" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a94494913728908efa7a25a2dd2e4f037e714897985c24273c40596638ed909" -dependencies = [ - "itertools 0.10.5", - "lalrpop", - "lalrpop-util", - "phf", - "thiserror", - "unicode-xid", -] - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - -[[package]] -name = "spki" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "spmc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" - -[[package]] -name = "sppark" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7a6d98937866ea8917015cd4a72d56d6e7feee8979dbccf83fc0c870053c46" -dependencies = [ - "cc", - "which", -] - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "string_cache" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared 0.10.0", - "precomputed-hash", -] - -[[package]] -name = "strsim" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" - -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" -dependencies = [ - "strum_macros", -] - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", -] - -[[package]] -name = "substrate-bn" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b5bbfa79abbae15dd642ea8176a21a635ff3c00059961d1ea27ad04e5b441c" -dependencies = [ - "byteorder", - "crunchy", - "lazy_static", - "rand 0.8.5", - "rustc-hex", -] - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - -[[package]] -name = "summa-solvency" -version = "0.1.0" -dependencies = [ - "ark-std", - "criterion", - "csv", - "ethers", - "ff_ce", - "halo2_gadgets", - "halo2_proofs", - "hex", - "itertools 0.10.5", - "nova-scotia", - "nova-snark", - "num-bigint 0.4.3", - "num-traits", - "num_cpus", - "plotters", - "poseidon-rs", - "rand 0.8.5", - "rayon", - "regex", - "serde", - "serde_json", - "snark-verifier", - "snark-verifier-sdk", - "tabbycat", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "tabbycat" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c45590f0f859197b4545be1b17b2bc3cc7bb075f7d1cc0ea1dc6521c0bf256a3" -dependencies = [ - "anyhow", - "derive_builder", - "regex", -] - -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - -[[package]] -name = "tempfile" -version = "3.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" -dependencies = [ - "autocfg", - "cfg-if", - "fastrand", - "redox_syscall 0.3.5", - "rustix 0.37.22", - "windows-sys", -] - -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thiserror" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.29.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" -dependencies = [ - "autocfg", - "backtrace", - "bytes", - "libc", - "mio", - "num_cpus", - "pin-project-lite", - "socket2", - "windows-sys", -] - -[[package]] -name = "tokio-util" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", - "tracing", -] - -[[package]] -name = "toml" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebafdf5ad1220cb59e7d17cf4d2c72015297b75b19a10472f99b89225089240" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.19.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" -dependencies = [ - "indexmap 2.0.0", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", -] - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] - -[[package]] -name = "tracing-core" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" -dependencies = [ - "once_cell", -] - -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - -[[package]] -name = "trait-set" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79e2e9c9ab44c6d7c20d5976961b47e8f49ac199154daa514b77cd1ab536625" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - -[[package]] -name = "ttf-parser" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" - -[[package]] -name = "typenum" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" - -[[package]] -name = "ucd-trie" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" - -[[package]] -name = "uint" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" - -[[package]] -name = "unicode-normalization" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "url" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", -] - -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom", - "serde", -] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "walkdir" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasm-bindgen" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" -dependencies = [ - "cfg-if", - "serde", - "serde_json", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.22", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-rayon" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df87c67450805c305d3ae44a3ac537b0253d029153c25afc3ecd2edc36ccafb1" -dependencies = [ - "js-sys", - "rayon", - "spmc", - "wasm-bindgen", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.87" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" - -[[package]] -name = "web-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "weezl" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix 0.38.11", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" - -[[package]] -name = "winnow" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" -dependencies = [ - "memchr", -] - -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] - -[[package]] -name = "wio" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" -dependencies = [ - "winapi", -] - -[[package]] -name = "ws_stream_wasm" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" -dependencies = [ - "async_io_stream", - "futures", - "js-sys", - "log", - "pharos", - "rustc_version 0.4.0", - "send_wrapper 0.6.0", - "thiserror", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" - -[[package]] -name = "yastl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca6c5a4d66c1a9ea261811cf4773c27343de7e5033e1b75ea3f297dc7db3c1a" -dependencies = [ - "flume", - "scopeguard", -] - -[[package]] -name = "yeslogic-fontconfig-sys" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2bbd69036d397ebbff671b1b8e4d918610c181c5a16073b96f984a38d08c386" -dependencies = [ - "const-cstr", - "dlib", - "once_cell", - "pkg-config", -] - -[[package]] -name = "zeroize" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.22", -] diff --git a/zk_prover/Cargo.toml b/zk_prover/Cargo.toml deleted file mode 100644 index 00483a5a..00000000 --- a/zk_prover/Cargo.toml +++ /dev/null @@ -1,42 +0,0 @@ -[package] -name = "summa-solvency" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[features] -dev-graph = ["halo2_proofs/dev-graph", "plotters"] - - -[dependencies] -halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20"} -halo2_gadgets = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20"} -plotters = { version = "0.3.4", optional = true } -rand = "0.8" -ark-std = { version = "0.3.0", features = ["print-trace"] } -tabbycat = { version = "0.1", features = ["attributes"], optional = true } -csv = "1.1" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -hex = "0.4.3" -num-bigint = "0.4" -num_cpus = "1.15" -snark-verifier-sdk = { git = "https://github.com/privacy-scaling-explorations/snark-verifier"} -snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier"} -itertools = "0.10.3" -ethers = { version = "2.0.7", default-features = false, features = ["ethers-solc"] } -regex-simple = { version = "1", package = "regex" } -nova-snark = "0.23.0" -nova-scotia = { git = "https://github.com/nalinbhardwaj/Nova-Scotia" } -poseidon-rs = { git = "https://github.com/arnaucube/poseidon-rs" } -ff = {package="ff_ce" , version="0.11", features = ["derive"]} -num-traits = "0.2.16" -rayon = "1.8.0" - -[dev-dependencies] -criterion= "0.3" - -[[bench]] -name = "full_solvency_flow" -harness = false diff --git a/zk_prover/README.md b/zk_prover/README.md deleted file mode 100644 index d92bd631..00000000 --- a/zk_prover/README.md +++ /dev/null @@ -1,130 +0,0 @@ -# ZK Prover - -This directory contains the Halo2 ZK circuit implementation for the Summa Proof of Solvency protocol. - -## Usage - -To build, test and print the circuits, execute - -``` -cargo build -cargo test --release --features dev-graph -``` - -## Documentation - -The documentation for the circuits can be generated by running - -``` -cargo doc --no-deps --open -``` - -## Powers of Tau Trusted Setup - -For testing purposes, it's not necessary to download the `ptau` file. The `generate_setup_artifacts` function can manage this by generating a new setup from a randomly generated value. This automated generation process is intended for testing and development convenience, and it should not be used in production. -For real-world situations, you must provide the path of a specific `ptau` file to the `generate_setup_artifacts`. The circuit will use the randomness from the given file. You can find an example that initializes a `Snapshot` instance [here](https://github.com/summa-dev/summa-solvency/blob/11d4fce5d18f6175804aa792fc9fc5ac27bf5c00/backend/src/apis/snapshot.rs#L115-L116) in the backend. - -## Build a Commitment - -A `gen_commitment.rs` script is provided to generate a commitment out of a Merkle Sum Tree. In particular, the example takes a csv file located in "../csv/entry_16.csv", build a Merkle Sum Tree and extract a commitment out it. The commitment is made of the `root_hash` and the `root_balances`. - -The script will eventually generate a `commitment_solidity_calldata.json` file that contains some testing calldata to be used within `contracts` and `backend` to test the publishing of the commitment to the Summa Smart Contract. - -The script can be run as follows: - -``` -cargo run --release --example gen_commitment -``` - -Note that the generic parameters of the Merkle Sum Tree `N_CURRENCIES` and `N_BYTES` are set to `2` and `14`. This means that this should go in pair with a Inclusion Verifier Circuit tuned to the same generic parameters. - -## Build an Inclusion Verifier Contract - -A `gen_inclusion_verifier.rs` script is provided to generate a solidity contract that can be used to verify the proof of user inclusion into CEX liabilites. The script can be run as follows: - -``` -cargo run --release --example gen_inclusion_verifier -``` - -The script will generate a new `InclusionVerifier.sol` and `InclusionVerifier.yul` contracts in `contracts/src`. - -Note that the generic parameters of the circuits `LEVELS`, `N_CURRENCIES` and `N_BYTES` are set to `4`, `2` and `14`. This means that the circuit is tuned to verify the proof of inclusion for an exchange with a userbase of 4 levels (2^4 = 16 users), 2 currencies and a balances in a range of 14 bytes. These parameters can be changed in the script. - -The verifier are generated based on an unsafe setup. For a production ready verifier, the setup should be generated by providing a `ptau` file generated after a trusted setup ceremony to `generate_setup_artifacts` function. - -On top of that the script will also generate a `inclusion_proof_solidity_calldata.json` file that contains some testing calldata to be used within `contracts` and `backend` to test the verifier. Again, in the example, the proof is generated based on the `../csv/entry_16.csv` file for a specific `user_index`, which is set to 0 by default. If you want to generate a testing proof for a different file, you can change the path in the script. If you want to generate a proof for a different `user_index`, you can change the `user_index` in the script. - -## Incremental Nova Verifier - -The Incremental Nova Verifier is an experimental feature that allows a user to verify a sequence of proofs of inclusion in one shot. More details can be found in the [write up](https://hackmd.io/@summa/HkGMF4Ovn). - -We provide an example to test the Nova verifier. The build folder already contains the artifacts generated by the circuit compilation. If you want to recompile the circuit, you can run the following command: - -``` -$ cd src/circom -$ npm install -$ circom incremental_mst_inclusion.circom --r1cs --wasm -o ../../examples/build --prime bn128 -``` - -To run the Nova Incremental Verifier example run: - -``` -cargo run --release --example nova_incremental_verifier -``` - -## Benches - -The benchmarking included the following areas: - -- Merkle Sum Tree Generation -- Verification Key Gen for MstInclusion Circuit -- Proving Key Gen for MstInclusion Circuit -- ZK Proof Generation for MstInclusion Circuit -- ZK Proof Verification for MstInclusion Circuit - -In order to run the benchmarking, we provide a set of dummy `username, balances` entries formatted in csv files. The csv files can be downloaded as follows - -``` -cd benches -mkdir csv -cd csv -wget https://summa-solvency.s3.eu-central-1.amazonaws.com/csv_files.tar.bz2 -tar -xjf csv_files.tar.bz2 -``` - -The csv folder will contain two subfolder namely `one_asset` and `two_assets`. Each folders will contain files named as `one_asset_entry_2_17.csv` or `two_assets_entry_2_5.csv`. 2^17 or 2^5 is the number of entries in the file that will be used to feed the merkle sum tree and, eventually, the zk prover. These entries represent the number of users of the exchange. - -To run the benches - -`cargo bench` - -You can set the following parameters to run the benches: - -- `LEVELS` -> the number of entries in the merkle sum tree. By default it is set to 20, which means that the benches will run for 2^20 entries. -- `SAMPLE_SIZE` -> the number of samples to run for each bench. By default it is set to 10, which is the minimum allowed by criterion.rs -- `N_CURRENCIES and PATH_NAME` -> the number of currencies to be used in the benchmarking. By default it is set to 1. For now you can only switch it between 1 and 2 as these are the only csv folder available. More will be added soon. - -Note that the `k` of the circuit may vary based on the LEVELS - -Furthermore the benchmarking function `verify_zk_proof_benchmark` will also print out the proof size in bytes. - -## Current Benches - -Run on MacBook Pro 2023, M2 Pro, 32GB RAM, 12 cores - -2^20 entries (1048576) users, 1 currency - -| MST init | -| -------- | -| 73.695 s | - -| MST init (sorted) | -| -------- | -| 73.847 s | - -For Merkle Sum Tree Proof of Inclusion circuit - -| VK Gen | Pk Gen | Proof Generation | Proof Verification | Proof Size (bytes) | -| ------------------ | ------------------- | ------------------- | ------------------- | ------------------ | -| 183.25 ms | 116.32 ms | 517.98 ms | 3.3291 ms | 1632 | - diff --git a/zk_prover/benches/full_solvency_flow.rs b/zk_prover/benches/full_solvency_flow.rs deleted file mode 100644 index 997b3e33..00000000 --- a/zk_prover/benches/full_solvency_flow.rs +++ /dev/null @@ -1,172 +0,0 @@ -#![feature(generic_const_exprs)] -use criterion::{criterion_group, criterion_main, Criterion}; -use halo2_proofs::plonk::{keygen_pk, keygen_vk}; -use snark_verifier_sdk::CircuitExt; -use summa_solvency::{ - circuits::merkle_sum_tree::MstInclusionCircuit, - circuits::utils::{full_prover, full_verifier, generate_setup_artifacts}, - merkle_sum_tree::{MerkleSumTree, Tree}, -}; - -const SAMPLE_SIZE: usize = 10; -const LEVELS: usize = 20; -const N_CURRENCIES: usize = 1; -const PATH_NAME: &str = "one_asset"; -const N_BYTES: usize = 14; - -fn build_mstree(_c: &mut Criterion) { - let mut criterion = Criterion::default().sample_size(SAMPLE_SIZE); - - let csv_file = format!( - "benches/csv/{}/{}_entry_2_{}.csv", - PATH_NAME, PATH_NAME, LEVELS - ); - - let bench_name = format!( - "build Merkle sum tree for 2 power of {} entries with {} currencies", - LEVELS, N_CURRENCIES - ); - - criterion.bench_function(&bench_name, |b| { - b.iter(|| { - MerkleSumTree::::new(&csv_file).unwrap(); - }) - }); -} - -fn build_sorted_mstree(_c: &mut Criterion) { - let mut criterion = Criterion::default().sample_size(SAMPLE_SIZE); - - let csv_file = format!( - "benches/csv/{}/{}_entry_2_{}.csv", - PATH_NAME, PATH_NAME, LEVELS - ); - - let bench_name = format!( - "build sorted Merkle sum tree for 2 power of {} entries with {} currencies", - LEVELS, N_CURRENCIES - ); - - criterion.bench_function(&bench_name, |b| { - b.iter(|| { - MerkleSumTree::::new_sorted(&csv_file).unwrap(); - }) - }); -} - -fn verification_key_gen_mst_inclusion_circuit(_c: &mut Criterion) { - let mut criterion = Criterion::default().sample_size(SAMPLE_SIZE); - - let empty_circuit = MstInclusionCircuit::::init_empty(); - - let (params, _, _) = generate_setup_artifacts(13, None, empty_circuit.clone()).unwrap(); - - let bench_name = format!( - "gen verification key for 2 power of {} entries with {} currencies mst inclusion circuit", - LEVELS, N_CURRENCIES - ); - criterion.bench_function(&bench_name, |b| { - b.iter(|| { - keygen_vk(¶ms, &empty_circuit).expect("vk generation should not fail"); - }) - }); -} - -fn proving_key_gen_mst_inclusion_circuit(_c: &mut Criterion) { - let mut criterion = Criterion::default().sample_size(SAMPLE_SIZE); - - let empty_circuit = MstInclusionCircuit::::init_empty(); - - let (params, _, vk) = generate_setup_artifacts(13, None, empty_circuit.clone()).unwrap(); - - let bench_name = format!( - "gen proving key for 2 power of {} entries with {} currencies mst inclusion circuit", - LEVELS, N_CURRENCIES - ); - criterion.bench_function(&bench_name, |b| { - b.iter(|| { - keygen_pk(¶ms, vk.clone(), &empty_circuit).expect("pk generation should not fail"); - }) - }); -} - -fn generate_zk_proof_mst_inclusion_circuit(_c: &mut Criterion) { - let mut criterion = Criterion::default().sample_size(SAMPLE_SIZE); - - let empty_circuit = MstInclusionCircuit::::init_empty(); - - let (params, pk, _) = generate_setup_artifacts(13, None, empty_circuit).unwrap(); - - let csv_file = format!( - "benches/csv/{}/{}_entry_2_{}.csv", - PATH_NAME, PATH_NAME, LEVELS - ); - - let merkle_sum_tree = MerkleSumTree::::new(&csv_file).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let bench_name = format!( - "generate zk proof - tree of 2 power of {} entries with {} currencies mst inclusion circuit", - LEVELS, N_CURRENCIES - ); - criterion.bench_function(&bench_name, |b| { - b.iter(|| { - full_prover(¶ms, &pk, circuit.clone(), circuit.instances()); - }) - }); -} - -fn verify_zk_proof_mst_inclusion_circuit(_c: &mut Criterion) { - let mut criterion = Criterion::default().sample_size(SAMPLE_SIZE); - - let empty_circuit = MstInclusionCircuit::::init_empty(); - - let (params, pk, vk) = generate_setup_artifacts(13, None, empty_circuit).unwrap(); - - let csv_file = format!( - "benches/csv/{}/{}_entry_2_{}.csv", - PATH_NAME, PATH_NAME, LEVELS - ); - - let merkle_sum_tree = MerkleSumTree::::new(&csv_file).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let proof = full_prover(¶ms, &pk, circuit.clone(), circuit.instances()); - - println!("proof size in bytes: {}", proof.len()); - - let bench_name = format!( - "verify zk proof - tree of 2 power of {} entries with {} currencies mst inclusion circuit", - LEVELS, N_CURRENCIES - ); - criterion.bench_function(&bench_name, |b| { - b.iter(|| { - full_verifier(¶ms, &vk, proof.clone(), circuit.instances()); - }) - }); -} - -criterion_group!( - benches, - build_mstree, - build_sorted_mstree, - verification_key_gen_mst_inclusion_circuit, - proving_key_gen_mst_inclusion_circuit, - generate_zk_proof_mst_inclusion_circuit, - verify_zk_proof_mst_inclusion_circuit, -); -criterion_main!(benches); diff --git a/zk_prover/circuit_parameters_gen/calc_round_numbers.py b/zk_prover/circuit_parameters_gen/calc_round_numbers.py deleted file mode 100644 index a656c2c3..00000000 --- a/zk_prover/circuit_parameters_gen/calc_round_numbers.py +++ /dev/null @@ -1,120 +0,0 @@ -# Credit: https://github.com/daira/pasta-hadeshash/blob/master/code/calc_round_numbers.py -from math import * - - -def sat_inequiv_alpha(p, t, R_F, R_P, alpha, M): - n = ceil(log(p, 2)) - N = int(n * t) - if alpha > 0: - R_F_1 = ( - 6 if M <= ((floor(log(p, 2) - ((alpha - 1) / 2.0))) * (t + 1)) else 10 - ) # Statistical - R_F_2 = ( - 1 + ceil(log(2, alpha) * min(M, n)) + ceil(log(t, alpha)) - R_P - ) # Interpolation - # R_F_3 = ceil(min(n, M) / float(3*log(alpha, 2))) - R_P # Groebner 1 - # R_F_3 = ((log(2, alpha) / float(2)) * min(n, M)) - R_P # Groebner 1 - R_F_3 = ( - 1 + (log(2, alpha) * min(M / float(3), log(p, 2) / float(2))) - R_P - ) # Groebner 1 - R_F_4 = ( - t - - 1 - + min( - (log(2, alpha) * M) / float(t + 1), - ((log(2, alpha) * log(p, 2)) / float(2)), - ) - - R_P - ) # Groebner 2 - # R_F_5 = ((1.0/(2*log((alpha**alpha)/float((alpha-1)**(alpha-1)), 2))) * min(n, M) + t - 2 - R_P) / float(t - 1) # Groebner 3 - R_F_max = max(ceil(R_F_1), ceil(R_F_2), ceil(R_F_3), ceil(R_F_4)) - return R_F >= R_F_max - elif alpha == (-1): - R_F_1 = 6 if M <= ((floor(log(p, 2) - 2)) * (t + 1)) else 10 # Statistical - R_P_1 = ( - 1 + ceil(0.5 * min(M, n)) + ceil(log(t, 2)) - floor(R_F * log(t, 2)) - ) # Interpolation - R_P_2 = 1 + ceil(0.5 * min(M, n)) + ceil(log(t, 2)) - floor(R_F * log(t, 2)) - R_P_3 = ( - t - - 1 - + ceil(log(t, 2)) - + min(ceil(M / float(t + 1)), ceil(0.5 * log(p, 2))) - - floor(R_F * log(t, 2)) - ) # Groebner 2 - R_F_max = ceil(R_F_1) - R_P_max = max(ceil(R_P_1), ceil(R_P_2), ceil(R_P_3)) - return R_F >= R_F_max and R_P >= R_P_max - else: - print("Invalid value for alpha!") - exit(1) - - -def get_sbox_cost(R_F, R_P, N, t): - return int(t * R_F + R_P) - - -def get_size_cost(R_F, R_P, N, t): - n = ceil(float(N) / t) - return int((N * R_F) + (n * R_P)) - - -def get_depth_cost(R_F, R_P, N, t): - return int(R_F + R_P) - - -def find_FD_round_numbers(p, t, alpha, M, cost_function, security_margin): - n = ceil(log(p, 2)) - N = int(n * t) - - sat_inequiv = sat_inequiv_alpha - - R_P = 0 - R_F = 0 - min_cost = float("inf") - max_cost_rf = 0 - # Brute-force approach - for R_P_t in range(1, 500): - for R_F_t in range(4, 100): - if R_F_t % 2 == 0: - if sat_inequiv(p, t, R_F_t, R_P_t, alpha, M) == True: - if security_margin == True: - R_F_t += 2 - R_P_t = int(ceil(float(R_P_t) * 1.075)) - cost = cost_function(R_F_t, R_P_t, N, t) - if (cost < min_cost) or ( - (cost == min_cost) and (R_F_t < max_cost_rf) - ): - R_P = ceil(R_P_t) - R_F = ceil(R_F_t) - min_cost = cost - max_cost_rf = R_F - return (int(R_F), int(R_P)) - - -def calc_final_numbers_fixed(p, t, alpha, M, security_margin): - # [Min. S-boxes] Find best possible for t and N - n = ceil(log(p, 2)) - N = int(n * t) - cost_function = get_sbox_cost - ret_list = [] - (R_F, R_P) = find_FD_round_numbers(p, t, alpha, M, cost_function, security_margin) - min_sbox_cost = cost_function(R_F, R_P, N, t) - ret_list.append(R_F) - ret_list.append(R_P) - ret_list.append(min_sbox_cost) - - # [Min. Size] Find best possible for t and N - # Minimum number of S-boxes for fixed n results in minimum size also (round numbers are the same)! - min_size_cost = get_size_cost(R_F, R_P, N, t) - ret_list.append(min_size_cost) - - return ret_list # [R_F, R_P, min_sbox_cost, min_size_cost] - - -# Modify this function to return results instead of printing them -def get_parameters(prime, t, alpha, M, security_margin): - [R_F, R_P, min_sbox_cost, min_size_cost] = calc_final_numbers_fixed( - prime, t, alpha, M, security_margin - ) - return t, M, alpha, security_margin, R_F, R_P, min_sbox_cost, min_size_cost \ No newline at end of file diff --git a/zk_prover/circuit_parameters_gen/generate_parameters_grain.sage b/zk_prover/circuit_parameters_gen/generate_parameters_grain.sage deleted file mode 100644 index e6db4561..00000000 --- a/zk_prover/circuit_parameters_gen/generate_parameters_grain.sage +++ /dev/null @@ -1,407 +0,0 @@ -# Credit: https://github.com/daira/pasta-hadeshash/blob/master/code/generate_parameters_grain.sage -#!/usr/bin/env sage - -# Remark: This script contains functionality for GF(2^n), but currently works only over GF(p)! A few small adaptations are needed for GF(2^n). -from sage.rings.polynomial.polynomial_gf2x import GF2X_BuildIrred_list - -# Note that R_P is increased to the closest multiple of t -# GF(p), alpha=3, N = 1536, n = 64, t = 24, R_F = 8, R_P = 42: sage generate_parameters_grain.sage 1 0 64 24 8 42 0xfffffffffffffeff -# GF(p), alpha=5, N = 1524, n = 254, t = 6, R_F = 8, R_P = 60: sage generate_parameters_grain.sage 1 0 254 6 8 60 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 -# GF(p), x^(-1), N = 1518, n = 253, t = 6, R_F = 8, R_P = 60: sage generate_parameters_grain.sage 1 1 253 6 8 60 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed - -# GF(p), alpha=5, N = 765, n = 255, t = 3, R_F = 8, R_P = 57: sage generate_parameters_grain.sage 1 0 255 3 8 57 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 -# GF(p), alpha=5, N = 1275, n = 255, t = 5, R_F = 8, R_P = 60: sage generate_parameters_grain.sage 1 0 255 5 8 60 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 -# GF(p), alpha=5, N = 762, n = 254, t = 3, R_F = 8, R_P = 57: sage generate_parameters_grain.sage 1 0 254 3 8 57 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 -# GF(p), alpha=5, N = 1270, n = 254, t = 5, R_F = 8, R_P = 60: sage generate_parameters_grain.sage 1 0 254 5 8 60 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 - -FIELD = None -SBOX = None -FIELD_SIZE = None -NUM_CELLS = None -R_F_FIXED = None -R_P_FIXED = None -PRIME_NUMBER = None -F = None -INIT_SEQUENCE = None - -def grain_sr_generator(): - bit_sequence = INIT_SEQUENCE - for _ in range(0, 160): - new_bit = bit_sequence[62] ^^ bit_sequence[51] ^^ bit_sequence[38] ^^ bit_sequence[23] ^^ bit_sequence[13] ^^ bit_sequence[0] - bit_sequence.pop(0) - bit_sequence.append(new_bit) - - while True: - new_bit = bit_sequence[62] ^^ bit_sequence[51] ^^ bit_sequence[38] ^^ bit_sequence[23] ^^ bit_sequence[13] ^^ bit_sequence[0] - bit_sequence.pop(0) - bit_sequence.append(new_bit) - while new_bit == 0: - new_bit = bit_sequence[62] ^^ bit_sequence[51] ^^ bit_sequence[38] ^^ bit_sequence[23] ^^ bit_sequence[13] ^^ bit_sequence[0] - bit_sequence.pop(0) - bit_sequence.append(new_bit) - new_bit = bit_sequence[62] ^^ bit_sequence[51] ^^ bit_sequence[38] ^^ bit_sequence[23] ^^ bit_sequence[13] ^^ bit_sequence[0] - bit_sequence.pop(0) - bit_sequence.append(new_bit) - new_bit = bit_sequence[62] ^^ bit_sequence[51] ^^ bit_sequence[38] ^^ bit_sequence[23] ^^ bit_sequence[13] ^^ bit_sequence[0] - bit_sequence.pop(0) - bit_sequence.append(new_bit) - yield new_bit -grain_gen = grain_sr_generator() - -def grain_random_bits(num_bits): - random_bits = [next(grain_gen) for i in range(0, num_bits)] - # random_bits.reverse() ## Remove comment to start from least significant bit - random_int = int("".join(str(i) for i in random_bits), 2) - return random_int - -def init_generator(field, sbox, n, t, R_F, R_P): - # Generate initial sequence based on parameters - bit_list_field = [_ for _ in (bin(FIELD)[2:].zfill(2))] - bit_list_sbox = [_ for _ in (bin(SBOX)[2:].zfill(4))] - bit_list_n = [_ for _ in (bin(FIELD_SIZE)[2:].zfill(12))] - bit_list_t = [_ for _ in (bin(NUM_CELLS)[2:].zfill(12))] - bit_list_R_F = [_ for _ in (bin(R_F)[2:].zfill(10))] - bit_list_R_P = [_ for _ in (bin(R_P)[2:].zfill(10))] - bit_list_1 = [1] * 30 - global INIT_SEQUENCE - INIT_SEQUENCE = bit_list_field + bit_list_sbox + bit_list_n + bit_list_t + bit_list_R_F + bit_list_R_P + bit_list_1 - INIT_SEQUENCE = [int(_) for _ in INIT_SEQUENCE] - -def generate_constants(field, n, t, R_F, R_P, prime_number): - round_constants = [] - num_constants = (R_F + R_P) * t - - if field == 0: - for i in range(0, num_constants): - random_int = grain_random_bits(n) - round_constants.append(random_int) - elif field == 1: - for i in range(0, num_constants): - random_int = grain_random_bits(n) - while random_int >= prime_number: - # print("[Info] Round constant is not in prime field! Taking next one.") - random_int = grain_random_bits(n) - round_constants.append(random_int) - return round_constants - -def print_hex(c, last, rust=False): - c = int(c) - hex_str = "" - if rust: - hex_str += " Fp::from_raw([\n" - for i in range(0, FIELD_SIZE, 64): - hex_str += " 0x%04x_%04x_%04x_%04x,\n" % tuple([(c >> j) & 0xFFFF for j in range(i+48, i-1, -16)]) - hex_str += " ]),\n" - else: - hex_length = (FIELD_SIZE + 3)//4 + 2 # +2 for "0x" - hex_str += "{0:#0{1}x}".format(c, hex_length) + ("" if last else ", ") - return hex_str - -def print_round_constants(round_constants, n, t, field, R_F, R_P, rust=False, file_name="./../src/chips/poseidon/poseidon_params.rs"): - num_round_constants = len(round_constants) - assert num_round_constants % t == 0 - rounds = num_round_constants // t # R_F + R_P - with open(file_name, 'w') as f: - f.write("//! This file was generated by running generate_params.py\n") - f.write("//! Number of round constants: {}\n".format(num_round_constants)) - - if field == 0: - f.write("//! Round constants for GF(2^n):\n") - elif field == 1: - f.write("//! Round constants for GF(p):\n") - if rust: - f.write("//! Parameters for using rate {} Poseidon with the BN256 field.\n".format(t - 1)) - f.write("//! Patterned after [halo2_gadgets::poseidon::primitives::fp]\n") - f.write("//! The parameters can be reproduced by running the following Sage script from\n") - f.write("//! [this repository](https://github.com/daira/pasta-hadeshash):\n") - f.write("//!\n//! ```text\n//! $ sage generate_parameters_grain.sage 1 0 254 {} {} {} 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 --rust\n//! ```\n//!\n".format(t, R_F, R_P)) - f.write("//! where 1 means 'prime field', 0 means 'non-negative sbox', 254 is the bitsize\n//! of the field, {} is the Poseidon width (rate + 1), {} is the number of full\n//! rounds, {} is the number of partial rounds.\n//! More info here => https://hackmd.io/@letargicus/SJOvx48Nn\n".format(t, R_F, R_P)) - f.write("use halo2_proofs::halo2curves::bn256::Fr as Fp;\n") - f.write("pub(crate) const ROUND_CONSTANTS: [[Fp; {}]; {}] = [\n".format(t, rounds)) - - for r in range(rounds): - f.write(" [\n" if rust else " [") - for (i, entry) in enumerate(round_constants[r*t : (r+1)*t]): - f.write(print_hex(entry, i == t-1, rust=rust)) - f.write(" ],\n" if rust else "],\n") - if rust: - f.write("];\n") - -def create_mds_p(n, t): - M = matrix(F, t, t) - - # Sample random distinct indices and assign to xs and ys - while True: - flag = True - rand_list = [F(grain_random_bits(n)) for _ in range(0, 2*t)] - while len(rand_list) != len(set(rand_list)): # Check for duplicates - rand_list = [F(grain_random_bits(n)) for _ in range(0, 2*t)] - xs = rand_list[:t] - ys = rand_list[t:] - # xs = [F(ele) for ele in range(0, t)] - # ys = [F(ele) for ele in range(t, 2*t)] - for i in range(0, t): - for j in range(0, t): - if (flag == False) or ((xs[i] + ys[j]) == 0): - flag = False - else: - entry = (xs[i] + ys[j])^(-1) - M[i, j] = entry - if flag == False: - continue - return M - -def generate_vectorspace(round_num, M, M_round, NUM_CELLS): - t = NUM_CELLS - s = 1 - V = VectorSpace(F, t) - if round_num == 0: - return V - elif round_num == 1: - return V.subspace(V.basis()[s:]) - else: - mat_temp = matrix(F) - for i in range(0, round_num-1): - add_rows = [] - for j in range(0, s): - add_rows.append(M_round[i].rows()[j][s:]) - mat_temp = matrix(mat_temp.rows() + add_rows) - r_k = mat_temp.right_kernel() - extended_basis_vectors = [] - for vec in r_k.basis(): - extended_basis_vectors.append(vector([0]*s + list(vec))) - S = V.subspace(extended_basis_vectors) - - return S - -def subspace_times_matrix(subspace, M, NUM_CELLS): - t = NUM_CELLS - V = VectorSpace(F, t) - subspace_basis = subspace.basis() - new_basis = [] - for vec in subspace_basis: - new_basis.append(M * vec) - new_subspace = V.subspace(new_basis) - return new_subspace - -# Returns True if the matrix is considered secure, False otherwise -def algorithm_1(M, NUM_CELLS): - t = NUM_CELLS - s = 1 - r = floor((t - s) / float(s)) - - # Generate round matrices - M_round = [] - for j in range(0, t+1): - M_round.append(M^(j+1)) - - for i in range(1, r+1): - mat_test = M^i - entry = mat_test[0, 0] - mat_target = matrix.circulant(vector([entry] + ([F(0)] * (t-1)))) - - if (mat_test - mat_target) == matrix.circulant(vector([F(0)] * (t))): - return [False, 1] - - S = generate_vectorspace(i, M, M_round, t) - V = VectorSpace(F, t) - - basis_vectors= [] - for eigenspace in mat_test.eigenspaces_right(format='galois'): - if (eigenspace[0] not in F): - continue - vector_subspace = eigenspace[1] - intersection = S.intersection(vector_subspace) - basis_vectors += intersection.basis() - IS = V.subspace(basis_vectors) - - if IS.dimension() >= 1 and IS != V: - return [False, 2] - for j in range(1, i+1): - S_mat_mul = subspace_times_matrix(S, M^j, t) - if S == S_mat_mul: - print("S.basis():\n", S.basis()) - return [False, 3] - - return [True, 0] - -# Returns True if the matrix is considered secure, False otherwise -def algorithm_2(M, NUM_CELLS): - t = NUM_CELLS - s = 1 - - V = VectorSpace(F, t) - trail = [None, None] - test_next = False - I = range(0, s) - I_powerset = list(sage.misc.misc.powerset(I))[1:] - for I_s in I_powerset: - test_next = False - new_basis = [] - for l in I_s: - new_basis.append(V.basis()[l]) - IS = V.subspace(new_basis) - for i in range(s, t): - new_basis.append(V.basis()[i]) - full_iota_space = V.subspace(new_basis) - for l in I_s: - v = V.basis()[l] - while True: - delta = IS.dimension() - v = M * v - IS = V.subspace(IS.basis() + [v]) - if IS.dimension() == t or IS.intersection(full_iota_space) != IS: - test_next = True - break - if IS.dimension() <= delta: - break - if test_next == True: - break - if test_next == True: - continue - return [False, [IS, I_s]] - - return [True, None] - -# Returns True if the matrix is considered secure, False otherwise -def algorithm_3(M, NUM_CELLS): - t = NUM_CELLS - s = 1 - - V = VectorSpace(F, t) - - l = 4*t - for r in range(2, l+1): - next_r = False - res_alg_2 = algorithm_2(M^r, t) - if res_alg_2[0] == False: - return [False, None] - - # if res_alg_2[1] == None: - # continue - # IS = res_alg_2[1][0] - # I_s = res_alg_2[1][1] - # for j in range(1, r): - # IS = subspace_times_matrix(IS, M, t) - # I_j = [] - # for i in range(0, s): - # new_basis = [] - # for k in range(0, t): - # if k != i: - # new_basis.append(V.basis()[k]) - # iota_space = V.subspace(new_basis) - # if IS.intersection(iota_space) != iota_space: - # single_iota_space = V.subspace([V.basis()[i]]) - # if IS.intersection(single_iota_space) == single_iota_space: - # I_j.append(i) - # else: - # next_r = True - # break - # if next_r == True: - # break - # if next_r == True: - # continue - # return [False, [IS, I_j, r]] - - return [True, None] - -def generate_matrix(FIELD, FIELD_SIZE, NUM_CELLS): - if FIELD == 0: - print("Matrix generation not implemented for GF(2^n).") - exit(1) - elif FIELD == 1: - mds_matrix = create_mds_p(FIELD_SIZE, NUM_CELLS) - result_1 = algorithm_1(mds_matrix, NUM_CELLS) - result_2 = algorithm_2(mds_matrix, NUM_CELLS) - result_3 = algorithm_3(mds_matrix, NUM_CELLS) - while result_1[0] == False or result_2[0] == False or result_3[0] == False: - mds_matrix = create_mds_p(FIELD_SIZE, NUM_CELLS) - result_1 = algorithm_1(mds_matrix, NUM_CELLS) - result_2 = algorithm_2(mds_matrix, NUM_CELLS) - result_3 = algorithm_3(mds_matrix, NUM_CELLS) - return mds_matrix - -def invert_matrix(M): - MS = MatrixSpace(F, NUM_CELLS, NUM_CELLS, sparse=False) - return MS.matrix(M).inverse() - -def print_matrix(M, t, rust=False, file_name="./../src/chips/poseidon/poseidon_params.rs"): - # 'a' for append mode - with open(file_name, 'a') as f: - for row in range(t): - f.write(" [\n" if rust else "") - for (i, entry) in enumerate(M[row]): - f.write(print_hex(entry, i == t-1, rust=rust)) - f.write(" ]," if rust else "],") - f.write("\n];\n") - -def print_linear_layer(M, n, t, rust=False, file_name="./../src/chips/poseidon/poseidon_params.rs"): - # 'a' for append mode - with open(file_name, 'a') as f: - f.write("// n: {}\n".format(n)) - f.write("// t: {}\n".format(t)) - f.write("// N: {}\n".format(n * t)) - f.write("// Result Algorithm 1:\n") - f.write("// {}\n".format(algorithm_1(M, NUM_CELLS))) - f.write("// Result Algorithm 2:\n") - f.write("// {}\n".format(algorithm_2(M, NUM_CELLS))) - f.write("// Result Algorithm 3:\n") - f.write("// {}\n".format(algorithm_3(M, NUM_CELLS))) - f.write("// Prime number: {}\n".format("0x" + hex(PRIME_NUMBER))) - - f.write("// MDS matrix:\n") - f.write("pub(crate) const MDS: [[Fp; {}]; {}] = [\n".format(t, t) if rust else "") - - print_matrix(M, t, rust=rust, file_name=file_name) - - with open(file_name, 'a') as f: - f.write("// Inverse MDS matrix:\n") - f.write("pub(crate) const MDS_INV: [[Fp; {}]; {}] = [\n".format(t, t) if rust else "") - - print_matrix(invert_matrix(M), t, rust=rust, file_name=file_name) - -def main(args): - if len(args) < 7: - print("Usage: sage generate_parameters_grain.sage () [--rust]") - print("field = 1 for GF(p)") - print("s_box = 0 for x^alpha, s_box = 1 for x^(-1)") - return - - # Parameters - global FIELD, SBOX, FIELD_SIZE, NUM_CELLS, R_F_FIXED, R_P_FIXED, PRIME_NUMBER, F - - FIELD = int(args[0]) # 0 .. GF(2^n), 1 .. GF(p) - SBOX = int(args[1]) # 0 .. x^alpha, 1 .. x^(-1) - FIELD_SIZE = int(args[2]) # n - NUM_CELLS = int(args[3]) # t - R_F_FIXED = int(args[4]) - R_P_FIXED = int(args[5]) - - PRIME_NUMBER = 0 - if FIELD == 0: - args = args[6:] - elif FIELD == 1 and len(args) < 7: - print("Please specify a prime number (in hex format)!") - return - elif FIELD == 1 and len(args) >= 7: - PRIME_NUMBER = int(args[6], 16) # e.g. 0xa7, 0xFFFFFFFFFFFFFEFF, 0xa1a42c3efd6dbfe08daa6041b36322ef - args = args[7:] - - F = GF(PRIME_NUMBER) - - file_name = args[0] - rust = '--rust' in args - - # Init - init_generator(FIELD, SBOX, FIELD_SIZE, NUM_CELLS, R_F_FIXED, R_P_FIXED) - - # Round constants - round_constants = generate_constants(FIELD, FIELD_SIZE, NUM_CELLS, R_F_FIXED, R_P_FIXED, PRIME_NUMBER) - print_round_constants(round_constants, FIELD_SIZE, NUM_CELLS, FIELD, R_F_FIXED, R_P_FIXED, rust=rust, file_name=file_name) - - # Matrix - linear_layer = generate_matrix(FIELD, FIELD_SIZE, NUM_CELLS) - print_linear_layer(linear_layer, FIELD_SIZE, NUM_CELLS, rust=rust, file_name=file_name) - -if __name__ == "__main__": - main(sys.argv[1:]) \ No newline at end of file diff --git a/zk_prover/circuit_parameters_gen/generate_params.py b/zk_prover/circuit_parameters_gen/generate_params.py deleted file mode 100644 index 9b5eddde..00000000 --- a/zk_prover/circuit_parameters_gen/generate_params.py +++ /dev/null @@ -1,95 +0,0 @@ -import os -from calc_round_numbers import get_parameters - -# Parameters -p = 0x30644E72E131A029B85045B68181585D2833E84879B9709143E1F593F0000001 - -t = 2 # Poseidon hasher width -M = 128 - -# Call the function and get the parameters -t, M, alpha, security_margin, R_F, R_P, min_sbox_cost, min_size_cost = get_parameters( - p, t, 5, M, True -) - -# Round R_P up to the nearest multiple of t -R_P = ((R_P + t - 1) // t) * t - -# Add one more t if partial rounds number is not even -if R_P % 2 != 0: - R_P += t - -command = f"sage generate_parameters_grain.sage 1 0 254 {t} {R_F} {R_P} 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 './../src/chips/poseidon/poseidon_params.rs' --rust" -os.system(command) - - -def generate_spec(t, alpha, R_F, R_P, file_name): - with open(file_name, "w") as f: - f.write("//! This file was generated by running generate_params.py\n") - f.write( - "//! Specification for rate {} Poseidon using the BN256 curve.".format( - t - 1 - ) - ) - f.write("\n") - f.write( - "//! Patterned after [halo2_gadgets::poseidon::primitives::P128Pow5T3]\n" - ) - - f.write("use crate::chips::poseidon::poseidon_params;\n") - f.write("use halo2_gadgets::poseidon::primitives::*;\n") - f.write("use halo2_proofs::arithmetic::Field;\n") - f.write("use halo2_proofs::halo2curves::bn256::Fr as Fp;\n") - f.write("\n") - f.write("#[derive(Debug, Clone, Copy)]\n") - f.write("pub struct PoseidonSpec;\n") - f.write("\n") - f.write("pub(crate) type Mds = [[Fp; T]; T];\n") - f.write("\n") - f.write("impl Spec for PoseidonSpec {{\n".format(t, t - 1)) - f.write(" fn full_rounds() -> usize {\n") - f.write(" {}\n".format(R_F)) - f.write(" }\n") - f.write("\n") - f.write(" fn partial_rounds() -> usize {\n") - f.write(" {}\n".format(R_P)) - f.write(" }\n") - f.write("\n") - f.write(" fn sbox(val: Fp) -> Fp {\n") - f.write(" val.pow_vartime([{}])\n".format(alpha)) - f.write(" }\n") - f.write("\n") - f.write(" fn secure_mds() -> usize {\n") - f.write(" unimplemented!()\n") - f.write(" }\n") - f.write("\n") - f.write( - " fn constants() -> (Vec<[Fp; {}]>, Mds, Mds) {{\n".format( - t, t, t - ) - ) - f.write(" (\n") - f.write(" poseidon_params::ROUND_CONSTANTS[..].to_vec(),\n") - f.write(" poseidon_params::MDS,\n") - f.write(" poseidon_params::MDS_INV,\n") - f.write(" )\n") - f.write(" }\n") - f.write("}\n") - - -file_name = "./../src/chips/poseidon/poseidon_spec.rs" -generate_spec(t, alpha, R_F, R_P, file_name) - -# Print the results -def print_results(t, M, alpha, security_margin, R_F, R_P, min_sbox_cost, min_size_cost): - print(f"t = {t}") - print(f"M = {M}") - print(f"alpha = {alpha}") - print(f"security_margin = {security_margin}") - print(f"R_F = {R_F}") - print(f"R_P = {R_P}") - print(f"min_sbox_cost = {min_sbox_cost}") - print(f"min_size_cost = {min_size_cost}") - - -print_results(t, M, alpha, security_margin, R_F, R_P, min_sbox_cost, min_size_cost) diff --git a/zk_prover/examples/build/incremental_mst_inclusion.r1cs b/zk_prover/examples/build/incremental_mst_inclusion.r1cs deleted file mode 100644 index d7258e5a..00000000 Binary files a/zk_prover/examples/build/incremental_mst_inclusion.r1cs and /dev/null differ diff --git a/zk_prover/examples/build/incremental_mst_inclusion_js/incremental_mst_inclusion.wasm b/zk_prover/examples/build/incremental_mst_inclusion_js/incremental_mst_inclusion.wasm deleted file mode 100644 index 7878c72b..00000000 Binary files a/zk_prover/examples/build/incremental_mst_inclusion_js/incremental_mst_inclusion.wasm and /dev/null differ diff --git a/zk_prover/examples/commitment_solidity_calldata.json b/zk_prover/examples/commitment_solidity_calldata.json deleted file mode 100644 index 90faf8a9..00000000 --- a/zk_prover/examples/commitment_solidity_calldata.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "root_hash": "0x18d6ab953235a811edffa4cead74ea045e7cd2085771a2269d59dca054c955b1", - "root_balances": [ - "0x87f3e", - "0x87f3e" - ] -} \ No newline at end of file diff --git a/zk_prover/examples/gen_commitment.rs b/zk_prover/examples/gen_commitment.rs deleted file mode 100644 index e7a5e87e..00000000 --- a/zk_prover/examples/gen_commitment.rs +++ /dev/null @@ -1,41 +0,0 @@ -#![feature(generic_const_exprs)] - -use serde_json::to_string_pretty; -use std::{fs::File, io::Write}; -use summa_solvency::{ - circuits::types::CommitmentSolidityCallData, - circuits::utils::field_element_to_solidity_calldata, - merkle_sum_tree::{MerkleSumTree, Tree}, -}; - -const N_CURRENCIES: usize = 2; -const N_BYTES: usize = 14; - -fn main() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let root = merkle_sum_tree.root(); - - // The commitment to be published on-chain is made of (root_hash, root_balances) - let root_hash_hex_string = field_element_to_solidity_calldata(root.hash); - let root_balances_hex_strings: Vec = root - .balances - .iter() - .map(|balance| field_element_to_solidity_calldata(*balance)) - .collect(); - - let commitment = CommitmentSolidityCallData { - root_hash: root_hash_hex_string, - root_balances: root_balances_hex_strings, - }; - - // Serialize to a JSON string - let serialized_data = to_string_pretty(&commitment).expect("Failed to serialize data"); - - // Save the serialized data to a JSON file - let mut file = File::create("./examples/commitment_solidity_calldata.json") - .expect("Unable to create file"); - file.write_all(serialized_data.as_bytes()) - .expect("Unable to write data to file"); -} diff --git a/zk_prover/examples/gen_inclusion_verifier.rs b/zk_prover/examples/gen_inclusion_verifier.rs deleted file mode 100644 index 7859133a..00000000 --- a/zk_prover/examples/gen_inclusion_verifier.rs +++ /dev/null @@ -1,111 +0,0 @@ -#![feature(generic_const_exprs)] - -use halo2_proofs::halo2curves::{bn256::Fr as Fp, ff::PrimeField}; -use num_bigint::BigInt; -use num_traits::Num; -use serde_json::to_string_pretty; -use snark_verifier_sdk::{ - evm::{evm_verify, gen_evm_proof_shplonk, gen_evm_verifier_shplonk}, - CircuitExt, -}; -use std::{fs::File, io::Write, path::Path}; -use summa_solvency::{ - circuits::{ - merkle_sum_tree::MstInclusionCircuit, - types::ProofSolidityCallData, - utils::{ - gen_proof_solidity_calldata, generate_setup_artifacts, write_verifier_sol_from_yul, - }, - }, - merkle_sum_tree::{MerkleSumTree, Tree}, -}; - -const LEVELS: usize = 4; -const N_CURRENCIES: usize = 2; -const N_BYTES: usize = 14; - -fn main() { - // Assert that there is no risk of overflow in the Merkle Root given the combination of `N_BYTES` and `LEVELS` - assert!(!is_there_risk_of_overflow(N_BYTES, LEVELS), "There is a risk of balance overflow in the Merkle Root, given the combination of `N_BYTES` and `LEVELS`"); - - // In order to generate the verifier we create the circuit using the init_empty() method, which means that the circuit is not initialized with any data. - let circuit = MstInclusionCircuit::::init_empty(); - - // generate a universal trusted setup for testing, along with the verification key (vk) and the proving key (pk). - let (params, pk, _) = - generate_setup_artifacts(11, Some("../backend/ptau/hermez-raw-11"), circuit.clone()) - .unwrap(); - - let num_instances = circuit.num_instance(); - - let yul_output_path = "../contracts/src/InclusionVerifier.yul"; - let sol_output_path = "../contracts/src/InclusionVerifier.sol"; - - let deployment_code = - gen_evm_verifier_shplonk::>( - ¶ms, - pk.get_vk(), - num_instances, - Some(Path::new(yul_output_path)), - ); - - write_verifier_sol_from_yul(yul_output_path, sol_output_path).unwrap(); - - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - // In order to generate a proof for testing purpose we create the circuit using the init() method - // which takes as input the merkle sum tree and the index of the leaf we are generating the proof for. - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - // Generate the circuit with the actual inputs - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let instances = circuit.instances(); - - let proof = gen_evm_proof_shplonk(¶ms, &pk, circuit.clone(), instances.clone()); - - let proof_solidity_calldata = gen_proof_solidity_calldata(¶ms, &pk, circuit.clone()); - - let proof_hex_string = format!("0x{}", hex::encode(&proof_solidity_calldata.clone().0 .0)); - - let data = ProofSolidityCallData { - proof: proof_hex_string, - public_inputs: proof_solidity_calldata.1, - }; - - // Serialize the data to a JSON string - let serialized_data = to_string_pretty(&data).expect("Failed to serialize data"); - - // Save the serialized data to a JSON file - let mut file = File::create("./examples/inclusion_proof_solidity_calldata.json") - .expect("Unable to create file"); - file.write_all(serialized_data.as_bytes()) - .expect("Unable to write data to file"); - - let gas_cost = evm_verify(deployment_code, instances, proof); - - print!("gas_cost: {:?}", gas_cost); -} - -// Calculate the maximum value that the Merkle Root can have, given N_BYTES and LEVELS -fn calculate_max_root_balance(n_bytes: usize, n_levels: usize) -> BigInt { - // The max value that can be stored in a leaf node or a sibling node, according to the constraint set in the circuit - let max_leaf_value = BigInt::from(2).pow(n_bytes as u32 * 8) - 1; - max_leaf_value * (n_levels + 1) -} - -// Given a combination of `N_BYTES` and `LEVELS`, check if there is a risk of overflow in the Merkle Root -fn is_there_risk_of_overflow(n_bytes: usize, n_levels: usize) -> bool { - // Calculate the max root balance value - let max_root_balance = calculate_max_root_balance(n_bytes, n_levels); - - // The modulus of the BN256 curve - let modulus = BigInt::from_str_radix(&Fp::MODULUS[2..], 16).unwrap(); - - // Check if the max balance value is greater than the prime - max_root_balance > modulus -} diff --git a/zk_prover/examples/inclusion_proof_solidity_calldata.json b/zk_prover/examples/inclusion_proof_solidity_calldata.json deleted file mode 100644 index 900a80c1..00000000 --- a/zk_prover/examples/inclusion_proof_solidity_calldata.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "proof": "0x2b8ec217faa4ff648136bd4fb5836ae599f2c7025d232df42c8edb977dd0dce120abf6efa3de5bfd0387687a8c5a31852c6a8e336d9881281be4896a5f56fbec0f52ab47f864ad21a3bccf14bf1ead807a2a09d1632b66f47a1b3d39ca9db4852a1863993de31e1fefc5d3d83df19638aceba560e20a18c499ef794c7eac07181117dc661ebe16ef4747828d2700b10b960e91bd253f4988c74ea3deb493fdde2b103c8cbfc595711ba36e4870623eefde8b5ce8e63f55ee1041c0b0526dc096278bb5dd249ac507adac511d223bb3201a8b14fbd8783902786904fda81dfa9b1bbbc67a76f54d73698aecbdc5e410d0d67a0a5912b1bdbf82b5868357cb684a0fbfdb9b4edb1f4021843572f1164b6628ccd628fbe9ec2075700cfa7a33f0462b7aab71071cae1ea223a0edcbc12488f8bf2d1fb81eba838e8d1641f91bc724301794f3cee5354776e99016447933681bfb9bbe32679a5693fd6f1413c2bc7d14a389f96365bb0addb52cec732e1990cdf1daf73e994d1c41f5f59645715e5a1d3b0015abaff3179104ed73f4e679c321b54de127bed122f2f2d129e15696b406b8395241aef1905fa3ba1e99c25ef40a4edd45c9ba53a052df0747a15d892c05a3a4f7fbf7e060ea50aa6373f32ed5de44d52cc02b1a08fe7ecfe48efb35151745982a2eb06d8891f3043183e0b432e58df1be4c67a1bbba5791320890e17111adfaf477216e37ebb2db397af59accd8ea14e047595d103d8ec4da13a22bd91ccea57b6f614b5e4f01f1281f85d7c8a4908c765c3ab73f0d14eb89f6f6bcdf1834490bf67f71ea578e0ff5692c3c16d4e2db0362b6eb55355b66e177eb91c209e67c95637a58d426edf89ad22b55bfbe440335a97e26f711e6607d8007d5362484e71a5cb5ebaabddf7970dd486d8c89c5524102a25c7203d059b687a3fb930df18e7fcfdc3940e3ee1297bcd5f24c22c2883b4d0cb2c5eb22f1e01d02bc7e0162838206bd631a050aa3c3f07a9474185735af8e3eddea823c7882ddd4c3c6141f2e41e3df26a5a0fe60afffa9903b923b25f2055e915793e7a9d942fa58a916a7a9a3a7ef18141c3e04134e506910d86a9ae0c09f3973ce6693bfe6432d921120763bbf6de53e7408db420ae014185ef69b1c7f203f79f61b4b3a28f836d5224c0bbabb23ccc7cf5e286cc243c95d412daaffd0271762daf9e465e76f60941c4b6a68f591ba7bb37a1005c2ce1e42eb91309e367f8f690fb8acc2f8102f07149927c8f0510c68bbcb6f98dc94d869d2415caa0e51bb7d862187e407699694194e516d961b00e33729aff5c4a4b1a112e6a208424217ee4548857ec7f9a97510e5be95e89dc1876229a87e86d661a58186ff22149390aeee5c5a4d861870c912ccf5acdd6a00eaafbd2dbd72b75e7a83005e9c8974474e28d7c37deac073780144011b7e7c3f7ce4d388852e34de994244db8c83d6c0185e70f3ec7276c5c4274d0eb5cb0ec0a9da8d2662aa77c60d004e20abe9339380e523cec01a7a0dda1dda17a53549b9539fc9a7fca3f303479ac9da7e6adb1013effdaf9aa6709e362c4ae1e2078c215c5581627f54bef6b55b2d5618b85df9e43fa2b9fe2d182be811066206e6224c5b632a4962a7eb3d6a8f29b10a6aa62aac8627fe6fc0f4b1b52a27c252ed2bb6f5f6c5e0d4987ef595b039e343984c5115e23b31b8aee89e7910dd40c368fd25c31eeeaf9d90206af9a09b26ec7b2e0acaa9206861efe3615f154c29f8722d3f9c9bdc4eee9c233bb97bdf08387a3a900ab0b6ee4d7634622c0852b3418d8318925a1f7f0365f83378b5ff13dc04c2d0f44290b17555f2d5db2e3e66ebab912dd822540d343f03e711b84b97433ad04b5f3b64641037ac2836027a959589488c1f1abe7b1a1728b1157738289c28a871a80c3fbdf0287271c0186bd9c324f838e4628bb7ffef0f6ce6906cfafe73ed2ba19575026de192576a06e532b372545fd6f690c0bdec35cd7e675f63b12a714c0bf1bc4a485fc14ad90c399b3dc32d63824044bc85d3a78b1943071350c2deed66a26d58a954c15ae01151f857d877633bd8a7a343af19c639c7965e34023b6f056ff6fcab5e3a58ff0b1d192e4bdbd63f4a6fa8d7865f452efe6aa7f01ee507de5ba0537e9a2b5b3722a25cc2ac937ea7c5d106af18db42be2704cc2c99e14307d9c27c5df4a793491d2a60089e118b151951899d0679fe31675ab75bf6d27cb3f5a0711805b4e3d41823fd8eab381199d8df15db53ce2f9d7d11e740c40302d5264823ffdc0b32e324768f5359e0ae0a78ea27713740010c919dce2d719c6bda51f87bbcfad2eec224a5feede2c93f76d746a042d20c2110edd9e3d67c68321adf17c1b5a93695072df36d505530b3db3f0d0f19a56e7a3cf19cf74e1c92e26a54e71b10e8bd97dc0a1d78b3de56fd28a80404695ed0dd979b3f49ffad4d573460882beaf828a4bb13fb65524b2ac61ea54c32fba196d38bb45016ddc10c356d089b6ca00c2da0880599fbfaa7db836f4cef2636b7a5c171f235f31478ff042f04926880ddaa863a1fb71fd14345862a5a8594743d7470c36ed6897616aa0ed22d5938bef7b283db279f21d671afb9e7744b82f86cee5a79ad96a222ce5da3d413bfb4abe5fee17d20fb01b51a5a68b8bfa5ffa6f112a88fd654e5936f3c86283a15c6ff96b6d4b305422f2c95734c2d36e835502db84726f159e0d4a58c12bf9aea22ddfeb4e10a23c852c21dddc01fdd73051cccd604331bbaff6fdd1b9b4b05176c4866f7ea260339ca3d20fee4259b3664428aa7bd925774815ffff772b2cc8d3ab49b0e18430c91ec310edf4bfa0b25e1ad9e03c8aaea974b5153b6552fffd0014715e19e9521d120f3d4937faad988f61acfa8708df3734c47b5bdfdc5e5b5c12cbb90e3b003678e1fb05ef01dbf967f978d64770ba731872439088e691b43d3ffde3d44c80e0f72444f7073ce8959f3c9718f290710fd35bd1a84f9b3a10beaa2da7c7b58", - "public_inputs": [ - "0xe113acd03b98f0bab0ef6f577245d5d008cbcc19ef2dab3608aa4f37f72a407", - "0x18d6ab953235a811edffa4cead74ea045e7cd2085771a2269d59dca054c955b1", - "0x87f3e", - "0x87f3e" - ] -} \ No newline at end of file diff --git a/zk_prover/examples/nova_incremental_verifier.rs b/zk_prover/examples/nova_incremental_verifier.rs deleted file mode 100644 index 3841d94f..00000000 --- a/zk_prover/examples/nova_incremental_verifier.rs +++ /dev/null @@ -1,449 +0,0 @@ -use std::{ - collections::HashMap, - env::current_dir, - fs::File, - io::{BufRead, BufReader}, - time::Instant, -}; - -use ff::{Field, PrimeField}; -use nova_scotia::{ - circom::reader::load_r1cs, create_public_params, create_recursive_circuit, FileLocation, F, S, -}; -use nova_snark::{provider, CompressedSNARK, PublicParams}; -use num_bigint::BigUint; -use serde_json::json; -use summa_solvency::merkle_sum_tree::utils::big_intify_username; - -const N_CURRENCIES: usize = 2; - -/// In this scenario the Exchange is generating an incremental inclusion proof for a user after 3 rounds. -/// It means that starting from this proof, the user can verify their correct inclusion in the Liabilities Tree for each round up to round 3 in a single proof. -/// -fn run_test(circuit_filepath: String, witness_gen_filepath: String) { - // Liabilities State represents the state of the Liabilities Tree at each step. H(prev_state, root) = liabiltiies_state. It starts at 0 - // The Liabilties State is submitted to the smart contract at each step as part of the Proof of Solvency (not included in this example) - let liabilities_state_0 = Fr::from_str("0").unwrap(); - - // Merkle Proof represents the inclusion proof for the user 0 for each state - let merkle_proof_1 = build_merkle_proof("../csv/states/entry_16_1.csv".to_string(), 0).unwrap(); - let liabilities_state_1 = - build_liabilities_state_cur(liabilities_state_0, merkle_proof_1.root.hash); - - let merkle_proof_2 = build_merkle_proof("../csv/states/entry_16_2.csv".to_string(), 0).unwrap(); - let liabilities_state_2 = - build_liabilities_state_cur(liabilities_state_1, merkle_proof_2.root.hash); - - let merkle_proof_3 = - build_merkle_proof("../csv/states/entry_16_3.csv".to_string(), 0).unwrap(); - let liabilities_state_3 = - build_liabilities_state_cur(liabilities_state_2, merkle_proof_3.root.hash); - - // At state 3, the user is requesting an incremental inclusion proof for the first time. The CEX generates it. - type G1 = provider::bn256_grumpkin::bn256::Point; - type G2 = provider::bn256_grumpkin::grumpkin::Point; - - println!( - "Running test with witness generator: {} and group: {}", - witness_gen_filepath, - std::any::type_name::() - ); - - let iteration_count = 3; - let root = current_dir().unwrap(); - - let circuit_file = root.join(circuit_filepath); - let r1cs = load_r1cs::(&FileLocation::PathBuf(circuit_file)); - let witness_generator_file = root.join(witness_gen_filepath); - - let pp: PublicParams = create_public_params(r1cs.clone()); - - println!( - "Number of constraints per step (primary circuit): {}", - pp.num_constraints().0 - ); - println!( - "Number of constraints per step (secondary circuit): {}", - pp.num_constraints().1 - ); - - println!( - "Number of variables per step (primary circuit): {}", - pp.num_variables().0 - ); - println!( - "Number of variables per step (secondary circuit): {}", - pp.num_variables().1 - ); - - // Build the private inputs for each step circuit - let merkle_proofs = vec![ - merkle_proof_1.clone(), - merkle_proof_2.clone(), - merkle_proof_3.clone(), - ]; - - let usernames = merkle_proofs - .iter() - .map(|proof| proof.username.clone()) - .collect::>(); - - let user_balances = merkle_proofs - .iter() - .map(|proof| proof.user_balances.clone()) - .collect::>>(); - - let path_element_hashes = merkle_proofs - .iter() - .map(|proof| proof.path_element_hashes.clone()) - .collect::>>(); - - let path_element_balances = merkle_proofs - .iter() - .map(|proof| proof.path_element_balances.clone()) - .collect::>>>(); - - let path_indices = merkle_proofs - .iter() - .map(|proof| proof.path_indices.clone()) - .collect::>>(); - - let mut private_inputs = Vec::new(); - for i in 0..iteration_count { - let mut private_input = HashMap::new(); - private_input.insert("username".to_string(), json!(usernames[i])); - private_input.insert("user_balances".to_string(), json!(user_balances[i])); - private_input.insert( - "path_element_hashes".to_string(), - json!(path_element_hashes[i]), - ); - private_input.insert( - "path_element_balances".to_string(), - json!(path_element_balances[i]), - ); - private_input.insert("path_indices".to_string(), json!(path_indices[i])); - private_inputs.push(private_input); - } - - // The start public input is [user_state_cur, liabilities_state_cur] which are both 0 at state 0 - let start_public_input = [F::::from(0), F::::from(0)]; - - println!("Creating a RecursiveSNARK..."); - let start = Instant::now(); - let recursive_snark = create_recursive_circuit( - FileLocation::PathBuf(witness_generator_file.clone()), - r1cs.clone(), - private_inputs, - start_public_input.to_vec(), - &pp, - ) - .unwrap(); - println!("RecursiveSNARK creation took {:?}", start.elapsed()); - - // TODO: empty? - let z0_secondary = [F::::from(0)]; - - // verify the recursive SNARK - println!("Verifying a RecursiveSNARK..."); - let start = Instant::now(); - let res = recursive_snark.verify(&pp, iteration_count, &start_public_input, &z0_secondary); - println!( - "RecursiveSNARK::verify: {:?}, took {:?}", - res, - start.elapsed() - ); - assert!(res.is_ok()); - - let z_last = res.unwrap().0; - - // The user has to check the correctness of the liabilities after state 3 according to the Incremental Proof - // The user checks that this is equal to the liabilities state committed by the CEX at state 3 - println!( - "liabilities_state_cur at state 3 as output of the Incremental Proof {:?}", - z_last[1] - ); - println!( - "liabilities state committed by the CEX at state 3 {:?}", - liabilities_state_3 - ); - - // The user also has to check the correctness of the user state after state 3 according to the Incremental Proof - // The user checks that this is equal to the locally computed user_state_cur - let user_state_0 = Fr::from_str("0").unwrap(); - - let user_state_1 = build_user_state_cur( - user_state_0, - merkle_proof_1.username, - merkle_proof_1.user_balances, - ); - let user_state_2 = build_user_state_cur( - user_state_1, - merkle_proof_2.username, - merkle_proof_2.user_balances, - ); - let user_state_3 = build_user_state_cur( - user_state_2, - merkle_proof_3.username, - merkle_proof_3.user_balances, - ); - - println!( - "user_state_cur at state 3 as output of the Incremental Proof {:?}", - z_last[0] - ); - println!( - "user state computed locally by the user starting from their logs {:?}", - user_state_3 - ); - - // produce a compressed SNARK - println!("Generating a CompressedSNARK using Spartan with IPA-PC..."); - let start = Instant::now(); - let (pk, vk) = CompressedSNARK::<_, _, _, _, S, S>::setup(&pp).unwrap(); - let res = CompressedSNARK::<_, _, _, _, S, S>::prove(&pp, &pk, &recursive_snark); - println!( - "CompressedSNARK::prove: {:?}, took {:?}", - res.is_ok(), - start.elapsed() - ); - assert!(res.is_ok()); - let compressed_snark = res.unwrap(); - - // verify the compressed SNARK - println!("Verifying a CompressedSNARK..."); - let start = Instant::now(); - let res = compressed_snark.verify( - &vk, - iteration_count, - start_public_input.to_vec(), - z0_secondary.to_vec(), - ); - println!( - "CompressedSNARK::verify: {:?}, took {:?}", - res.is_ok(), - start.elapsed() - ); - assert!(res.is_ok()); -} - -fn main() { - let circuit_filepath = "examples/build/incremental_mst_inclusion.r1cs".to_string(); - let witness_gen_filepath = - "examples/build/incremental_mst_inclusion_js/incremental_mst_inclusion.wasm".to_string(); - run_test(circuit_filepath.clone(), witness_gen_filepath); -} - -use num_traits::Num; -use poseidon_rs::{Fr, Poseidon}; - -// Note that we cannot reuse the MerkleSumTree implementation from zk_prover because it is not compatible with circom's Poseidon Hasher -#[derive(Clone, Debug)] -struct Node { - hash: Fr, - balance: [Fr; N_CURRENCIES], -} - -#[derive(Clone, Debug)] -struct MerkleProof { - username: String, - user_balances: Vec, - path_element_hashes: Vec, - path_element_balances: Vec>, - path_indices: Vec, - root: Node, -} - -impl Node { - /// Constructs a new Node given left and right child hashes. - fn new( - left: &Node, - right: &Node, - hasher: &Poseidon, - ) -> Node { - let mut input = vec![left.hash]; - input.extend(left.balance); - input.push(right.hash); - input.extend(right.balance); - - let mut balance = vec![]; - - // iterate over N_CURRENCIES - for i in 0..N_CURRENCIES { - let mut sum = Fr::from_str("0").unwrap(); - sum.add_assign(&left.balance[i]); - sum.add_assign(&right.balance[i]); - - balance.push(sum); - } - - Node { - hash: hasher.hash(input).unwrap(), - balance: balance.try_into().unwrap(), - } - } -} - -/// Generates a Merkle proof of inclusion for a leaf at a given index -fn build_merkle_proof( - csv_filepath: String, - user_index: usize, -) -> Option> { - let file = File::open(csv_filepath).expect("Unable to open file"); - let reader = BufReader::new(file); - - let mut leaves = vec![]; - - let hasher = Poseidon::new(); - - let mut captured_username = String::new(); - let mut captured_user_balances = vec![]; - - for (idx, line) in reader.lines().skip(1).enumerate() { - // skipping header - let line = line.expect("Unable to read line"); - let data: Vec<&str> = line.split(';').collect(); - - if data.len() != 2 { - continue; // Invalid line format - } - - let username = big_intify_username(data[0]).to_string(); - - // convert balances to Fr - let balances: Vec = data[1] - .split(',') - .map(|balance_str| Fr::from_str(balance_str).unwrap()) - .collect(); - - assert_eq!(balances.len(), N_CURRENCIES); - - // capture user's data if the index matches - if idx == user_index { - captured_username = username.to_string(); - captured_user_balances = data[1].split(',').map(|s| s.to_string()).collect(); - } - - let username = Fr::from_str(&username).unwrap(); - - // create a vector input that takes the username and the balances - let mut input = vec![username]; - input.extend(balances.clone()); - - let hash = hasher.hash(input).unwrap(); - - leaves.push(Node { - hash, - balance: balances.try_into().unwrap(), - }); - } - - let mut current_level = leaves.clone(); - - let mut path_element_hashes = vec![]; - let mut path_element_balances = vec![]; - let mut path_indices = vec![]; - - while current_level.len() > 1 { - let mut next_level = vec![]; - - for i in (0..current_level.len()).step_by(2) { - let left = ¤t_level[i]; - let right = if i + 1 < current_level.len() { - ¤t_level[i + 1] - } else { - ¤t_level[i] - }; - - if user_index == i { - path_element_hashes.push(fr_to_string(right.hash).unwrap()); - path_element_balances.push( - right - .balance - .iter() - .map(|fr| fr_to_string(*fr).unwrap()) - .collect(), - ); - path_indices.push("0".to_string()); // 0 means that the right element is the path element - } else if user_index == i + 1 { - path_element_hashes.push(fr_to_string(left.hash).unwrap()); - path_element_balances.push( - left.balance - .iter() - .map(|fr| fr_to_string(*fr).unwrap()) - .collect(), // 1 means that the left element is the path element - ); - path_indices.push("1".to_string()); - } - - let parent = Node::new(left, right, &hasher); - next_level.push(parent); - } - - current_level = next_level; - } - - // fetch the root - let root = current_level[0].clone(); - - Some(MerkleProof { - username: captured_username, - user_balances: captured_user_balances, - path_element_hashes, - path_element_balances, - path_indices, - root, - }) -} - -/// The current liabilities state is obtained by hashing the previous liabilities state and the root hash of the current liabilities tree -fn build_liabilities_state_cur(liabilities_state_prev: Fr, root_hash: Fr) -> Fr { - let hasher = Poseidon::new(); - - let mut input = vec![liabilities_state_prev]; - input.push(root_hash); - - hasher.hash(input).unwrap() -} - -/// The current user state is obtained by hashing the previous user state and the user leaf hash of the current liabilities tree -fn build_user_state_cur(user_state_prev: Fr, username: String, user_balances: Vec) -> Fr { - let hasher = Poseidon::new(); - - let leaf_hash = { - let mut input = vec![Fr::from_str(&username).unwrap()]; - input.extend( - user_balances - .iter() - .map(|balance_str| Fr::from_str(balance_str).unwrap()), - ); - - hasher.hash(input).unwrap() - }; - - let mut input = vec![user_state_prev]; - input.push(leaf_hash); - - hasher.hash(input).unwrap() -} - -/// Converts a Fr to a its decimal string representation -fn fr_to_string(v: Fr) -> Option { - // Convert v to string - let s = v.to_string(); - - // Extract the hexadecimal portion from the string. - // The pattern "Fr(" and ")" should surround the hexadecimal. - if let Some(hex_start) = s.find("Fr(0x") { - let hex_end = s.rfind(')')?; - let hex_str = &s[hex_start + 5..hex_end]; - - // Convert the hexadecimal to a decimal string. - let decimal_str = BigUint::from_str_radix(hex_str, 16) - .ok() - .map(|bigint| bigint.to_str_radix(10)) - .unwrap(); - - return Some(decimal_str); - } - None -} diff --git a/zk_prover/prints/lt-check-layout.png b/zk_prover/prints/lt-check-layout.png deleted file mode 100644 index aef5304d..00000000 Binary files a/zk_prover/prints/lt-check-layout.png and /dev/null differ diff --git a/zk_prover/prints/mst-inclusion-layout.png b/zk_prover/prints/mst-inclusion-layout.png deleted file mode 100644 index 5db063d4..00000000 Binary files a/zk_prover/prints/mst-inclusion-layout.png and /dev/null differ diff --git a/zk_prover/prints/range-check-layout.png b/zk_prover/prints/range-check-layout.png deleted file mode 100644 index cc706e85..00000000 Binary files a/zk_prover/prints/range-check-layout.png and /dev/null differ diff --git a/zk_prover/prints/solvency-layout.png b/zk_prover/prints/solvency-layout.png deleted file mode 100644 index f1c0b3fe..00000000 Binary files a/zk_prover/prints/solvency-layout.png and /dev/null differ diff --git a/zk_prover/rust-toolchain b/zk_prover/rust-toolchain deleted file mode 100644 index 4524b7cb..00000000 --- a/zk_prover/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2023-07-11 \ No newline at end of file diff --git a/zk_prover/src/chips/merkle_sum_tree.rs b/zk_prover/src/chips/merkle_sum_tree.rs deleted file mode 100644 index 7cc72b0f..00000000 --- a/zk_prover/src/chips/merkle_sum_tree.rs +++ /dev/null @@ -1,274 +0,0 @@ -use halo2_proofs::circuit::{AssignedCell, Layouter}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use halo2_proofs::plonk::{Advice, Column, ConstraintSystem, Error, Expression, Selector}; -use halo2_proofs::poly::Rotation; - -/// Configuration for the Merkle Sum Tree Chip -/// -/// # Fields -/// -/// * `advice`: advice columns to fit the witness values. -/// * `bool_and_swap_selector`: Selector to enable the bool and swap constraints. -/// * `sum_selector`: Selector to enable the sum constraints. -#[derive(Debug, Clone)] -pub struct MerkleSumTreeConfig { - advice: [Column; 3], - bool_and_swap_selector: Selector, - sum_selector: Selector, -} - -/// Chip that performs various constraints related to a Merkle Sum Tree data structure such as: -/// -/// * `s * swap_bit * (1 - swap_bit) = 0` (if `bool_and_swap_selector` is toggled). It basically enforces that swap_bit is either a 0 or 1. -/// * `s * (element_r_cur - element_l_cur) * swap_bit + element_l_cur - element_l_next = 0` (if `bool_and_swap_selector` is toggled). -/// * `s * (element_l_cur - element_r_cur) * swap_bit + element_r_cur - element_r_next = 0` (if `bool_and_swap_selector` is toggled). -/// These 2 constraints enforce that if the swap_bit is equal to 1, the values will be swapped on the next row. If the swap_bit is equal to 0, the values will not be swapped on the next row. -/// * `s * (left_balance + right_balance - computed_sum)`. It constraints the computed sum to be equal to the sum of the left and right balances (if `sum_selector` is toggled). - -#[derive(Debug, Clone)] -pub struct MerkleSumTreeChip { - config: MerkleSumTreeConfig, -} - -impl MerkleSumTreeChip { - pub fn construct(config: MerkleSumTreeConfig) -> Self { - Self { config } - } - - pub fn configure( - meta: &mut ConstraintSystem, - advice: [Column; 3], - selectors: [Selector; 2], - ) -> MerkleSumTreeConfig { - let col_a: Column = advice[0]; - let col_b: Column = advice[1]; - let col_c: Column = advice[2]; - - let bool_and_swap_selector = selectors[0]; - let sum_selector = selectors[1]; - - meta.create_gate("bool constraint", |meta| { - let s = meta.query_selector(bool_and_swap_selector); - let swap_bit = meta.query_advice(col_c, Rotation::cur()); - vec![s * swap_bit.clone() * (Expression::Constant(Fp::from(1)) - swap_bit)] - }); - - meta.create_gate("swap constraint", |meta| { - let s = meta.query_selector(bool_and_swap_selector); - let swap_bit = meta.query_advice(col_c, Rotation::cur()); - let element_l_cur = meta.query_advice(col_a, Rotation::cur()); - let element_r_cur = meta.query_advice(col_b, Rotation::cur()); - let element_l_next = meta.query_advice(col_a, Rotation::next()); - let element_r_next = meta.query_advice(col_b, Rotation::next()); - - // element_l_next = (element_r_cur - element_l_cur)*s + element_l_cur - let swap_constraint_1 = s.clone() - * ((element_r_cur.clone() - element_l_cur.clone()) * swap_bit.clone() - + element_l_cur.clone() - - element_l_next); - - // element_r_next = (element_l_cur - element_r_cur)*s + element_r_cur - let swap_constraint_2 = s - * ((element_l_cur - element_r_cur.clone()) * swap_bit + element_r_cur - - element_r_next); - - vec![swap_constraint_1, swap_constraint_2] - }); - - meta.create_gate("sum constraint", |meta| { - (0..N_CURRENCIES) - .map(|_| { - let left_balance = meta.query_advice(col_a, Rotation::cur()); - let right_balance = meta.query_advice(col_b, Rotation::cur()); - let computed_sum = meta.query_advice(col_c, Rotation::cur()); - let s = meta.query_selector(sum_selector); - s * (left_balance + right_balance - computed_sum) - }) - .collect::>() - }); - - MerkleSumTreeConfig { - advice, - bool_and_swap_selector, - sum_selector, - } - } - - /// Swap the values of two cells in a region following this layout on 3 advice columns: - /// - /// | a | b | c | - /// | ------------ | ------------- | ---------- | - /// | `current_hash` | `sibling_hash` | `1` | - /// | `sibling_hash` | `current_hash` | - | - /// - /// At row 0 bool_and_swap_selector is enabled - /// If swap_bit is 0, the values will remain the same on the next row - /// If swap_bit is 1, the values will be swapped on the next row - pub fn swap_hashes_per_level( - &self, - mut layouter: impl Layouter, - current_hash: &AssignedCell, - sibling_hash: &AssignedCell, - swap_bit_assigned: &AssignedCell, - ) -> Result<(AssignedCell, AssignedCell), Error> { - layouter.assign_region( - || "assign nodes hashes per merkle tree level", - |mut region| { - // enable the bool_and_swap_selector at row 0 - self.config.bool_and_swap_selector.enable(&mut region, 0)?; - - // copy the current_hash to the column self.config.advice[0] at offset 0 - let l1 = current_hash.copy_advice( - || "copy current hash from previous level", - &mut region, - self.config.advice[0], - 0, - )?; - - // assign the element hash to the column self.config.advice[1] at offset 0 - let r1 = sibling_hash.copy_advice( - || "copy element hash from assigned value", - &mut region, - self.config.advice[1], - 0, - )?; - - // assign the swap_bit to the column self.config.advice[2] at offset 0 - let swap_bit = swap_bit_assigned.copy_advice( - || "swap bit", - &mut region, - self.config.advice[2], - 0, - )?; - - // Extract the value from the cell - let mut l1_val = l1.value().copied(); - let mut r1_val = r1.value().copied(); - - // perform the swap according to the swap bit - // if swap_bit is 0 return (l1, r1) else return (r1, l1) - swap_bit.value().copied().map(|x| { - (l1_val, r1_val) = if x == Fp::zero() { - (l1_val, r1_val) - } else { - (r1_val, l1_val) - }; - }); - - // Perform the assignment according to the swap at offset 1 - let left_hash = region.assign_advice( - || "assign left hash after swap", - self.config.advice[0], - 1, - || l1_val, - )?; - - let right_hash = region.assign_advice( - || "assign right hash after swap", - self.config.advice[1], - 1, - || r1_val, - )?; - - Ok((left_hash, right_hash)) - }, - ) - } - - /// Assign the nodes balance for a single currency in a region following this layout on 3 advice columns: - /// - /// | a | b | c | - /// | ------------ | ------------- | ---------- | - /// | `current_balance` | `element_balance` | `0` | - /// | `current_balance` | `element_balance` | `sum` | - /// - /// At row 0 bool_and_swap_selector is enabled. - /// At row 1 sum_selector is enabled - /// If swap_bit is 0, the values will remain the same on the next row - /// If swap_bit is 1, the values will be swapped on the next row - pub fn swap_balances_per_level( - &self, - mut layouter: impl Layouter, - current_balance: &AssignedCell, - element_balance: &AssignedCell, - swap_bit_assigned: &AssignedCell, - ) -> Result< - ( - AssignedCell, - AssignedCell, - AssignedCell, - ), - Error, - > { - layouter.assign_region( - || "assign nodes balances per currency", - |mut region| { - // enable the bool_and_swap_selector at row 0 - self.config.bool_and_swap_selector.enable(&mut region, 0)?; - - // copy the current_balances to the column self.config.advice[0] at offset 0 - let l1 = current_balance.copy_advice( - || "copy current balance from prev level", - &mut region, - self.config.advice[0], - 0, - )?; - - // assign the element_balance to the column self.config.advice[1] at offset 0 - let r1 = element_balance.copy_advice( - || "element balance", - &mut region, - self.config.advice[1], - 0, - )?; - - // assign the swap_bit to the column self.config.advice[2] at offset 0 - let swap_bit = swap_bit_assigned.copy_advice( - || "swap bit", - &mut region, - self.config.advice[2], - 0, - )?; - - // Extract the value from the cell - let mut l1_val = l1.value().copied(); - let mut r1_val = r1.value().copied(); - - // perform the swap according to the swap bit - // if swap_bit is 0 return (l1, r1) else return (r1, l1) - swap_bit.value().copied().map(|x| { - (l1_val, r1_val) = if x == Fp::zero() { - (l1_val, r1_val) - } else { - (r1_val, l1_val) - }; - }); - - // Perform the assignment according to the swap at offset 1 - let left_currency_balance = region.assign_advice( - || "assign left balance after swap", - self.config.advice[0], - 1, - || l1_val, - )?; - - let right_currency_balance = region.assign_advice( - || "assign right balance after swap", - self.config.advice[1], - 1, - || r1_val, - )?; - - // enable the sum_selector at offset 1 - self.config.sum_selector.enable(&mut region, 1)?; - - // compute the sum of the two balances and assign it to the column self.config.advice[2] at offset 1 - let sum = l1_val.zip(r1_val).map(|(a, b)| a + b); - let sum_cell = - region.assign_advice(|| "sum of balances", self.config.advice[2], 1, || sum)?; - - Ok((left_currency_balance, right_currency_balance, sum_cell)) - }, - ) - } -} diff --git a/zk_prover/src/chips/mod.rs b/zk_prover/src/chips/mod.rs deleted file mode 100644 index 97a1ea8f..00000000 --- a/zk_prover/src/chips/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod merkle_sum_tree; -pub mod poseidon; -pub mod range; diff --git a/zk_prover/src/chips/poseidon/hash.rs b/zk_prover/src/chips/poseidon/hash.rs deleted file mode 100644 index 21fdafeb..00000000 --- a/zk_prover/src/chips/poseidon/hash.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! An easy-to-use implementation of the Poseidon Hash in the form of a Halo2 Chip. While the Poseidon Hash function -//! is already implemented in halo2_gadgets, there is no wrapper chip that makes it easy to use in other circuits. -use halo2_gadgets::poseidon::{primitives::*, Hash, Pow5Chip, Pow5Config}; -use halo2_proofs::{ - circuit::{AssignedCell, Layouter}, - halo2curves::bn256::Fr as Fp, - plonk::{Advice, Column, ConstraintSystem, Error, Fixed}, -}; -use std::marker::PhantomData; - -#[derive(Debug, Clone)] - -/// Wrapper structure around Pow5Config which is the Poseidon Hash Configuration from halo2_gadgets. -/// -/// Poseidon is a zk-friendly hash function. -/// -/// # Type Parameters -/// -/// * `WIDTH`: The width of the Poseidon permutation, -/// * `RATE`: The rate of the Poseidon permutation, typically WIDTH - 1. -/// * `L`: The length of the input array to the Poseidon hash function. -/// -/// # Fields -/// -/// * `pow5_config`: The configuration for the inner [halo2_gadgets::poseidon::Pow5Config] -pub struct PoseidonConfig { - pow5_config: Pow5Config, -} - -#[derive(Debug, Clone)] - -/// Chip that performs the Poseidon Hash -/// -/// # Type Parameters -/// -/// * `S`: The specification for the Poseidon hash function, -/// * `WIDTH`: The width of the Poseidon permutation, -/// * `RATE`: The rate of the Poseidon permutation, typically WIDTH - 1. -/// * `L`: The length of the input array to the Poseidon hash function. -pub struct PoseidonChip< - S: Spec, - const WIDTH: usize, - const RATE: usize, - const L: usize, -> { - config: PoseidonConfig, - _marker: PhantomData, -} - -impl, const WIDTH: usize, const RATE: usize, const L: usize> - PoseidonChip -{ - /// Constructs a new Poseidon Chip given a PoseidonConfig - pub fn construct(config: PoseidonConfig) -> Self { - Self { - config, - _marker: PhantomData, - } - } - - /// Configures the Poseidon Chip - pub fn configure( - meta: &mut ConstraintSystem, - state: [Column; WIDTH], - partial_sbox: Column, - rc_a: [Column; WIDTH], - rc_b: [Column; WIDTH], - ) -> PoseidonConfig { - let pow5_config = Pow5Chip::configure::(meta, state, partial_sbox, rc_a, rc_b); - - PoseidonConfig { pow5_config } - } - - /// Performs poseidon hash on the given input cells. Returns the output cell. - pub fn hash( - &self, - mut layouter: impl Layouter, - input_cells: [AssignedCell; L], - ) -> Result, Error> { - let pow5_chip = Pow5Chip::construct(self.config.pow5_config.clone()); - - let hasher = Hash::<_, _, S, ConstantLength, WIDTH, RATE>::init( - pow5_chip, - layouter.namespace(|| "hasher"), - )?; - hasher.hash(layouter.namespace(|| "hash"), input_cells) - } -} diff --git a/zk_prover/src/chips/poseidon/mod.rs b/zk_prover/src/chips/poseidon/mod.rs deleted file mode 100644 index fd69810e..00000000 --- a/zk_prover/src/chips/poseidon/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod hash; -mod poseidon_params; -pub mod poseidon_spec; diff --git a/zk_prover/src/chips/poseidon/poseidon_params.rs b/zk_prover/src/chips/poseidon/poseidon_params.rs deleted file mode 100644 index 61331ef9..00000000 --- a/zk_prover/src/chips/poseidon/poseidon_params.rs +++ /dev/null @@ -1,990 +0,0 @@ -//! Parameters for Poseidon Hasher based on a specific Rate and Curve. -//! -//! This file was generated by running `generate_params.py`. -//! - Number of round constants: 128 -//! - Round constants for GF(p): -//! -//! Parameters for using rate 1 Poseidon with the BN256 field. -//! Patterned after [halo2_gadgets::poseidon::primitives] -//! The parameters can be reproduced by running the following Sage script from -//! [this repository](https://github.com/daira/pasta-hadeshash) -//! -//! ```text -//! $ sage generate_parameters_grain.sage 1 0 254 2 8 56 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 --rust -//! ``` -//! -//! where 1 means 'prime field', 0 means 'non-negative sbox', 254 is the bitsize -//! of the field, 2 is the Poseidon width (rate + 1), 8 is the number of full -//! rounds, 56 is the number of partial rounds. -//! More info here => -use halo2_proofs::halo2curves::bn256::Fr as Fp; -pub(crate) const ROUND_CONSTANTS: [[Fp; 2]; 64] = [ - [ - Fp::from_raw([ - 0x6c7d_c0db_d0ab_d7a7, - 0xa71a_a177_534c_dd1b, - 0xfe1f_aaba_294c_ba38, - 0x09c4_6e9e_c68e_9bd4, - ]), - Fp::from_raw([ - 0x3c1d_83ff_a604_cb81, - 0xc514_2b3a_e405_b834, - 0x2a97_ed93_7f31_35cf, - 0x0c03_5653_0896_eec4, - ]), - ], - [ - Fp::from_raw([ - 0x317e_a977_cc15_4a30, - 0xa00e_a5aa_bd62_68bd, - 0x142e_5118_2bb5_4cf4, - 0x1e28_a1d9_3569_8ad1, - ]), - Fp::from_raw([ - 0x4cf9_e2b1_2b91_251f, - 0x0e57_57c3_e008_db96, - 0x0809_65db_30e2_98e4, - 0x27af_2d83_1a9d_2748, - ]), - ], - [ - Fp::from_raw([ - 0x79aa_f435_45b7_4e03, - 0x4129_1462_f214_cd08, - 0x3a6a_3cfe_16ae_175a, - 0x1e6f_11ce_60fc_8f51, - ]), - Fp::from_raw([ - 0xf719_2062_68d1_42d3, - 0x0446_2ed1_4c36_13d8, - 0x8541_819c_b681_f0be, - 0x2a67_384d_3bbd_5e43, - ]), - ], - [ - Fp::from_raw([ - 0x3640_8f5d_5c9f_45d0, - 0xb985_e381_f025_1889, - 0x1609_f8e1_2fbf_ecf0, - 0x0b66_fdf3_5609_3a61, - ]), - Fp::from_raw([ - 0xdaa6_852d_bdb0_9e21, - 0x0b26_c83c_c5ce_beed, - 0x830c_6109_3c2a_de37, - 0x012e_e3ec_1e78_d470, - ]), - ], - [ - Fp::from_raw([ - 0x2d10_8e7b_445b_b1b9, - 0x6cd1_c431_b099_b6bb, - 0xfd88_f67f_8175_e3fd, - 0x0252_ba5f_6760_bfbd, - ]), - Fp::from_raw([ - 0xef5a_eaad_7ca9_32f1, - 0x5439_1a89_35ff_71d6, - 0x6c6b_ec3c_ef54_2963, - 0x1794_74cc_eca5_ff67, - ]), - ], - [ - Fp::from_raw([ - 0x7e1a_2589_bbed_2b91, - 0x9c1f_974a_2649_69b3, - 0x9228_ff4a_503f_d4ed, - 0x2c24_2613_79a5_1bfa, - ]), - Fp::from_raw([ - 0x53e6_6c05_5180_1b05, - 0xc2f6_3f50_01fc_0fc5, - 0xac2f_288b_d069_5b43, - 0x1cc1_d7b6_2692_e63e, - ]), - ], - [ - Fp::from_raw([ - 0x5d9e_ff5f_d9c9_1b56, - 0x0078_4dbf_17fb_acd0, - 0xb2ed_55f8_5297_9e96, - 0x2550_5930_1aad_a98b, - ]), - Fp::from_raw([ - 0xb11c_29ce_7e59_efd9, - 0xaea2_4234_970a_8193, - 0x79e1_f5c0_eccd_32b3, - 0x2843_7be3_ac1c_b2e4, - ]), - ], - [ - Fp::from_raw([ - 0x3387_62c3_7f5f_2043, - 0x1854_8da8_fb4f_78d4, - 0x1ca4_fa6b_5376_6eb1, - 0x2821_6a44_2f2e_1f71, - ]), - Fp::from_raw([ - 0x131f_2377_3234_82c9, - 0xeee1_efce_0309_4581, - 0x1f39_f4e7_056d_d03f, - 0x2c1f_47cd_17fa_5adf, - ]), - ], - [ - Fp::from_raw([ - 0x646b_8566_a621_afc9, - 0xd9da_fca2_7663_8a63, - 0x8632_bcc9_356c_eb7d, - 0x07ab_ad02_b7a5_ebc4, - ]), - Fp::from_raw([ - 0x37da_0c4d_15f9_6c3c, - 0x9429_f908_80a6_9cd1, - 0x275b_33ff_aab5_1dfe, - 0x0230_2646_01ff_df29, - ]), - ], - [ - Fp::from_raw([ - 0x717e_5d66_899a_a0a9, - 0xa864_4145_57ee_289e, - 0xa0f1_6865_6497_ca40, - 0x1bc9_7305_4e51_d905, - ]), - Fp::from_raw([ - 0x2a6b_2228_8f0a_67fc, - 0xd249_aff5_c2d8_421f, - 0x206c_3157_e863_41ed, - 0x2e1c_22f9_6443_5008, - ]), - ], - [ - Fp::from_raw([ - 0xa704_52bc_2bba_86b8, - 0x9e8e_a159_8e46_c9f7, - 0x121c_1d5f_461b_bc50, - 0x1224_f38d_f67c_5378, - ]), - Fp::from_raw([ - 0x69d2_9891_86cd_e20e, - 0xd7bf_e8cd_9dfe_da19, - 0x9280_b4bd_9ed0_068f, - 0x02e4_e69d_8ba5_9e51, - ]), - ], - [ - Fp::from_raw([ - 0x6d47_e973_5d98_018e, - 0x4f19_ee36_4e65_3f07, - 0x7f5d_f81f_c04f_f3ee, - 0x1f1e_ccc3_4aab_a013, - ]), - Fp::from_raw([ - 0xeacb_8a4d_4284_f582, - 0x1424_4480_32cd_1819, - 0x7426_6c30_39a9_a731, - 0x1672_ad3d_709a_3539, - ]), - ], - [ - Fp::from_raw([ - 0x1d2e_d602_df8c_8fc7, - 0xcda6_961f_284d_2499, - 0x56f4_4af5_192b_4ae9, - 0x283e_3fdc_2c6e_420c, - ]), - Fp::from_raw([ - 0x614f_bd69_ff39_4bcc, - 0x6837_51f8_fdff_59d6, - 0xd0db_0957_170f_a013, - 0x1c2a_3d12_0c55_0ecf, - ]), - ], - [ - Fp::from_raw([ - 0x96cb_6b81_7765_3fbd, - 0x143a_9a43_773e_a6f2, - 0xf789_7a73_2345_6efe, - 0x216f_8487_7aac_6172, - ]), - Fp::from_raw([ - 0x11a1_f515_52f9_4788, - 0xceaa_47ea_61ca_59a4, - 0x64ba_7e8e_3e28_d12b, - 0x2c0d_272b_ecf2_a757, - ]), - ], - [ - Fp::from_raw([ - 0xcb4a_6c3d_8954_6f43, - 0x170a_5480_abe0_508f, - 0x484e_e7a7_4c45_4e9f, - 0x16e3_4299_865c_0e28, - ]), - Fp::from_raw([ - 0x48cd_9397_5548_8fc5, - 0x7720_4776_5802_290f, - 0x375a_232a_6fb9_cc71, - 0x175c_eba5_99e9_6f5b, - ]), - ], - [ - Fp::from_raw([ - 0xd8c5_ffbb_44a1_ee32, - 0x6aa4_10bf_bc35_4f54, - 0xfead_9e17_58b0_2806, - 0x0c75_9444_0dc4_8c16, - ]), - Fp::from_raw([ - 0x9247_9882_d919_fd8d, - 0x760e_2001_3ccf_912c, - 0xc466_db7d_7eb6_fd8f, - 0x1a3c_29bc_39f2_1bb5, - ]), - ], - [ - Fp::from_raw([ - 0x95c8_eeab_cd22_e68f, - 0x0855_d349_074f_5a66, - 0xc098_6ea0_49b2_5340, - 0x0ccf_dd90_6f34_26e5, - ]), - Fp::from_raw([ - 0xe0e6_99b6_7dd9_e796, - 0x66a7_a8a3_fd06_5b3c, - 0x2bdb_475c_e6c9_4118, - 0x14f6_bc81_d9f1_86f6, - ]), - ], - [ - Fp::from_raw([ - 0x88ed_eb73_86b9_7052, - 0xcc09_9810_c9c4_95c8, - 0x9702_ca70_b2f6_c5aa, - 0x0962_b827_89fb_3d12, - ]), - Fp::from_raw([ - 0xafef_0c8f_6a31_a86d, - 0x1328_4ab0_1ef0_2575, - 0xbf20_c79d_e251_27bc, - 0x1a88_0af7_074d_18b3, - ]), - ], - [ - Fp::from_raw([ - 0x4c30_12bb_7ae9_311b, - 0x20af_2924_fc20_ff3f, - 0xcd5e_77f0_211c_154b, - 0x10cb_a184_19a6_a332, - ]), - Fp::from_raw([ - 0x756a_2849_f302_f10d, - 0xfa27_b731_9cae_3406, - 0xbdc7_6ba6_3a9e_aca8, - 0x057e_62a9_a8f8_9b3e, - ]), - ], - [ - Fp::from_raw([ - 0xafa0_413b_4428_0cee, - 0xb961_303b_bf65_cff5, - 0xd44a_df53_84b4_988c, - 0x287c_971d_e91d_c0ab, - ]), - Fp::from_raw([ - 0x6f7f_7960_e306_891d, - 0x1e56_2bc4_6d4a_ba4e, - 0xb3bc_a9da_0cca_908f, - 0x21df_3388_af16_87bb, - ]), - ], - [ - Fp::from_raw([ - 0x3eff_8b56_0e16_82b3, - 0x789d_f8f7_0b49_8fd8, - 0x3e25_cc97_4d09_34cd, - 0x1be5_c887_d25b_ce70, - ]), - Fp::from_raw([ - 0x48d5_9c27_06a0_d5c1, - 0xd2cb_5d42_fda5_acea, - 0x6811_7175_cea2_cd0d, - 0x268d_a36f_76e5_68fb, - ]), - ], - [ - Fp::from_raw([ - 0xbd06_460c_c26a_5ed6, - 0xc5d8_bb74_135e_bd05, - 0xc609_beaf_5510_ecec, - 0x0e17_ab09_1f6e_ae50, - ]), - Fp::from_raw([ - 0x040f_5caa_1f62_af40, - 0x91ef_62d8_cf83_d270, - 0x7aee_535a_b074_a430, - 0x04d7_27e7_28ff_a0a6, - ]), - ], - [ - Fp::from_raw([ - 0x2b15_417d_7e39_ca6e, - 0x3370_2ac1_0f1b_fd86, - 0x81b5_4976_2bc0_22ed, - 0x0ddb_d7bf_9c29_3415, - ]), - Fp::from_raw([ - 0x8a29_c49c_8789_654b, - 0x34f5_b0d1_d3af_9b58, - 0x7681_62e8_2989_c6c2, - 0x2790_eb33_5162_1752, - ]), - ], - [ - Fp::from_raw([ - 0x84b7_6420_6142_f9e9, - 0x395f_3d9a_b8b2_fd09, - 0x4471_9501_93d8_a570, - 0x1e45_7c60_1a63_b73e, - ]), - Fp::from_raw([ - 0xc4c6_86fc_46e0_91b0, - 0xfa90_ecd0_c43f_f91f, - 0x638d_6ab2_bbe7_135f, - 0x21ae_6430_1dca_9625, - ]), - ], - [ - Fp::from_raw([ - 0x5858_534e_ed8d_350b, - 0x854b_e9e3_432e_0955, - 0x4da2_9316_6f49_4928, - 0x0379_f63c_8ce3_468d, - ]), - Fp::from_raw([ - 0x8c9f_58a3_24c3_5049, - 0xca0e_4921_a466_86ac, - 0x6a74_4a08_0809_e054, - 0x002d_5642_0359_d026, - ]), - ], - [ - Fp::from_raw([ - 0x0fc2_c5af_9635_15a6, - 0xda8d_6245_9e21_f409, - 0x1d68_b3cd_32e1_0bbe, - 0x1231_58e5_965b_5d9b, - ]), - Fp::from_raw([ - 0x60c8_0eb4_9cad_9ec1, - 0x0fbb_2b6f_5283_6d4e, - 0x661d_14bb_f6cb_e042, - 0x0be2_9fc4_0847_a941, - ]), - ], - [ - Fp::from_raw([ - 0x2338_02f2_4fdf_4c1a, - 0x36db_9d85_9cad_5f9a, - 0x5771_6142_015a_453c, - 0x1ac9_6991_dec2_bb05, - ]), - Fp::from_raw([ - 0x51ca_3355_bcb0_627e, - 0x5e12_c9fa_97f1_8a92, - 0x5f49_64fc_61d2_3b3e, - 0x1596_443f_763d_bcc2, - ]), - ], - [ - Fp::from_raw([ - 0xd6d0_49ea_e3ba_3212, - 0xf185_7d9f_17e7_15ae, - 0x6b28_61d4_ec3a_eae0, - 0x12e0_bcd3_654b_dfa7, - ]), - Fp::from_raw([ - 0x04e6_c76c_7cf9_64ba, - 0xceab_ac7f_3715_4b19, - 0x9ea7_3d4a_f9af_2a50, - 0x0fc9_2b4f_1bbe_a82b, - ]), - ], - [ - Fp::from_raw([ - 0x9c7e_9652_3387_2762, - 0xb14f_7c77_2223_6f4f, - 0xd6f2_e592_a801_3f40, - 0x1f9c_0b16_1044_6442, - ]), - Fp::from_raw([ - 0x8d15_9f64_3dbb_f4d3, - 0x050d_914d_a38b_4c05, - 0xf8cd_e061_57a7_82f4, - 0x0ebd_7424_4ae7_2675, - ]), - ], - [ - Fp::from_raw([ - 0x7a83_9839_dccf_c6d1, - 0x3b06_71e9_7346_ee39, - 0x69a9_fafd_4ab9_51c0, - 0x2cb7_f0ed_39e1_6e9f, - ]), - Fp::from_raw([ - 0x90c7_2bca_7352_d9bf, - 0xce76_1d05_14ce_5266, - 0x5605_443e_e41b_ab20, - 0x1a9d_6e2e_cff0_22cc, - ]), - ], - [ - Fp::from_raw([ - 0x87da_182d_648e_c72f, - 0xd0c1_3326_a9a7_ba30, - 0x5ea8_3c3b_c44a_9331, - 0x2a11_5439_607f_335a, - ]), - Fp::from_raw([ - 0x9535_c115_c5a4_c060, - 0xe738_b563_05cd_44f2, - 0x15b8_fa7a_ee3e_3410, - 0x23f9_b652_9b5d_040d, - ]), - ], - [ - Fp::from_raw([ - 0x260e_b939_f0e6_e8a7, - 0xa3ce_97c1_6d58_b68b, - 0x249a_c6ba_484b_b9c3, - 0x0587_2c16_db0f_72a2, - ]), - Fp::from_raw([ - 0x2b62_4a7c_dedd_f6a7, - 0x0219_b615_1d55_b5c5, - 0xca20_fb80_1180_75f4, - 0x1300_bdee_08bb_7824, - ]), - ], - [ - Fp::from_raw([ - 0x072e_4e7b_7d52_b376, - 0x8d7a_d299_16d9_8cb1, - 0xe638_1786_3a8f_6c28, - 0x19b9_b63d_2f10_8e17, - ]), - Fp::from_raw([ - 0x24a2_0128_481b_4f7f, - 0x13d1_c887_26b5_ec42, - 0xb5bd_a237_6685_22f6, - 0x015b_ee13_57e3_c015, - ]), - ], - [ - Fp::from_raw([ - 0xea92_c785_b128_ffd1, - 0xfe1e_1ce4_bab2_18cb, - 0x1b97_07a4_f161_5e4e, - 0x2953_736e_94bb_6b9f, - ]), - Fp::from_raw([ - 0x4ce7_266e_d660_8dfc, - 0x851b_98d3_72b4_5f54, - 0x862f_8061_80c0_385f, - 0x0b06_9353_ba09_1618, - ]), - ], - [ - Fp::from_raw([ - 0x4f58_8ac9_7d81_f429, - 0x55ae_b7eb_9306_b64e, - 0x15e4_e0bc_fb93_817e, - 0x304f_74d4_61cc_c131, - ]), - Fp::from_raw([ - 0xb8ee_5415_cde9_13fc, - 0xaad2_a164_a461_7a4c, - 0xe8a3_3f5e_77df_e4f5, - 0x15bb_f146_ce9b_ca09, - ]), - ], - [ - Fp::from_raw([ - 0xa9ff_2385_9572_c8c6, - 0x9b8f_4b85_0405_c10c, - 0x4490_1031_4879_64ed, - 0x0ab4_dfe0_c274_2cde, - ]), - Fp::from_raw([ - 0x251d_e39f_9639_779a, - 0xef5e_edfe_a546_dea9, - 0x97f4_5f76_49a1_9675, - 0x0e32_db32_0a04_4e31, - ]), - ], - [ - Fp::from_raw([ - 0xa307_8efa_516d_a016, - 0x6797_733a_8277_4896, - 0xb276_35a7_8b68_88e6, - 0x0a17_56aa_1f37_8ca4, - ]), - Fp::from_raw([ - 0x4254_d6a2_a25d_93ef, - 0x95e6_1d32_8f85_efa9, - 0x47fd_1717_7f95_2ef8, - 0x044c_4a33_b10f_6934, - ]), - ], - [ - Fp::from_raw([ - 0xd37b_07b5_466c_4b8b, - 0xfe08_79d7_9a49_6891, - 0xbe65_5b53_7f66_f700, - 0x2ed3_611b_725b_8a70, - ]), - Fp::from_raw([ - 0xd833_9ea7_1208_58aa, - 0xadfd_eb9c_fdd3_47b5, - 0xc8ec_c3d7_22aa_2e0e, - 0x1f9b_a4e8_bab7_ce42, - ]), - ], - [ - Fp::from_raw([ - 0xb740_56f8_65c5_d3da, - 0xa38e_82ac_4502_066d, - 0x8f7e_e907_a84e_518a, - 0x1b23_3043_052e_8c28, - ]), - Fp::from_raw([ - 0xca2f_97b0_2087_5954, - 0x9020_53bf_c0f1_4db0, - 0x7403_1ab7_2bd5_5b4c, - 0x2431_e1cc_164b_b8d0, - ]), - ], - [ - Fp::from_raw([ - 0xa791_f273_9658_01fd, - 0xa13e_3220_9758_3319, - 0x30cd_6953_a0a7_db45, - 0x082f_934c_91f5_aac3, - ]), - Fp::from_raw([ - 0x9ad6_bb93_0c48_997c, - 0xc772_45e2_ae7c_be99, - 0xa34b_e074_3155_42a3, - 0x2b9a_0a22_3e75_38b0, - ]), - ], - [ - Fp::from_raw([ - 0xb0b5_89cc_7021_4e7d, - 0x8164_163e_75a8_a00e, - 0xceb8_5483_b887_a9be, - 0x0e1c_d91e_dd2c_fa2c, - ]), - Fp::from_raw([ - 0x88d3_2460_1ceb_e2f9, - 0x9977_4f19_854d_00f5, - 0xc951_f614_77e3_6989, - 0x2e1e_ac0f_2bfd_fd63, - ]), - ], - [ - Fp::from_raw([ - 0x23d7_4811_5b50_0b83, - 0x7345_784d_8efd_b33c, - 0x0c76_158e_769d_6d15, - 0x0cbf_a95f_37fb_7406, - ]), - Fp::from_raw([ - 0x980c_232d_fa4a_4f84, - 0x76d9_91e3_a775_13d9, - 0xd65a_d49d_8a61_e9a6, - 0x08f0_5b3b_e923_ed44, - ]), - ], - [ - Fp::from_raw([ - 0x25a2_dd51_0c04_7ef6, - 0xe728_4925_dc07_58a3, - 0x52bf_8e21_984d_0443, - 0x2271_9e2a_070b_cd08, - ]), - Fp::from_raw([ - 0xf41f_62b2_f268_30c0, - 0x7bdb_f036_1199_82c0, - 0xc060_f7fc_c3a1_ab4c, - 0x041f_596a_9ee1_cb2b, - ]), - ], - [ - Fp::from_raw([ - 0x19fc_dd09_86b1_0f89, - 0x021b_e1c2_d0dc_464a, - 0x8762_8eb0_6f6b_1d4c, - 0x233f_d35d_e1be_520a, - ]), - Fp::from_raw([ - 0xefcb_453c_61c9_c267, - 0xd31e_078a_a1b4_707e, - 0x4325_e0a4_23eb_c810, - 0x0524_b46d_1aa8_7a5e, - ]), - ], - [ - Fp::from_raw([ - 0xcc44_8623_7c51_5211, - 0x4227_bb95_4b0f_3199, - 0xce47_fcac_894b_8582, - 0x2c34_f424_c81e_5716, - ]), - Fp::from_raw([ - 0xf330_1032_7de4_915e, - 0x2dd2_025b_5457_cc97, - 0x207e_ffc2_b554_1fb7, - 0x0b5f_2a4b_6338_7819, - ]), - ], - [ - Fp::from_raw([ - 0xaefa_c41f_e05c_659f, - 0xc174_35d2_f57a_f6ce, - 0xc5b7_2fe4_39d2_cfd6, - 0x2220_7856_082c_cc54, - ]), - Fp::from_raw([ - 0x2785_4048_ce2c_8171, - 0xcdfb_2101_94ca_f79f, - 0x4e24_159b_7f89_50b5, - 0x24d5_7a8b_f5da_63fe, - ]), - ], - [ - Fp::from_raw([ - 0x7391_9bb2_3b79_396e, - 0x374a_d709_7bb0_1a85, - 0x3b37_1d75_bd69_3f98, - 0x0afa_b181_fdd5_e058, - ]), - Fp::from_raw([ - 0xf162_90d6_2b11_28ee, - 0x76c0_0571_94c1_6c0b, - 0x998a_52ef_ac7c_bd56, - 0x2dba_9b10_8f20_8772, - ]), - ], - [ - Fp::from_raw([ - 0x5aff_13e6_bce4_20b3, - 0xcbb8_3de0_bd59_2b25, - 0x56f8_81c7_88f5_3f83, - 0x2634_9b66_edb8_b16f, - ]), - Fp::from_raw([ - 0x2352_88a3_e6f1_37db, - 0xd81a_56d2_8ecc_193b, - 0x685e_95f9_2339_753a, - 0x25af_7ce0_e5e1_0357, - ]), - ], - [ - Fp::from_raw([ - 0x1f7c_0187_fe35_011f, - 0x70ee_d7aa_e88b_2bff, - 0xc094_d6a5_5edd_68b9, - 0x25b4_ce7b_d229_4390, - ]), - Fp::from_raw([ - 0x8cb9_d54c_1e02_b631, - 0xde9c_ef28_ebdf_30b1, - 0x387e_53f1_908a_88e5, - 0x22c5_43f1_0f6c_89ec, - ]), - ], - [ - Fp::from_raw([ - 0xdf66_8e74_882f_87a9, - 0x425e_906a_919d_7a34, - 0x4fc7_908a_9f19_1e1e, - 0x0236_f93e_7789_c472, - ]), - Fp::from_raw([ - 0x9cb4_97af_980c_4b52, - 0x652b_dae1_14eb_0165, - 0x0e7d_27e3_7d05_da99, - 0x2935_0b40_1166_ca01, - ]), - ], - [ - Fp::from_raw([ - 0xee12_6091_6652_363f, - 0x65ed_b75d_844e_bb89, - 0x6bd3_1bba_b547_f75a, - 0x0eed_787d_6582_0d3f, - ]), - Fp::from_raw([ - 0x1906_f656_f4de_6fad, - 0xfdcd_0e99_bd94_297d, - 0x036a_753f_520b_3291, - 0x07cc_1170_f13b_46f2, - ]), - ], - [ - Fp::from_raw([ - 0x2059_4356_89e8_acea, - 0x9087_86d7_f9f5_d10c, - 0xf49b_cf61_3a3d_30b1, - 0x22b9_3923_3b1d_7205, - ]), - Fp::from_raw([ - 0xadd6_50ac_e60a_e5a6, - 0x740f_083a_5aa8_5438, - 0x8aad_1dc8_bc33_e870, - 0x0145_1762_a0aa_b81c, - ]), - ], - [ - Fp::from_raw([ - 0xe704_fec0_892f_ce89, - 0xe32e_aa61_dec7_da57, - 0x61fa_bf10_25d4_6d1f, - 0x2350_6bb5_d872_7d44, - ]), - Fp::from_raw([ - 0x7f8b_d689_0735_5522, - 0x2a37_0953_1e1e_fea9, - 0xbac0_6ae3_f71b_dd09, - 0x2e48_4c44_e838_aea0, - ]), - ], - [ - Fp::from_raw([ - 0x4541_8da2_6835_b54c, - 0xaf4a_5945_45ce_dc25, - 0x379e_78c5_0bd2_e42b, - 0x0f4b_c7d0_7eba_fd64, - ]), - Fp::from_raw([ - 0xe620_996d_50d8_e74e, - 0x5158_2388_725d_f460, - 0xfa76_6378_62fa_aee8, - 0x1f4d_3c8f_6583_e9e5, - ]), - ], - [ - Fp::from_raw([ - 0x53eb_9bcb_48fe_7389, - 0xfae0_2abc_7b68_1d91, - 0x2660_d07b_e0e4_a988, - 0x0935_14e0_c707_11f8, - ]), - Fp::from_raw([ - 0x4a58_e0a3_47e1_53d8, - 0x43ee_83ec_e472_28f2, - 0x4669_9a2b_5f3b_c036, - 0x1ada_b0c8_e2b3_bad3, - ]), - ], - [ - Fp::from_raw([ - 0x1a22_dbef_9e80_dad2, - 0x378c_1b94_b807_2bac, - 0xd147_09eb_b474_641a, - 0x1672_b172_6057_d99d, - ]), - Fp::from_raw([ - 0x30d4_7b23_9b47_9c14, - 0xc5d8_e2fa_e0ac_c4ee, - 0x8f44_f53f_dcab_468c, - 0x1dfd_53d4_576a_f2e3, - ]), - ], - [ - Fp::from_raw([ - 0xbc7f_2077_5320_5c60, - 0xe6d7_7d64_0f6f_c3de, - 0xa70a_3626_3a37_e17f, - 0x0c68_88a1_0b75_b0f3, - ]), - Fp::from_raw([ - 0x8509_1ecc_a9d1_e508, - 0x611a_61e0_0ee6_848b, - 0x92b3_4a7e_77d1_2fe8, - 0x1add_b933_a65b_e770, - ]), - ], - [ - Fp::from_raw([ - 0x7935_628e_299d_1791, - 0xf638_ff54_25f0_afff, - 0x5c10_ae18_d1de_933c, - 0x00d7_540d_cd26_8a84, - ]), - Fp::from_raw([ - 0xd316_939d_20b8_2c0e, - 0x26fe_dde4_acd9_9db1, - 0x01b2_827a_5664_ca9c, - 0x140c_0e42_687e_9ead, - ]), - ], - [ - Fp::from_raw([ - 0xc091_e2ae_5656_5984, - 0xc20a_0f9b_24f8_c5ed, - 0x91ba_89b8_d13d_1806, - 0x2f0c_3a11_5d43_17d1, - ]), - Fp::from_raw([ - 0xd8c5_38a1_dc95_8c61, - 0x08a0_cff6_70b2_2b82, - 0x3006_ed22_0cf9_c810, - 0x0c4e_e778_ff7c_1455, - ]), - ], - [ - Fp::from_raw([ - 0x27c3_d748_5de7_4c69, - 0x9424_ed26_c0ac_c662, - 0x3693_f004_40cc_c360, - 0x1704_f276_6d46_f82c, - ]), - Fp::from_raw([ - 0x39b6_6fe9_009c_3cfa, - 0xf076_9c9f_8544_e402, - 0xa7a0_2c1b_51d2_44ab, - 0x2f2d_19cc_3ea5_d78e, - ]), - ], - [ - Fp::from_raw([ - 0xd6c7_66a8_06fc_6629, - 0xdd7e_e6cb_9cfe_d9c7, - 0x5053_f112_e2a8_e8dc, - 0x1ae0_3853_b75f_caba, - ]), - Fp::from_raw([ - 0x4e41_a86d_daf0_56d5, - 0x3556_921b_2d6f_014e, - 0x51d1_31d0_fa61_aa5f, - 0x0971_aabf_7952_41df, - ]), - ], - [ - Fp::from_raw([ - 0x5f5c_29f7_bfe2_f646, - 0xda62_4f83_80df_1c87, - 0x91d4_cf6b_6e0d_e73e, - 0x1408_c316_e601_4e1a, - ]), - Fp::from_raw([ - 0x4169_1f39_822e_f5bd, - 0x6c89_f1f7_73ef_2853, - 0x248a_be42_b543_093b, - 0x1667_f3fe_2edb_e850, - ]), - ], - [ - Fp::from_raw([ - 0x424c_6957_6500_fe37, - 0x5b81_7184_09e5_c133, - 0xa48b_0a03_557c_df91, - 0x13bf_7c5d_0d2c_4376, - ]), - Fp::from_raw([ - 0x19bc_0ba7_43a6_2c2c, - 0x024b_9534_7856_b797, - 0x3016_adf3_d353_3c24, - 0x0762_0a6d_fb0b_6cec, - ]), - ], - [ - Fp::from_raw([ - 0x1675_de3e_1982_b4d0, - 0x75d2_959e_2f32_2b73, - 0x36a8_ca08_bdbd_d8b0, - 0x1574_c7ef_0c43_545f, - ]), - Fp::from_raw([ - 0xc06e_03a7_ff83_78f0, - 0x5bd4_1845_71c2_54fd, - 0xfd56_7970_a717_ceec, - 0x269e_4b5b_7a2e_b21a, - ]), - ], -]; -// n: 254 -// t: 2 -// N: 508 -// Result Algorithm 1: -// [True, 0] -// Result Algorithm 2: -// [True, None] -// Result Algorithm 3: -// [True, None] -// Prime number: 0x0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 -// MDS matrix: -pub(crate) const MDS: [[Fp; 2]; 2] = [ - [ - Fp::from_raw([ - 0xbcec_a70b_d2af_7ad5, - 0xaf07_f38a_f8c9_52a7, - 0xec10_3453_51a2_3a3a, - 0x066f_6f85_d6f6_8a85, - ]), - Fp::from_raw([ - 0x0546_2b9f_8125_b1e8, - 0x20a7_c02b_bd8b_ea73, - 0x7782_e150_9b1d_0fdb, - 0x2b9d_4b41_10c9_ae99, - ]), - ], - [ - Fp::from_raw([ - 0xf573_f431_221f_8ff9, - 0xb6c0_9d55_7013_fff1, - 0x2bf6_7a44_93cc_262f, - 0x0cc5_7cdb_b085_07d6, - ]), - Fp::from_raw([ - 0x21bc_d147_9432_03c8, - 0xade8_57e8_6eb5_c3a1, - 0xa31a_6ed6_9724_e1ad, - 0x1274_e649_a32e_d355, - ]), - ], -]; -// Inverse MDS matrix: -pub(crate) const MDS_INV: [[Fp; 2]; 2] = [ - [ - Fp::from_raw([ - 0x8dbe_bd0f_a8c5_3e66, - 0x0554_569d_9b29_d1ea, - 0x7081_9ab1_c784_6f21, - 0x13ab_ec39_0ada_7f43, - ]), - Fp::from_raw([ - 0xaaf6_185b_1a1e_60fe, - 0xbd52_1ead_5dfe_0345, - 0x4c98_62a1_d97d_1510, - 0x1eb9_e1dc_19a3_3a62, - ]), - ], - [ - Fp::from_raw([ - 0x763f_7875_036b_cb02, - 0x8ce5_1690_30a2_ad69, - 0x601a_bc49_fdad_4f03, - 0x0fc1_c939_4db8_9bb2, - ]), - Fp::from_raw([ - 0x8abc_ed6b_d147_c8be, - 0x2b7e_ac34_3459_61bc, - 0x9502_054e_dc03_e7b2, - 0x16a9_e98c_493a_902b, - ]), - ], -]; diff --git a/zk_prover/src/chips/poseidon/poseidon_spec.rs b/zk_prover/src/chips/poseidon/poseidon_spec.rs deleted file mode 100644 index ed8d4096..00000000 --- a/zk_prover/src/chips/poseidon/poseidon_spec.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! This file was generated by running generate_params.py -//! Specification for rate 1 Poseidon using the BN256 curve. -//! Patterned after [halo2_gadgets::poseidon::primitives::P128Pow5T3] -use crate::chips::poseidon::poseidon_params; -use halo2_gadgets::poseidon::primitives::*; -use halo2_proofs::arithmetic::Field; -use halo2_proofs::halo2curves::bn256::Fr as Fp; - -#[derive(Debug, Clone, Copy)] -pub struct PoseidonSpec; - -pub(crate) type Mds = [[Fp; T]; T]; - -impl Spec for PoseidonSpec { - fn full_rounds() -> usize { - 8 - } - - fn partial_rounds() -> usize { - 56 - } - - fn sbox(val: Fp) -> Fp { - val.pow_vartime([5]) - } - - fn secure_mds() -> usize { - unimplemented!() - } - - fn constants() -> (Vec<[Fp; 2]>, Mds, Mds) { - ( - poseidon_params::ROUND_CONSTANTS[..].to_vec(), - poseidon_params::MDS, - poseidon_params::MDS_INV, - ) - } -} diff --git a/zk_prover/src/chips/range/mod.rs b/zk_prover/src/chips/range/mod.rs deleted file mode 100644 index 0f763cbb..00000000 --- a/zk_prover/src/chips/range/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod range_check; -mod tests; -pub mod utils; diff --git a/zk_prover/src/chips/range/range_check.rs b/zk_prover/src/chips/range/range_check.rs deleted file mode 100644 index d1421770..00000000 --- a/zk_prover/src/chips/range/range_check.rs +++ /dev/null @@ -1,154 +0,0 @@ -use halo2_proofs::arithmetic::Field; -use halo2_proofs::circuit::{AssignedCell, Layouter, Value}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use halo2_proofs::plonk::{Advice, Column, ConstraintSystem, Error, Expression, Fixed, Selector}; -use halo2_proofs::poly::Rotation; - -use std::fmt::Debug; - -use super::utils::decompose_fp_to_bytes; - -/// Configuration for the Range Check Chip -/// -/// # Type Parameters -/// -/// * `N_BYTES`: Number of bytes in which the value to be checked should lie -/// -/// # Fields -/// -/// * `z`: Advice column for the value to be checked and its running sum. -/// * `lookup_enable_selector`: Selector to enable the lookup check. -/// -/// Patterned after [halo2_gadgets](https://github.com/privacy-scaling-explorations/halo2/blob/main/halo2_gadgets/src/utilities/decompose_running_sum.rs) -#[derive(Debug, Copy, Clone)] -pub struct RangeCheckConfig { - z: Column, - lookup_enable_selector: Selector, -} - -/// Helper chip that verifies that the value witnessed in a given cell lies within a given range defined by N_BYTES. -/// For example, Let's say we want to constraint 0x1f2f3f4f to be within the range N_BYTES=4. -/// -/// `z(0) = 0x1f2f3f4f` -/// `z(1) = (0x1f2f3f4f - 0x4f) / 2^8 = 0x1f2f3f` -/// `z(2) = (0x1f2f3f - 0x3f) / 2^8 = 0x1f2f` -/// `z(3) = (0x1f2f - 0x2f) / 2^8 = 0x1f` -/// `z(4) = (0x1f - 0x1f) / 2^8 = 0x00` -/// -/// | | z | -/// | --- | ---------- | -/// | 0 | 0x1f2f3f4f | -/// | 1 | 0x1f2f3f | -/// | 2 | 0x1f2f | -/// | 3 | 0x1f | -/// | 4 | 0x00 | -/// -/// The column z contains the witnessed value to be checked at offset 0 -/// At offset i, the column z contains the value z(i+1) = (z(i) - k(i)) / 2^8 (shift right by 8 bits) where k(i) is the i-th decomposition big-endian of `value` -/// The constraints that are enforced are: -/// - z(i) - 2^8â‹…z(i+1) ∈ lookup_u8_table (enabled by lookup_enable_selector at offset [0, N_BYTES - 1]) -/// - z(N_BYTES) == 0 -#[derive(Debug, Clone)] -pub struct RangeCheckChip { - config: RangeCheckConfig, -} - -impl RangeCheckChip { - pub fn construct(config: RangeCheckConfig) -> Self { - Self { config } - } - - /// Configures the Range Chip - /// Note: the lookup table should be loaded with values from `0` to `2^8 - 1` otherwise the range check will fail. - pub fn configure( - meta: &mut ConstraintSystem, - z: Column, - lookup_u8_table: Column, - lookup_enable_selector: Selector, - ) -> RangeCheckConfig { - meta.annotate_lookup_any_column(lookup_u8_table, || "LOOKUP_MAXBITS_RANGE"); - - meta.lookup_any( - "range u8 check for difference between each interstitial running sum output", - |meta| { - let z_cur = meta.query_advice(z, Rotation::cur()); - let z_next = meta.query_advice(z, Rotation::next()); - - let lookup_enable_selector = meta.query_selector(lookup_enable_selector); - let u8_range = meta.query_fixed(lookup_u8_table, Rotation::cur()); - - let diff = z_cur - z_next * Expression::Constant(Fp::from(1 << 8)); - - vec![(lookup_enable_selector * diff, u8_range)] - }, - ); - - RangeCheckConfig { - z, - lookup_enable_selector, - } - } - - /// Assign the running sum to the chip starting from the value within an assigned cell. - pub fn assign( - &self, - mut layouter: impl Layouter, - value: &AssignedCell, - ) -> Result<(), Error> { - layouter.assign_region( - || "assign value to perform range check", - |mut region| { - // enable the lookup at offset [0, N_BYTES - 1] - for i in 0..N_BYTES { - self.config.lookup_enable_selector.enable(&mut region, i)?; - } - - // copy `value` to `z_0` at offset 0 - let z_0 = value.copy_advice( - || "assign value to be range checked", - &mut region, - self.config.z, - 0, - )?; - - // Decompose the value in #N_BYTES bytes - let bytes = value - .value() - .copied() - .map(|x| decompose_fp_to_bytes(x, N_BYTES)) - .transpose_vec(N_BYTES); - - // Initialize empty vector to store running sum values [z_0, ..., z_W]. - let mut zs: Vec> = vec![z_0.clone()]; - let mut z = z_0; - - // Assign running sum `z_{i+1}` = (z_i - k_i) / (2^8) for i = 0..=N_BYTES - 1. - let two_pow_k_inv = Value::known(Fp::from(1 << 8).invert().unwrap()); - - for (i, byte) in bytes.iter().enumerate() { - // z_next = (z_cur - byte) / (2^K) - let z_next = { - let z_cur_val = z.value().copied(); - let byte = byte.map(|byte| Fp::from(byte as u64)); - let z_next_val = (z_cur_val - byte) * two_pow_k_inv; - region.assign_advice( - || format!("z_{:?}", i + 1), - self.config.z, - i + 1, - || z_next_val, - )? - }; - - // Update `z`. - z = z_next; - zs.push(z.clone()); - } - - // Constrain the final running sum output to be zero. - region.constrain_constant(zs[N_BYTES].cell(), Fp::from(0))?; - - Ok(()) - }, - ) - } -} diff --git a/zk_prover/src/chips/range/tests.rs b/zk_prover/src/chips/range/tests.rs deleted file mode 100644 index 07cc5768..00000000 --- a/zk_prover/src/chips/range/tests.rs +++ /dev/null @@ -1,295 +0,0 @@ -use crate::{ - chips::range::range_check::{RangeCheckChip, RangeCheckConfig}, - circuits::traits::CircuitBase, -}; -use halo2_proofs::{ - circuit::{AssignedCell, Layouter, SimpleFloorPlanner, Value}, - halo2curves::bn256::Fr as Fp, - plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Selector}, - poly::Rotation, -}; - -#[derive(Debug, Clone)] -pub struct AddConfig { - pub col_a: Column, // stores the value of a - pub col_b: Column, // stores the value of b - pub col_c: Column, // stores the value of c = a + b - pub selector: Selector, -} - -#[derive(Debug, Clone)] -pub struct AddChip { - pub config: AddConfig, -} - -impl AddChip { - pub fn construct(config: AddConfig) -> Self { - Self { config } - } - - pub fn configure( - meta: &mut ConstraintSystem, - col_a: Column, - col_b: Column, - col_c: Column, - add_selector: Selector, - ) -> AddConfig { - meta.create_gate("add", |meta| { - let s = meta.query_selector(add_selector); - let a = meta.query_advice(col_a, Rotation::cur()); - let b = meta.query_advice(col_b, Rotation::cur()); - let c = meta.query_advice(col_c, Rotation::cur()); - vec![s * (a + b - c)] - }); - - AddConfig { - col_a, - col_b, - col_c, - selector: add_selector, - } - } - - pub fn assign( - &self, - a: Fp, - b: Fp, - mut layouter: impl Layouter, - ) -> Result< - ( - AssignedCell, - AssignedCell, - AssignedCell, - ), - Error, - > { - layouter.assign_region( - || "initialize value and sum", - |mut region| { - self.config.selector.enable(&mut region, 0)?; - - let a_cell = - region.assign_advice(|| "a", self.config.col_a, 0, || Value::known(a))?; - - let b_cell = - region.assign_advice(|| "b", self.config.col_b, 0, || Value::known(b))?; - - let c_cell = region.assign_advice( - || "a + b", - self.config.col_c, - 0, - || a_cell.value().copied() + b_cell.value(), - )?; - - Ok((a_cell, b_cell, c_cell)) - }, - ) - } -} - -#[derive(Debug, Clone)] -pub struct TestConfig { - pub addchip_config: AddConfig, - pub range_check_config: RangeCheckConfig, - pub lookup_u8_table: Column, -} - -// The test circuit takes two inputs a and b. -// It adds them together by using the add chip to produce c = a + b. -// Performs a range check on a, b and c. Each value should lie in N_BYTES. -#[derive(Default, Clone, Debug)] -struct TestCircuit { - pub a: Fp, - pub b: Fp, -} - -/// Inherit the `CircuitBase` trait for the `TestCircuit` struct. -impl CircuitBase for TestCircuit {} - -impl Circuit for TestCircuit { - type Config = TestConfig; - type FloorPlanner = SimpleFloorPlanner; - - fn without_witnesses(&self) -> Self { - Self::default() - } - - fn configure(meta: &mut ConstraintSystem) -> Self::Config { - let z = meta.advice_column(); - let lookup_u8_table = meta.fixed_column(); - - let a = meta.advice_column(); - let b = meta.advice_column(); - let c = meta.advice_column(); - - meta.enable_equality(z); - meta.enable_equality(a); - meta.enable_equality(b); - meta.enable_equality(c); - - let constants = meta.fixed_column(); - meta.enable_constant(constants); - - let add_selector = meta.selector(); - let lookup_enable_selector = meta.complex_selector(); - - let range_check_config = - RangeCheckChip::::configure(meta, z, lookup_u8_table, lookup_enable_selector); - - let addchip_config = AddChip::configure(meta, a, b, c, add_selector); - - { - TestConfig { - addchip_config, - range_check_config, - lookup_u8_table, - } - } - } - - fn synthesize( - &self, - config: Self::Config, - mut layouter: impl Layouter, - ) -> Result<(), Error> { - // Initiate the add chip - let addchip = AddChip::construct(config.addchip_config); - let (a_cell, b_cell, c_cell) = - addchip.assign(self.a, self.b, layouter.namespace(|| "add chip"))?; - - // Load the lookup table - self.load(&mut layouter, config.lookup_u8_table)?; - - // Initiate the range check chip - let range_chip = RangeCheckChip::construct(config.range_check_config); - - // check range on a, b and c - range_chip.assign( - layouter.namespace(|| "checking value a is in range"), - &a_cell, - )?; - range_chip.assign( - layouter.namespace(|| "checking value b is in range"), - &b_cell, - )?; - range_chip.assign( - layouter.namespace(|| "checking value c is in range"), - &c_cell, - )?; - - Ok(()) - } -} - -#[cfg(test)] -mod testing { - use super::TestCircuit; - use halo2_proofs::{ - dev::{FailureLocation, MockProver, VerifyFailure}, - halo2curves::bn256::Fr as Fp, - plonk::Any, - }; - - // a = (1 << 16) - 2 = 0xfffe - // b = 1 - // c = a + b = 0xffff - // All the values are within 2 bytes range. - #[test] - fn test_none_overflow_16bits() { - let k = 9; - - // a: new value - let a = Fp::from((1 << 16) - 2); - let b = Fp::from(1); - - let circuit = TestCircuit::<2> { a, b }; - let prover = MockProver::run(k, &circuit, vec![]).unwrap(); - prover.assert_satisfied(); - } - - // a = (1 << 16) - 2 = 0xfffe - // b = 2 - // c = a + b = 0x10000 - // a and b are within 2 bytes range. - // c overflows 2 bytes so the circuit should fail. - #[test] - fn test_overflow_16bits() { - let k = 9; - - let a = Fp::from((1 << 16) - 2); - let b = Fp::from(2); - - let circuit = TestCircuit::<2> { a, b }; - let invalid_prover = MockProver::run(k, &circuit, vec![]).unwrap(); - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (4, "assign value to perform range check").into(), - offset: 2 - } - }, - VerifyFailure::Permutation { - column: (Any::Fixed, 1).into(), - location: FailureLocation::OutsideRegion { row: 2 } - }, - ]) - ); - } - - // a is the max value within the range (32 bits / 4 bytes) - // a = 0x-ff-ff-ff-ff - // b = 1 - // a and b are within 4 bytes range. - // c overflows 4 bytes so the circuit should fail. - #[test] - fn test_overflow_32bits() { - let k = 9; - - let a = Fp::from(0xffffffff); - let b = Fp::from(1); - - let circuit = TestCircuit::<4> { a, b }; - let invalid_prover = MockProver::run(k, &circuit, vec![]).unwrap(); - - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (4, "assign value to perform range check").into(), - offset: 4 - } - }, - VerifyFailure::Permutation { - column: (Any::Fixed, 1).into(), - location: FailureLocation::OutsideRegion { row: 2 } - }, - ]) - ); - } - - #[cfg(feature = "dev-graph")] - #[test] - fn print_range_check_test() { - use plotters::prelude::*; - - let root = - BitMapBackend::new("prints/range-check-layout.png", (1024, 3096)).into_drawing_area(); - root.fill(&WHITE).unwrap(); - let root = root - .titled("Range Check Layout", ("sans-serif", 60)) - .unwrap(); - - let circuit = TestCircuit::<4> { - a: Fp::from(0x1f2f3f4f), - b: Fp::from(1), - }; - halo2_proofs::dev::CircuitLayout::default() - .render(9, &circuit, &root) - .unwrap(); - } -} diff --git a/zk_prover/src/chips/range/utils.rs b/zk_prover/src/chips/range/utils.rs deleted file mode 100644 index 1b20a29a..00000000 --- a/zk_prover/src/chips/range/utils.rs +++ /dev/null @@ -1,89 +0,0 @@ -use crate::merkle_sum_tree::utils::{big_uint_to_fp, fp_to_big_uint}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use num_bigint::BigUint; - -/// Converts value Fp to array of n bytes in little endian order. -/// If value is decomposed in #bytes which are less than n, then the returned bytes are padded with 0s at the most significant bytes. -/// Example: -/// decompose_fp_to_bytes(0x1f2f3f, 4) -> [0x3f, 0x2f, 0x1f, 0x00] -/// If value is decomposed in #bytes which are greater than n, then the most significant bytes are truncated. A warning is printed. -/// Example: -/// decompose_fp_to_bytes(0x1f2f3f, 2) -> [0x3f, 0x2f] -pub fn decompose_fp_to_bytes(value: Fp, n: usize) -> Vec { - let value_biguint = fp_to_big_uint(value); - - let mut bytes = value_biguint.to_bytes_le(); - - // Pad with 0s at the most significant bytes if bytes length is less than n. - while bytes.len() < n { - bytes.push(0); - } - - // If the bytes length exceeds n, print a warning and truncate the byte array at the most significant bytes. - if bytes.len() > n { - println!("Warning: `decompose_fp_to_bytes` value is decomposed in #bytes which are greater than n. Truncating the output to fit the specified length."); - bytes.truncate(n); - } - - bytes -} - -pub fn pow_of_two(by: usize) -> Fp { - let res = BigUint::from(1u8) << by; - big_uint_to_fp(&res) -} - -#[cfg(test)] -mod testing { - - use super::*; - use num_bigint::BigUint; - - #[test] - fn test_fp_to_big_uint() { - let f = Fp::from(5); - let big_uint = fp_to_big_uint(f); - assert_eq!(big_uint, BigUint::from(5u8)); - } - - // convert a 32 bit number in 4 bytes. Should correctly convert to 4 bytes - #[test] - fn test_decompose_fp_to_bytes_no_padding() { - let f = Fp::from(0x1f2f3f4f); - let bytes = decompose_fp_to_bytes(f, 4); - assert_eq!(bytes, vec![0x4f, 0x3f, 0x2f, 0x1f]); - } - - // convert a 32 bit number in 6 bytes. Should correctly convert to 6 bytes in which the first 2 bytes are 0 padded. - #[test] - fn test_decompose_fp_to_bytes_padding() { - let f = Fp::from(0x1f2f3f4f); - let bytes = decompose_fp_to_bytes(f, 6); - assert_eq!(bytes, vec![0x4f, 0x3f, 0x2f, 0x1f, 0x00, 0x00]); - } - - // convert a 32 bit number in 2 bytes. Should convert to 2 bytes and truncate the most significant bytes and emit a warning - #[test] - fn test_decompose_fp_to_bytes_overflow() { - let f = Fp::from(0x1f2f3f4f); - let bytes = decompose_fp_to_bytes(f, 2); - assert_eq!(bytes, vec![0x4f, 0x3f]); - } - - // convert a 40 bit number in 2 bytes. Should convert to 2 most significant bytes and truncate the least significant byte - #[test] - fn test_decompose_fp_to_bytes_overflow_2() { - let f = Fp::from(0xf1f2f3f); - let bytes = decompose_fp_to_bytes(f, 2); - assert_eq!(bytes, vec![0x3f, 0x2f]); - } - - #[test] - fn test_pow_2() { - let pow = pow_of_two(8); - assert_eq!(pow, Fp::from(0x100)); - let pow = pow_of_two(72); - let big_uint = BigUint::from(0x1000000000000000000u128); - assert_eq!(pow, big_uint_to_fp(&big_uint)); - } -} diff --git a/zk_prover/src/circom/incremental_mst_inclusion.circom b/zk_prover/src/circom/incremental_mst_inclusion.circom deleted file mode 100644 index 3dd14bdd..00000000 --- a/zk_prover/src/circom/incremental_mst_inclusion.circom +++ /dev/null @@ -1,77 +0,0 @@ -pragma circom 2.0.3; - -include "./node_modules/circomlib/circuits/poseidon.circom"; -include "./merkle_sum_tree.circom"; - -/* -Inputs: ---------- -- step_in[2] : `user_state_prev` and `liabilities_state_prev` from the previous step of the IVC -- username: username of the user whose inclusion in the merkle sum tree we want to prove -- user_balances[N_CURRENCIES]: balances of the user whose inclusion in the merkle sum tree we want to prove -- path_element_hashes[LEVELS]: hashes of elements of the merkle path -- path_element_balances[LEVELS][N_CURRENCIES]: balances of the elements of the merkle path -- path_indices[LEVELS]: binary selector that indicates whether given path_element is on the left or right side of merkle path - -Outputs: ---------- -- step_out[2] : `user_state_cur` and `liabilities_state_cur`, namely the resulting states after the IVC step. - - `user_state_cur` is equal to H(`user_state_prev`, `leaf_hash`) - - `liabilities_state_cur` is equal to H(`liabilities_state_prev`, `root_hash`) - -Parameters: ------------- -- LEVELS: number of levels in the merkle sum tree -- N_CURRENCIES: number of currencies for each user -- N_BYTES: range of the balances of the users - -Functionality: --------------- -1. Starting from the username and balances of the user, compute the `leaf_hash` -2. Starting from `user_state_prev` and `leaf_hash`, compute `user_state_cur` as H(`user_state_prev`, `leaf_hash`) -3. Starting from the `leaf_hash` and the Merkle Proof, compute the `root_hash` of the resulting Merkle Sum Tree -4. Starting from `liabilities_state_prev` and `root_hash`, compute `liabilities_state_cur` as H(`liabilities_state_prev`, `root_hash`) -*/ -template IncrementalMstInclusion (LEVELS, N_CURRENCIES, N_BYTES) { - signal input step_in[2]; - - signal input username; - signal input user_balances[N_CURRENCIES]; - signal input path_element_hashes[LEVELS]; - signal input path_element_balances[LEVELS][N_CURRENCIES]; - signal input path_indices[LEVELS]; - - signal output step_out[2]; - - // 1. - component build_leaf_hash = Poseidon(1 + N_CURRENCIES); - build_leaf_hash.inputs[0] <== username; - for (var i = 0; i < N_CURRENCIES; i++) { - build_leaf_hash.inputs[i + 1] <== user_balances[i]; - } - - // 2. - component build_user_state_cur = Poseidon(2); - build_user_state_cur.inputs[0] <== step_in[0]; - build_user_state_cur.inputs[1] <== build_leaf_hash.out; - - // 3. - component check_inclusion = MerkleSumTreeInclusion(LEVELS, N_CURRENCIES, N_BYTES); - - check_inclusion.leaf_hash <== build_leaf_hash.out; - check_inclusion.leaf_balances <== user_balances; - check_inclusion.path_element_hashes <== path_element_hashes; - check_inclusion.path_element_balances <== path_element_balances; - check_inclusion.path_indices <== path_indices; - - // 4. - component build_liabilities_state_cur = Poseidon(2); - build_liabilities_state_cur.inputs[0] <== step_in[1]; - build_liabilities_state_cur.inputs[1] <== check_inclusion.root_hash; - - step_out[0] <== build_user_state_cur.out; - step_out[1] <== build_liabilities_state_cur.out; -} - -component main { public [step_in] } = IncrementalMstInclusion(4, 2, 14); - diff --git a/zk_prover/src/circom/merkle_sum_tree.circom b/zk_prover/src/circom/merkle_sum_tree.circom deleted file mode 100644 index 94cb83c0..00000000 --- a/zk_prover/src/circom/merkle_sum_tree.circom +++ /dev/null @@ -1,254 +0,0 @@ -pragma circom 2.0.3; - -include "./node_modules/circomlib/circuits/poseidon.circom"; -include "./node_modules/circomlib/circuits/bitify.circom"; -include "./node_modules/circomlib/circuits/mux1.circom"; - -/* -Inputs: ---------- -- left_balances[N_CURRENCIES] : Balances of the left node -- right_balances[N_CURRENCIES] : Balances of the right node - -Outputs: ---------- -- out_balances[N_CURRENCIES] : Each element of `out_balances` is the sum of the corresponding elements in left_balances and right_balances. -Ex. out_balances[0] = left_balances[0] + right_balances[0] - -Functionality: --------------- -1. Constraint each input balance to be within the range [0, N_BYTES] -2. Perform the summation of two balances - -Notes: ------- -- The range check is performed only on the input of the summation. The range check on the output of the summation will be performed in the next level of the tree. -When the output will be used as an input to another summation. When the next level is the root, the range check is performed outside of the Summer template - -*/ - -template Summer(N_CURRENCIES, N_BYTES) { - signal input left_balances[N_CURRENCIES]; - signal input right_balances[N_CURRENCIES]; - signal output out_balances[N_CURRENCIES]; - - component left_in_range[N_CURRENCIES]; - component right_in_range[N_CURRENCIES]; - - for (var i = 0; i < N_CURRENCIES; i++) { - left_in_range[i] = Num2Bits(8*N_BYTES); - right_in_range[i] = Num2Bits(8*N_BYTES); - - left_in_range[i].in <== left_balances[i]; - right_in_range[i].in <== right_balances[i]; - - out_balances[i] <== left_balances[i] + right_balances[i]; - } -} - -/* -Inputs: ---------- -- left_hash: Hash of the left node -- left_balances[N_CURRENCIES] : Balances of the left node -- right_hash: Hash of the right node -- right_balances[N_CURRENCIES] : Balances of the right node -- s: binary selector - -Outputs: ---------- -- swapped_left_hash: left_hash if s = 0, right_hash if s = 1 -- swapped_left_balances[N_CURRENCIES]: left_balances if s = 0, right_balances if s = 1 -- swapped_right_hash: right_hash if s = 0, left_hash if s = 1 -- swapped_right_balances[N_CURRENCIES]: right_balances if s = 0, left_balances if s = 1 - -Parameters: ------------- -- N_CURRENCIES: number of currencies for each user - -Functionality: --------------- -1. Perform the swapping of two nodes belonging to a level of the merkle sum tree according to the binary selector s -2. Constraint that s is either 0 or 1 -*/ - -template Swapper(N_CURRENCIES) { - signal input left_hash; - signal input left_balances[N_CURRENCIES]; - signal input right_hash; - signal input right_balances[N_CURRENCIES]; - signal input s; - signal output swapped_left_hash; - signal output swapped_left_balances[N_CURRENCIES]; - signal output swapped_right_hash; - signal output swapped_right_balances[N_CURRENCIES]; - - s * (1 - s) === 0; - - component mux = MultiMux1(2 + 2*N_CURRENCIES); - - mux.c[0][0] <== left_hash; - - for (var i = 0; i < N_CURRENCIES; i++) { - mux.c[1 + i][0] <== left_balances[i]; - } - - mux.c[1 + N_CURRENCIES][0] <== right_hash; - - for (var i = 0; i < N_CURRENCIES; i++) { - mux.c[2 + N_CURRENCIES + i][0] <== right_balances[i]; - } - - mux.c[0][1] <== right_hash; - - for (var i = 0; i < N_CURRENCIES; i++) { - mux.c[1 + i][1] <== right_balances[i]; - } - - mux.c[1 + N_CURRENCIES][1] <== left_hash; - - for (var i = 0; i < N_CURRENCIES; i++) { - mux.c[2 + N_CURRENCIES + i][1] <== left_balances[i]; - } - - mux.s <== s; - - swapped_left_hash <== mux.out[0]; - - for (var i = 0; i < N_CURRENCIES; i++) { - swapped_left_balances[i] <== mux.out[1 + i]; - } - - swapped_right_hash <== mux.out[1 + N_CURRENCIES]; - - for (var i = 0; i < N_CURRENCIES; i++) { - swapped_right_balances[i] <== mux.out[2 + N_CURRENCIES + i]; - } -} - -/* -Inputs: ---------- -- left_hash: Hash of the left node -- left_balances[N_CURRENCIES] : Balances of the left node -- right_hash: Hash of the right node -- right_balances[N_CURRENCIES] : Balances of the right node - -Outputs: ---------- -- hash: poseidon hash of (left_hash, left_balances[0], ..., left_balances[N_CURRENCIES - 1], right_hash, right_balances[0], ..., right_balances[N_CURRENCIES - 1]) - -Parameters: ------------- -- N_CURRENCIES: number of currencies for each user - -Functionality: --------------- -1. Perform the hashing of two nodes belonging to a level of the merkle sum tree -*/ - -template Hasher(N_CURRENCIES) { - signal input left_hash; - signal input left_balances[N_CURRENCIES]; - signal input right_hash; - signal input right_balances[N_CURRENCIES]; - signal output hash; - - // 1. - component hasher = Poseidon(2 + 2*N_CURRENCIES); - - hasher.inputs[0] <== left_hash; - - for (var i = 0; i < N_CURRENCIES; i++) { - hasher.inputs[1 + i] <== left_balances[i]; - } - - hasher.inputs[1 + N_CURRENCIES] <== right_hash; - - for (var i = 0; i < N_CURRENCIES; i++) { - hasher.inputs[2 + N_CURRENCIES + i] <== right_balances[i]; - } - - hash <== hasher.out; -} - - -/* -Inputs: ---------- -- leaf_hash: hash of the leaf node that we want to prove inclusion for -- leaf_balances[N_CURRENCIES]: balances of the leaf node that we want to prove inclusion for -- path_element_hashes[LEVELS]: hashes of elements of the merkle path -- path_element_balances[LEVELS][N_CURRENCIES]: balances of the elements of the merkle path -- path_indices[LEVELS]: binary selector that indicates whether given path_element is on the left or right side of merkle path - -Outputs: ---------- -- root_hash: root hash of the resulting merkle sum tree - -Parameters: ------------- -- LEVELS: number of levels in the merkle sum tree -- N_CURRENCIES: number of currencies for each user -- N_BYTES: range of the balances of the users - -Functionality: --------------- -1. For each level of the tree, perform the summation between the balances of the two nodes -2. For each level of the tree, perform the swapping of the nodes according to the binary selector -3. For each level of the tree, perform the hashing of the two swapped nodes -4. At the latest level, perform the range check on the root balances - -Notes: ------- -- The summer is performed before the swapper because the swap doesn't influence the summation. -*/ -template MerkleSumTreeInclusion(LEVELS, N_CURRENCIES, N_BYTES) { - signal input leaf_hash; - signal input leaf_balances[N_CURRENCIES]; - signal input path_element_hashes[LEVELS]; - signal input path_element_balances[LEVELS][N_CURRENCIES]; - signal input path_indices[LEVELS]; - - signal output root_hash; - - component summers[LEVELS]; - component swappers[LEVELS]; - component hashers[LEVELS]; - - for (var i = 0; i < LEVELS; i++) { - // 1. - summers[i] = Summer(N_CURRENCIES, N_BYTES); - - summers[i].left_balances <== i == 0 ? leaf_balances : summers[i - 1].out_balances; - summers[i].right_balances <== path_element_balances[i]; - - // 2. - swappers[i] = Swapper(N_CURRENCIES); - - swappers[i].left_hash <== i == 0 ? leaf_hash : hashers[i - 1].hash; - swappers[i].left_balances <== i == 0 ? leaf_balances : summers[i - 1].out_balances; - swappers[i].right_hash <== path_element_hashes[i]; - swappers[i].right_balances <== path_element_balances[i]; - swappers[i].s <== path_indices[i]; - - // 3. - hashers[i] = Hasher(N_CURRENCIES); - - hashers[i].left_hash <== swappers[i].swapped_left_hash; - hashers[i].left_balances <== swappers[i].swapped_left_balances; - hashers[i].right_hash <== swappers[i].swapped_right_hash; - hashers[i].right_balances <== swappers[i].swapped_right_balances; - - } - - // 4. - component root_balance_in_range[N_CURRENCIES]; - - for (var i = 0; i < N_CURRENCIES; i++) { - root_balance_in_range[i] = Num2Bits(8*N_BYTES); - root_balance_in_range[i].in <== summers[LEVELS - 1].out_balances[i]; - } - - root_hash <== hashers[LEVELS - 1].hash; -} \ No newline at end of file diff --git a/zk_prover/src/circom/package-lock.json b/zk_prover/src/circom/package-lock.json deleted file mode 100644 index 123c8553..00000000 --- a/zk_prover/src/circom/package-lock.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "circom", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "circom", - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "circomlib": "^2.0.5" - } - }, - "node_modules/circomlib": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/circomlib/-/circomlib-2.0.5.tgz", - "integrity": "sha512-O7NQ8OS+J4eshBuoy36z/TwQU0YHw8W3zxZcs4hVwpEll3e4hDm3mgkIPqItN8FDeLEKZFK3YeT/+k8TiLF3/A==" - } - } -} diff --git a/zk_prover/src/circom/package.json b/zk_prover/src/circom/package.json deleted file mode 100644 index 7117d386..00000000 --- a/zk_prover/src/circom/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "circom", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "dependencies": { - "circomlib": "^2.0.5" - } -} diff --git a/zk_prover/src/circuits/merkle_sum_tree.rs b/zk_prover/src/circuits/merkle_sum_tree.rs deleted file mode 100644 index 7b3b9d2d..00000000 --- a/zk_prover/src/circuits/merkle_sum_tree.rs +++ /dev/null @@ -1,525 +0,0 @@ -use crate::chips::merkle_sum_tree::{MerkleSumTreeChip, MerkleSumTreeConfig}; -use crate::chips::poseidon::hash::{PoseidonChip, PoseidonConfig}; -use crate::chips::poseidon::poseidon_spec::PoseidonSpec; -use crate::chips::range::range_check::{RangeCheckChip, RangeCheckConfig}; -use crate::circuits::traits::CircuitBase; -use crate::merkle_sum_tree::utils::big_uint_to_fp; -use crate::merkle_sum_tree::{Entry, MerkleProof, Node}; -use halo2_proofs::circuit::{AssignedCell, Layouter, SimpleFloorPlanner}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use halo2_proofs::plonk::{ - Advice, Circuit, Column, ConstraintSystem, Error, Fixed, Instance, Selector, -}; -use snark_verifier_sdk::CircuitExt; - -/// Circuit for verifying inclusion of an entry (username, balances) inside a merkle sum tree with a given root. -/// -/// # Type Parameters -/// -/// * `LEVELS`: The number of levels of the merkle sum tree. In particular, it indicates the number of hashing operations that are performed from the leaf to the root. For example a tree with 16 entries has 4 levels. -/// * `N_CURRENCIES`: The number of currencies for which the solvency is verified. -/// * `N_BYTES`: The number of bytes in which the balances should lie -/// -/// # Fields -/// -/// * `entry`: The entry to be verified inclusion of. -/// * `path_indices`: The boolean indices of the path elements from the leaf to the root. 0 indicates that the element is on the right to the path, 1 indicates that the element is on the left to the path. The length of this vector is LEVELS -/// * `sibling_leaf_node_hash_preimage`: The preimage of the hash that corresponds to the Sibling Leaf Node (part of the Merkle Proof). -/// * `sibling_middle_node_hash_preimages`: The preimages of the hashes that corresponds to the Sibling Middle Nodes (part of the Merkle Proof). -/// * `root`: The root of the Merkle Sum Tree -#[derive(Clone)] -pub struct MstInclusionCircuit -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - pub entry: Entry, - pub path_indices: Vec, - pub sibling_leaf_node_hash_preimage: [Fp; N_CURRENCIES + 1], - pub sibling_middle_node_hash_preimages: Vec<[Fp; N_CURRENCIES + 2]>, - pub root: Node, -} - -impl CircuitExt - for MstInclusionCircuit -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - /// Returns the number of public inputs of the circuit. It is {2 + N_CURRENCIES}, namely the leaf hash to be verified inclusion of, the root hash of the merkle sum tree and the root balances of the merkle sum tree. - fn num_instance(&self) -> Vec { - vec![{ 2 + N_CURRENCIES }] - } - /// Returns the values of the public inputs of the circuit. Namely the leaf hash to be verified inclusion of and the root hash of the merkle sum tree. - fn instances(&self) -> Vec> { - let mut instance = vec![self.entry.compute_leaf().hash, self.root.hash]; - instance.extend_from_slice(&self.root.balances); - vec![instance] - } -} - -impl CircuitBase - for MstInclusionCircuit -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ -} - -impl - MstInclusionCircuit -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - pub fn init_empty() -> Self { - Self { - entry: Entry::init_empty(), - path_indices: vec![Fp::zero(); LEVELS], - sibling_leaf_node_hash_preimage: [Fp::zero(); N_CURRENCIES + 1], - sibling_middle_node_hash_preimages: vec![[Fp::zero(); N_CURRENCIES + 2]; LEVELS], - root: Node::init_empty(), - } - } - - /// Initializes the circuit with the merkle proof and the entry of the user of which the inclusion is to be verified. - pub fn init(merkle_proof: MerkleProof) -> Self - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - assert_eq!(merkle_proof.path_indices.len(), LEVELS); - assert_eq!( - merkle_proof.sibling_middle_node_hash_preimages.len(), - LEVELS - 1 - ); - Self { - entry: merkle_proof.entry, - path_indices: merkle_proof.path_indices, - sibling_leaf_node_hash_preimage: merkle_proof.sibling_leaf_node_hash_preimage, - sibling_middle_node_hash_preimages: merkle_proof.sibling_middle_node_hash_preimages, - root: merkle_proof.root, - } - } -} - -/// Configuration for the Mst Inclusion circuit -/// # Type Parameters -/// -/// * `N_CURRENCIES`: The number of currencies for which the solvency is verified. -/// * `N_BYTES`: The number of bytes in which the balances should lie -/// -/// # Fields -/// -/// * `merkle_sum_tree_config`: Configuration for the merkle sum tree -/// * `poseidon_entry_config`: Configuration for the poseidon hash function with WIDTH = 2 and RATE = 1 and input length of N_CURRENCIES + 1. Needed to perform the hashing from the entry to the leaf. -/// * `poseidon_middle_config`: Configuration for the poseidon hash function with WIDTH = 2 and RATE = 1 and input length of N_CURRENCIES + 2. Needed to perform hashings from the leaf to the root. -/// * `range_check_config`: Configuration for the range check chip -/// * `instance`: Instance column used to store the public inputs -/// * `advices`: Advice columns used to store the private inputs - -#[derive(Debug, Clone)] -pub struct MstInclusionConfig -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - merkle_sum_tree_config: MerkleSumTreeConfig, - poseidon_entry_config: PoseidonConfig<2, 1, { N_CURRENCIES + 1 }>, - poseidon_middle_config: PoseidonConfig<2, 1, { N_CURRENCIES + 2 }>, - range_check_config: RangeCheckConfig, - instance: Column, - advices: [Column; 3], - fixed_columns: [Column; 5], -} - -impl MstInclusionConfig -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - pub fn configure(meta: &mut ConstraintSystem) -> Self { - // the max number of advices columns needed is WIDTH + 1 given requirement of the poseidon config - let advices: [Column; 3] = std::array::from_fn(|_| meta.advice_column()); - - // we need 2 * WIDTH fixed columns for poseidon config + 1 for the range check chip - let fixed_columns: [Column; 5] = std::array::from_fn(|_| meta.fixed_column()); - - // we also need 2 selectors for the MerkleSumTreeChip - let selectors: [Selector; 2] = std::array::from_fn(|_| meta.selector()); - - // we need 1 complex selector for the lookup check in the range check chip - let enable_lookup_selector = meta.complex_selector(); - - // enable constant for the fixed_column[2], this is required for the poseidon chip and the range check chip - meta.enable_constant(fixed_columns[2]); - - let poseidon_entry_config = - PoseidonChip::::configure( - meta, - advices[0..2].try_into().unwrap(), - advices[2], - fixed_columns[0..2].try_into().unwrap(), - fixed_columns[2..4].try_into().unwrap(), - ); - - // in fact, the poseidon config requires #WIDTH advice columns for state and 1 for partial_sbox, #WIDTH fixed columns for rc_a and #WIDTH for rc_b - let poseidon_middle_config = - PoseidonChip::::configure( - meta, - advices[0..2].try_into().unwrap(), - advices[2], - fixed_columns[0..2].try_into().unwrap(), - fixed_columns[2..4].try_into().unwrap(), - ); - - // enable permutation for all the advice columns - for col in &advices { - meta.enable_equality(*col); - } - - // the configuration of merkle_sum_tree will always require 3 advices, no matter the number of currencies - let merkle_sum_tree_config = MerkleSumTreeChip::::configure( - meta, - advices[0..3].try_into().unwrap(), - selectors[0..2].try_into().unwrap(), - ); - - let range_check_config = RangeCheckChip::::configure( - meta, - advices[0], - fixed_columns[4], - enable_lookup_selector, - ); - - let instance = meta.instance_column(); - meta.enable_equality(instance); - - Self { - merkle_sum_tree_config, - poseidon_entry_config, - poseidon_middle_config, - range_check_config, - instance, - advices, - fixed_columns, - } - } -} - -impl Circuit - for MstInclusionCircuit -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - type Config = MstInclusionConfig; - type FloorPlanner = SimpleFloorPlanner; - - fn without_witnesses(&self) -> Self { - Self::init_empty() - } - - /// Configures the circuit - fn configure(meta: &mut ConstraintSystem) -> Self::Config { - MstInclusionConfig::::configure(meta) - } - - fn synthesize( - &self, - config: Self::Config, - mut layouter: impl Layouter, - ) -> Result<(), Error> { - // build auxiliary chips - let merkle_sum_tree_chip = - MerkleSumTreeChip::::construct(config.merkle_sum_tree_config); - - let poseidon_entry_chip = - PoseidonChip::::construct( - config.poseidon_entry_config, - ); - - let poseidon_middle_chip = - PoseidonChip::::construct( - config.poseidon_middle_config, - ); - - let range_check_chip = RangeCheckChip::::construct(config.range_check_config); - - // Assign the entry username to the witness - let username = self.assign_value_to_witness( - layouter.namespace(|| "assign entry username"), - big_uint_to_fp(self.entry.username_as_big_uint()), - "entry username", - config.advices[0], - )?; - - // Assign the entry balances to the witness - let mut current_balances = vec![]; - - for i in 0..N_CURRENCIES { - let balance = self.assign_value_to_witness( - layouter.namespace(|| format!("assign entry balance {}", i)), - big_uint_to_fp(&self.entry.balances()[i]), - "entry balance", - config.advices[1], - )?; - current_balances.push(balance); - } - - // Perform the hashing to username and balances to obtain the leaf hash - // create an hash_input array of length N_CURRENCIES + 1 that contains the entry username and the entry balances - let entry_hasher_input_vec: Vec> = [username] - .iter() - .chain(current_balances.iter()) - .map(|x| x.to_owned()) - .collect(); - - let entry_hasher_input: [AssignedCell; N_CURRENCIES + 1] = - match entry_hasher_input_vec.try_into() { - Ok(arr) => arr, - Err(_) => panic!("Failed to convert Vec to Array"), - }; - - // compute the entry hash - let mut current_hash = poseidon_entry_chip.hash( - layouter.namespace(|| "perform poseidon entry hash"), - entry_hasher_input, - )?; - - // expose the first current hash, namely the leaf hash, as public input - self.expose_public( - layouter.namespace(|| "public leaf hash"), - ¤t_hash, - 0, - config.instance, - )?; - - // load lookup table for range check - self.load(&mut layouter, config.fixed_columns[4])?; - - for level in 0..LEVELS { - let namespace_prefix = format!("level {}", level); - - let sibling_hash: AssignedCell; // hash of the sibling node - let mut sibling_balances: Vec> = vec![]; // balances of the sibling node - - // Perform the hashing of sibling leaf hash preimage to obtain the sibling leaf hash - if level == 0 { - // Assign username from sibling leaf node hash preimage to the circuit - let sibling_leaf_node_username = self.assign_value_to_witness( - layouter.namespace(|| format!("sibling leaf node username")), - self.sibling_leaf_node_hash_preimage[0], - "sibling leaf node username", - config.advices[0], - )?; - - // Assign balances from sibling leaf node hash preimage to the circuit - for currency in 0..N_CURRENCIES { - let leaf_node_sibling_balance = self.assign_value_to_witness( - layouter.namespace(|| format!("sibling leaf node balance {}", currency)), - self.sibling_leaf_node_hash_preimage[currency + 1], - "sibling leaf balance", - config.advices[1], - )?; - sibling_balances.push(leaf_node_sibling_balance); - } - - // create an hash_input array of length N_CURRENCIES + 1 that contains the sibling_leaf_node_username and the sibling_balances (the sibling leaf node hash preimage) - let sibling_hasher_input_vec: Vec> = - [sibling_leaf_node_username] - .iter() - .chain(sibling_balances.iter()) - .map(|x| x.to_owned()) - .collect(); - - let sibling_hasher_input: [AssignedCell; N_CURRENCIES + 1] = - match sibling_hasher_input_vec.try_into() { - Ok(arr) => arr, - Err(_) => panic!("Failed to convert Vec to Array"), - }; - - // compute the sibling hash - let computed_sibling_hash = poseidon_entry_chip.hash( - layouter.namespace(|| format!("{}: perform poseidon hash", namespace_prefix)), - sibling_hasher_input, - )?; - - // For level 0, perform range check on the leaf node balances and on the sibling node balances - for currency in 0..N_CURRENCIES { - // Each balance cell is constrained to be within the range defined by N_BYTES - range_check_chip.assign( - layouter.namespace(|| { - format!( - "{}: currency {}: range check leaf balance", - namespace_prefix, currency - ) - }), - ¤t_balances[currency], - )?; - range_check_chip.assign( - layouter.namespace(|| { - format!( - "{}: currency {}: range check sibling balance", - namespace_prefix, currency - ) - }), - &sibling_balances[currency], - )?; - } - - sibling_hash = computed_sibling_hash; - } - // Other levels - // Assign sibling node hash preimage to the circuit (split it in balances, left child hash and right child hash) - // Perform the hashing of sibling node hash preimage to obtain the sibling node hash - else { - // Assign balances from sibling middle node hash preimage to the circuit - for currency in 0..N_CURRENCIES { - let middle_node_sibling_balance = self.assign_value_to_witness( - layouter.namespace(|| format!("sibling node balance {}", currency)), - self.sibling_middle_node_hash_preimages[level - 1][currency], - "sibling node balance", - config.advices[1], - )?; - sibling_balances.push(middle_node_sibling_balance); - } - - // Assign middle_node_sibling_child_left_hash from middle node hash preimage to the circuit - let middle_node_sibling_child_left_hash = self.assign_value_to_witness( - layouter.namespace(|| format!("sibling left hash")), - self.sibling_middle_node_hash_preimages[level - 1][N_CURRENCIES], - "sibling left hash", - config.advices[2], - )?; - - // Assign middle_node_sibling_child_right_hash from middle node hash preimage to the circuit - let middle_node_sibling_child_right_hash = self.assign_value_to_witness( - layouter.namespace(|| format!("sibling right hash")), - self.sibling_middle_node_hash_preimages[level - 1][N_CURRENCIES + 1], - "sibling right hash", - config.advices[2], - )?; - - // create an hash_input array of length 2 + N_CURRENCIES that contains the sibling balances, the middle_node_sibling_child_left_hash and the middle_node_sibling_child_right_hash - let sibling_hasher_input_vec: Vec> = sibling_balances - .iter() - .chain([middle_node_sibling_child_left_hash].iter()) - .chain([middle_node_sibling_child_right_hash].iter()) - .map(|x| x.to_owned()) - .collect(); - - let sibling_hasher_input: [AssignedCell; N_CURRENCIES + 2] = - match sibling_hasher_input_vec.try_into() { - Ok(arr) => arr, - Err(_) => panic!("Failed to convert Vec to Array"), - }; - - // compute the sibling hash - let computed_sibling_hash = poseidon_middle_chip.hash( - layouter.namespace(|| format!("{}: perform poseidon hash", namespace_prefix)), - sibling_hasher_input, - )?; - - // For other levels, only perform range on the sibling node balances. Any risk of overflow of the `current_balances` will be checked during verification - for currency in 0..N_CURRENCIES { - // Each balance cell is constrained to be within the range defined by N_BYTES - range_check_chip.assign( - layouter.namespace(|| { - format!( - "{}: currency {}: range check sibling balance", - namespace_prefix, currency - ) - }), - &sibling_balances[currency], - )?; - } - - sibling_hash = computed_sibling_hash; - }; - - // For each level assign the swap bit to the circuit - let swap_bit_level = self.assign_value_to_witness( - layouter.namespace(|| format!("{}: assign swap bit", namespace_prefix)), - self.path_indices[level], - "swap bit", - config.advices[0], - )?; - - // For every level, perform the swap of the hashes (between `current_hash` and `sibling_hash`) according to the swap bit - let (hash_left_current, hash_right_current) = merkle_sum_tree_chip - .swap_hashes_per_level( - layouter.namespace(|| format!("{}: swap hashes", namespace_prefix)), - ¤t_hash, - &sibling_hash, - &swap_bit_level, - )?; - - let mut next_balances = vec![]; - let mut left_balances = vec![]; - let mut right_balances = vec![]; - - // For every level, perform the swap of the balances (between `current_balances` and `sibling_balances`) according to the swap bit - for currency in 0..N_CURRENCIES { - let (left_balance, right_balance, next_balance) = merkle_sum_tree_chip - .swap_balances_per_level( - layouter.namespace(|| { - format!( - "{}: currency {}: assign nodes balance", - namespace_prefix, currency - ) - }), - ¤t_balances[currency], - &sibling_balances[currency], - &swap_bit_level, - )?; - - next_balances.push(next_balance); - left_balances.push(left_balance); - right_balances.push(right_balance); - } - - // create an hash_input array of length N_CURRENCIES + 2 that contains the next balances, the left hash and the right hash - let middle_hasher_input_vec: Vec> = next_balances - .iter() - .chain([hash_left_current].iter()) - .chain([hash_right_current].iter()) - .map(|x| x.to_owned()) - .collect(); - - let middle_hasher_input: [AssignedCell; N_CURRENCIES + 2] = - match middle_hasher_input_vec.try_into() { - Ok(arr) => arr, - Err(_) => panic!("Failed to convert Vec to Array"), - }; - - // compute the next hash - let computed_hash = poseidon_middle_chip.hash( - layouter.namespace(|| format!("{}: perform poseidon hash", namespace_prefix)), - middle_hasher_input, - )?; - - current_balances = next_balances; - current_hash = computed_hash; - } - - // expose the last current hash, namely the root hash, as public input - self.expose_public( - layouter.namespace(|| "public root hash"), - ¤t_hash, - 1, - config.instance, - )?; - - // expose the last current balances, namely the root balances, as public input - for (i, balance) in current_balances.iter().enumerate() { - self.expose_public( - layouter.namespace(|| format!("public root balance {}", i)), - balance, - 2 + i, - config.instance, - )?; - } - Ok(()) - } -} diff --git a/zk_prover/src/circuits/mod.rs b/zk_prover/src/circuits/mod.rs deleted file mode 100644 index 1a494993..00000000 --- a/zk_prover/src/circuits/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod merkle_sum_tree; -mod tests; -pub mod traits; -pub mod types; -pub mod utils; diff --git a/zk_prover/src/circuits/tests.rs b/zk_prover/src/circuits/tests.rs deleted file mode 100644 index 5a021059..00000000 --- a/zk_prover/src/circuits/tests.rs +++ /dev/null @@ -1,496 +0,0 @@ -#[cfg(test)] -mod test { - - use crate::merkle_sum_tree::{MerkleSumTree, Tree}; - use crate::{ - circuits::{ - merkle_sum_tree::MstInclusionCircuit, - utils::{full_prover, full_verifier, generate_setup_artifacts}, - }, - merkle_sum_tree::Entry, - }; - use halo2_proofs::{ - dev::{FailureLocation, MockProver, VerifyFailure}, - halo2curves::bn256::Fr as Fp, - plonk::Any, - }; - use num_bigint::ToBigUint; - use snark_verifier_sdk::CircuitExt; - - const N_CURRENCIES: usize = 2; - const LEVELS: usize = 4; - const N_BYTES: usize = 14; - const K: u32 = 11; - - #[test] - fn test_valid_merkle_sum_tree() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - for user_index in 0..16 { - // get proof for entry ˆuser_indexˆ - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let valid_prover = MockProver::run(K, &circuit, circuit.instances()).unwrap(); - - assert_eq!(circuit.instances()[0].len(), circuit.num_instance()[0]); - assert_eq!(circuit.instances()[0].len(), 2 + N_CURRENCIES); - - valid_prover.assert_satisfied(); - } - } - - #[test] - fn test_valid_merkle_sum_tree_with_full_prover() { - let circuit = MstInclusionCircuit::::init_empty(); - - // Generate a universal trusted setup for testing purposes. - // - // The verification key (vk) and the proving key (pk) are then generated. - // An empty circuit is used here to emphasize that the circuit inputs are not relevant when generating the keys. - // Important: The dimensions of the circuit used to generate the keys must match those of the circuit used to generate the proof. - // In this case, the dimensions are represented by the height of the Merkle tree. - let (params, pk, vk) = generate_setup_artifacts(K, None, circuit).unwrap(); - - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - let user_entry = merkle_sum_tree.get_entry(user_index); - - // Only now we can instantiate the circuit with the actual inputs - let circuit = MstInclusionCircuit::::init(merkle_proof); - - // Generate the proof - let proof = full_prover(¶ms, &pk, circuit.clone(), circuit.instances()); - - // verify the proof to be true - assert!(full_verifier(¶ms, &vk, proof, circuit.instances())); - - // the user should perform the check on the public inputs - // public input #0 is the leaf hash - let expected_leaf_hash = user_entry.compute_leaf().hash; - assert_eq!(circuit.instances()[0][0], expected_leaf_hash); - - // public input #1 is the root hash - let expected_root_hash = merkle_sum_tree.root().hash; - assert_eq!(circuit.instances()[0][1], expected_root_hash); - - // public inputs [2, 2+N_CURRENCIES - 1] are the root balances - let expected_root_balances = merkle_sum_tree.root().balances; - for i in 0..N_CURRENCIES { - assert_eq!(circuit.instances()[0][2 + i], expected_root_balances[i]); - } - } - - // Passing an invalid root hash in the instance column should fail the permutation check between the computed root hash and the instance column root hash - #[test] - fn test_invalid_root_hash() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let mut instances = circuit.instances(); - let invalid_root_hash = Fp::from(1000u64); - instances[0][1] = invalid_root_hash; - - let invalid_prover = MockProver::run(K, &circuit, instances).unwrap(); - - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (121, "permute state").into(), - offset: 36 - } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 1 } - }, - ]) - ); - } - - #[test] - fn test_invalid_root_hash_as_instance_with_full_prover() { - let circuit = MstInclusionCircuit::::init_empty(); - - // generate a universal trusted setup for testing, along with the verification key (vk) and the proving key (pk). - let (params, pk, vk) = generate_setup_artifacts(K, None, circuit).unwrap(); - - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let invalid_root_hash = Fp::from(1000u64); - - let mut instances = circuit.instances(); - instances[0][1] = invalid_root_hash; - - // Generate the proof - let proof = full_prover(¶ms, &pk, circuit, instances.clone()); - - // verify the proof to be false - assert!(!full_verifier(¶ms, &vk, proof, instances)); - } - - // Passing an invalid entry balance as input for the witness generation should fail: - // - the permutation check between the leaf hash and the instance column leaf hash - // - the permutation check between the computed root hash and the instance column root hash - // - the permutations checks between the computed root balances and the instance column root balances - #[test] - fn test_invalid_entry_balance_as_witness() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - let mut circuit = MstInclusionCircuit::::init(merkle_proof); - - let instances = circuit.instances(); - - let invalid_leaf_balances = [1000.to_biguint().unwrap(), 1000.to_biguint().unwrap()]; - - // invalidate user entry - let invalid_entry = - Entry::new(circuit.entry.username().to_string(), invalid_leaf_balances).unwrap(); - - circuit.entry = invalid_entry; - - let invalid_prover = MockProver::run(K, &circuit, instances).unwrap(); - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (26, "assign nodes hashes per merkle tree level").into(), - offset: 0 - } - }, - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (121, "permute state").into(), - offset: 36 - } - }, - VerifyFailure::Permutation { - column: (Any::advice(), 2).into(), - location: FailureLocation::InRegion { - region: (111, "assign nodes balances per currency").into(), - offset: 1 - } - }, - VerifyFailure::Permutation { - column: (Any::advice(), 2).into(), - location: FailureLocation::InRegion { - region: (112, "assign nodes balances per currency").into(), - offset: 1 - } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 0 } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 1 } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 2 } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 3 } - }, - ]) - ); - } - - // Passing an invalid leaf hash in the instance column should fail the permutation check between the (valid) leaf hash added as part of the witness and the instance column leaf hash - #[test] - fn test_invalid_leaf_hash_as_instance() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let mut instances = circuit.instances(); - let invalid_leaf_hash = Fp::from(1000u64); - instances[0][0] = invalid_leaf_hash; - - let invalid_prover = MockProver::run(K, &circuit, instances).unwrap(); - - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (26, "assign nodes hashes per merkle tree level").into(), - offset: 0 - } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 0 } - }, - ]) - ); - } - - // Passing a non binary index should fail the bool constraint inside "assign nodes hashes per merkle tree level" and "assign nodes balances per currency" region and the permutation check between the computed root hash and the instance column root hash - #[test] - fn test_non_binary_index() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - let mut circuit = MstInclusionCircuit::::init(merkle_proof); - - let instances = circuit.instances(); - - // invalidate path index inside the circuit - circuit.path_indices[0] = Fp::from(2); - - let invalid_prover = MockProver::run(K, &circuit, instances).unwrap(); - - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::ConstraintNotSatisfied { - constraint: ((6, "bool constraint").into(), 0, "").into(), - location: FailureLocation::InRegion { - region: (26, "assign nodes hashes per merkle tree level").into(), - offset: 0 - }, - cell_values: vec![(((Any::advice(), 2).into(), 0).into(), "0x2".to_string()),] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((6, "bool constraint").into(), 0, "").into(), - location: FailureLocation::InRegion { - region: (27, "assign nodes balances per currency").into(), - offset: 0 - }, - cell_values: vec![(((Any::advice(), 2).into(), 0).into(), "0x2".to_string()),] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((6, "bool constraint").into(), 0, "").into(), - location: FailureLocation::InRegion { - region: (28, "assign nodes balances per currency").into(), - offset: 0 - }, - cell_values: vec![(((Any::advice(), 2).into(), 0).into(), "0x2".to_string()),] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((7, "swap constraint").into(), 0, "").into(), - location: FailureLocation::InRegion { - region: (26, "assign nodes hashes per merkle tree level").into(), - offset: 0 - }, - cell_values: vec![ - ( - ((Any::advice(), 0).into(), 0).into(), - "0xe113acd03b98f0bab0ef6f577245d5d008cbcc19ef2dab3608aa4f37f72a407" - .to_string() - ), - ( - ((Any::advice(), 0).into(), 1).into(), - "0x17ef9d8ee0e2c8470814651413b71009a607a020214f749687384a7b7a7eb67a" - .to_string() - ), - ( - ((Any::advice(), 1).into(), 0).into(), - "0x17ef9d8ee0e2c8470814651413b71009a607a020214f749687384a7b7a7eb67a" - .to_string() - ), - (((Any::advice(), 2).into(), 0).into(), "0x2".to_string()), - ] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((7, "swap constraint").into(), 1, "").into(), - location: FailureLocation::InRegion { - region: (26, "assign nodes hashes per merkle tree level").into(), - offset: 0 - }, - cell_values: vec![ - ( - ((Any::advice(), 0).into(), 0).into(), - "0xe113acd03b98f0bab0ef6f577245d5d008cbcc19ef2dab3608aa4f37f72a407" - .to_string() - ), - ( - ((Any::advice(), 1).into(), 0).into(), - "0x17ef9d8ee0e2c8470814651413b71009a607a020214f749687384a7b7a7eb67a" - .to_string() - ), - ( - ((Any::advice(), 1).into(), 1).into(), - "0xe113acd03b98f0bab0ef6f577245d5d008cbcc19ef2dab3608aa4f37f72a407" - .to_string() - ), - (((Any::advice(), 2).into(), 0).into(), "0x2".to_string()), - ] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((7, "swap constraint").into(), 0, "").into(), - location: FailureLocation::InRegion { - region: (27, "assign nodes balances per currency").into(), - offset: 0 - }, - cell_values: vec![ - (((Any::advice(), 0).into(), 0).into(), "0x2e70".to_string()), - (((Any::advice(), 0).into(), 1).into(), "0x108ef".to_string()), - (((Any::advice(), 1).into(), 0).into(), "0x108ef".to_string()), - (((Any::advice(), 2).into(), 0).into(), "0x2".to_string()), - ] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((7, "swap constraint").into(), 1, "").into(), - location: FailureLocation::InRegion { - region: (27, "assign nodes balances per currency").into(), - offset: 0 - }, - cell_values: vec![ - (((Any::advice(), 0).into(), 0).into(), "0x2e70".to_string()), - (((Any::advice(), 1).into(), 0).into(), "0x108ef".to_string()), - (((Any::advice(), 1).into(), 1).into(), "0x2e70".to_string()), - (((Any::advice(), 2).into(), 0).into(), "0x2".to_string()), - ] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((7, "swap constraint").into(), 0, "").into(), - location: FailureLocation::InRegion { - region: (28, "assign nodes balances per currency").into(), - offset: 0 - }, - cell_values: vec![ - (((Any::advice(), 0).into(), 0).into(), "0xa0cb".to_string()), - (((Any::advice(), 0).into(), 1).into(), "0x48db".to_string()), - (((Any::advice(), 1).into(), 0).into(), "0x48db".to_string()), - (((Any::advice(), 2).into(), 0).into(), "0x2".to_string()), - ] - }, - VerifyFailure::ConstraintNotSatisfied { - constraint: ((7, "swap constraint").into(), 1, "").into(), - location: FailureLocation::InRegion { - region: (28, "assign nodes balances per currency").into(), - offset: 0 - }, - cell_values: vec![ - (((Any::advice(), 0).into(), 0).into(), "0xa0cb".to_string()), - (((Any::advice(), 1).into(), 0).into(), "0x48db".to_string()), - (((Any::advice(), 1).into(), 1).into(), "0xa0cb".to_string()), - (((Any::advice(), 2).into(), 0).into(), "0x2".to_string()), - ] - }, - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (121, "permute state").into(), - offset: 36 - } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 1 } - }, - ]) - ); - } - - // Swapping the indices should fail the permutation check between the computed root hash and the instance column root hash - #[test] - fn test_swapping_index() { - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - // Only now we can instantiate the circuit with the actual inputs - let mut circuit = MstInclusionCircuit::::init(merkle_proof); - - let instances = circuit.instances(); - - // swap indices - circuit.path_indices[0] = Fp::from(1); - - let invalid_prover = MockProver::run(K, &circuit, instances).unwrap(); - - assert_eq!( - invalid_prover.verify(), - Err(vec![ - VerifyFailure::Permutation { - column: (Any::advice(), 0).into(), - location: FailureLocation::InRegion { - region: (121, "permute state").into(), - offset: 36 - } - }, - VerifyFailure::Permutation { - column: (Any::Instance, 0).into(), - location: FailureLocation::OutsideRegion { row: 1 } - }, - ]) - ); - } - - #[cfg(feature = "dev-graph")] - #[test] - fn print_mst_inclusion() { - use plotters::prelude::*; - - let merkle_sum_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let user_index = 0; - - let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); - - let circuit = MstInclusionCircuit::::init(merkle_proof); - - let root = BitMapBackend::new("prints/mst-inclusion-layout.png", (2048, 32768)) - .into_drawing_area(); - root.fill(&WHITE).unwrap(); - let root = root - .titled("Merkle Sum Tree Inclusion Layout", ("sans-serif", 60)) - .unwrap(); - - halo2_proofs::dev::CircuitLayout::default() - .render(K, &circuit, &root) - .unwrap(); - } -} diff --git a/zk_prover/src/circuits/traits.rs b/zk_prover/src/circuits/traits.rs deleted file mode 100644 index 359b3f5b..00000000 --- a/zk_prover/src/circuits/traits.rs +++ /dev/null @@ -1,53 +0,0 @@ -use halo2_proofs::circuit::{Layouter, Value}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use halo2_proofs::plonk::{Advice, Column, Error, Fixed}; -use halo2_proofs::{circuit::AssignedCell, plonk::Instance}; - -/// Trait containing common methods for all circuits -pub trait CircuitBase { - /// Enforce copy constraint check between input cell and instance column at row passed as input - fn expose_public( - &self, - mut layouter: impl Layouter, - cell: &AssignedCell, - row: usize, - instance: Column, - ) -> Result<(), Error> { - layouter.constrain_instance(cell.cell(), instance, row) - } - - /// Generic method to assign `value` to a cell in the witness table to advice column `advice_col`. `object_to_assign` is label to identify the object being assigned. It is useful for debugging. - /// Returns the assigned cell. - fn assign_value_to_witness( - &self, - mut layouter: impl Layouter, - value: Fp, - object_to_assign: &'static str, - advice_col: Column, - ) -> Result, Error> { - layouter.assign_region( - || format!("assign {}", object_to_assign), - |mut region| region.assign_advice(|| "value", advice_col, 0, || Value::known(value)), - ) - } - - /// Loads the lookup table with values from `0` to `2^8 - 1` - fn load(&self, layouter: &mut impl Layouter, column: Column) -> Result<(), Error> { - let range = 1 << 8; - - layouter.assign_region( - || format!("load range check table of {} bits", 8), - |mut region| { - for i in 0..range { - region.assign_fixed( - || "assign cell in fixed column", - column, - i, - || Value::known(Fp::from(i as u64)), - )?; - } - Ok(()) - }, - ) - } -} diff --git a/zk_prover/src/circuits/types.rs b/zk_prover/src/circuits/types.rs deleted file mode 100644 index 4a546666..00000000 --- a/zk_prover/src/circuits/types.rs +++ /dev/null @@ -1,14 +0,0 @@ -use ethers::types::U256; -use serde::{Deserialize, Serialize}; - -#[derive(Serialize, Deserialize)] -pub struct ProofSolidityCallData { - pub proof: String, - pub public_inputs: Vec, -} - -#[derive(Serialize, Deserialize)] -pub struct CommitmentSolidityCallData { - pub root_hash: U256, - pub root_balances: Vec, -} diff --git a/zk_prover/src/circuits/utils.rs b/zk_prover/src/circuits/utils.rs deleted file mode 100644 index 80525204..00000000 --- a/zk_prover/src/circuits/utils.rs +++ /dev/null @@ -1,483 +0,0 @@ -use std::{ - fs::File, - io::{BufRead, BufReader, Write}, - path::PathBuf, -}; - -use ark_std::{end_timer, start_timer}; -use ethers::types::{Bytes, U256}; -use halo2_proofs::{ - halo2curves::{ - bn256::{Bn256, Fr as Fp, G1Affine}, - ff::PrimeField, - }, - plonk::{create_proof, keygen_pk, keygen_vk, verify_proof, Circuit, ProvingKey, VerifyingKey}, - poly::{ - commitment::{Params, ParamsProver}, - kzg::{ - commitment::{KZGCommitmentScheme, ParamsKZG}, - multiopen::{ProverSHPLONK, VerifierSHPLONK}, - strategy::SingleStrategy, - }, - }, - transcript::{ - Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer, - }, -}; -use rand::rngs::OsRng; -use regex_simple::Regex; -use snark_verifier::{ - cost::CostEstimation, - pcs::kzg::{Bdfg21, KzgAs}, - system::halo2::{compile, Config}, - verifier::plonk::PlonkSuccinctVerifier, -}; -use snark_verifier_sdk::{evm::gen_evm_proof_shplonk, CircuitExt}; - -/// Generate setup artifacts for a circuit of size `k`, where 2^k represents the number of rows in the circuit. -/// -/// If the trusted setup parameters are not found, the function performs an unsafe trusted setup to generate the necessary parameters -/// If the provided `k` value is larger than the `k` value of the loaded parameters, an error is returned, as the provided `k` is too large. -/// Otherwise, if the `k` value is smaller than the `k` value of the loaded parameters, the parameters are downsized to fit the requested `k`. -pub fn generate_setup_artifacts + CircuitExt>( - k: u32, - params_path: Option<&str>, - circuit: C, -) -> Result< - ( - ParamsKZG, - ProvingKey, - VerifyingKey, - ), - &'static str, -> { - let mut params: ParamsKZG; - - match params_path { - Some(path) => { - let timer = start_timer!(|| "Creating params"); - let mut params_fs = File::open(path).expect("couldn't load params"); - params = ParamsKZG::::read(&mut params_fs).expect("Failed to read params"); - end_timer!(timer); - - if params.k() < k { - return Err("k is too large for the given params"); - } - - if params.k() > k { - let timer = start_timer!(|| "Downsizing params"); - params.downsize(k); - end_timer!(timer); - } - } - None => { - let timer = start_timer!(|| "None Creating params"); - params = ParamsKZG::::setup(k, OsRng); - end_timer!(timer); - } - } - - let vk = keygen_vk(¶ms, &circuit).expect("vk generation should not fail"); - let pk = keygen_pk(¶ms, vk.clone(), &circuit).expect("pk generation should not fail"); - - Ok((params, pk, vk)) -} - -/// Generates a proof given the public setup, the proving key, the initiated circuit and its public inputs. -pub fn full_prover + CircuitExt>( - params: &ParamsKZG, - pk: &ProvingKey, - circuit: C, - public_inputs: Vec>, -) -> Vec { - let pf_time = start_timer!(|| "Creating proof"); - - let instance: Vec<&[Fp]> = public_inputs.iter().map(|input| &input[..]).collect(); - let instances = &[&instance[..]]; - - let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]); - create_proof::< - KZGCommitmentScheme, - ProverSHPLONK<'_, Bn256>, - Challenge255, - _, - Blake2bWrite, G1Affine, Challenge255>, - _, - >(params, pk, &[circuit], instances, OsRng, &mut transcript) - .expect("prover should not fail"); - let proof = transcript.finalize(); - end_timer!(pf_time); - proof -} - -/// Verifies a proof given the public setup, the verification key, the proof and the public inputs of the circuit. -pub fn full_verifier( - params: &ParamsKZG, - vk: &VerifyingKey, - proof: Vec, - public_inputs: Vec>, -) -> bool { - let verifier_params = params.verifier_params(); - let strategy = SingleStrategy::new(params); - let mut transcript = Blake2bRead::<_, _, Challenge255<_>>::init(&proof[..]); - - let instance: Vec<&[Fp]> = public_inputs.iter().map(|input| &input[..]).collect(); - let instances = &[&instance[..]]; - - verify_proof::< - KZGCommitmentScheme, - VerifierSHPLONK<'_, Bn256>, - Challenge255, - Blake2bRead<&[u8], G1Affine, Challenge255>, - SingleStrategy<'_, Bn256>, - >(verifier_params, vk, strategy, instances, &mut transcript) - .is_ok() -} - -/// Generate a solidity verifier contract starting from its yul code. -/// patterned after https://github.com/zkonduit/ezkl/blob/main/src/eth.rs#L326-L602 -fn fix_verifier_sol(yul_code_path: PathBuf) -> Result> { - let file = File::open(yul_code_path.clone())?; - let reader = BufReader::new(file); - - let mut transcript_addrs: Vec = Vec::new(); - let mut modified_lines: Vec = Vec::new(); - - // convert calldataload 0x0 to 0x40 to read from pubInputs, and the rest - // from proof - let calldata_pattern = Regex::new(r"^.*(calldataload\((0x[a-f0-9]+)\)).*$")?; - let mstore_pattern = Regex::new(r"^\s*(mstore\(0x([0-9a-fA-F]+)+),.+\)")?; - let mstore8_pattern = Regex::new(r"^\s*(mstore8\((\d+)+),.+\)")?; - let mstoren_pattern = Regex::new(r"^\s*(mstore\((\d+)+),.+\)")?; - let mload_pattern = Regex::new(r"(mload\((0x[0-9a-fA-F]+))\)")?; - let keccak_pattern = Regex::new(r"(keccak256\((0x[0-9a-fA-F]+))")?; - let modexp_pattern = - Regex::new(r"(staticcall\(gas\(\), 0x5, (0x[0-9a-fA-F]+), 0xc0, (0x[0-9a-fA-F]+), 0x20)")?; - let ecmul_pattern = - Regex::new(r"(staticcall\(gas\(\), 0x7, (0x[0-9a-fA-F]+), 0x60, (0x[0-9a-fA-F]+), 0x40)")?; - let ecadd_pattern = - Regex::new(r"(staticcall\(gas\(\), 0x6, (0x[0-9a-fA-F]+), 0x80, (0x[0-9a-fA-F]+), 0x40)")?; - let ecpairing_pattern = - Regex::new(r"(staticcall\(gas\(\), 0x8, (0x[0-9a-fA-F]+), 0x180, (0x[0-9a-fA-F]+), 0x20)")?; - let bool_pattern = Regex::new(r":bool")?; - - // Count the number of pub inputs - let mut start = None; - let mut end = None; - for (i, line) in reader.lines().enumerate() { - let line = line?; - if line.trim().starts_with("mstore(0x20") && start.is_none() { - start = Some(i as u32); - } - - if line.trim().starts_with("mstore(0x0") { - end = Some(i as u32); - break; - } - } - - let num_pubinputs = if let Some(s) = start { - end.unwrap() - s - } else { - 0 - }; - - let mut max_pubinputs_addr = 0; - if num_pubinputs > 0 { - max_pubinputs_addr = num_pubinputs * 32 - 32; - } - // println!("max_pubinputs_addr {}", max_pubinputs_addr); - - let file = File::open(yul_code_path)?; - let reader = BufReader::new(file); - - for line in reader.lines() { - let mut line = line?; - let m = bool_pattern.captures(&line); - if m.is_some() { - line = line.replace(":bool", ""); - } - - let m = calldata_pattern.captures(&line); - if let Some(m) = m { - let calldata_and_addr = m.get(1).unwrap().as_str(); - let addr = m.get(2).unwrap().as_str(); - let addr_as_num = u32::from_str_radix(addr.strip_prefix("0x").unwrap(), 16)?; - - if addr_as_num <= max_pubinputs_addr { - let pub_addr = format!("{:#x}", addr_as_num + 32); - // println!("pub_addr {}", pub_addr); - line = line.replace( - calldata_and_addr, - &format!("mload(add(pubInputs, {}))", pub_addr), - ); - } else { - let proof_addr = format!("{:#x}", addr_as_num - max_pubinputs_addr); - // println!("proof_addr {}", proof_addr); - line = line.replace( - calldata_and_addr, - &format!("mload(add(proof, {}))", proof_addr), - ); - } - } - - let m = mstore8_pattern.captures(&line); - if let Some(m) = m { - let mstore = m.get(1).unwrap().as_str(); - let addr = m.get(2).unwrap().as_str(); - let addr_as_num = addr.parse::()?; - let transcript_addr = format!("{:#x}", addr_as_num); - transcript_addrs.push(addr_as_num); - line = line.replace( - mstore, - &format!("mstore8(add(transcript, {})", transcript_addr), - ); - } - - let m = mstoren_pattern.captures(&line); - if let Some(m) = m { - let mstore = m.get(1).unwrap().as_str(); - let addr = m.get(2).unwrap().as_str(); - let addr_as_num = addr.parse::()?; - let transcript_addr = format!("{:#x}", addr_as_num); - transcript_addrs.push(addr_as_num); - line = line.replace( - mstore, - &format!("mstore(add(transcript, {})", transcript_addr), - ); - } - - let m = modexp_pattern.captures(&line); - if let Some(m) = m { - let modexp = m.get(1).unwrap().as_str(); - let start_addr = m.get(2).unwrap().as_str(); - let result_addr = m.get(3).unwrap().as_str(); - let start_addr_as_num = - u32::from_str_radix(start_addr.strip_prefix("0x").unwrap(), 16)?; - let result_addr_as_num = - u32::from_str_radix(result_addr.strip_prefix("0x").unwrap(), 16)?; - - let transcript_addr = format!("{:#x}", start_addr_as_num); - transcript_addrs.push(start_addr_as_num); - let result_addr = format!("{:#x}", result_addr_as_num); - line = line.replace( - modexp, - &format!( - "staticcall(gas(), 0x5, add(transcript, {}), 0xc0, add(transcript, {}), 0x20", - transcript_addr, result_addr - ), - ); - } - - let m = ecmul_pattern.captures(&line); - if let Some(m) = m { - let ecmul = m.get(1).unwrap().as_str(); - let start_addr = m.get(2).unwrap().as_str(); - let result_addr = m.get(3).unwrap().as_str(); - let start_addr_as_num = - u32::from_str_radix(start_addr.strip_prefix("0x").unwrap(), 16)?; - let result_addr_as_num = - u32::from_str_radix(result_addr.strip_prefix("0x").unwrap(), 16)?; - - let transcript_addr = format!("{:#x}", start_addr_as_num); - let result_addr = format!("{:#x}", result_addr_as_num); - transcript_addrs.push(start_addr_as_num); - transcript_addrs.push(result_addr_as_num); - line = line.replace( - ecmul, - &format!( - "staticcall(gas(), 0x7, add(transcript, {}), 0x60, add(transcript, {}), 0x40", - transcript_addr, result_addr - ), - ); - } - - let m = ecadd_pattern.captures(&line); - if let Some(m) = m { - let ecadd = m.get(1).unwrap().as_str(); - let start_addr = m.get(2).unwrap().as_str(); - let result_addr = m.get(3).unwrap().as_str(); - let start_addr_as_num = - u32::from_str_radix(start_addr.strip_prefix("0x").unwrap(), 16)?; - let result_addr_as_num = - u32::from_str_radix(result_addr.strip_prefix("0x").unwrap(), 16)?; - - let transcript_addr = format!("{:#x}", start_addr_as_num); - let result_addr = format!("{:#x}", result_addr_as_num); - transcript_addrs.push(start_addr_as_num); - transcript_addrs.push(result_addr_as_num); - line = line.replace( - ecadd, - &format!( - "staticcall(gas(), 0x6, add(transcript, {}), 0x80, add(transcript, {}), 0x40", - transcript_addr, result_addr - ), - ); - } - - let m = ecpairing_pattern.captures(&line); - if let Some(m) = m { - let ecpairing = m.get(1).unwrap().as_str(); - let start_addr = m.get(2).unwrap().as_str(); - let result_addr = m.get(3).unwrap().as_str(); - let start_addr_as_num = - u32::from_str_radix(start_addr.strip_prefix("0x").unwrap(), 16)?; - let result_addr_as_num = - u32::from_str_radix(result_addr.strip_prefix("0x").unwrap(), 16)?; - - let transcript_addr = format!("{:#x}", start_addr_as_num); - let result_addr = format!("{:#x}", result_addr_as_num); - transcript_addrs.push(start_addr_as_num); - transcript_addrs.push(result_addr_as_num); - line = line.replace( - ecpairing, - &format!( - "staticcall(gas(), 0x8, add(transcript, {}), 0x180, add(transcript, {}), 0x20", - transcript_addr, result_addr - ), - ); - } - - let m = mstore_pattern.captures(&line); - if let Some(m) = m { - let mstore = m.get(1).unwrap().as_str(); - let addr = m.get(2).unwrap().as_str(); - let addr_as_num = u32::from_str_radix(addr, 16)?; - let transcript_addr = format!("{:#x}", addr_as_num); - transcript_addrs.push(addr_as_num); - line = line.replace( - mstore, - &format!("mstore(add(transcript, {})", transcript_addr), - ); - } - - let m = keccak_pattern.captures(&line); - if let Some(m) = m { - let keccak = m.get(1).unwrap().as_str(); - let addr = m.get(2).unwrap().as_str(); - let addr_as_num = u32::from_str_radix(addr.strip_prefix("0x").unwrap(), 16)?; - let transcript_addr = format!("{:#x}", addr_as_num); - transcript_addrs.push(addr_as_num); - line = line.replace( - keccak, - &format!("keccak256(add(transcript, {})", transcript_addr), - ); - } - - // mload can show up multiple times per line - loop { - let m = mload_pattern.captures(&line); - if m.is_none() { - break; - } - let mload = m.as_ref().unwrap().get(1).unwrap().as_str(); - let addr = m.as_ref().unwrap().get(2).unwrap().as_str(); - - let addr_as_num = u32::from_str_radix(addr.strip_prefix("0x").unwrap(), 16)?; - let transcript_addr = format!("{:#x}", addr_as_num); - transcript_addrs.push(addr_as_num); - line = line.replace( - mload, - &format!("mload(add(transcript, {})", transcript_addr), - ); - } - - modified_lines.push(line); - } - - // get the max transcript addr - let max_transcript_addr = transcript_addrs.iter().max().unwrap() / 32; - let mut contract = format!( - "// SPDX-License-Identifier: MIT - pragma solidity ^0.8.17; - - contract Verifier {{ - function verify( - uint256[] memory pubInputs, - bytes memory proof - ) public view returns (bool) {{ - bool success = true; - bytes32[{}] memory transcript; - assembly {{ - ", - max_transcript_addr - ) - .trim() - .to_string(); - - // using a boxed Write trait object here to show it works for any Struct impl'ing Write - // you may also use a std::fs::File here - let write: Box<&mut dyn std::fmt::Write> = Box::new(&mut contract); - - for line in modified_lines[16..modified_lines.len() - 7].iter() { - write!(write, "{}", line).unwrap(); - } - writeln!(write, "}} return success; }} }}")?; - Ok(contract) -} - -/// Generate the proof Solidity calldata for a circuit -pub fn gen_proof_solidity_calldata + CircuitExt>( - params: &ParamsKZG, - pk: &ProvingKey, - circuit: C, -) -> (Bytes, Vec) { - let instances = circuit.instances(); - - let pf_time = start_timer!(|| "Creating proof"); - // To generate the proof calldata, make sure you have installed `solc` - let proof_calldata = gen_evm_proof_shplonk(params, pk, circuit, instances.clone()); - end_timer!(pf_time); - - let mut public_inputs = vec![]; - let flattened_instances = instances.into_iter().flatten(); - - for val in flattened_instances { - public_inputs.push(field_element_to_solidity_calldata(val)); - } - - let solidity_proof_calldata = Bytes::from(proof_calldata); - - (solidity_proof_calldata, public_inputs) -} - -/// Converts a field element to a Solidity calldata -pub fn field_element_to_solidity_calldata(field_element: Fp) -> U256 { - let bytes = field_element.to_repr(); - let u = U256::from_little_endian(bytes.as_slice()); - u -} - -/// Generates the solidity code for the verification contract starting from the yul code (yul_code_path) and writes it to sol_code_path -pub fn write_verifier_sol_from_yul( - yul_code_path: &str, - sol_code_path: &str, -) -> Result<(), Box> { - let output = fix_verifier_sol(PathBuf::from(yul_code_path))?; - - let mut f = File::create(sol_code_path)?; - f.write_all(output.as_bytes())?; - - Ok(()) -} - -/// Compiles the verification protcol and returns the cost estimate -/// num_instance indicates the number of values in the instance column of the circuit. If there are more than one instance column, num_instance is equal to the sum of the number of values in each instance column. -/// num_commitment is equal to the number of witness polynomials + the number of chunks of the quotient polynomial -/// num_evaluation is equal to number of evaluations points of the polynomials that are part of the transcript -/// num_msm indicates the number of msm operations that are part of the protocol -/// num_pairing indicates the number of pairing operations that are part of the protocol -pub fn get_verification_cost + CircuitExt>( - params: &ParamsKZG, - pk: &ProvingKey, - circuit: C, -) { - let protocol = compile( - params, - pk.get_vk(), - Config::kzg().with_num_instance(circuit.num_instance()), - ); - - let cost = PlonkSuccinctVerifier::>::estimate_cost(&protocol); - dbg!(cost); -} diff --git a/zk_prover/src/lib.rs b/zk_prover/src/lib.rs deleted file mode 100644 index 378c8434..00000000 --- a/zk_prover/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! This crate contains the cryptogarphic primitives for implementing proof of solvency protocol. -//! The tooling being used to generate the zkSNARKs is [Halo2 PSE Fork](https://github.com/privacy-scaling-explorations/halo2). - -#![feature(generic_const_exprs)] - -/// Zk circuit subcomponents aka chips. -pub mod chips; -/// Zk circuits with a full prover and verifier. A circuit can be viewed as an assembly of chips. -pub mod circuits; -/// Utilities to build the merkle sum tree data structure. No zk proof in here. -pub mod merkle_sum_tree; \ No newline at end of file diff --git a/zk_prover/src/merkle_sum_tree/entry.rs b/zk_prover/src/merkle_sum_tree/entry.rs deleted file mode 100644 index 9f4d886b..00000000 --- a/zk_prover/src/merkle_sum_tree/entry.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::merkle_sum_tree::utils::big_intify_username; -use crate::merkle_sum_tree::Node; -use num_bigint::BigUint; - -/// An entry in the Merkle Sum Tree from the database of the CEX. -/// It contains the username and the balances of the user. -#[derive(Clone, Debug)] -pub struct Entry { - username_as_big_uint: BigUint, - balances: [BigUint; N_CURRENCIES], - username: String, -} - -impl Entry { - pub fn new(username: String, balances: [BigUint; N_CURRENCIES]) -> Result { - Ok(Entry { - username_as_big_uint: big_intify_username(&username), - balances, - username, - }) - } - - pub fn init_empty() -> Self { - let empty_balances: [BigUint; N_CURRENCIES] = std::array::from_fn(|_| BigUint::from(0u32)); - - Entry { - username_as_big_uint: BigUint::from(0u32), - balances: empty_balances, - username: "".to_string(), - } - } - - pub fn compute_leaf(&self) -> Node - where - [usize; N_CURRENCIES + 1]: Sized, - { - Node::leaf(&self.username_as_big_uint, &self.balances) - } - - /// Stores the new balance values - /// - /// Returns the updated node - pub fn recompute_leaf(&mut self, updated_balances: &[BigUint; N_CURRENCIES]) -> Node - where - [usize; N_CURRENCIES + 1]: Sized, - { - self.balances = updated_balances.clone(); - Node::leaf(&self.username_as_big_uint, updated_balances) - } - - pub fn balances(&self) -> &[BigUint; N_CURRENCIES] { - &self.balances - } - - pub fn username_as_big_uint(&self) -> &BigUint { - &self.username_as_big_uint - } - - pub fn username(&self) -> &str { - &self.username - } -} diff --git a/zk_prover/src/merkle_sum_tree/mod.rs b/zk_prover/src/merkle_sum_tree/mod.rs deleted file mode 100644 index c8f7f731..00000000 --- a/zk_prover/src/merkle_sum_tree/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -mod entry; -mod mst; -mod node; -mod tests; -mod tree; -pub mod utils; -use halo2_proofs::halo2curves::bn256::Fr as Fp; - -/// A struct representing a Merkle Proof. -/// -/// Fields: -/// * `entry`: The entry for which the proof is generated -/// * `root`: The root of the Merkle Sum Tree -/// * `sibling_leaf_node_hash_preimage`: The hash preimage of the sibling leaf node. The hash preimage is equal to `[sibling_username, sibling.balance[0], sibling.balance[1], ... sibling.balance[N_CURRENCIES - 1]]` -/// * `sibling_middle_node_hash_preimages`: The hash preimages of the sibling middle nodes. The hash preimage is equal to `[sibling_left_child.balance[0] + sibling_right_child.balance[0], sibling_left_child.balance[1] + sibling_right_child.balance[1], ..., sibling_left_child.balance[N_CURRENCIES - 1] + sibling_right_child.balance[N_CURRENCIES - 1], sibling_left_child.hash, sibling_right_child.hash]` -#[derive(Clone, Debug)] -pub struct MerkleProof -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - pub entry: Entry, - pub root: Node, - pub sibling_leaf_node_hash_preimage: [Fp; N_CURRENCIES + 1], - pub sibling_middle_node_hash_preimages: Vec<[Fp; N_CURRENCIES + 2]>, - pub path_indices: Vec, -} - -pub use entry::Entry; -pub use mst::Cryptocurrency; -pub use mst::MerkleSumTree; -pub use node::Node; -pub use tree::Tree; diff --git a/zk_prover/src/merkle_sum_tree/mst.rs b/zk_prover/src/merkle_sum_tree/mst.rs deleted file mode 100644 index c9c25058..00000000 --- a/zk_prover/src/merkle_sum_tree/mst.rs +++ /dev/null @@ -1,193 +0,0 @@ -use crate::merkle_sum_tree::utils::{ - build_leaves_from_entries, build_merkle_tree_from_leaves, parse_csv_to_entries, -}; -use crate::merkle_sum_tree::{Entry, Node, Tree}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use num_bigint::BigUint; - -/// Merkle Sum Tree Data Structure. -/// -/// A Merkle Sum Tree is a binary Merkle Tree with the following properties: -/// * Each Entry of a Merkle Sum Tree is a pair of a username and #N_CURRENCIES balances. -/// * Each Leaf Node contains a hash and #N_CURRENCIES balances. The hash is equal to `H(username, balance[0], balance[1], ... balance[N_CURRENCIES - 1])`. The balances are equal to the balances associated to the entry -/// * Each Middle Node contains a hash and #N_CURRENCIES balances. The hash is equal to `H(LeftChild.balance[0] + RightChild.balance[0], LeftChild.balance[1] + RightChild.balance[1], ..., LeftChild.balance[N_CURRENCIES - 1] + RightChild.balance[N_CURRENCIES - 1], LeftChild.hash, RightChild.hash)`. The balances are equal to the sum of the balances of the child nodes per each cryptocurrency. -/// * The Root Node represents the committed state of the Tree and contains the sum of all the entries' balances per each cryptocurrency. -/// -/// # Type Parameters -/// -/// * `N_CURRENCIES`: The number of cryptocurrencies for each user account -/// * `N_BYTES`: Range in which each node balance should lie -#[derive(Debug, Clone)] -pub struct MerkleSumTree { - root: Node, - nodes: Vec>>, - depth: usize, - entries: Vec>, - cryptocurrencies: Vec, - is_sorted: bool, -} - -impl Tree - for MerkleSumTree -{ - fn root(&self) -> &Node { - &self.root - } - - fn depth(&self) -> &usize { - &self.depth - } - - fn leaves(&self) -> &[Node] { - &self.nodes[0] - } - - fn nodes(&self) -> &[Vec>] { - &self.nodes - } - - fn get_entry(&self, index: usize) -> &Entry { - &self.entries[index] - } - - fn entries(&self) -> &[Entry] { - &self.entries - } - fn cryptocurrencies(&self) -> &[Cryptocurrency] { - &self.cryptocurrencies - } -} - -#[derive(Debug, Clone)] -pub struct Cryptocurrency { - pub name: String, - pub chain: String, -} - -impl MerkleSumTree { - /// Builds a Merkle Sum Tree from a CSV file stored at `path`. The CSV file must be formatted as follows: - /// - /// `username,balance__,balance__,...` - /// - /// `dxGaEAii,11888,41163` - pub fn new(path: &str) -> Result> - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - let (cryptocurrencies, entries) = parse_csv_to_entries::<&str, N_CURRENCIES, N_BYTES>(path)?; - Self::from_entries(entries, cryptocurrencies, false) - } - - /// Builds a Merkle Sum Tree from a CSV file stored at `path`. The MST leaves are sorted by the username byte values. The CSV file must be formatted as follows: - /// - /// `username,balance__,balance__,...` - /// - /// `dxGaEAii,11888,41163` - pub fn new_sorted(path: &str) -> Result> - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - let (cryptocurrencies, mut entries) = - parse_csv_to_entries::<&str, N_CURRENCIES, N_BYTES>(path)?; - - entries.sort_by(|a, b| a.username().cmp(b.username())); - - Self::from_entries(entries, cryptocurrencies, true) - } - - pub fn from_entries( - entries: Vec>, - cryptocurrencies: Vec, - is_sorted: bool, - ) -> Result, Box> - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - let depth = (entries.len() as f64).log2().ceil() as usize; - - let mut nodes = vec![]; - - let leaves = build_leaves_from_entries(&entries); - - let root = build_merkle_tree_from_leaves(&leaves, depth, &mut nodes)?; - - Ok(MerkleSumTree { - root, - nodes, - depth, - entries, - cryptocurrencies, - is_sorted, - }) - } - - /// Updates the balances of the entry with the given username and returns the new root of the tree. - /// - /// # Arguments - /// - /// * `username`: The username of the entry to update - /// * `new_balances`: The new balances of the entry - /// - /// # Returns - /// - /// The new root of the tree - pub fn update_leaf( - &mut self, - username: &str, - new_balances: &[BigUint; N_CURRENCIES], - ) -> Result, Box> - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - let index = self.index_of_username(username)?; - - // Update the leaf node. - let updated_leaf = self.entries[index].recompute_leaf(new_balances); - self.nodes[0][index] = updated_leaf; - - // Recompute the hashes and balances up the tree. - let mut current_index = index; - for depth in 1..=self.depth { - let parent_index = current_index / 2; - let left_child = &self.nodes[depth - 1][2 * parent_index]; - let right_child = &self.nodes[depth - 1][2 * parent_index + 1]; - - let mut hash_preimage = [Fp::zero(); N_CURRENCIES + 2]; - for (i, balance) in hash_preimage.iter_mut().enumerate().take(N_CURRENCIES) { - *balance = left_child.balances[i] + right_child.balances[i]; - } - hash_preimage[N_CURRENCIES] = left_child.hash; - hash_preimage[N_CURRENCIES + 1] = right_child.hash; - - self.nodes[depth][parent_index] = Node::middle_node_from_preimage(&hash_preimage); - current_index = parent_index; - } - - let root = self.nodes[self.depth][0].clone(); - - Ok(root) - } - - /// Returns the index of the leaf with the matching username - pub fn index_of_username(&self, username: &str) -> Result> - where - [usize; N_CURRENCIES + 1]: Sized, - { - if !self.is_sorted { - self.entries - .iter() - .enumerate() - .find(|(_, entry)| entry.username() == username) - .map(|(index, _)| index) - .ok_or_else(|| Box::from("Username not found")) - } else { - self.entries - .binary_search_by_key(&username, |entry| entry.username()) - .map_err(|_| Box::from("Username not found")) - } - } -} diff --git a/zk_prover/src/merkle_sum_tree/node.rs b/zk_prover/src/merkle_sum_tree/node.rs deleted file mode 100644 index 5e115bd3..00000000 --- a/zk_prover/src/merkle_sum_tree/node.rs +++ /dev/null @@ -1,112 +0,0 @@ -use crate::chips::poseidon::poseidon_spec::PoseidonSpec; -use crate::merkle_sum_tree::utils::big_uint_to_fp; -use halo2_gadgets::poseidon::primitives::{self as poseidon, ConstantLength}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use num_bigint::BigUint; - -#[derive(Clone, Debug)] -pub struct Node { - pub hash: Fp, - pub balances: [Fp; N_CURRENCIES], -} -impl Node { - /// Builds a leaf-level node of the MST - /// The leaf node hash is equal to `H(username, balance[0], balance[1], ... balance[N_CURRENCIES - 1])` - /// The balances are equal to `balance[0], balance[1], ... balance[N_CURRENCIES - 1]` - pub fn leaf(username: &BigUint, balances: &[BigUint; N_CURRENCIES]) -> Node - where - [usize; N_CURRENCIES + 1]: Sized, - { - let mut hash_preimage = [Fp::zero(); N_CURRENCIES + 1]; - hash_preimage[0] = big_uint_to_fp(username); - for (i, balance) in hash_preimage.iter_mut().enumerate().skip(1) { - *balance = big_uint_to_fp(&balances[i - 1]); - } - - Node::leaf_node_from_preimage(&hash_preimage) - } - /// Builds a "middle" (non-leaf-level) node of the MST - /// The middle node hash is equal to `H(LeftChild.balance[0] + RightChild.balance[0], LeftChild.balance[1] + RightChild.balance[1], ..., LeftChild.balance[N_CURRENCIES - 1] + RightChild.balance[N_CURRENCIES - 1], LeftChild.hash, RightChild.hash)` - /// The balances are equal to `LeftChild.balance[0] + RightChild.balance[0], LeftChild.balance[1] + RightChild.balance[1], ..., LeftChild.balance[N_CURRENCIES - 1] + RightChild.balance[N_CURRENCIES - 1]` - pub fn middle(child_l: &Node, child_r: &Node) -> Node - where - [(); N_CURRENCIES + 2]: Sized, - { - let mut hash_preimage = [Fp::zero(); N_CURRENCIES + 2]; - for (i, balance) in hash_preimage.iter_mut().enumerate().take(N_CURRENCIES) { - *balance = child_l.balances[i] + child_r.balances[i]; - } - hash_preimage[N_CURRENCIES] = child_l.hash; - hash_preimage[N_CURRENCIES + 1] = child_r.hash; - - Node::middle_node_from_preimage(&hash_preimage) - } - - pub fn init_empty() -> Node - where - [usize; N_CURRENCIES + 1]: Sized, - { - Node { - hash: Fp::zero(), - balances: [Fp::zero(); N_CURRENCIES], - } - } - - pub fn leaf_node_from_preimage(preimage: &[Fp; N_CURRENCIES + 1]) -> Node - where - [usize; N_CURRENCIES + 1]: Sized, - { - Node { - hash: Self::poseidon_hash_leaf(preimage[0], preimage[1..].try_into().unwrap()), - balances: preimage[1..].try_into().unwrap(), - } - } - - /// Builds a middle-level node of the MST - /// The hash preimage must be equal to `LeftChild.balance[0] + RightChild.balance[0], LeftChild.balance[1] + RightChild.balance[1], ..., LeftChild.balance[N_CURRENCIES - 1] + RightChild.balance[N_CURRENCIES - 1], LeftChild.hash, RightChild.hash` - /// The balances are equal to `LeftChild.balance[0] + RightChild.balance[0], LeftChild.balance[1] + RightChild.balance[1], ..., LeftChild.balance[N_CURRENCIES - 1] + RightChild.balance[N_CURRENCIES - 1]` - pub fn middle_node_from_preimage(preimage: &[Fp; N_CURRENCIES + 2]) -> Node - where - [usize; N_CURRENCIES + 2]: Sized, - { - Node { - hash: Self::poseidon_hash_middle( - preimage[0..N_CURRENCIES].try_into().unwrap(), - preimage[N_CURRENCIES], - preimage[N_CURRENCIES + 1], - ), - balances: preimage[0..N_CURRENCIES].try_into().unwrap(), - } - } - - fn poseidon_hash_middle( - balances_sum: [Fp; N_CURRENCIES], - hash_child_left: Fp, - hash_child_right: Fp, - ) -> Fp - where - [usize; N_CURRENCIES + 2]: Sized, - { - let mut hash_inputs: [Fp; N_CURRENCIES + 2] = [Fp::zero(); N_CURRENCIES + 2]; - - hash_inputs[0..N_CURRENCIES].copy_from_slice(&balances_sum); - hash_inputs[N_CURRENCIES] = hash_child_left; - hash_inputs[N_CURRENCIES + 1] = hash_child_right; - - poseidon::Hash::, 2, 1>::init() - .hash(hash_inputs) - } - - fn poseidon_hash_leaf(username: Fp, balances: [Fp; N_CURRENCIES]) -> Fp - where - [usize; N_CURRENCIES + 1]: Sized, - { - let mut hash_inputs: [Fp; N_CURRENCIES + 1] = [Fp::zero(); N_CURRENCIES + 1]; - - hash_inputs[0] = username; - hash_inputs[1..N_CURRENCIES + 1].copy_from_slice(&balances); - - poseidon::Hash::, 2, 1>::init() - .hash(hash_inputs) - } -} diff --git a/zk_prover/src/merkle_sum_tree/tests.rs b/zk_prover/src/merkle_sum_tree/tests.rs deleted file mode 100644 index 4d1f25bd..00000000 --- a/zk_prover/src/merkle_sum_tree/tests.rs +++ /dev/null @@ -1,233 +0,0 @@ -#[cfg(test)] -mod test { - - use crate::merkle_sum_tree::utils::big_uint_to_fp; - use crate::merkle_sum_tree::{Entry, MerkleSumTree, Node, Tree}; - use num_bigint::{BigUint, ToBigUint}; - use rand::Rng as _; - - const N_CURRENCIES: usize = 2; - const N_BYTES: usize = 8; - - #[test] - fn test_mst() { - // create new merkle tree - let merkle_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - // get root - let root = merkle_tree.root(); - - // expect root hash to be different than 0 - assert!(root.hash != 0.into()); - // expect balance to match the sum of all entries - assert!(root.balances == [556862.into(), 556862.into()]); - // expect depth to be 4 - assert!(*merkle_tree.depth() == 4_usize); - - // get proof for entry 0 - let proof = merkle_tree.generate_proof(0).unwrap(); - - // verify proof - assert!(merkle_tree.verify_proof(&proof)); - - // Should generate different root hashes when changing the entry order - let merkle_tree_2 = - MerkleSumTree::::new("../csv/entry_16_switched_order.csv") - .unwrap(); - assert_ne!(root.hash, merkle_tree_2.root().hash); - - // the balance total should be the same - assert_eq!(root.balances, merkle_tree_2.root().balances); - - // should create valid proof for each entry in the tree and verify it - for i in 0..15 { - let proof = merkle_tree.generate_proof(i).unwrap(); - assert!(merkle_tree.verify_proof(&proof)); - } - - // shouldn't create a proof for an entry that doesn't exist in the tree - assert!(merkle_tree.generate_proof(16).is_err()); - - // shouldn't verify a proof with a wrong leaf - let invalid_entry = Entry::new( - "AtwIxZHo".to_string(), - [35479.to_biguint().unwrap(), 35479.to_biguint().unwrap()], - ) - .unwrap(); - let invalid_entry = invalid_entry; - let mut proof_invalid_1 = proof.clone(); - proof_invalid_1.entry = invalid_entry; - assert!(!merkle_tree.verify_proof(&proof_invalid_1)); - - // shouldn't verify a proof with a wrong root hash - let mut proof_invalid_2 = proof.clone(); - proof_invalid_2.root.hash = 0.into(); - assert!(!merkle_tree.verify_proof(&proof_invalid_2)); - } - - #[test] - fn test_update_mst_leaf() { - let merkle_tree_1 = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let root_hash_1 = merkle_tree_1.root().hash; - - //Create the second tree with the 7th entry different from the the first tree - let mut merkle_tree_2 = - MerkleSumTree::::new("../csv/entry_16_modified.csv").unwrap(); - - let root_hash_2 = merkle_tree_2.root().hash; - assert!(root_hash_1 != root_hash_2); - - //Update the 7th leaf of the second tree so all the entries now match the first tree - let new_root = merkle_tree_2 - .update_leaf( - "RkLzkDun", - &[2087.to_biguint().unwrap(), 79731.to_biguint().unwrap()], - ) - .unwrap(); - //The roots should match - assert!(root_hash_1 == new_root.hash); - } - - #[test] - fn test_update_invalid_mst_leaf() { - let mut merkle_tree = - MerkleSumTree::::new_sorted("../csv/entry_16.csv").unwrap(); - - let new_root = merkle_tree.update_leaf( - "non_existing_user", //This username is not present in the tree - &[11888.to_biguint().unwrap(), 41163.to_biguint().unwrap()], - ); - - if let Err(e) = new_root { - assert_eq!(e.to_string(), "Username not found"); - } - } - - #[test] - fn test_sorted_mst() { - let merkle_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let old_root_balances = merkle_tree.root().balances; - let old_root_hash = merkle_tree.root().hash; - - let sorted_merkle_tree = - MerkleSumTree::::new_sorted("../csv/entry_16.csv").unwrap(); - - let new_root_balances = sorted_merkle_tree.root().balances; - let new_root_hash = sorted_merkle_tree.root().hash; - - // The root balances should be the same for sorted and unsorted MST - assert!(old_root_balances == new_root_balances); - // The root hash should not be the same for sorted and unsorted MST - assert!(old_root_hash != new_root_hash); - } - - // Passing a csv file with a single entry that has a balance that is not in the expected range will fail - #[test] - fn test_mst_overflow_1() { - let result = MerkleSumTree::::new("../csv/entry_16_overflow.csv"); - - if let Err(e) = result { - assert_eq!( - e.to_string(), - "Accumulated balance is not in the expected range, proof generation will fail!" - ); - } - } - - #[test] - // Passing a csv file in which the entries have a balance in the range, but while summing it generates a ndoe in which the balance is not in the expected range will fail - fn test_mst_overflow_2() { - let result = MerkleSumTree::::new("../csv/entry_16_overflow_2.csv"); - - if let Err(e) = result { - assert_eq!( - e.to_string(), - "Accumulated balance is not in the expected range, proof generation will fail!" - ); - } - } - - // Passing a csv file with a single entry that has a balance that is the maximum that can fit in the expected range will not fail - #[test] - fn test_mst_no_overflow() { - let result = MerkleSumTree::::new("../csv/entry_16_no_overflow.csv"); - assert!(result.is_ok()); - } - - #[test] - fn test_big_uint_conversion() { - let big_uint = 3.to_biguint().unwrap(); - let fp = big_uint_to_fp(&big_uint); - - assert_eq!(fp, 3.into()); - - let big_int_over_64 = (18446744073709551616_i128).to_biguint().unwrap(); - let fp_2 = big_uint_to_fp(&big_int_over_64); - - let big_int_to_bytes = { - let mut bytes = BigUint::to_bytes_le(&big_int_over_64); - bytes.resize(32, 0); - bytes - }; - - assert_eq!(fp_2.to_bytes().to_vec(), big_int_to_bytes); - - let fp_3 = fp_2 - fp; - assert_eq!(fp_3, 18446744073709551613.into()); - } - - #[test] - fn get_middle_node_hash_preimage() { - let merkle_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - let depth = *merkle_tree.depth(); - - // The tree has 16 leaves, so the levels are 0, 1, 2, 3, 4. Where level 0 is the leaves and level 4 is the root - // Fetch a random level from 1 to depth - let mut rng = rand::thread_rng(); - let level = rng.gen_range(1..depth); - - // Fetch a random index inside the level. For example level 1 has 8 nodes, so the index can be 0, 1, 2, 3, 4, 5, 6, 7 - let index = rng.gen_range(0..merkle_tree.nodes()[level].len()); - - // Fetch middle node with index from level - let middle_node = merkle_tree.nodes()[level][index].clone(); - - // Fetch the hash preimage of the middle node - let hash_preimage = merkle_tree - .get_middle_node_hash_preimage(level, index) - .unwrap(); - - let computed_middle_node = Node::::middle_node_from_preimage(&hash_preimage); - - // The hash of the middle node should match the hash computed from the hash preimage - assert_eq!(middle_node.hash, computed_middle_node.hash); - } - - #[test] - fn get_leaf_node_hash_preimage() { - let merkle_tree = - MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); - - // Generate a random number between 0 and 15 - let mut rng = rand::thread_rng(); - let index = rng.gen_range(0..16); - - // Fetch leaf with index - let leaf = merkle_tree.leaves()[index].clone(); - - // Fetch the hash preimage of the leaf - let hash_preimage = merkle_tree.get_leaf_node_hash_preimage(index).unwrap(); - - let computed_leaf = Node::::leaf_node_from_preimage(&hash_preimage); - - // The hash of the leaf should match the hash computed from the hash preimage - assert_eq!(leaf.hash, computed_leaf.hash); - } -} diff --git a/zk_prover/src/merkle_sum_tree/tree.rs b/zk_prover/src/merkle_sum_tree/tree.rs deleted file mode 100644 index d100e67f..00000000 --- a/zk_prover/src/merkle_sum_tree/tree.rs +++ /dev/null @@ -1,193 +0,0 @@ -use crate::merkle_sum_tree::utils::big_uint_to_fp; -use crate::merkle_sum_tree::Cryptocurrency; -use crate::merkle_sum_tree::{Entry, MerkleProof, Node}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; - -/// A trait representing the basic operations for a Merkle-Sum-like Tree. -pub trait Tree { - /// Returns a reference to the root node. - fn root(&self) -> &Node; - - /// Returns the depth of the tree. - fn depth(&self) -> &usize; - - /// Returns a slice of the leaf nodes. - fn leaves(&self) -> &[Node]; - - /// Returns a slice of the nodes. - fn nodes(&self) -> &[Vec>]; - - /// Returns the cryptocurrencies whose balances are in the tree. The order of cryptocurrencies and balances is supposed to agree for all the entries. - fn cryptocurrencies(&self) -> &[Cryptocurrency]; - - fn get_entry(&self, index: usize) -> &Entry; - - fn entries(&self) -> &[Entry]; - - /// Returns the hash preimage of a middle node. - fn get_middle_node_hash_preimage( - &self, - level: usize, - index: usize, - ) -> Result<[Fp; N_CURRENCIES + 2], Box> - where - [usize; N_CURRENCIES + 2]: Sized, - { - if level == 0 || level > *self.depth() { - return Err(Box::from("Invalid depth")); - } - - self.nodes() - .get(level) - .and_then(|layer| layer.get(index)) - .ok_or_else(|| Box::::from("Node not found"))?; - - // Assuming the left and right children are stored in order - let left_child = &self.nodes()[level - 1][2 * index]; - let right_child = &self.nodes()[level - 1][2 * index + 1]; - - // Constructing preimage - let mut preimage = [Fp::zero(); N_CURRENCIES + 2]; - - // for each balance in the left and right child, add them together and store in preimage - for (i, balance) in preimage.iter_mut().enumerate().take(N_CURRENCIES) { - *balance = left_child.balances[i] + right_child.balances[i]; - } - - // Add left and right child hashes to preimage - preimage[N_CURRENCIES] = left_child.hash; - preimage[N_CURRENCIES + 1] = right_child.hash; - - Ok(preimage) - } - - /// Returns the hash preimage of a leaf node. - fn get_leaf_node_hash_preimage( - &self, - index: usize, - ) -> Result<[Fp; N_CURRENCIES + 1], Box> - where - [usize; N_CURRENCIES + 1]: Sized, - { - // Fetch entry corresponding to index - let entry = self - .entries() - .get(index) - .ok_or_else(|| Box::::from("Node not found"))?; - - // Constructing preimage - let mut preimage = [Fp::zero(); N_CURRENCIES + 1]; - - // Add username to preimage - preimage[0] = big_uint_to_fp(entry.username_as_big_uint()); - - // Add balances to preimage - for (i, balance) in preimage.iter_mut().enumerate().skip(1).take(N_CURRENCIES) { - *balance = big_uint_to_fp(&entry.balances()[i - 1]); - } - - Ok(preimage) - } - - /// Generates a MerkleProof for the user with the given index. - fn generate_proof( - &self, - index: usize, - ) -> Result, Box> - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - let nodes = self.nodes(); - let depth = *self.depth(); - let root = self.root(); - - if index >= nodes[0].len() { - return Err(Box::from("Index out of bounds")); - } - - let mut sibling_middle_node_hash_preimages = Vec::with_capacity(depth - 1); - - let sibling_leaf_index = if index % 2 == 0 { index + 1 } else { index - 1 }; - - let sibling_leaf_node_hash_preimage: [Fp; N_CURRENCIES + 1] = - self.get_leaf_node_hash_preimage(sibling_leaf_index)?; - let mut path_indices = vec![Fp::zero(); depth]; - let mut current_index = index; - - for level in 0..depth { - let position = current_index % 2; - let sibling_index = current_index - position + (1 - position); - - if sibling_index < nodes[level].len() && level != 0 { - // Fetch hash preimage for sibling middle nodes - let sibling_node_preimage = - self.get_middle_node_hash_preimage(level, sibling_index)?; - sibling_middle_node_hash_preimages.push(sibling_node_preimage); - } - - path_indices[level] = Fp::from(position as u64); - current_index /= 2; - } - - let entry = self.get_entry(index).clone(); - - Ok(MerkleProof { - entry, - root: root.clone(), - sibling_leaf_node_hash_preimage, - sibling_middle_node_hash_preimages, - path_indices, - }) - } - - /// Verifies a MerkleProof. - fn verify_proof(&self, proof: &MerkleProof) -> bool - where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, - { - let mut node = proof.entry.compute_leaf(); - - let sibling_leaf_node = - Node::::leaf_node_from_preimage(&proof.sibling_leaf_node_hash_preimage); - - let mut hash_preimage = [Fp::zero(); N_CURRENCIES + 2]; - for (i, balance) in hash_preimage.iter_mut().enumerate().take(N_CURRENCIES) { - *balance = node.balances[i] + sibling_leaf_node.balances[i]; - } - - if proof.path_indices[0] == 0.into() { - hash_preimage[N_CURRENCIES] = node.hash; - hash_preimage[N_CURRENCIES + 1] = sibling_leaf_node.hash; - node = Node::middle_node_from_preimage(&hash_preimage); - } else { - hash_preimage[N_CURRENCIES] = sibling_leaf_node.hash; - hash_preimage[N_CURRENCIES + 1] = node.hash; - node = Node::middle_node_from_preimage(&hash_preimage); - } - - for i in 1..proof.path_indices.len() { - let sibling_node = Node::::middle_node_from_preimage( - &proof.sibling_middle_node_hash_preimages[i - 1], - ); - - let mut hash_preimage = [Fp::zero(); N_CURRENCIES + 2]; - for (i, balance) in hash_preimage.iter_mut().enumerate().take(N_CURRENCIES) { - *balance = node.balances[i] + sibling_node.balances[i]; - } - - if proof.path_indices[i] == 0.into() { - hash_preimage[N_CURRENCIES] = node.hash; - hash_preimage[N_CURRENCIES + 1] = sibling_node.hash; - node = Node::middle_node_from_preimage(&hash_preimage); - } else { - hash_preimage[N_CURRENCIES] = sibling_node.hash; - hash_preimage[N_CURRENCIES + 1] = node.hash; - node = Node::middle_node_from_preimage(&hash_preimage); - } - } - - proof.root.hash == node.hash && proof.root.balances == node.balances - } -} diff --git a/zk_prover/src/merkle_sum_tree/utils/build_tree.rs b/zk_prover/src/merkle_sum_tree/utils/build_tree.rs deleted file mode 100644 index 596fb3ca..00000000 --- a/zk_prover/src/merkle_sum_tree/utils/build_tree.rs +++ /dev/null @@ -1,90 +0,0 @@ -use crate::merkle_sum_tree::{Entry, Node}; -use halo2_proofs::halo2curves::bn256::Fr as Fp; -use rayon::prelude::*; - -pub fn build_merkle_tree_from_leaves( - leaves: &[Node], - depth: usize, - nodes: &mut Vec>>, -) -> Result, Box> -where - [usize; N_CURRENCIES + 1]: Sized, - [usize; N_CURRENCIES + 2]: Sized, -{ - let n = leaves.len(); - - let mut tree: Vec>> = Vec::with_capacity(depth + 1); - - tree.push(vec![ - Node { - hash: Fp::from(0), - balances: [Fp::from(0); N_CURRENCIES] - }; - n - ]); - - for _ in 1..=depth { - let previous_level = tree.last().unwrap(); - let nodes_in_level = (previous_level.len() + 1) / 2; - - tree.push(vec![ - Node { - hash: Fp::from(0), - balances: [Fp::from(0); N_CURRENCIES] - }; - nodes_in_level - ]); - } - - for (index, leaf) in leaves.iter().enumerate() { - tree[0][index] = leaf.clone(); - } - - for level in 1..=depth { - build_middle_level(level, &mut tree) - } - - let root = tree[depth][0].clone(); - *nodes = tree; - Ok(root) -} - -pub fn build_leaves_from_entries( - entries: &[Entry], -) -> Vec> -where - [usize; N_CURRENCIES + 1]: Sized, -{ - let leaves = entries - .par_iter() - .map(|entry| entry.compute_leaf()) - .collect::>(); - - leaves -} - -fn build_middle_level(level: usize, tree: &mut [Vec>]) -where - [usize; N_CURRENCIES + 2]: Sized, -{ - let results: Vec> = (0..tree[level - 1].len()) - .into_par_iter() - .step_by(2) - .map(|index| { - let mut hash_preimage = [Fp::zero(); N_CURRENCIES + 2]; - - for (i, balance) in hash_preimage.iter_mut().enumerate().take(N_CURRENCIES) { - *balance = - tree[level - 1][index].balances[i] + tree[level - 1][index + 1].balances[i]; - } - - hash_preimage[N_CURRENCIES] = tree[level - 1][index].hash; - hash_preimage[N_CURRENCIES + 1] = tree[level - 1][index + 1].hash; - Node::middle_node_from_preimage(&hash_preimage) - }) - .collect(); - - for (index, new_node) in results.into_iter().enumerate() { - tree[level][index] = new_node; - } -} diff --git a/zk_prover/src/merkle_sum_tree/utils/csv_parser.rs b/zk_prover/src/merkle_sum_tree/utils/csv_parser.rs deleted file mode 100644 index fc089eb6..00000000 --- a/zk_prover/src/merkle_sum_tree/utils/csv_parser.rs +++ /dev/null @@ -1,75 +0,0 @@ -use crate::merkle_sum_tree::{Cryptocurrency, Entry}; -use num_bigint::BigUint; -use std::collections::HashMap; -use std::error::Error; -use std::fs::File; -use std::path::Path; - -pub fn parse_csv_to_entries, const N_CURRENCIES: usize, const N_BYTES: usize>( - path: P, -) -> Result<(Vec, Vec>), Box> { - let file = File::open(path)?; - let mut rdr = csv::ReaderBuilder::new().from_reader(file); - - let headers = rdr.headers()?.clone(); - let mut cryptocurrencies: Vec = Vec::with_capacity(N_CURRENCIES); - - // Extracting cryptocurrency names from column names - for header in headers.iter().skip(1) { - // Skipping 'username' column - let parts: Vec<&str> = header.split('_').collect(); - if parts.len() == 3 && parts[0] == "balance" { - cryptocurrencies.push(Cryptocurrency { - name: parts[1].to_owned(), - chain: parts[2].to_owned(), - }); - } else { - // Throw an error if the header is malformed - return Err(format!("Invalid header: {}", header).into()); - } - } - - let mut entries = Vec::new(); - let mut balances_acc: Vec = vec![BigUint::from(0_usize); N_CURRENCIES]; - - for result in rdr.deserialize() { - let record: HashMap = result?; - let username = record.get("username").ok_or("Username not found")?.clone(); - - let mut balances_big_int = Vec::new(); - for cryptocurrency in &cryptocurrencies { - let balance_str = record - .get(format!("balance_{}_{}", cryptocurrency.name, cryptocurrency.chain).as_str()) - .ok_or(format!( - "Balance for {} on {} not found", - cryptocurrency.name, cryptocurrency.chain - ))?; - let balance = BigUint::parse_bytes(balance_str.as_bytes(), 10).ok_or(format!( - "Invalid balance for {} on {}", - cryptocurrency.name, cryptocurrency.chain - ))?; - balances_big_int.push(balance); - } - - balances_acc = balances_acc - .iter() - .zip(balances_big_int.iter()) - .map(|(x, y)| x + y) - .collect(); - - let entry = Entry::new(username, balances_big_int.try_into().unwrap())?; - entries.push(entry); - } - - // Iterate through the balance accumulator and throw error if any balance is not in range 0, 2 ^ (8 * N_BYTES): - for balance in balances_acc { - if balance >= BigUint::from(2_usize).pow(8 * N_BYTES as u32) { - return Err( - "Accumulated balance is not in the expected range, proof generation will fail!" - .into(), - ); - } - } - - Ok((cryptocurrencies, entries)) -} diff --git a/zk_prover/src/merkle_sum_tree/utils/mod.rs b/zk_prover/src/merkle_sum_tree/utils/mod.rs deleted file mode 100644 index c4f0a33e..00000000 --- a/zk_prover/src/merkle_sum_tree/utils/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod build_tree; -mod csv_parser; -mod operation_helpers; - -pub use build_tree::{build_leaves_from_entries, build_merkle_tree_from_leaves}; -pub use csv_parser::parse_csv_to_entries; -pub use operation_helpers::*; diff --git a/zk_prover/src/merkle_sum_tree/utils/operation_helpers.rs b/zk_prover/src/merkle_sum_tree/utils/operation_helpers.rs deleted file mode 100644 index 81704c63..00000000 --- a/zk_prover/src/merkle_sum_tree/utils/operation_helpers.rs +++ /dev/null @@ -1,17 +0,0 @@ -use halo2_proofs::halo2curves::{bn256::Fr as Fp, group::ff::PrimeField}; -use num_bigint::BigUint; - -/// Return a BigUint representation of the username -pub fn big_intify_username(username: &str) -> BigUint { - let utf8_bytes = username.as_bytes(); - BigUint::from_bytes_be(utf8_bytes) -} -/// Converts a BigUint to a Field Element -pub fn big_uint_to_fp(big_uint: &BigUint) -> Fp { - Fp::from_str_vartime(&big_uint.to_str_radix(10)[..]).unwrap() -} - -/// Converts a Field element to a BigUint -pub fn fp_to_big_uint(f: Fp) -> BigUint { - BigUint::from_bytes_le(f.to_bytes().as_slice()) -}