Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Disallow decoding of phantom asset (#6597)
Browse files Browse the repository at this point in the history
* Disallow decoding of phantom asset

* Remove pub
  • Loading branch information
gavofyork authored Jan 20, 2023
1 parent 153543b commit 157c032
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion xcm/src/v3/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl TryFrom<AssetInstance> for u128 {
}

/// Classification of whether an asset is fungible or not, along with a mandatory amount or instance.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum Fungibility {
/// A fungible asset; we record a number of units, as a `u128` in the inner item.
Expand All @@ -245,6 +245,23 @@ pub enum Fungibility {
NonFungible(AssetInstance),
}

#[derive(Decode)]
enum UncheckedFungibility {
Fungible(#[codec(compact)] u128),
NonFungible(AssetInstance),
}

impl Decode for Fungibility {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, parity_scale_codec::Error> {
match UncheckedFungibility::decode(input)? {
UncheckedFungibility::Fungible(a) if a != 0 => Ok(Self::Fungible(a)),
UncheckedFungibility::NonFungible(i) => Ok(Self::NonFungible(i)),
UncheckedFungibility::Fungible(_) =>
Err("Fungible asset of zero amount is not allowed".into()),
}
}
}

impl Fungibility {
pub fn is_kind(&self, w: WildFungibility) -> bool {
use Fungibility::*;
Expand Down

0 comments on commit 157c032

Please sign in to comment.