diff --git a/.dvc/.gitignore b/.dvc/.gitignore deleted file mode 100644 index 528f30c71..000000000 --- a/.dvc/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/config.local -/tmp -/cache diff --git a/.dvc/config b/.dvc/config deleted file mode 100644 index 516646fc2..000000000 --- a/.dvc/config +++ /dev/null @@ -1,4 +0,0 @@ -[core] - remote = origin -['remote "origin"'] - url = https://github.com/webb-tools/substrate-fixtures diff --git a/.dvcignore b/.dvcignore deleted file mode 100644 index 519730552..000000000 --- a/.dvcignore +++ /dev/null @@ -1,3 +0,0 @@ -# Add patterns of files dvc should ignore, which could improve -# the performance. Learn more at -# https://dvc.org/doc/user-guide/dvcignore diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index f8f16501f..6bf949fde 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -32,7 +32,7 @@ jobs: uses: iterative/setup-dvc@v1 - name: Fetch Fixtures - run: dvc pull + run: ./scripts/fetch-fixtures.sh - name: Install toolchain uses: dtolnay/rust-toolchain@stable diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index abe4b3769..1d72003c3 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -33,7 +33,7 @@ jobs: uses: iterative/setup-dvc@v1 - name: Fetch Fixtures - run: dvc pull + run: ./scripts/fetch-fixtures.sh - name: Install apt dependencies run: | diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 3a41c0ec4..bd7e496ce 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -29,7 +29,7 @@ jobs: uses: iterative/setup-dvc@v1 - name: Fetch Fixtures - run: dvc pull + run: ./scripts/fetch-fixtures.sh - name: Cache Cargo uses: actions/cache@v2 diff --git a/.gitignore b/.gitignore index 6cb74e7bf..a0c9a94b8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,12 +13,14 @@ .local #vscode files +.vscode/ .vscode/launch.json .idea/ *.iml /substrate-fixtures +/solidity-fixtures **/node_modules types/build types/ts-types \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 7bd409da7..7f2078f9e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,8 @@ -[submodule "protocol-substrate-fixtures"] - path = protocol-substrate-fixtures - url = https://github.com/webb-tools/protocol-substrate-fixtures +[submodule "substrate-fixtures"] + path = substrate-fixtures + url = https://github.com/webb-tools/substrate-fixtures + +[submodule "solidity-fixtures"] + path = solidity-fixtures + url = https://github.com/webb-tools/solidity-fixtures + diff --git a/Cargo.lock b/Cargo.lock index 8c4d4e034..19b39a345 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" dependencies = [ - "gimli 0.27.0", + "gimli 0.27.2", ] [[package]] @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" +checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800" [[package]] name = "approx" @@ -146,6 +146,59 @@ dependencies = [ "ark-std", ] +[[package]] +name = "ark-circom" +version = "0.1.0" +source = "git+https://github.com/gakonst/ark-circom?branch=master#35ce5a909ee09ae8c3101e69cc57785a21ed7f64" +dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-groth16 0.3.0 (git+https://github.com/arkworks-rs/groth16?rev=765817f)", + "ark-poly", + "ark-relations", + "ark-serialize", + "ark-std", + "byteorder", + "cfg-if", + "color-eyre 0.6.2", + "criterion", + "fnv", + "hex", + "num", + "num-bigint", + "num-traits", + "thiserror", + "wasmer", +] + +[[package]] +name = "ark-circom" +version = "0.1.0" +source = "git+https://github.com/vacp2p/ark-circom?branch=wasm#0e587145cb05e08b2d1a01509eb578670088eb2f" +dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-groth16 0.3.0 (git+https://github.com/arkworks-rs/groth16?rev=765817f)", + "ark-poly", + "ark-relations", + "ark-serialize", + "ark-std", + "byteorder", + "cfg-if", + "color-eyre 0.5.11", + "criterion", + "ethers-core", + "fnv", + "hex", + "num", + "num-bigint", + "num-traits", + "thiserror", + "wasmer", +] + [[package]] name = "ark-crypto-primitives" version = "0.3.0" @@ -163,6 +216,7 @@ dependencies = [ "blake2 0.9.2", "derivative", "digest 0.9.0", + "rayon", "tracing", ] @@ -177,6 +231,7 @@ dependencies = [ "ark-std", "derivative", "num-traits", + "rayon", "zeroize", ] @@ -194,6 +249,7 @@ dependencies = [ "num-bigint", "num-traits", "paste", + "rayon", "rustc_version 0.3.3", "zeroize", ] @@ -235,6 +291,21 @@ dependencies = [ "ark-std", ] +[[package]] +name = "ark-groth16" +version = "0.3.0" +source = "git+https://github.com/arkworks-rs/groth16?rev=765817f#765817f77a6e14964c6f264d565b18676b11bd59" +dependencies = [ + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-poly", + "ark-relations", + "ark-serialize", + "ark-std", + "rayon", +] + [[package]] name = "ark-nonnative-field" version = "0.3.0" @@ -264,6 +335,7 @@ dependencies = [ "ark-std", "derivative", "hashbrown 0.11.2", + "rayon", ] [[package]] @@ -291,7 +363,7 @@ dependencies = [ "ark-ff", "ark-std", "tracing", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -335,6 +407,7 @@ checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" dependencies = [ "num-traits", "rand 0.8.5", + "rayon", ] [[package]] @@ -385,7 +458,7 @@ dependencies = [ "ark-crypto-primitives", "ark-ec", "ark-ff", - "ark-groth16", + "ark-groth16 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ark-r1cs-std", "ark-relations", "ark-serialize", @@ -517,9 +590,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" [[package]] name = "async-trait" -version = "0.1.61" +version = "0.1.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705339e0e4a9690e2908d2b3d049d85682cf19fbd5782494498fbf7003a6a282" +checksum = "1cd7fce9ba8c3c042128ce72d8b2ddbf3a05747efb67ea0313c635e10bda47a2" dependencies = [ "proc-macro2", "quote", @@ -541,9 +614,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" [[package]] name = "atty" @@ -556,6 +629,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "auto_impl" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a8c1df849285fbacd587de7818cc7d13be6cd2cbcd47a04fb1801b0e2706e33" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -573,7 +658,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object 0.30.1", + "object 0.30.3", "rustc-demangle", ] @@ -601,11 +686,17 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "base64ct" -version = "1.5.3" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beef" @@ -627,9 +718,9 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.60.1" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ "bitflags", "cexpr", @@ -642,6 +733,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", + "syn", ] [[package]] @@ -684,24 +776,24 @@ dependencies = [ [[package]] name = "blake2b_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72936ee4afc7f8f736d1c38383b56480b5497b4617b4a77bdbf1d2ababc76127" +checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] name = "blake2s_simd" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" +checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" dependencies = [ "arrayref", "arrayvec 0.7.2", - "constant_time_eq 0.1.5", + "constant_time_eq", ] [[package]] @@ -714,7 +806,7 @@ dependencies = [ "arrayvec 0.7.2", "cc", "cfg-if", - "constant_time_eq 0.2.4", + "constant_time_eq", ] [[package]] @@ -785,9 +877,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45ea9b00a7b3f2988e9a65ad3917e62123c38dba709b666506207be96d1790b" +checksum = "5ffdb39cb703212f3c11973452c2861b972f757b021158f3516ba10f2fa8b2c1" dependencies = [ "memchr", "serde", @@ -804,9 +896,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byte-slice-cast" @@ -820,6 +912,27 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" +[[package]] +name = "bytecheck" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d11cac2c12b5adc6570dad2ee1b87eff4955dac476fe12d81e5fdd352e52406f" +dependencies = [ + "bytecheck_derive", + "ptr_meta", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e576ebe98e605500b3c8041bb888e966653577172df6dd97398714eb30b9bf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "byteorder" version = "1.4.3" @@ -828,9 +941,12 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +dependencies = [ + "serde", +] [[package]] name = "bzip2-sys" @@ -845,9 +961,9 @@ dependencies = [ [[package]] name = "camino" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77df041dc383319cc661b428b6961a005db4d6808d5e12536931b1ca9556055" +checksum = "6031a462f977dd38968b6f23378356512feeace69cef817e1a4475108093cec3" dependencies = [ "serde", ] @@ -874,11 +990,17 @@ dependencies = [ "serde_json", ] +[[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.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] @@ -977,9 +1099,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.4.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3" +checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" dependencies = [ "glob", "libc", @@ -988,9 +1110,20 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.32" +version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "bitflags", + "textwrap", + "unicode-width", +] + +[[package]] +name = "clap" +version = "4.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3" dependencies = [ "bitflags", "clap_derive", @@ -1003,9 +1136,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.21" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" dependencies = [ "heck", "proc-macro-error", @@ -1016,9 +1149,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" dependencies = [ "os_str_bytes", ] @@ -1033,6 +1166,60 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color-eyre" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f1885697ee8a177096d42f158922251a41973117f6d8a234cee94b9509157b7" +dependencies = [ + "backtrace", + "color-spantrace 0.1.6", + "eyre", + "indenter", + "once_cell", + "owo-colors 1.3.0", + "tracing-error 0.1.2", +] + +[[package]] +name = "color-eyre" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +dependencies = [ + "backtrace", + "color-spantrace 0.2.0", + "eyre", + "indenter", + "once_cell", + "owo-colors 3.5.0", + "tracing-error 0.2.0", +] + +[[package]] +name = "color-spantrace" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6eee477a4a8a72f4addd4de416eb56d54bc307b284d6601bafdee1f4ea462d1" +dependencies = [ + "once_cell", + "owo-colors 1.3.0", + "tracing-core", + "tracing-error 0.1.2", +] + +[[package]] +name = "color-spantrace" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" +dependencies = [ + "once_cell", + "owo-colors 3.5.0", + "tracing-core", + "tracing-error 0.2.0", +] + [[package]] name = "comfy-table" version = "6.1.4" @@ -1046,24 +1233,18 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" dependencies = [ "crossbeam-utils", ] [[package]] name = "const-oid" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cec318a675afcb6a1ea1d4340e2d377e56e47c266f28043ceccbf4412ddfdd3b" - -[[package]] -name = "constant_time_eq" -version = "0.1.5" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" [[package]] name = "constant_time_eq" @@ -1096,6 +1277,19 @@ dependencies = [ "memchr", ] +[[package]] +name = "corosensei" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9847f90f32a50b0dcbd68bc23ff242798b13080b97b0569f6ed96a45ce4cf2cd" +dependencies = [ + "autocfg", + "cfg-if", + "libc", + "scopeguard", + "windows-sys 0.33.0", +] + [[package]] name = "cpp_demangle" version = "0.3.5" @@ -1114,13 +1308,39 @@ dependencies = [ "libc", ] +[[package]] +name = "cranelift-bforest" +version = "0.82.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38faa2a16616c8e78a18d37b4726b98bfd2de192f2fdc8a39ddf568a408a0f75" +dependencies = [ + "cranelift-entity 0.82.3", +] + [[package]] name = "cranelift-bforest" version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52056f6d0584484b57fa6c1a65c1fcb15f3780d8b6a758426d9e3084169b2ddd" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.88.2", +] + +[[package]] +name = "cranelift-codegen" +version = "0.82.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26f192472a3ba23860afd07d2b0217dc628f21fcc72617aa1336d98e1671f33b" +dependencies = [ + "cranelift-bforest 0.82.3", + "cranelift-codegen-meta 0.82.3", + "cranelift-codegen-shared 0.82.3", + "cranelift-entity 0.82.3", + "gimli 0.26.2", + "log", + "regalloc", + "smallvec", + "target-lexicon", ] [[package]] @@ -1131,10 +1351,10 @@ checksum = "18fed94c8770dc25d01154c3ffa64ed0b3ba9d583736f305fed7beebe5d9cf74" dependencies = [ "arrayvec 0.7.2", "bumpalo", - "cranelift-bforest", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-entity", + "cranelift-bforest 0.88.2", + "cranelift-codegen-meta 0.88.2", + "cranelift-codegen-shared 0.88.2", + "cranelift-entity 0.88.2", "cranelift-isle", "gimli 0.26.2", "log", @@ -1143,21 +1363,42 @@ dependencies = [ "target-lexicon", ] +[[package]] +name = "cranelift-codegen-meta" +version = "0.82.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f32ddb89e9b89d3d9b36a5b7d7ea3261c98235a76ac95ba46826b8ec40b1a24" +dependencies = [ + "cranelift-codegen-shared 0.82.3", +] + [[package]] name = "cranelift-codegen-meta" version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c451b81faf237d11c7e4f3165eeb6bac61112762c5cfe7b4c0fb7241474358f" dependencies = [ - "cranelift-codegen-shared", + "cranelift-codegen-shared 0.88.2", ] +[[package]] +name = "cranelift-codegen-shared" +version = "0.82.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01fd0d9f288cc1b42d9333b7a776b17e278fc888c28e6a0f09b5573d45a150bc" + [[package]] name = "cranelift-codegen-shared" version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c940133198426d26128f08be2b40b0bd117b84771fd36798969c4d712d81fc" +[[package]] +name = "cranelift-entity" +version = "0.82.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e3bfe172b83167604601faf9dc60453e0d0a93415b57a9c4d1a7ae6849185cf" + [[package]] name = "cranelift-entity" version = "0.88.2" @@ -1167,13 +1408,25 @@ dependencies = [ "serde", ] +[[package]] +name = "cranelift-frontend" +version = "0.82.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a006e3e32d80ce0e4ba7f1f9ddf66066d052a8c884a110b91d05404d6ce26dce" +dependencies = [ + "cranelift-codegen 0.82.3", + "log", + "smallvec", + "target-lexicon", +] + [[package]] name = "cranelift-frontend" version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34897538b36b216cc8dd324e73263596d51b8cf610da6498322838b2546baf8a" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.88.2", "log", "smallvec", "target-lexicon", @@ -1191,7 +1444,7 @@ version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20937dab4e14d3e225c5adfc9c7106bafd4ac669bdb43027b911ff794c6fb318" dependencies = [ - "cranelift-codegen", + "cranelift-codegen 0.88.2", "libc", "target-lexicon", ] @@ -1202,13 +1455,13 @@ version = "0.88.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80fc2288957a94fd342a015811479de1837850924166d1f1856d8406e6f3609b" dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", + "cranelift-codegen 0.88.2", + "cranelift-entity 0.88.2", + "cranelift-frontend 0.88.2", "itertools", "log", "smallvec", - "wasmparser", + "wasmparser 0.89.1", "wasmtime-types", ] @@ -1221,6 +1474,42 @@ 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 2.34.0", + "criterion-plot", + "csv", + "itertools", + "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", +] + [[package]] name = "crossbeam-channel" version = "0.5.6" @@ -1312,6 +1601,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "csv" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af91f40b7355f82b0a891f50e70399475945bb0b0da4f1700ce60761c9d3e359" +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.8.0" @@ -1349,9 +1659,9 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-pre.5" +version = "4.0.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67bc65846be335cb20f4e52d49a437b773a2c1fdb42b19fc84e79e6f6771536f" +checksum = "8da00a7a9a4eb92a0a0f8e75660926d48f0d0f3c537e455c457bcdaa1e16b1ac" dependencies = [ "cfg-if", "fiat-crypto", @@ -1363,9 +1673,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.86" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" dependencies = [ "cc", "cxxbridge-flags", @@ -1375,9 +1685,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.86" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" dependencies = [ "cc", "codespan-reporting", @@ -1390,15 +1700,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.86" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" [[package]] name = "cxxbridge-macro" -version = "1.0.86" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" dependencies = [ "proc-macro2", "quote", @@ -1407,9 +1717,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" +checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8" dependencies = [ "darling_core", "darling_macro", @@ -1417,9 +1727,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a784d2ccaf7c98501746bf0be29b2022ba41fd62a2e622af997a03e9f972859f" +checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" dependencies = [ "fnv", "ident_case", @@ -1431,9 +1741,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" +checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ "darling_core", "quote", @@ -1643,9 +1953,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ "signature", ] @@ -1680,9 +1990,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "elliptic-curve" @@ -1715,6 +2025,26 @@ dependencies = [ "syn", ] +[[package]] +name = "enum-iterator" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eeac5c5edb79e4e39fe8439ef35207780a11f69c52cbe424ce3dfad4cb78de6" +dependencies = [ + "enum-iterator-derive", +] + +[[package]] +name = "enum-iterator-derive" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "enumflags2" version = "0.7.5" @@ -1735,6 +2065,27 @@ dependencies = [ "syn", ] +[[package]] +name = "enumset" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19be8061a06ab6f3a6cf21106c873578bf01bd42ad15e0311a9c76161cb1c753" +dependencies = [ + "enumset_derive", +] + +[[package]] +name = "enumset_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e7b551eba279bf0fa88b83a46330168c1560a52a94f5126f892f0b364ab3e0" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "env_logger" version = "0.10.0" @@ -1781,11 +2132,28 @@ version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f76ef192b63e8a44b3d08832acebbb984c3fba154b5c26f70037c860202a0d4b" dependencies = [ - "ethereum-types", + "ethereum-types 0.12.1", "hex", "sha3 0.9.1", ] +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types 0.14.1", + "hex", + "once_cell", + "regex", + "serde", + "serde_json", + "sha3 0.10.6", + "thiserror", + "uint", +] + [[package]] name = "ethbloom" version = "0.11.1" @@ -1797,18 +2165,77 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash 0.8.0", + "impl-codec", + "impl-rlp", + "impl-serde", + "scale-info", + "tiny-keccak", +] + [[package]] name = "ethereum-types" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05136f7057fe789f06e6d41d07b34e6f70d8c86e5693b60f97aaa6553553bdaf" dependencies = [ - "ethbloom", + "ethbloom 0.11.1", "fixed-hash 0.7.0", "primitive-types 0.10.1", "uint", ] +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom 0.13.0", + "fixed-hash 0.8.0", + "impl-codec", + "impl-rlp", + "impl-serde", + "primitive-types 0.12.1", + "scale-info", + "uint", +] + +[[package]] +name = "ethers-core" +version = "1.0.2" +source = "git+https://github.com/gakonst/ethers-rs#620300f3571d427f39a767d7c4218f9ef9352fad" +dependencies = [ + "arrayvec 0.7.2", + "bytes", + "chrono", + "elliptic-curve", + "ethabi 18.0.0", + "generic-array 0.14.6", + "getrandom 0.2.8", + "hex", + "k256", + "num_enum", + "open-fastrlp", + "rand 0.8.5", + "rlp", + "rlp-derive", + "serde", + "serde_json", + "strum", + "tempfile", + "thiserror", + "tiny-keccak", + "unicode-xid", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -1824,6 +2251,16 @@ dependencies = [ "futures", ] +[[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 = "fake-simd" version = "0.1.2" @@ -1838,9 +2275,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" dependencies = [ "instant", ] @@ -1882,14 +2319,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9" +checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -2017,7 +2454,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap", + "clap 4.1.6", "comfy-table", "frame-benchmarking", "frame-support", @@ -2237,12 +2674,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "fs_extra" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" - [[package]] name = "funty" version = "2.0.0" @@ -2251,9 +2682,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", @@ -2266,9 +2697,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", @@ -2276,15 +2707,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" +checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" +checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", @@ -2294,9 +2725,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-lite" @@ -2315,9 +2746,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" +checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", @@ -2337,15 +2768,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" +checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" +checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-timer" @@ -2355,9 +2786,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" +checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-channel", "futures-core", @@ -2458,9 +2889,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.0" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" [[package]] name = "glob" @@ -2511,6 +2942,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "handlebars" version = "4.3.6" @@ -2560,9 +2997,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -2582,6 +3019,12 @@ 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" @@ -2666,9 +3109,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -2712,9 +3155,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.23" +version = "0.14.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" +checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" dependencies = [ "bytes", "futures-channel", @@ -2838,6 +3281,15 @@ 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" @@ -2858,6 +3310,12 @@ dependencies = [ "syn", ] +[[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.2" @@ -2895,12 +3353,12 @@ checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" [[package]] name = "io-lifetimes" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ "libc", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -2929,14 +3387,14 @@ checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "is-terminal" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" dependencies = [ - "hermit-abi 0.2.6", - "io-lifetimes 1.0.3", - "rustix 0.36.6", - "windows-sys 0.42.0", + "hermit-abi 0.3.1", + "io-lifetimes 1.0.5", + "rustix 0.36.8", + "windows-sys 0.45.0", ] [[package]] @@ -2965,9 +3423,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -3129,6 +3587,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "sha2 0.10.6", + "sha3 0.10.6", ] [[package]] @@ -3185,6 +3644,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + [[package]] name = "libc" version = "0.2.139" @@ -3547,9 +4012,9 @@ dependencies = [ [[package]] name = "librocksdb-sys" -version = "0.8.0+7.4.4" +version = "0.8.3+7.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611804e4666a25136fcc5f8cf425ab4d26c7f74ea245ffe92ea23b85b6420b5d" +checksum = "557b255ff04123fcc176162f56ed0c9cd42d8f357cf55b3fabeb60f7413741b3" dependencies = [ "bindgen", "bzip2-sys", @@ -3567,7 +4032,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" dependencies = [ "arrayref", - "base64", + "base64 0.13.1", "digest 0.9.0", "hmac-drbg", "libsecp256k1-core", @@ -3684,6 +4149,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "loupe" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6a72dfa44fe15b5e76b94307eeb2ff995a8c5b283b55008940c02e0c5b634d" +dependencies = [ + "indexmap", + "loupe-derive", + "rustversion", +] + +[[package]] +name = "loupe-derive" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "lru" version = "0.8.1" @@ -3748,9 +4234,9 @@ dependencies = [ [[package]] name = "matches" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "matrixmultiply" @@ -3773,14 +4259,14 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b20a59d985586e4a5aef64564ac77299f8586d8be6cf9106a5a40207e8908efb" dependencies = [ - "rustix 0.36.6", + "rustix 0.36.8", ] [[package]] name = "memmap2" -version = "0.5.8" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" dependencies = [ "libc", ] @@ -3859,14 +4345,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -3896,6 +4382,12 @@ dependencies = [ "syn", ] +[[package]] +name = "more-asserts" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" + [[package]] name = "multiaddr" version = "0.14.0" @@ -3944,9 +4436,9 @@ dependencies = [ [[package]] name = "multihash-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -4042,9 +4534,9 @@ dependencies = [ [[package]] name = "netlink-packet-utils" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25af9cf0dc55498b7bd94a1508af7a78706aa0ab715a73c5169273e03c84845e" +checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" dependencies = [ "anyhow", "byteorder", @@ -4069,9 +4561,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92b654097027250401127914afb37cb1f311df6610a9891ff07a757e94199027" +checksum = "260e21fbb6f3d253a14df90eb0000a6066780a15dd901a7519ce02d77a94985b" dependencies = [ "async-io", "bytes", @@ -4099,9 +4591,9 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "nom" -version = "7.1.2" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5507769c4919c998e69e49c839d9dc6e693ede4cc4290d6ad8b41d4f09c548c" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -4113,6 +4605,20 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "num" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.3" @@ -4122,13 +4628,14 @@ dependencies = [ "autocfg", "num-integer", "num-traits", + "rand 0.8.5", ] [[package]] name = "num-complex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" dependencies = [ "num-traits", ] @@ -4153,6 +4660,17 @@ dependencies = [ "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" @@ -4185,6 +4703,39 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "object" +version = "0.28.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" +dependencies = [ + "crc32fast", + "hashbrown 0.11.2", + "indexmap", + "memchr", +] + [[package]] name = "object" version = "0.29.0" @@ -4199,18 +4750,24 @@ dependencies = [ [[package]] name = "object" -version = "0.30.1" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d864c91689fdc196779b98dba0aceac6118594c2df6ee5d943eb6a8df4d107a" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.17.0" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "oorandom" +version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "opaque-debug" @@ -4224,6 +4781,31 @@ 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.2", + "auto_impl", + "bytes", + "ethereum-types 0.14.1", + "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", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -4233,7 +4815,7 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "orml-currencies" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#4f5a3f34d8cbd98b7bc2e295219a3e7b99b9ecaf" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#db0381f6363e0c8e781082b6f552c092b688fb1c" dependencies = [ "frame-support", "frame-system", @@ -4250,7 +4832,7 @@ dependencies = [ [[package]] name = "orml-tokens" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#4f5a3f34d8cbd98b7bc2e295219a3e7b99b9ecaf" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#db0381f6363e0c8e781082b6f552c092b688fb1c" dependencies = [ "frame-support", "frame-system", @@ -4265,7 +4847,7 @@ dependencies = [ [[package]] name = "orml-traits" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#4f5a3f34d8cbd98b7bc2e295219a3e7b99b9ecaf" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#db0381f6363e0c8e781082b6f552c092b688fb1c" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -4283,7 +4865,7 @@ dependencies = [ [[package]] name = "orml-utilities" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#4f5a3f34d8cbd98b7bc2e295219a3e7b99b9ecaf" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library.git?branch=polkadot-v0.9.36#db0381f6363e0c8e781082b6f552c092b688fb1c" dependencies = [ "frame-support", "parity-scale-codec", @@ -4300,6 +4882,18 @@ version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +[[package]] +name = "owo-colors" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "packed_simd_2" version = "0.3.8" @@ -5311,22 +5905,27 @@ dependencies = [ name = "pallet-vanchor" version = "1.0.0" dependencies = [ - "ark-bls12-381", "ark-bn254", + "ark-circom 0.1.0 (git+https://github.com/vacp2p/ark-circom?branch=wasm)", "ark-crypto-primitives", "ark-ec", "ark-ff", - "ark-groth16", + "ark-groth16 0.3.0 (git+https://github.com/arkworks-rs/groth16?rev=765817f)", "ark-relations", "ark-serialize", "ark-std", "arkworks-native-gadgets", "arkworks-setups", + "cfg-if", + "color-eyre 0.6.2", "frame-benchmarking", "frame-support", "frame-system", "frame-system-benchmarking", - "getrandom 0.2.8", + "hex", + "num-bigint", + "num-traits", + "once_cell", "orml-currencies", "orml-tokens", "orml-traits", @@ -5343,10 +5942,13 @@ dependencies = [ "rand 0.8.5", "scale-info", "serde", + "serde_json", "sp-core 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "sp-runtime 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "sp-std 5.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", + "thiserror", + "wasmer", "webb-primitives", ] @@ -5431,9 +6033,9 @@ dependencies = [ [[package]] name = "parity-db" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a7511a0bec4a336b5929999d02b560d2439c993cccf98c26481484e811adc43" +checksum = "dd684a725651d9588ef21f140a328b6b4f64e646b2e931f3e6f14f75eedf9980" dependencies = [ "blake2 0.10.6", "crc32fast", @@ -5450,9 +6052,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.2.1" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a" +checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" dependencies = [ "arrayvec 0.7.2", "bitvec", @@ -5465,9 +6067,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.1.3" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9299338969a3d2f491d65f140b00ddec470858402f888af98e8642fb5e8965cd" +checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -5537,7 +6139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.5", + "parking_lot_core 0.9.7", ] [[package]] @@ -5556,15 +6158,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.5" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] @@ -5605,9 +6207,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" dependencies = [ "thiserror", "ucd-trie", @@ -5615,9 +6217,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" +checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69" dependencies = [ "pest", "pest_generator", @@ -5625,9 +6227,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" +checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202" dependencies = [ "pest", "pest_meta", @@ -5638,20 +6240,20 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.2" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" +checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616" dependencies = [ "once_cell", "pest", - "sha1", + "sha2 0.10.6", ] [[package]] name = "petgraph" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5014253a1331579ce62aa67443b4a658c5e7dd03d4bc6d302b94474888143" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" dependencies = [ "fixedbitset", "indexmap", @@ -5723,6 +6325,34 @@ version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" +[[package]] +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + [[package]] name = "polling" version = "2.5.2" @@ -5834,6 +6464,7 @@ checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" dependencies = [ "fixed-hash 0.8.0", "impl-codec", + "impl-rlp", "impl-serde", "scale-info", "uint", @@ -5841,11 +6472,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell", "thiserror", "toml", ] @@ -5882,9 +6512,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] @@ -5928,9 +6558,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.5" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01db6702aa05baa3f57dec92b8eeeeb4cb19e894e73996b32a4093289e54592" +checksum = "e48e50df39172a3e7eb17e14642445da64996989bc212b583015435d39a58537" dependencies = [ "bytes", "prost-derive", @@ -5938,9 +6568,9 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.5" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5320c680de74ba083512704acb90fe00f28f79207286a848e730c45dd73ed6" +checksum = "2c828f93f5ca4826f97fedcbd3f9a536c16b12cff3dbbb4a007f932bbad95b12" dependencies = [ "bytes", "heck", @@ -5973,9 +6603,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.5" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8842bad1a5419bca14eac663ba798f6bc19c413c2fdceb5f3ba3b0932d96720" +checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" dependencies = [ "anyhow", "itertools", @@ -5986,11 +6616,10 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.11.5" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "017f79637768cde62820bc2d4fe0e45daaa027755c323ad077767c6c5f173091" +checksum = "379119666929a1afd7a043aa6cf96fa67a6dce9af60c88095a4686dbce4c9c88" dependencies = [ - "bytes", "prost", ] @@ -6003,6 +6632,26 @@ dependencies = [ "cc", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -6153,9 +6802,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -6203,6 +6852,17 @@ dependencies = [ "syn", ] +[[package]] +name = "regalloc" +version = "0.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62446b1d3ebf980bdc68837700af1d77b37bc430e524bf95319c6eada2a4cc02" +dependencies = [ + "log", + "rustc-hash", + "smallvec", +] + [[package]] name = "regalloc2" version = "0.3.2" @@ -6242,14 +6902,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] -name = "remove_dir_all" -version = "0.5.3" +name = "region" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +checksum = "76e189c2369884dce920945e2ddf79b3dff49e071a167dd1817fa9c4c00d512e" dependencies = [ + "bitflags", + "libc", + "mach", "winapi", ] +[[package]] +name = "rend" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581008d2099240d37fb08d77ad713bcaec2c4d89d50b5b21a8bb1996bbab68ab" +dependencies = [ + "bytecheck", +] + [[package]] name = "resolv-conf" version = "0.7.0" @@ -6286,6 +6958,52 @@ dependencies = [ "winapi", ] +[[package]] +name = "rkyv" +version = "0.7.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c30f1d45d9aa61cbc8cd1eb87705470892289bb2d01943e7803b873a57404dc3" +dependencies = [ + "bytecheck", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff26ed6c7c4dfc2aa9480b86a60e3c7233543a270a680e10758a507c5a4ce476" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "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", +] + [[package]] name = "rocksdb" version = "0.19.0" @@ -6393,23 +7111,23 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.6" +version = "0.36.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" dependencies = [ "bitflags", "errno", - "io-lifetimes 1.0.3", + "io-lifetimes 1.0.5", "libc", "linux-raw-sys 0.1.4", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] name = "rustls" -version = "0.20.7" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" dependencies = [ "log", "ring", @@ -6431,11 +7149,11 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64", + "base64 0.21.0", ] [[package]] @@ -6591,7 +7309,7 @@ source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3 dependencies = [ "array-bytes", "chrono", - "clap", + "clap 4.1.6", "fdlimit", "futures", "libp2p", @@ -7462,7 +8180,7 @@ dependencies = [ "thiserror", "tracing", "tracing-log", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -7606,9 +8324,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" dependencies = [ "dyn-clone", "schemars_derive", @@ -7618,9 +8336,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" dependencies = [ "proc-macro2", "quote", @@ -7668,6 +8386,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "sec1" version = "0.3.0" @@ -7684,9 +8408,9 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9512ffd81e3a3503ed401f79c33168b9148c75038956039166cd750eaa037c3" +checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" dependencies = [ "secp256k1-sys", ] @@ -7711,9 +8435,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.7.0" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation", @@ -7724,9 +8448,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys", "libc", @@ -7792,6 +8516,25 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +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.152" @@ -7816,9 +8559,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.91" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", @@ -7827,9 +8570,9 @@ dependencies = [ [[package]] name = "serde_nanos" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44969a61f5d316be20a42ff97816efb3b407a924d06824c3d8a49fa8450de0e" +checksum = "8ae801b7733ca8d6a2b580debe99f67f36826a0f5b8a36055dc6bc40f8d6bc71" dependencies = [ "serde", ] @@ -7847,17 +8590,6 @@ dependencies = [ "opaque-debug 0.3.0", ] -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.6", -] - [[package]] name = "sha2" version = "0.8.2" @@ -7933,9 +8665,9 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] @@ -7964,9 +8696,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] @@ -7991,14 +8723,14 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "snow" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" +checksum = "12ba5f4d4ff12bdb6a169ed51b7c48c0e0ac4b0b4b31012b2571e97d78d3201d" dependencies = [ "aes-gcm", "blake2 0.10.6", "chacha20poly1305", - "curve25519-dalek 4.0.0-pre.5", + "curve25519-dalek 4.0.0-rc.0", "rand_core 0.6.4", "ring", "rustc_version 0.4.0", @@ -8022,7 +8754,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2" dependencies = [ - "base64", + "base64 0.13.1", "bytes", "flate2", "futures", @@ -8897,7 +9629,7 @@ dependencies = [ "sp-std 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "tracing", "tracing-core", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -8909,7 +9641,7 @@ dependencies = [ "sp-std 5.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "tracing", "tracing-core", - "tracing-subscriber", + "tracing-subscriber 0.2.25", ] [[package]] @@ -9089,9 +9821,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.37.0" +version = "1.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d44528162f980c0e03c71e005d334332c8da0aec9f2b0b4bdc557ed4a9f24776" +checksum = "ecf0bd63593ef78eca595a7fc25e9a443ca46fe69fd472f8f09f5245cdcd769d" dependencies = [ "Inflector", "num-format", @@ -9358,9 +10090,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.107" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -9408,29 +10140,28 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "target-lexicon" -version = "0.12.5" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9410d0f6853b1d94f0e519fb95df60f29d2c1eff2d921ffdf01a4c8a3b54f12d" +checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "tempfile" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" dependencies = [ "cfg-if", "fastrand", - "libc", "redox_syscall", - "remove_dir_all", - "winapi", + "rustix 0.36.8", + "windows-sys 0.42.0", ] [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -9441,6 +10172,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8" +[[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.38" @@ -9469,10 +10209,11 @@ checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" [[package]] name = "thread_local" -version = "1.1.4" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ + "cfg-if", "once_cell", ] @@ -9487,12 +10228,11 @@ dependencies = [ [[package]] name = "tikv-jemalloc-sys" -version = "0.5.2+5.3.0-patched" +version = "0.5.3+5.3.0-patched" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec45c14da997d0925c7835883e4d5c181f196fa142f8c19d7643d1e9af2592c3" +checksum = "a678df20055b43e57ef8cddde41cdfda9a3c1a060b67f4c5836dfb1d78543ba8" dependencies = [ "cc", - "fs_extra", "libc", ] @@ -9535,6 +10275,16 @@ 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" @@ -9546,15 +10296,15 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.24.1" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "bytes", @@ -9594,9 +10344,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" dependencies = [ "futures-core", "pin-project-lite 0.2.9", @@ -9605,9 +10355,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" dependencies = [ "bytes", "futures-core", @@ -9620,9 +10370,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] @@ -9702,6 +10452,26 @@ dependencies = [ "valuable", ] +[[package]] +name = "tracing-error" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" +dependencies = [ + "tracing", + "tracing-subscriber 0.2.25", +] + +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber 0.3.16", +] + [[package]] name = "tracing-futures" version = "0.2.5" @@ -9756,6 +10526,17 @@ dependencies = [ "tracing-serde", ] +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + [[package]] name = "trie-db" version = "0.24.0" @@ -9884,9 +10665,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" [[package]] name = "unicode-ident" @@ -10025,9 +10806,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -10035,9 +10816,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -10050,9 +10831,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.33" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if", "js-sys", @@ -10062,9 +10843,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -10072,9 +10853,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -10085,9 +10866,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "wasm-encoder" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "68f7d56227d910901ce12dfd19acc40c12687994dfb3f57c90690f80be946ec5" +dependencies = [ + "leb128", +] [[package]] name = "wasm-instrument" @@ -10154,6 +10944,237 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wasmer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea8d8361c9d006ea3d7797de7bd6b1492ffd0f91a22430cfda6c1658ad57bedf" +dependencies = [ + "cfg-if", + "indexmap", + "js-sys", + "loupe", + "more-asserts", + "target-lexicon", + "thiserror", + "wasm-bindgen", + "wasmer-artifact", + "wasmer-compiler", + "wasmer-compiler-cranelift", + "wasmer-derive", + "wasmer-engine", + "wasmer-engine-dylib", + "wasmer-engine-universal", + "wasmer-types", + "wasmer-vm", + "wat", + "winapi", +] + +[[package]] +name = "wasmer-artifact" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aaf9428c29c1d8ad2ac0e45889ba8a568a835e33fd058964e5e500f2f7ce325" +dependencies = [ + "enumset", + "loupe", + "thiserror", + "wasmer-compiler", + "wasmer-types", +] + +[[package]] +name = "wasmer-compiler" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67a6cd866aed456656db2cfea96c18baabbd33f676578482b85c51e1ee19d2c" +dependencies = [ + "enumset", + "loupe", + "rkyv", + "serde", + "serde_bytes", + "smallvec", + "target-lexicon", + "thiserror", + "wasmer-types", + "wasmparser 0.83.0", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48be2f9f6495f08649e4f8b946a2cbbe119faf5a654aa1457f9504a99d23dae0" +dependencies = [ + "cranelift-codegen 0.82.3", + "cranelift-entity 0.82.3", + "cranelift-frontend 0.82.3", + "gimli 0.26.2", + "loupe", + "more-asserts", + "rayon", + "smallvec", + "target-lexicon", + "tracing", + "wasmer-compiler", + "wasmer-types", +] + +[[package]] +name = "wasmer-derive" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00e50405cc2a2f74ff574584710a5f2c1d5c93744acce2ca0866084739284b51" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "wasmer-engine" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f98f010978c244db431b392aeab0661df7ea0822343334f8f2a920763548e45" +dependencies = [ + "backtrace", + "enumset", + "lazy_static", + "loupe", + "memmap2", + "more-asserts", + "rustc-demangle", + "serde", + "serde_bytes", + "target-lexicon", + "thiserror", + "wasmer-artifact", + "wasmer-compiler", + "wasmer-types", + "wasmer-vm", +] + +[[package]] +name = "wasmer-engine-dylib" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0358af9c154724587731175553805648d9acb8f6657880d165e378672b7e53" +dependencies = [ + "cfg-if", + "enum-iterator", + "enumset", + "leb128", + "libloading", + "loupe", + "object 0.28.4", + "rkyv", + "serde", + "tempfile", + "tracing", + "wasmer-artifact", + "wasmer-compiler", + "wasmer-engine", + "wasmer-object", + "wasmer-types", + "wasmer-vm", + "which", +] + +[[package]] +name = "wasmer-engine-universal" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "440dc3d93c9ca47865a4f4edd037ea81bf983b5796b59b3d712d844b32dbef15" +dependencies = [ + "cfg-if", + "enumset", + "leb128", + "loupe", + "region", + "rkyv", + "wasmer-compiler", + "wasmer-engine", + "wasmer-engine-universal-artifact", + "wasmer-types", + "wasmer-vm", + "winapi", +] + +[[package]] +name = "wasmer-engine-universal-artifact" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f1db3f54152657eb6e86c44b66525ff7801dad8328fe677da48dd06af9ad41" +dependencies = [ + "enum-iterator", + "enumset", + "loupe", + "rkyv", + "thiserror", + "wasmer-artifact", + "wasmer-compiler", + "wasmer-types", +] + +[[package]] +name = "wasmer-object" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d831335ff3a44ecf451303f6f891175c642488036b92ceceb24ac8623a8fa8b" +dependencies = [ + "object 0.28.4", + "thiserror", + "wasmer-compiler", + "wasmer-types", +] + +[[package]] +name = "wasmer-types" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39df01ea05dc0a9bab67e054c7cb01521e53b35a7bb90bd02eca564ed0b2667f" +dependencies = [ + "backtrace", + "enum-iterator", + "indexmap", + "loupe", + "more-asserts", + "rkyv", + "serde", + "thiserror", +] + +[[package]] +name = "wasmer-vm" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d965fa61f4dc4cdb35a54daaf7ecec3563fbb94154a6c35433f879466247dd" +dependencies = [ + "backtrace", + "cc", + "cfg-if", + "corosensei", + "enum-iterator", + "indexmap", + "lazy_static", + "libc", + "loupe", + "mach", + "memoffset 0.6.5", + "more-asserts", + "region", + "rkyv", + "scopeguard", + "serde", + "thiserror", + "wasmer-artifact", + "wasmer-types", + "winapi", +] + [[package]] name = "wasmi" version = "0.13.2" @@ -10187,6 +11208,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "wasmparser" +version = "0.83.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" + [[package]] name = "wasmparser" version = "0.89.1" @@ -10215,7 +11242,7 @@ dependencies = [ "rayon", "serde", "target-lexicon", - "wasmparser", + "wasmparser 0.89.1", "wasmtime-cache", "wasmtime-cranelift", "wasmtime-environ", @@ -10240,7 +11267,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcd849399d17d2270141cfe47fa0d91ee52d5f8ea9b98cf7ddde0d53e5f79882" dependencies = [ "anyhow", - "base64", + "base64 0.13.1", "bincode", "directories-next", "file-per-thread-logger", @@ -10260,9 +11287,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bd91339b742ff20bfed4532a27b73c86b5bcbfedd6bea2dcdf2d64471e1b5c6" dependencies = [ "anyhow", - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", + "cranelift-codegen 0.88.2", + "cranelift-entity 0.88.2", + "cranelift-frontend 0.88.2", "cranelift-native", "cranelift-wasm", "gimli 0.26.2", @@ -10270,7 +11297,7 @@ dependencies = [ "object 0.29.0", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.89.1", "wasmtime-environ", ] @@ -10281,7 +11308,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebb881c61f4f627b5d45c54e629724974f8a8890d455bcbe634330cc27309644" dependencies = [ "anyhow", - "cranelift-entity", + "cranelift-entity 0.88.2", "gimli 0.26.2", "indexmap", "log", @@ -10289,7 +11316,7 @@ dependencies = [ "serde", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.89.1", "wasmtime-types", ] @@ -10360,17 +11387,38 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d23d61cb4c46e837b431196dd06abb11731541021916d03476a178b54dc07aeb" dependencies = [ - "cranelift-entity", + "cranelift-entity 0.88.2", "serde", "thiserror", - "wasmparser", + "wasmparser 0.89.1", +] + +[[package]] +name = "wast" +version = "54.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d48d9d731d835f4f8dacbb8de7d47be068812cb9877f5c60d408858778d8d2a" +dependencies = [ + "leb128", + "memchr", + "unicode-width", + "wasm-encoder", +] + +[[package]] +name = "wat" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1db2e3ed05ea31243761439194bec3af6efbbaf87c4c8667fb879e4f23791a0" +dependencies = [ + "wast", ] [[package]] name = "web-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", @@ -10382,23 +11430,41 @@ version = "0.1.0" dependencies = [ "ark-bls12-381", "ark-bn254", + "ark-circom 0.1.0 (git+https://github.com/gakonst/ark-circom?branch=master)", "ark-crypto-primitives", "ark-ec", "ark-ff", + "ark-groth16 0.3.0 (git+https://github.com/arkworks-rs/groth16?rev=765817f)", "ark-relations", "ark-serialize", "ark-std", "arkworks-native-gadgets", "arkworks-setups", + "cfg-if", + "color-eyre 0.6.2", + "frame-benchmarking", + "frame-support", + "frame-system", "hex", + "num-bigint", + "num-traits", + "once_cell", + "orml-currencies", + "orml-tokens", + "pallet-balances", "parity-scale-codec", + "rand 0.8.5", "scale-info", "serde", + "serde_json", "sp-core 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", + "sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "sp-keyring 7.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-runtime 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.36)", "subxt", + "thiserror", "tokio", + "wasmer", "webb-primitives", ] @@ -10411,15 +11477,17 @@ dependencies = [ "ark-crypto-primitives", "ark-ec", "ark-ff", - "ark-groth16", + "ark-groth16 0.3.0 (git+https://github.com/arkworks-rs/groth16?rev=765817f)", "ark-relations", "ark-serialize", "ark-std", "arkworks-native-gadgets", "blake2 0.9.2", + "byteorder", "digest 0.9.0", - "ethabi", + "ethabi 15.0.0", "frame-support", + "num-traits", "parity-scale-codec", "scale-info", "serde", @@ -10434,9 +11502,8 @@ dependencies = [ [[package]] name = "webb-proposals" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2ab97c42b53720c745a0a87eb734c3cb90a979ef0ddaae52c83bddb4bd858a" +version = "0.5.5" +source = "git+https://github.com/webb-tools/webb-rs#ee6cd26cd4171af68963d5429ab3c150bb176526" dependencies = [ "num-traits", "parity-scale-codec", @@ -10454,7 +11521,7 @@ dependencies = [ "ark-bn254", "arkworks-setups", "array-bytes", - "clap", + "clap 4.1.6", "frame-benchmarking", "frame-benchmarking-cli", "frame-system", @@ -10638,9 +11705,9 @@ dependencies = [ [[package]] name = "which" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", "libc", @@ -10697,6 +11764,19 @@ dependencies = [ "windows_x86_64_msvc 0.34.0", ] +[[package]] +name = "windows-sys" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43dbb096663629518eb1dfa72d80243ca5a6aca764cae62a2df70af760a9be75" +dependencies = [ + "windows_aarch64_msvc 0.33.0", + "windows_i686_gnu 0.33.0", + "windows_i686_msvc 0.33.0", + "windows_x86_64_gnu 0.33.0", + "windows_x86_64_msvc 0.33.0", +] + [[package]] name = "windows-sys" version = "0.36.1" @@ -10717,19 +11797,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc 0.42.1", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" [[package]] name = "windows_aarch64_msvc" @@ -10745,9 +11855,15 @@ checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" [[package]] name = "windows_i686_gnu" @@ -10763,9 +11879,15 @@ checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" [[package]] name = "windows_i686_msvc" @@ -10781,9 +11903,15 @@ checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" [[package]] name = "windows_x86_64_gnu" @@ -10799,15 +11927,21 @@ checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" [[package]] name = "windows_x86_64_msvc" @@ -10823,9 +11957,9 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winreg" @@ -10943,10 +12077,11 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.4+zstd.1.5.2" +version = "2.0.7+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" dependencies = [ "cc", "libc", + "pkg-config", ] diff --git a/README.md b/README.md index 14f5bed0a..0ff2da920 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Repo environment setup: git clone git@github.com:webb-tools/protocol-substrate.git # Fetch fixtures -dvc pull +Run the script in `scripts/fetch-fixtures.sh` file. ``` Build the node in `release mode`: diff --git a/client/Cargo.toml b/client/Cargo.toml index 8f3173cbc..8b95f5681 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -8,6 +8,8 @@ version = "0.1.0" [dependencies] codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] } subxt = { version = "0.25.0" } +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } [dev-dependencies] hex = "0.4" @@ -27,8 +29,39 @@ ark-ff = { version = "^0.3.0", default-features = false } ark-relations = { version = "^0.3.0", default-features = false } ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] } ark-std = { version = "^0.3.0", default-features = false } +ark-circom = { git = "https://github.com/gakonst/ark-circom", branch = "master", default-features = false, features = ["circom-2"] } +ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", features = ["parallel"] } +rand = "0.8.4" +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } +arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false } +num-bigint = { version = "0.4", default-features = false, features = ["rand"] } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +# For ark-circom +once_cell = "1.14.0" +cfg-if = "1.0" +wasmer = { version = "2.3.0", default-features = false } +num-traits = "0.2.11" +thiserror = "1.0.0" +color-eyre = "0.6.1" +serde_json = "1.0.48" + # Webb deps arkworks-native-gadgets = { version = "1.2.0", default-features = false } -arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false } webb-primitives = { path = "../primitives", features = ["hashing", "verifying", "field_ops"] } + +[features] +default = ["std", "wasmer/sys-default"] +std = [ + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", +] +runtime-benchmarks = [ + "frame-system/runtime-benchmarks", + "frame-support/runtime-benchmarks", +] +wasm = ["wasmer/js", "wasmer/std"] \ No newline at end of file diff --git a/client/tests/integration_tests.rs b/client/tests/integration_tests.rs index dae7ede48..5e03c1c21 100644 --- a/client/tests/integration_tests.rs +++ b/client/tests/integration_tests.rs @@ -1,4 +1,8 @@ +use ark_ff::ToBytes; +use ark_groth16::{Proof as ArkProof, ProvingKey, VerifyingKey}; +use ark_relations::r1cs::ConstraintMatrices; use sp_keyring::AccountKeyring; +use sp_runtime::traits::Verify; use webb_client::webb_runtime; use webb_primitives::ElementTrait; @@ -8,7 +12,7 @@ use codec::Encode; use utils::*; use webb_primitives::{hashing::ethereum::keccak_256, utils::compute_chain_id_type, IntoAbiToken}; -use ark_bn254::Fr as Bn254Fr; +use ark_bn254::{Bn254, Fr as Bn254Fr}; use arkworks_native_gadgets::ark_std::rand::rngs::OsRng; use arkworks_setups::{ common::{verify_unchecked, verify_unchecked_raw}, @@ -17,21 +21,27 @@ use arkworks_setups::{ use subxt::{ ext::sp_runtime::AccountId32, tx::{PairSigner, TxProgress}, - OnlineClient, PolkadotConfig, + OnlineClient, SubstrateConfig, }; use utils::ExtData; +use ark_circom::{read_zkey, WitnessCalculator}; use ark_ff::{BigInteger, PrimeField}; +use ark_serialize::CanonicalSerialize; +use std::{fs::File, sync::Mutex}; #[tokio::test] +#[ignore] async fn test_mixer() -> Result<(), Box> { - let api: OnlineClient<_> = OnlineClient::::new().await?; + let api: OnlineClient<_> = OnlineClient::::new().await?; let signer = PairSigner::new(AccountKeyring::Alice.pair()); - let pk_bytes = - include_bytes!("../../substrate-fixtures/mixer/bn254/x5/proving_key_uncompressed.bin"); - let vk_bytes = - include_bytes!("../../substrate-fixtures/mixer/bn254/x5/verifying_key_uncompressed.bin"); + let pk_bytes = include_bytes!( + "../../substrate-fixtures/substrate-fixtures/mixer/bn254/x5/proving_key_uncompressed.bin" + ); + let vk_bytes = include_bytes!( + "../../substrate-fixtures/substrate-fixtures/mixer/bn254/x5/verifying_key_uncompressed.bin" + ); let recipient = AccountKeyring::Bob.to_account_id(); let relayer = AccountKeyring::Bob.to_account_id(); let recipient_bytes = truncate_and_pad(&recipient.encode()); @@ -53,8 +63,8 @@ async fn test_mixer() -> Result<(), Box> { expect_event::< webb_runtime::mixer_bn254::events::Deposit, - PolkadotConfig, - OnlineClient, + SubstrateConfig, + OnlineClient, >(&mut deposit_res) .await?; @@ -133,8 +143,8 @@ async fn test_mixer() -> Result<(), Box> { expect_event::< webb_runtime::mixer_bn254::events::Withdraw, - PolkadotConfig, - OnlineClient, + SubstrateConfig, + OnlineClient, >(&mut withdraw_res) .await?; @@ -142,8 +152,9 @@ async fn test_mixer() -> Result<(), Box> { } async fn make_vanchor_tx( - pk_bytes: &[u8], - vk_bytes: &[u8], + circom_params: &(ProvingKey, ConstraintMatrices), + #[cfg(not(target_arch = "wasm32"))] wc: &Mutex, + #[cfg(target_arch = "wasm32")] wc: &mut WitnessCalculator, recipient: &AccountId32, relayer: &AccountId32, public_amount: i128, @@ -152,7 +163,7 @@ async fn make_vanchor_tx( in_utxos: [Utxo; 2], out_utxos: [Utxo; 2], ) -> Result<(), Box> { - let api = OnlineClient::::new().await?; + let api = OnlineClient::::new().await?; let signer = PairSigner::new(AccountKeyring::Alice.pair()); let chain_type = [2, 0]; @@ -185,11 +196,13 @@ async fn make_vanchor_tx( out_utxos.clone(), custom_roots, leaves, - pk_bytes.to_vec(), + circom_params, + wc, ); - let res = verify_unchecked::(&public_inputs, vk_bytes, &proof)?; - assert!(res, "Invalid proof"); + let res = verify_proof(&circom_params.0.vk, &proof, &public_inputs); + assert!(res.unwrap(), "Invalid proof"); + println!("proof verified"); // Deconstructing public inputs let (_chain_id, public_amount, root_set, nullifiers, commitments, ext_data_hash) = @@ -202,14 +215,18 @@ async fn make_vanchor_tx( println!("commitments {commitments:?}"); println!("ext data hash {ext_data_hash:?}"); + let mut proof_vec = Vec::new(); + let _ = &proof.write(&mut proof_vec).unwrap(); + // Constructing proof data let proof_data = - ProofData::new(proof, public_amount, root_set, nullifiers, commitments, ext_data_hash); + ProofData::new(proof_vec, public_amount, root_set, nullifiers, commitments, ext_data_hash); + println!("my name is: {:?}", &proof_data.roots.len()); // mixer = 0..3 // anchor = 3..6 // vanchor = 6 - let tree_id = 6; + let tree_id = 5; // Get the vanchor transaction API let vanchor = webb_runtime::tx().v_anchor_bn254(); @@ -220,8 +237,8 @@ async fn make_vanchor_tx( expect_event::< webb_runtime::v_anchor_bn254::events::Transaction, - PolkadotConfig, - OnlineClient, + SubstrateConfig, + OnlineClient, >(&mut transact_res) .await?; @@ -230,14 +247,16 @@ async fn make_vanchor_tx( #[tokio::test] async fn test_vanchor() -> Result<(), Box> { - let api: OnlineClient<_> = OnlineClient::::new().await?; + let api: OnlineClient<_> = OnlineClient::::new().await?; - let pk_bytes = include_bytes!( - "../../substrate-fixtures/vanchor/bn254/x5/2-2-2/proving_key_uncompressed.bin" - ); - let vk_bytes = include_bytes!( - "../../substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key_uncompressed.bin" - ); + let path_2_2 = "../solidity-fixtures/solidity-fixtures/vanchor_2/2/circuit_final.zkey"; + let mut file_2_2 = File::open(path_2_2).unwrap(); + let params_2_2 = read_zkey(&mut file_2_2).unwrap(); + + let wasm_2_2_path = + "../solidity-fixtures/solidity-fixtures//vanchor_2/2/poseidon_vanchor_2_2.wasm"; + + let wc_2_2 = circom_from_folder(wasm_2_2_path); let recipient = AccountKeyring::Bob.to_account_id(); let relayer = AccountKeyring::Bob.to_account_id(); @@ -262,8 +281,8 @@ async fn test_vanchor() -> Result<(), Box> { let leaves: Vec> = vec![leaf0, leaf1]; make_vanchor_tx( - pk_bytes, - vk_bytes, + ¶ms_2_2, + wc_2_2, &(*AsRef::<[u8; 32]>::as_ref(&recipient)).into(), &(*AsRef::<[u8; 32]>::as_ref(&relayer)).into(), public_amount, @@ -277,7 +296,7 @@ async fn test_vanchor() -> Result<(), Box> { // Get the vanchor storage API let mt_storage = webb_runtime::storage().merkle_tree_bn254(); - let tree_id = 6; + let tree_id = 5; let tree_metadata_storage_key = mt_storage.trees(tree_id); let tree_metadata_res = api.storage().fetch(&tree_metadata_storage_key, None).await?; let tree_metadata = tree_metadata_res.unwrap(); @@ -307,8 +326,8 @@ async fn test_vanchor() -> Result<(), Box> { let out_utxos = setup_utxos(out_chain_ids, new_out_amounts, None); make_vanchor_tx( - pk_bytes, - vk_bytes, + ¶ms_2_2, + wc_2_2, &(*AsRef::<[u8; 32]>::as_ref(&recipient)).into(), &(*AsRef::<[u8; 32]>::as_ref(&relayer)).into(), public_amount, diff --git a/client/tests/utils.rs b/client/tests/utils.rs index 5c5de1f41..b78d7e464 100644 --- a/client/tests/utils.rs +++ b/client/tests/utils.rs @@ -28,11 +28,245 @@ use arkworks_setups::{ }; use webb_primitives::types::{ElementTrait, IntoAbiToken, Token}; -use ark_bn254::{Bn254, Fr as Bn254Fr}; -use ark_std::{rand::thread_rng, UniformRand}; +use ark_bn254::{Bn254, Fr}; +use ark_circom::WitnessCalculator; +use ark_groth16::{ + create_proof_with_reduction_and_matrices, prepare_verifying_key, + verify_proof as ark_verify_proof, Proof as ArkProof, ProvingKey, VerifyingKey, +}; +use ark_relations::r1cs::ConstraintMatrices; +use ark_std::{rand::thread_rng, vec::Vec, UniformRand}; use codec::{Decode, Encode}; +use num_bigint::BigInt; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; +use std::{convert::TryInto, sync::Mutex}; + +type Bn254Fr = ark_bn254::Fr; + +pub const DEFAULT_LEAF: [u8; 32] = [ + 47, 229, 76, 96, 211, 172, 171, 243, 52, 58, 53, 182, 235, 161, 93, 180, 130, 27, 52, 15, 118, + 231, 65, 226, 36, 150, 133, 237, 72, 153, 175, 108, +]; + +#[allow(non_camel_case_types)] +type VAnchorProver_Bn254_30_2_2_2 = + VAnchorR1CSProver; + +use ark_bn254::{Fq, Fq2, G1Affine, G1Projective, G2Affine, G2Projective}; +use ark_circom::{read_zkey, CircomConfig, CircomReduction}; +use ark_ff::{BigInteger256, ToBytes}; +use ark_relations::r1cs::SynthesisError; +use arkworks_native_gadgets::merkle_tree::{Path, SparseMerkleTree}; +use cfg_if::cfg_if; +use frame_benchmarking::account; +use frame_support::{assert_ok, traits::OnInitialize}; +use num_bigint::{BigUint, Sign}; +use once_cell::sync::OnceCell; +use serde_json::Value; +use sp_core::hashing::keccak_256; +use std::{ + convert::TryFrom, + fs::{self, File}, + io::{Cursor, Error, ErrorKind}, + result::Result, + str::FromStr, +}; +use thiserror::Error; +use wasmer::{Module, Store}; +use webb_primitives::{ + linkable_tree::LinkableTreeInspector, merkle_tree::TreeInspector, utils::compute_chain_id_type, + verifying::CircomError, AccountId, +}; + +#[derive(Error, Debug)] +pub enum ProofError { + #[error("Error reading circuit key: {0}")] + CircuitKeyError(#[from] std::io::Error), + #[error("Error producing witness: {0}")] + WitnessError(color_eyre::Report), + #[error("Error producing proof: {0}")] + SynthesisError(#[from] SynthesisError), +} + +#[cfg(not(target_arch = "wasm32"))] +static WITNESS_CALCULATOR: OnceCell> = OnceCell::new(); + +// Utilities to convert a json verification key in a groth16::VerificationKey +fn fq_from_str(s: &str) -> Fq { + Fq::try_from(BigUint::from_str(s).unwrap()).unwrap() +} + +// Extracts the element in G1 corresponding to its JSON serialization +fn json_to_g1(json: &Value, key: &str) -> G1Affine { + let els: Vec = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| i.as_str().unwrap().to_string()) + .collect(); + G1Affine::from(G1Projective::new( + fq_from_str(&els[0]), + fq_from_str(&els[1]), + fq_from_str(&els[2]), + )) +} + +// Extracts the vector of G1 elements corresponding to its JSON serialization +fn json_to_g1_vec(json: &Value, key: &str) -> Vec { + let els: Vec> = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| { + i.as_array() + .unwrap() + .iter() + .map(|x| x.as_str().unwrap().to_string()) + .collect::>() + }) + .collect(); + + els.iter() + .map(|coords| { + G1Affine::from(G1Projective::new( + fq_from_str(&coords[0]), + fq_from_str(&coords[1]), + fq_from_str(&coords[2]), + )) + }) + .collect() +} + +// Extracts the element in G2 corresponding to its JSON serialization +fn json_to_g2(json: &Value, key: &str) -> G2Affine { + let els: Vec> = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| { + i.as_array() + .unwrap() + .iter() + .map(|x| x.as_str().unwrap().to_string()) + .collect::>() + }) + .collect(); + + let x = Fq2::new(fq_from_str(&els[0][0]), fq_from_str(&els[0][1])); + let y = Fq2::new(fq_from_str(&els[1][0]), fq_from_str(&els[1][1])); + let z = Fq2::new(fq_from_str(&els[2][0]), fq_from_str(&els[2][1])); + G2Affine::from(G2Projective::new(x, y, z)) +} + +// Converts JSON to a VerifyingKey +fn to_verifying_key(json: serde_json::Value) -> VerifyingKey { + VerifyingKey { + alpha_g1: json_to_g1(&json, "vk_alpha_1"), + beta_g2: json_to_g2(&json, "vk_beta_2"), + gamma_g2: json_to_g2(&json, "vk_gamma_2"), + delta_g2: json_to_g2(&json, "vk_delta_2"), + gamma_abc_g1: json_to_g1_vec(&json, "IC"), + } +} + +// Computes the verification key from its JSON serialization +fn vk_from_json(vk_path: &str) -> VerifyingKey { + let json = std::fs::read_to_string(vk_path).unwrap(); + let json: Value = serde_json::from_str(&json).unwrap(); + + to_verifying_key(json) +} + +pub fn generate_proof( + #[cfg(not(target_arch = "wasm32"))] witness_calculator: &Mutex, + #[cfg(target_arch = "wasm32")] witness_calculator: &mut WitnessCalculator, + proving_key: &(ProvingKey, ConstraintMatrices), + vanchor_witness: [(&str, Vec); 15], +) -> Result<(ArkProof, Vec), ProofError> { + let inputs = vanchor_witness + .into_iter() + .map(|(name, values)| (name.to_string(), values.clone())); + + println!("inputs {:?}", inputs); + + cfg_if! { + if #[cfg(target_arch = "wasm32")] { + let full_assignment = witness_calculator + .calculate_witness_element::(inputs, false) + .map_err(ProofError::WitnessError)?; + } else { + let full_assignment = witness_calculator + .lock() + .expect("witness_calculator mutex should not get poisoned") + .calculate_witness_element::(inputs, false) + .map_err(ProofError::WitnessError)?; + } + } + + // Random Values + let mut rng = thread_rng(); + let r = Fr::rand(&mut rng); + let s = Fr::rand(&mut rng); + + let proof = create_proof_with_reduction_and_matrices::<_, CircomReduction>( + &proving_key.0, + r, + s, + &proving_key.1, + proving_key.1.num_instance_variables, + proving_key.1.num_constraints, + full_assignment.as_slice(), + )?; + + Ok((proof, full_assignment)) +} + +/// Verifies a given RLN proof +/// +/// # Errors +/// +/// Returns a [`ProofError`] if verifying fails. Verification failure does not +/// necessarily mean the proof is incorrect. +pub fn verify_proof( + verifying_key: &VerifyingKey, + proof: &ArkProof, + inputs: &Vec, +) -> Result { + // Check that the proof is valid + let pvk = prepare_verifying_key(verifying_key); + //let pr: ArkProof = (*proof).into(); + + let verified = ark_verify_proof(&pvk, proof, inputs)?; + + Ok(verified) +} + +// Initializes the witness calculator using a bytes vector +#[cfg(not(target_arch = "wasm32"))] +pub fn circom_from_raw(wasm_buffer: Vec) -> &'static Mutex { + WITNESS_CALCULATOR.get_or_init(|| { + let store = Store::default(); + let module = Module::new(&store, wasm_buffer).unwrap(); + let result = + WitnessCalculator::from_module(module).expect("Failed to create witness calculator"); + Mutex::new(result) + }) +} + +// Initializes the witness calculator +#[cfg(not(target_arch = "wasm32"))] +pub fn circom_from_folder(wasm_path: &str) -> &'static Mutex { + // We read the wasm file + let wasm_buffer = std::fs::read(wasm_path).unwrap(); + circom_from_raw(wasm_buffer) +} #[derive( Debug, Encode, Decode, Default, Copy, Clone, PartialEq, Eq, TypeInfo, Serialize, Deserialize, @@ -170,16 +404,9 @@ impl From> for WebbExtData; -#[allow(non_camel_case_types)] -type VAnchorProver_Bn254_30_2_2_2 = - VAnchorR1CSProver; pub fn setup_mixer_leaf() -> (Element, Element, Element, Element) { let rng = &mut thread_rng(); @@ -275,8 +502,10 @@ pub fn setup_vanchor_circuit( out_utxos: [Utxo; NUM_UTXOS], custom_roots: Option<[Vec; ANCHOR_CT]>, leaves: Vec>, - pk_bytes: Vec, -) -> (Vec, Vec) { + circom_params: &(ProvingKey, ConstraintMatrices), + #[cfg(not(target_arch = "wasm32"))] wc: &Mutex, + #[cfg(target_arch = "wasm32")] wc: &mut WitnessCalculator, +) -> (ArkProof, Vec) { let curve = Curve::Bn254; let rng = &mut thread_rng(); @@ -288,9 +517,7 @@ pub fn setup_vanchor_circuit( let in_indices = [in_utxos[0].get_index().unwrap(), in_utxos[1].get_index().unwrap()]; // This allows us to pass zero roots for initial transaction - let in_root_set = if custom_roots.is_some() { - custom_roots.unwrap() - } else { + let (mut in_root_set, in_paths) = { let params3 = setup_params::(curve, 5, 3); let poseidon3 = Poseidon::new(params3); let (tree, _) = setup_tree_and_create_path::, TREE_DEPTH>( @@ -300,32 +527,127 @@ pub fn setup_vanchor_circuit( &DEFAULT_LEAF, ) .unwrap(); - [(); ANCHOR_CT].map(|_| tree.root().into_repr().to_bytes_be()) + let in_paths: Vec<_> = + in_indices.iter().map(|i| tree.generate_membership_proof(*i)).collect(); + ([(); ANCHOR_CT].map(|_| tree.root().into_repr().to_bytes_be()), in_paths) }; - let vanchor_proof = VAnchorProver_Bn254_30_2_2_2::create_proof( - curve, - chain_id, - public_amount, - ext_data_hash, - in_root_set, - in_indices, - in_leaves, - in_utxos, - out_utxos, - pk_bytes, - DEFAULT_LEAF, - rng, - ) - .unwrap(); + if custom_roots.is_some() { + in_root_set = custom_roots.unwrap(); + } - let pub_ins = vanchor_proof - .public_inputs_raw + let params4 = setup_params::(Curve::Bn254, 5, 4); + let nullifier_hasher = Poseidon:: { params: params4 }; + + // Make Inputs + let mut public_amount_as_vec = if public_amount > 0 { + vec![BigInt::from_bytes_be(Sign::Plus, &public_amount.to_be_bytes())] + } else { + vec![BigInt::from_bytes_be(Sign::Minus, &(-public_amount).to_be_bytes())] + }; + + let mut ext_data_hash_as_vec = vec![BigInt::from_bytes_be(Sign::Plus, &ext_data_hash)]; + let mut input_nullifier_as_vec = Vec::new(); + let mut output_commitment_as_vec = Vec::new(); + for i in 0..NUM_UTXOS { + input_nullifier_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &in_utxos[i] + .calculate_nullifier(&nullifier_hasher) + .unwrap() + .into_repr() + .to_bytes_be(), + )); + output_commitment_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].commitment.into_repr().to_bytes_be(), + )); + } + + let mut chain_id_as_vec = vec![BigInt::from_bytes_be(Sign::Plus, &chain_id.to_be_bytes())]; + + let mut roots_as_vec = in_root_set .iter() - .map(|x| Bn254Fr::from_be_bytes_mod_order(x)) - .collect(); + .map(|x| BigInt::from_bytes_be(Sign::Plus, x)) + .collect::>(); + + let mut in_amount_as_vec = Vec::new(); + let mut in_private_key_as_vec = Vec::new(); + let mut in_blinding_as_vec = Vec::new(); + let mut in_path_indices_as_vec = Vec::new(); + let mut in_path_elements_as_vec = Vec::new(); + let mut out_chain_id_as_vec = Vec::new(); + let mut out_amount_as_vec = Vec::new(); + let mut out_pub_key_as_vec = Vec::new(); + let mut out_blinding_as_vec = Vec::new(); + + for i in 0..NUM_UTXOS { + in_amount_as_vec + .push(BigInt::from_bytes_be(Sign::Plus, &in_utxos[i].amount.into_repr().to_bytes_be())); + in_private_key_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &in_utxos[i].keypair.secret_key.unwrap().into_repr().to_bytes_be(), + )); + in_blinding_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &in_utxos[i].blinding.into_repr().to_bytes_be(), + )); + in_path_indices_as_vec.push(BigInt::from(in_utxos[i].get_index().unwrap())); + for j in 0..TREE_DEPTH { + let neighbor_elt: Bn254Fr = + if in_indices[i] == 0 { in_paths[i].path[j].1 } else { in_paths[i].path[j].0 }; + in_path_elements_as_vec + .push(BigInt::from_bytes_be(Sign::Plus, &neighbor_elt.into_repr().to_bytes_be())); + } + + out_chain_id_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].chain_id.into_repr().to_bytes_be(), + )); + + out_amount_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].amount.into_repr().to_bytes_be(), + )); + + out_pub_key_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].keypair.public_key.into_repr().to_bytes_be(), + )); + + out_blinding_as_vec.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].blinding.into_repr().to_bytes_be(), + )); + } - (vanchor_proof.proof, pub_ins) + let inputs_for_proof = [ + ("publicAmount", public_amount_as_vec.clone()), + ("extDataHash", ext_data_hash_as_vec.clone()), + ("inputNullifier", input_nullifier_as_vec.clone()), + ("inAmount", in_amount_as_vec.clone()), + ("inPrivateKey", in_private_key_as_vec.clone()), + ("inBlinding", in_blinding_as_vec.clone()), + ("inPathIndices", in_path_indices_as_vec.clone()), + ("inPathElements", in_path_elements_as_vec.clone()), + ("outputCommitment", output_commitment_as_vec.clone()), + ("outChainID", out_chain_id_as_vec.clone()), + ("outAmount", out_amount_as_vec.clone()), + ("outPubkey", out_pub_key_as_vec.clone()), + ("outBlinding", out_blinding_as_vec.clone()), + ("chainID", chain_id_as_vec.clone()), + ("roots", roots_as_vec.clone()), + ]; + + let x = generate_proof(wc, circom_params, inputs_for_proof.clone()); + + let num_inputs = circom_params.1.num_instance_variables; + + let (proof, full_assignment) = x.unwrap(); + + let mut public_inputs = &full_assignment[1..num_inputs]; + + (proof, public_inputs.to_vec()) } pub fn deconstruct_vanchor_pi( diff --git a/pallets/anonymity-mining-rewards/Cargo.toml b/pallets/anonymity-mining-rewards/Cargo.toml index 29aae1167..0c7786f18 100644 --- a/pallets/anonymity-mining-rewards/Cargo.toml +++ b/pallets/anonymity-mining-rewards/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "Pallet that handles rewards from anonymity mining." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-anonymity-mining-rewards" diff --git a/pallets/anonymity-mining-rewards/src/lib.rs b/pallets/anonymity-mining-rewards/src/lib.rs index aedfd70f5..a93ac6d8e 100644 --- a/pallets/anonymity-mining-rewards/src/lib.rs +++ b/pallets/anonymity-mining-rewards/src/lib.rs @@ -173,7 +173,7 @@ pub mod pallet { let tokens_sold_u64 = tokens.saturated_into::(); let prev_tokens_sold_u64 = Self::get_tokens_sold(); - Self::set_tokens_sold(prev_tokens_sold_u64 + tokens_sold_u64); + Self::set_tokens_sold(prev_tokens_sold_u64 + tokens_sold_u64)?; // Deposit AP tokens to the pallet >::Currency::transfer( diff --git a/pallets/anonymity-mining-rewards/src/tests.rs b/pallets/anonymity-mining-rewards/src/tests.rs index f3fd24c70..3ba66adb8 100644 --- a/pallets/anonymity-mining-rewards/src/tests.rs +++ b/pallets/anonymity-mining-rewards/src/tests.rs @@ -19,7 +19,6 @@ use arkworks_setups::{common::setup_params, Curve}; use pallet_vanchor_handler::AnchorList; const SEED: u32 = 0; -const START_TIMESTAMP: u64 = 0; const INITIAL_LIQUIDITY: u128 = 10000000; const LIQUIDITY: u128 = 20000000; const INITIAL_TOTAL_REWARDS_BALANCE: i128 = 30000000; diff --git a/pallets/hasher/Cargo.toml b/pallets/hasher/Cargo.toml index adba474ca..32d3d6255 100644 --- a/pallets/hasher/Cargo.toml +++ b/pallets/hasher/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "Pallet that provides a single hash function + parameters for use in other pallets." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-hasher" diff --git a/pallets/hasher/src/lib.rs b/pallets/hasher/src/lib.rs index 3d2b60b38..5c7dba1aa 100644 --- a/pallets/hasher/src/lib.rs +++ b/pallets/hasher/src/lib.rs @@ -118,7 +118,7 @@ pub mod pallet { #[pallet::error] pub enum Error { /// Parameters haven't been initialized - ParametersNotInitialized, + HashingParametersNotInitialized, /// Error during hashing HashError, } @@ -146,7 +146,7 @@ pub mod pallet { impl, I: 'static> HasherModule for Pallet { fn hash(data: &[u8]) -> Result, DispatchError> { let params = Self::parameters(); - ensure!(!params.is_empty(), Error::::ParametersNotInitialized); + ensure!(!params.is_empty(), Error::::HashingParametersNotInitialized); match T::Hasher::hash(data, ¶ms) { Ok(hash) => Ok(hash), Err(_e) => { diff --git a/pallets/hasher/src/tests.rs b/pallets/hasher/src/tests.rs index e3432f98f..66cc54814 100644 --- a/pallets/hasher/src/tests.rs +++ b/pallets/hasher/src/tests.rs @@ -13,7 +13,7 @@ fn should_fail_with_params_not_initialized() { new_test_ext().execute_with(|| { assert_err!( ::hash(&[1u8; 32]), - Error::::ParametersNotInitialized + Error::::HashingParametersNotInitialized ); }); } diff --git a/pallets/key-storage/Cargo.toml b/pallets/key-storage/Cargo.toml index 01f7b285e..75f3daf7d 100644 --- a/pallets/key-storage/Cargo.toml +++ b/pallets/key-storage/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "A pallet that stores an account and public key mapping." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-key-storage" diff --git a/pallets/linkable-tree/Cargo.toml b/pallets/linkable-tree/Cargo.toml index 5808a77d0..945b6c7d7 100644 --- a/pallets/linkable-tree/Cargo.toml +++ b/pallets/linkable-tree/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Webb Technologies Inc."] -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-linkable-tree" diff --git a/pallets/mixer/Cargo.toml b/pallets/mixer/Cargo.toml index f831f7877..ac525dda5 100644 --- a/pallets/mixer/Cargo.toml +++ b/pallets/mixer/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Webb Technologies Inc."] -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-mixer" diff --git a/pallets/mixer/src/mock.rs b/pallets/mixer/src/mock.rs index b4b7c1844..2591c14ae 100644 --- a/pallets/mixer/src/mock.rs +++ b/pallets/mixer/src/mock.rs @@ -35,8 +35,8 @@ frame_support::construct_runtime!( Balances: pallet_balances::{Pallet, Call, Storage, Event}, HasherPallet: pallet_hasher::{Pallet, Call, Storage, Event}, VerifierPallet: pallet_verifier::{Pallet, Call, Storage, Event}, - MerkleTree: pallet_mt::{Pallet, Call, Storage, Event}, - Mixer: pallet_mixer::{Pallet, Call, Storage, Event}, + MerkleTree: pallet_mt::::{Pallet, Call, Storage, Event}, + Mixer: pallet_mixer::::{Pallet, Call, Storage, Event}, AssetRegistry: pallet_asset_registry::{Pallet, Call, Storage, Event}, Currencies: orml_currencies::{Pallet, Call}, Tokens: orml_tokens::{Pallet, Storage, Call, Event}, @@ -155,7 +155,8 @@ parameter_types! { pub const MaxDefaultHashes: u32 = 1000; } -impl pallet_mt::Config for Test { +type MerkleInstance1 = pallet_mt::Instance1; +impl pallet_mt::Config for Test { type Currency = Balances; type DataDepositBase = LeafDepositBase; type DataDepositPerByte = LeafDepositPerByte; @@ -213,6 +214,18 @@ impl pallet_asset_registry::Config for Test { type WeightInfo = (); } +type MixerInstance1 = pallet_mixer::Instance1; +impl pallet_mixer::Config for Test { + type Currency = Currencies; + type RuntimeEvent = RuntimeEvent; + type NativeCurrencyId = NativeCurrencyId; + type PalletId = MixerPalletId; + type Tree = MerkleTree; + type Verifier = VerifierPallet; + type ArbitraryHasher = Keccak256HasherBn254; + type WeightInfo = (); +} + /// Tokens Configurations impl orml_tokens::Config for Test { type Amount = Amount; @@ -242,17 +255,6 @@ parameter_types! { pub const NativeCurrencyId: AssetId = 0; } -impl Config for Test { - type Currency = Currencies; - type RuntimeEvent = RuntimeEvent; - type NativeCurrencyId = NativeCurrencyId; - type PalletId = MixerPalletId; - type Tree = MerkleTree; - type Verifier = VerifierPallet; - type ArbitraryHasher = Keccak256HasherBn254; - type WeightInfo = (); -} - // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { use sp_runtime::traits::Zero; diff --git a/pallets/mixer/src/tests.rs b/pallets/mixer/src/tests.rs index 256644b4d..42ba10146 100644 --- a/pallets/mixer/src/tests.rs +++ b/pallets/mixer/src/tests.rs @@ -1,3 +1,4 @@ +use crate::Instance1; use arkworks_setups::{common::setup_params, Curve}; use codec::Encode; use frame_benchmarking::account; @@ -44,10 +45,11 @@ fn setup_environment(curve: Curve) -> Vec { // 3. Setup the VerifierPallet // but to do so, we need to have a VerifyingKey let pk_bytes = include_bytes!( - "../../../substrate-fixtures/mixer/bn254/x5/proving_key_uncompressed.bin" + "../../../substrate-fixtures/substrate-fixtures/mixer/bn254/x5/proving_key_uncompressed.bin" + ); + let vk_bytes = include_bytes!( + "../../../substrate-fixtures/substrate-fixtures/mixer/bn254/x5/verifying_key.bin" ); - let vk_bytes = - include_bytes!("../../../substrate-fixtures/mixer/bn254/x5/verifying_key.bin"); assert_ok!(VerifierPallet::force_set_parameters( RuntimeOrigin::root(), @@ -282,7 +284,7 @@ fn mixer_should_fail_when_invalid_merkle_roots() { fee_value, refund_value, ), - crate::Error::::UnknownRoot + crate::Error::::UnknownRoot ); }); } @@ -337,7 +339,7 @@ fn mixer_should_fail_when_relayer_id_is_different_from_that_in_proof_generation( fee_value, refund_value, ), - crate::Error::::InvalidWithdrawProof + crate::Error::::InvalidWithdrawProof ); }); } @@ -392,7 +394,7 @@ fn mixer_should_fail_with_when_fee_submitted_is_changed() { 100u128, refund_value, ), - crate::Error::::InvalidWithdrawProof + crate::Error::::InvalidWithdrawProof ); }); } @@ -447,7 +449,7 @@ fn mixer_should_fail_with_invalid_proof_when_account_ids_are_truncated_in_revers fee_value, refund_value, ), - crate::Error::::InvalidWithdrawProof + crate::Error::::InvalidWithdrawProof ); }); } @@ -520,7 +522,7 @@ fn double_spending_should_fail() { fee_value, refund_value, ), - crate::Error::::AlreadyRevealedNullifier + crate::Error::::AlreadyRevealedNullifier ); }); } diff --git a/pallets/mt/Cargo.toml b/pallets/mt/Cargo.toml index b9169db64..d2b0c8f6b 100644 --- a/pallets/mt/Cargo.toml +++ b/pallets/mt/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Webb Technologies Inc."] -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-mt" diff --git a/pallets/relayer-registry/Cargo.toml b/pallets/relayer-registry/Cargo.toml index 15acaf44c..ff610914f 100644 --- a/pallets/relayer-registry/Cargo.toml +++ b/pallets/relayer-registry/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "A pallet that maintains relayer configuration metadata." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-relayer-registry" diff --git a/pallets/signature-bridge/Cargo.toml b/pallets/signature-bridge/Cargo.toml index 19486efae..4d0470c83 100644 --- a/pallets/signature-bridge/Cargo.toml +++ b/pallets/signature-bridge/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "FRAME pallet for Webb bridge." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-signature-bridge" diff --git a/pallets/token-wrapper-handler/Cargo.toml b/pallets/token-wrapper-handler/Cargo.toml index 5e5f7932e..5e93e2156 100644 --- a/pallets/token-wrapper-handler/Cargo.toml +++ b/pallets/token-wrapper-handler/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "A token wrapper handler for the bridging system" -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-token-wrapper-handler" diff --git a/pallets/token-wrapper/Cargo.toml b/pallets/token-wrapper/Cargo.toml index 83428c1cd..8788651ae 100644 --- a/pallets/token-wrapper/Cargo.toml +++ b/pallets/token-wrapper/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "A pallet for maintaing wrapping relationships for various tokens." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-token-wrapper" diff --git a/pallets/vanchor-handler/Cargo.toml b/pallets/vanchor-handler/Cargo.toml index 41a931157..bb7a957e8 100644 --- a/pallets/vanchor-handler/Cargo.toml +++ b/pallets/vanchor-handler/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "FRAME pallet for Webb anchor-handler." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-vanchor-handler" diff --git a/pallets/vanchor-verifier/Cargo.toml b/pallets/vanchor-verifier/Cargo.toml index c2b8f3c73..8c0528500 100644 --- a/pallets/vanchor-verifier/Cargo.toml +++ b/pallets/vanchor-verifier/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "A pallet that stores zero-knowledge verifier parameters and provides verification of zero-knowledge proofs for VAnchors." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-vanchor-verifier" diff --git a/pallets/vanchor-verifier/src/lib.rs b/pallets/vanchor-verifier/src/lib.rs index baa43a580..aec3a89df 100644 --- a/pallets/vanchor-verifier/src/lib.rs +++ b/pallets/vanchor-verifier/src/lib.rs @@ -148,7 +148,7 @@ pub mod pallet { #[pallet::error] pub enum Error { /// Parameters haven't been initialized - ParametersNotInitialized, + VerifyingParametersNotInitialized, /// Error during verification VerifyError, } @@ -182,7 +182,7 @@ impl, I: 'static> VAnchorVerifierModule for Pallet { num_inputs: u8, ) -> Result { let params = Self::parameters((num_anchors, num_inputs)); - ensure!(!params.is_empty(), Error::::ParametersNotInitialized); + ensure!(!params.is_empty(), Error::::VerifyingParametersNotInitialized); match T::Verifier::verify(public_inp_bytes, proof, ¶ms) { Ok(verified) => Ok(verified), Err(e) => { diff --git a/pallets/vanchor-verifier/src/tests.rs b/pallets/vanchor-verifier/src/tests.rs index d2ec7439e..8ecac78ff 100644 --- a/pallets/vanchor-verifier/src/tests.rs +++ b/pallets/vanchor-verifier/src/tests.rs @@ -8,7 +8,7 @@ fn should_fail_to_verify_without_parameters() { // Pass arbitrary assert_err!( ::verify(&[], &[1u8; 32], 0, 0), - Error::::ParametersNotInitialized + Error::::VerifyingParametersNotInitialized ); }); } diff --git a/pallets/vanchor/Cargo.toml b/pallets/vanchor/Cargo.toml index 0c1e7b9be..deef37fcd 100644 --- a/pallets/vanchor/Cargo.toml +++ b/pallets/vanchor/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Webb Technologies Inc."] -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-vanchor" @@ -13,71 +13,77 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] } -ark-ff = { version = "^0.3.0", default-features = false } -ark-std = { version = "^0.3.0", default-features = false } -arkworks-native-gadgets = { version = "1.2.0", default-features = false } -arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false } -frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", optional = true } frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", optional = true } -getrandom = { version = "0.2", features = ["js"] } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } -pallet-asset-registry = { path = "../asset-registry", default-features = false } -pallet-hasher = { path = "../hasher", default-features = false } -pallet-linkable-tree = { path = "../linkable-tree", default-features = false } -pallet-mt = { path = "../mt", default-features = false } -pallet-token-wrapper = { path = "../token-wrapper", default-features = false } -pallet-vanchor-verifier = { path = "../vanchor-verifier", default-features = false } -sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +pallet-linkable-tree = { path = "../linkable-tree", default-features = false } +pallet-mt = { path = "../mt", default-features = false } webb-primitives = { path = "../../primitives", default-features = false, features = ["hashing", "verifying", "field_ops"] } +orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } +pallet-asset-registry = { path = "../asset-registry", default-features = false } +pallet-token-wrapper = { path = "../token-wrapper", default-features = false } +frame-system-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36", optional = true } +arkworks-native-gadgets = { version = "1.2.0", default-features = false } +ark-std = { version = "^0.3.0", default-features = false } +ark-bn254 = { version = "^0.3.0", default-features = false, features = [ "curve" ] } +ark-ff = { version = "^0.3.0", default-features = false} [dev-dependencies] -ark-bls12-381 = { version = "^0.3.0", default-features = false, features = ["curve"] } -ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"] } -ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false } -ark-ec = { version = "^0.3.0", default-features = false } -ark-ff = { version = "^0.3.0", default-features = false } -ark-groth16 = { version = "^0.3.0", default-features = false } -ark-relations = { version = "^0.3.0", default-features = false } -ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] } -ark-std = { version = "^0.3.0", default-features = false } -orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } -orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-key-storage = { path = "../key-storage" } -pallet-treasury = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +hex = "0.4" rand = "0.8.4" serde = { version = "1.0.119" } sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +pallet-treasury = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +pallet-key-storage = {path = "../key-storage"} +pallet-hasher = { path = "../hasher", default-features = false } +pallet-vanchor-verifier = { path = "../vanchor-verifier", default-features = false } +orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } +orml-currencies = { git = "https://github.com/open-web3-stack/open-runtime-module-library.git", branch = "polkadot-v0.9.36", default-features = false } +arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false } +ark-crypto-primitives = { version = "^0.3.0", features = ["r1cs"], default-features = false } +ark-ff = { version = "0.3.0", default-features = false, features = [ "asm"] } +ark-ec = { version = "^0.3.0", default-features = false } +ark-relations = { version = "^0.3.0", default-features = false } +ark-serialize = { version = "^0.3.0", default-features = false, features = [ "derive" ] } +ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", default-features = false, features = ["parallel"] } +ark-std = { version = "^0.3.0", default-features = false } +ark-bn254 = { version = "0.3.0" } +ark-circom = { git = "https://github.com/vacp2p/ark-circom", branch = "wasm", default-features = false, features = ["circom-2"] } +num-bigint = { version = "0.4", default-features = false, features = ["rand"] } +frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +# For ark-circom +once_cell = "1.14.0" +cfg-if = "1.0" +wasmer = { version = "2.3.0", default-features = false } +num-traits = "0.2.11" +thiserror = "1.0.0" +color-eyre = "0.6.1" +serde_json = "1.0.48" [features] -default = ["std"] -runtime-benchmarks = [ - "frame-benchmarking", - "frame-system/runtime-benchmarks", - "frame-support/runtime-benchmarks", -] +default = ["std", "wasmer/sys-default"] std = [ - "codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "sp-runtime/std", - "sp-std/std", - "pallet-hasher/std", - "pallet-linkable-tree/std", - "pallet-vanchor-verifier/std", - "pallet-asset-registry/std", - "webb-primitives/std", - "frame-benchmarking/std", - "pallet-token-wrapper/std", - "ark-std/std", + "codec/std", + "scale-info/std", + "frame-support/std", + "frame-system/std", + "sp-runtime/std", + "sp-std/std", + "pallet-hasher/std", + "pallet-linkable-tree/std", + "pallet-asset-registry/std", + "webb-primitives/std", + "frame-benchmarking/std", + "pallet-token-wrapper/std", + "ark-std/std" +] +runtime-benchmarks = [ + "frame-system/runtime-benchmarks", + "frame-support/runtime-benchmarks", ] +wasm = ["wasmer/js", "wasmer/std"] \ No newline at end of file diff --git a/pallets/vanchor/src/benchmarking.rs b/pallets/vanchor/src/benchmarking.rs index c37eb747c..6f1149d6f 100644 --- a/pallets/vanchor/src/benchmarking.rs +++ b/pallets/vanchor/src/benchmarking.rs @@ -68,20 +68,22 @@ where // but to do so, we need to have a VerifyingKey let pk_2_2_bytes = include_bytes!( - "../../../substrate-fixtures/vanchor/bn254/x5/2-2-2/proving_key_uncompressed.bin" + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-2-2/proving_key_uncompressed.bin" + ) + .to_vec(); + let vk_2_2_bytes = include_bytes!( + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key.bin" ) .to_vec(); - let vk_2_2_bytes = - include_bytes!("../../../substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key.bin") - .to_vec(); let pk_2_16_bytes = include_bytes!( - "../../../substrate-fixtures/vanchor/bn254/x5/2-16-2/proving_key_uncompressed.bin" + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-16-2/proving_key_uncompressed.bin" + ) + .to_vec(); + let vk_2_16_bytes = include_bytes!( + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-16-2/verifying_key.bin" ) .to_vec(); - let vk_2_16_bytes = - include_bytes!("../../../substrate-fixtures/vanchor/bn254/x5/2-16-2/verifying_key.bin") - .to_vec(); assert_ok!(>::force_set_parameters( RawOrigin::Root.into(), @@ -118,24 +120,23 @@ benchmarks_instance_pallet! { pallet_linkable_tree::Pallet: webb_primitives::linkable_tree::LinkableTreeInspector> } create { - let i in 1..MAX_EDGES; - let d in 1..>::MaxTreeDepth::get() as u32; + let i in 1..MAX_EDGES; + let d in 1..>::MaxTreeDepth::get() as u32; pallet_hasher::Pallet::::force_set_parameters(RawOrigin::Root.into(), hasher_params().try_into().unwrap()).unwrap(); - let asset_id = <>::NativeCurrencyId as Get>>::get(); + let asset_id = <>::NativeCurrencyId as Get>>::get(); }: _(RawOrigin::Root, i, d as u8, asset_id) verify { assert_last_event::(Event::VAnchorCreation{ tree_id : 0_u32.into() }.into()) } transact { - let pk_2_2_bytes = setup_env::(); let deposit_size: u32 = 50_000_000; let asset_id = <>::NativeCurrencyId as Get>>::get(); - let depth = >::MaxTreeDepth::get(); + let depth = >::MaxTreeDepth::get(); let tree_id = as VAnchorInterface>>::create(None, depth, 1u32, asset_id, 1u32.into())?; @@ -202,10 +203,9 @@ benchmarks_instance_pallet! { // Constructing proof data let proof_data = ProofData::new(proof, public_amount, root_set, nullifiers, commitments, ext_data_hash); - - }: _(RawOrigin::Signed(transactor.clone()), tree_id, proof_data.clone(), ext_data) - verify { - assert_last_event::( + }: _(RawOrigin::Signed(transactor.clone()), tree_id, proof_data.clone(), ext_data) + verify { + assert_last_event::( Event::Transaction { transactor, tree_id, @@ -217,13 +217,10 @@ benchmarks_instance_pallet! { } register_and_transact { - let pk_2_2_bytes = setup_env::(); - - let deposit_size: u32 = 50_000_000; let asset_id = <>::NativeCurrencyId as Get>>::get(); - let depth = >::MaxTreeDepth::get(); + let depth = >::MaxTreeDepth::get(); let tree_id = as VAnchorInterface>>::create(None, depth, 1u32, asset_id, 1u32.into())?; @@ -290,33 +287,30 @@ benchmarks_instance_pallet! { // Constructing proof data let proof_data = ProofData::new(proof, public_amount, root_set, nullifiers, commitments, ext_data_hash); - - }: _(RawOrigin::Signed(transactor.clone()), transactor.clone(),[0u8; 32].to_vec(),tree_id, proof_data.clone(), ext_data) - verify { + }: _(RawOrigin::Signed(transactor.clone()), transactor.clone(),[0u8; 32].to_vec(),tree_id, proof_data.clone(), ext_data) + verify { assert_last_event::( - Event::Transaction { - transactor, - tree_id, - leafs : proof_data.output_commitments, - encrypted_output1: output1.to_vec(), - encrypted_output2: output2.to_vec(), - amount : ext_amount.into() }.into() - ) - } + Event::Transaction { + transactor, + tree_id, + leafs : proof_data.output_commitments, + encrypted_output1: output1.to_vec(), + encrypted_output2: output2.to_vec(), + amount : ext_amount.into() }.into() + ) + } set_max_deposit_amount { - }: _(RawOrigin::Root, 100u32.into(), 101u32.into()) - verify { - assert_last_event::(Event::MaxDepositAmountChanged{ max_deposit_amount : 100_u32.into() }.into()) + }: _(RawOrigin::Root, 100u32.into(), 101u32.into()) + verify { + assert_last_event::(Event::MaxDepositAmountChanged{ max_deposit_amount : 100_u32.into() }.into()) } set_min_withdraw_amount { }: _(RawOrigin::Root, 1u32.into(), 101u32.into()) verify { assert_last_event::(Event::MinWithdrawAmountChanged{ min_withdraw_amount : 1_u32.into() }.into()) - } - - + } } impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); diff --git a/pallets/vanchor/src/lib.rs b/pallets/vanchor/src/lib.rs index d2af3ae8f..45f886c5b 100644 --- a/pallets/vanchor/src/lib.rs +++ b/pallets/vanchor/src/lib.rs @@ -46,6 +46,10 @@ pub mod mock; mod test_utils; #[cfg(test)] mod tests; +#[cfg(test)] +mod tests_circom; +#[cfg(test)] +mod zerokit_utils; mod benchmarking; mod benchmarking_utils; @@ -704,19 +708,34 @@ impl, I: 'static> Pallet { abs_amount <= MaxDepositAmount::::get(), Error::::InvalidDepositAmount ); - // Deposit tokens to the pallet from the transactor's account - >::Currency::transfer( - vanchor.asset, - transactor, - &Self::account_id(), - abs_amount, - )?; + // If the token is not the same as the vanchor asset then + // we need to wrap the tokens into the vanchor asset + if ext_data.token != vanchor.asset { + // Wrap tokens from the transactor's account + T::TokenWrapper::wrap( + transactor.clone(), + ext_data.token, + vanchor.asset, + abs_amount, + Self::account_id(), + )?; + } else { + // Deposit tokens to the pallet from the transactor's account + >::Currency::transfer( + vanchor.asset, + transactor, + &Self::account_id(), + abs_amount, + )?; + } } else if is_negative { ensure!( abs_amount >= MinWithdrawAmount::::get(), Error::::InvalidWithdrawAmount ); - if ext_data.token != T::MaxCurrencyId::get() { + // If the token is not the same as the vanchor asset then + // we need to unwrap the tokens from the vanchor asset + if ext_data.token != vanchor.asset { // Unwrap to recipient account T::TokenWrapper::unwrap( Self::account_id(), diff --git a/pallets/vanchor/src/mock.rs b/pallets/vanchor/src/mock.rs index 2530a0697..f4b23674b 100644 --- a/pallets/vanchor/src/mock.rs +++ b/pallets/vanchor/src/mock.rs @@ -21,7 +21,10 @@ pub use webb_primitives::{ types::{ElementTrait, IntoAbiToken}, AccountId, Element, }; -use webb_primitives::{hashing::ArkworksPoseidonHasherBn254, verifying::ArkworksVerifierBn254}; +use webb_primitives::{ + hashing::ArkworksPoseidonHasherBn254, + verifying::{ArkworksVerifierBn254, CircomVerifierBn254}, +}; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -45,17 +48,27 @@ frame_support::construct_runtime!( { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Event}, - HasherPallet: pallet_hasher::{Pallet, Call, Storage, Event}, - VAnchorVerifier: pallet_vanchor_verifier::{Pallet, Call, Storage, Event}, - MerkleTree: pallet_mt::{Pallet, Call, Storage, Event}, - LinkableTree: pallet_linkable_tree::{Pallet, Call, Storage, Event}, Currencies: orml_currencies::{Pallet, Call}, Tokens: orml_tokens::{Pallet, Storage, Call, Event}, AssetRegistry: pallet_asset_registry::{Pallet, Call, Storage, Event}, - VAnchor: pallet_vanchor::{Pallet, Call, Storage, Event}, Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event}, TokenWrapper: pallet_token_wrapper::{Pallet, Call, Storage, Event}, - KeyStorage: pallet_key_storage::{Pallet, Call, Storage, Event, Config} + KeyStorage: pallet_key_storage::{Pallet, Call, Storage, Event, Config}, + + Hasher1: pallet_hasher::::{Pallet, Call, Storage, Event}, + Hasher2: pallet_hasher::::{Pallet, Call, Storage, Event}, + + MerkleTree1: pallet_mt::::{Pallet, Call, Storage, Event}, + MerkleTree2: pallet_mt::::{Pallet, Call, Storage, Event}, + + LinkableTree1: pallet_linkable_tree::::{Pallet, Call, Storage, Event}, + LinkableTree2: pallet_linkable_tree::::{Pallet, Call, Storage, Event}, + + VAnchorVerifier1: pallet_vanchor_verifier::::{Pallet, Call, Storage, Event}, + VAnchorVerifier2: pallet_vanchor_verifier::::{Pallet, Call, Storage, Event}, + + VAnchor1: pallet_vanchor::::{Pallet, Call, Storage, Event}, + VAnchor2: pallet_vanchor::::{Pallet, Call, Storage, Event}, } ); @@ -114,7 +127,8 @@ parameter_types! { pub const MetadataDepositPerByte: u64 = 1; } -impl pallet_vanchor_verifier::Config for Test { +type VAnchorVerifierInstance1 = pallet_vanchor_verifier::Instance1; +impl pallet_vanchor_verifier::Config for Test { type RuntimeEvent = RuntimeEvent; type ForceOrigin = frame_system::EnsureRoot; type MaxParameterLength = ConstU32<10000>; @@ -122,7 +136,26 @@ impl pallet_vanchor_verifier::Config for Test { type WeightInfo = (); } -impl pallet_hasher::Config for Test { +type VAnchorVerifierInstance2 = pallet_vanchor_verifier::Instance2; +impl pallet_vanchor_verifier::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ForceOrigin = frame_system::EnsureRoot; + type MaxParameterLength = ConstU32<10000>; + type Verifier = CircomVerifierBn254; + type WeightInfo = (); +} + +type HasherInstance1 = pallet_hasher::Instance1; +impl pallet_hasher::Config for Test { + type RuntimeEvent = RuntimeEvent; + type ForceOrigin = frame_system::EnsureRoot; + type MaxParameterLength = ConstU32<10000>; + type Hasher = ArkworksPoseidonHasherBn254; + type WeightInfo = (); +} + +type HasherInstance2 = pallet_hasher::Instance2; +impl pallet_hasher::Config for Test { type RuntimeEvent = RuntimeEvent; type ForceOrigin = frame_system::EnsureRoot; type MaxParameterLength = ConstU32<10000>; @@ -151,7 +184,8 @@ parameter_types! { pub const MaxDefaultHashes: u32 = 1000; } -impl pallet_mt::Config for Test { +type MerkleInstance1 = pallet_mt::Instance1; +impl pallet_mt::Config for Test { type Currency = Balances; type DataDepositBase = LeafDepositBase; type DataDepositPerByte = LeafDepositPerByte; @@ -161,7 +195,30 @@ impl pallet_mt::Config for Test { type MaxDefaultHashes = MaxDefaultHashes; type RuntimeEvent = RuntimeEvent; type ForceOrigin = frame_system::EnsureRoot; - type Hasher = HasherPallet; + type Hasher = Hasher1; + type LeafIndex = u32; + type MaxTreeDepth = MaxTreeDepth; + type RootHistorySize = RootHistorySize; + type RootIndex = u32; + type StringLimit = StringLimit; + type TreeDeposit = TreeDeposit; + type TreeId = u32; + type Two = Two; + type WeightInfo = (); +} + +type MerkleInstance2 = pallet_mt::Instance2; +impl pallet_mt::Config for Test { + type Currency = Balances; + type DataDepositBase = LeafDepositBase; + type DataDepositPerByte = LeafDepositPerByte; + type DefaultZeroElement = DefaultZeroElement; + type Element = Element; + type MaxEdges = MaxEdges; + type MaxDefaultHashes = MaxDefaultHashes; + type RuntimeEvent = RuntimeEvent; + type ForceOrigin = frame_system::EnsureRoot; + type Hasher = Hasher2; type LeafIndex = u32; type MaxTreeDepth = MaxTreeDepth; type RootHistorySize = RootHistorySize; @@ -180,13 +237,25 @@ parameter_types! { pub const ChainIdentifier: ChainId = 1; } -impl pallet_linkable_tree::Config for Test { +type LinkableTreeInstance1 = pallet_linkable_tree::Instance1; +impl pallet_linkable_tree::Config for Test { + type ChainId = ChainId; + type ChainType = ChainType; + type ChainIdentifier = ChainIdentifier; + type RuntimeEvent = RuntimeEvent; + type HistoryLength = HistoryLength; + type Tree = MerkleTree1; + type WeightInfo = (); +} + +type LinkableTreeInstance2 = pallet_linkable_tree::Instance2; +impl pallet_linkable_tree::Config for Test { type ChainId = ChainId; type ChainType = ChainType; type ChainIdentifier = ChainIdentifier; type RuntimeEvent = RuntimeEvent; type HistoryLength = HistoryLength; - type Tree = MerkleTree; + type Tree = MerkleTree2; type WeightInfo = (); } @@ -291,12 +360,33 @@ parameter_types! { pub const MaxCurrencyId: AssetId = AssetId::MAX - 1; } -impl pallet_vanchor::Config for Test { +type VAnchorInstance1 = pallet_vanchor::Instance1; +impl pallet_vanchor::Config for Test { + type Currency = Currencies; + type EthereumHasher = Keccak256HasherBn254; + type RuntimeEvent = RuntimeEvent; + type IntoField = ArkworksIntoFieldBn254; + type LinkableTree = LinkableTree1; + type NativeCurrencyId = NativeCurrencyId; + type PalletId = VAnchorPalletId; + type MaxFee = MaxFee; + type MaxExtAmount = MaxExtAmount; + type MaxCurrencyId = MaxCurrencyId; + type ProposalNonce = u32; + type TokenWrapper = TokenWrapper; + type PostDepositHook = (); + type VAnchorVerifier = VAnchorVerifier1; + type KeyStorage = KeyStorage; + type WeightInfo = (); +} + +type VAnchorInstance2 = pallet_vanchor::Instance2; +impl pallet_vanchor::Config for Test { type Currency = Currencies; type EthereumHasher = Keccak256HasherBn254; type RuntimeEvent = RuntimeEvent; type IntoField = ArkworksIntoFieldBn254; - type LinkableTree = LinkableTree; + type LinkableTree = LinkableTree2; type NativeCurrencyId = NativeCurrencyId; type PalletId = VAnchorPalletId; type MaxFee = MaxFee; @@ -305,7 +395,7 @@ impl pallet_vanchor::Config for Test { type ProposalNonce = u32; type TokenWrapper = TokenWrapper; type PostDepositHook = (); - type VAnchorVerifier = VAnchorVerifier; + type VAnchorVerifier = VAnchorVerifier2; type KeyStorage = KeyStorage; type WeightInfo = (); } diff --git a/pallets/vanchor/src/test_utils.rs b/pallets/vanchor/src/test_utils.rs index 5ccd4bf77..304a7b389 100644 --- a/pallets/vanchor/src/test_utils.rs +++ b/pallets/vanchor/src/test_utils.rs @@ -1,4 +1,16 @@ +use crate::tests::{ + BIGGER_DEFAULT_BALANCE, BIGGER_TRANSACTOR_ACCOUNT_ID, BIG_DEFAULT_BALANCE, + BIG_TRANSACTOR_ACCOUNT_ID, DEFAULT_BALANCE, RELAYER_ACCOUNT_ID, SEED, TRANSACTOR_ACCOUNT_ID, +}; +use ark_bn254::Fr; +use ark_circom::WitnessCalculator; use ark_ff::{BigInteger, PrimeField}; +use ark_groth16::{ + create_proof_with_reduction_and_matrices, create_random_proof as prove, + generate_random_parameters, prepare_verifying_key, verify_proof as ark_verify_proof, + Proof as ArkProof, ProvingKey, VerifyingKey, +}; +use ark_relations::r1cs::ConstraintMatrices; use ark_std::{rand::thread_rng, vec::Vec}; use arkworks_native_gadgets::poseidon::Poseidon; use arkworks_setups::{ @@ -7,7 +19,8 @@ use arkworks_setups::{ utxo::Utxo, Curve, VAnchorProver, }; -use std::{collections::BTreeMap, convert::TryInto}; +use num_bigint::BigInt; +use std::{collections::BTreeMap, convert::TryInto, sync::Mutex}; use webb_primitives::ElementTrait; use crate::mock::Element; @@ -15,9 +28,9 @@ use crate::mock::Element; type Bn254Fr = ark_bn254::Fr; type Bn254 = ark_bn254::Bn254; -const TREE_DEPTH: usize = 30; -const ANCHOR_CT: usize = 2; -const NUM_UTXOS: usize = 2; +pub const TREE_DEPTH: usize = 30; +pub const ANCHOR_CT: usize = 2; +pub const NUM_UTXOS: usize = 2; pub const DEFAULT_LEAF: [u8; 32] = [ 47, 229, 76, 96, 211, 172, 171, 243, 52, 58, 53, 182, 235, 161, 93, 180, 130, 27, 52, 15, 118, 231, 65, 226, 36, 150, 133, 237, 72, 153, 175, 108, @@ -27,6 +40,298 @@ pub const DEFAULT_LEAF: [u8; 32] = [ type VAnchorProver_Bn254_30_2_2_2 = VAnchorR1CSProver; +use crate::{mock::*, zerokit_utils::*, Instance2}; +use ark_bn254::{Fq, Fq2, G1Affine, G1Projective, G2Affine, G2Projective}; +use ark_circom::{read_zkey, CircomConfig, CircomReduction}; +use ark_ff::{BigInteger256, ToBytes}; +use ark_relations::r1cs::SynthesisError; +use ark_std::UniformRand; +use arkworks_native_gadgets::merkle_tree::{Path, SparseMerkleTree}; +use cfg_if::cfg_if; +use frame_benchmarking::account; +use frame_support::{assert_ok, traits::OnInitialize}; +use num_bigint::{BigUint, Sign}; +use once_cell::sync::OnceCell; +use pallet_linkable_tree::LinkableTreeConfigration; +use serde_json::Value; +use sp_core::hashing::keccak_256; +use std::{ + convert::TryFrom, + fs::{self, File}, + io::{Cursor, Error, ErrorKind}, + result::Result, + str::FromStr, +}; +use thiserror::Error; +use wasmer::{Module, Store}; +use webb_primitives::{ + linkable_tree::LinkableTreeInspector, + merkle_tree::TreeInspector, + types::vanchor::{ExtData, ProofData}, + utils::compute_chain_id_type, + verifying::CircomError, + AccountId, +}; + +#[derive(Error, Debug)] +pub enum ProofError { + #[error("Error reading circuit key: {0}")] + CircuitKeyError(#[from] std::io::Error), + #[error("Error producing witness: {0}")] + WitnessError(color_eyre::Report), + #[error("Error producing proof: {0}")] + SynthesisError(#[from] SynthesisError), +} + +#[cfg(not(target_arch = "wasm32"))] +static WITNESS_CALCULATOR: OnceCell> = OnceCell::new(); + +// Utilities to convert a json verification key in a groth16::VerificationKey +fn fq_from_str(s: &str) -> Fq { + Fq::try_from(BigUint::from_str(s).unwrap()).unwrap() +} + +// Extracts the element in G1 corresponding to its JSON serialization +fn json_to_g1(json: &Value, key: &str) -> G1Affine { + let els: Vec = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| i.as_str().unwrap().to_string()) + .collect(); + G1Affine::from(G1Projective::new( + fq_from_str(&els[0]), + fq_from_str(&els[1]), + fq_from_str(&els[2]), + )) +} + +// Extracts the vector of G1 elements corresponding to its JSON serialization +fn json_to_g1_vec(json: &Value, key: &str) -> Vec { + let els: Vec> = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| { + i.as_array() + .unwrap() + .iter() + .map(|x| x.as_str().unwrap().to_string()) + .collect::>() + }) + .collect(); + + els.iter() + .map(|coords| { + G1Affine::from(G1Projective::new( + fq_from_str(&coords[0]), + fq_from_str(&coords[1]), + fq_from_str(&coords[2]), + )) + }) + .collect() +} + +// Extracts the element in G2 corresponding to its JSON serialization +fn json_to_g2(json: &Value, key: &str) -> G2Affine { + let els: Vec> = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| { + i.as_array() + .unwrap() + .iter() + .map(|x| x.as_str().unwrap().to_string()) + .collect::>() + }) + .collect(); + + let x = Fq2::new(fq_from_str(&els[0][0]), fq_from_str(&els[0][1])); + let y = Fq2::new(fq_from_str(&els[1][0]), fq_from_str(&els[1][1])); + let z = Fq2::new(fq_from_str(&els[2][0]), fq_from_str(&els[2][1])); + G2Affine::from(G2Projective::new(x, y, z)) +} + +// Converts JSON to a VerifyingKey +fn to_verifying_key(json: serde_json::Value) -> VerifyingKey { + VerifyingKey { + alpha_g1: json_to_g1(&json, "vk_alpha_1"), + beta_g2: json_to_g2(&json, "vk_beta_2"), + gamma_g2: json_to_g2(&json, "vk_gamma_2"), + delta_g2: json_to_g2(&json, "vk_delta_2"), + gamma_abc_g1: json_to_g1_vec(&json, "IC"), + } +} + +// Computes the verification key from its JSON serialization +fn vk_from_json(vk_path: &str) -> VerifyingKey { + let json = std::fs::read_to_string(vk_path).unwrap(); + let json: Value = serde_json::from_str(&json).unwrap(); + + to_verifying_key(json) +} + +pub fn generate_proof( + #[cfg(not(target_arch = "wasm32"))] witness_calculator: &Mutex, + #[cfg(target_arch = "wasm32")] witness_calculator: &mut WitnessCalculator, + proving_key: &(ProvingKey, ConstraintMatrices), + vanchor_witness: [(&str, Vec); 15], +) -> Result<(ArkProof, Vec), ProofError> { + let inputs = vanchor_witness + .into_iter() + .map(|(name, values)| (name.to_string(), values.clone())); + + println!("inputs {:?}", inputs); + + cfg_if! { + if #[cfg(target_arch = "wasm32")] { + let full_assignment = witness_calculator + .calculate_witness_element::(inputs, false) + .map_err(ProofError::WitnessError)?; + } else { + let full_assignment = witness_calculator + .lock() + .expect("witness_calculator mutex should not get poisoned") + .calculate_witness_element::(inputs, false) + .map_err(ProofError::WitnessError)?; + } + } + + // Random Values + let mut rng = thread_rng(); + let r = Fr::rand(&mut rng); + let s = Fr::rand(&mut rng); + + let proof = create_proof_with_reduction_and_matrices::<_, CircomReduction>( + &proving_key.0, + r, + s, + &proving_key.1, + proving_key.1.num_instance_variables, + proving_key.1.num_constraints, + full_assignment.as_slice(), + )?; + + Ok((proof, full_assignment)) +} + +/// Verifies a given RLN proof +/// +/// # Errors +/// +/// Returns a [`ProofError`] if verifying fails. Verification failure does not +/// necessarily mean the proof is incorrect. +pub fn verify_proof( + verifying_key: &VerifyingKey, + proof: &ArkProof, + inputs: Vec, +) -> Result { + // Check that the proof is valid + let pvk = prepare_verifying_key(verifying_key); + //let pr: ArkProof = (*proof).into(); + + let verified = ark_verify_proof(&pvk, proof, &inputs)?; + + Ok(verified) +} + +// Initializes the witness calculator using a bytes vector +#[cfg(not(target_arch = "wasm32"))] +pub fn circom_from_raw(wasm_buffer: Vec) -> &'static Mutex { + WITNESS_CALCULATOR.get_or_init(|| { + let store = Store::default(); + let module = Module::new(&store, wasm_buffer).unwrap(); + let result = + WitnessCalculator::from_module(module).expect("Failed to create witness calculator"); + Mutex::new(result) + }) +} + +// Initializes the witness calculator +#[cfg(not(target_arch = "wasm32"))] +pub fn circom_from_folder(wasm_path: &str) -> &'static Mutex { + // We read the wasm file + let wasm_buffer = std::fs::read(wasm_path).unwrap(); + circom_from_raw(wasm_buffer) +} + +fn setup_environment_with_circom( +) -> ((ProvingKey, ConstraintMatrices), &'static Mutex) { + let curve = Curve::Bn254; + let params3 = setup_params::(curve, 5, 3); + // 1. Setup The Hasher Pallet. + println!("Setting up the hasher pallet"); + assert_ok!(Hasher2::force_set_parameters( + RuntimeOrigin::root(), + params3.to_bytes().try_into().unwrap() + )); + // 2. Initialize Merkle pallet. + println!("Initializing the merkle tree pallet"); + >::on_initialize(1); + // 3. Setup the VerifierPallet + // but to do so, we need to have a VerifyingKey + + // Load the WASM and R1CS for witness and proof generation + // Get path to solidity fixtures + println!("Setting up the verifier pallet"); + // let wasm_2_2_path = fs::canonicalize( + // "../../solidity-fixtures/solidity-fixtures/vanchor_2/2/poseidon_vanchor_2_2.wasm", + // ); + // let r1cs_2_2_path = fs::canonicalize( + // "../../solidity-fixtures/solidity-fixtures/vanchor_2/2/poseidon_vanchor_2_2.r1cs", + // ); + // println!("Setting up CircomConfig"); + // println!("wasm_2_2_path: {:?}", wasm_2_2_path); + // println!("r1cs_2_2_path: {:?}", r1cs_2_2_path); + // let cfg_2_2 = + // CircomConfig::::new(wasm_2_2_path.unwrap(), r1cs_2_2_path.unwrap()).unwrap(); + + println!("Setting up ZKey"); + let path_2_2 = "../../solidity-fixtures/solidity-fixtures/vanchor_2/2/circuit_final.zkey"; + let mut file_2_2 = File::open(path_2_2).unwrap(); + let params_2_2 = read_zkey(&mut file_2_2).unwrap(); + + let wasm_2_2_path = + "../../solidity-fixtures/solidity-fixtures//vanchor_2/2/poseidon_vanchor_2_2.wasm"; + + let wc_2_2 = circom_from_folder(wasm_2_2_path); + + let transactor = account::("", TRANSACTOR_ACCOUNT_ID, SEED); + let relayer = account::("", RELAYER_ACCOUNT_ID, SEED); + let big_transactor = account::("", BIG_TRANSACTOR_ACCOUNT_ID, SEED); + let bigger_transactor = account::("", BIGGER_TRANSACTOR_ACCOUNT_ID, SEED); + + // Set balances + assert_ok!(Balances::set_balance(RuntimeOrigin::root(), transactor, DEFAULT_BALANCE, 0)); + assert_ok!(Balances::set_balance(RuntimeOrigin::root(), relayer, DEFAULT_BALANCE, 0)); + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), + big_transactor, + BIG_DEFAULT_BALANCE, + 0 + )); + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), + bigger_transactor, + BIGGER_DEFAULT_BALANCE, + 0 + )); + + // set configurable storage + assert_ok!(VAnchor2::set_max_deposit_amount(RuntimeOrigin::root(), 10, 1)); + assert_ok!(VAnchor2::set_min_withdraw_amount(RuntimeOrigin::root(), 3, 2)); + + // finally return the provingkey bytes + (params_2_2, wc_2_2) +} + pub fn setup_utxos( // Transaction inputs chain_ids: [u64; NUM_UTXOS], diff --git a/pallets/vanchor/src/tests.rs b/pallets/vanchor/src/tests.rs index 48dee7896..04d7a66c7 100644 --- a/pallets/vanchor/src/tests.rs +++ b/pallets/vanchor/src/tests.rs @@ -1,7 +1,7 @@ use crate::{ mock::*, - test_utils::{deconstruct_public_inputs_el, setup_utxos, setup_zk_circuit}, - Error, MaxDepositAmount, MinWithdrawAmount, + test_utils::{deconstruct_public_inputs_el, setup_utxos, setup_zk_circuit, TREE_DEPTH}, + Error, Instance1, MaxDepositAmount, MinWithdrawAmount, }; use ark_ff::{BigInteger, PrimeField}; use arkworks_setups::{common::setup_params, utxo::Utxo, Curve}; @@ -22,18 +22,17 @@ use webb_primitives::{ type Bn254Fr = ark_bn254::Fr; -const SEED: u32 = 0; -const TREE_DEPTH: usize = 30; -const EDGE_CT: usize = 1; -const DEFAULT_BALANCE: u128 = 10_000; -const BIG_DEFAULT_BALANCE: u128 = 20_000; -const BIGGER_DEFAULT_BALANCE: u128 = 30_000; +pub const SEED: u32 = 0; +pub const EDGE_CT: usize = 1; +pub const DEFAULT_BALANCE: u128 = 10_000; +pub const BIG_DEFAULT_BALANCE: u128 = 20_000; +pub const BIGGER_DEFAULT_BALANCE: u128 = 30_000; -const TRANSACTOR_ACCOUNT_ID: u32 = 0; -const RECIPIENT_ACCOUNT_ID: u32 = 1; -const BIG_TRANSACTOR_ACCOUNT_ID: u32 = 2; -const BIGGER_TRANSACTOR_ACCOUNT_ID: u32 = 3; -const RELAYER_ACCOUNT_ID: u32 = 4; +pub const TRANSACTOR_ACCOUNT_ID: u32 = 0; +pub const RECIPIENT_ACCOUNT_ID: u32 = 1; +pub const BIG_TRANSACTOR_ACCOUNT_ID: u32 = 2; +pub const BIGGER_TRANSACTOR_ACCOUNT_ID: u32 = 3; +pub const RELAYER_ACCOUNT_ID: u32 = 4; pub fn get_account(id: u32) -> AccountId { account::("", id, SEED) @@ -43,37 +42,39 @@ fn setup_environment() -> (Vec, Vec, Vec, Vec) { let curve = Curve::Bn254; let params3 = setup_params::(curve, 5, 3); // 1. Setup The Hasher Pallet. - assert_ok!(HasherPallet::force_set_parameters( + assert_ok!(Hasher1::force_set_parameters( RuntimeOrigin::root(), params3.to_bytes().try_into().unwrap() )); // 2. Initialize MerkleTree pallet. - >::on_initialize(1); + >::on_initialize(1); // 3. Setup the VerifierPallet // but to do so, we need to have a VerifyingKey let pk_2_2_bytes = include_bytes!( - "../../../substrate-fixtures/vanchor/bn254/x5/2-2-2/proving_key_uncompressed.bin" + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-2-2/proving_key_uncompressed.bin" + ) + .to_vec(); + let vk_2_2_bytes = include_bytes!( + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key.bin" ) .to_vec(); - let vk_2_2_bytes = - include_bytes!("../../../substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key.bin") - .to_vec(); let pk_2_16_bytes = include_bytes!( - "../../../substrate-fixtures/vanchor/bn254/x5/2-16-2/proving_key_uncompressed.bin" + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-16-2/proving_key_uncompressed.bin" + ) + .to_vec(); + let vk_2_16_bytes = include_bytes!( + "../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-16-2/verifying_key.bin" ) .to_vec(); - let vk_2_16_bytes = - include_bytes!("../../../substrate-fixtures/vanchor/bn254/x5/2-16-2/verifying_key.bin") - .to_vec(); - assert_ok!(VAnchorVerifier::force_set_parameters( + assert_ok!(VAnchorVerifier1::force_set_parameters( RuntimeOrigin::root(), (2, 2), vk_2_2_bytes.clone().try_into().unwrap() )); - assert_ok!(VAnchorVerifier::force_set_parameters( + assert_ok!(VAnchorVerifier1::force_set_parameters( RuntimeOrigin::root(), (2, 16), vk_2_16_bytes.clone().try_into().unwrap() @@ -101,8 +102,8 @@ fn setup_environment() -> (Vec, Vec, Vec, Vec) { )); // set configurable storage - assert_ok!(VAnchor::set_max_deposit_amount(RuntimeOrigin::root(), 10, 1)); - assert_ok!(VAnchor::set_min_withdraw_amount(RuntimeOrigin::root(), 3, 2)); + assert_ok!(VAnchor1::set_max_deposit_amount(RuntimeOrigin::root(), 10, 1)); + assert_ok!(VAnchor1::set_min_withdraw_amount(RuntimeOrigin::root(), 3, 2)); // finally return the provingkey bytes (pk_2_2_bytes, vk_2_2_bytes, pk_2_16_bytes, vk_2_16_bytes) @@ -111,8 +112,8 @@ fn setup_environment() -> (Vec, Vec, Vec, Vec) { fn create_vanchor(asset_id: u32) -> u32 { let max_edges = EDGE_CT as u32; let depth = TREE_DEPTH as u8; - assert_ok!(VAnchor::create(RuntimeOrigin::root(), max_edges, depth, asset_id)); - MerkleTree::next_tree_id() - 1 + assert_ok!(VAnchor1::create(RuntimeOrigin::root(), max_edges, depth, asset_id)); + MerkleTree1::next_tree_id() - 1 } fn create_vanchor_with_deposits( @@ -150,16 +151,16 @@ fn create_vanchor_with_deposits( ext_amount, fee, 0, - MaxCurrencyId::get(), + asset_id.unwrap_or_default(), output1.to_vec(), // Mock encryption value, not meant to be used in production output2.to_vec(), // Mock encryption value, not meant to be used in production ); let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() @@ -183,7 +184,12 @@ fn create_vanchor_with_deposits( let proof_data = ProofData::new(proof, public_amount, root_set, nullifiers, commitments, ext_data_hash); - assert_ok!(VAnchor::transact(RuntimeOrigin::signed(transactor), tree_id, proof_data, ext_data)); + assert_ok!(VAnchor1::transact( + RuntimeOrigin::signed(transactor), + tree_id, + proof_data, + ext_data + )); (tree_id, out_utxos) } @@ -221,7 +227,7 @@ fn should_complete_2x2_transaction_with_deposit() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -230,13 +236,14 @@ fn should_complete_2x2_transaction_with_deposit() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -261,7 +268,7 @@ fn should_complete_2x2_transaction_with_deposit() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -273,7 +280,7 @@ fn should_complete_2x2_transaction_with_deposit() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let recipient_balance_before = Balances::free_balance(recipient.clone()); let transactor_balance_before = Balances::free_balance(transactor.clone()); - assert_ok!(VAnchor::transact( + assert_ok!(VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, @@ -300,7 +307,7 @@ fn should_complete_2x2_transaction_with_withdraw() { new_test_ext().execute_with(|| { let (proving_key_2x2_bytes, _, _, _) = setup_environment(); let (tree_id, in_utxos) = create_vanchor_with_deposits(proving_key_2x2_bytes.clone(), None); - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let transactor: AccountId = get_account(TRANSACTOR_ACCOUNT_ID); let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); @@ -326,19 +333,20 @@ fn should_complete_2x2_transaction_with_withdraw() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -363,7 +371,7 @@ fn should_complete_2x2_transaction_with_withdraw() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -374,7 +382,7 @@ fn should_complete_2x2_transaction_with_withdraw() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let recipient_balance_before = Balances::free_balance(recipient.clone()); - assert_ok!(VAnchor::transact( + assert_ok!(VAnchor1::transact( RuntimeOrigin::signed(transactor), tree_id, proof_data, @@ -444,20 +452,21 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_native_token( ext_amount, fee, refund, - MaxCurrencyId::get(), + 0, output1.to_vec(), // Mock encryption value, not meant to be used in production output2.to_vec(), // Mock encryption value, not meant to be used in production ); let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -483,10 +492,10 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_native_token( let proof_data = ProofData::new(proof, public_amount, root_set, nullifiers, commitments, ext_data_hash); - assert_ok!(VAnchor::transact(RuntimeOrigin::signed(alice), tree_id, proof_data, ext_data)); + assert_ok!(VAnchor1::transact(RuntimeOrigin::signed(alice), tree_id, proof_data, ext_data)); /**** Withdraw and unwrap **** */ - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let ext_amount: Amount = -5; let fee: Balance = 2; let refund: Balance = 10; @@ -515,12 +524,13 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_native_token( let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -543,7 +553,7 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_native_token( let recipient_balance_before = Balances::free_balance(recipient.clone()); let relayer_balance_before = Balances::free_balance(relayer.clone()); let relayer_balance_wrapped_token_before = Currencies::free_balance(asset_id, &relayer); - assert_ok!(VAnchor::transact( + assert_ok!(VAnchor1::transact( RuntimeOrigin::signed(get_account(RELAYER_ACCOUNT_ID)), tree_id, proof_data, @@ -594,15 +604,6 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_non_native_to let pooled_asset_id = AssetRegistry::next_asset_id() - 1; // Mint some wrapped asset / pool share by depositing the native asset let alice = get_account(TRANSACTOR_ACCOUNT_ID); - assert_ok!(TokenWrapper::wrap( - RuntimeOrigin::signed(alice.clone()), - first_asset_id, - pooled_asset_id, - 1_000, - alice.clone(), - )); - assert_eq!(Currencies::free_balance(first_asset_id, &alice), 9_000); - assert_eq!(Currencies::free_balance(pooled_asset_id, &alice), 1_000); /**** Create deposits with the newly wrapped token *** */ let tree_id = create_vanchor(pooled_asset_id); @@ -634,7 +635,7 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_non_native_to ext_amount, fee, refund, - MaxCurrencyId::get(), + first_asset_id, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -643,13 +644,14 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_non_native_to let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -669,10 +671,9 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_non_native_to let proof_data = ProofData::new(proof, public_amount, root_set, nullifiers, commitments, ext_data_hash); - assert_ok!(VAnchor::transact(RuntimeOrigin::signed(alice), tree_id, proof_data, ext_data)); - + assert_ok!(VAnchor1::transact(RuntimeOrigin::signed(alice), tree_id, proof_data, ext_data)); /**** Withdraw and unwrap **** */ - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let ext_amount: Amount = -5; let fee: Balance = 2; let refund: Balance = 10; @@ -701,12 +702,13 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_non_native_to let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -749,7 +751,7 @@ fn should_complete_2x2_transaction_with_withdraw_unwrap_and_refund_non_native_to Currencies::free_balance(pooled_asset_id, &recipient); let recipient_balance_unwrapped_token_before = Currencies::free_balance(first_asset_id, &recipient); - assert_ok!(VAnchor::transact( + assert_ok!(VAnchor1::transact( RuntimeOrigin::signed(get_account(RELAYER_ACCOUNT_ID)), tree_id, proof_data, @@ -788,7 +790,7 @@ fn should_complete_register_and_transact() { new_test_ext().execute_with(|| { let (proving_key_2x2_bytes, _, _, _) = setup_environment(); let (tree_id, in_utxos) = create_vanchor_with_deposits(proving_key_2x2_bytes.clone(), None); - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let transactor: AccountId = get_account(TRANSACTOR_ACCOUNT_ID); let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); @@ -814,19 +816,20 @@ fn should_complete_register_and_transact() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -851,7 +854,7 @@ fn should_complete_register_and_transact() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -862,7 +865,7 @@ fn should_complete_register_and_transact() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let recipient_balance_before = Balances::free_balance(recipient.clone()); - assert_ok!(VAnchor::register_and_transact( + assert_ok!(VAnchor1::register_and_transact( RuntimeOrigin::signed(transactor.clone()), transactor, [0u8; 32].to_vec(), @@ -914,7 +917,7 @@ fn should_not_complete_transaction_if_ext_data_is_invalid() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -923,13 +926,14 @@ fn should_not_complete_transaction_if_ext_data_is_invalid() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -956,7 +960,7 @@ fn should_not_complete_transaction_if_ext_data_is_invalid() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -969,13 +973,13 @@ fn should_not_complete_transaction_if_ext_data_is_invalid() { let transactor_balance_before = Balances::free_balance(transactor.clone()); let recipient_balance_before = Balances::free_balance(recipient.clone()); assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidExtData, + Error::::InvalidExtData, ); // Relayer balance should be zero since the fee was zero and the transaction @@ -999,7 +1003,7 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_big() { new_test_ext().execute_with(|| { let (proving_key_2x2_bytes, _, _, _) = setup_environment(); let (tree_id, in_utxos) = create_vanchor_with_deposits(proving_key_2x2_bytes.clone(), None); - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let transactor = get_account(TRANSACTOR_ACCOUNT_ID); let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); @@ -1025,7 +1029,7 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_big() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -1034,12 +1038,13 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_big() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1064,7 +1069,7 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_big() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1078,13 +1083,13 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_big() { let recipient_balance_before = Balances::free_balance(recipient.clone()); // Should fail with invalid external data error assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidTransactionProof + Error::::InvalidTransactionProof ); // Should be zero, since transaction failed @@ -1108,7 +1113,7 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_small() { new_test_ext().execute_with(|| { let (proving_key_2x2_bytes, _, _, _) = setup_environment(); let (tree_id, in_utxos) = create_vanchor_with_deposits(proving_key_2x2_bytes.clone(), None); - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let transactor = get_account(TRANSACTOR_ACCOUNT_ID); let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); @@ -1135,7 +1140,7 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_small() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -1144,12 +1149,13 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_small() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1174,7 +1180,7 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_small() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1188,13 +1194,13 @@ fn should_not_complete_withdraw_if_out_amount_sum_is_too_small() { let recipient_balance_before = Balances::free_balance(recipient.clone()); // Should fail with invalid external data error assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidTransactionProof + Error::::InvalidTransactionProof ); // Should be zero, since transaction failed @@ -1216,7 +1222,7 @@ fn should_not_be_able_to_double_spend() { new_test_ext().execute_with(|| { let (proving_key_2x2_bytes, _, _, _) = setup_environment(); let (tree_id, in_utxos) = create_vanchor_with_deposits(proving_key_2x2_bytes.clone(), None); - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let transactor: AccountId = get_account(TRANSACTOR_ACCOUNT_ID); let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); @@ -1242,7 +1248,7 @@ fn should_not_be_able_to_double_spend() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -1251,12 +1257,13 @@ fn should_not_be_able_to_double_spend() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1281,7 +1288,7 @@ fn should_not_be_able_to_double_spend() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1293,20 +1300,20 @@ fn should_not_be_able_to_double_spend() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let transactor_balance_before = Balances::free_balance(transactor.clone()); let recipient_balance_before = Balances::free_balance(recipient.clone()); - assert_ok!(VAnchor::transact( + assert_ok!(VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data.clone(), ext_data.clone() )); assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::AlreadyRevealedNullifier + Error::::AlreadyRevealedNullifier ); // Fee is paid out once @@ -1356,7 +1363,7 @@ fn should_not_be_able_to_exceed_max_fee() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -1365,13 +1372,14 @@ fn should_not_be_able_to_exceed_max_fee() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1396,7 +1404,7 @@ fn should_not_be_able_to_exceed_max_fee() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1408,13 +1416,13 @@ fn should_not_be_able_to_exceed_max_fee() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let transactor_balance_before = Balances::free_balance(transactor.clone()); assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidFee + Error::::InvalidFee ); // Relayer balance should be zero since the fee was zero @@ -1461,7 +1469,7 @@ fn should_not_be_able_to_exceed_max_deposit() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -1470,13 +1478,14 @@ fn should_not_be_able_to_exceed_max_deposit() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1501,7 +1510,7 @@ fn should_not_be_able_to_exceed_max_deposit() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1513,13 +1522,13 @@ fn should_not_be_able_to_exceed_max_deposit() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let transactor_balance_before = Balances::free_balance(transactor.clone()); assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidDepositAmount + Error::::InvalidDepositAmount ); // Relayer balance should be zero since the fee was zero @@ -1566,7 +1575,7 @@ fn should_not_be_able_to_exceed_external_amount() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, // Mock encryption value, not meant to be used in production output1.to_vec(), // Mock encryption value, not meant to be used in production @@ -1575,13 +1584,14 @@ fn should_not_be_able_to_exceed_external_amount() { let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let custom_root = MerkleTree::get_default_root(tree_id).unwrap(); - let neighbor_roots: [Element; EDGE_CT] = , + let custom_root = MerkleTree1::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1606,7 +1616,7 @@ fn should_not_be_able_to_exceed_external_amount() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1618,13 +1628,13 @@ fn should_not_be_able_to_exceed_external_amount() { let relayer_balance_before = Balances::free_balance(relayer.clone()); let transactor_balance_before = Balances::free_balance(transactor.clone()); assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidExtAmount + Error::::InvalidExtAmount ); // Relayer balance should be zero since the transaction failed @@ -1642,7 +1652,7 @@ fn should_not_be_able_to_withdraw_less_than_minimum() { new_test_ext().execute_with(|| { let (proving_key_2x2_bytes, _, _, _) = setup_environment(); let (tree_id, in_utxos) = create_vanchor_with_deposits(proving_key_2x2_bytes.clone(), None); - let custom_root = MerkleTree::get_root(tree_id).unwrap(); + let custom_root = MerkleTree1::get_root(tree_id).unwrap(); let transactor: AccountId = get_account(TRANSACTOR_ACCOUNT_ID); let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); @@ -1668,19 +1678,20 @@ fn should_not_be_able_to_withdraw_less_than_minimum() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), // Mock encryption value, not meant to be used in production output2.to_vec(), // Mock encryption value, not meant to be used in production ); let ext_data_hash = keccak_256(&ext_data.encode_abi()); - let neighbor_roots = , + let neighbor_roots = , >>::get_neighbor_roots(tree_id) .unwrap() .try_into() .unwrap(); + let (proof, public_inputs) = setup_zk_circuit( public_amount, chain_id, @@ -1705,7 +1716,7 @@ fn should_not_be_able_to_withdraw_less_than_minimum() { ext_amount, fee, 0, - MaxCurrencyId::get(), + 0, output1.to_vec(), output2.to_vec(), ); @@ -1718,13 +1729,13 @@ fn should_not_be_able_to_withdraw_less_than_minimum() { let transactor_balance_before = Balances::free_balance(transactor.clone()); let recipient_balance_before = Balances::free_balance(recipient.clone()); assert_err!( - VAnchor::transact( + VAnchor1::transact( RuntimeOrigin::signed(transactor.clone()), tree_id, proof_data, ext_data ), - Error::::InvalidWithdrawAmount + Error::::InvalidWithdrawAmount ); // Fee is not paid out @@ -1743,34 +1754,34 @@ fn should_not_be_able_to_withdraw_less_than_minimum() { #[test] fn set_get_max_deposit_amount() { new_test_ext().execute_with(|| { - assert_ok!(VAnchor::set_max_deposit_amount(RuntimeOrigin::root(), 1, 1)); - assert_eq!(MaxDepositAmount::::get(), 1); + assert_ok!(VAnchor1::set_max_deposit_amount(RuntimeOrigin::root(), 1, 1)); + assert_eq!(MaxDepositAmount::::get(), 1); - assert_ok!(VAnchor::set_max_deposit_amount(RuntimeOrigin::root(), 5, 2)); - assert_eq!(MaxDepositAmount::::get(), 5); + assert_ok!(VAnchor1::set_max_deposit_amount(RuntimeOrigin::root(), 5, 2)); + assert_eq!(MaxDepositAmount::::get(), 5); }) } #[test] fn set_get_min_withdraw_amount() { new_test_ext().execute_with(|| { - assert_ok!(VAnchor::set_min_withdraw_amount(RuntimeOrigin::root(), 2, 1)); - assert_eq!(MinWithdrawAmount::::get(), 2); + assert_ok!(VAnchor1::set_min_withdraw_amount(RuntimeOrigin::root(), 2, 1)); + assert_eq!(MinWithdrawAmount::::get(), 2); - assert_ok!(VAnchor::set_min_withdraw_amount(RuntimeOrigin::root(), 5, 2)); - assert_eq!(MinWithdrawAmount::::get(), 5); + assert_ok!(VAnchor1::set_min_withdraw_amount(RuntimeOrigin::root(), 5, 2)); + assert_eq!(MinWithdrawAmount::::get(), 5); }) } #[test] fn should_fail_to_set_amounts_with_invalid_nonces() { new_test_ext().execute_with(|| { - assert_ok!(VAnchor::set_min_withdraw_amount(RuntimeOrigin::root(), 2, 1)); - assert_eq!(MinWithdrawAmount::::get(), 2); + assert_ok!(VAnchor1::set_min_withdraw_amount(RuntimeOrigin::root(), 2, 1)); + assert_eq!(MinWithdrawAmount::::get(), 2); assert_err!( - VAnchor::set_min_withdraw_amount(RuntimeOrigin::root(), 5, 1), - Error::::InvalidNonce + VAnchor1::set_min_withdraw_amount(RuntimeOrigin::root(), 5, 1), + Error::::InvalidNonce ); }) } diff --git a/pallets/vanchor/src/tests_circom.rs b/pallets/vanchor/src/tests_circom.rs new file mode 100644 index 000000000..014e1eb67 --- /dev/null +++ b/pallets/vanchor/src/tests_circom.rs @@ -0,0 +1,570 @@ +use crate::{mock::*, test_utils::*, tests::*, zerokit_utils::*, Instance2}; +use ark_bn254::{Bn254, Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective}; +use ark_circom::{read_zkey, CircomConfig, CircomReduction, WitnessCalculator}; +use ark_ff::{BigInteger, BigInteger256, PrimeField, ToBytes}; +use ark_groth16::{ + create_proof_with_reduction_and_matrices, create_random_proof as prove, + generate_random_parameters, prepare_verifying_key, verify_proof as ark_verify_proof, + Proof as ArkProof, ProvingKey, VerifyingKey, +}; +use ark_relations::r1cs::{ConstraintMatrices, SynthesisError}; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use ark_std::{rand::thread_rng, UniformRand}; +use arkworks_native_gadgets::{ + merkle_tree::{Path, SparseMerkleTree}, + poseidon::Poseidon, + to_field_elements, +}; +use arkworks_setups::{ + common::{setup_params, setup_tree_and_create_path}, + utxo::Utxo, + Curve, +}; +use cfg_if::cfg_if; +use frame_benchmarking::account; +use frame_support::{assert_ok, traits::OnInitialize}; +use num_bigint::{BigInt, BigUint, Sign}; +use once_cell::sync::OnceCell; +use pallet_linkable_tree::LinkableTreeConfigration; +use serde_json::Value; +use sp_core::hashing::keccak_256; +use std::{ + convert::{TryFrom, TryInto}, + fs::{self, File}, + io::{Cursor, Error, ErrorKind}, + result::Result, + str::FromStr, + sync::Mutex, +}; +use thiserror::Error; +use wasmer::{Module, Store}; +use webb_primitives::{ + linkable_tree::LinkableTreeInspector, + merkle_tree::TreeInspector, + types::vanchor::{ExtData, ProofData}, + utils::compute_chain_id_type, + verifying::CircomError, + AccountId, +}; + +type Bn254Fr = ark_bn254::Fr; + +#[cfg(not(target_arch = "wasm32"))] +static WITNESS_CALCULATOR: OnceCell> = OnceCell::new(); + +// Utilities to convert a json verification key in a groth16::VerificationKey +fn fq_from_str(s: &str) -> Fq { + Fq::try_from(BigUint::from_str(s).unwrap()).unwrap() +} + +// Extracts the element in G1 corresponding to its JSON serialization +fn json_to_g1(json: &Value, key: &str) -> G1Affine { + let els: Vec = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| i.as_str().unwrap().to_string()) + .collect(); + G1Affine::from(G1Projective::new( + fq_from_str(&els[0]), + fq_from_str(&els[1]), + fq_from_str(&els[2]), + )) +} + +// Extracts the vector of G1 elements corresponding to its JSON serialization +fn json_to_g1_vec(json: &Value, key: &str) -> Vec { + let els: Vec> = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| { + i.as_array() + .unwrap() + .iter() + .map(|x| x.as_str().unwrap().to_string()) + .collect::>() + }) + .collect(); + + els.iter() + .map(|coords| { + G1Affine::from(G1Projective::new( + fq_from_str(&coords[0]), + fq_from_str(&coords[1]), + fq_from_str(&coords[2]), + )) + }) + .collect() +} + +// Extracts the element in G2 corresponding to its JSON serialization +fn json_to_g2(json: &Value, key: &str) -> G2Affine { + let els: Vec> = json + .get(key) + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|i| { + i.as_array() + .unwrap() + .iter() + .map(|x| x.as_str().unwrap().to_string()) + .collect::>() + }) + .collect(); + + let x = Fq2::new(fq_from_str(&els[0][0]), fq_from_str(&els[0][1])); + let y = Fq2::new(fq_from_str(&els[1][0]), fq_from_str(&els[1][1])); + let z = Fq2::new(fq_from_str(&els[2][0]), fq_from_str(&els[2][1])); + G2Affine::from(G2Projective::new(x, y, z)) +} + +// Converts JSON to a VerifyingKey +fn to_verifying_key(json: serde_json::Value) -> VerifyingKey { + VerifyingKey { + alpha_g1: json_to_g1(&json, "vk_alpha_1"), + beta_g2: json_to_g2(&json, "vk_beta_2"), + gamma_g2: json_to_g2(&json, "vk_gamma_2"), + delta_g2: json_to_g2(&json, "vk_delta_2"), + gamma_abc_g1: json_to_g1_vec(&json, "IC"), + } +} + +// Computes the verification key from its JSON serialization +fn vk_from_json(vk_path: &str) -> VerifyingKey { + let json = std::fs::read_to_string(vk_path).unwrap(); + let json: Value = serde_json::from_str(&json).unwrap(); + + to_verifying_key(json) +} + +pub fn generate_proof( + #[cfg(not(target_arch = "wasm32"))] witness_calculator: &Mutex, + #[cfg(target_arch = "wasm32")] witness_calculator: &mut WitnessCalculator, + proving_key: &(ProvingKey, ConstraintMatrices), + vanchor_witness: [(&str, Vec); 15], +) -> Result<(ArkProof, Vec), ProofError> { + let inputs = vanchor_witness + .into_iter() + .map(|(name, values)| (name.to_string(), values.clone())); + + println!("inputs {:?}", inputs); + + cfg_if! { + if #[cfg(target_arch = "wasm32")] { + let full_assignment = witness_calculator + .calculate_witness_element::(inputs, false) + .map_err(ProofError::WitnessError)?; + } else { + let full_assignment = witness_calculator + .lock() + .expect("witness_calculator mutex should not get poisoned") + .calculate_witness_element::(inputs, false) + .map_err(ProofError::WitnessError)?; + } + } + + // Random Values + let mut rng = thread_rng(); + let r = Fr::rand(&mut rng); + let s = Fr::rand(&mut rng); + + let proof = create_proof_with_reduction_and_matrices::<_, CircomReduction>( + &proving_key.0, + r, + s, + &proving_key.1, + proving_key.1.num_instance_variables, + proving_key.1.num_constraints, + full_assignment.as_slice(), + )?; + + Ok((proof, full_assignment)) +} + +/// Verifies a given RLN proof +/// +/// # Errors +/// +/// Returns a [`ProofError`] if verifying fails. Verification failure does not +/// necessarily mean the proof is incorrect. +pub fn verify_proof( + verifying_key: &VerifyingKey, + proof: &ArkProof, + inputs: Vec, +) -> Result { + // Check that the proof is valid + let pvk = prepare_verifying_key(verifying_key); + //let pr: ArkProof = (*proof).into(); + + let verified = ark_verify_proof(&pvk, proof, &inputs)?; + + Ok(verified) +} + +// Initializes the witness calculator using a bytes vector +#[cfg(not(target_arch = "wasm32"))] +pub fn circom_from_raw(wasm_buffer: Vec) -> &'static Mutex { + WITNESS_CALCULATOR.get_or_init(|| { + let store = Store::default(); + let module = Module::new(&store, wasm_buffer).unwrap(); + let result = + WitnessCalculator::from_module(module).expect("Failed to create witness calculator"); + Mutex::new(result) + }) +} + +// Initializes the witness calculator +#[cfg(not(target_arch = "wasm32"))] +pub fn circom_from_folder(wasm_path: &str) -> &'static Mutex { + // We read the wasm file + let wasm_buffer = std::fs::read(wasm_path).unwrap(); + circom_from_raw(wasm_buffer) +} + +fn setup_environment_with_circom( +) -> ((ProvingKey, ConstraintMatrices), &'static Mutex) { + let curve = Curve::Bn254; + let params3 = setup_params::(curve, 5, 3); + // 1. Setup The Hasher Pallet. + println!("Setting up the hasher pallet"); + assert_ok!(Hasher2::force_set_parameters( + RuntimeOrigin::root(), + params3.to_bytes().try_into().unwrap() + )); + // 2. Initialize MerkleTree pallet. + println!("Initializing the merkle tree pallet"); + >::on_initialize(1); + // 3. Setup the VerifierPallet + // but to do so, we need to have a VerifyingKey + + // Load the WASM and R1CS for witness and proof generation + // Get path to solidity fixtures + println!("Setting up the verifier pallet"); + // let wasm_2_2_path = fs::canonicalize( + // "../../solidity-fixtures/solidity-fixtures/vanchor_2/2/poseidon_vanchor_2_2.wasm", + // ); + // let r1cs_2_2_path = fs::canonicalize( + // "../../solidity-fixtures/solidity-fixtures/vanchor_2/2/poseidon_vanchor_2_2.r1cs", + // ); + // println!("Setting up CircomConfig"); + // println!("wasm_2_2_path: {:?}", wasm_2_2_path); + // println!("r1cs_2_2_path: {:?}", r1cs_2_2_path); + // let cfg_2_2 = + // CircomConfig::::new(wasm_2_2_path.unwrap(), r1cs_2_2_path.unwrap()).unwrap(); + + println!("Setting up ZKey"); + let path_2_2 = "../../solidity-fixtures/solidity-fixtures/vanchor_2/2/circuit_final.zkey"; + let mut file_2_2 = File::open(path_2_2).unwrap(); + let params_2_2 = read_zkey(&mut file_2_2).unwrap(); + + let wasm_2_2_path = + "../../solidity-fixtures/solidity-fixtures//vanchor_2/2/poseidon_vanchor_2_2.wasm"; + + let wc_2_2 = circom_from_folder(wasm_2_2_path); + + let transactor = account::("", TRANSACTOR_ACCOUNT_ID, SEED); + let relayer = account::("", RELAYER_ACCOUNT_ID, SEED); + let big_transactor = account::("", BIG_TRANSACTOR_ACCOUNT_ID, SEED); + let bigger_transactor = account::("", BIGGER_TRANSACTOR_ACCOUNT_ID, SEED); + + // Set balances + assert_ok!(Balances::set_balance(RuntimeOrigin::root(), transactor, DEFAULT_BALANCE, 0)); + assert_ok!(Balances::set_balance(RuntimeOrigin::root(), relayer, DEFAULT_BALANCE, 0)); + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), + big_transactor, + BIG_DEFAULT_BALANCE, + 0 + )); + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), + bigger_transactor, + BIGGER_DEFAULT_BALANCE, + 0 + )); + + // set configurable storage + assert_ok!(VAnchor2::set_max_deposit_amount(RuntimeOrigin::root(), 10, 1)); + assert_ok!(VAnchor2::set_min_withdraw_amount(RuntimeOrigin::root(), 3, 2)); + + // finally return the provingkey bytes + (params_2_2, wc_2_2) +} + +fn insert_utxos_to_merkle_tree( + utxos: &[Utxo; 2], + neighbor_roots: [Element; ANCHOR_CT - 1], + custom_root: Element, +) -> ( + [u64; 2], + [Vec; 2], + SparseMerkleTree, TREE_DEPTH>, + Vec, TREE_DEPTH>>, +) { + let curve = Curve::Bn254; + let leaf0 = utxos[0].commitment.into_repr().to_bytes_be(); + let leaf1 = utxos[1].commitment.into_repr().to_bytes_be(); + + let leaves: Vec> = vec![leaf0, leaf1]; + let leaves_f: Vec = + leaves.iter().map(|x| Bn254Fr::from_be_bytes_mod_order(x)).collect(); + + let in_indices = [0, 1]; + + let params3 = setup_params::(curve, 5, 3); + let poseidon3 = Poseidon::new(params3); + let (tree, _) = setup_tree_and_create_path::, TREE_DEPTH>( + &poseidon3, + &leaves_f, + 0, + &DEFAULT_LEAF, + ) + .unwrap(); + + let in_paths: Vec<_> = in_indices.iter().map(|i| tree.generate_membership_proof(*i)).collect(); + + let roots_f: [Bn254Fr; ANCHOR_CT] = vec![if custom_root != Element::from_bytes(&[0u8; 32]) { + Bn254Fr::from_be_bytes_mod_order(custom_root.to_bytes()) + } else { + tree.root() + }] + .iter() + .chain( + neighbor_roots + .iter() + .map(|r| Bn254Fr::from_be_bytes_mod_order(r.to_bytes())) + .collect::>() + .iter(), + ) + .cloned() + .collect::>() + .try_into() + .unwrap(); + let in_root_set = roots_f.map(|x| x.into_repr().to_bytes_be()); + + (in_indices, in_root_set, tree, in_paths) +} + +pub fn create_vanchor(asset_id: u32) -> u32 { + let max_edges = EDGE_CT as u32; + let depth = TREE_DEPTH as u8; + assert_ok!(VAnchor2::create(RuntimeOrigin::root(), max_edges, depth, asset_id)); + MerkleTree2::next_tree_id() - 1 +} + +#[test] +fn circom_should_complete_2x2_transaction_with_withdraw() { + new_test_ext().execute_with(|| { + let params4 = setup_params::(Curve::Bn254, 5, 4); + let nullifier_hasher = Poseidon:: { params: params4 }; + let (params_2_2, wc_2_2) = setup_environment_with_circom(); + let tree_id = create_vanchor(0); + + let transactor = get_account(TRANSACTOR_ACCOUNT_ID); + let recipient: AccountId = get_account(RECIPIENT_ACCOUNT_ID); + let relayer: AccountId = get_account(RELAYER_ACCOUNT_ID); + + let ext_amount: Amount = 10_i128; + let public_amount = 10_i128; + let fee: Balance = 0; + + let chain_type = [2, 0]; + let chain_id = compute_chain_id_type(ChainIdentifier::get(), chain_type); + let in_chain_ids = [chain_id; 2]; + let in_amounts = [0, 0]; + let in_indices = [0, 1]; + let out_chain_ids = [chain_id; 2]; + let out_amounts = [10, 0]; + + let in_utxos = setup_utxos(in_chain_ids, in_amounts, Some(in_indices)); + let out_utxos = setup_utxos(out_chain_ids, out_amounts, None); + + let output1 = out_utxos[0].commitment.into_repr().to_bytes_be(); + let output2 = out_utxos[1].commitment.into_repr().to_bytes_be(); + let ext_data = ExtData::::new( + recipient.clone(), + relayer.clone(), + ext_amount, + fee, + 0, + 0, + // Mock encryption value, not meant to be used in production + output1.to_vec(), + // Mock encryption value, not meant to be used in production + output2.to_vec(), + ); + println!("ext_data: {:?}", ext_data); + + let custom_root = MerkleTree2::get_default_root(tree_id).unwrap(); + let neighbor_roots: [Element; EDGE_CT] = , + >>::get_neighbor_roots(tree_id) + .unwrap() + .try_into() + .unwrap(); + println!("neighbor_roots: {:?}", neighbor_roots); + + let input_nullifiers = in_utxos + .clone() + .map(|utxo| utxo.calculate_nullifier(&nullifier_hasher).unwrap()); + + let (in_indices, _in_root_set, _tree, in_paths) = + insert_utxos_to_merkle_tree(&in_utxos, neighbor_roots, custom_root); + + // Make Inputs + let public_amount = if public_amount > 0 { + vec![BigInt::from_bytes_be(Sign::Plus, &public_amount.to_be_bytes())] + } else { + vec![BigInt::from_bytes_be(Sign::Minus, &(-public_amount).to_be_bytes())] + }; + + let mut ext_data_hash = + vec![BigInt::from_bytes_be(Sign::Plus, keccak_256(&ext_data.encode_abi()).as_slice())]; + + let mut input_nullifier = Vec::new(); + let mut output_commitment = Vec::new(); + for i in 0..NUM_UTXOS { + input_nullifier.push(BigInt::from_bytes_be( + Sign::Plus, + &input_nullifiers[i].into_repr().to_bytes_be(), + )); + output_commitment.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].commitment.into_repr().to_bytes_be(), + )); + } + + let mut chain_id = vec![BigInt::from_bytes_be(Sign::Plus, &chain_id.to_be_bytes())]; + + let mut roots = Vec::new(); + + roots.push(BigInt::from_bytes_be(Sign::Plus, &custom_root.0)); + for i in 0..ANCHOR_CT - 1 { + roots.push(BigInt::from_bytes_be(Sign::Plus, &neighbor_roots[i].0)); + } + + let mut in_amount = Vec::new(); + let mut in_private_key = Vec::new(); + let mut in_blinding = Vec::new(); + let mut in_path_indices = Vec::new(); + let mut in_path_elements = Vec::new(); + let mut out_chain_id = Vec::new(); + let mut out_amount = Vec::new(); + let mut out_pub_key = Vec::new(); + let mut out_blinding = Vec::new(); + + for i in 0..NUM_UTXOS { + in_amount.push(BigInt::from_bytes_be( + Sign::Plus, + &in_utxos[i].amount.into_repr().to_bytes_be(), + )); + in_private_key.push(BigInt::from_bytes_be( + Sign::Plus, + &in_utxos[i].keypair.secret_key.unwrap().into_repr().to_bytes_be(), + )); + in_blinding.push(BigInt::from_bytes_be( + Sign::Plus, + &in_utxos[i].blinding.into_repr().to_bytes_be(), + )); + in_path_indices.push(BigInt::from(in_indices[i])); + for j in 0..TREE_DEPTH { + let neighbor_elt: Bn254Fr = + if in_indices[i] == 0 { in_paths[i].path[j].1 } else { in_paths[i].path[j].0 }; + in_path_elements.push(BigInt::from_bytes_be( + Sign::Plus, + &neighbor_elt.into_repr().to_bytes_be(), + )); + } + + out_chain_id.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].chain_id.into_repr().to_bytes_be(), + )); + + out_amount.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].amount.into_repr().to_bytes_be(), + )); + + out_pub_key.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].keypair.public_key.into_repr().to_bytes_be(), + )); + + out_blinding.push(BigInt::from_bytes_be( + Sign::Plus, + &out_utxos[i].blinding.into_repr().to_bytes_be(), + )); + } + + let inputs_for_proof = [ + ("publicAmount", public_amount.clone()), + ("extDataHash", ext_data_hash.clone()), + ("inputNullifier", input_nullifier.clone()), + ("inAmount", in_amount.clone()), + ("inPrivateKey", in_private_key.clone()), + ("inBlinding", in_blinding.clone()), + ("inPathIndices", in_path_indices.clone()), + ("inPathElements", in_path_elements.clone()), + ("outputCommitment", output_commitment.clone()), + ("outChainID", out_chain_id.clone()), + ("outAmount", out_amount.clone()), + ("outPubkey", out_pub_key.clone()), + ("outBlinding", out_blinding.clone()), + ("chainID", chain_id.clone()), + ("roots", roots.clone()), + ]; + + let x = generate_proof(wc_2_2, ¶ms_2_2, inputs_for_proof.clone()); + + let num_inputs = params_2_2.1.num_instance_variables; + + let (proof, full_assignment) = x.unwrap(); + + let mut inputs_for_verification = &full_assignment[1..num_inputs]; + + let did_proof_work = + verify_proof(¶ms_2_2.0.vk, &proof, inputs_for_verification.to_vec()).unwrap(); + assert!(did_proof_work); + + let mut vk_2_2_bytes = Vec::new(); + params_2_2.0.vk.serialize(&mut vk_2_2_bytes).unwrap(); + + let (_chain_id, public_amount, root_set, nullifiers, commitments, ext_data_hash) = + deconstruct_public_inputs_el(&inputs_for_verification.to_vec()); + let mut proof_bytes = Vec::new(); + proof.serialize(&mut proof_bytes).unwrap(); + let proof_data = ProofData::new( + proof_bytes, + public_amount, + root_set, + nullifiers, + commitments, + ext_data_hash, + ); + println!("Proof data: {proof_data:?}"); + + VAnchorVerifier2::force_set_parameters( + RuntimeOrigin::root(), + (2, 2), + vk_2_2_bytes.try_into().unwrap(), + ); + + let _relayer_balance_before = Balances::free_balance(relayer.clone()); + let _recipient_balance_before = Balances::free_balance(recipient.clone()); + let _transactor_balance_before = Balances::free_balance(transactor.clone()); + assert_ok!(VAnchor2::transact( + RuntimeOrigin::signed(transactor.clone()), + tree_id, + proof_data, + ext_data + )); + }); +} diff --git a/pallets/vanchor/src/zerokit_utils.rs b/pallets/vanchor/src/zerokit_utils.rs new file mode 100644 index 000000000..fb0a01b9e --- /dev/null +++ b/pallets/vanchor/src/zerokit_utils.rs @@ -0,0 +1,304 @@ +// This crate provides cross-module useful utilities (mainly type conversions) not necessarily +// specific to RLN + +use ark_bn254::Fr; +use ark_ff::{BigInteger256, PrimeField}; +use num_bigint::{BigInt, BigUint}; +use num_traits::Num; +use std::{ + convert::{TryFrom, TryInto}, + iter::Extend, +}; + +pub fn from_bigint(el: &BigInt) -> Fr { + let res_1: BigUint = (el.clone()).try_into().unwrap(); + let res_2 = BigInteger256::try_from(res_1).unwrap(); + Fr::from(res_2) +} + +pub fn to_bigint(el: &Fr) -> BigInt { + let res: BigUint = (*el).try_into().unwrap(); + res.try_into().unwrap() +} + +pub fn fr_byte_size() -> usize { + let mbs = ::size_in_bits(); + (mbs + 64 - (mbs % 64)) / 8 +} + +pub fn str_to_fr(input: &str, radix: u32) -> Fr { + assert!((radix == 10) || (radix == 16)); + + // We remove any quote present and we trim + let single_quote: char = '\"'; + let mut input_clean = input.replace(single_quote, ""); + input_clean = input_clean.trim().to_string(); + + if radix == 10 { + BigUint::from_str_radix(&input_clean, radix).unwrap().try_into().unwrap() + } else { + input_clean = input_clean.replace("0x", ""); + BigUint::from_str_radix(&input_clean, radix).unwrap().try_into().unwrap() + } +} + +pub fn bytes_le_to_fr(input: &[u8]) -> (Fr, usize) { + let el_size = fr_byte_size(); + (Fr::from(BigUint::from_bytes_le(&input[0..el_size])), el_size) +} + +pub fn bytes_be_to_fr(input: &[u8]) -> (Fr, usize) { + let el_size = fr_byte_size(); + (Fr::from(BigUint::from_bytes_be(&input[0..el_size])), el_size) +} + +pub fn fr_to_bytes_le(input: &Fr) -> Vec { + let input_biguint: BigUint = (*input).into(); + let mut res = input_biguint.to_bytes_le(); + //BigUint conversion ignores most significant zero bytes. We restore them otherwise + // serialization will fail (length % 8 != 0) + while res.len() != fr_byte_size() { + res.push(0); + } + res +} + +pub fn fr_to_bytes_be(input: &Fr) -> Vec { + let input_biguint: BigUint = (*input).into(); + let mut res = input_biguint.to_bytes_be(); + // BigUint conversion ignores most significant zero bytes. We restore them otherwise + // serialization might fail Fr elements are stored using 64 bits nimbs + while res.len() != fr_byte_size() { + res.insert(0, 0); + } + res +} + +pub fn vec_fr_to_bytes_le(input: &[Fr]) -> Vec { + let mut bytes: Vec = Vec::new(); + //We store the vector length + bytes.extend(u64::try_from(input.len()).unwrap().to_le_bytes().to_vec()); + // We store each element + input.iter().for_each(|el| bytes.extend(fr_to_bytes_le(el))); + + bytes +} + +pub fn vec_fr_to_bytes_be(input: &[Fr]) -> Vec { + let mut bytes: Vec = Vec::new(); + //We store the vector length + bytes.extend(u64::try_from(input.len()).unwrap().to_be_bytes().to_vec()); + // We store each element + input.iter().for_each(|el| bytes.extend(fr_to_bytes_be(el))); + + bytes +} + +pub fn vec_u8_to_bytes_le(input: &[u8]) -> Vec { + let mut bytes: Vec = Vec::new(); + //We store the vector length + bytes.extend(u64::try_from(input.len()).unwrap().to_le_bytes().to_vec()); + bytes.extend(input); + bytes +} + +pub fn vec_u8_to_bytes_be(input: Vec) -> Vec { + let mut bytes: Vec = Vec::new(); + //We store the vector length + bytes.extend(u64::try_from(input.len()).unwrap().to_be_bytes().to_vec()); + bytes.extend(input); + bytes +} + +pub fn bytes_le_to_vec_u8(input: &[u8]) -> (Vec, usize) { + let mut read: usize = 0; + + let len = u64::from_le_bytes(input[0..8].try_into().unwrap()) as usize; + read += 8; + + let res = input[8..8 + len].to_vec(); + read += res.len(); + + (res, read) +} + +pub fn bytes_be_to_vec_u8(input: &[u8]) -> (Vec, usize) { + let mut read: usize = 0; + + let len = u64::from_be_bytes(input[0..8].try_into().unwrap()) as usize; + read += 8; + + let res = input[8..8 + len].to_vec(); + + read += res.len(); + + (res, read) +} + +pub fn bytes_le_to_vec_fr(input: &[u8]) -> (Vec, usize) { + let mut read: usize = 0; + let mut res: Vec = Vec::new(); + + let len = u64::from_le_bytes(input[0..8].try_into().unwrap()) as usize; + read += 8; + + let el_size = fr_byte_size(); + for i in 0..len { + let (curr_el, _) = bytes_le_to_fr(&input[8 + el_size * i..8 + el_size * (i + 1)]); + res.push(curr_el); + read += el_size; + } + + (res, read) +} + +pub fn bytes_be_to_vec_fr(input: &[u8]) -> (Vec, usize) { + let mut read: usize = 0; + let mut res: Vec = Vec::new(); + + let len = u64::from_be_bytes(input[0..8].try_into().unwrap()) as usize; + read += 8; + + let el_size = fr_byte_size(); + for i in 0..len { + let (curr_el, _) = bytes_be_to_fr(&input[8 + el_size * i..8 + el_size * (i + 1)]); + res.push(curr_el); + read += el_size; + } + + (res, read) +} + +/* Old conversion utilities between different libraries data types + +// Conversion Utilities between poseidon-rs Field and arkworks Fr (in order to call directly poseidon-rs' poseidon_hash) + +use ff::{PrimeField as _, PrimeFieldRepr as _}; +use poseidon_rs::Fr as PosFr; + +pub fn fr_to_posfr(value: Fr) -> PosFr { + let mut bytes = [0_u8; 32]; + let byte_vec = value.into_repr().to_bytes_be(); + bytes.copy_from_slice(&byte_vec[..]); + let mut repr = ::Repr::default(); + repr.read_be(&bytes[..]) + .expect("read from correctly sized slice always succeeds"); + PosFr::from_repr(repr).expect("value is always in range") +} + +pub fn posfr_to_fr(value: PosFr) -> Fr { + let mut bytes = [0u8; 32]; + value + .into_repr() + .write_be(&mut bytes[..]) + .expect("write to correctly sized slice always succeeds"); + Fr::from_be_bytes_mod_order(&bytes) +} + + +// Conversion Utilities between semaphore-rs Field and arkworks Fr + +use semaphore::Field; + +pub fn to_fr(el: &Field) -> Fr { + Fr::try_from(*el).unwrap() +} + +pub fn to_field(el: &Fr) -> Field { + (*el).try_into().unwrap() +} + +pub fn vec_to_fr(v: &[Field]) -> Vec { + v.iter().map(|el| to_fr(el)).collect() +} + +pub fn vec_to_field(v: &[Fr]) -> Vec { + v.iter().map(|el| to_field(el)).collect() +} + +pub fn vec_fr_to_field(input: &[Fr]) -> Vec { + input.iter().map(|el| to_field(el)).collect() +} + +pub fn vec_field_to_fr(input: &[Field]) -> Vec { + input.iter().map(|el| to_fr(el)).collect() +} + +pub fn str_to_field(input: String, radix: i32) -> Field { + assert!((radix == 10) || (radix == 16)); + + // We remove any quote present and we trim + let single_quote: char = '\"'; + let input_clean = input.replace(single_quote, ""); + let input_clean = input_clean.trim(); + + if radix == 10 { + Field::from_str(&format!( + "{:01$x}", + BigUint::from_str(input_clean).unwrap(), + 64 + )) + .unwrap() + } else { + let input_clean = input_clean.replace("0x", ""); + Field::from_str(&format!("{:0>64}", &input_clean)).unwrap() + } +} + +pub fn bytes_le_to_field(input: &[u8]) -> (Field, usize) { + let (fr_el, read) = bytes_le_to_fr(input); + (to_field(&fr_el), read) +} + +pub fn bytes_be_to_field(input: &[u8]) -> (Field, usize) { + let (fr_el, read) = bytes_be_to_fr(input); + (to_field(&fr_el), read) +} + + +pub fn field_to_bytes_le(input: &Field) -> Vec { + fr_to_bytes_le(&to_fr(input)) +} + +pub fn field_to_bytes_be(input: &Field) -> Vec { + fr_to_bytes_be(&to_fr(input)) +} + + +pub fn vec_field_to_bytes_le(input: &[Field]) -> Vec { + vec_fr_to_bytes_le(&vec_field_to_fr(input)) +} + +pub fn vec_field_to_bytes_be(input: &[Field]) -> Vec { + vec_fr_to_bytes_be(&vec_field_to_fr(input)) +} + + +pub fn bytes_le_to_vec_field(input: &[u8]) -> (Vec, usize) { + let (vec_fr, read) = bytes_le_to_vec_fr(input); + (vec_fr_to_field(&vec_fr), read) +} + +pub fn bytes_be_to_vec_field(input: &[u8]) -> (Vec, usize) { + let (vec_fr, read) = bytes_be_to_vec_fr(input); + (vec_fr_to_field(&vec_fr), read) +} + +// Arithmetic over Field elements (wrapped over arkworks algebra crate) + +pub fn add(a: &Field, b: &Field) -> Field { + to_field(&(to_fr(a) + to_fr(b))) +} + +pub fn mul(a: &Field, b: &Field) -> Field { + to_field(&(to_fr(a) * to_fr(b))) +} + +pub fn div(a: &Field, b: &Field) -> Field { + to_field(&(to_fr(a) / to_fr(b))) +} + +pub fn inv(a: &Field) -> Field { + to_field(&(Fr::from(1) / to_fr(a))) +} +*/ diff --git a/pallets/verifier/Cargo.toml b/pallets/verifier/Cargo.toml index 30cd76ff4..b17f4cf8e 100644 --- a/pallets/verifier/Cargo.toml +++ b/pallets/verifier/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Webb Technologies Inc."] description = "A pallet that stores zero-knowledge verifier parameters and provides verification of zero-knowledge proofs." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "pallet-verifier" diff --git a/pallets/verifier/src/lib.rs b/pallets/verifier/src/lib.rs index 64a78c7dc..a20f615f7 100644 --- a/pallets/verifier/src/lib.rs +++ b/pallets/verifier/src/lib.rs @@ -137,7 +137,7 @@ pub mod pallet { #[pallet::error] pub enum Error { /// Parameters haven't been initialized - ParametersNotInitialized, + VerifyingParametersNotInitialized, /// Error during verification VerifyError, } @@ -165,7 +165,7 @@ pub mod pallet { impl, I: 'static> VerifierModule for Pallet { fn verify(public_inp_bytes: &[u8], proof: &[u8]) -> Result { let params = Self::parameters(); - ensure!(!params.is_empty(), Error::::ParametersNotInitialized); + ensure!(!params.is_empty(), Error::::VerifyingParametersNotInitialized); match T::Verifier::verify(public_inp_bytes, proof, ¶ms) { Ok(verified) => Ok(verified), Err(e) => { diff --git a/pallets/verifier/src/tests.rs b/pallets/verifier/src/tests.rs index 68784020b..76448ebd2 100644 --- a/pallets/verifier/src/tests.rs +++ b/pallets/verifier/src/tests.rs @@ -8,7 +8,7 @@ fn should_fail_to_verify_without_parameters() { // Pass arbitrary assert_err!( ::verify(&[], &[1u8; 32]), - Error::::ParametersNotInitialized + Error::::VerifyingParametersNotInitialized ); }); } diff --git a/pallets/xanchor/Cargo.toml b/pallets/xanchor/Cargo.toml index b58d54fdd..95308bc9d 100644 --- a/pallets/xanchor/Cargo.toml +++ b/pallets/xanchor/Cargo.toml @@ -1,5 +1,5 @@ [package] -edition = "2021" +edition = "2018" name = "pallet-xanchor" version = "0.1.0" @@ -51,8 +51,9 @@ ark-ff = { version = "^0.3.0", default-features = false } ark-relations = { version = "^0.3.0", default-features = false } ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] } ark-std = { version = "^0.3.0", default-features = false } -arkworks-native-gadgets = { version = "1.2.0", default-features = false } +ark-bn254 = { version = "^0.3.0", default-features = false, features = [ "curve" ] } arkworks-setups = { version = "1.2.1", features = ["r1cs"], default-features = false } +arkworks-native-gadgets = { version = "1.2.0", default-features = false } webb-primitives = { path = "../../primitives" } diff --git a/pallets/xanchor/src/tests.rs b/pallets/xanchor/src/tests.rs index ed50655a4..12036c08e 100644 --- a/pallets/xanchor/src/tests.rs +++ b/pallets/xanchor/src/tests.rs @@ -34,12 +34,12 @@ fn setup_environment(curve: Curve) -> Vec { // but to do so, we need to have a VerifyingKey let (pk_bytes, vk_bytes) = ( std::fs::read( - "../../substrate-fixtures/fixed-anchor/bn254/x5/2/proving_key.bin", + "../../substrate-fixtures/substrate-fixtures/fixed-anchor/bn254/x5/2/proving_key.bin", ) .expect("Unable to read file") .to_vec(), std::fs::read( - "../../substrate-fixtures/fixed-anchor/bn254/x5/2/verifying_key.bin", + "../../substrate-fixtures/substrate-fixtures/fixed-anchor/bn254/x5/2/verifying_key.bin", ) .expect("Unable to read file") .to_vec(), diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 1b3b44765..f456e3034 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -23,12 +23,14 @@ ark-bls12-381 = { version = "^0.3.0", default-features = false, features = ["cur ark-bn254 = { version = "^0.3.0", default-features = false, features = ["curve"], optional = true } ark-ec = { version = "^0.3.0", default-features = false } ark-ff = { version = "^0.3.0", default-features = false } -ark-groth16 = { version = "^0.3.0", default-features = false } +ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", rev = "765817f", default-features = false, features = ["parallel"] } ark-relations = { version = "^0.3.0", default-features = false } ark-serialize = { version = "^0.3.0", default-features = false, features = ["derive"] } ark-std = { version = "^0.3.0", default-features = false } # ark-circom = { git = "https://github.com/gakonst/ark-circom.git", default-features = false } +byteorder = { version = "1", default-features = false } +num-traits = { version = "0.2.0", default-features = false } blake2 = { version = "0.9", default-features = false } digest = { version = "0.9", default-features = false } diff --git a/primitives/src/field_ops/arkworks.rs b/primitives/src/field_ops/arkworks.rs index e89648a5b..c8d60c8bd 100644 --- a/primitives/src/field_ops/arkworks.rs +++ b/primitives/src/field_ops/arkworks.rs @@ -1,4 +1,3 @@ -use ark_bls12_381::Fr as Bls381; use ark_bn254::Fr as Bn254; use ark_ff::{BigInteger, PrimeField}; use sp_std::{marker::PhantomData, vec::Vec}; @@ -20,4 +19,3 @@ impl IntoPrimeField for ArkworksIntoField { } pub type ArkworksIntoFieldBn254 = ArkworksIntoField; -pub type ArkworksIntoFieldBls381 = ArkworksIntoField; diff --git a/primitives/src/hashing/arkworks.rs b/primitives/src/hashing/arkworks.rs index b4de7f3da..698732a57 100644 --- a/primitives/src/hashing/arkworks.rs +++ b/primitives/src/hashing/arkworks.rs @@ -22,6 +22,3 @@ impl InstanceHasher for ArkworksPoseidonHasher { use ark_bn254::Fr as Bn254; pub type ArkworksPoseidonHasherBn254 = ArkworksPoseidonHasher; - -use ark_bls12_381::Fr as Bls381; -pub type ArkworksPoseidonHasherBls381 = ArkworksPoseidonHasher; diff --git a/primitives/src/hashing/ethereum.rs b/primitives/src/hashing/ethereum.rs index dcc3ba928..cfb18d71d 100644 --- a/primitives/src/hashing/ethereum.rs +++ b/primitives/src/hashing/ethereum.rs @@ -17,6 +17,3 @@ impl InstanceHasher for Keccak256Hasher { use ark_bn254::Fr as Bn254; pub type Keccak256HasherBn254 = Keccak256Hasher; - -use ark_bls12_381::Fr as Bls381; -pub type Keccak256HasherBls381 = Keccak256Hasher; diff --git a/primitives/src/verifying/circom.rs b/primitives/src/verifying/circom.rs index ef1c44594..c1587f9b6 100644 --- a/primitives/src/verifying/circom.rs +++ b/primitives/src/verifying/circom.rs @@ -1,39 +1,56 @@ use crate::*; -use ark_circom::circom; -use ark_crypto_primitives::{Error, SNARK}; -use ark_ec::PairingEngine; -use ark_groth16::{Groth16, Proof as ArkProof, VerifyingKey as ArkVerifyingKey, PreparedVerifyingKey}; +use ark_bn254::{Bn254, Fr}; +use ark_crypto_primitives::Error; use ark_groth16::{ - prepare_verifying_key, verify_proof, + verify_proof, PreparedVerifyingKey, Proof as ArkProof, VerifyingKey as ArkVerifyingKey, }; use ark_serialize::CanonicalDeserialize; +use ark_std::vec::Vec; use arkworks_native_gadgets::to_field_elements; -use ark_circom::ethereum::Proof; -use ark_circom::ethereum::VerifyingKey; -use sp_std::marker::PhantomData; -pub struct CircomVerifierGroth16(PhantomData); +use sp_core::U256; -pub fn verify_groth16( - vk: &PreparedVerifyingKey, - public_inputs: &[E::Fr], - proof: &ArkProof, +pub struct CircomVerifierBn254; + +#[derive(Debug)] +pub enum CircomError { + InvalidVerifyingKeyBytes, + InvalidProofBytes, + InvalidBuilderConfig, + ProvingFailure, + VerifyingFailure, + ParameterGenerationFailure, +} + +impl ark_std::error::Error for CircomError {} + +impl core::fmt::Display for CircomError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + CircomError::InvalidVerifyingKeyBytes => write!(f, "Invalid verifying key bytes"), + CircomError::InvalidProofBytes => write!(f, "Invalid proof bytes"), + CircomError::InvalidBuilderConfig => write!(f, "Invalid builder config"), + CircomError::ProvingFailure => write!(f, "Proving failure"), + CircomError::VerifyingFailure => write!(f, "Verifying failure"), + CircomError::ParameterGenerationFailure => write!(f, "Parameter generation failure"), + } + } +} + +pub fn verify_groth16( + vk: &PreparedVerifyingKey, + public_inputs: &[Fr], + proof: &ArkProof, ) -> Result { let res = verify_proof(vk, proof, public_inputs)?; Ok(res) } -impl InstanceVerifier for CircomVerifierGroth16 { +impl InstanceVerifier for CircomVerifierBn254 { fn verify(public_inp_bytes: &[u8], proof_bytes: &[u8], vk_bytes: &[u8]) -> Result { - let public_input_field_elts = to_field_elements::(public_inp_bytes)?; - let circom_vk = VerifyingKey::from(vk_bytes); - let circom_proof = Proof::from(proof_bytes); - let vk = ArkVerifyingKey::::from(circom_vk)?; - let proof = ArkProof::::from(circom_proof)?; - let res = verify_groth16::(&vk.into(), &public_input_field_elts, &proof)?; + let public_input_field_elts = to_field_elements::(public_inp_bytes)?; + let vk = ArkVerifyingKey::deserialize(vk_bytes)?; + let proof = ArkProof::deserialize(proof_bytes)?; + let res = verify_groth16(&vk.into(), &public_input_field_elts, &proof)?; Ok(res) } } - -use ark_bn254::Bn254; -pub type CircomVerifierBn254 = CircomVerifierGroth16; - diff --git a/primitives/src/verifying/mod.rs b/primitives/src/verifying/mod.rs index 6ef47bf2f..f2bb8555f 100644 --- a/primitives/src/verifying/mod.rs +++ b/primitives/src/verifying/mod.rs @@ -1,5 +1,5 @@ pub mod arkworks; pub use arkworks::*; -// pub mod circom; -// pub use circom::*; +pub mod circom; +pub use circom::*; diff --git a/protocol-substrate-fixtures b/protocol-substrate-fixtures deleted file mode 160000 index 845bdb051..000000000 --- a/protocol-substrate-fixtures +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 845bdb05177a4ab2fd3101bfee4cddf9f19a6821 diff --git a/scripts/fetch-fixtures.sh b/scripts/fetch-fixtures.sh new file mode 100755 index 000000000..d6063ef91 --- /dev/null +++ b/scripts/fetch-fixtures.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Update submodules +git submodule update --init --recursive + +# cd into protocol-solidity submodules +cd solidity-fixtures + +# run dvc pull +dvc pull -v + +# Check if dvc pull succeeds +if [ "$?" -ne 0 ]; then + echo "dvc pull failed in solidity-fixtures" + exit 1 +fi + +# cd out of solidity fixtures +cd .. + +# cd into substrate-fixtures +cd substrate-fixtures + +# run dvc pull +dvc pull -v + +# Check if dvc pull succeeds +if [ "$?" -ne 0 ]; then + echo "dvc pull failed in substrate-fixtures" + exit 1 +fi diff --git a/solidity-fixtures b/solidity-fixtures new file mode 160000 index 000000000..56f98c388 --- /dev/null +++ b/solidity-fixtures @@ -0,0 +1 @@ +Subproject commit 56f98c38805d02e5e60851d27f9e804d5ba0d757 diff --git a/standalone/node/Cargo.toml b/standalone/node/Cargo.toml index 80543d445..ba021ff68 100644 --- a/standalone/node/Cargo.toml +++ b/standalone/node/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Webb Technologies Inc."] build = "build.rs" description = "A fresh FRAME-based Substrate node, ready for hacking." -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "webb-standalone-node" diff --git a/standalone/node/src/chain_spec.rs b/standalone/node/src/chain_spec.rs index 651a9d517..6dd32dc5c 100644 --- a/standalone/node/src/chain_spec.rs +++ b/standalone/node/src/chain_spec.rs @@ -200,20 +200,21 @@ fn testnet_genesis( log::info!("Verifier params for mixer"); let mixer_verifier_bn254_params = { - let vk_bytes = - include_bytes!("../../../substrate-fixtures/mixer/bn254/x5/verifying_key.bin"); + let vk_bytes = include_bytes!( + "../../../substrate-fixtures/substrate-fixtures/mixer/bn254/x5/verifying_key.bin" + ); vk_bytes.to_vec() }; log::info!("Verifier params for vanchor"); let vanchor_verifier_2_2_bn254_params = { let vk_bytes = - include_bytes!("../../../substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key.bin"); + include_bytes!("../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-2-2/verifying_key.bin"); vk_bytes.to_vec() }; let vanchor_verifier_2_16_bn254_params = { let vk_bytes = - include_bytes!("../../../substrate-fixtures/vanchor/bn254/x5/2-16-2/verifying_key.bin"); + include_bytes!("../../../substrate-fixtures/substrate-fixtures/vanchor/bn254/x5/2-16-2/verifying_key.bin"); vk_bytes.to_vec() }; diff --git a/standalone/runtime/Cargo.toml b/standalone/runtime/Cargo.toml index 99a48cc89..df0bf13d4 100644 --- a/standalone/runtime/Cargo.toml +++ b/standalone/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] authors = ["Webb Technologies Inc."] -edition = "2018" +edition = "2021" homepage = "https://substrate.dev" license = "Unlicense" name = "webb-standalone-runtime" diff --git a/substrate-fixtures b/substrate-fixtures new file mode 160000 index 000000000..2ee2d9448 --- /dev/null +++ b/substrate-fixtures @@ -0,0 +1 @@ +Subproject commit 2ee2d9448af09772aedefd22972d4230f7fdc14f diff --git a/substrate-fixtures.dvc b/substrate-fixtures.dvc deleted file mode 100644 index 72bb90603..000000000 --- a/substrate-fixtures.dvc +++ /dev/null @@ -1,12 +0,0 @@ -md5: 556aaf5231aabec2aca01802ccba23d6 -frozen: true -deps: -- path: substrate-fixtures - repo: - url: https://github.com/webb-tools/substrate-fixtures - rev_lock: 2ee2d9448af09772aedefd22972d4230f7fdc14f -outs: -- md5: 9c00cd97c42bef50fcfdb4b8878be0fb.dir - size: 240092288 - nfiles: 35 - path: substrate-fixtures