diff --git a/Cargo.lock b/Cargo.lock index de80273b5..58f41e74b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "affix" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e7ea84d3fa2009f355f8429a0b418a96849135a4188fadf384f59127d5d4bc" +dependencies = [ + "convert_case 0.5.0", +] + [[package]] name = "ahash" version = "0.7.6" @@ -88,6 +97,11 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf688625d06217d5b1bb0ea9d9c44a1635fd0ee3534466388d18203174f4d11" +[[package]] +name = "amcl" +version = "0.3.0" +source = "git+https://github.com/darwinia-network/milagro_bls#076d5fb697b304534b26cb8b7fe488b9a7e70a99" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -633,7 +647,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" dependencies = [ - "block-padding", + "block-padding 0.1.5", "byte-tools", "byteorder", "generic-array 0.12.4", @@ -645,6 +659,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ + "block-padding 0.2.1", "generic-array 0.14.6", ] @@ -666,6 +681,12 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "blocking" version = "1.2.0" @@ -850,7 +871,9 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" dependencies = [ + "lazy_static", "memchr", + "regex-automata", ] [[package]] @@ -940,6 +963,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "case" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" + [[package]] name = "cc" version = "1.0.76" @@ -1176,6 +1205,19 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "terminal_size", + "winapi", +] + [[package]] name = "const-oid" version = "0.7.1" @@ -1194,6 +1236,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "convert_case" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" + [[package]] name = "core-foundation" version = "0.9.3" @@ -2101,6 +2149,45 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "darwinia-precompile-bls12-381" +version = "6.0.0" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "milagro_bls", + "pallet-balances", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "precompile-utils", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "darwinia-precompile-state-storage" +version = "6.0.0" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "pallet-balances", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "precompile-utils", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "darwinia-runtime" version = "6.0.0" @@ -2121,6 +2208,8 @@ dependencies = [ "cumulus-primitives-timestamp", "cumulus-primitives-utility", "darwinia-common-runtime", + "darwinia-precompile-bls12-381", + "darwinia-precompile-state-storage", "dc-primitives", "fp-evm", "fp-rpc", @@ -2144,6 +2233,7 @@ dependencies = [ "pallet-evm", "pallet-evm-precompile-blake2", "pallet-evm-precompile-bn128", + "pallet-evm-precompile-dispatch", "pallet-evm-precompile-modexp", "pallet-evm-precompile-simple", "pallet-fee-market", @@ -2237,7 +2327,7 @@ version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "convert_case", + "convert_case 0.4.0", "proc-macro2", "quote", "rustc_version", @@ -2436,6 +2526,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "enum-as-inner" version = "0.4.0" @@ -2549,7 +2645,7 @@ dependencies = [ "rlp-derive", "scale-info", "serde", - "sha3", + "sha3 0.10.6", "triehash", ] @@ -2593,7 +2689,7 @@ dependencies = [ "rlp", "scale-info", "serde", - "sha3", + "sha3 0.10.6", ] [[package]] @@ -2630,7 +2726,7 @@ dependencies = [ "environmental", "evm-core", "primitive-types", - "sha3", + "sha3 0.10.6", ] [[package]] @@ -2716,7 +2812,7 @@ dependencies = [ [[package]] name = "fc-cli" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "clap", "ethereum-types", @@ -2735,7 +2831,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "async-trait", "fc-db", @@ -2754,7 +2850,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fp-storage", "kvdb-rocksdb", @@ -2772,7 +2868,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fc-db", "fp-consensus", @@ -2789,7 +2885,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "ethereum-types", @@ -2832,7 +2928,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "ethereum-types", @@ -2955,7 +3051,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "parity-scale-codec", @@ -2967,7 +3063,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "ethereum-types", @@ -2982,7 +3078,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "evm", "frame-support", @@ -2995,7 +3091,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "ethereum-types", @@ -3012,7 +3108,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "frame-support", @@ -3026,7 +3122,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "parity-scale-codec", "serde", @@ -4716,7 +4812,7 @@ dependencies = [ "pin-project", "rand 0.8.5", "salsa20", - "sha3", + "sha3 0.10.6", ] [[package]] @@ -5199,6 +5295,16 @@ dependencies = [ "thrift", ] +[[package]] +name = "milagro_bls" +version = "1.5.0" +source = "git+https://github.com/darwinia-network/milagro_bls#076d5fb697b304534b26cb8b7fe488b9a7e70a99" +dependencies = [ + "amcl", + "rand 0.8.5", + "zeroize", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -5268,7 +5374,7 @@ dependencies = [ "digest 0.10.5", "multihash-derive", "sha2 0.10.6", - "sha3", + "sha3 0.10.6", "unsigned-varint", ] @@ -5789,7 +5895,7 @@ dependencies = [ [[package]] name = "pallet-base-fee" version = "1.0.0" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fp-evm", "frame-support", @@ -6067,7 +6173,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "ethereum", "ethereum-types", @@ -6094,7 +6200,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "environmental", "evm", @@ -6119,7 +6225,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fp-evm", ] @@ -6127,17 +6233,27 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fp-evm", "sp-core", "substrate-bn", ] +[[package]] +name = "pallet-evm-precompile-dispatch" +version = "2.0.0-dev" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" +dependencies = [ + "fp-evm", + "frame-support", + "pallet-evm", +] + [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fp-evm", "num", @@ -6146,7 +6262,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#ce45aff1903e058f4cf6e660f2c9202847a15b25" +source = "git+https://github.com/paritytech/frontier?branch=polkadot-v0.9.30#1bd889c001b2a4735777160354cb57b8c17cf756" dependencies = [ "fp-evm", "ripemd", @@ -8255,6 +8371,46 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "precompile-utils" +version = "0.1.0" +source = "git+https://github.com/darwinia-network/moonbeam.git?branch=polkadot-v0.9.30#38c37cc41b9a97482292717aec58b305d5f627f4" +dependencies = [ + "affix", + "evm", + "fp-evm", + "frame-support", + "frame-system", + "hex", + "impl-trait-for-tuples", + "log", + "num_enum", + "pallet-evm", + "parity-scale-codec", + "paste", + "precompile-utils-macro", + "sha3 0.9.1", + "similar-asserts", + "sp-core", + "sp-io", + "sp-std", + "xcm", +] + +[[package]] +name = "precompile-utils-macro" +version = "0.1.0" +source = "git+https://github.com/darwinia-network/moonbeam.git?branch=polkadot-v0.9.30#38c37cc41b9a97482292717aec58b305d5f627f4" +dependencies = [ + "case", + "num_enum", + "prettyplease", + "proc-macro2", + "quote", + "sha3 0.8.2", + "syn", +] + [[package]] name = "prettyplease" version = "0.1.21" @@ -10430,6 +10586,31 @@ dependencies = [ "digest 0.10.5", ] +[[package]] +name = "sha3" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" +dependencies = [ + "block-buffer 0.7.3", + "byte-tools", + "digest 0.8.1", + "keccak", + "opaque-debug 0.2.3", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug 0.3.0", +] + [[package]] name = "sha3" version = "0.10.6" @@ -10496,6 +10677,26 @@ dependencies = [ "paste", ] +[[package]] +name = "similar" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +dependencies = [ + "bstr", + "unicode-segmentation", +] + +[[package]] +name = "similar-asserts" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf644ad016b75129f01a34a355dcb8d66a5bc803e417c7a77cc5d5ee9fa0f18" +dependencies = [ + "console", + "similar", +] + [[package]] name = "slab" version = "0.4.7" @@ -10842,7 +11043,7 @@ dependencies = [ "byteorder", "digest 0.10.5", "sha2 0.10.6", - "sha3", + "sha3 0.10.6", "sp-std", "twox-hash", ] @@ -11648,6 +11849,16 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "terminal_size" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "textwrap" version = "0.16.0" @@ -12088,7 +12299,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.5", "rand 0.8.5", "static_assertions", @@ -12148,6 +12359,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" + [[package]] name = "unicode-width" version = "0.1.10" diff --git a/Cargo.toml b/Cargo.toml index 696505b18..52ec33ac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,5 @@ members = [ "core/*", "node", "runtime/*", + "precompiles/*" ] diff --git a/precompiles/bls12-381/Cargo.toml b/precompiles/bls12-381/Cargo.toml new file mode 100644 index 000000000..9c0ad018d --- /dev/null +++ b/precompiles/bls12-381/Cargo.toml @@ -0,0 +1,50 @@ +[package] +authors = ["Darwinia Network "] +description = "State storage precompiles for EVM pallet." +edition = "2021" +homepage = "https://darwinia.network" +license = "GPL-3.0" +name = "darwinia-precompile-bls12-381" +readme = "README.md" +repository = "https://github.com/darwinia-network/darwinia" +version = "6.0.0" + +[dependencies] +# crates.io +milagro_bls = { default-features = false, git = "https://github.com/darwinia-network/milagro_bls" } +# frontier +fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +# moonbeam +precompile-utils = {default-features = false, git = "https://github.com/darwinia-network/moonbeam.git", branch = "polkadot-v0.9.30" } +# paritytech +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[dev-dependencies] +# crates.io +codec = { package = "parity-scale-codec", version = "3.2" } +scale-info = { version = "2.3", features = ["derive"] } +# moonbeam +precompile-utils = { git = "https://github.com/darwinia-network/moonbeam.git", branch = "polkadot-v0.9.30", features = [ "testing" ] } +# paritytech +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] + +std = [ + # frontier + "fp-evm/std", + "pallet-evm/std", + # moonbeam + "precompile-utils/std", + # paritytech + # "frame-support/std", + "sp-std/std" +] \ No newline at end of file diff --git a/precompiles/bls12-381/src/lib.rs b/precompiles/bls12-381/src/lib.rs new file mode 100644 index 000000000..79eebe79e --- /dev/null +++ b/precompiles/bls12-381/src/lib.rs @@ -0,0 +1,60 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +// std +use core::marker::PhantomData; +// crates.io +use milagro_bls::{AggregatePublicKey, AggregateSignature, PublicKey, Signature}; +// moonbeam +use precompile_utils::prelude::*; +// substrate +use sp_std::vec::Vec; + +pub(crate) const VERIFY_ESTIMATED_COST: u64 = 100_000; + +pub struct BLS12381(PhantomData); + +#[precompile_utils::precompile] +impl BLS12381 { + #[precompile::public("fast_aggregate_verify(bytes[],bytes,bytes)")] + #[precompile::view] + fn state_storage_at( + handle: &mut impl PrecompileHandle, + pubkeys: Vec, + message: UnboundedBytes, + signature: UnboundedBytes, + ) -> EvmResult { + handle.record_cost(VERIFY_ESTIMATED_COST)?; + + let sig = + Signature::from_bytes(signature.as_bytes()).map_err(|_| revert("Invalid signature"))?; + let agg_sig = AggregateSignature::from_signature(&sig); + + let public_keys: Result, _> = + pubkeys.into_iter().map(|k| PublicKey::from_bytes(k.as_bytes())).collect(); + let Ok(keys) = public_keys else { + return Err(revert("Invalid pubkeys")); + }; + + let agg_pub_key = + AggregatePublicKey::into_aggregate(&keys).map_err(|_| revert("Invalid aggregate"))?; + Ok(agg_sig.fast_aggregate_verify_pre_aggregated(message.as_bytes(), &agg_pub_key)) + } +} diff --git a/precompiles/state-storage/Cargo.toml b/precompiles/state-storage/Cargo.toml new file mode 100644 index 000000000..9552d8018 --- /dev/null +++ b/precompiles/state-storage/Cargo.toml @@ -0,0 +1,48 @@ +[package] +authors = ["Darwinia Network "] +description = "State storage precompiles for EVM pallet." +edition = "2021" +homepage = "https://darwinia.network" +license = "GPL-3.0" +name = "darwinia-precompile-state-storage" +readme = "README.md" +repository = "https://github.com/darwinia-network/darwinia" +version = "6.0.0" + +[dependencies] +# frontier +fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +# moonbeam +precompile-utils = {default-features = false, git = "https://github.com/darwinia-network/moonbeam.git", branch = "polkadot-v0.9.30" } +# paritytech +frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[dev-dependencies] +# crates.io +codec = { package = "parity-scale-codec", version = "3.2" } +scale-info = { version = "2.3", features = ["derive"] } +# moonbeam +precompile-utils = { git = "https://github.com/darwinia-network/moonbeam.git", branch = "polkadot-v0.9.30", features = [ "testing" ] } +# paritytech +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } + +[features] +default = ["std"] + +std = [ + # frontier + "fp-evm/std", + "pallet-evm/std", + # moonbeam + "precompile-utils/std", + # paritytech + # "frame-support/std", + "sp-std/std" +] diff --git a/precompiles/state-storage/src/lib.rs b/precompiles/state-storage/src/lib.rs new file mode 100644 index 000000000..1e0ccf7e1 --- /dev/null +++ b/precompiles/state-storage/src/lib.rs @@ -0,0 +1,72 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(test)] +mod mock; +#[cfg(test)] +mod tests; + +// std +use core::marker::PhantomData; +// moonbeam +use precompile_utils::prelude::*; +// substrate +use frame_support::{StorageHasher, Twox128}; + +const PALLET_PREFIX_LENGTH: usize = 16; + +pub trait StorageFilterT { + fn allow(prefix: &[u8]) -> bool; +} + +pub struct StateStorage { + _marker: PhantomData<(Runtime, Filter)>, +} + +pub struct EthereumStorageFilter; +impl StorageFilterT for EthereumStorageFilter { + fn allow(prefix: &[u8]) -> bool { + prefix != Twox128::hash(b"EVM") && prefix != Twox128::hash(b"Ethereum") + } +} + +#[precompile_utils::precompile] +impl StateStorage +where + Runtime: pallet_evm::Config, + Filter: StorageFilterT, +{ + #[precompile::public("state_storage(bytes)")] + #[precompile::view] + fn state_storage_at( + handle: &mut impl PrecompileHandle, + key: UnboundedBytes, + ) -> EvmResult { + handle.record_cost(RuntimeHelper::::db_read_gas_cost())?; + + let bytes = key.as_bytes(); + if bytes.len() < PALLET_PREFIX_LENGTH || !Filter::allow(&bytes[0..PALLET_PREFIX_LENGTH]) { + return Err(revert("Read restriction")); + } + + let output = frame_support::storage::unhashed::get_raw(&bytes); + Ok(output.unwrap_or_default().as_slice().into()) + } +} diff --git a/precompiles/state-storage/src/mock.rs b/precompiles/state-storage/src/mock.rs new file mode 100644 index 000000000..df8fd8995 --- /dev/null +++ b/precompiles/state-storage/src/mock.rs @@ -0,0 +1,265 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . + +//! Test utilities + +// crates.io +use codec::{Decode, Encode, MaxEncodedLen}; +// frontier +use fp_evm::{Precompile, PrecompileSet}; +use pallet_evm::AddressMapping; +// parity +use frame_support::{ + pallet_prelude::Weight, + traits::{ConstU32, Everything}, + StorageHasher, Twox128, +}; +use sp_core::{H160, H256, U256}; +use sp_runtime::{ + testing::Header, + traits::{BlakeTwo256, IdentityLookup}, + AccountId32, +}; +use sp_std::{marker::PhantomData, prelude::*}; +// darwinia +use crate::*; + +pub type Block = frame_system::mocking::MockBlock; +pub type Balance = u64; +pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + +#[derive( + Eq, + PartialEq, + Ord, + PartialOrd, + Clone, + Encode, + Decode, + Debug, + MaxEncodedLen, + scale_info::TypeInfo, +)] +pub enum Account { + Alice, + Bob, + Charlie, + Bogus, + Precompile, +} + +impl Default for Account { + fn default() -> Self { + Self::Bogus + } +} + +impl Into for Account { + fn into(self) -> H160 { + match self { + Account::Alice => H160::repeat_byte(0xAA), + Account::Bob => H160::repeat_byte(0xBB), + Account::Charlie => H160::repeat_byte(0xCC), + Account::Bogus => H160::repeat_byte(0xDD), + Account::Precompile => H160::from_low_u64_be(1), + } + } +} + +frame_support::parameter_types! { + pub const BlockHashCount: u64 = 250; +} +impl frame_system::Config for TestRuntime { + type AccountData = pallet_balances::AccountData; + type AccountId = AccountId32; + type BaseCallFilter = Everything; + type BlockHashCount = (); + type BlockLength = (); + type BlockNumber = u64; + type BlockWeights = (); + type DbWeight = (); + type Hash = H256; + type Hashing = BlakeTwo256; + type Header = Header; + type Index = u64; + type Lookup = IdentityLookup; + type MaxConsumers = ConstU32<16>; + type OnKilledAccount = (); + type OnNewAccount = (); + type OnSetCode = (); + type PalletInfo = PalletInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type SS58Prefix = (); + type SystemWeightInfo = (); + type Version = (); +} + +frame_support::parameter_types! { + pub const MaxLocks: u32 = 10; + pub const ExistentialDeposit: u64 = 0; +} +impl pallet_balances::Config for TestRuntime { + type AccountStore = System; + type Balance = Balance; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type MaxLocks = MaxLocks; + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + +frame_support::parameter_types! { + pub const MinimumPeriod: u64 = 6000 / 2; +} +impl pallet_timestamp::Config for TestRuntime { + type MinimumPeriod = MinimumPeriod; + type Moment = u64; + type OnTimestampSet = (); + type WeightInfo = (); +} + +pub struct StorageFilter; +impl StorageFilterT for StorageFilter { + fn allow(prefix: &[u8]) -> bool { + prefix != Twox128::hash(b"EVM") + } +} + +pub struct TestPrecompiles(PhantomData); +impl TestPrecompiles +where + R: pallet_evm::Config, +{ + pub fn new() -> Self { + Self(Default::default()) + } + + pub fn used_addresses() -> [H160; 1] { + [addr(1)] + } +} +impl PrecompileSet for TestPrecompiles +where + StateStorage: Precompile, + R: pallet_evm::Config, +{ + fn execute(&self, handle: &mut impl PrecompileHandle) -> Option> { + match handle.code_address() { + a if a == addr(1) => Some(StateStorage::::execute(handle)), + _ => None, + } + } + + fn is_precompile(&self, address: H160) -> bool { + Self::used_addresses().contains(&address) + } +} +fn addr(a: u64) -> H160 { + H160::from_low_u64_be(a) +} + +pub struct HashedAddressMapping; +impl AddressMapping for HashedAddressMapping { + fn into_account_id(address: H160) -> AccountId32 { + let mut data = [0u8; 32]; + data[0..20].copy_from_slice(&address[..]); + AccountId32::from(Into::<[u8; 32]>::into(data)) + } +} + +frame_support::parameter_types! { + pub const TransactionByteFee: u64 = 1; + pub const ChainId: u64 = 42; + pub const BlockGasLimit: U256 = U256::MAX; + pub const WeightPerGas: Weight = Weight::from_ref_time(20_000); + pub PrecompilesValue: TestPrecompiles = TestPrecompiles::<_>::new(); +} + +pub type PCall = StateStorageCall; + +impl pallet_evm::Config for TestRuntime { + type AddressMapping = HashedAddressMapping; + type BlockGasLimit = BlockGasLimit; + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type CallOrigin = pallet_evm::EnsureAddressRoot; + type ChainId = ChainId; + type Currency = Balances; + type FeeCalculator = (); + type FindAuthor = (); + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type OnChargeTransaction = (); + type PrecompilesType = TestPrecompiles; + type PrecompilesValue = PrecompilesValue; + type Runner = pallet_evm::runner::stack::Runner; + type RuntimeEvent = RuntimeEvent; + type WeightPerGas = WeightPerGas; + type WithdrawOrigin = pallet_evm::EnsureAddressNever; +} + +frame_support::construct_runtime! { + pub enum TestRuntime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Pallet, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Pallet, Call, Storage}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, + EVM: pallet_evm::{Pallet, Call, Storage, Config, Event}, + } +} + +#[derive(Default)] +pub(crate) struct ExtBuilder { + // endowed accounts with balances + balances: Vec<(AccountId32, Balance)>, +} + +impl ExtBuilder { + pub(crate) fn with_balances(mut self, balances: Vec<(H160, Balance)>) -> Self { + let balances = balances + .iter() + .map(|(account, amount)| { + ( + ::AddressMapping::into_account_id(*account), + *amount, + ) + }) + .collect(); + self.balances = balances; + self + } + + pub(crate) fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .expect("Frame system builds valid default genesis config"); + + pallet_balances::GenesisConfig:: { balances: self.balances } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} diff --git a/precompiles/state-storage/src/tests.rs b/precompiles/state-storage/src/tests.rs new file mode 100644 index 000000000..b73a2b2a2 --- /dev/null +++ b/precompiles/state-storage/src/tests.rs @@ -0,0 +1,90 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . + +// darwinia +use crate::mock::{ + Account::{Alice, Precompile}, + ExtBuilder, PCall, PrecompilesValue, System, TestPrecompiles, TestRuntime, +}; +// moonbeam +use precompile_utils::{ + prelude::{RuntimeHelper, UnboundedBytes}, + testing::{PrecompileTesterExt, PrecompilesModifierTester}, + EvmDataWriter, +}; +// substrate +use frame_support::{StorageHasher, Twox128}; + +fn precompiles() -> TestPrecompiles { + PrecompilesValue::get() +} + +#[test] +fn selectors() { + assert!(PCall::state_storage_at_selectors().contains(&0x78943fb7)); +} + +#[test] +fn modifier() { + ExtBuilder::default().build().execute_with(|| { + let mut tester = PrecompilesModifierTester::new(PrecompilesValue::get(), Alice, Precompile); + tester.test_view_modifier(PCall::state_storage_at_selectors()); + }); +} + +#[test] +fn no_selector_exists_but_length_is_right() { + ExtBuilder::default().build().execute_with(|| { + precompiles() + .prepare_test(Alice, Precompile, vec![1u8, 2u8, 3u8, 4u8]) + .execute_reverts(|output| output == b"Unknown selector"); + }); +} + +#[test] +fn test_state_storage() { + ExtBuilder::default().with_balances(vec![(Alice.into(), 100)]).build().execute_with(|| { + System::set_block_number(5); + + let mut key = vec![0u8; 32]; + key[0..16].copy_from_slice(&Twox128::hash(b"System")); + key[16..32].copy_from_slice(&Twox128::hash(b"Number")); + + precompiles() + .prepare_test(Alice, Precompile, PCall::state_storage_at { key: key.into() }) + .expect_cost(RuntimeHelper::::db_read_gas_cost()) + .expect_no_logs() + .execute_returns( + EvmDataWriter::new().write(UnboundedBytes::from(&5u64.to_le_bytes())).build(), + ); + }); +} + +#[test] +fn test_storage_filter() { + ExtBuilder::default().with_balances(vec![(Alice.into(), 100)]).build().execute_with(|| { + let mut key = vec![0u8; 32]; + key[0..16].copy_from_slice(&Twox128::hash(b"EVM")); + key[16..32].copy_from_slice(&Twox128::hash(b"AccountCodes")); + + precompiles() + .prepare_test(Alice, Precompile, PCall::state_storage_at { key: key.into() }) + .expect_no_logs() + .execute_reverts(|output| output == b"Read restriction"); + }); +} diff --git a/runtime/darwinia/Cargo.toml b/runtime/darwinia/Cargo.toml index 4d1a3e711..da5cf00d8 100644 --- a/runtime/darwinia/Cargo.toml +++ b/runtime/darwinia/Cargo.toml @@ -35,8 +35,10 @@ parachain-info = { default-features = false, git = "https://git cumulus-pallet-session-benchmarking = { optional = true, default-features = false, git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.30" } # darwinia -darwinia-common-runtime = { default-features = false, path = "../common" } -dc-primitives = { default-features = false, path = "../../core/primitives" } +darwinia-common-runtime = { default-features = false, path = "../common" } +darwinia-precompile-bls12-381 = { default-features = false, path = "../../precompiles/bls12-381" } +darwinia-precompile-state-storage = { default-features = false, path = "../../precompiles/state-storage" } +dc-primitives = { default-features = false, path = "../../core/primitives" } # darwinia-messages-substrate bp-message-dispatch = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" } @@ -50,16 +52,18 @@ pallet-bridge-messages = { default-features = false, git = "https://github.com/d pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" } # frontier -fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -fp-self-contained = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-base-fee = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-ethereum = { default-features = false, features = ["forbid-evm-reentrancy"], git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-evm = { default-features = false, features = ["forbid-evm-reentrancy"], git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-evm-precompile-blake2 = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-evm-precompile-bn128 = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-evm-precompile-modexp = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } -pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +fp-self-contained = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-base-fee = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-ethereum = { default-features = false, features = ["forbid-evm-reentrancy"], git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm = { default-features = false, features = ["forbid-evm-reentrancy"], git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm-precompile-blake2 = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm-precompile-bn128 = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm-precompile-dispatch = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm-precompile-modexp = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } +pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } + # polkadot pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } @@ -122,6 +126,8 @@ std = [ # darwinia "darwinia-common-runtime/std", + "darwinia-precompile-bls12-381/std", + "darwinia-precompile-state-storage/std", "dc-primitives/std", # darwinia-messages-substrate @@ -144,6 +150,7 @@ std = [ "pallet-evm/std", "pallet-evm-precompile-blake2/std", "pallet-evm-precompile-bn128/std", + "pallet-evm-precompile-dispatch/std", "pallet-evm-precompile-modexp/std", "pallet-evm-precompile-simple/std", @@ -237,7 +244,9 @@ try-runtime = [ "parachain-info/try-runtime", # frontier + "pallet-base-fee/try-runtime", "pallet-ethereum/try-runtime", + "pallet-evm/try-runtime", # polkadot "pallet-xcm/try-runtime", diff --git a/runtime/darwinia/src/pallets/evm.rs b/runtime/darwinia/src/pallets/evm.rs index 1e5ade093..b1d73060b 100644 --- a/runtime/darwinia/src/pallets/evm.rs +++ b/runtime/darwinia/src/pallets/evm.rs @@ -18,6 +18,8 @@ // darwinia use crate::*; +use darwinia_precompile_bls12_381::BLS12381; +use darwinia_precompile_state_storage::{EthereumStorageFilter, StateStorage}; use dc_primitives::EVM_ADDR_PREFIX; // frontier use pallet_ethereum::EthereumBlockHashMapping; @@ -27,6 +29,7 @@ use pallet_evm::{ }; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; +use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_simple::{ECRecover, Identity, Ripemd160, Sha256}; // substrate @@ -69,7 +72,6 @@ impl FeeCalculator for FixedGasPrice { (U256::from(GWEI), Weight::zero()) } } - pub struct ConcatAddressMapping; impl AddressMapping for ConcatAddressMapping where @@ -98,8 +100,21 @@ where Self(Default::default()) } - pub fn used_addresses() -> [H160; 9] { - [addr(1), addr(2), addr(3), addr(4), addr(5), addr(6), addr(7), addr(8), addr(9)] + pub fn used_addresses() -> [H160; 12] { + [ + addr(1), + addr(2), + addr(3), + addr(4), + addr(5), + addr(6), + addr(7), + addr(8), + addr(9), + addr(1024), + addr(1025), + addr(2048), + ] } } impl PrecompileSet for DarwiniaPrecompiles @@ -118,7 +133,12 @@ where a if a == addr(7) => Some(Bn128Mul::execute(handle)), a if a == addr(8) => Some(Bn128Pairing::execute(handle)), a if a == addr(9) => Some(Blake2F::execute(handle)), - // Non-Frontier specific nor Ethereum precompiles: + // Darwinia precompiles: 1024+ for stable precompiles. + a if a == addr(1024) => + Some(>::execute(handle)), + a if a == addr(1025) => Some(>::execute(handle)), + // Darwinia precompiles: 2048+ for experimental precompiles. + a if a == addr(2048) => Some(>::execute(handle)), _ => None, } }