diff --git a/.gitignore b/.gitignore index d1d65c2e..47d386fd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ .vs/ .idea/ .sub/ -log/ \ No newline at end of file +log/ + +# need to inclue wasm src file +!/pallets/template/res/* diff --git a/.gitmodules b/.gitmodules index fddb8ce7..68b8e6d3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "vendor/substrate"] path = vendor/substrate url = https://github.com/patractlabs/substrate.git - branch = patract-contracts + branch = parity/at-chain-extension diff --git a/Cargo.lock b/Cargo.lock index 79320484..4ea55d20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,186 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" +[[package]] +name = "ark-bls12-377" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/curves#23e87bf224c23be5c5bccc6084aae31fff8bb83f" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bls12-381" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/curves#23e87bf224c23be5c5bccc6084aae31fff8bb83f" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bn254" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/curves#23e87bf224c23be5c5bccc6084aae31fff8bb83f" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bw6-761" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/curves#23e87bf224c23be5c5bccc6084aae31fff8bb83f" +dependencies = [ + "ark-bls12-377", + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-cp6-782" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/curves#23e87bf224c23be5c5bccc6084aae31fff8bb83f" +dependencies = [ + "ark-bls12-377", + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-crypto-primitives" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/crypto-primitives.git?branch=main#ce5cc89011b394eb006987a24088947d5099d641" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-relations", + "ark-snark", + "ark-std", + "bench-utils", + "blake2 0.8.1", + "derivative", + "digest 0.8.1", + "rand 0.7.3", +] + +[[package]] +name = "ark-ec" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/algebra#70ebfa6bed96c6738535a13372e3c30a5008c751" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "num-traits", + "rand 0.7.3", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/algebra#70ebfa6bed96c6738535a13372e3c30a5008c751" +dependencies = [ + "ark-ff-asm", + "ark-serialize", + "ark-std", + "derivative", + "num-traits", + "rand 0.7.3", + "rustc_version 0.3.0", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/algebra#70ebfa6bed96c6738535a13372e3c30a5008c751" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "ark-groth16" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/groth16#412e5a58372b847d4599e0373776cd87dd92d579" +dependencies = [ + "ark-crypto-primitives", + "ark-ec", + "ark-ff", + "ark-poly", + "ark-relations", + "ark-serialize", + "ark-std", + "bench-utils", + "rand 0.7.3", +] + +[[package]] +name = "ark-poly" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/algebra#61bde284e4ed1e61cb0e86df0d5ed73b8e6dfd45" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "rand 0.7.3", +] + +[[package]] +name = "ark-relations" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/snark#0648c547e4f9fda46a40ad0a4896652b87c2316b" +dependencies = [ + "ark-ff", + "ark-std", + "tracing", +] + +[[package]] +name = "ark-serialize" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/algebra#70ebfa6bed96c6738535a13372e3c30a5008c751" +dependencies = [ + "ark-serialize-derive", + "ark-std", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.1.1-alpha.0" +source = "git+https://github.com/arkworks-rs/algebra#70ebfa6bed96c6738535a13372e3c30a5008c751" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ark-snark" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/snark#0648c547e4f9fda46a40ad0a4896652b87c2316b" +dependencies = [ + "ark-ff", + "ark-relations", + "ark-std", + "rand 0.7.3", +] + +[[package]] +name = "ark-std" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/utils#f6974ac72f59339b7ab798a728a84c5a7b8bac45" + [[package]] name = "arrayref" version = "0.3.6" @@ -374,20 +554,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] -name = "bellman_ce" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ca1343d8690bb4d62e0665116bd4f109e33a642f86908ed107d226a402b0ef" -dependencies = [ - "bit-vec", - "byteorder", - "cfg-if 0.1.10", - "crossbeam", - "futures 0.3.8", - "num_cpus", - "pairing_ce", - "rand 0.4.6", -] +name = "bench-utils" +version = "0.1.0" +source = "git+https://github.com/arkworks-rs/utils#f6974ac72f59339b7ab798a728a84c5a7b8bac45" [[package]] name = "bincode" @@ -423,12 +592,6 @@ dependencies = [ "which", ] -[[package]] -name = "bit-vec" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" - [[package]] name = "bitflags" version = "1.2.1" @@ -445,6 +608,18 @@ dependencies = [ "radium", ] +[[package]] +name = "blake2" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" +dependencies = [ + "byte-tools", + "crypto-mac 0.7.0", + "digest 0.8.1", + "opaque-debug 0.2.3", +] + [[package]] name = "blake2" version = "0.9.1" @@ -874,30 +1049,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "crossbeam" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" -dependencies = [ - "cfg-if 0.1.10", - "crossbeam-channel 0.4.4", - "crossbeam-deque 0.7.3", - "crossbeam-epoch 0.8.2", - "crossbeam-queue", - "crossbeam-utils 0.7.2", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils 0.7.2", - "maybe-uninit", -] - [[package]] name = "crossbeam-channel" version = "0.5.0" @@ -1071,6 +1222,17 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "993a608597367c6377b258c25d7120740f00ed23a2252b729b1932dd7866f908" +[[package]] +name = "derivative" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive_more" version = "0.99.11" @@ -1332,32 +1494,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ff_ce" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4592897f75fd1bd178e5ec12d9d7df3d1943464feda2cbce1e708a484e82c8f6" -dependencies = [ - "byteorder", - "ff_derive_ce", - "hex", - "rand 0.4.6", -] - -[[package]] -name = "ff_derive_ce" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c052fa6d4c2f12305ec364bfb8ef884836f3f61ea015b202372ff996d1ac4b" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "file-per-thread-logger" version = "0.1.4" @@ -1820,7 +1956,7 @@ dependencies = [ "cc", "libc", "log", - "rustc_version", + "rustc_version 0.2.3", "winapi 0.3.9", ] @@ -2175,7 +2311,7 @@ dependencies = [ "itoa", "log", "net2", - "rustc_version", + "rustc_version 0.2.3", "time", "tokio 0.1.22", "tokio-buf", @@ -2549,6 +2685,18 @@ dependencies = [ "jupiter-cli", ] +[[package]] +name = "jupiter-chain-extension" +version = "0.1.0" +dependencies = [ + "jupiter-io", + "megaclite-arkworks", + "pallet-contracts", + "parity-scale-codec", + "sp-runtime", + "sp-std", +] + [[package]] name = "jupiter-cli" version = "0.1.0" @@ -2562,7 +2710,7 @@ dependencies = [ "jupiter-runtime-common", "log", "pallet-authority-discovery", - "pallet-contracts 2.0.0 (git+https://github.com/paritytech/substrate)", + "pallet-contracts", "pallet-im-online", "pallet-staking", "parking_lot 0.10.2", @@ -2604,13 +2752,12 @@ dependencies = [ "frame-benchmarking", "frame-benchmarking-cli", "futures 0.3.8", - "jupiter-dev-executor", "jupiter-dev-runtime", "jupiter-io", "jupiter-primitives", "jupiter-rpc", "log", - "pallet-contracts 2.0.0", + "pallet-contracts", "parking_lot 0.10.2", "sc-basic-authorship", "sc-cli", @@ -2631,15 +2778,6 @@ dependencies = [ "substrate-build-script-utils", ] -[[package]] -name = "jupiter-dev-executor" -version = "0.1.0" -dependencies = [ - "frame-benchmarking", - "jupiter-dev-runtime", - "sc-executor", -] - [[package]] name = "jupiter-dev-runtime" version = "0.1.0" @@ -2651,16 +2789,18 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "hex-literal 0.3.1", + "jupiter-chain-extension", "jupiter-primitives", "jupiter-runtime-common", "pallet-authorship", "pallet-balances", - "pallet-contracts 2.0.0", + "pallet-contracts", "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", "pallet-indices", "pallet-randomness-collective-flip", "pallet-sudo", + "pallet-template", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", @@ -2693,8 +2833,11 @@ dependencies = [ name = "jupiter-io" version = "0.2.0" dependencies = [ - "megaclite", + "megaclite-arkworks", + "num-bigint 0.3.1", + "num-traits", "sp-runtime-interface", + "sp-std", ] [[package]] @@ -2745,6 +2888,7 @@ dependencies = [ "frame-support", "frame-system", "frame-system-rpc-runtime-api", + "jupiter-chain-extension", "jupiter-primitives", "jupiter-runtime-common", "pallet-authority-discovery", @@ -2752,7 +2896,7 @@ dependencies = [ "pallet-babe", "pallet-balances", "pallet-collective", - "pallet-contracts 2.0.0 (git+https://github.com/paritytech/substrate)", + "pallet-contracts", "pallet-contracts-primitives", "pallet-contracts-rpc-runtime-api", "pallet-democracy", @@ -3502,11 +3646,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] -name = "megaclite" +name = "megaclite-arkworks" version = "0.1.0" -source = "git+https://github.com/patractlabs/megaclite.git#83484f7c6329fbfc74856c87d6fddf1ef033e43d" -dependencies = [ - "bellman_ce", +source = "git+https://github.com/patractlabs/megaclite.git#40b05c1dee61e1dc77b785e8d12914a9eb7db272" +dependencies = [ + "ark-bls12-377", + "ark-bls12-381", + "ark-bn254", + "ark-bw6-761", + "ark-cp6-782", + "ark-ec", + "ark-ff", + "ark-groth16", + "ark-relations", + "ark-serialize", + "ark-std", + "cfg-if 1.0.0", + "num-bigint 0.3.1", + "parity-scale-codec", + "rand 0.7.3", + "rustc-hex", ] [[package]] @@ -3803,6 +3962,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-bigint" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e9a41747ae4633fce5adffb4d2e81ffc5e89593cb19917f8fb2cc5ff76507bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-complex" version = "0.2.4" @@ -3830,7 +4000,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" dependencies = [ "autocfg", - "num-bigint", + "num-bigint 0.2.6", "num-integer", "num-traits", ] @@ -3914,17 +4084,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "pairing_ce" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc00d65b1d29e0a067a967fcea83d8db261c149f76a557ba73f0304f01cdfde" -dependencies = [ - "byteorder", - "ff_ce", - "rand 0.4.6", -] - [[package]] name = "pallet-authority-discovery" version = "2.0.0" @@ -4018,7 +4177,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "jupiter-io", "pallet-contracts-primitives", "pallet-contracts-proc-macro", "parity-scale-codec", @@ -4035,27 +4193,6 @@ dependencies = [ "wasmi-validation", ] -[[package]] -name = "pallet-contracts" -version = "2.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#c88b104028b4fdda35311adb12eabf7aa5aa4316" -dependencies = [ - "frame-support", - "frame-system", - "pallet-contracts-primitives", - "pallet-contracts-proc-macro", - "parity-scale-codec", - "parity-wasm 0.41.0", - "pwasm-utils 0.16.0", - "serde", - "sp-core", - "sp-io", - "sp-runtime", - "sp-sandbox", - "sp-std", - "wasmi-validation", -] - [[package]] name = "pallet-contracts-primitives" version = "2.0.0" @@ -4368,6 +4505,31 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-template" +version = "2.0.0" +dependencies = [ + "assert_matches", + "frame-benchmarking", + "frame-support", + "frame-system", + "hex", + "jupiter-chain-extension", + "jupiter-io", + "jupiter-runtime-common", + "megaclite-arkworks", + "pallet-balances", + "pallet-contracts", + "pallet-randomness-collective-flip", + "pallet-timestamp", + "pallet-transaction-payment", + "parity-scale-codec", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-timestamp" version = "2.0.0" @@ -4621,7 +4783,7 @@ checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ "lock_api 0.3.4", "parking_lot_core 0.6.2", - "rustc_version", + "rustc_version 0.2.3", ] [[package]] @@ -4655,7 +4817,7 @@ dependencies = [ "cloudabi 0.0.3", "libc", "redox_syscall", - "rustc_version", + "rustc_version 0.2.3", "smallvec 0.6.13", "winapi 0.3.9", ] @@ -5209,7 +5371,7 @@ checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" dependencies = [ "bitflags", "cc", - "rustc_version", + "rustc_version 0.2.3", ] [[package]] @@ -5236,7 +5398,7 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ - "crossbeam-channel 0.5.0", + "crossbeam-channel", "crossbeam-deque 0.8.0", "crossbeam-utils 0.8.0", "lazy_static", @@ -5429,6 +5591,15 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c94201b44764d6d1f7e37c15a8289ed55e546c1762c7f1d57f616966e0c181" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rustls" version = "0.18.1" @@ -5490,7 +5661,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d3d055a2582e6b00ed7a31c1524040aa391092bf636328350813f3a0605215c" dependencies = [ - "rustc_version", + "rustc_version 0.2.3", ] [[package]] @@ -5751,7 +5922,7 @@ dependencies = [ "futures-timer 3.0.2", "log", "merlin", - "num-bigint", + "num-bigint 0.2.6", "num-rational", "num-traits", "parity-scale-codec", @@ -6812,12 +6983,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "795dd7aeeee24468e5a32661f6d27f7b5cbed802031b2d7640c7b10f8fb2dd50" dependencies = [ "aes-gcm", - "blake2", + "blake2 0.9.1", "chacha20poly1305", "rand 0.7.3", "rand_core 0.5.1", "ring", - "rustc_version", + "rustc_version 0.2.3", "sha2 0.9.2", "subtle 2.3.0", "x25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index b01b94b4..82c3e4f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ members = [ # "runtime/jupiter-para", "primitives", "primitives/io", + "primitives/chain-extension", + "pallets/template", "rpc", ] exclude = ["vendor/substrate"] diff --git a/bin/node-dev/cli/Cargo.toml b/bin/node-dev/cli/Cargo.toml index 08dd19e9..05b123a0 100644 --- a/bin/node-dev/cli/Cargo.toml +++ b/bin/node-dev/cli/Cargo.toml @@ -14,7 +14,7 @@ structopt = "0.3.8" parking_lot = "0.10.0" serde_json = "1.0" -sc-cli = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master" } +sc-cli = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master", features = ["wasmtime"] } sp-core = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } sc-executor = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master" } sc-service = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master" } @@ -36,7 +36,7 @@ frame-benchmarking-cli = { version = "2.0.0", git = "https://github.com/parityte jupiter-primitives = { path = "../../../primitives" } jupiter-dev-runtime = { path = "../../../runtime/jupiter-dev" } -jupiter-dev-executor = { path = "../executor" } +# jupiter-dev-executor = { path = "../executor" } jupiter-rpc = { path = "../../../rpc" } jupiter-io = { path = "../../../primitives/io" } diff --git a/bin/node-dev/cli/src/chain_spec.rs b/bin/node-dev/cli/src/chain_spec.rs index ffea78d2..7335da0d 100644 --- a/bin/node-dev/cli/src/chain_spec.rs +++ b/bin/node-dev/cli/src/chain_spec.rs @@ -34,7 +34,8 @@ where } pub fn development_config() -> Result { - let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?; + let wasm_binary = + WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?; Ok(ChainSpec::from_genesis( // Name diff --git a/bin/node-dev/cli/src/command.rs b/bin/node-dev/cli/src/command.rs index a37c7930..b7217ac8 100644 --- a/bin/node-dev/cli/src/command.rs +++ b/bin/node-dev/cli/src/command.rs @@ -1,4 +1,3 @@ -use jupiter_dev_executor::Executor; use jupiter_dev_runtime::Block; use sc_cli::{ChainSpec, Role, RuntimeVersion, SubstrateCli}; use sc_service::PartialComponents; @@ -6,7 +5,7 @@ use sc_service::PartialComponents; use crate::chain_spec; use crate::cli::{Cli, Subcommand}; use crate::service; -use crate::service::new_partial; +use crate::service::{new_partial, Executor}; impl SubstrateCli for Cli { fn impl_name() -> String { diff --git a/bin/node-dev/cli/src/service.rs b/bin/node-dev/cli/src/service.rs index f0a875b6..da691390 100644 --- a/bin/node-dev/cli/src/service.rs +++ b/bin/node-dev/cli/src/service.rs @@ -21,7 +21,7 @@ native_executor_instance!( pub Executor, jupiter_dev_runtime::api::dispatch, jupiter_dev_runtime::native_version, - (frame_benchmarking::benchmarking::HostFunctions, jupiter_io::zk_snarks::HostFunctions), + (frame_benchmarking::benchmarking::HostFunctions, jupiter_io::pairing::HostFunctions), ); /// Returns most parts of a service. Not enough to run a full chain, @@ -158,7 +158,7 @@ pub fn new_full(config: Configuration) -> Result { task_manager: &mut task_manager, transaction_pool: transaction_pool.clone(), telemetry_connection_sinks: telemetry_connection_sinks.clone(), - rpc_extensions_builder: rpc_extensions_builder, + rpc_extensions_builder, on_demand: None, remote_blockchain: None, backend, diff --git a/bin/node-dev/executor/Cargo.toml b/bin/node-dev/executor/Cargo.toml deleted file mode 100644 index 4eb9c916..00000000 --- a/bin/node-dev/executor/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "jupiter-dev-executor" -version = "0.1.0" -authors = ["Jupiter "] -edition = "2018" - -[dependencies] -frame-benchmarking = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } -sc-executor = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master" } -jupiter-dev-runtime = { path = "../../../runtime/jupiter-dev" } - -[features] -wasmtime = [ - "sc-executor/wasmtime", -] -wasmi-errno = [ - "sc-executor/wasmi-errno", -] diff --git a/bin/node-dev/executor/src/lib.rs b/bin/node-dev/executor/src/lib.rs deleted file mode 100644 index e8529090..00000000 --- a/bin/node-dev/executor/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -use sc_executor::native_executor_instance; -pub use sc_executor::NativeExecutor; - -// Declare an instance of the native executor named `Executor`. Include the wasm binary as the -// equivalent wasm code. -native_executor_instance!( - pub Executor, - jupiter_dev_runtime::api::dispatch, - jupiter_dev_runtime::native_version, - frame_benchmarking::benchmarking::HostFunctions, -); diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 312d4e1f..8ebfc730 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -37,7 +37,8 @@ sp-authority-discovery = { version = "2.0.0", git = "https://github.com/parityte sc-cli = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sc-service = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master", optional = true } -pallet-contracts = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } +# pallet-contracts = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-contracts = { package = "pallet-contracts", path = "../../../vendor/substrate/frame/contracts" } pallet-authority-discovery = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } pallet-im-online = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } pallet-staking = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/bin/node/cli/src/chain_spec.rs b/bin/node/cli/src/chain_spec.rs index 10359a77..7a6d7a89 100644 --- a/bin/node/cli/src/chain_spec.rs +++ b/bin/node/cli/src/chain_spec.rs @@ -3,7 +3,7 @@ use std::convert::TryInto; use hex_literal::hex; -use sc_service::ChainType; +use sc_service::{config::TelemetryEndpoints, ChainType}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public}; @@ -24,7 +24,7 @@ use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_staking::{Forcing, StakerStatus}; // The URL for the telemetry server. -// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +const PATRACT_TELEMETRY_URL: &str = "wss://telemetry.patract.io/submit"; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -196,10 +196,10 @@ pub fn staging_testnet_config() -> Result { let root_key: AccountId = hex!["8a5b214c82362a8aba60af2a5fee63989f1ae4ce3ec802251c0b3ff9f4ad1826"].into(); // bash: - // for i in 1 2; do for j in stash controller; do subkey inspect "$SECRET//$i//$j"; done; done - // for i in 1 2; do for j in babe; do subkey inspect --scheme Sr25519 "$SECRET//$i//$j"; done; done - // for i in 1 2; do for j in grandpa; do subkey inspect --scheme Ed25519 "$SECRET//$i//$j"; done; done - // for i in 1 2; do for j in im_online; do subkey inspect --scheme Sr25519 "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in stash controller; do subkey inspect "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in babe; do subkey inspect --scheme Sr25519 "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in grandpa; do subkey inspect --scheme Ed25519 "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in im_online; do subkey inspect --scheme Sr25519 "$SECRET//$i//$j"; done; done // stash & controller let (stash1, controller1): (AccountId, AccountId) = ( @@ -214,13 +214,31 @@ pub fn staging_testnet_config() -> Result { // 5DMRmiSn4DTdo7HZM2frH88UZFapYGMCgEQukpD6yd5fc1Pm hex!["38fd41ccf5b2020e4f79ab9007e0496096ff5edd692c57cba1dbfce5eaa77c69"].into(), ); + let (stash3, controller3): (AccountId, AccountId) = ( + // 5EEbdKijxzqspBP1SKAbE7gREHx4m5AXfAAB9vaga9rWkEFB + hex!["6003f2d767ffb437bad9a5cdf0ea3782cbb36207edd3e284a84eba2419ae3c4d"].into(), + // 5G9ALoW7Ccpm8zDwz21RdGHRFhfGYQKFgMDf7JkYXFCnLKHo + hex!["b4571275b5dfdcafca6f42e77dd627da0ecde9bd9e60426b38d90dbca511a654"].into(), + ); + let (stash4, controller4): (AccountId, AccountId) = ( + // 5GvFNec4YCaH2Wu5ysmG938AjtHcrka2h6u8GD9aEiJHut7n + hex!["d6ba0dd1b58e3fe1a380f51f289e5745d2bdf3dfef712e5febaea4f867c57429"].into(), + // 5Cafs4eRGLi9yyat5YwduLNL2xZA36PoLKjvApk1Cm1ScMwA + hex!["16daa7070bf20d6170f39b468b5abadd5d0ad810f7c1e8303fa48a79081d6d44"].into(), + ); // babe - // 5EtZp8WCs4yRDvfLapwU8GrSoS9e7qpXVtYZVCNDFBXuVsiW + // 5DhZaXAow1FwaJPSn2JNHxMqsmjp6reNLWQmPNuqq5PNZ4CW let babe1: BabeId = - hex!["7cf92b27e280cef89900a7d351e37cdc6a578104a71f918165f52fee77aef647"].unchecked_into(); - // 5GRaVtCnSKjeXXXu6S5cVEcqn5yGbnCTGYYeKodxiRbnnZBd + hex!["485872201949c11fed2706383b0bdece75f891e579bf44458b7e40d90ab7b84d"].unchecked_into(); + // 5H3wddAi5xfRvGApjJ4ZQj3bwHf2UNxRGdy6397SxZ48ryyK let babe2: BabeId = - hex!["c0dc511c88d7ef3bc5b465de48aac4efc643283f179b93d413f97e4a7aac714b"].unchecked_into(); + hex!["dc984b002d46efcadf477db5fa64fccc14282999663ec909bb6e90b16de24e23"].unchecked_into(); + // 5Do1StjFe2SPe6fUCKWyVwTg9CKGAd2ZRir2e7XSdQVo6K83 + let babe3: BabeId = + hex!["4c7fc0fe786089da8571fb20b2546d31b6be583b4c640cdf2878461c6ab6ee15"].unchecked_into(); + // 5Gs4SpDKNQDZxPtB3asd6B3M7mwo8VMasW7YLwLiNu1or4cG + let babe4: BabeId = + hex!["d44b87bdd403d8b7380ae2380cae6fea08a965c8910791c89b8b595eac90e474"].unchecked_into(); // grandpa // 5CwDbbQZY7dWGhgPvGqbi2WnhcFw7WkpW2ZrmvSvhtM7qVKn let grandpa1: GrandpaId = @@ -228,20 +246,38 @@ pub fn staging_testnet_config() -> Result { // 5G6VvSAqrqNLoqoRM4GUxrKQkfHuZ3ggnW8bbsQZbi187kfu let grandpa2: GrandpaId = hex!["b24f3f629e5cc692b50f08b9714c67be656b057293bb077beb44781a9a0e2992"].unchecked_into(); + // 5DTqERGezEdBkhNKaAczspP9MTzv73GAQr91Rf1t82csFUbJ + let grandpa3: GrandpaId = + hex!["3ddfb449782bb812d1a85a1a05870667549847c254ab981a4586c43d89f09203"].unchecked_into(); + // 5FVKQ3FXyUSGWt8eBK6Q2NJuzoZaSBtoukGPfqbMfb4RtqV4 + let grandpa4: GrandpaId = + hex!["977a3b37d4be87bcdc027461c30d6c5f7a0e2c4fc11c91b618444a1be9a2b18c"].unchecked_into(); // im_online - // 5EtZp8WCs4yRDvfLapwU8GrSoS9e7qpXVtYZVCNDFBXuVsiW + // 5DCVpVpaogBmFaovbpLkvjdzwsNoASYZoFDhyLvGBCi4YdLa let imonline1: ImOnlineId = - hex!["7cf92b27e280cef89900a7d351e37cdc6a578104a71f918165f52fee77aef647"].unchecked_into(); - // 5GRaVtCnSKjeXXXu6S5cVEcqn5yGbnCTGYYeKodxiRbnnZBd + hex!["322dacd21c5f1db0a530fb8e3d87c5347d9c2e01aab574fea5797ef76a239147"].unchecked_into(); + // 5EcYTkD6yYBUvtfBi7Y5VtZzCDMfqhGbe2LWTm7yrjudC8VC let imonline2: ImOnlineId = - hex!["c0dc511c88d7ef3bc5b465de48aac4efc643283f179b93d413f97e4a7aac714b"].unchecked_into(); - // authority_discovery - // 5EtZp8WCs4yRDvfLapwU8GrSoS9e7qpXVtYZVCNDFBXuVsiW + hex!["70c0b15510e3d2d1fda9dbc7568c211932ef6aa49eb4bf48a7068dbeb9acf26e"].unchecked_into(); + // 5EWsJmZebbHLAnghieEMKrpBpTmu7bSGaT6VRfcV7tpmFnvX + let imonline3: ImOnlineId = + hex!["6c6ca8b2c42dd0f37981a89998ef37ccb05b6808518e96e01a3d920e02cb6452"].unchecked_into(); + // 5ESAnfDPdLXAozgazozAPsyoJXy6xD9c1WBbyKQ4pxRZGn5D + let imonline4: ImOnlineId = + hex!["68d7471ed1508b29497258a46a0cd0bd2eb5b3cce8eefb03b09044827b3bdf0c"].unchecked_into(); + // authority_discovery (same as im_online) + // 5DCVpVpaogBmFaovbpLkvjdzwsNoASYZoFDhyLvGBCi4YdLa let audi1: AuthorityDiscoveryId = - hex!["7cf92b27e280cef89900a7d351e37cdc6a578104a71f918165f52fee77aef647"].unchecked_into(); - // 5GRaVtCnSKjeXXXu6S5cVEcqn5yGbnCTGYYeKodxiRbnnZBd + hex!["322dacd21c5f1db0a530fb8e3d87c5347d9c2e01aab574fea5797ef76a239147"].unchecked_into(); + // 5EcYTkD6yYBUvtfBi7Y5VtZzCDMfqhGbe2LWTm7yrjudC8VC let audi2: AuthorityDiscoveryId = - hex!["c0dc511c88d7ef3bc5b465de48aac4efc643283f179b93d413f97e4a7aac714b"].unchecked_into(); + hex!["70c0b15510e3d2d1fda9dbc7568c211932ef6aa49eb4bf48a7068dbeb9acf26e"].unchecked_into(); + // 5EWsJmZebbHLAnghieEMKrpBpTmu7bSGaT6VRfcV7tpmFnvX + let audi3: AuthorityDiscoveryId = + hex!["6c6ca8b2c42dd0f37981a89998ef37ccb05b6808518e96e01a3d920e02cb6452"].unchecked_into(); + // 5ESAnfDPdLXAozgazozAPsyoJXy6xD9c1WBbyKQ4pxRZGn5D + let audi4: AuthorityDiscoveryId = + hex!["68d7471ed1508b29497258a46a0cd0bd2eb5b3cce8eefb03b09044827b3bdf0c"].unchecked_into(); let initial_authorities: Vec = vec![ ( @@ -260,6 +296,22 @@ pub fn staging_testnet_config() -> Result { imonline2, audi2, ), + ( + controller3.clone(), + stash3.clone(), + babe3, + grandpa3, + imonline3, + audi3, + ), + ( + controller4.clone(), + stash4.clone(), + babe4, + grandpa4, + imonline4, + audi4, + ), ]; Ok(ChainSpec::from_genesis( @@ -282,17 +334,28 @@ pub fn staging_testnet_config() -> Result { stash1.clone(), controller2.clone(), stash2.clone(), + controller3.clone(), + stash3.clone(), + controller4.clone(), + stash4.clone(), ], true, ) }, // Bootnodes vec![ - "/dns/p2p.staging-1.patract.io/tcp/30333/p2p/12D3KooWERffViUKxaPU1XEpQ11wPyjBM775XZU6jkApz25wxzEZ".to_string().try_into().expect("must be valid bootnode"), - "/dns/p2p.staging-2.patract.io/tcp/30334/p2p/12D3KooWK4YK8jbwirhMsmfMX4QgyihZJGQz72G1Jd4iV8zLjjpq".to_string().try_into().expect("must be valid bootnode"), + "/dns/staging-1.jupiter.p2p.patract.io/tcp/30333/p2p/12D3KooWA8LCSwvSvrsVL5ANMzY5z23NDKrnSqLtyNq3geRmUsRT".to_string().try_into().expect("must be valid bootnode"), + "/dns/staging-2.jupiter.p2p.patract.io/tcp/30334/p2p/12D3KooWSZAzpj81ouT2bZJFbfL6JTKiMiGZZq82AJZMUDB23JJ5".to_string().try_into().expect("must be valid bootnode"), + "/dns/staging-3.jupiter.p2p.patract.io/tcp/30335/p2p/12D3KooWEm8wPo1AAZeiNifEGPz6doJeQeyk3z5343scxpiU46ef".to_string().try_into().expect("must be valid bootnode"), + "/dns/staging-4.jupiter.p2p.patract.io/tcp/30336/p2p/12D3KooWMx9TH6AtZf8y7DnVxDfYJmLPrL43uVbrhsnH8JtsvH2r".to_string().try_into().expect("must be valid bootnode"), ], // Telemetry - None, + Some(TelemetryEndpoints::new( + vec![ + (PATRACT_TELEMETRY_URL.to_string(), 0) + ]) + .expect("Polkadot Staging telemetry url is valid; qed"), + ), // Protocol ID Some("jupiter_staging_testnet"), // Properties @@ -322,6 +385,13 @@ fn testnet_genesis( const ENDOWMENT: u128 = 1_000_000 * DOTS; const STASH: u128 = 100 * DOTS; + let mut endowed_accounts: Vec = endowed_accounts; + initial_authorities.iter().for_each(|x| { + if !endowed_accounts.contains(&x.0) { + endowed_accounts.push(x.0.clone()) + } + }); + GenesisConfig { frame_system: Some(SystemConfig { // Add Wasm runtime to storage. @@ -332,7 +402,6 @@ fn testnet_genesis( balances: endowed_accounts .iter() .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) .collect(), }), pallet_indices: Some(IndicesConfig { indices: vec![] }), @@ -359,7 +428,11 @@ fn testnet_genesis( }, }), pallet_staking: Some(StakingConfig { - validator_count: initial_authorities.len() as u32 * 2, + validator_count: if initial_authorities.len() < 4 { + initial_authorities.len() as u32 * 2 + } else { + 50 + }, minimum_validator_count: initial_authorities.len() as u32, stakers: initial_authorities .iter() diff --git a/pallets/template/Cargo.toml b/pallets/template/Cargo.toml new file mode 100644 index 00000000..bf885413 --- /dev/null +++ b/pallets/template/Cargo.toml @@ -0,0 +1,69 @@ +[package] +authors = ['Anonymous'] +edition = '2018' +name = 'pallet-template' +version = "2.0.0" +license = "Unlicense" +homepage = "https://substrate.dev" +repository = "https://github.com/paritytech/substrate/" +description = "FRAME pallet template for defining custom runtime logic." +readme = "README.md" + +[package.metadata.docs.rs] +targets = [ "x86_64-unknown-linux-gnu" ] + +[dependencies] +codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false} +hex = { version = "0.4.2", optional = true, default-features = false } + +[dependencies.jupiter-io] +package = "jupiter-io" +path = "../../primitives/io" +default-features = false + +[dependencies.curve] +package = "megaclite-arkworks" +git = "https://github.com/patractlabs/megaclite.git" +features = ["tests"] +default-features = false + +[dependencies.contract] +package = "pallet-contracts" +path = "../../vendor/substrate/frame/contracts" +default-features = false + +[dev-dependencies] +hex = "0.4.2" +assert_matches = "1.3.0" +pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-randomness-collective-flip = { git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" } +jupiter-runtime-common = { path = "../../runtime/common" } +jupiter-chain-extension = { path = "../../primitives/chain-extension" } + +[features] +default = ['std'] +std = [ + 'codec/std', + 'contract/std', + 'frame-support/std', + 'frame-system/std', + 'frame-benchmarking/std', + 'jupiter-io/std', + 'sp-std/std', +] +runtime-benchmarks = [ + "hex", + "frame-benchmarking", + 'frame-system/runtime-benchmarks', + 'frame-support/runtime-benchmarks', + 'contract/runtime-benchmarks', +] diff --git a/pallets/template/README.md b/pallets/template/README.md new file mode 100644 index 00000000..8d751a42 --- /dev/null +++ b/pallets/template/README.md @@ -0,0 +1 @@ +License: Unlicense \ No newline at end of file diff --git a/pallets/template/metadata.json b/pallets/template/metadata.json new file mode 100644 index 00000000..1883254a --- /dev/null +++ b/pallets/template/metadata.json @@ -0,0 +1,274 @@ +{ + "metadataVersion": "0.1.0", + "source": { + "hash": "0xf4cd725fc486c0d1e5c9d196641450e301fb0deb5d3f368f9676a9d479aee4a4", + "language": "ink! 3.0.0-rc2", + "compiler": "rustc 1.50.0-nightly" + }, + "contract": { + "name": "groth16", + "version": "0.1.0", + "authors": [ + "[your_name] <[your_email]>" + ] + }, + "spec": { + "constructors": [ + { + "args": [], + "docs": [], + "name": [ + "default" + ], + "selector": "0x6a3712e2" + } + ], + "docs": [], + "events": [], + "messages": [ + { + "args": [ + { + "name": "vk_gamma_abc", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + }, + { + "name": "vk", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "proof", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "public_inputs", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + } + ], + "docs": [], + "mutates": false, + "name": [ + "bls12_377_verify" + ], + "payable": false, + "returnType": { + "displayName": [ + "bool" + ], + "type": 4 + }, + "selector": "0x4e1f2d81" + }, + { + "args": [ + { + "name": "vk_gamma_abc", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + }, + { + "name": "vk", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "proof", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "public_inputs", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + } + ], + "docs": [], + "mutates": false, + "name": [ + "bls12_381_verify" + ], + "payable": false, + "returnType": { + "displayName": [ + "bool" + ], + "type": 4 + }, + "selector": "0x99a06637" + }, + { + "args": [ + { + "name": "vk_gamma_abc", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + }, + { + "name": "vk", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "proof", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "public_inputs", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + } + ], + "docs": [], + "mutates": false, + "name": [ + "bn254_verify" + ], + "payable": false, + "returnType": { + "displayName": [ + "bool" + ], + "type": 4 + }, + "selector": "0xe0282497" + }, + { + "args": [ + { + "name": "vk_gamma_abc", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + }, + { + "name": "vk", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "proof", + "type": { + "displayName": [ + "Vec" + ], + "type": 2 + } + }, + { + "name": "public_inputs", + "type": { + "displayName": [ + "Vec" + ], + "type": 1 + } + } + ], + "docs": [], + "mutates": false, + "name": [ + "bw6_761" + ], + "payable": false, + "returnType": { + "displayName": [ + "bool" + ], + "type": 4 + }, + "selector": "0x4399fe06" + } + ] + }, + "storage": { + "struct": { + "fields": [] + } + }, + "types": [ + { + "def": { + "sequence": { + "type": 2 + } + } + }, + { + "def": { + "sequence": { + "type": 3 + } + } + }, + { + "def": { + "primitive": "u8" + } + }, + { + "def": { + "primitive": "bool" + } + } + ] +} \ No newline at end of file diff --git a/pallets/template/res/groth16.wasm b/pallets/template/res/groth16.wasm new file mode 100644 index 00000000..9ef003de Binary files /dev/null and b/pallets/template/res/groth16.wasm differ diff --git a/pallets/template/src/benchmarking.rs b/pallets/template/src/benchmarking.rs new file mode 100644 index 00000000..d4ab6e6e --- /dev/null +++ b/pallets/template/src/benchmarking.rs @@ -0,0 +1,317 @@ +// This file is part of Substrate. + +// Copyright (C) 2020 Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Balances pallet benchmarking. + +#![cfg(feature = "runtime-benchmarks")] +// #![recursion_limit = "256"] + +use super::*; + +use contract::{BalanceOf, Module as Contracts}; +use frame_benchmarking::{benchmarks, whitelisted_caller}; +use frame_support::{traits::Currency, weights::Weight}; +use frame_system::RawOrigin; +use sp_runtime::traits::{Bounded, Hash}; +use sp_std::prelude::*; + +macro_rules! addr { + () => {{ + let caller: T::AccountId = whitelisted_caller(); + let origin = RawOrigin::Signed(caller.clone()); + T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); + + // Put WASM module + let module = include_bytes!("../res/groth16.wasm").to_vec(); + let hash = T::Hashing::hash(&module); + >::put_code(origin.clone().into(), module)?; + if let Err(e) = >::instantiate( + origin.clone().into(), + BalanceOf::::max_value() / 2_u32.into(), // endowment + Weight::max_value(), // gas_limit + hash.clone(), // code_hash + [106, 55, 18, 226].to_vec(), // deafult + b"".to_vec(), // salt + ) { + panic!("{:?}", e); + } + + // Calculate addr + ( + Contracts::::contract_address(&caller, &hash, &b"".to_vec()), + caller, + ) + }}; +} + +benchmarks! { + where_clause { where + T::AccountId: UncheckedFrom, + T::AccountId: AsRef<[u8]>, + } + _ {} + + bls12_377_verify { + let (addr, caller) = addr!(); + let data = hex::decode("4e1f2d8108850171c5a779bb19e0aeb6030768f5001017bbd4edb645306ff1591424c501e7aa8b480fc18d8ed404c893d473afa9b82c01fb3e19bdf85f4fb8acf97d1507b75eb48972c8a10e13f4637f7bee71f89eafc141453e4646c82e188d9ef8cf71fa2f000085014d0869345487bb4070110fa318b0f408dcffce12304589878797615d8a72cc00b6a1e3f50cc0e59770638640090726013db560d3a19288ecedc60ed9ee0afd50ad3ac96db89d99fc249b85a453ef837e9213f8977ac572d818dc43387678a50100910a54f796d78550d14c4ee03cd5915fd8037569696f878312b0093f0149919fc717c0b3f8a2d419fad0edde7e1d55cd2f002c312b660250225a00baf5df511dcce61eb23b28f3980be7fcde0091284670e9064015f452f244e65cad047a20fdd000ca76892d04e1283e575e098c8e4281ba9113443515f22247921b9c3189dc03dd83cf22b9da3eda70cdd2644a795376002e0b1d0d1d5945dab12a28a31497b48d07739028ac3153be3cf367e3d7e788ac43f6d3ccd3c5c20a4f2d6b0db05ce40000f70cb4191a256ed9a4d90305f5864993032a0e40433040c259b14c8069d117f3491d75d993271a0a3f13efdd5b18ce006d90eff3b45f8fa10b43a2d4fb80a554304ba5d94ddc19c92b2e1e2f756bd3042c4c0d6e10b6c22c2ea5eb136fb42900aca080ed5cfa9ccf92da7e4f631f1f9fd52a4dd227898e21585a7a55656f6315fa3f1e541011b941084fb663515ede0024ff6c7745872af24c5de2acfbf4b7a238f3f80face2310d83d9e953de2051a70abc3be988220291e03c92840e1c1c01005720823639fe8f3818ade6c24c6d6ed8f78b87369a9fac8a548e01ca001e424ba931033958641fe06677c3f4a1b39f01f6d3e9a2052ad1185af9a80086665df50b41674f7f6f181773cee6e78d09ea34ce970ccb5907d5cb2f69c9e0ed8d1f01009d629094c47bdf026bbd3424f6e7748b0c3529b495cf24677f309d9f1ed7d3435513224cba204902fd733522b3b855015f395e5b2a7f0fe9e50665d705c48f9b8b20a3f9619f50c1dcddbea7c4a561cdffed750045f875b2d2c569e8d5d0320015e739c8881a211865f82e39bb6ad21a66ceb1808a5ecc3f11833d61dc938a3b160b1b1829527b52e9d3d98800f29701078dfc5fda2f3dcebaca0f43ac23f6da5044f51cf12ac8b3439df503ab1732f5047601b2cd9d93e6d161dc4719beda00000d06e2342d048b06618cfc80a5fb5301373032d5780ca45e5287e824fd1d3dccfc36d1befe73edaea7378968a003f94e1801de729f41f406c7d94db4995cc2956cdd6b250937dd52b3c8ac812dff25985eb802c727dbfb7c6b055db545d687b1bd000090f4ad7dc16060ebfbe2bff08077e404e878850682e15f64a5b0f243f53a6d61dc358d41fa6aed615c6296904d71c200c04fe75b3adbecdc3d00df22556a1c949e4b87c81483225f6eaa7560e3035a1c919c4a0d446125dca2e2ef541d58a200ec9b0644bea1bd34e84ff04b65c0cc8733d425b43225f81a7580e1027a41b4ce85eb513213f54a76e2b69320dc6d51003b06cb148aa149b0b0e1ffb8f5901adbda3e431c19404cae29f26aac97085c6d1d8eeef33024aafdc649da6475ab99000026b3bb740a34b4db3a1c689d471b5a7834bb27fd57108bca8cd88d12bb81eae5f8ad807e5de758978ab51d0146017100c31d5c7971576e79eec56286dc2602025cb1d0a01e1acdc23a8aece6e9f3c3ecf97d0a9667634e31e79f653a93c13b01000480a4961fec1c734055a80af91b3fd7405a2cdb741e1867aa7f783ca0959a077110").expect("Decode failed"); + }: call( + RawOrigin::Signed(caller), + T::Lookup::unlookup(addr), + 0_u32.into(), + Weight::max_value(), + data + ) + + bls12_381_verify { + let (addr, caller) = addr!(); + let data = hex::decode("99a06637088501e60f6032ed7f170ba3481c5d99c0890554c808ad380a7c9aefc9e62eeecf0363ecef5e59ba8eaf6dd0af40e08d7cfd024314f90080a1461a207aa3098308149837bc6322a8f4b499671c507203e798f90a9aa8fafaebb806c8708c3207a93316008501ea7f398187aecf2721441218e54645b17acd35bdf65886255e772a58353ef2e25c92cf7f872bea5afca6081d03e6b115e74befd85720c241ee5ef038621a1cc72e329db9aebec0faf480e83cbd9e4b735650ab0cce2e321d64311bd34bca9e0200910a9094c864d37f890720969430f2682ccc76dc83f9234694590bd334b40dbfa7f28de40e914571d8ae2a88712844f86f0d6dd2f4875120f66304bfcedd55c9a805310155a5345ddc626cbb6fe5ce7026be174a08c798e4d1f1010f97138c30b10a0e23d3cde62852c7b2aabcd7603f87fc54cb0c2fcfa48a1a6e07ea917eec248284a1409dd21ae7bd64b862e7df91fd0af1f36857260a843ea18cd393172b91196ca17bc5f37efb126d585abfcf23b8438d72f90365c382b661256d7caa361d07000c06c5cc02155140b97283cc024daf57023a781a9115bb6e17350264f8b52784a6008921402af8c05dd39f4b789bd50435d2c5aefeb6dc9817af41f45779e3a2d80ab98ef923723b938566747c10a4a169ca5097c5d5073449c3d2e65e16291850a5721416e102df69729ffab67cf948ca51c4ac4c2b54c521552fd4a5a5462d6d3b77ba9932aba0fda8ea8da76e5b0b9166ba600f9c5cc5e442b64ed560c126f8b88e2761c0c6a17a4dcbc1a132a975683ed0b6018ac45d7f4942ad7831790e00408697568bc15871da494a2fe12199531130a8a5b96f07c69020dc01bf9f3ed043a6e1bd08f8d7826c7d5c0fc5c771195ab91bf6eeaa33cbd89cd7dce7930b383c2453d0cca5c227e1b97b1ae253e40cadf4468d6d86f0bf69a0b0bb55774219005b6d86316ea7c1dc4df3e3396a9f78aadf416d5af1619883f5dbbf0a39c6743b194e5adedda54d7cb3ae33e556602e19dd43a31bca7bdb15ad5245dc1ad0affb97edc8f35bb00d1c5b417a132d5be9b72a39870193b6a142198a888c0fe3760fdf1467c7208394270f2aff044c5c002d6cf189a28e34851dc434933e73e07482dad6c7ab931bfbdf29f5d51a6a866d028b91cd89abc9728cf2f8e139f612b5a248ca0758365d1d83c6bc299152b15a89b136e804ae71174d4f35970be570fd14000d06fcafa9753aee681f006d7bf6fc885dcc1a70c33bbfe92bb581ac51e1325b782b1128b1586767cb2ea27555e243abd213634b87418421a65002e06fd9347b23205761d7e35a2a83ffcd35b16b6bf23982700597f2ed9706ae5e039542e8eabd1800443cc8d6ffec17c44207dd41e8ab2f2f2c663f5ed9ab724321de43cbe2ea81908c13643c42a41be1adbc5076e4927b13046d3cdaf5ef775ee48d842599508178276cd41d30e289cbd1d2bb9f92f59b520138fef3e9529139f3961f40f6ea92113ed1701b0eb62a8b21b0852f5ae0d23b4d8cf7a02a69b04abbf0b9213cc1cd16b0afed74a09f1d965f72e0faaad60215c2788b9672a8f53fb90d44b47fb16e4f97f910226d8ad46ddc1dfa6eb4f709a3c95ccfa7f4cd1b9ea5f3cf3d10c5dd0200de094abc5e25fac259efcfd79a97401359069cde3b48eaa9d3a4d848959eb269d788a415d9c22fb418459474f1f0fc16f4572ace2876cf1170d400d1d12d588f816023602a077b8fa66293ac19c951b6c572fad4481fa576e362d9f3a0ffa0120004801d6c7850edbac8a5281ab93d2ed245d47b64f20c21950926d595624b488c291c").expect("Decode failed"); + }: call( + RawOrigin::Signed(caller), + T::Lookup::unlookup(addr), + 0_u32.into(), + Weight::max_value(), + data + ) + + bn254_verify { + let (addr, caller) = addr!(); + let data = hex::decode("e028249708050103c2e806d904d8789f0caf1276fc4897bbf2bbb2e7243df2e4bf941ce616790479b410872e3c6f73f481d3e37b861fc1521d4a70457ac41efbe874fe0bf6572f0005014d609323ed564943ba7dfd3b362cc85abf7691dd9957c613fc0d282f258f4d17cd4ddfa713c0a6d4d0dcbfc245847bd6a96fa8603a0c0d55389279cdf2967f06001107f00c5d68983d7c029a66ae498a1cc6a2423bf67760bbf922ea7a937a87705e158db79bbff4eb9516d5342ce8cd8d09f68fa094434edceebbb43383fc415d9b235c64a2bc82ea6fa740441af956bc764eefb6be4067948d2d7afc08d7dc114a2e1c0c46208e6590bed192c336b7d89f55c2eca918e6f4eb88e1c729a10612690900f70bfb6ec84456af219bcd1d682133db3db80b0ae54cf31879e74a0ae547ec0ef92f56757f4a7976c50dc3d538cb1b4ed1736d4e8e8734d5cbf85b2ac8a93d0b654ff74df7e792b9cf0fd9d1b07b6ce4d0675f57bc7e9740e64b56c9f866b309eb428ffdf69b419fc53b9d76f1de62559aedc6db7e8b6ac2f3dd0cc963ca041300cc165291944a7b617bad2e6f1560f89f4e7eb42f154333b730e2f2da7828911d7cd0a28314d647bae049c72d4e0b4f31c1f09177fcab13014e3060a70024cb210094b31d9ebcca3957fff3d94960b0eba2197fabaaa68776e767e8785f63b4541d456d755240d72dae2ee0452c0cd705d7312b9a1d17cff916e87c763d459a550438b765cd8877bf753869e1852a7c0d9ac4520abb2b935e2f3ec12423d9edc5289eba05bed12e9fe16017c86791d682d4ae86d94eeab1d7888845c0fb0af85805000d04cf3bb657065cd0878eabc53790c5fa3680cad24db586bab799e3ae790217c61ba5050a0024f8761028a11dd22dfc030227b0a6c353ef5e7e1afad863c13a3304000227ad22191396e6ffe7aff14de91d7801e943f836de399b5fd5c8312086440c036648b695ffa27790f2f2a63fcf4c0b130e6b88ac786e3351fc6f13452d18034bee420c244cf7c63db4761f2feb7c14e409c8c550a68940cc0387e3812ccb10c4eb591ff3a67a87e794e2e76e25126b823ea9f38f95730951f13784e6e10f26007a922013b86567d6d48ff65baf8cdd0558c52db98f27b6c216df96f8aa1d4d2df7b1ead51d93e93ef5abdff83acaabd54736546f6995083127be1ae281ca5200000480829d3d572251103bac02b39e397c657c0b1f372bfc4d1b74f6c23de4993b4824").expect("Decode failed"); + }: call( + RawOrigin::Signed(caller), + T::Lookup::unlookup(addr), + 0_u32.into(), + Weight::max_value(), + data + ) + + bw6_761_verify { + let (addr, caller) = addr!(); + let data = hex::decode("4399fe0608050329f6308fb1faee384c2deae7744b65d79eafa98a3947df7e35330c73ad0165a2f92844dab884fec1e15e52ac08f9306a1d8e7b4b66f718cece36a90f9aafe59588aafcd6588a55b9c05c3177904e5cbd1e3b59e4077d1caff6329268b5882200e349c8213aacabd50f11abe7f59b68fdd37f17b7fe6cee7ec3d04dca42812df1854c6c14234dd6fb7f64220949439c660ede18a5e79c8a115b942bbb7812b89be516469237a138752f6f798bcaf6afdf261e471f6c808aacd4274293cb8aff00000503639a14c4e08b97d97166d09eff9b57abf973b487fd5f5007c6ccc8adc31dbac74372477c035964e06f06d93e1483fe81ef1b51e525ffad28a053af20271dd363353e7ccd34cd599ac7c8c97fc175e4d9db8b9399db1647f52564757781209b001cc3d1e9665bc2a8b7e82d2d074e595f297df3dff536046353057a150f6a453521182a7219ef5d38ae85efd3b505f16549ed4bd63b7166e3a4f82142f584b3ad3e27c371db05cc0ba8a8f870fefccd9eb6e5635d6684193aa4b60082a0b2ac0000110c73174e4bb9c9b03c5ee9ddf21056832e01546744fffc64a5221e7e5cee09d37e534b27ae3725db7d3706c85b3932b269078f55cf1dd54c6e3247ad9a7619ef71315f5fee37909c44a216246c2ba2889b7b00b7f1298f5fb2776562527f4014008864e0733bfdd0d8f599c8bccd50d2204e3dab1863fc52e8a30476c836c16e3e6f7d098f0b34fd9edde526f9039323dcb0228a5e7c6841dcda703efe88d7331ba7d096b5753f442647e643d8ac9dfdd9d85b44824bbcc29ee8b4596e1cee520000d1e9ebd9d4d430b34703ac55be08c6d63e791dd2da3f7543b5d6db64e6ce9e0cfb031c168e2bede9cbd39070ecb4e1678d41cd0d48b087fa8a324964fded508df2ef48a7a6c21f1fe95e89aa98b00fb59bee1713e4ffaba216f00e5f15d12201f23da7e61729bc8866bcdd39bcd7d74e6cc9f9192b94c45c6753b60cef11c3b0474eaa53b3beaf3ee9f3885a547ae21385b5a5d5f15be620b9f2669573461b56e74dd326b48662cd271d1a21bb0c120f45d6bbdc632261908bc6e3ab4356480000be5dddc202ba74caa75135e9f81338910969729484a89a438090564689177b491e67f8cfa06ecfcee4acfd7cd364e094c1a4d028f7c7e0677d066cdf1355123e976fa498af59e308954054051fb3fabdda4b0d7a165cd454a71c53ff26546d000b193a142d557066f0a66964c249e4ee2d0247969ecfe861014dd4f36956da4c870ff3fbd6e16999cd43dc27c2fb2a5d72c7317dbc22d2f32541c1489a7bf716e698f898299c0ddfd09e3a892d2aa2940eec0b9f0cf63e52d83cd5dba7be50000021a8ba5d55fabd1999a5a9d717008e812486fd4309d9b4fb75ce4d22199360d6f8855d2e55259220392a9a67b9104adfa1424633f0c527b5516535d43c2632e594a118c05394ea735234b998018ac2906d7f24f89226bb07d1229c6000b13900b565ae54006fc9ef616aa866efa0e85b4c8d5a13ee55d60a478a0ea0b0cc29bc1fcab4045b6f980297a1815dcfbf5ad3031a0bb4429ad863f8695719b68208d1cd4e515a2b3129142a4bbdca3c3cde033c6256daa1fb79f133f28147a40c5200000d09cf5ea12a32dc313ec0791efdfca4ffa5dca127faeb57027754f0fcdd0e868623082e4543cae1bb11078c359dabbd4abbb38640c75081dca4aa2ef35bdb5ee4c856465c7b75956b88ab36d940a8df7e13adaa709ee349ed9454c7d6705211020087f361ca8cb2e83018809872a71853f0eb99a989362a3a753edbe4f58feec45c19be03b06567b357ec6779f3756b1494b74d98503d5c67ef3548ca9464d7525a3f92cdf335702a76eaaff83330f9da2c4a84b02a99ce06e0b04a1a0f1fd2f80000335b53718581ba3e14b48e381078551ff535a3d7a1671dc42898e742857f158a27d249a4d3bbe060016acdf3e9bde0095b23e073e40d56027474673321542ab30641f50f61452762d66984e33745d9456c5eba2cdafc07a52525ef1d3e221e00c92be8c3030de0338c27d281e887a63ab927478464faa7e7b0bbc68de44734c20cfd24763b8384fc6a15b2f82bf0349b86392aaa2e6fc2c95c1d0891f83a92d3b2c1deb230316eb43d9ddcbd069e600aff23ef13dd1f7b9cfade33db4872300000d1367d1907cd90da19e25e3241fb83393731c0d6183300675275017cc6287f2154abf2320cdc2cefc9df0383f98688e2e22914bef4fc32136222fb9dde45840de012e91cce1d02fbb6250a342b72c8c4155e0ff2ffa7ee71211f2641e816f200f8e725a65be98dafc395c538b2c1a009af190aedb99ecae9410257b5b295fb757dc7af138db54d06c582021442342f8924e092ae2fbf375fe94d6480910f7154b14aec033bd5cf27a2cdd225282b7a2fcaab6ac338a89d994c45976d9b7fa1000004c028933fc1b649ded455bd7739026be2bf6f7e1c0acde6dee164724218bbf1391e318017e5a6ab8248bda0bdd1f40b8301").expect("Decode failed"); + }: call( + RawOrigin::Signed(caller), + T::Lookup::unlookup(addr), + 0_u32.into(), + Weight::max_value(), + data + ) + + wasm_bls12_377_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_377_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_377_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_377_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_377_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_377_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_377_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_377_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_377_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_377_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + // bls12_381 + + wasm_bls12_381_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_381_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_381_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_381_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bls12_381_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_381_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_381_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_381_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_381_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bls12_381_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + // bn254 + + wasm_bn254_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bn254_mul { + let caller: T::AccountId = whitelisted_caller(); + }: wasm_bn254_mul(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bn254_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bn254_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bn254_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bn254_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bn254_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bn254_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bn254_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bn254_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + // bw6_761 + + wasm_bw6_761_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bw6_761_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bw6_761_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bw6_761_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + wasm_bw6_761_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bw6_761_add { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bw6_761_mul { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bw6_761_pairing_two { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bw6_761_pairing_six { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} + + native_bw6_761_verify { + let caller: T::AccountId = whitelisted_caller(); + }: _(RawOrigin::Signed(caller.clone())) + verify {} +} diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs new file mode 100644 index 00000000..986c2a4e --- /dev/null +++ b/pallets/template/src/lib.rs @@ -0,0 +1,314 @@ +#![cfg_attr(not(feature = "std"), no_std)] +#![recursion_limit = "256"] + +use contract::{BalanceOf, CodeHash, Gas, Module as Contracts}; +/// Edit this file to define custom logic or remove it if it is not needed. +/// Learn more about FRAME and the core library of Substrate FRAME pallets: +/// https://substrate.dev/docs/en/knowledgebase/runtime/frame +use frame_support::{decl_error, decl_event, decl_module, decl_storage, dispatch, traits::Get}; +use sp_core::crypto::UncheckedFrom; +use sp_runtime::traits::StaticLookup; +use sp_std::vec::Vec; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + +/// Configure the pallet by specifying the parameters and types on which it depends. +pub trait Config: frame_system::Config + contract::Config { + /// Because this pallet emits events, it depends on the runtime's definition of an event. + type Event: From> + Into<::Event>; + // type AccountId: contract::Config::AccountId; +} + +// The pallet's runtime storage items. +// https://substrate.dev/docs/en/knowledgebase/runtime/storage +decl_storage! { + // A unique name is used to ensure that the pallet's storage items are isolated. + // This name may be updated, but each pallet in the runtime must use a unique name. + // ---------------------------------vvvvvvvvvvvvvv + trait Store for Module as TemplateModule + where + T::AccountId: AsRef<[u8]>, + T::AccountId: UncheckedFrom, + { + // The Contract + pub Contract: CodeHash; + } +} + +// Pallets use events to inform users when important changes are made. +// https://substrate.dev/docs/en/knowledgebase/runtime/events +decl_event!( + pub enum Event + where + AccountId = ::AccountId, + { + /// Event documentation should end with an array that provides descriptive names for event + /// parameters. [something, who] + SomethingStored(u32, AccountId), + } +); + +// Errors inform users that something went wrong. +decl_error! { + pub enum Error for Module + where + T::AccountId: AsRef<[u8]>, + T::AccountId: UncheckedFrom, + { + /// Error names should be descriptive. + NoneValue, + /// The contract we just put disappeared + ContractDisappeared, + /// Failed + InstantiateContractFailed + } +} + +// Dispatchable functions allows users to interact with the pallet and invoke state changes. +// These functions materialize as "extrinsics", which are often compared to transactions. +// Dispatchable functions must be annotated with a weight and must return a DispatchResult. +decl_module! { + pub struct Module for enum Call + where + origin: T::Origin, + T::AccountId: AsRef<[u8]>, + T::AccountId: UncheckedFrom, + { + // Errors must be initialized if they are used by the pallet. + type Error = Error; + + // Events must be initialized if they are used by the pallet. + fn deposit_event() = default; + + /// Call the contract + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn call( + origin, + dest: ::Source, + value: BalanceOf, + gas: Gas, + data: Vec, + ) -> dispatch::DispatchResultWithPostInfo { + >::call( + origin, + dest, // contract address + value, // T::Currency::minimum_balance() * 100u32.into(), // value + gas, // gas_limit + data // fn + ) + } + + // bls12_377 + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_377_add(origin) { + curve::tests::add(0x2a); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_377_mul(origin) { + curve::tests::mul(0x2a); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_377_pairing_two(origin) { + curve::tests::pairing(0x2a); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_377_pairing_six(origin) { + curve::tests::pairing_six(0x2a); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_377_verify(origin) { + curve::tests::verify(0x2a); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_377_add(origin) { + jupiter_io::pairing::bls12_377_add(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_377_mul(origin) { + jupiter_io::pairing::bls12_377_mul(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_377_pairing_two(origin) { + jupiter_io::pairing::bls12_377_pairing_two(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_377_pairing_six(origin) { + jupiter_io::pairing::bls12_377_pairing_six(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_377_verify(origin) { + jupiter_io::pairing::bls12_377_verify(); + } + + // bls12_381 + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_381_add(origin) { + curve::tests::add(0x2b); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_381_mul(origin) { + curve::tests::mul(0x2b); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_381_pairing_two(origin) { + curve::tests::pairing(0x2b); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_381_pairing_six(origin) { + curve::tests::pairing_six(0x2b); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bls12_381_verify(origin) { + curve::tests::verify(0x2b); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_381_add(origin) { + jupiter_io::pairing::bls12_381_add(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_381_mul(origin) { + jupiter_io::pairing::bls12_381_mul(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_381_pairing_two(origin) { + jupiter_io::pairing::bls12_381_pairing_two(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_381_pairing_six(origin) { + jupiter_io::pairing::bls12_381_pairing_six(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bls12_381_verify(origin) { + jupiter_io::pairing::bls12_381_verify(); + } + + // bn254 + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bn254_add(origin) { + curve::tests::add(0x2c); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bn254_mul(origin) { + curve::tests::mul(0x2c); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bn254_pairing_two(origin) { + curve::tests::pairing(0x2c); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bn254_pairing_six(origin) { + curve::tests::pairing_six(0x2c); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bn254_verify(origin) { + curve::tests::verify(0x2c); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bn254_add(origin) { + jupiter_io::pairing::bn254_add(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bn254_mul(origin) { + jupiter_io::pairing::bn254_mul(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bn254_pairing_two(origin) { + jupiter_io::pairing::bn254_pairing_two(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bn254_pairing_six(origin) { + jupiter_io::pairing::bn254_pairing_six(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bn254_verify(origin) { + jupiter_io::pairing::bn254_verify(); + } + + // bw6_781 + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bw6_761_add(origin) { + curve::tests::add(0x2d); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bw6_761_mul(origin) { + curve::tests::mul(0x2d); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bw6_761_pairing_two(origin) { + curve::tests::pairing(0x2d); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bw6_761_pairing_six(origin) { + curve::tests::pairing_six(0x2d); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn wasm_bw6_761_verify(origin) { + curve::tests::verify(0x2d); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bw6_761_add(origin) { + jupiter_io::pairing::bw6_761_add(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bw6_761_mul(origin) { + jupiter_io::pairing::bw6_761_mul(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bw6_761_pairing_two(origin) { + jupiter_io::pairing::bw6_761_pairing_two(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bw6_761_pairing_six(origin) { + jupiter_io::pairing::bw6_761_pairing_six(); + } + + #[weight = 10_000 + T::DbWeight::get().writes(1)] + pub fn native_bw6_761_verify(origin) { + jupiter_io::pairing::bw6_761_verify(); + } + } +} diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs new file mode 100644 index 00000000..621093d2 --- /dev/null +++ b/pallets/template/src/mock.rs @@ -0,0 +1,190 @@ +use crate::Config; +use frame_support::{ + impl_outer_event, impl_outer_origin, parameter_types, traits::Currency, weights::Weight, +}; +use frame_system as system; +use sp_runtime::{ + testing::{Header, H256}, + traits::{BlakeTwo256, Convert, Hash, IdentityLookup}, + AccountId32, Perbill, +}; + +impl_outer_origin! { + pub enum Origin for Test {} +} + +// Configure a mock runtime to test the pallet. + +#[derive(Clone, Eq, PartialEq, Debug)] +pub struct Test; + +impl Convert> for Test { + fn convert(w: Weight) -> contract::BalanceOf { + w as u128 + } +} + +parameter_types! { + pub const BlockHashCount: u64 = 250; + pub const MaximumBlockWeight: Weight = 1024; + pub const MaximumBlockLength: u32 = 2 * 1024; + pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); +} + +impl system::Config for Test { + type BaseCallFilter = (); + type Origin = Origin; + type Call = (); + type Index = u64; + type BlockNumber = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId32; + type Lookup = IdentityLookup; + type Header = Header; + type Event = (); + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = (); + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type BlockWeights = (); + type BlockLength = (); +} + +parameter_types! { + pub const MinimumPeriod: u64 = 1; + pub static ExistentialDeposit: u128 = 0; +} + +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +impl_outer_event! { + pub enum MetaEvent for Test { + frame_system, + pallet_balances, + contract, + } +} + +impl Config for Test { + type Event = (); +} + +type System = system::Module; + +impl pallet_balances::Config for Test { + type MaxLocks = (); + type Balance = u128; + type Event = (); + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); +} + +pub type Balances = pallet_balances::Module; +type Timestamp = pallet_timestamp::Module; +type Randomness = pallet_randomness_collective_flip::Module; + +parameter_types! { + pub const SignedClaimHandicap: u64 = 2; + pub const TombstoneDeposit: u128 = 16; + pub const StorageSizeOffset: u32 = 8; + pub const RentByteFee: u128 = 4; + pub const RentDepositOffset: u128 = 10_000; + pub const SurchargeReward: u128 = 150; + pub const MaxDepth: u32 = 100; + pub const MaxValueSize: u32 = 16_384; +} + +impl contract::Config for Test { + type Time = Timestamp; + type Randomness = Randomness; + type Currency = Balances; + type Event = (); + type RentPayment = (); + type SignedClaimHandicap = SignedClaimHandicap; + type TombstoneDeposit = TombstoneDeposit; + type StorageSizeOffset = StorageSizeOffset; + type RentByteFee = RentByteFee; + type RentDepositOffset = RentDepositOffset; + type SurchargeReward = SurchargeReward; + type MaxDepth = MaxDepth; + type MaxValueSize = MaxValueSize; + type WeightPrice = Self; + type WeightInfo = (); + type ChainExtension = jupiter_chain_extension::JupiterExt; +} + +pub type Contracts = contract::Module; + +pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]); + +pub struct ExtBuilder { + existential_deposit: u128, +} +impl Default for ExtBuilder { + fn default() -> Self { + Self { + existential_deposit: 1, + } + } +} + +impl ExtBuilder { + pub fn set_associated_consts(&self) { + EXISTENTIAL_DEPOSIT.with(|v| *v.borrow_mut() = self.existential_deposit); + } + + pub fn existential_deposit(mut self, existential_deposit: u128) -> Self { + self.existential_deposit = existential_deposit; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + self.set_associated_consts(); + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + pallet_balances::GenesisConfig:: { balances: vec![] } + .assimilate_storage(&mut t) + .unwrap(); + + let mut current_schedule = contract::Schedule::::default(); + current_schedule.enable_println = true; + contract::GenesisConfig:: { current_schedule } + .assimilate_storage(&mut t) + .unwrap(); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} + +/// Compile groth16 with test data +pub fn groth16_addr(caller: AccountId32) -> AccountId32 { + let module = include_bytes!("../res/groth16.wasm").to_vec(); + let hash = ::Hashing::hash(&module); + let _ = crate::mock::Balances::deposit_creating(&caller, 100_000_000_000_000); + Contracts::put_code(Origin::signed(caller.clone()), module).unwrap(); + Contracts::instantiate( + Origin::signed(ALICE.clone()), + 1_000_000, // endowment + Weight::max_value(), // gas_limit + hash.clone(), // code_hash + [106, 55, 18, 226].to_vec(), // flip + b"".to_vec(), // salt + ) + .unwrap(); + let addr = Contracts::contract_address(&caller, &hash, &b"".to_vec()); + addr +} diff --git a/pallets/template/src/tests.rs b/pallets/template/src/tests.rs new file mode 100644 index 00000000..10be8271 --- /dev/null +++ b/pallets/template/src/tests.rs @@ -0,0 +1,138 @@ +#![cfg(test)] +use crate::{mock::*, Module}; +use frame_support::{assert_ok, weights::Weight}; + +#[test] +fn test_verify_bls12_377() { + ExtBuilder::default() + .existential_deposit(50) + .build() + .execute_with(|| { + let addr = groth16_addr(ALICE); + assert_ok!(>::call( + Origin::signed(ALICE), + addr.clone(), + 0, + Weight::max_value(), + hex::decode("4e1f2d8108850171c5a779bb19e0aeb6030768f5001017bbd4edb645306ff1591424c501e7aa8b480fc18d8ed404c893d473afa9b82c01fb3e19bdf85f4fb8acf97d1507b75eb48972c8a10e13f4637f7bee71f89eafc141453e4646c82e188d9ef8cf71fa2f000085014d0869345487bb4070110fa318b0f408dcffce12304589878797615d8a72cc00b6a1e3f50cc0e59770638640090726013db560d3a19288ecedc60ed9ee0afd50ad3ac96db89d99fc249b85a453ef837e9213f8977ac572d818dc43387678a50100910a54f796d78550d14c4ee03cd5915fd8037569696f878312b0093f0149919fc717c0b3f8a2d419fad0edde7e1d55cd2f002c312b660250225a00baf5df511dcce61eb23b28f3980be7fcde0091284670e9064015f452f244e65cad047a20fdd000ca76892d04e1283e575e098c8e4281ba9113443515f22247921b9c3189dc03dd83cf22b9da3eda70cdd2644a795376002e0b1d0d1d5945dab12a28a31497b48d07739028ac3153be3cf367e3d7e788ac43f6d3ccd3c5c20a4f2d6b0db05ce40000f70cb4191a256ed9a4d90305f5864993032a0e40433040c259b14c8069d117f3491d75d993271a0a3f13efdd5b18ce006d90eff3b45f8fa10b43a2d4fb80a554304ba5d94ddc19c92b2e1e2f756bd3042c4c0d6e10b6c22c2ea5eb136fb42900aca080ed5cfa9ccf92da7e4f631f1f9fd52a4dd227898e21585a7a55656f6315fa3f1e541011b941084fb663515ede0024ff6c7745872af24c5de2acfbf4b7a238f3f80face2310d83d9e953de2051a70abc3be988220291e03c92840e1c1c01005720823639fe8f3818ade6c24c6d6ed8f78b87369a9fac8a548e01ca001e424ba931033958641fe06677c3f4a1b39f01f6d3e9a2052ad1185af9a80086665df50b41674f7f6f181773cee6e78d09ea34ce970ccb5907d5cb2f69c9e0ed8d1f01009d629094c47bdf026bbd3424f6e7748b0c3529b495cf24677f309d9f1ed7d3435513224cba204902fd733522b3b855015f395e5b2a7f0fe9e50665d705c48f9b8b20a3f9619f50c1dcddbea7c4a561cdffed750045f875b2d2c569e8d5d0320015e739c8881a211865f82e39bb6ad21a66ceb1808a5ecc3f11833d61dc938a3b160b1b1829527b52e9d3d98800f29701078dfc5fda2f3dcebaca0f43ac23f6da5044f51cf12ac8b3439df503ab1732f5047601b2cd9d93e6d161dc4719beda00000d06e2342d048b06618cfc80a5fb5301373032d5780ca45e5287e824fd1d3dccfc36d1befe73edaea7378968a003f94e1801de729f41f406c7d94db4995cc2956cdd6b250937dd52b3c8ac812dff25985eb802c727dbfb7c6b055db545d687b1bd000090f4ad7dc16060ebfbe2bff08077e404e878850682e15f64a5b0f243f53a6d61dc358d41fa6aed615c6296904d71c200c04fe75b3adbecdc3d00df22556a1c949e4b87c81483225f6eaa7560e3035a1c919c4a0d446125dca2e2ef541d58a200ec9b0644bea1bd34e84ff04b65c0cc8733d425b43225f81a7580e1027a41b4ce85eb513213f54a76e2b69320dc6d51003b06cb148aa149b0b0e1ffb8f5901adbda3e431c19404cae29f26aac97085c6d1d8eeef33024aafdc649da6475ab99000026b3bb740a34b4db3a1c689d471b5a7834bb27fd57108bca8cd88d12bb81eae5f8ad807e5de758978ab51d0146017100c31d5c7971576e79eec56286dc2602025cb1d0a01e1acdc23a8aece6e9f3c3ecf97d0a9667634e31e79f653a93c13b01000480a4961fec1c734055a80af91b3fd7405a2cdb741e1867aa7f783ca0959a077110").expect("Decode failed"))); + }); +} + +#[test] +fn test_verify_bls12_381() { + ExtBuilder::default() + .existential_deposit(50) + .build() + .execute_with(|| { + let addr = groth16_addr(ALICE); + assert_ok!(>::call( + Origin::signed(ALICE), + addr.clone(), + 0, + Weight::max_value(), + hex::decode("99a06637088501e60f6032ed7f170ba3481c5d99c0890554c808ad380a7c9aefc9e62eeecf0363ecef5e59ba8eaf6dd0af40e08d7cfd024314f90080a1461a207aa3098308149837bc6322a8f4b499671c507203e798f90a9aa8fafaebb806c8708c3207a93316008501ea7f398187aecf2721441218e54645b17acd35bdf65886255e772a58353ef2e25c92cf7f872bea5afca6081d03e6b115e74befd85720c241ee5ef038621a1cc72e329db9aebec0faf480e83cbd9e4b735650ab0cce2e321d64311bd34bca9e0200910a9094c864d37f890720969430f2682ccc76dc83f9234694590bd334b40dbfa7f28de40e914571d8ae2a88712844f86f0d6dd2f4875120f66304bfcedd55c9a805310155a5345ddc626cbb6fe5ce7026be174a08c798e4d1f1010f97138c30b10a0e23d3cde62852c7b2aabcd7603f87fc54cb0c2fcfa48a1a6e07ea917eec248284a1409dd21ae7bd64b862e7df91fd0af1f36857260a843ea18cd393172b91196ca17bc5f37efb126d585abfcf23b8438d72f90365c382b661256d7caa361d07000c06c5cc02155140b97283cc024daf57023a781a9115bb6e17350264f8b52784a6008921402af8c05dd39f4b789bd50435d2c5aefeb6dc9817af41f45779e3a2d80ab98ef923723b938566747c10a4a169ca5097c5d5073449c3d2e65e16291850a5721416e102df69729ffab67cf948ca51c4ac4c2b54c521552fd4a5a5462d6d3b77ba9932aba0fda8ea8da76e5b0b9166ba600f9c5cc5e442b64ed560c126f8b88e2761c0c6a17a4dcbc1a132a975683ed0b6018ac45d7f4942ad7831790e00408697568bc15871da494a2fe12199531130a8a5b96f07c69020dc01bf9f3ed043a6e1bd08f8d7826c7d5c0fc5c771195ab91bf6eeaa33cbd89cd7dce7930b383c2453d0cca5c227e1b97b1ae253e40cadf4468d6d86f0bf69a0b0bb55774219005b6d86316ea7c1dc4df3e3396a9f78aadf416d5af1619883f5dbbf0a39c6743b194e5adedda54d7cb3ae33e556602e19dd43a31bca7bdb15ad5245dc1ad0affb97edc8f35bb00d1c5b417a132d5be9b72a39870193b6a142198a888c0fe3760fdf1467c7208394270f2aff044c5c002d6cf189a28e34851dc434933e73e07482dad6c7ab931bfbdf29f5d51a6a866d028b91cd89abc9728cf2f8e139f612b5a248ca0758365d1d83c6bc299152b15a89b136e804ae71174d4f35970be570fd14000d06fcafa9753aee681f006d7bf6fc885dcc1a70c33bbfe92bb581ac51e1325b782b1128b1586767cb2ea27555e243abd213634b87418421a65002e06fd9347b23205761d7e35a2a83ffcd35b16b6bf23982700597f2ed9706ae5e039542e8eabd1800443cc8d6ffec17c44207dd41e8ab2f2f2c663f5ed9ab724321de43cbe2ea81908c13643c42a41be1adbc5076e4927b13046d3cdaf5ef775ee48d842599508178276cd41d30e289cbd1d2bb9f92f59b520138fef3e9529139f3961f40f6ea92113ed1701b0eb62a8b21b0852f5ae0d23b4d8cf7a02a69b04abbf0b9213cc1cd16b0afed74a09f1d965f72e0faaad60215c2788b9672a8f53fb90d44b47fb16e4f97f910226d8ad46ddc1dfa6eb4f709a3c95ccfa7f4cd1b9ea5f3cf3d10c5dd0200de094abc5e25fac259efcfd79a97401359069cde3b48eaa9d3a4d848959eb269d788a415d9c22fb418459474f1f0fc16f4572ace2876cf1170d400d1d12d588f816023602a077b8fa66293ac19c951b6c572fad4481fa576e362d9f3a0ffa0120004801d6c7850edbac8a5281ab93d2ed245d47b64f20c21950926d595624b488c291c").expect("Decode failed"))); + }); +} + +#[test] +fn test_verify_bn254() { + ExtBuilder::default() + .existential_deposit(50) + .build() + .execute_with(|| { + let addr = groth16_addr(ALICE); + assert_ok!(>::call( + Origin::signed(ALICE), + addr.clone(), + 0, + Weight::max_value(), + hex::decode("e028249708050103c2e806d904d8789f0caf1276fc4897bbf2bbb2e7243df2e4bf941ce616790479b410872e3c6f73f481d3e37b861fc1521d4a70457ac41efbe874fe0bf6572f0005014d609323ed564943ba7dfd3b362cc85abf7691dd9957c613fc0d282f258f4d17cd4ddfa713c0a6d4d0dcbfc245847bd6a96fa8603a0c0d55389279cdf2967f06001107f00c5d68983d7c029a66ae498a1cc6a2423bf67760bbf922ea7a937a87705e158db79bbff4eb9516d5342ce8cd8d09f68fa094434edceebbb43383fc415d9b235c64a2bc82ea6fa740441af956bc764eefb6be4067948d2d7afc08d7dc114a2e1c0c46208e6590bed192c336b7d89f55c2eca918e6f4eb88e1c729a10612690900f70bfb6ec84456af219bcd1d682133db3db80b0ae54cf31879e74a0ae547ec0ef92f56757f4a7976c50dc3d538cb1b4ed1736d4e8e8734d5cbf85b2ac8a93d0b654ff74df7e792b9cf0fd9d1b07b6ce4d0675f57bc7e9740e64b56c9f866b309eb428ffdf69b419fc53b9d76f1de62559aedc6db7e8b6ac2f3dd0cc963ca041300cc165291944a7b617bad2e6f1560f89f4e7eb42f154333b730e2f2da7828911d7cd0a28314d647bae049c72d4e0b4f31c1f09177fcab13014e3060a70024cb210094b31d9ebcca3957fff3d94960b0eba2197fabaaa68776e767e8785f63b4541d456d755240d72dae2ee0452c0cd705d7312b9a1d17cff916e87c763d459a550438b765cd8877bf753869e1852a7c0d9ac4520abb2b935e2f3ec12423d9edc5289eba05bed12e9fe16017c86791d682d4ae86d94eeab1d7888845c0fb0af85805000d04cf3bb657065cd0878eabc53790c5fa3680cad24db586bab799e3ae790217c61ba5050a0024f8761028a11dd22dfc030227b0a6c353ef5e7e1afad863c13a3304000227ad22191396e6ffe7aff14de91d7801e943f836de399b5fd5c8312086440c036648b695ffa27790f2f2a63fcf4c0b130e6b88ac786e3351fc6f13452d18034bee420c244cf7c63db4761f2feb7c14e409c8c550a68940cc0387e3812ccb10c4eb591ff3a67a87e794e2e76e25126b823ea9f38f95730951f13784e6e10f26007a922013b86567d6d48ff65baf8cdd0558c52db98f27b6c216df96f8aa1d4d2df7b1ead51d93e93ef5abdff83acaabd54736546f6995083127be1ae281ca5200000480829d3d572251103bac02b39e397c657c0b1f372bfc4d1b74f6c23de4993b4824").expect("Decode failed"))); + }); +} + +#[test] +fn test_verify_bw6_761() { + ExtBuilder::default() + .existential_deposit(50) + .build() + .execute_with(|| { + let addr = groth16_addr(ALICE); + assert_ok!(>::call( + Origin::signed(ALICE), + addr.clone(), + 0, + Weight::max_value(), + hex::decode("4399fe0608050329f6308fb1faee384c2deae7744b65d79eafa98a3947df7e35330c73ad0165a2f92844dab884fec1e15e52ac08f9306a1d8e7b4b66f718cece36a90f9aafe59588aafcd6588a55b9c05c3177904e5cbd1e3b59e4077d1caff6329268b5882200e349c8213aacabd50f11abe7f59b68fdd37f17b7fe6cee7ec3d04dca42812df1854c6c14234dd6fb7f64220949439c660ede18a5e79c8a115b942bbb7812b89be516469237a138752f6f798bcaf6afdf261e471f6c808aacd4274293cb8aff00000503639a14c4e08b97d97166d09eff9b57abf973b487fd5f5007c6ccc8adc31dbac74372477c035964e06f06d93e1483fe81ef1b51e525ffad28a053af20271dd363353e7ccd34cd599ac7c8c97fc175e4d9db8b9399db1647f52564757781209b001cc3d1e9665bc2a8b7e82d2d074e595f297df3dff536046353057a150f6a453521182a7219ef5d38ae85efd3b505f16549ed4bd63b7166e3a4f82142f584b3ad3e27c371db05cc0ba8a8f870fefccd9eb6e5635d6684193aa4b60082a0b2ac0000110c73174e4bb9c9b03c5ee9ddf21056832e01546744fffc64a5221e7e5cee09d37e534b27ae3725db7d3706c85b3932b269078f55cf1dd54c6e3247ad9a7619ef71315f5fee37909c44a216246c2ba2889b7b00b7f1298f5fb2776562527f4014008864e0733bfdd0d8f599c8bccd50d2204e3dab1863fc52e8a30476c836c16e3e6f7d098f0b34fd9edde526f9039323dcb0228a5e7c6841dcda703efe88d7331ba7d096b5753f442647e643d8ac9dfdd9d85b44824bbcc29ee8b4596e1cee520000d1e9ebd9d4d430b34703ac55be08c6d63e791dd2da3f7543b5d6db64e6ce9e0cfb031c168e2bede9cbd39070ecb4e1678d41cd0d48b087fa8a324964fded508df2ef48a7a6c21f1fe95e89aa98b00fb59bee1713e4ffaba216f00e5f15d12201f23da7e61729bc8866bcdd39bcd7d74e6cc9f9192b94c45c6753b60cef11c3b0474eaa53b3beaf3ee9f3885a547ae21385b5a5d5f15be620b9f2669573461b56e74dd326b48662cd271d1a21bb0c120f45d6bbdc632261908bc6e3ab4356480000be5dddc202ba74caa75135e9f81338910969729484a89a438090564689177b491e67f8cfa06ecfcee4acfd7cd364e094c1a4d028f7c7e0677d066cdf1355123e976fa498af59e308954054051fb3fabdda4b0d7a165cd454a71c53ff26546d000b193a142d557066f0a66964c249e4ee2d0247969ecfe861014dd4f36956da4c870ff3fbd6e16999cd43dc27c2fb2a5d72c7317dbc22d2f32541c1489a7bf716e698f898299c0ddfd09e3a892d2aa2940eec0b9f0cf63e52d83cd5dba7be50000021a8ba5d55fabd1999a5a9d717008e812486fd4309d9b4fb75ce4d22199360d6f8855d2e55259220392a9a67b9104adfa1424633f0c527b5516535d43c2632e594a118c05394ea735234b998018ac2906d7f24f89226bb07d1229c6000b13900b565ae54006fc9ef616aa866efa0e85b4c8d5a13ee55d60a478a0ea0b0cc29bc1fcab4045b6f980297a1815dcfbf5ad3031a0bb4429ad863f8695719b68208d1cd4e515a2b3129142a4bbdca3c3cde033c6256daa1fb79f133f28147a40c5200000d09cf5ea12a32dc313ec0791efdfca4ffa5dca127faeb57027754f0fcdd0e868623082e4543cae1bb11078c359dabbd4abbb38640c75081dca4aa2ef35bdb5ee4c856465c7b75956b88ab36d940a8df7e13adaa709ee349ed9454c7d6705211020087f361ca8cb2e83018809872a71853f0eb99a989362a3a753edbe4f58feec45c19be03b06567b357ec6779f3756b1494b74d98503d5c67ef3548ca9464d7525a3f92cdf335702a76eaaff83330f9da2c4a84b02a99ce06e0b04a1a0f1fd2f80000335b53718581ba3e14b48e381078551ff535a3d7a1671dc42898e742857f158a27d249a4d3bbe060016acdf3e9bde0095b23e073e40d56027474673321542ab30641f50f61452762d66984e33745d9456c5eba2cdafc07a52525ef1d3e221e00c92be8c3030de0338c27d281e887a63ab927478464faa7e7b0bbc68de44734c20cfd24763b8384fc6a15b2f82bf0349b86392aaa2e6fc2c95c1d0891f83a92d3b2c1deb230316eb43d9ddcbd069e600aff23ef13dd1f7b9cfade33db4872300000d1367d1907cd90da19e25e3241fb83393731c0d6183300675275017cc6287f2154abf2320cdc2cefc9df0383f98688e2e22914bef4fc32136222fb9dde45840de012e91cce1d02fbb6250a342b72c8c4155e0ff2ffa7ee71211f2641e816f200f8e725a65be98dafc395c538b2c1a009af190aedb99ecae9410257b5b295fb757dc7af138db54d06c582021442342f8924e092ae2fbf375fe94d6480910f7154b14aec033bd5cf27a2cdd225282b7a2fcaab6ac338a89d994c45976d9b7fa1000004c028933fc1b649ded455bd7739026be2bf6f7e1c0acde6dee164724218bbf1391e318017e5a6ab8248bda0bdd1f40b8301").expect("Decode failed"))); + }); +} + +#[test] +fn test_bls12_377_verify() { + let vk_ic:Vec = hex::decode("71c5a779bb19e0aeb6030768f5001017bbd4edb645306ff1591424c501e7aa8b480fc18d8ed404c893d473afa9b82c01fb3e19bdf85f4fb8acf97d1507b75eb48972c8a10e13f4637f7bee71f89eafc141453e4646c82e188d9ef8cf71fa2f0000").unwrap(); + let vk_ic2:Vec = hex::decode("4d0869345487bb4070110fa318b0f408dcffce12304589878797615d8a72cc00b6a1e3f50cc0e59770638640090726013db560d3a19288ecedc60ed9ee0afd50ad3ac96db89d99fc249b85a453ef837e9213f8977ac572d818dc43387678a50100").unwrap(); + let vk_encode:Vec = hex::decode("54f796d78550d14c4ee03cd5915fd8037569696f878312b0093f0149919fc717c0b3f8a2d419fad0edde7e1d55cd2f002c312b660250225a00baf5df511dcce61eb23b28f3980be7fcde0091284670e9064015f452f244e65cad047a20fdd000ca76892d04e1283e575e098c8e4281ba9113443515f22247921b9c3189dc03dd83cf22b9da3eda70cdd2644a795376002e0b1d0d1d5945dab12a28a31497b48d07739028ac3153be3cf367e3d7e788ac43f6d3ccd3c5c20a4f2d6b0db05ce40000f70cb4191a256ed9a4d90305f5864993032a0e40433040c259b14c8069d117f3491d75d993271a0a3f13efdd5b18ce006d90eff3b45f8fa10b43a2d4fb80a554304ba5d94ddc19c92b2e1e2f756bd3042c4c0d6e10b6c22c2ea5eb136fb42900aca080ed5cfa9ccf92da7e4f631f1f9fd52a4dd227898e21585a7a55656f6315fa3f1e541011b941084fb663515ede0024ff6c7745872af24c5de2acfbf4b7a238f3f80face2310d83d9e953de2051a70abc3be988220291e03c92840e1c1c01005720823639fe8f3818ade6c24c6d6ed8f78b87369a9fac8a548e01ca001e424ba931033958641fe06677c3f4a1b39f01f6d3e9a2052ad1185af9a80086665df50b41674f7f6f181773cee6e78d09ea34ce970ccb5907d5cb2f69c9e0ed8d1f01009d629094c47bdf026bbd3424f6e7748b0c3529b495cf24677f309d9f1ed7d3435513224cba204902fd733522b3b855015f395e5b2a7f0fe9e50665d705c48f9b8b20a3f9619f50c1dcddbea7c4a561cdffed750045f875b2d2c569e8d5d0320015e739c8881a211865f82e39bb6ad21a66ceb1808a5ecc3f11833d61dc938a3b160b1b1829527b52e9d3d98800f29701078dfc5fda2f3dcebaca0f43ac23f6da5044f51cf12ac8b3439df503ab1732f5047601b2cd9d93e6d161dc4719beda0000").unwrap(); + let proof_encode:Vec = hex::decode("e2342d048b06618cfc80a5fb5301373032d5780ca45e5287e824fd1d3dccfc36d1befe73edaea7378968a003f94e1801de729f41f406c7d94db4995cc2956cdd6b250937dd52b3c8ac812dff25985eb802c727dbfb7c6b055db545d687b1bd000090f4ad7dc16060ebfbe2bff08077e404e878850682e15f64a5b0f243f53a6d61dc358d41fa6aed615c6296904d71c200c04fe75b3adbecdc3d00df22556a1c949e4b87c81483225f6eaa7560e3035a1c919c4a0d446125dca2e2ef541d58a200ec9b0644bea1bd34e84ff04b65c0cc8733d425b43225f81a7580e1027a41b4ce85eb513213f54a76e2b69320dc6d51003b06cb148aa149b0b0e1ffb8f5901adbda3e431c19404cae29f26aac97085c6d1d8eeef33024aafdc649da6475ab99000026b3bb740a34b4db3a1c689d471b5a7834bb27fd57108bca8cd88d12bb81eae5f8ad807e5de758978ab51d0146017100c31d5c7971576e79eec56286dc2602025cb1d0a01e1acdc23a8aece6e9f3c3ecf97d0a9667634e31e79f653a93c13b0100").unwrap(); + let public_input: Vec = + hex::decode("a4961fec1c734055a80af91b3fd7405a2cdb741e1867aa7f783ca0959a077110").unwrap(); + + assert_ok!(curve::verify( + 0x00, + vec![vk_ic, vk_ic2], + vk_encode, + proof_encode, + vec![public_input] + )); +} + +#[test] +fn test_based_bls12_381_mimc_groth16() { + let vk_ic:Vec = hex::decode("e60f6032ed7f170ba3481c5d99c0890554c808ad380a7c9aefc9e62eeecf0363ecef5e59ba8eaf6dd0af40e08d7cfd024314f90080a1461a207aa3098308149837bc6322a8f4b499671c507203e798f90a9aa8fafaebb806c8708c3207a9331600").unwrap(); + let vk_ic2:Vec = hex::decode("ea7f398187aecf2721441218e54645b17acd35bdf65886255e772a58353ef2e25c92cf7f872bea5afca6081d03e6b115e74befd85720c241ee5ef038621a1cc72e329db9aebec0faf480e83cbd9e4b735650ab0cce2e321d64311bd34bca9e0200").unwrap(); + let vk_encode:Vec = hex::decode("9094c864d37f890720969430f2682ccc76dc83f9234694590bd334b40dbfa7f28de40e914571d8ae2a88712844f86f0d6dd2f4875120f66304bfcedd55c9a805310155a5345ddc626cbb6fe5ce7026be174a08c798e4d1f1010f97138c30b10a0e23d3cde62852c7b2aabcd7603f87fc54cb0c2fcfa48a1a6e07ea917eec248284a1409dd21ae7bd64b862e7df91fd0af1f36857260a843ea18cd393172b91196ca17bc5f37efb126d585abfcf23b8438d72f90365c382b661256d7caa361d07000c06c5cc02155140b97283cc024daf57023a781a9115bb6e17350264f8b52784a6008921402af8c05dd39f4b789bd50435d2c5aefeb6dc9817af41f45779e3a2d80ab98ef923723b938566747c10a4a169ca5097c5d5073449c3d2e65e16291850a5721416e102df69729ffab67cf948ca51c4ac4c2b54c521552fd4a5a5462d6d3b77ba9932aba0fda8ea8da76e5b0b9166ba600f9c5cc5e442b64ed560c126f8b88e2761c0c6a17a4dcbc1a132a975683ed0b6018ac45d7f4942ad7831790e00408697568bc15871da494a2fe12199531130a8a5b96f07c69020dc01bf9f3ed043a6e1bd08f8d7826c7d5c0fc5c771195ab91bf6eeaa33cbd89cd7dce7930b383c2453d0cca5c227e1b97b1ae253e40cadf4468d6d86f0bf69a0b0bb55774219005b6d86316ea7c1dc4df3e3396a9f78aadf416d5af1619883f5dbbf0a39c6743b194e5adedda54d7cb3ae33e556602e19dd43a31bca7bdb15ad5245dc1ad0affb97edc8f35bb00d1c5b417a132d5be9b72a39870193b6a142198a888c0fe3760fdf1467c7208394270f2aff044c5c002d6cf189a28e34851dc434933e73e07482dad6c7ab931bfbdf29f5d51a6a866d028b91cd89abc9728cf2f8e139f612b5a248ca0758365d1d83c6bc299152b15a89b136e804ae71174d4f35970be570fd1400").unwrap(); + let proof_encode:Vec = hex::decode("fcafa9753aee681f006d7bf6fc885dcc1a70c33bbfe92bb581ac51e1325b782b1128b1586767cb2ea27555e243abd213634b87418421a65002e06fd9347b23205761d7e35a2a83ffcd35b16b6bf23982700597f2ed9706ae5e039542e8eabd1800443cc8d6ffec17c44207dd41e8ab2f2f2c663f5ed9ab724321de43cbe2ea81908c13643c42a41be1adbc5076e4927b13046d3cdaf5ef775ee48d842599508178276cd41d30e289cbd1d2bb9f92f59b520138fef3e9529139f3961f40f6ea92113ed1701b0eb62a8b21b0852f5ae0d23b4d8cf7a02a69b04abbf0b9213cc1cd16b0afed74a09f1d965f72e0faaad60215c2788b9672a8f53fb90d44b47fb16e4f97f910226d8ad46ddc1dfa6eb4f709a3c95ccfa7f4cd1b9ea5f3cf3d10c5dd0200de094abc5e25fac259efcfd79a97401359069cde3b48eaa9d3a4d848959eb269d788a415d9c22fb418459474f1f0fc16f4572ace2876cf1170d400d1d12d588f816023602a077b8fa66293ac19c951b6c572fad4481fa576e362d9f3a0ffa01200").unwrap(); + let public_input: Vec = + hex::decode("1d6c7850edbac8a5281ab93d2ed245d47b64f20c21950926d595624b488c291c").unwrap(); + + assert_ok!(curve::verify( + 0x10, + vec![vk_ic, vk_ic2], + vk_encode, + proof_encode, + vec![public_input] + )); +} + +#[test] +fn test_based_bn254_mimc_groth16() { + let vk_ic:Vec = hex::decode("03c2e806d904d8789f0caf1276fc4897bbf2bbb2e7243df2e4bf941ce616790479b410872e3c6f73f481d3e37b861fc1521d4a70457ac41efbe874fe0bf6572f00").unwrap(); + let vk_ic2:Vec = hex::decode("4d609323ed564943ba7dfd3b362cc85abf7691dd9957c613fc0d282f258f4d17cd4ddfa713c0a6d4d0dcbfc245847bd6a96fa8603a0c0d55389279cdf2967f0600").unwrap(); + let vk_encode:Vec = hex::decode("f00c5d68983d7c029a66ae498a1cc6a2423bf67760bbf922ea7a937a87705e158db79bbff4eb9516d5342ce8cd8d09f68fa094434edceebbb43383fc415d9b235c64a2bc82ea6fa740441af956bc764eefb6be4067948d2d7afc08d7dc114a2e1c0c46208e6590bed192c336b7d89f55c2eca918e6f4eb88e1c729a10612690900f70bfb6ec84456af219bcd1d682133db3db80b0ae54cf31879e74a0ae547ec0ef92f56757f4a7976c50dc3d538cb1b4ed1736d4e8e8734d5cbf85b2ac8a93d0b654ff74df7e792b9cf0fd9d1b07b6ce4d0675f57bc7e9740e64b56c9f866b309eb428ffdf69b419fc53b9d76f1de62559aedc6db7e8b6ac2f3dd0cc963ca041300cc165291944a7b617bad2e6f1560f89f4e7eb42f154333b730e2f2da7828911d7cd0a28314d647bae049c72d4e0b4f31c1f09177fcab13014e3060a70024cb210094b31d9ebcca3957fff3d94960b0eba2197fabaaa68776e767e8785f63b4541d456d755240d72dae2ee0452c0cd705d7312b9a1d17cff916e87c763d459a550438b765cd8877bf753869e1852a7c0d9ac4520abb2b935e2f3ec12423d9edc5289eba05bed12e9fe16017c86791d682d4ae86d94eeab1d7888845c0fb0af8580500").unwrap(); + let proof_encode:Vec = hex::decode("cf3bb657065cd0878eabc53790c5fa3680cad24db586bab799e3ae790217c61ba5050a0024f8761028a11dd22dfc030227b0a6c353ef5e7e1afad863c13a3304000227ad22191396e6ffe7aff14de91d7801e943f836de399b5fd5c8312086440c036648b695ffa27790f2f2a63fcf4c0b130e6b88ac786e3351fc6f13452d18034bee420c244cf7c63db4761f2feb7c14e409c8c550a68940cc0387e3812ccb10c4eb591ff3a67a87e794e2e76e25126b823ea9f38f95730951f13784e6e10f26007a922013b86567d6d48ff65baf8cdd0558c52db98f27b6c216df96f8aa1d4d2df7b1ead51d93e93ef5abdff83acaabd54736546f6995083127be1ae281ca520000").unwrap(); + let public_input: Vec = + hex::decode("829d3d572251103bac02b39e397c657c0b1f372bfc4d1b74f6c23de4993b4824").unwrap(); + + assert_ok!(curve::verify( + 0x20, + vec![vk_ic, vk_ic2], + vk_encode, + proof_encode, + vec![public_input] + )); +} + +#[test] +fn test_based_bw6_761_mimc_groth16() { + let vk_ic:Vec = hex::decode("29f6308fb1faee384c2deae7744b65d79eafa98a3947df7e35330c73ad0165a2f92844dab884fec1e15e52ac08f9306a1d8e7b4b66f718cece36a90f9aafe59588aafcd6588a55b9c05c3177904e5cbd1e3b59e4077d1caff6329268b5882200e349c8213aacabd50f11abe7f59b68fdd37f17b7fe6cee7ec3d04dca42812df1854c6c14234dd6fb7f64220949439c660ede18a5e79c8a115b942bbb7812b89be516469237a138752f6f798bcaf6afdf261e471f6c808aacd4274293cb8aff0000").unwrap(); + let vk_ic2:Vec = hex::decode("639a14c4e08b97d97166d09eff9b57abf973b487fd5f5007c6ccc8adc31dbac74372477c035964e06f06d93e1483fe81ef1b51e525ffad28a053af20271dd363353e7ccd34cd599ac7c8c97fc175e4d9db8b9399db1647f52564757781209b001cc3d1e9665bc2a8b7e82d2d074e595f297df3dff536046353057a150f6a453521182a7219ef5d38ae85efd3b505f16549ed4bd63b7166e3a4f82142f584b3ad3e27c371db05cc0ba8a8f870fefccd9eb6e5635d6684193aa4b60082a0b2ac0000").unwrap(); + let vk_encode:Vec = hex::decode("73174e4bb9c9b03c5ee9ddf21056832e01546744fffc64a5221e7e5cee09d37e534b27ae3725db7d3706c85b3932b269078f55cf1dd54c6e3247ad9a7619ef71315f5fee37909c44a216246c2ba2889b7b00b7f1298f5fb2776562527f4014008864e0733bfdd0d8f599c8bccd50d2204e3dab1863fc52e8a30476c836c16e3e6f7d098f0b34fd9edde526f9039323dcb0228a5e7c6841dcda703efe88d7331ba7d096b5753f442647e643d8ac9dfdd9d85b44824bbcc29ee8b4596e1cee520000d1e9ebd9d4d430b34703ac55be08c6d63e791dd2da3f7543b5d6db64e6ce9e0cfb031c168e2bede9cbd39070ecb4e1678d41cd0d48b087fa8a324964fded508df2ef48a7a6c21f1fe95e89aa98b00fb59bee1713e4ffaba216f00e5f15d12201f23da7e61729bc8866bcdd39bcd7d74e6cc9f9192b94c45c6753b60cef11c3b0474eaa53b3beaf3ee9f3885a547ae21385b5a5d5f15be620b9f2669573461b56e74dd326b48662cd271d1a21bb0c120f45d6bbdc632261908bc6e3ab4356480000be5dddc202ba74caa75135e9f81338910969729484a89a438090564689177b491e67f8cfa06ecfcee4acfd7cd364e094c1a4d028f7c7e0677d066cdf1355123e976fa498af59e308954054051fb3fabdda4b0d7a165cd454a71c53ff26546d000b193a142d557066f0a66964c249e4ee2d0247969ecfe861014dd4f36956da4c870ff3fbd6e16999cd43dc27c2fb2a5d72c7317dbc22d2f32541c1489a7bf716e698f898299c0ddfd09e3a892d2aa2940eec0b9f0cf63e52d83cd5dba7be50000021a8ba5d55fabd1999a5a9d717008e812486fd4309d9b4fb75ce4d22199360d6f8855d2e55259220392a9a67b9104adfa1424633f0c527b5516535d43c2632e594a118c05394ea735234b998018ac2906d7f24f89226bb07d1229c6000b13900b565ae54006fc9ef616aa866efa0e85b4c8d5a13ee55d60a478a0ea0b0cc29bc1fcab4045b6f980297a1815dcfbf5ad3031a0bb4429ad863f8695719b68208d1cd4e515a2b3129142a4bbdca3c3cde033c6256daa1fb79f133f28147a40c520000").unwrap(); + let proof_encode:Vec = hex::decode("cf5ea12a32dc313ec0791efdfca4ffa5dca127faeb57027754f0fcdd0e868623082e4543cae1bb11078c359dabbd4abbb38640c75081dca4aa2ef35bdb5ee4c856465c7b75956b88ab36d940a8df7e13adaa709ee349ed9454c7d6705211020087f361ca8cb2e83018809872a71853f0eb99a989362a3a753edbe4f58feec45c19be03b06567b357ec6779f3756b1494b74d98503d5c67ef3548ca9464d7525a3f92cdf335702a76eaaff83330f9da2c4a84b02a99ce06e0b04a1a0f1fd2f80000335b53718581ba3e14b48e381078551ff535a3d7a1671dc42898e742857f158a27d249a4d3bbe060016acdf3e9bde0095b23e073e40d56027474673321542ab30641f50f61452762d66984e33745d9456c5eba2cdafc07a52525ef1d3e221e00c92be8c3030de0338c27d281e887a63ab927478464faa7e7b0bbc68de44734c20cfd24763b8384fc6a15b2f82bf0349b86392aaa2e6fc2c95c1d0891f83a92d3b2c1deb230316eb43d9ddcbd069e600aff23ef13dd1f7b9cfade33db4872300000d1367d1907cd90da19e25e3241fb83393731c0d6183300675275017cc6287f2154abf2320cdc2cefc9df0383f98688e2e22914bef4fc32136222fb9dde45840de012e91cce1d02fbb6250a342b72c8c4155e0ff2ffa7ee71211f2641e816f200f8e725a65be98dafc395c538b2c1a009af190aedb99ecae9410257b5b295fb757dc7af138db54d06c582021442342f8924e092ae2fbf375fe94d6480910f7154b14aec033bd5cf27a2cdd225282b7a2fcaab6ac338a89d994c45976d9b7fa10000").unwrap(); + let public_input:Vec = hex::decode("28933fc1b649ded455bd7739026be2bf6f7e1c0acde6dee164724218bbf1391e318017e5a6ab8248bda0bdd1f40b8301").unwrap(); + + assert_ok!(curve::verify( + 0x30, + vec![vk_ic, vk_ic2], + vk_encode, + proof_encode, + vec![public_input] + )); +} diff --git a/primitives/chain-extension/Cargo.toml b/primitives/chain-extension/Cargo.toml new file mode 100644 index 00000000..d229270a --- /dev/null +++ b/primitives/chain-extension/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "jupiter-chain-extension" +version = "0.1.0" +authors = ["clearloop "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +jupiter-io = { path = "../io", default-features = false } +pallet-contracts = { path = "../../vendor/substrate/frame/contracts", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +parity-scale-codec = { version = "1.3.5", features = ["derive"], default-features = false } + +[dependencies.curve] +git = "https://github.com/patractlabs/megaclite.git" +package = "megaclite-arkworks" +default-features = false + +[features] +default = ["std"] +std = [ + "jupiter-io/std", + "pallet-contracts/std", + "sp-runtime/std", +] \ No newline at end of file diff --git a/primitives/chain-extension/src/lib.rs b/primitives/chain-extension/src/lib.rs new file mode 100644 index 00000000..8438b9cc --- /dev/null +++ b/primitives/chain-extension/src/lib.rs @@ -0,0 +1,40 @@ +//! Jupiter Chain Extension +#![cfg_attr(not(feature = "std"), no_std)] +use pallet_contracts::chain_extension::{ + ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, UncheckedFrom, +}; +use parity_scale_codec::Encode; +use sp_runtime::DispatchError; +use sp_std::vec::Vec; + +/// The chain Extension of Jupiter +pub struct JupiterExt; + +impl ChainExtension for JupiterExt { + fn call(func_id: u32, env: Environment) -> Result + where + ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, + { + let mut env = env.buf_in_buf_out(); + env.charge_weight(1_000_000_000_u64)?; + + // The memory of the vm stores buf in scale-codec + let input: Vec = env.read_as()?; + let raw_output: Vec = if jupiter_io::pairing::wasm() { + curve::call(func_id, &input) + .map_err(|_| DispatchError::Other("Call chain extension failed"))? + } else { + jupiter_io::pairing::call(func_id, &input) + .ok_or(DispatchError::Other("Call chain extension failed"))? + }; + + // Encode back to the memory + let output: Vec = raw_output.encode(); + env.write(&output, false, None)?; + Ok(RetVal::Converging(0)) + } + + fn enabled() -> bool { + true + } +} diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index dd9b8c95..bf85e657 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -9,11 +9,24 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false } -megaclite = { git = "https://github.com/patractlabs/megaclite.git", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "master", default-features = false } + +[dependencies.curve] +git = "https://github.com/patractlabs/megaclite.git" +package = "megaclite-arkworks" +features = [ "tests" ] +default-features = false + +[dependencies.num-bigint] +version = "0.3.1" +default-features = false + +[dependencies.num-traits] +version = "0.2.14" +default-features = false [features] default = ["std"] std = [ - "megaclite", - "sp-runtime-interface/std", + "sp-runtime-interface/std" ] diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 9027fe7d..d637e782 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1,38 +1,103 @@ //! Jupiter primitives - IO Module -#![deny(missing_docs)] +#![allow(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] use sp_runtime_interface::runtime_interface; +use sp_std::vec::Vec; -/// ZK-SNARKs runtime interface +/// Pairing runtime interface #[runtime_interface] -pub trait ZkSnarks { - /// altbn_128 add - fn altbn_128_add(input: &[u8]) -> Option<[u8; 64]> { - megaclite::altbn_128::add(input).ok() +pub trait Pairing { + fn wasm() -> bool { + if let Ok(mode) = ::std::env::var("JIO_MODE") { + if mode.to_uppercase() == "WASM" { + return true; + } + } + + false + } + + fn call(func_id: u32, input: &[u8]) -> Option> { + curve::call(func_id, input).ok() + } + + fn bls12_377_add() { + curve::tests::add(0x2a); + } + + fn bls12_377_mul() { + curve::tests::mul(0x2a); + } + + fn bls12_377_pairing_two() { + curve::tests::pairing(0x2a); + } + + fn bls12_377_pairing_six() { + curve::tests::pairing_six(0x2a); + } + + fn bls12_377_verify() { + curve::tests::verify(0x2a); + } + + fn bls12_381_add() { + curve::tests::add(0x2b); + } + + fn bls12_381_mul() { + curve::tests::mul(0x2b); + } + + fn bls12_381_pairing_two() { + curve::tests::pairing(0x2b); + } + + fn bls12_381_pairing_six() { + curve::tests::pairing_six(0x2b); + } + + fn bls12_381_verify() { + curve::tests::verify(0x2b); + } + + fn bn254_add() { + curve::tests::add(0x2c); + } + + fn bn254_mul() { + curve::tests::mul(0x2c); + } + + fn bn254_pairing_two() { + curve::tests::pairing(0x2c); + } + + fn bn254_pairing_six() { + curve::tests::pairing_six(0x2c); + } + + fn bn254_verify() { + curve::tests::verify(0x2c); } - /// altbn_128 mul - fn altbn_128_mul(input: &[u8]) -> Option<[u8; 64]> { - megaclite::altbn_128::mul(input).ok() + fn bw6_761_add() { + curve::tests::add(0x2d); } - /// altbn_128 pairing - fn altbn_128_pairing(input: &[u8]) -> Option { - megaclite::altbn_128::pairing(input).ok() + fn bw6_761_mul() { + curve::tests::mul(0x2d); } - /// bls12_381 add - fn bls12_381_add(input: &[u8]) -> Option<[u8; 96]> { - megaclite::bls12_381::add(input).ok() + fn bw6_761_pairing_two() { + curve::tests::pairing(0x2d); } - /// bls12_381 mul - fn bls12_381_mul(input: &[u8]) -> Option<[u8; 96]> { - megaclite::bls12_381::mul(input).ok() + fn bw6_761_pairing_six() { + curve::tests::pairing_six(0x2d); } - /// bls12_381 pairing - fn bls12_381_pairing(input: &[u8]) -> Option { - megaclite::bls12_381::pairing(input).ok() + fn bw6_761_verify() { + curve::tests::verify(0x2d); } } diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 444c3c18..f357e4c1 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -33,4 +33,3 @@ pallet-transaction-payment-rpc = { version = "2.0.0", git = "https://github.com/ pallet-contracts-rpc = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master" } jupiter-primitives = { path = "../primitives" } - diff --git a/runtime/jupiter-dev/Cargo.toml b/runtime/jupiter-dev/Cargo.toml index 1a3e6386..391ff91c 100644 --- a/runtime/jupiter-dev/Cargo.toml +++ b/runtime/jupiter-dev/Cargo.toml @@ -47,8 +47,10 @@ pallet-contracts-rpc-runtime-api = { version = "0.8.0", git = "https://github.co # local runtime module pallet-contracts = { path = "../../vendor/substrate/frame/contracts", default-features = false } +pallet-template = { path = "../../pallets/template", default-features = false } jupiter-primitives = { path = "../../primitives", default-features = false } +jupiter-chain-extension = { path = "../../primitives/chain-extension", default-features = false } jupiter-runtime-common = { path = "../common", default-features = false } [build-dependencies] @@ -68,6 +70,7 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "sp-offchain/std", "frame-executive/std", "frame-support/std", @@ -87,8 +90,10 @@ std = [ "pallet-contracts-rpc-runtime-api/std", "pallet-contracts/std", + "pallet-template/std", "jupiter-primitives/std", + "jupiter-chain-extension/std", "jupiter-runtime-common/std", ] runtime-benchmarks = [ @@ -96,6 +101,12 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-system-benchmarking", + "sp-runtime/runtime-benchmarks", + + "pallet-timestamp/runtime-benchmarks", + "pallet-indices/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-template/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", "jupiter-runtime-common/runtime-benchmarks", diff --git a/runtime/jupiter-dev/src/lib.rs b/runtime/jupiter-dev/src/lib.rs index 7f462eee..32e4af32 100644 --- a/runtime/jupiter-dev/src/lib.rs +++ b/runtime/jupiter-dev/src/lib.rs @@ -37,6 +37,7 @@ pub use frame_support::{ StorageValue, }; pub use pallet_balances::Call as BalancesCall; +pub use pallet_template::Call as TemplateCall; pub use pallet_timestamp::Call as TimestampCall; pub use jupiter_primitives::{ @@ -233,6 +234,7 @@ impl pallet_contracts::Config for Runtime { type MaxValueSize = MaxValueSize; type WeightPrice = pallet_transaction_payment::Module; type WeightInfo = pallet_contracts::weights::SubstrateWeight; + type ChainExtension = jupiter_chain_extension::JupiterExt; } impl pallet_sudo::Config for Runtime { @@ -240,6 +242,10 @@ impl pallet_sudo::Config for Runtime { type Call = Call; } +impl pallet_template::Config for Runtime { + type Event = Event; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -262,6 +268,9 @@ construct_runtime!( Contracts: pallet_contracts::{Module, Call, Config, Storage, Event}, Sudo: pallet_sudo::{Module, Call, Config, Storage, Event}, + + // Test + Template: pallet_template::{Module, Call, Storage, Event}, } ); @@ -385,7 +394,7 @@ impl_runtime_apis! { gas_limit: u64, input_data: Vec, ) -> pallet_contracts_primitives::ContractExecResult { - Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data) + Contracts::bare_call(origin, dest, value, gas_limit, input_data) } fn get_storage( @@ -455,6 +464,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_contracts, Contracts); add_benchmark!(params, batches, pallet_indices, Indices); add_benchmark!(params, batches, pallet_timestamp, Timestamp); + add_benchmark!(params, batches, pallet_template, Template); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/jupiter/Cargo.toml b/runtime/jupiter/Cargo.toml index 52251735..5d944a79 100644 --- a/runtime/jupiter/Cargo.toml +++ b/runtime/jupiter/Cargo.toml @@ -60,13 +60,15 @@ pallet-timestamp = { version = "2.0.0", git = "https://github.com/paritytech/sub pallet-utility = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } # vendor modules -pallet-contracts = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +# pallet-contracts = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-contracts = { path = "../../vendor/substrate/frame/contracts", default-features = false } pallet-contracts-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-contracts-rpc-runtime-api = { version = "0.8.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } # local runtime module jupiter-primitives = { path = "../../primitives", default-features = false } jupiter-runtime-common = { path = "../common", default-features = false } +jupiter-chain-extension = { path = "../../primitives/chain-extension", default-features = false } [build-dependencies] substrate-wasm-builder = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } @@ -127,4 +129,5 @@ std = [ "jupiter-primitives/std", "jupiter-runtime-common/std", + "jupiter-chain-extension/std", ] diff --git a/runtime/jupiter/src/lib.rs b/runtime/jupiter/src/lib.rs index 729b405f..6c217288 100644 --- a/runtime/jupiter/src/lib.rs +++ b/runtime/jupiter/src/lib.rs @@ -733,6 +733,7 @@ impl pallet_contracts::Config for Runtime { type MaxValueSize = MaxValueSize; type WeightPrice = pallet_transaction_payment::Module; type WeightInfo = pallet_contracts::weights::SubstrateWeight; + type ChainExtension = jupiter_chain_extension::JupiterExt; } impl pallet_utility::Config for Runtime { diff --git a/scripts/benchmark.sh b/scripts/benchmark.sh new file mode 100755 index 00000000..e46eae30 --- /dev/null +++ b/scripts/benchmark.sh @@ -0,0 +1,77 @@ +#!/bin/bash +declare -a curves=( + 'bls12_377' + 'bls12_381' + 'bn254' + 'bw6_761' +) + + +declare -a exs=( + 'add' + 'mul' + 'pairing_two' +) + + +function bm() { + target/release/jupiter-dev \ + benchmark \ + -p 'pallet_template' \ + -e "$1" "${@:2}" | grep 'Time ~=' -m 1 +} + + +function ops() { + for p in "${curves[@]}" + do + echo "Curve: ${p}" + echo '=========================µs' + for q in "${exs[@]}" + do + echo "--->${q}" + printf "Wasm: " + d=wasm_"${p}"_"${q}" + bm "$d" '--execution=Wasm' '--wasm-execution=Compiled' '-r=3' + printf "RuIn: " + d=native_"${p}"_"${q}" + bm "$d" '--execution=Wasm' '--wasm-execution=Compiled' '-r=3' + done + echo "" + echo "" + done +} + + +function groth16() { + echo '=========================µs' + for p in "${curves[@]}" + do + echo "---> ${p}" + bm "${p}"_verify '--execution=Wasm' '--wasm-execution=Compiled' '-r=3' + done +} + +function verify() { + echo "Wasm groth16 verification:" + JIO_MODE=WASM groth16 + + printf "\n\n" + + echo "NATIVE groth16 verification:" + JIO_MODE=NATIVE groth16 +} + +function main() { + case $1 in + groth16) + verify + ;; + *) + ops + ;; + esac + +} + +main $@ diff --git a/vendor/substrate b/vendor/substrate index 37ec9699..3a021986 160000 --- a/vendor/substrate +++ b/vendor/substrate @@ -1 +1 @@ -Subproject commit 37ec96994cc5892f3da4f2d883c2a0b1f7f9b3f7 +Subproject commit 3a0219863a43a21bf462d880a5f24725ffde0ebc