Skip to content

Commit 5f46a7d

Browse files
author
MarcoFalke
committed
transaction_tests: Be more strict checking dust
* Don't allow off-by-one or more * Make clear dust is coupled with minRelayTxFee * Check rounding for odd values
1 parent 503ff6e commit 5f46a7d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/primitives/transaction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class CTxOut
143143
// to spend something, then we consider it dust.
144144
// A typical spendable txout is 34 bytes big, and will
145145
// need a CTxIn of at least 148 bytes to spend:
146-
// so dust is a spendable txout less than 546 satoshis
147-
// with default minRelayTxFee.
146+
// so dust is a spendable txout less than
147+
// 546*minRelayTxFee/1000 (in satoshis)
148148
if (scriptPubKey.IsUnspendable())
149149
return 0;
150150

src/test/transaction_tests.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,26 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
342342
string reason;
343343
BOOST_CHECK(IsStandardTx(t, reason));
344344

345-
t.vout[0].nValue = 501; // dust
345+
// Check dust with default relay fee:
346+
CAmount nDustThreshold = 182 * minRelayTxFee.GetFeePerK()/1000 * 3;
347+
BOOST_CHECK_EQUAL(nDustThreshold, 546);
348+
// dust:
349+
t.vout[0].nValue = nDustThreshold - 1;
346350
BOOST_CHECK(!IsStandardTx(t, reason));
351+
// not dust:
352+
t.vout[0].nValue = nDustThreshold;
353+
BOOST_CHECK(IsStandardTx(t, reason));
347354

348-
t.vout[0].nValue = 2730; // not dust
355+
// Check dust with odd relay fee to verify rounding:
356+
// nDustThreshold = 182 * 1234 / 1000 * 3
357+
minRelayTxFee = CFeeRate(1234);
358+
// dust:
359+
t.vout[0].nValue = 672 - 1;
360+
BOOST_CHECK(!IsStandardTx(t, reason));
361+
// not dust:
362+
t.vout[0].nValue = 672;
349363
BOOST_CHECK(IsStandardTx(t, reason));
364+
minRelayTxFee = CFeeRate(1000);
350365

351366
t.vout[0].scriptPubKey = CScript() << OP_1;
352367
BOOST_CHECK(!IsStandardTx(t, reason));

0 commit comments

Comments
 (0)