Skip to content

Commit 8e11b9a

Browse files
Merge #6865: coinjoin/server: validate DSQUEUE denomination; remove redundant time stamp screens; tests: add denom and timestamp coverage
3739540 coinjoin/server: validate DSQUEUE denomination; remove redundant timestamp screens; rely on IsTimeOutOfBounds(); tests: add denom and timestamp coverage (pasta) Pull request description: ## 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 - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 3739540 kwvg: utACK 3739540 Tree-SHA512: 6e4fe3affcfb002f92044b99acff12f2d2bf03cb1c8dda62000875987145a4162cc7d397dc834ea4ecd883961d480672d079a0ad8d9c134b00c87de93c94d15d
2 parents 54e2588 + 3739540 commit 8e11b9a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/coinjoin/server.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ MessageProcessingResult CCoinJoinServer::ProcessDSQUEUE(NodeId from, CDataStream
117117
MessageProcessingResult ret{};
118118
ret.m_to_erase = CInv{MSG_DSQ, dsq.GetHash()};
119119

120+
// Validate denomination first
121+
if (!CoinJoin::IsValidDenomination(dsq.nDenom)) {
122+
LogPrint(BCLog::COINJOIN, "DSQUEUE -- invalid denomination %d from peer %d\n", dsq.nDenom, from);
123+
ret.m_error = MisbehavingError{10};
124+
return ret;
125+
}
126+
120127
if (dsq.masternodeOutpoint.IsNull() && dsq.m_protxHash.IsNull()) {
121128
ret.m_error = MisbehavingError{100};
122129
return ret;

src/test/coinjoin_queue_tests.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,46 @@ BOOST_AUTO_TEST_CASE(queue_hashes_and_equality)
5353
BOOST_CHECK(a.GetSignatureHash() == b.GetSignatureHash());
5454
}
5555

56+
BOOST_AUTO_TEST_CASE(queue_denomination_validation)
57+
{
58+
// Test that valid denominations pass
59+
int validDenom = CoinJoin::AmountToDenomination(CoinJoin::GetSmallestDenomination());
60+
BOOST_CHECK(CoinJoin::IsValidDenomination(validDenom));
61+
62+
// Test that invalid denominations fail
63+
BOOST_CHECK(!CoinJoin::IsValidDenomination(0)); // Zero
64+
BOOST_CHECK(!CoinJoin::IsValidDenomination(-1)); // Negative
65+
BOOST_CHECK(!CoinJoin::IsValidDenomination(999)); // Invalid value
66+
}
67+
68+
BOOST_AUTO_TEST_CASE(queue_timestamp_validation)
69+
{
70+
CCoinJoinQueue q;
71+
q.nDenom = CoinJoin::AmountToDenomination(CoinJoin::GetSmallestDenomination());
72+
q.masternodeOutpoint = COutPoint(uint256S("cc"), 3);
73+
q.m_protxHash = uint256::ONE;
74+
75+
int64_t current_time = GetAdjustedTime();
76+
77+
// Test valid timestamp (current time)
78+
q.nTime = current_time;
79+
BOOST_CHECK(!q.IsTimeOutOfBounds(current_time));
80+
81+
// Test timestamp slightly in future (within COINJOIN_QUEUE_TIMEOUT = 30)
82+
q.nTime = current_time + 15; // 15 seconds in future
83+
BOOST_CHECK(!q.IsTimeOutOfBounds(current_time));
84+
85+
// Test timestamp slightly in past (within COINJOIN_QUEUE_TIMEOUT = 30)
86+
q.nTime = current_time - 15; // 15 seconds ago
87+
BOOST_CHECK(!q.IsTimeOutOfBounds(current_time));
88+
89+
// Test timestamp too far in future (outside COINJOIN_QUEUE_TIMEOUT = 30)
90+
q.nTime = current_time + 60; // 60 seconds in future
91+
BOOST_CHECK(q.IsTimeOutOfBounds(current_time));
92+
93+
// Test timestamp too far in past (outside COINJOIN_QUEUE_TIMEOUT = 30)
94+
q.nTime = current_time - 60; // 60 seconds ago
95+
BOOST_CHECK(q.IsTimeOutOfBounds(current_time));
96+
}
97+
5698
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)