From a28a76794db3966293fd840d20dc820bee5eae54 Mon Sep 17 00:00:00 2001 From: Shawn Xie Date: Fri, 6 Sep 2024 13:20:42 -0400 Subject: [PATCH 1/3] add issuance not found code --- include/xrpl/protocol/TER.h | 1 + src/libxrpl/protocol/TER.cpp | 1 + src/test/app/MPToken_test.cpp | 18 ++++++++++++++++++ src/xrpld/ledger/detail/View.cpp | 4 ++-- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/xrpl/protocol/TER.h b/include/xrpl/protocol/TER.h index 605e7f6073a..b4dcd6ff875 100644 --- a/include/xrpl/protocol/TER.h +++ b/include/xrpl/protocol/TER.h @@ -345,6 +345,7 @@ enum TECcodes : TERUnderlyingType { tecMPT_MAX_AMOUNT_EXCEEDED = 193, tecMPT_LOCKED = 194, tecMPT_NOT_SUPPORTED = 195, + tecMPT_ISSUANCE_NOT_FOUND = 196 }; //------------------------------------------------------------------------------ diff --git a/src/libxrpl/protocol/TER.cpp b/src/libxrpl/protocol/TER.cpp index 950163e3aa5..1803d836625 100644 --- a/src/libxrpl/protocol/TER.cpp +++ b/src/libxrpl/protocol/TER.cpp @@ -119,6 +119,7 @@ transResults() MAKE_ERROR(tecMPTOKEN_EXISTS, "The account already owns the MPToken object."), MAKE_ERROR(tecMPT_MAX_AMOUNT_EXCEEDED, "The MPT's maximum amount is exceeded."), MAKE_ERROR(tecMPT_LOCKED, "MPT is locked by the issuer."), + MAKE_ERROR(tecMPT_ISSUANCE_NOT_FOUND, "The MPTokenIssuance object is not found"), MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."), MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."), diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index d534b24320a..00bded0ab64 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -980,6 +980,24 @@ class MPToken_test : public beast::unit_test::suite jrr[jss::result][jss::error_message] == "Field 'build_path' not allowed in this context."); } + + // Issuer fails trying to send fund after issuance was destroyed + { + Env env{*this, features}; + + MPTTester mptAlice(env, alice, {.holders = {&bob}}); + + mptAlice.create({.ownerCount = 1, .holderCount = 0}); + + mptAlice.authorize({.account = &bob}); + + // alice destroys issuance + mptAlice.destroy({.ownerCount = 0}); + + // alice tries to send bob fund after issuance is destroy, should + // fail. + mptAlice.pay(alice, bob, 100, tecMPT_ISSUANCE_NOT_FOUND); + } } void diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index 22a8249758e..55a44c6538c 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -1875,7 +1875,7 @@ rippleCredit( view.update(sle); } else - return tecINTERNAL; + return tecMPT_ISSUANCE_NOT_FOUND; } else { @@ -1914,7 +1914,7 @@ rippleCredit( return tecINSUFFICIENT_FUNDS; } else - return tecINTERNAL; + return tecMPT_ISSUANCE_NOT_FOUND; } else { From f5ed98b412c2d4859be9367690d1904b9c5b8ee0 Mon Sep 17 00:00:00 2001 From: Shawn Xie Date: Mon, 9 Sep 2024 10:13:45 -0400 Subject: [PATCH 2/3] add issuance check to start of func --- src/test/app/MPToken_test.cpp | 17 +++++++++++++++++ src/xrpld/ledger/detail/View.cpp | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index 00bded0ab64..0cac8811366 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -998,6 +998,23 @@ class MPToken_test : public beast::unit_test::suite // fail. mptAlice.pay(alice, bob, 100, tecMPT_ISSUANCE_NOT_FOUND); } + + // Issuer fails trying to send to some who doesn't own MPT for a + // issuance that was destroyed + { + Env env{*this, features}; + + MPTTester mptAlice(env, alice, {.holders = {&bob}}); + + mptAlice.create({.ownerCount = 1, .holderCount = 0}); + + // alice destroys issuance + mptAlice.destroy({.ownerCount = 0}); + + // alice tries to send bob who doesn't own the MPT after issuance is + // destroyed, it should fail + mptAlice.pay(alice, bob, 100, tecMPT_ISSUANCE_NOT_FOUND); + } } void diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index 55a44c6538c..c0c9ee50384 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -1860,6 +1860,10 @@ rippleCredit( { auto const mptID = keylet::mptIssuance(saAmount.issue().getMptID()); auto const issuer = saAmount.getIssuer(); + + if (!view.peek(mptID)) + return tecMPT_ISSUANCE_NOT_FOUND; + if (uSenderID == issuer) { if (auto sle = view.peek(mptID)) @@ -1875,7 +1879,7 @@ rippleCredit( view.update(sle); } else - return tecMPT_ISSUANCE_NOT_FOUND; + return tecINTERNAL; } else { @@ -1914,7 +1918,7 @@ rippleCredit( return tecINSUFFICIENT_FUNDS; } else - return tecMPT_ISSUANCE_NOT_FOUND; + return tecINTERNAL; } else { From af86095c464496223a1251b430e4b49d6b40de1f Mon Sep 17 00:00:00 2001 From: Shawn Xie Date: Mon, 9 Sep 2024 10:15:37 -0400 Subject: [PATCH 3/3] uses `exists()` --- src/xrpld/ledger/detail/View.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index c0c9ee50384..3a422c0c88a 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -1861,7 +1861,7 @@ rippleCredit( auto const mptID = keylet::mptIssuance(saAmount.issue().getMptID()); auto const issuer = saAmount.getIssuer(); - if (!view.peek(mptID)) + if (!view.exists(mptID)) return tecMPT_ISSUANCE_NOT_FOUND; if (uSenderID == issuer)