Skip to content

fix: Clamp VaultClawback to assetsAvailable for zero-amount clawback#6646

Merged
bthomee merged 14 commits intodevelopfrom
tapanito/fix-vault-clawback-clamp
Apr 6, 2026
Merged

fix: Clamp VaultClawback to assetsAvailable for zero-amount clawback#6646
bthomee merged 14 commits intodevelopfrom
tapanito/fix-vault-clawback-clamp

Conversation

@Tapanito
Copy link
Copy Markdown
Collaborator

@Tapanito Tapanito commented Mar 25, 2026

Zero-amount clawback (meaning "clawback all") returned early without clamping to assetsAvailable, allowing more assets to be recovered than available when there was an outstanding loan. Move the zero-amount path inside the try block so it shares the same clamping logic as non-zero clawback.

The old early-return behavior is retained behind an amendment gate for ledger replay compatibility.

High Level Overview of Change

Context of Change

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Zero-amount clawback (meaning "clawback all") returned early without
clamping to assetsAvailable, allowing more assets to be recovered than
available when there was an outstanding loan. Move the zero-amount
path inside the try block so it shares the same clamping logic as
non-zero clawback.

The old early-return behavior is retained behind a !fixAssortedFixes
gate for ledger replay compatibility.
@Tapanito Tapanito added Amendment AI Triage Bugs and fixes that have been triaged via AI initiatives labels Mar 25, 2026
- Add test for the pre-fixAssortedFixes legacy code path where
  zero-amount clawback does not clamp to assetsAvailable, verifying
  the transaction fails with tefINTERNAL for ledger replay fidelity
- Remove unused sharesBefore variable in zero-amount post-fix test
- Normalize env.balance() calls to use PrettyAsset directly
- Strengthen non-zero clawback share assertions from inequality
  checks to exact expected values matching the zero-amount test
@github-actions
Copy link
Copy Markdown

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

…_1_3

Resolve amendment conflict: drop placeholder fixAssortedFixes, adopt
fixSecurity3_1_3 (Supported::no) from develop. Update VaultClawback
and tests to reference the new amendment name and explicitly enable
it in the test Env since it is disabled by default.
@github-actions
Copy link
Copy Markdown

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@Tapanito Tapanito marked this pull request as ready for review March 26, 2026 09:47
@Tapanito
Copy link
Copy Markdown
Collaborator Author

/ai-review

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.

One low-severity naming collision in setupVault — see inline.

Review by Claude Opus 4.6 · Prompt: V12

Comment thread src/test/app/Vault_test.cpp
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.4%. Comparing base (02fa55d) to head (e663c10).
⚠️ Report is 7 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6646     +/-   ##
=========================================
- Coverage     81.4%   81.4%   -0.0%     
=========================================
  Files          999     999             
  Lines        74439   74446      +7     
  Branches      7564    7560      -4     
=========================================
- Hits         60621   60620      -1     
- Misses       13818   13826      +8     
Files with missing lines Coverage Δ
src/libxrpl/tx/transactors/vault/VaultClawback.cpp 97.8% <100.0%> (+0.1%) ⬆️

... and 2 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a VaultClawback edge case where a zero-amount clawback (“claw back all”) could recover more than sfAssetsAvailable when loans are outstanding, by ensuring the zero-amount path shares the same clamping logic as non-zero clawbacks (while retaining legacy behavior behind a feature gate for replay compatibility).

Changes:

  • Update VaultClawback::assetsToClawback to compute and clamp recovered assets for zero-amount clawback within the same guarded path as non-zero clawback.
  • Add regression tests covering zero-amount and non-zero clawback clamping when sfAssetsAvailable < sfAssetsTotal due to an outstanding loan.
  • Add a legacy-path test to validate pre-fix behavior when the relevant feature is disabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/test/app/Vault_test.cpp Adds regression and legacy-path tests for clamping behavior under outstanding loans; enables the relevant feature for the test environment.
src/libxrpl/tx/transactors/vault/VaultClawback.cpp Refactors zero-amount clawback handling so it is clamped to sfAssetsAvailable, preserving legacy behavior behind a feature flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/app/Vault_test.cpp Outdated
Comment thread src/libxrpl/tx/transactors/vault/VaultClawback.cpp
Comment thread src/test/app/Vault_test.cpp Outdated
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 - left minor comment

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.

Looks good.

Review by Claude Opus 4.6 · Prompt: V12

Remove unused sharesBefore variable and consolidate
BEAST_EXPECT + null-check into idiomatic if (!BEAST_EXPECT(..)) pattern.
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.

One null-dereference risk in setupVault — see inline comment.

Review by Claude Opus 4.6 · Prompt: V12

Comment thread src/test/app/Vault_test.cpp
The zero-amount clawback on an empty vault was hitting the
tecWRONG_ASSET ambiguity check when issuer == owner. Provide
an explicit share amount to test the intended tecNO_PERMISSION
path.
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.

Took a pass through this

Two issues flagged inline: a pre-patch inverted guard that silently skipped a negative-path security test, and a pre-fix zero-amount clawback bypass of the assetsAvailable cap. Both are addressed by this MR; comments request CI validation and an audit of analogous liquidation paths.


Review by ReviewBot 🤖

Review by Claude Opus 4.6 · Prompt: V12

Comment thread src/test/app/Vault_test.cpp
Comment thread src/libxrpl/tx/transactors/vault/VaultClawback.cpp
Comment thread src/test/app/Vault_test.cpp
Copy link
Copy Markdown
Contributor

@pratikmankawde pratikmankawde left a comment

Choose a reason for hiding this comment

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

Looks good. Left minor comments on missing tests.

Cover four boundary cases not previously tested:
- Partial clawback below assetsAvailable (no clamping needed)
- Clawback exactly equal to assetsAvailable (boundary)
- Clawback with zero assetsAvailable (fully borrowed vault)
- Non-1:1 share ratio (scale=1) with outstanding loan

Increase IOU/MPT funding from 1000 to 2000 to accommodate the
additional setupVault calls.
@mvadari
Copy link
Copy Markdown
Collaborator

mvadari commented Mar 31, 2026

@Tapanito how does this handle sfLockedAmount in MPTs?

@Tapanito
Copy link
Copy Markdown
Collaborator Author

Tapanito commented Apr 1, 2026

@mvadari good question, I added vault unit tests to ensure that sfLockedAmount is handled correctly.

@ximinez ximinez added this pull request to the merge queue Apr 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

All conflicts have been resolved. Assigned reviewers can now start or resume their review.

@Tapanito Tapanito changed the base branch from develop to ripple/staging-313 April 1, 2026 21:29
@Tapanito Tapanito changed the base branch from ripple/staging-313 to develop April 1, 2026 21:30
@bthomee bthomee added this pull request to the merge queue Apr 6, 2026
Merged via the queue into develop with commit 7d524a0 Apr 6, 2026
34 checks passed
@bthomee bthomee deleted the tapanito/fix-vault-clawback-clamp branch April 6, 2026 15:29
Kassaking7 pushed a commit to Kassaking7/rippled that referenced this pull request Apr 6, 2026
Kassaking7 pushed a commit to Kassaking7/rippled that referenced this pull request Apr 6, 2026
@ximinez ximinez modified the milestones: 3.1.3, 3.1.3 (develop) Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Triage Bugs and fixes that have been triaged via AI initiatives Amendment Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants