Skip to content

fix: Prevents overwriting a bool value in an invariant#6609

Merged
bthomee merged 32 commits into
developfrom
tapanito/invariant-bugfix
Apr 30, 2026
Merged

fix: Prevents overwriting a bool value in an invariant#6609
bthomee merged 32 commits into
developfrom
tapanito/invariant-bugfix

Conversation

@Tapanito

@Tapanito Tapanito commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes a bug where boolean results could be overwritten by multiple calls to visitEntry.

Backport for 3.1.x: #6961.

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)

@Tapanito Tapanito requested review from bthomee and mvadari March 20, 2026 16:46
@Tapanito Tapanito changed the title fix: prevents overwritting a bool value in an invariant fix: Prevents overwritting a bool value in an invariant Mar 20, 2026

@mvadari mvadari left a comment

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.

This needs an amendment

@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.1%. Comparing base (6407f0f) to head (72dc6af).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6609     +/-   ##
=========================================
- Coverage     82.1%   82.1%   -0.0%     
=========================================
  Files         1010    1010             
  Lines        76048   76064     +16     
  Branches      7384    7378      -6     
=========================================
+ Hits         62413   62424     +11     
- Misses       13635   13640      +5     
Files with missing lines Coverage Δ
include/xrpl/protocol/Rules.h 100.0% <ø> (ø)
src/libxrpl/protocol/Rules.cpp 98.0% <100.0%> (+0.2%) ⬆️
src/libxrpl/tx/invariants/InvariantCheck.cpp 95.7% <100.0%> (+0.1%) ⬆️

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

@bthomee

bthomee commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

/ai-review

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V12

@Tapanito Tapanito changed the title fix: Prevents overwritting a bool value in an invariant fix: Prevents overwriting a bool value in an invariant Mar 21, 2026
Three invariant checks used = instead of |= to accumulate their
boolean flag across multiple visited entries. A later "good" entry
could overwrite a violation detected by an earlier "bad" entry.

Gate the corrected |= behavior behind fixInvariantOverwrite to
preserve pre-amendment consensus. Each affected class tracks both
the fixed (|=) and legacy (=) values; finalize picks which to use
based on the amendment.

Affected invariants:
- NoZeroEscrow (bad_ for MPT locked vs outstanding)
- NoXRPTrustLines (xrpTrustLine_)
- NoDeepFreezeTrustLinesWithoutFreeze (deepFreezeWithoutFreeze_)
@Tapanito Tapanito requested a review from mvadari March 21, 2026 13:37
@Tapanito

Copy link
Copy Markdown
Collaborator Author

/ai-review

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

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.

Invariant detection vulnerable to boolean flag overwrite in legacy mode

Review by Claude Opus 4.6 · Prompt: V12

Comment thread include/xrpl/protocol/detail/features.macro Outdated
Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
Comment thread src/test/app/Invariants_test.cpp Outdated
Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
@mvadari mvadari added the AI Triage Bugs and fixes that have been triaged via AI initiatives label Mar 24, 2026
@github-actions

Copy link
Copy Markdown

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

Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
@github-actions

Copy link
Copy Markdown

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

@xrplf-ai-reviewer

Copy link
Copy Markdown
Contributor

⚠️ Review Error — The automated review failed to complete. Please re-trigger with /ai-review.

Error: Bad response code, expected 200: {'status_code': 400, 'headers': {':exception-type': 'internalServerException', ':content-type': 'application/json', ':message-type': 'exception'}, 'body': b'{"message"

Review by Claude Opus 4.6 · Prompt: v12

Comment thread src/libxrpl/tx/invariants/InvariantCheck.cpp Outdated
Comment thread src/test/app/Invariants_test.cpp Outdated
Comment thread src/test/app/Invariants_test.cpp Outdated
@github-actions

Copy link
Copy Markdown

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

ximinez added 2 commits April 21, 2026 14:23
…bugfix

* XRPLF/develop:
  chore: Enable clang-tidy modernize checks (6975)
  ci: Upload clang-tidy git diff (6983)
  fix: Add rounding to Vault invariants (6217) (6955)
  fix: Disallow MPTClearRequireAuth if is set (6712)
@github-actions

Copy link
Copy Markdown

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

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.


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

Comment thread src/test/app/Invariants_test.cpp Outdated
@bthomee

bthomee commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

@Tapanito please take a look at the Copilot review. If something needs changing, we should change that too in the staging branch. Otherwise, if Copilot is wrong please resolve the comment and indicate that this PR is ready to merge.

Both the NoXRPTrustLines and NoDeepFreeze regression tests constructed
a pair of keylets, hash-sorted them, and inserted two SLEs in that
order - duplicating the ordering logic. Extract this into a local
insertOrderedTrustLinePair helper so each test only configures what
distinguishes its bad/good entries.

Also fixes the NoDeepFreeze test, which previously chose between two
unrelated key pairings (key_A2_usd/key_A3_eur vs key_A3_usd/key_A2_eur)
based on a comparison only valid for the first pairing - the bad-first
visit ordering the test relied on was not actually guaranteed.

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@Tapanito Tapanito added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Apr 30, 2026

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

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.

No issues.

Review by Claude Opus 4.6 · Prompt: V15

@bthomee bthomee enabled auto-merge April 30, 2026 12:47
@bthomee bthomee added this pull request to the merge queue Apr 30, 2026
Merged via the queue into develop with commit 31180f9 Apr 30, 2026
3 checks passed
@bthomee bthomee deleted the tapanito/invariant-bugfix branch April 30, 2026 13:28
marek-foss-neti pushed a commit to marek-foss-neti/rippled that referenced this pull request May 5, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 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