Skip to content

Commit

Permalink
feat(runtime): add metadata signed-extension
Browse files Browse the repository at this point in the history
Add a new signed extension that enables the metadata hash verification feature approved under [RFC 0078](https://polkadot-fellows.github.io/RFCs/approved/0078-merkleized-metadata.html#rfc-0078-merkleized-metadata). This enhancement will support the new generic ledger hardware wallet app and future hardware wallets within the Polkadot ecosystem.
  • Loading branch information
enddynayn committed Jul 24, 2024
1 parent 2676db8 commit cccf0c3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 8 deletions.
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "r
frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
Expand All @@ -44,6 +45,7 @@ scale-info = { version = "2.10.0", default-features = false, features = [
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0", default-features = false }
chrono = { version = "0.4.24" }
pretty_assertions = { version = "1.3.0" }
smallvec = "1.11.0"
Expand Down
1 change: 1 addition & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ frame-benchmarking-cli = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
pallet-balances = { workspace = true }
pallet-transaction-payment = { workspace = true }
sc-cli = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions node/cli/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub fn create_benchmark_extrinsic(
pallet_frequency_tx_payment::ChargeFrqTransactionPayment::<runtime::Runtime>::from(0),
pallet_msa::CheckFreeExtrinsicUse::<runtime::Runtime>::new(),
pallet_handles::handles_signed_extension::HandlesSignedExtension::<runtime::Runtime>::new(),
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(false),
);

let raw_payload = sp_runtime::generic::SignedPayload::from_raw(
Expand All @@ -146,6 +147,7 @@ pub fn create_benchmark_extrinsic(
(),
(),
(),
None,
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down
16 changes: 14 additions & 2 deletions runtime/frequency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version = "0.0.0"
targets = ["x86_64-unknown-linux-gnu"]

[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.8.0"}
substrate-wasm-builder = { optional = true, workspace = true }

[dependencies]
parity-scale-codec = { workspace = true, features = ["derive"] }
Expand All @@ -30,6 +30,7 @@ frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
frame-system-rpc-runtime-api = { workspace = true }
frame-try-runtime = { workspace = true, optional = true }
frame-metadata-hash-extension = { workspace = true }

pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
Expand Down Expand Up @@ -162,6 +163,8 @@ std = [
"common-runtime/std",
"sp-version/std",
"system-runtime-api/std",
"substrate-wasm-builder",
"frame-metadata-hash-extension/std",
]
runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down Expand Up @@ -238,4 +241,13 @@ frequency-local = ["common-runtime/frequency-local"]
frequency-no-relay = ["common-runtime/frequency-no-relay"]
# Following features are used in generating lean wasms
no-metadata-docs = ["frame-support/no-metadata-docs"]
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

# Enable the metadata hash generation.
#
# This is hidden behind a feature because it increases the compile time.
# The wasm binary needs to be compiled twice, once to fetch the metadata,
# generate the metadata hash and then a second time with the
# `RUNTIME_METADATA_HASH` environment variable set for the `CheckMetadataHash`
# extension.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
26 changes: 20 additions & 6 deletions runtime/frequency/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
use substrate_wasm_builder::WasmBuilder;
#[cfg(all(feature = "std", feature = "metadata-hash"))]
fn main() {
substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_metadata_hash("FRQCY", 8)
.build();

substrate_wasm_builder::WasmBuilder::init_with_defaults()
.set_file_name("fast_runtime_binary.rs")
.enable_feature("fast-runtime")
.enable_metadata_hash("FRQCY", 8)
.build();
}

#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
fn main() {
// VSCode Users: Uncomment the following line to disable the ANSI color codes.
// The OUTPUT pane does not understand ANSI color codes and will show garbage without this.
// std::env::set_var("WASM_BUILD_NO_COLOR", "1");
WasmBuilder::new()
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
.build();
}

/// The wasm builder is deactivated when compiling
/// this crate for wasm to speed up the compilation.
#[cfg(not(feature = "std"))]
fn main() {}
1 change: 1 addition & 0 deletions runtime/frequency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ pub type SignedExtra = (
pallet_frequency_tx_payment::ChargeFrqTransactionPayment<Runtime>,
pallet_msa::CheckFreeExtrinsicUse<Runtime>,
pallet_handles::handles_signed_extension::HandlesSignedExtension<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock<Block>;
Expand Down

0 comments on commit cccf0c3

Please sign in to comment.