Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: runtime metadata hash verification #5467

Merged
merged 13 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ ethbloom = { version = "0.13" }
ethereum = { version = "0.14", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
ethers = { version = "2.0.8" }
frame-metadata = { version = "16.0.0" }
fs_extra = { version = "1.3.0" }
futures = { version = "0.3.30" }
futures-core = { version = "0.3.30" }
Expand Down Expand Up @@ -178,6 +177,8 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/chainfl
frame-benchmarking = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
frame-benchmarking-cli = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
frame-executive = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
frame-metadata = { version = "16.0.0", default-features = false }
frame-metadata-hash-extension = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
frame-support = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
frame-system = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
frame-system-benchmarking = { git = "https://github.com/chainflip-io/polkadot-sdk.git", tag = "chainflip-substrate-1.15.2+2", default-features = false }
Expand Down
7 changes: 4 additions & 3 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ codec = { workspace = true, default-features = true, features = [
"derive",
"full",
] }
frame-metadata = { workspace = true, default-features = true, features = [
"current",
] }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true, default-features = true }
frame-system = { workspace = true, default-features = true }
sc-rpc-api = { workspace = true, default-features = true }
Expand All @@ -113,9 +117,6 @@ sp-runtime = { workspace = true, default-features = true }
sp-version = { workspace = true, default-features = true }
substrate-frame-rpc-system = { workspace = true }

frame-metadata = { workspace = true, default-features = true, features = [
"current",
] }
serde_bytes = { workspace = true, default-features = true }
bs58 = { workspace = true, default-features = true }
base64 = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ where
// This is the tx fee tip. Normally this determines transaction priority. We currently
// ignore this in the runtime but it needs to be set to some default value.
state_chain_runtime::ChargeTransactionPayment::from(0),
frame_metadata_hash_extension::CheckMetadataHash::<state_chain_runtime::Runtime>::new(
false,
),
);
let additional_signed = (
(),
Expand All @@ -68,6 +71,7 @@ where
(),
(),
(),
None,
);

let signed_payload = state_chain_runtime::SignedPayload::from_raw(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<'a, 'env, BaseRpcClient: base_rpc_api::BaseRpcApi + Send + Sync + 'static>

// Find any submissions that are for the nonce of the extrinsic
if let Some(submissions) = extrinsic.signature.as_ref().and_then(
|(address, _, (.., frame_system::CheckNonce(nonce), _, _))| {
|(address, _, (.., frame_system::CheckNonce(nonce), _, _, _))| {
// We only care about the extrinsic if it is from our account
(*address == MultiAddress::Id(self.signer.account_id.clone()))
.then_some(())
Expand Down
3 changes: 3 additions & 0 deletions state-chain/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ sp-io = { workspace = true, default-features = true }
sp-timestamp = { workspace = true, default-features = true }
sp-inherents = { workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }

# FRAME dependencies
frame-metadata-hash-extension = { workspace = true }
frame-system = { workspace = true, default-features = true }
pallet-transaction-payment = { workspace = true, default-features = true }

Expand Down
2 changes: 2 additions & 0 deletions state-chain/node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn create_benchmark_extrinsic(
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(false),
);

let raw_payload = runtime::SignedPayload::from_raw(
Expand All @@ -96,6 +97,7 @@ pub fn create_benchmark_extrinsic(
(),
(),
(),
None,
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down
9 changes: 5 additions & 4 deletions state-chain/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ pallet-session = { workspace = true, features = ["historical"] }
# Substrate dependencies
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
frame-try-runtime = { workspace = true, optional = true }

pallet-aura = { workspace = true }
pallet-grandpa = { workspace = true }
Expand All @@ -84,6 +86,7 @@ sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true, features = ["serde"] }
sp-consensus-grandpa = { workspace = true, features = ["serde"] }
sp-core = { workspace = true, features = ["serde"] }
sp-genesis-builder = { workspace = true }
sp-inherents = { workspace = true }
sp-offchain = { workspace = true }
sp-runtime = { workspace = true, features = ["serde"] }
Expand All @@ -92,10 +95,6 @@ sp-std = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }

sp-genesis-builder = { workspace = true }

frame-try-runtime = { workspace = true, optional = true }

# Used for RPCs
frame-system-rpc-runtime-api = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
Expand Down Expand Up @@ -207,6 +206,7 @@ std = [
"sp-version/std",
"dep:cf-test-utilities",
"dep:substrate-wasm-builder",
"frame-metadata-hash-extension/std",
]
try-runtime = [
"cf-runtime-utilities/try-runtime",
Expand Down Expand Up @@ -243,3 +243,4 @@ try-runtime = [
"pallet-authorship/try-runtime",
"sp-runtime/try-runtime",
]
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
12 changes: 11 additions & 1 deletion state-chain/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
fn main() {
#[cfg(feature = "std")]
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build();
}

#[cfg(all(feature = "std", feature = "metadata-hash"))]
{
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("FLIP", 18)
ramizhasan111 marked this conversation as resolved.
Show resolved Hide resolved
.build();
}
}
3 changes: 2 additions & 1 deletion state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_version: 180,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 12,
transaction_version: 13,
state_version: 1,
};

Expand Down Expand Up @@ -1158,6 +1158,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
Expand Down
Loading