Skip to content

coinjoin/server: validate DSQUEUE denomination; remove redundant time stamp screens; tests: add denom and timestamp coverage - #6865

Merged
PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:pr/coinjoin-dsq-validate
Oct 3, 2025
Merged

PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:pr/coinjoin-dsq-validate

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Ensure we believe that a DSQ is fully valid before we broadcast it further; add unit tests

What was done?

Describe your changes in detail

How Has This Been Tested?

Please describe in detail how you tested your changes.

Include details of your testing environment, and the tests you ran
to see how your change affects other areas of the code, etc.

Breaking Changes

Please describe any breaking changes your code introduces

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

…stamp screens; rely on IsTimeOutOfBounds(); tests: add denom and timestamp coverage
@PastaPastaPasta PastaPastaPasta added this to the 23 milestone Sep 30, 2025
@github-actions

Copy link
Copy Markdown

✅ No Merge Conflicts Detected

This PR currently has no conflicts with other open PRs.

@coderabbitai

coderabbitai Bot commented Sep 30, 2025

Copy link
Copy Markdown

Walkthrough

A pre-check was added in src/coinjoin/server.cpp within ProcessDSQUEUE to validate dsq.nDenom using CoinJoin::IsValidDenomination. On invalid input, it logs an "invalid denomination" message with the peer id, sets ret.m_error to MisbehavingError{10}, and returns early. Existing validations remain unchanged. Two unit tests were added: queue_denomination_validation (valid/invalid denomination cases) and queue_timestamp_validation (IsTimeOutOfBounds with current, ±15s, and ±60s, assuming COINJOIN_QUEUE_TIMEOUT=30). No public/exported entity changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Single, focused input-validation addition plus two straightforward tests; low heterogeneity and logic density.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title accurately lists the key changes—adding DSQUEUE denomination validation, removing redundant timestamp checks, and extending test coverage—so it clearly reflects the scope of the PR even though it is somewhat lengthy.
Description Check ✅ Passed The description’s opening section clearly states the intent to validate DSQ messages and add unit tests, which aligns with the actual code changes, so it is on-topic and satisfies the lenient criteria for this check.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/coinjoin_queue_tests.cpp (1)

68-96: Reference COINJOIN_QUEUE_TIMEOUT directly in the assertions.

Hard-coding 15 and 60 seconds will go stale if COINJOIN_QUEUE_TIMEOUT ever changes. Drive the checks off the constant to keep the test aligned with production values.

-    q.nTime = current_time + 15; // 15 seconds in future
+    q.nTime = current_time + (COINJOIN_QUEUE_TIMEOUT - 1);
@@
-    q.nTime = current_time - 15; // 15 seconds ago
+    q.nTime = current_time - (COINJOIN_QUEUE_TIMEOUT - 1);
@@
-    q.nTime = current_time + 60; // 60 seconds in future
+    q.nTime = current_time + (COINJOIN_QUEUE_TIMEOUT + 1);
@@
-    q.nTime = current_time - 60; // 60 seconds ago
+    q.nTime = current_time - (COINJOIN_QUEUE_TIMEOUT + 1);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54e2588 and 3739540.

📒 Files selected for processing (2)
  • src/coinjoin/server.cpp (1 hunks)
  • src/test/coinjoin_queue_tests.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{cpp,h,cc,cxx,hpp}: Dash Core C++ codebase must be written in C++20 and require at least Clang 16 or GCC 11.1
Dash uses unordered_lru_cache for efficient caching with LRU eviction

Files:

  • src/test/coinjoin_queue_tests.cpp
  • src/coinjoin/server.cpp
src/{test,wallet/test,qt/test}/**/*.{cpp,h,cc,cxx,hpp}

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests for C++ code should be placed in src/test/, src/wallet/test/, or src/qt/test/ and use Boost::Test or Qt 5 for GUI tests

Files:

  • src/test/coinjoin_queue_tests.cpp
🧬 Code graph analysis (1)
src/test/coinjoin_queue_tests.cpp (1)
src/node/interfaces.cpp (1)
  • GetSmallestDenomination (387-390)
🪛 GitHub Actions: Clang Diff Format Check
src/test/coinjoin_queue_tests.cpp

[error] 60-60: Clang format differences found between before/after formatting. See diff_output.txt for details; please run clang-format to fix formatting.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: mac-build / Build source
  • GitHub Check: win64-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: Lint / Run linters
🔇 Additional comments (2)
src/coinjoin/server.cpp (1)

120-125: Denomination guard is a solid early exit.

Thanks for validating dsq.nDenom up front and assigning a misbehavior score before doing any heavier work. This closes a validation gap without disturbing the rest of the flow.

src/test/coinjoin_queue_tests.cpp (1)

56-66: Re-run clang-format on src/test/coinjoin_queue_tests.cpp
CI has detected formatting deviations in this file, but clang-format isn’t available in this environment. Please run clang-format locally on src/test/coinjoin_queue_tests.cpp and commit the updated formatting so the CI check passes.

@UdjinM6 UdjinM6 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

utACK 3739540

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

utACK 3739540

BOOST_CHECK(!CoinJoin::IsValidDenomination(999)); // Invalid value
}

BOOST_AUTO_TEST_CASE(queue_timestamp_validation)

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: should've been a separate commit

