Skip to content

Commit

Permalink
Prevent arithmetic overflow panick when handling XCM (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Oct 22, 2024
1 parent 6ddf2e7 commit 1e95060
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

7 changes: 7 additions & 0 deletions modules/ismp/clients/parachain/inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::sync::Arc;
use anyhow::anyhow;
use codec::{Decode, Encode};
use cumulus_relay_chain_interface::RelayChainInterface;
use sp_api::ApiExt;
use sp_runtime::{
generic::{BlockId, Header},
traits::{BlakeTwo256, Block as BlockT},
Expand Down Expand Up @@ -51,6 +52,12 @@ impl ConsensusInherentProvider {
C::Api: IsmpParachainApi<B> + IsmpRuntimeApi<B, B::Hash>,
B: BlockT,
{
// Check if it has the parachain runtime api
if !client.runtime_api().has_api::<dyn IsmpParachainApi<B>>(parent)? {
log::trace!("IsmpParachainApi not implemented");
return Ok(ConsensusInherentProvider(None));
}

let para_ids = client.runtime_api().para_ids(parent)?;

log::trace!("ParaIds from runtime: {para_ids:?}");
Expand Down
5 changes: 4 additions & 1 deletion modules/ismp/pallets/asset-gateway/src/xcm_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ where
let base_fee =
if who.dest_state_machine == StateMachine::Evm(1) { 20_000_000_000u128 } else { 0 };
let protocol_fees = protocol_percentage * u128::from(amount) + base_fee;
let remainder = amount - protocol_fees.into();
let remainder = u128::from(amount)
.checked_sub(protocol_fees.into())
.ok_or_else(|| XcmError::Overflow)?
.into();
// Mint protocol fees
T::Assets::mint_into(asset_id.clone(), &protocol_account, protocol_fees.into())
.map_err(|e| XcmError::FailedToTransactAsset(e.into()))?;
Expand Down
2 changes: 1 addition & 1 deletion parachain/node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperbridge"
version = "0.6.2"
version = "0.6.3"
authors = ["Polytope Labs <[email protected]>"]
description = "The Hyperbridge coprocessor node"
repository = "https://github.com/polytope-labs/hyperbridge"
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("gargantua"),
impl_name: create_runtime_str!("gargantua"),
authoring_version: 1,
spec_version: 1150,
spec_version: 1160,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 1e95060

Please sign in to comment.