From 8a2d0b1aa4e4b3bcbdf3cd841b6402a17a8bea37 Mon Sep 17 00:00:00 2001 From: Elliot Lee Date: Fri, 20 Feb 2026 02:22:41 +0900 Subject: [PATCH] refactor(AMMClawback): move tfClawTwoAssets check (#5201) Move tfClawTwoAssets check to preflight and return error temINVALID_FLAG --------- Co-authored-by: yinyiqian1 --- src/test/app/AMMClawback_test.cpp | 6 +++--- src/xrpld/app/tx/detail/AMMClawback.cpp | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/test/app/AMMClawback_test.cpp b/src/test/app/AMMClawback_test.cpp index 705a12740..c547a537b 100644 --- a/src/test/app/AMMClawback_test.cpp +++ b/src/test/app/AMMClawback_test.cpp @@ -303,13 +303,13 @@ class AMMClawback_test : public jtx::AMMTest // gw creates AMM pool of XRP/USD. AMM amm(env, gw, XRP(100), USD(100), ter(tesSUCCESS)); - // Return tecNO_PERMISSION because the issuer set tfClawTwoAssets, + // Return temINVALID_FLAG because the issuer set tfClawTwoAssets, // but the issuer only issues USD in the pool. The issuer is not // allowed to set tfClawTwoAssets flag if he did not issue both - // assts in the pool. + // assets in the pool. env(amm::ammClawback(gw, alice, USD, XRP, std::nullopt), txflags(tfClawTwoAssets), - ter(tecNO_PERMISSION)); + ter(temINVALID_FLAG)); } // Test clawing back XRP is being prohibited. diff --git a/src/xrpld/app/tx/detail/AMMClawback.cpp b/src/xrpld/app/tx/detail/AMMClawback.cpp index 64150ded6..cd1e3008e 100644 --- a/src/xrpld/app/tx/detail/AMMClawback.cpp +++ b/src/xrpld/app/tx/detail/AMMClawback.cpp @@ -42,7 +42,8 @@ AMMClawback::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; // LCOV_EXCL_LINE - if (ctx.tx.getFlags() & tfAMMClawbackMask) + auto const flags = ctx.tx.getFlags(); + if (flags & tfAMMClawbackMask) return temINVALID_FLAG; AccountID const issuer = ctx.tx[sfAccount]; @@ -57,10 +58,19 @@ AMMClawback::preflight(PreflightContext const& ctx) std::optional const clawAmount = ctx.tx[~sfAmount]; auto const asset = ctx.tx[sfAsset]; + auto const asset2 = ctx.tx[sfAsset2]; if (isXRP(asset)) return temMALFORMED; + if (flags & tfClawTwoAssets && asset.account != asset2.account) + { + JLOG(ctx.j.trace()) + << "AMMClawback: tfClawTwoAssets can only be enabled when two " + "assets in the AMM pool are both issued by the issuer"; + return temINVALID_FLAG; + } + if (asset.account != issuer) { JLOG(ctx.j.trace()) << "AMMClawback: Asset's account does not " @@ -108,15 +118,6 @@ AMMClawback::preclaim(PreclaimContext const& ctx) (issuerFlagsIn & lsfNoFreeze)) return tecNO_PERMISSION; - auto const flags = ctx.tx.getFlags(); - if (flags & tfClawTwoAssets && asset.account != asset2.account) - { - JLOG(ctx.j.trace()) - << "AMMClawback: tfClawTwoAssets can only be enabled when two " - "assets in the AMM pool are both issued by the issuer"; - return tecNO_PERMISSION; - } - return tesSUCCESS; }