From 90629dead79ce6aa927603e63830be0488ba6dd5 Mon Sep 17 00:00:00 2001 From: gregtatcam Date: Wed, 21 Feb 2024 08:23:51 +0000 Subject: [PATCH] Check AMM/OfferCreate for MPT amounts * Add type restriction to StepImp and flow() * Add temMPT_NOT_SUPPORTED_BY_TX --- src/ripple/app/paths/impl/Steps.h | 2 ++ src/ripple/app/paths/impl/StrandFlow.h | 2 ++ src/ripple/app/tx/impl/AMMCreate.cpp | 6 ++++++ src/ripple/app/tx/impl/CreateOffer.cpp | 3 +++ src/ripple/protocol/TER.h | 2 ++ src/ripple/protocol/impl/TER.cpp | 1 + 6 files changed, 16 insertions(+) diff --git a/src/ripple/app/paths/impl/Steps.h b/src/ripple/app/paths/impl/Steps.h index 1ae2273929d..99ed00376b2 100644 --- a/src/ripple/app/paths/impl/Steps.h +++ b/src/ripple/app/paths/impl/Steps.h @@ -445,6 +445,8 @@ toStrands( /// @cond INTERNAL template +requires (!(std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v)) struct StepImp : public Step { explicit StepImp() = default; diff --git a/src/ripple/app/paths/impl/StrandFlow.h b/src/ripple/app/paths/impl/StrandFlow.h index 7817251560f..d11f3197f55 100644 --- a/src/ripple/app/paths/impl/StrandFlow.h +++ b/src/ripple/app/paths/impl/StrandFlow.h @@ -551,6 +551,8 @@ class ActiveStrands sandbox */ template +requires (!(std::is_same_v || std::is_same_v || + std::is_same_v || std::is_same_v)) FlowResult flow( PaymentSandbox const& baseView, diff --git a/src/ripple/app/tx/impl/AMMCreate.cpp b/src/ripple/app/tx/impl/AMMCreate.cpp index 55b1126fcd0..38eaea7c95d 100644 --- a/src/ripple/app/tx/impl/AMMCreate.cpp +++ b/src/ripple/app/tx/impl/AMMCreate.cpp @@ -50,6 +50,12 @@ AMMCreate::preflight(PreflightContext const& ctx) auto const amount = ctx.tx[sfAmount]; auto const amount2 = ctx.tx[sfAmount2]; + if (amount.isMPT() || amount2.isIssue()) + { + JLOG(ctx.j.debug()) << "AMM Instance: MPT is not supported."; + return temMPT_NOT_SUPPORTED_BY_TX; + } + if (amount.issue() == amount2.issue()) { JLOG(ctx.j.debug()) diff --git a/src/ripple/app/tx/impl/CreateOffer.cpp b/src/ripple/app/tx/impl/CreateOffer.cpp index 17f7e2853db..a78e2c72731 100644 --- a/src/ripple/app/tx/impl/CreateOffer.cpp +++ b/src/ripple/app/tx/impl/CreateOffer.cpp @@ -83,6 +83,9 @@ CreateOffer::preflight(PreflightContext const& ctx) STAmount saTakerPays = tx[sfTakerPays]; STAmount saTakerGets = tx[sfTakerGets]; + if (saTakerPays.isMPT() || saTakerGets.isMPT()) + return temMPT_NOT_SUPPORTED_BY_TX; + if (!isLegalNet(saTakerPays) || !isLegalNet(saTakerGets)) return temBAD_AMOUNT; diff --git a/src/ripple/protocol/TER.h b/src/ripple/protocol/TER.h index 8e8d8097fc7..afc452fa73e 100644 --- a/src/ripple/protocol/TER.h +++ b/src/ripple/protocol/TER.h @@ -136,6 +136,8 @@ enum TEMcodes : TERUnderlyingType { temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT, temEMPTY_DID, + + temMPT_NOT_SUPPORTED_BY_TX }; //------------------------------------------------------------------------------ diff --git a/src/ripple/protocol/impl/TER.cpp b/src/ripple/protocol/impl/TER.cpp index 9eaf86f5f76..f33a8251d2a 100644 --- a/src/ripple/protocol/impl/TER.cpp +++ b/src/ripple/protocol/impl/TER.cpp @@ -183,6 +183,7 @@ transResults() MAKE_ERROR(temEMPTY_DID, "Malformed: No DID data provided."), MAKE_ERROR(temINVALID, "The transaction is ill-formed."), MAKE_ERROR(temINVALID_FLAG, "The transaction has an invalid flag."), + MAKE_ERROR(temMPT_NOT_SUPPORTED_BY_TX, "MPT is not supported by the transaction."), MAKE_ERROR(temREDUNDANT, "The transaction is redundant."), MAKE_ERROR(temRIPPLE_EMPTY, "PathSet with no paths."), MAKE_ERROR(temUNCERTAIN, "In process of determining result. Never returned."),