From 73a0944e6a274a6e8fff7ca8f47c71059b95d694 Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:42:52 +0200 Subject: [PATCH] add `CheckMetadataHash` signed extension (#202) --- Cargo.lock | 74 ++++++++++++++++++++++++++++++++++++++-- node/Cargo.toml | 1 + node/src/benchmarking.rs | 2 ++ runtime/Cargo.toml | 5 ++- runtime/build.rs | 12 +++---- runtime/src/lib.rs | 1 + 6 files changed, 86 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 390dcc4..62e0e7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -626,9 +626,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.4.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" dependencies = [ "arrayref", "arrayvec", @@ -2282,6 +2282,22 @@ dependencies = [ "serde", ] +[[package]] +name = "frame-metadata-hash-extension" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1fa15dc90efe948898c06a3be111628230db100ffa2907e662062e9c9d1abd" +dependencies = [ + "array-bytes", + "docify", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", +] + [[package]] name = "frame-support" version = "35.0.0" @@ -3141,6 +3157,7 @@ dependencies = [ "clap", "frame-benchmarking", "frame-benchmarking-cli", + "frame-metadata-hash-extension", "frame-system", "futures", "hex", @@ -3188,6 +3205,7 @@ version = "1.1.38" dependencies = [ "frame-benchmarking", "frame-executive", + "frame-metadata-hash-extension", "frame-support", "frame-system", "frame-system-benchmarking", @@ -4314,6 +4332,20 @@ dependencies = [ "hash-db", ] +[[package]] +name = "merkleized-metadata" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f313fcff1d2a4bcaa2deeaa00bf7530d77d5f7bd0467a117dde2e29a75a7a17a" +dependencies = [ + "array-bytes", + "blake3", + "frame-metadata", + "parity-scale-codec", + "scale-decode", + "scale-info", +] + [[package]] name = "merlin" version = "3.0.0" @@ -7804,6 +7836,29 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "scale-bits" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57b1e7f6b65ed1f04e79a85a57d755ad56d76fdf1e9bddcc9ae14f71fcdcf54" +dependencies = [ + "parity-scale-codec", + "scale-type-resolver", +] + +[[package]] +name = "scale-decode" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98f3262c250d90e700bb802eb704e1f841e03331c2eb815e46516c4edbf5b27" +dependencies = [ + "derive_more", + "parity-scale-codec", + "scale-bits", + "scale-type-resolver", + "smallvec", +] + [[package]] name = "scale-info" version = "2.11.3" @@ -7830,6 +7885,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "scale-type-resolver" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0cded6518aa0bd6c1be2b88ac81bf7044992f0f154bfbabd5ad34f43512abcb" + [[package]] name = "schannel" version = "0.1.22" @@ -9273,13 +9334,22 @@ version = "23.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dc993ad871b63fbba60362f3ea86583f5e7e1256e8fdcb3b5b249c9ead354bf" dependencies = [ + "array-bytes", "build-helper", "cargo_metadata", "console", "filetime", + "frame-metadata", + "merkleized-metadata", + "parity-scale-codec", "parity-wasm", "polkavm-linker", + "sc-executor", + "sp-core", + "sp-io", "sp-maybe-compressed-blob", + "sp-tracing", + "sp-version", "strum 0.26.3", "tempfile", "toml 0.8.14", diff --git a/node/Cargo.toml b/node/Cargo.toml index 4663e00..9ef7300 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -22,6 +22,7 @@ hex = { workspace = true } hex-literal = { workspace = true } serde_json = { workspace = true } +frame-metadata-hash-extension = { workspace = true, features = ["std"] } frame-system = { workspace = true, features = ["std"] } pallet-transaction-payment = { workspace = true, features = ["std"] } sc-cli = { workspace = true } diff --git a/node/src/benchmarking.rs b/node/src/benchmarking.rs index ad0b117..fcd4d2b 100644 --- a/node/src/benchmarking.rs +++ b/node/src/benchmarking.rs @@ -121,6 +121,7 @@ pub fn create_benchmark_extrinsic( frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0), + frame_metadata_hash_extension::CheckMetadataHash::::new(false), ); let raw_payload = runtime::SignedPayload::from_raw( @@ -135,6 +136,7 @@ pub fn create_benchmark_extrinsic( (), (), (), + None, ), ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index c82d0be..6480eb1 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -54,6 +54,7 @@ sp-version = { workspace = true } # frame frame-executive = { workspace = true } +frame-metadata-hash-extension = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } @@ -67,7 +68,7 @@ frame-system-benchmarking = { optional = true, workspace = true } hex-literal = { workspace = true, optional = true } [build-dependencies] -substrate-wasm-builder = { workspace = true } +substrate-wasm-builder = { workspace = true, optional = true, features = ["metadata-hash"] } [features] default = ["std"] @@ -76,6 +77,7 @@ std = [ "parity-scale-codec/std", "scale-info/std", "frame-executive/std", + "frame-metadata-hash-extension/std", "frame-support/std", "frame-system-rpc-runtime-api/std", "frame-system/std", @@ -106,6 +108,7 @@ std = [ "sp-storage/std", "sp-transaction-pool/std", "sp-version/std", + "substrate-wasm-builder", "pallet-teerex/std", "pallet-claims/std", "pallet-enclave-bridge/std", diff --git a/runtime/build.rs b/runtime/build.rs index 9b53d24..c77071c 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -1,9 +1,9 @@ -use substrate_wasm_builder::WasmBuilder; - +#[cfg(feature = "std")] fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() + substrate_wasm_builder::WasmBuilder::init_with_defaults() + .enable_metadata_hash("ERT", 12) .build() } + +#[cfg(not(feature = "std"))] +fn main() {} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b3e3c5f..bcaad27 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -668,6 +668,7 @@ pub type SignedExtra = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, ); /// All migrations of the runtime, aside from the ones declared in the pallets.