Skip to content

Commit fad0b4f

Browse files
author
MacroFake
committed
Pass datacarrier setting into IsStandard
1 parent fa2a6b8 commit fad0b4f

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/policy/policy.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
6767
return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn));
6868
}
6969

70-
bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType)
70+
bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType)
7171
{
7272
std::vector<std::vector<unsigned char> > vSolutions;
7373
whichType = Solver(scriptPubKey, vSolutions);
@@ -83,7 +83,7 @@ bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType)
8383
if (m < 1 || m > n)
8484
return false;
8585
} else if (whichType == TxoutType::NULL_DATA) {
86-
if (!g_max_datacarrier_bytes || scriptPubKey.size() > *g_max_datacarrier_bytes) {
86+
if (!max_datacarrier_bytes || scriptPubKey.size() > *max_datacarrier_bytes) {
8787
return false;
8888
}
8989
}
@@ -131,7 +131,7 @@ bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeR
131131
unsigned int nDataOut = 0;
132132
TxoutType whichType;
133133
for (const CTxOut& txout : tx.vout) {
134-
if (!::IsStandard(txout.scriptPubKey, whichType)) {
134+
if (!::IsStandard(txout.scriptPubKey, g_max_datacarrier_bytes, whichType)) {
135135
reason = "scriptpubkey";
136136
return false;
137137
}

src/policy/policy.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
105105

106106
bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
107107

108-
bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType);
108+
bool IsStandard(const CScript& scriptPubKey, const std::optional<unsigned>& max_datacarrier_bytes, TxoutType& whichType);
109109

110110

111111
// Changing the default transaction version requires a two step process: first

src/test/fuzz/key.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ FUZZ_TARGET_INIT(key, initialize_key)
157157
assert(fillable_signing_provider_pub.HaveKey(pubkey.GetID()));
158158

159159
TxoutType which_type_tx_pubkey;
160-
const bool is_standard_tx_pubkey = IsStandard(tx_pubkey_script, which_type_tx_pubkey);
160+
const bool is_standard_tx_pubkey = IsStandard(tx_pubkey_script, std::nullopt, which_type_tx_pubkey);
161161
assert(is_standard_tx_pubkey);
162162
assert(which_type_tx_pubkey == TxoutType::PUBKEY);
163163

164164
TxoutType which_type_tx_multisig;
165-
const bool is_standard_tx_multisig = IsStandard(tx_multisig_script, which_type_tx_multisig);
165+
const bool is_standard_tx_multisig = IsStandard(tx_multisig_script, std::nullopt, which_type_tx_multisig);
166166
assert(is_standard_tx_multisig);
167167
assert(which_type_tx_multisig == TxoutType::MULTISIG);
168168

src/test/fuzz/script.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ FUZZ_TARGET_INIT(script, initialize_script)
5555
}
5656

5757
TxoutType which_type;
58-
bool is_standard_ret = IsStandard(script, which_type);
58+
bool is_standard_ret = IsStandard(script, std::nullopt, which_type);
5959
if (!is_standard_ret) {
6060
assert(which_type == TxoutType::NONSTANDARD ||
6161
which_type == TxoutType::NULL_DATA ||

src/test/multisig_tests.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,30 @@ BOOST_AUTO_TEST_CASE(multisig_IsStandard)
141141
for (int i = 0; i < 4; i++)
142142
key[i].MakeNewKey(true);
143143

144-
TxoutType whichType;
144+
const auto is_standard{[](const CScript& spk) {
145+
TxoutType type;
146+
bool res{::IsStandard(spk, std::nullopt, type)};
147+
if (res) {
148+
BOOST_CHECK_EQUAL(type, TxoutType::MULTISIG);
149+
}
150+
return res;
151+
}};
145152

146153
CScript a_and_b;
147154
a_and_b << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
148-
BOOST_CHECK(::IsStandard(a_and_b, whichType));
155+
BOOST_CHECK(is_standard(a_and_b));
149156

150157
CScript a_or_b;
151158
a_or_b << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
152-
BOOST_CHECK(::IsStandard(a_or_b, whichType));
159+
BOOST_CHECK(is_standard(a_or_b));
153160

154161
CScript escrow;
155162
escrow << OP_2 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << OP_3 << OP_CHECKMULTISIG;
156-
BOOST_CHECK(::IsStandard(escrow, whichType));
163+
BOOST_CHECK(is_standard(escrow));
157164

158165
CScript one_of_four;
159166
one_of_four << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << ToByteVector(key[2].GetPubKey()) << ToByteVector(key[3].GetPubKey()) << OP_4 << OP_CHECKMULTISIG;
160-
BOOST_CHECK(!::IsStandard(one_of_four, whichType));
167+
BOOST_CHECK(!is_standard(one_of_four));
161168

162169
CScript malformed[6];
163170
malformed[0] << OP_3 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_2 << OP_CHECKMULTISIG;
@@ -167,8 +174,9 @@ BOOST_AUTO_TEST_CASE(multisig_IsStandard)
167174
malformed[4] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey()) << OP_CHECKMULTISIG;
168175
malformed[5] << OP_1 << ToByteVector(key[0].GetPubKey()) << ToByteVector(key[1].GetPubKey());
169176

170-
for (int i = 0; i < 6; i++)
171-
BOOST_CHECK(!::IsStandard(malformed[i], whichType));
177+
for (int i = 0; i < 6; i++) {
178+
BOOST_CHECK(!is_standard(malformed[i]));
179+
}
172180
}
173181

174182
BOOST_AUTO_TEST_CASE(multisig_Sign)

0 commit comments

Comments
 (0)