Skip to content

Commit aaa5597

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26875: Tests: Fill out dust limit unit test for known types except bare multisig
b093f56 Fill out dust limit unit test for known types except bare multisig (Greg Sanders) Pull request description: Having the constants checked explicitly in a single spot helps with possible regressions and also useful for documentation. In addition, add a check for undefined v1 witness programs. ACKs for top commit: theStack: Code-review ACK b093f56 MarcoFalke: review ACK b093f56 🥉 Tree-SHA512: 1421f75471739d29b9ef59b0a925b6b07e4e9af92822dbe56eedfb590be9a00fb0c34312146c7c1b5211906461ed00bfa2eb53c88595c6e5a27694b2dc21df38
2 parents 7753efc + b093f56 commit aaa5597

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/test/transaction_tests.cpp

+40-5
Original file line numberDiff line numberDiff line change
@@ -935,23 +935,58 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
935935
CheckIsNotStandard(t, "bare-multisig");
936936
g_bare_multi = DEFAULT_PERMIT_BAREMULTISIG;
937937

938+
// Check compressed P2PK outputs dust threshold (must have leading 02 or 03)
939+
t.vout[0].scriptPubKey = CScript() << std::vector<unsigned char>(33, 0x02) << OP_CHECKSIG;
940+
t.vout[0].nValue = 576;
941+
CheckIsStandard(t);
942+
t.vout[0].nValue = 575;
943+
CheckIsNotStandard(t, "dust");
944+
945+
// Check uncompressed P2PK outputs dust threshold (must have leading 04/06/07)
946+
t.vout[0].scriptPubKey = CScript() << std::vector<unsigned char>(65, 0x04) << OP_CHECKSIG;
947+
t.vout[0].nValue = 672;
948+
CheckIsStandard(t);
949+
t.vout[0].nValue = 671;
950+
CheckIsNotStandard(t, "dust");
951+
952+
// Check P2PKH outputs dust threshold
953+
t.vout[0].scriptPubKey = CScript() << OP_DUP << OP_HASH160 << std::vector<unsigned char>(20, 0) << OP_EQUALVERIFY << OP_CHECKSIG;
954+
t.vout[0].nValue = 546;
955+
CheckIsStandard(t);
956+
t.vout[0].nValue = 545;
957+
CheckIsNotStandard(t, "dust");
958+
959+
// Check P2SH outputs dust threshold
960+
t.vout[0].scriptPubKey = CScript() << OP_HASH160 << std::vector<unsigned char>(20, 0) << OP_EQUAL;
961+
t.vout[0].nValue = 540;
962+
CheckIsStandard(t);
963+
t.vout[0].nValue = 539;
964+
CheckIsNotStandard(t, "dust");
965+
938966
// Check P2WPKH outputs dust threshold
939-
t.vout[0].scriptPubKey = CScript() << OP_0 << ParseHex("ffffffffffffffffffffffffffffffffffffffff");
967+
t.vout[0].scriptPubKey = CScript() << OP_0 << std::vector<unsigned char>(20, 0);
940968
t.vout[0].nValue = 294;
941969
CheckIsStandard(t);
942970
t.vout[0].nValue = 293;
943971
CheckIsNotStandard(t, "dust");
944972

945973
// Check P2WSH outputs dust threshold
946-
t.vout[0].scriptPubKey = CScript() << OP_0 << ParseHex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
974+
t.vout[0].scriptPubKey = CScript() << OP_0 << std::vector<unsigned char>(32, 0);
975+
t.vout[0].nValue = 330;
976+
CheckIsStandard(t);
977+
t.vout[0].nValue = 329;
978+
CheckIsNotStandard(t, "dust");
979+
980+
// Check P2TR outputs dust threshold (Invalid xonly key ok!)
981+
t.vout[0].scriptPubKey = CScript() << OP_1 << std::vector<unsigned char>(32, 0);
947982
t.vout[0].nValue = 330;
948983
CheckIsStandard(t);
949984
t.vout[0].nValue = 329;
950985
CheckIsNotStandard(t, "dust");
951986

952-
// Check future Witness Program versions dust threshold
953-
for (int op = OP_2; op <= OP_16; op += 1) {
954-
t.vout[0].scriptPubKey = CScript() << (opcodetype)op << ParseHex("ffff");
987+
// Check future Witness Program versions dust threshold (non-32-byte pushes are undefined for version 1)
988+
for (int op = OP_1; op <= OP_16; op += 1) {
989+
t.vout[0].scriptPubKey = CScript() << (opcodetype)op << std::vector<unsigned char>(2, 0);
955990
t.vout[0].nValue = 240;
956991
CheckIsStandard(t);
957992

0 commit comments

Comments
 (0)