Skip to content

fix: Add MPT/DEX assorted fixes#6855

Open
gregtatcam wants to merge 15 commits intodevelopfrom
gregtatcam/mpt/assorted-fixes-dev
Open

fix: Add MPT/DEX assorted fixes#6855
gregtatcam wants to merge 15 commits intodevelopfrom
gregtatcam/mpt/assorted-fixes-dev

Conversation

@gregtatcam
Copy link
Copy Markdown
Collaborator

High Level Overview of Change

  • ValidMPTTransfer, check for valid MPTLocked, MPTCanTrade, MPTCanTransfer.
  • Replace canTrade with canTransfer in CheckCreate/Cash (Check is not DEX tx).
  • Change tecFROZEN to tecLOCKED for locked MPT.
  • Replace checkMPTTxAllowed() with canMPTTradeAndTransfer().
  • Fix double adjustOwnerCount() in AMMWithdraw.
  • Extend the unit-tests.

@gregtatcam gregtatcam requested review from shawnxie999 and vlntb April 10, 2026 18:37
Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed canTrade() creation-time guard needs audit — see inline comment at line 167.

Review by Claude Opus 4.6 · Prompt: V14

}

return canTrade(ctx.view, ctx.tx[sfSendMax].asset());
return tesSUCCESS;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed canTrade() check replaced with unconditional success — verify IOU tradeability is still enforced elsewhere at creation time.

The old code returned canTrade(ctx.view, ctx.tx[sfSendMax].asset()) here, which gated check creation on asset tradeability. The MPT path now has an explicit canTransfer guard (lines 148–153), but the IOU visitor branch (lines 103–135) should be audited to confirm an equivalent check exists. Dropping this shifts all IOU trade enforcement to cash time, creating a single point of failure if CheckCash is ever bypassed or misconfigured.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an issue. canTrade() was added for MPT/DEX feature. canTrade() returns tesSUCCESS for Issue. Since CheckCreate is not a DEX transaction, this logic is reverted to pre MPT/DEX code-base; i.e., return tesSUCCESS. canTransfer() is added only for MPTIssue to check if MPTCanTransfer flag is enabled.

Comment thread src/libxrpl/ledger/helpers/MPTokenHelpers.cpp
Comment thread src/libxrpl/tx/invariants/MPTInvariant.cpp Outdated
// Check once: if any involved account is frozen, the whole
// issuance transfer is considered frozen. Only need to check for
// frozen if there is a transfer of funds.
if (!frozen && isFrozen(view, account, MPTIssue{mptID}))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we possibly want to include requireAuth as well?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. This is going to be a check for the receivers only, right?

Copy link
Copy Markdown
Collaborator

@shawnxie999 shawnxie999 Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also make sense to check for sender as well? Both should have auth when transferring

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with send is that the send object could be deleted, in which case requireAuth fails. I can call it with WeakAuth, but it still might fail. The only thing that I can do if it's deleted is to check for MPTRequireAuth flag on the MPTokenIssuance and if set then check MPTAuthorized flag on before object. If the latter is not set then the invariant fails.

Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile error (undeclared txnType) flagged in MPTInvariant.cpp; potential missing trading-restriction enforcement in CheckCreate.cpp — see inline comments.

Review by Claude Opus 4.6 · Prompt: V14

// DEX transactions (AMM[Create,Deposit,Withdraw], cross-currency payments, offer creates) are
// subject to the MPTCanTrade flag in addition to the standard transfer rules.
// A payment is only DEX if it is a cross-currency payment.
auto const isDEX = [&tx, &txnType] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txnType is captured by reference but never declared in scope — won't compile. Declare it before the lambda:

    auto const txnType = tx.getTxnType();
    auto const isDEX = [&tx, &txnType] {

}

return canTrade(ctx.view, ctx.tx[sfSendMax].asset());
return tesSUCCESS;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unconditional tesSUCCESS replaces the prior canTrade call — confirm IOU trading restrictions are enforced elsewhere.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct change.

Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked through this one

Potential validation gap at line 167 — the unconditional canTrade call for all asset types was replaced with tesSUCCESS; the IOU path may be missing an equivalent check. See inline.


Review by ReviewBot 🤖

Review by Claude Opus 4.6 · Prompt: V14

}

return canTrade(ctx.view, ctx.tx[sfSendMax].asset());
return tesSUCCESS;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canTrade was previously called unconditionally for all asset types — confirm it was a no-op for IOU assets, or add an IOU branch validation to avoid silently dropping that check.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 99.21875% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.6%. Comparing base (6a0ce46) to head (e85f010).
⚠️ Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
src/libxrpl/tx/invariants/MPTInvariant.cpp 98.2% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6855     +/-   ##
=========================================
- Coverage     81.6%   81.6%   -0.0%     
=========================================
  Files         1010    1010             
  Lines        75973   76030     +57     
  Branches      7610    7604      -6     
=========================================
+ Hits         61993   62038     +45     
- Misses       13980   13992     +12     
Files with missing lines Coverage Δ
include/xrpl/tx/invariants/InvariantCheck.h 100.0% <ø> (ø)
src/libxrpl/ledger/helpers/MPTokenHelpers.cpp 96.1% <100.0%> (+<0.1%) ⬆️
src/libxrpl/ledger/helpers/TokenHelpers.cpp 95.4% <100.0%> (+0.1%) ⬆️
src/libxrpl/tx/transactors/check/CheckCash.cpp 90.6% <100.0%> (+<0.1%) ⬆️
src/libxrpl/tx/transactors/check/CheckCreate.cpp 99.1% <100.0%> (+0.1%) ⬆️
src/libxrpl/tx/transactors/dex/AMMClawback.cpp 98.1% <100.0%> (+2.6%) ⬆️
src/libxrpl/tx/transactors/dex/AMMCreate.cpp 90.9% <100.0%> (+0.1%) ⬆️
src/libxrpl/tx/transactors/dex/AMMDeposit.cpp 96.4% <100.0%> (+0.3%) ⬆️
src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp 94.3% <100.0%> (+0.2%) ⬆️
src/libxrpl/tx/transactors/dex/OfferCreate.cpp 93.3% <100.0%> (+0.1%) ⬆️
... and 1 more

... and 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ReadView const& view,
beast::Journal const& j)
{
// AMMClawback is called by the issuer, so freeze restrictions do not apply.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - this comment can probably be removed/changed

Comment on lines +474 to +477
if (!frozen && isFrozen(view, account, MPTIssue{mptID}))
{
frozen = true;
}
Copy link
Copy Markdown
Collaborator

@shawnxie999 shawnxie999 Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we combine the auth checks with the freeze logic here? That way we wouldn’t need separate frozen and reqAuth booleans—we could instead use a single illegalTransfer boolean that covers both cases. (it probably doesn't hurt to check auth for the sender)

* Combine frozen and reqAuth.
* Check senders and receivers for reqAuth.
Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - clean fixes across the board.

Review by Claude Opus 4.6 · Prompt: V14

Copy link
Copy Markdown
Collaborator

@shawnxie999 shawnxie999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - solid fixes.

Review by Claude Opus 4.6 · Prompt: V15

Copy link
Copy Markdown
Contributor

@xrplf-ai-reviewer xrplf-ai-reviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - solid fixes across MPT/DEX handling.

Review by Claude Opus 4.6 · Prompt: V15

@github-actions
Copy link
Copy Markdown

This PR has conflicts, please resolve them in order for the PR to be reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants