Skip to content

Commit 1e95060

Browse files
authored
Prevent arithmetic overflow panick when handling XCM (#328)
1 parent 6ddf2e7 commit 1e95060

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/ismp/clients/parachain/inherent/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::sync::Arc;
2121
use anyhow::anyhow;
2222
use codec::{Decode, Encode};
2323
use cumulus_relay_chain_interface::RelayChainInterface;
24+
use sp_api::ApiExt;
2425
use sp_runtime::{
2526
generic::{BlockId, Header},
2627
traits::{BlakeTwo256, Block as BlockT},
@@ -51,6 +52,12 @@ impl ConsensusInherentProvider {
5152
C::Api: IsmpParachainApi<B> + IsmpRuntimeApi<B, B::Hash>,
5253
B: BlockT,
5354
{
55+
// Check if it has the parachain runtime api
56+
if !client.runtime_api().has_api::<dyn IsmpParachainApi<B>>(parent)? {
57+
log::trace!("IsmpParachainApi not implemented");
58+
return Ok(ConsensusInherentProvider(None));
59+
}
60+
5461
let para_ids = client.runtime_api().para_ids(parent)?;
5562

5663
log::trace!("ParaIds from runtime: {para_ids:?}");

modules/ismp/pallets/asset-gateway/src/xcm_utilities.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ where
182182
let base_fee =
183183
if who.dest_state_machine == StateMachine::Evm(1) { 20_000_000_000u128 } else { 0 };
184184
let protocol_fees = protocol_percentage * u128::from(amount) + base_fee;
185-
let remainder = amount - protocol_fees.into();
185+
let remainder = u128::from(amount)
186+
.checked_sub(protocol_fees.into())
187+
.ok_or_else(|| XcmError::Overflow)?
188+
.into();
186189
// Mint protocol fees
187190
T::Assets::mint_into(asset_id.clone(), &protocol_account, protocol_fees.into())
188191
.map_err(|e| XcmError::FailedToTransactAsset(e.into()))?;

parachain/node/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hyperbridge"
3-
version = "0.6.2"
3+
version = "0.6.3"
44
authors = ["Polytope Labs <hello@polytope.technology>"]
55
description = "The Hyperbridge coprocessor node"
66
repository = "https://github.com/polytope-labs/hyperbridge"

parachain/runtimes/gargantua/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
233233
spec_name: create_runtime_str!("gargantua"),
234234
impl_name: create_runtime_str!("gargantua"),
235235
authoring_version: 1,
236-
spec_version: 1150,
236+
spec_version: 1160,
237237
impl_version: 0,
238238
apis: RUNTIME_API_VERSIONS,
239239
transaction_version: 1,

0 commit comments

Comments
 (0)