Skip to content

Commit

Permalink
Check AMM/OfferCreate for MPT amounts
Browse files Browse the repository at this point in the history
* Add type restriction to StepImp and flow()
* Add temMPT_NOT_SUPPORTED_BY_TX
  • Loading branch information
gregtatcam committed Feb 21, 2024
1 parent 987065e commit 90629de
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ripple/app/paths/impl/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ toStrands(

/// @cond INTERNAL
template <class TIn, class TOut, class TDerived>
requires (!(std::is_same_v<TIn, STAmount> || std::is_same_v<TIn, MPTAmount> ||
std::is_same_v<TOut, STAmount> || std::is_same_v<TOut, MPTAmount>))
struct StepImp : public Step
{
explicit StepImp() = default;
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/app/paths/impl/StrandFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ class ActiveStrands
sandbox
*/
template <class TInAmt, class TOutAmt>
requires (!(std::is_same_v<TInAmt, STAmount> || std::is_same_v<TInAmt, MPTAmount> ||
std::is_same_v<TOutAmt, STAmount> || std::is_same_v<TOutAmt, MPTAmount>))
FlowResult<TInAmt, TOutAmt>
flow(
PaymentSandbox const& baseView,
Expand Down
6 changes: 6 additions & 0 deletions src/ripple/app/tx/impl/AMMCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/app/tx/impl/CreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/ripple/protocol/TER.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ enum TEMcodes : TERUnderlyingType {
temXCHAIN_BRIDGE_BAD_REWARD_AMOUNT,

temEMPTY_DID,

temMPT_NOT_SUPPORTED_BY_TX
};

//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/impl/TER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down

0 comments on commit 90629de

Please sign in to comment.