@PastaPastaPasta
PastaPastaPasta merged commit 8e11b9a into dashpay:develop Oct 3, 2025
@PastaPastaPasta
PastaPastaPasta deleted the pr/coinjoin-dsq-validate branch October 3, 2025 14:55
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 11, 2026
The server started rejecting DSQUEUE messages with an invalid
denomination (misbehaving 10) in dashpay#6865, but the wallet-side handler
never got that check. A client accepted a signed DSQUEUE with a bogus
denomination into its queue, where it matched no session and only took
up a slot.

Validate client DSQUEUEs with CoinJoin::ValidateDSQueue, the checks the
server already uses, so the client rejects such queues with the same
penalty. The client keeps its own duplicate tracking under
cs_ProcessDSQueue, the ready-queue submission and the mixing-rate
threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 13, 2026
The server started rejecting DSQUEUE messages with an invalid
denomination (misbehaving 10) in dashpay#6865, but the wallet-side handler
never got that check. A client accepted a signed DSQUEUE with a bogus
denomination into its queue, where it matched no session and only took
up a slot.

Validate client DSQUEUEs with CoinJoin::ValidateDSQueue, the checks the
server already uses, so the client rejects such queues with the same
penalty. The client keeps its own duplicate tracking under
cs_ProcessDSQueue, the ready-queue submission and the mixing-rate
threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PastaPastaPasta added a commit that referenced this pull request Nov 14, 2026
…nts by sharing the server validation

79defda fix(coinjoin): validate DSQUEUE denomination on mixing clients (pasta)
8957837 refactor(coinjoin): extract shared DSQUEUE validation from the server (pasta)

Pull request description:

  ## Issue being fixed or feature implemented

  Mixing clients accept a signed DSQUEUE with an invalid denomination into their queue. Masternodes have rejected such queues (misbehaving 10) since #6865, but that check was added only to the server's DSQUEUE handler. The wallet-side handler keeps its own copy of the same validation, and the two copies have drifted apart. The bogus queue matches no session, but it takes up a queue slot, and it counts toward the masternode's mixing-rate threshold.

  ## What was done?

  - **refactor:** moved the DSQUEUE checks that both roles share into `CoinJoin::ValidateDSQueue` (`src/coinjoin/coinjoin.{h,cpp}`):
    - denomination
    - masternode lookup by protx
    - time bounds
    - collateral lookup
    - operator signature

    It returns the signing masternode and the score to penalize the peer with. `CCoinJoinServer::ProcessDSQUEUE` now uses it. The server's checks, order and penalties are unchanged.
  - **fix:** `CJWalletManagerImpl::ProcessDSQueue` uses the same function, so clients now reject invalid denominations with the same penalty as the server (10).

  The duplicate check is passed in as a callback. Each role keeps its own queue storage and locking, and duplicates are still dropped before the BLS signature is verified. Each caller applies the returned penalty its own way (`PeerMisbehaving` on the server, `MisbehavingError` on the client).

  Remaining differences between the two handlers, kept on purpose and not changed here:
  - **Mixing-rate threshold:** the server applies it, and `AllowMixing`, only to non-ready queues, and never stores or relays ready queues. The client first tries to submit to its session for a ready queue. If no session is waiting on that masternode, it applies the threshold and stores the ready queue like any other. So on clients, ready queues count toward the threshold. This is long-standing behavior. It may deserve its own look, but this PR doesn't change it.
  - **Duplicate tracking:** the server uses `TryCheckDuplicate` under `TRY_LOCK` and drops the message silently on lock contention. The client takes a blocking lock, checks `HasQueue(hash)` then `HasQueueFromMasternode`, and holds `cs_ProcessDSQueue` until it has stored the queue.
  - **After validation:** the server relays the queue. The client marks queues it already joined as tried.

  Side effects of the client change:
  - The client penalizes the peer that relayed the queue, as the server already does. Only masternodes relay DSQUEUEs, and since v23.0.0 they drop invalid denominations before relaying. A masternode running something older than v23.0.0 could relay a bad-denomination queue that another masternode signed, and get scored 10. The server has behaved this way since #6865.
  - A ready queue with an invalid denomination is now dropped before the client tries to submit to its session.

  `masternodeOutpoint` is not serialized, so in practice every DSQUEUE is resolved through `m_protxHash`. The collateral lookup and protx fill-in after it can't fail for network input. I kept them so the server code moves over line for line.

  ## How Has This Been Tested?

  - New unit test `coinjoin_queue_tests/client_rejects_invalid_queues`:
    - It registers a masternode on a DIP3 regtest chain and feeds signed DSQUEUEs through `CJWalletManager::processMessage`.
    - It checks the returned penalty and whether the queue was stored for: an invalid denomination (non-ready and ready queue), a missing protx, an unknown protx and a wrong signer.
    - A valid queue from the same masternode is the accepted control.
    - Without the client change, the invalid-denomination row fails: the queue is stored and no penalty is returned.
  - Both commits build on their own, and `coinjoin_queue_tests` passes on each.
  - Also run on Linux x86_64 with `--enable-debug`:
    - unit tests: `coinjoin_queue_tests`, `coinjoin_inouts_tests`, `coinjoin_dstxmanager_tests`, `coinjoin_tests`
    - functional tests: `rpc_coinjoin.py`, `p2p_dstx.py`
    - lints: `lint-circular-dependencies.py`, `lint-includes.py`, `lint-whitespace.py`

  ## Breaking Changes

  None.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: b34ea65f1977b646253eba334a9b4cbc638869070589f1fac57d3c621b1a149a2d421b952087044dbd087d5fd4189ae57128eeea846174492a6c1410c7e6a4da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants