From c3aae7b81d6d011c31ab7328bbf1a8ee2759eb52 Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Fri, 26 Jun 2026 13:19:42 +0200 Subject: [PATCH] AI feedback --- include/xrpl/ledger/helpers/TokenHelpers.h | 75 ++++++++++++--------- src/libxrpl/ledger/helpers/TokenHelpers.cpp | 6 +- src/test/jtx/Env.h | 7 ++ src/test/jtx/utility.h | 9 --- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/include/xrpl/ledger/helpers/TokenHelpers.h b/include/xrpl/ledger/helpers/TokenHelpers.h index 16d47b06fc..0c9871cd76 100644 --- a/include/xrpl/ledger/helpers/TokenHelpers.h +++ b/include/xrpl/ledger/helpers/TokenHelpers.h @@ -132,32 +132,36 @@ checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset); /** - * Checks freeze compliance for withdrawing an asset from a pseudo-account - * (e.g. Vault, AMM, LoanBroker) to a destination account. + * Checks freeze compliance for withdrawing an asset from a pseudo-account (e.g. Vault, AMM, + * LoanBroker) to a destination account. * - * Asserts that sourceAcct is a pseudo-account. + * Asserts that sourceAcct is a pseudo-account and that submitterAcct and dstAcct are not. * - * Issuer exemption: returns tesSUCCESS immediately when dstAcct is the asset - * issuer — the issuer can always receive their own token, even when the pool - * is frozen. Callers that need to block withdrawals from a frozen pool even - * for the issuer (e.g. because the pool math cannot handle it) must check - * checkFrozen(sourceAcct, asset) separately before calling this function. + * Issuer exemption: returns tesSUCCESS immediately when dstAcct is the asset issuer — the issuer + * can always receive their own token, even when the pool is frozen. Callers that need to block + * withdrawals from a frozen pool even for the issuer (e.g. because the pool math cannot handle it) + * must check checkFrozen(sourceAcct, asset) separately before calling this function. * * Otherwise checks, in order: - * 1. checkFrozen(sourceAcct, asset) — the pseudo-account's trustline / - * global freeze must not block sending. - * 1a. For MPT assets: isVaultPseudoAccountFrozen(sourceAcct, asset) — - * the pseudo-account's vault share must not be transitively frozen - * via its underlying asset. - * 2. checkFrozen(submitterAcct, asset) — skipped when submitter == dst - * (self-withdrawal); a regular freeze should not prevent recovering - * one's own funds. - * 3. checkDeepFrozen(dstAcct, asset) — the destination must not be - * deep-frozen (cannot receive under any circumstance). + * 1. If the asset is globally frozen the remaining checks are redundant. + * 2. For MPT shares: The pseudo-account's vault share must not be transitively frozen via its + * underlying asset. + * 3. The pseudo-account's trustline / MPToken must not be frozen for sending. + * 4. Skipped when submitter == dst (self-withdrawal); a regular freeze should not prevent + * recovering one's own funds. + * 5. The destination must not be deep-frozen (cannot receive under any circumstance). * - * For IOUs a regular individual freeze on the withdrawer does NOT block - * self-withdrawal; only deep freeze does. For MPTs "locked" is equivalent - * to deep-frozen, so locked MPT holders are always blocked. + * For IOUs a regular individual freeze on the withdrawer does NOT block self-withdrawal; only deep + * freeze does. For MPTs "locked" is equivalent to deep-frozen, so locked MPT holders are always + * blocked. + * + * @param view Ledger view to read freeze state from. + * @param srcAcct Pseudo-account the funds are withdrawn from (sender). + * @param submitterAcct Account that submitted the withdrawal transaction. + * @param dstAcct Account receiving the withdrawn funds. + * @param asset Asset being withdrawn. + * @return tesSUCCESS if the withdrawal is permitted, otherwise a freeze + * result (tecFROZEN for IOUs, tecLOCKED for MPTs). */ [[nodiscard]] TER checkWithdrawFreeze( @@ -168,21 +172,26 @@ checkWithdrawFreeze( Asset const& asset); /** - * Checks freeze compliance for depositing an asset into a pseudo-account - * (e.g. Vault, AMM, LoanBroker). + * Checks freeze compliance for depositing an asset into a pseudo-account (e.g. Vault, AMM, + * LoanBroker). * - * Asserts that dstAcct is a pseudo-account. * * Checks, in order: - * 1. checkFrozen(srcAcct, asset) — the depositor must not be frozen - * (global or individual) for the asset. - * 1a. For MPT assets: isVaultPseudoAccountFrozen(dstAcct, asset) — - * the pseudo-account's vault share must not be transitively frozen - * via its underlying asset. - * 2. checkFrozen(dstAcct, asset) — the pseudo-account must not be - * frozen for the asset. Unlike regular accounts, pseudo-accounts - * cannot receive deposits under a regular freeze because the - * deposited funds could not later be withdrawn. + * 1. If the asset is globally frozen the remaining checks are redundant. + * 2. For MPT shares: the pseudo-account's vault share must not be transitively frozen via its + * underlying asset (returns tecLOCKED). + * 3. The depositor must not be individually frozen. Skipped when srcAcct is the asset issuer, + * since the issuer can always send its own asset. + * 4. The pseudo-account must not be individually frozen for the asset. Unlike regular accounts, + * pseudo-accounts cannot receive deposits under a regular freeze because the deposited funds + * could not later be withdrawn. + * + * @param view Ledger view to read freeze state from. + * @param srcAcct Depositor sending the funds. + * @param dstAcct Pseudo-account receiving the deposit. + * @param asset Asset being deposited. + * @return tesSUCCESS if the deposit is permitted, otherwise a freeze result + * (tecFROZEN for IOUs, tecLOCKED for MPTs). */ [[nodiscard]] TER checkDepositFreeze( diff --git a/src/libxrpl/ledger/helpers/TokenHelpers.cpp b/src/libxrpl/ledger/helpers/TokenHelpers.cpp index b242c0953c..cc9e156df2 100644 --- a/src/libxrpl/ledger/helpers/TokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/TokenHelpers.cpp @@ -220,14 +220,10 @@ checkDepositFreeze( !isPseudoAccount(view, srcAcct), "xrpl::checkDepositFreeze : source is not a pseudo-account"); - // An Issuer cannot deposit when: - // 1. Asset is globally frozen - // 2. The trustline/mptoken of the pseudo-account is frozen - if (auto const ret = checkGlobalFrozen(view, asset); !isTesSuccess(ret)) return ret; - // Special case for shares - check if the shares (and the transitive asset) is not frozen + // Special case for shares - check if the shares and the transitive asset is not frozen if (asset.holds() && isVaultPseudoAccountFrozen(view, dstAcct, asset.get(), 0)) { diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 90a73c3350..aca6074c4a 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -96,6 +96,13 @@ testableAmendments() return kIds; } +/** + * Returns all 2^N permutations of a seed FeatureBitset with each subset of + * the given features excluded. The seed is included as the first element. + * + * Useful for running a test over every combination of optional amendments + * so that each case is exercised both with and without each feature. + */ inline std::vector amendmentCombinations(std::initializer_list features, FeatureBitset seed) { diff --git a/src/test/jtx/utility.h b/src/test/jtx/utility.h index 597e006575..5cf6261f37 100644 --- a/src/test/jtx/utility.h +++ b/src/test/jtx/utility.h @@ -54,13 +54,4 @@ fillSeq(json::Value& jv, ReadView const& view); /** Given an xrpld unit test rpc command, return the corresponding JSON. */ json::Value cmdToJSONRPC(std::vector const& args, beast::Journal j, unsigned int apiVersion); - -/** - * Returns all 2^N permutations of a seed FeatureBitset with each subset of - * the given features excluded. The seed is included as the first element. - * - * Useful for running a test over every combination of optional amendments - * so that each case is exercised both with and without each feature. - */ - } // namespace xrpl::test::jtx