mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge #18612: script: Remove undocumented and unused operator+
ccccd5190898ece3ac17aa3178f320d091f221df script: Remove undocumented and unused operator+ (MarcoFalke)
Pull request description:
This operator has no documented use case and is also unused outside of test code. The test code and all other (imaginary) code that might use this operator is written more clear and concise by the existing CScript push operators for opcodes and data.
Removing the operator is also going to protect against accidentally reintroducing bugs like this 6ff5f718b6 (diff-8458adcedc17d046942185cb709ff5c3L1135)
(last time it was used).
ACKs for top commit:
laanwj:
ACK ccccd5190898ece3ac17aa3178f320d091f221df
Tree-SHA512: 43898ac77e4d9643d9f8ac6f8f65497a4f0bbb1fb5dcaecc839c3719aa36181ba77befb213e59a9f33a20a29e0173a0e9c4763b1930940b32c3d1598b3e39af9
This commit is contained in:
parent
58ba7a3d88
commit
f87b37e07b
@ -416,28 +416,15 @@ public:
|
|||||||
|
|
||||||
SERIALIZE_METHODS(CScript, obj) { READWRITEAS(CScriptBase, obj); }
|
SERIALIZE_METHODS(CScript, obj) { READWRITEAS(CScriptBase, obj); }
|
||||||
|
|
||||||
CScript& operator+=(const CScript& b)
|
|
||||||
{
|
|
||||||
reserve(size() + b.size());
|
|
||||||
insert(end(), b.begin(), b.end());
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend CScript operator+(const CScript& a, const CScript& b)
|
|
||||||
{
|
|
||||||
CScript ret = a;
|
|
||||||
ret += b;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit CScript(int64_t b) { operator<<(b); }
|
explicit CScript(int64_t b) { operator<<(b); }
|
||||||
|
|
||||||
explicit CScript(opcodetype b) { operator<<(b); }
|
explicit CScript(opcodetype b) { operator<<(b); }
|
||||||
explicit CScript(const CScriptNum& b) { operator<<(b); }
|
explicit CScript(const CScriptNum& b) { operator<<(b); }
|
||||||
// delete non-existent constructor to defend against future introduction
|
// delete non-existent constructor to defend against future introduction
|
||||||
// e.g. via prevector
|
// e.g. via prevector
|
||||||
explicit CScript(const std::vector<unsigned char>& b) = delete;
|
explicit CScript(const std::vector<unsigned char>& b) = delete;
|
||||||
|
|
||||||
|
/** Delete non-existent operator to defend against future introduction */
|
||||||
|
CScript& operator<<(const CScript& b) = delete;
|
||||||
|
|
||||||
CScript& operator<<(int64_t b) { return push_int64(b); }
|
CScript& operator<<(int64_t b) { return push_int64(b); }
|
||||||
|
|
||||||
@ -484,15 +471,6 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CScript& operator<<(const CScript& b)
|
|
||||||
{
|
|
||||||
// I'm not sure if this should push the script or concatenate scripts.
|
|
||||||
// If there's ever a use for pushing a script onto a script, delete this member fn
|
|
||||||
assert(!"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
|
bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
|
||||||
{
|
{
|
||||||
return GetScriptOp(pc, end(), opcodeRet, &vchRet);
|
return GetScriptOp(pc, end(), opcodeRet, &vchRet);
|
||||||
@ -503,7 +481,6 @@ public:
|
|||||||
return GetScriptOp(pc, end(), opcodeRet, nullptr);
|
return GetScriptOp(pc, end(), opcodeRet, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Encode/decode small integers: */
|
/** Encode/decode small integers: */
|
||||||
static int DecodeOP_N(opcodetype opcode)
|
static int DecodeOP_N(opcodetype opcode)
|
||||||
{
|
{
|
||||||
|
@ -17,12 +17,16 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||||||
CScript script = ConsumeScript(fuzzed_data_provider);
|
CScript script = ConsumeScript(fuzzed_data_provider);
|
||||||
while (fuzzed_data_provider.remaining_bytes() > 0) {
|
while (fuzzed_data_provider.remaining_bytes() > 0) {
|
||||||
switch (fuzzed_data_provider.ConsumeIntegralInRange(0, 7)) {
|
switch (fuzzed_data_provider.ConsumeIntegralInRange(0, 7)) {
|
||||||
case 0:
|
case 0: {
|
||||||
script += ConsumeScript(fuzzed_data_provider);
|
CScript s = ConsumeScript(fuzzed_data_provider);
|
||||||
|
script = std::move(s);
|
||||||
break;
|
break;
|
||||||
case 1:
|
}
|
||||||
script = script + ConsumeScript(fuzzed_data_provider);
|
case 1: {
|
||||||
|
const CScript& s = ConsumeScript(fuzzed_data_provider);
|
||||||
|
script = s;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 2:
|
case 2:
|
||||||
script << fuzzed_data_provider.ConsumeIntegral<int64_t>();
|
script << fuzzed_data_provider.ConsumeIntegral<int64_t>();
|
||||||
break;
|
break;
|
||||||
|
@ -207,7 +207,6 @@ struct KeyData
|
|||||||
|
|
||||||
KeyData()
|
KeyData()
|
||||||
{
|
{
|
||||||
|
|
||||||
key0.Set(vchKey0, vchKey0 + 32, false);
|
key0.Set(vchKey0, vchKey0 + 32, false);
|
||||||
key0C.Set(vchKey0, vchKey0 + 32, true);
|
key0C.Set(vchKey0, vchKey0 + 32, true);
|
||||||
pubkey0 = key0.GetPubKey();
|
pubkey0 = key0.GetPubKey();
|
||||||
@ -250,9 +249,9 @@ private:
|
|||||||
|
|
||||||
void DoPush(const std::vector<unsigned char>& data)
|
void DoPush(const std::vector<unsigned char>& data)
|
||||||
{
|
{
|
||||||
DoPush();
|
DoPush();
|
||||||
push = data;
|
push = data;
|
||||||
havePush = true;
|
havePush = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -272,10 +271,10 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestBuilder& Add(const CScript& _script)
|
TestBuilder& Opcode(const opcodetype& _op)
|
||||||
{
|
{
|
||||||
DoPush();
|
DoPush();
|
||||||
spendTx.vin[0].scriptSig += _script;
|
spendTx.vin[0].scriptSig << _op;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,22 +643,22 @@ BOOST_AUTO_TEST_CASE(script_build)
|
|||||||
|
|
||||||
tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey1C) << OP_2 << OP_CHECKMULTISIG,
|
tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey1C) << OP_2 << OP_CHECKMULTISIG,
|
||||||
"2-of-2 with two identical keys and sigs pushed using OP_DUP but no SIGPUSHONLY", 0
|
"2-of-2 with two identical keys and sigs pushed using OP_DUP but no SIGPUSHONLY", 0
|
||||||
).Num(0).PushSig(keys.key1).Add(CScript() << OP_DUP));
|
).Num(0).PushSig(keys.key1).Opcode(OP_DUP));
|
||||||
tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey1C) << OP_2 << OP_CHECKMULTISIG,
|
tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey1C) << OP_2 << OP_CHECKMULTISIG,
|
||||||
"2-of-2 with two identical keys and sigs pushed using OP_DUP", SCRIPT_VERIFY_SIGPUSHONLY
|
"2-of-2 with two identical keys and sigs pushed using OP_DUP", SCRIPT_VERIFY_SIGPUSHONLY
|
||||||
).Num(0).PushSig(keys.key1).Add(CScript() << OP_DUP).ScriptError(SCRIPT_ERR_SIG_PUSHONLY));
|
).Num(0).PushSig(keys.key1).Opcode(OP_DUP).ScriptError(SCRIPT_ERR_SIG_PUSHONLY));
|
||||||
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
||||||
"P2SH(P2PK) with non-push scriptSig but no P2SH or SIGPUSHONLY", 0, true
|
"P2SH(P2PK) with non-push scriptSig but no P2SH or SIGPUSHONLY", 0, true
|
||||||
).PushSig(keys.key2).Add(CScript() << OP_NOP8).PushRedeem());
|
).PushSig(keys.key2).Opcode(OP_NOP8).PushRedeem());
|
||||||
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
||||||
"P2PK with non-push scriptSig but with P2SH validation", 0
|
"P2PK with non-push scriptSig but with P2SH validation", 0
|
||||||
).PushSig(keys.key2).Add(CScript() << OP_NOP8));
|
).PushSig(keys.key2).Opcode(OP_NOP8));
|
||||||
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
||||||
"P2SH(P2PK) with non-push scriptSig but no SIGPUSHONLY", SCRIPT_VERIFY_P2SH, true
|
"P2SH(P2PK) with non-push scriptSig but no SIGPUSHONLY", SCRIPT_VERIFY_P2SH, true
|
||||||
).PushSig(keys.key2).Add(CScript() << OP_NOP8).PushRedeem().ScriptError(SCRIPT_ERR_SIG_PUSHONLY));
|
).PushSig(keys.key2).Opcode(OP_NOP8).PushRedeem().ScriptError(SCRIPT_ERR_SIG_PUSHONLY));
|
||||||
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
tests.push_back(TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG,
|
||||||
"P2SH(P2PK) with non-push scriptSig but not P2SH", SCRIPT_VERIFY_SIGPUSHONLY, true
|
"P2SH(P2PK) with non-push scriptSig but not P2SH", SCRIPT_VERIFY_SIGPUSHONLY, true
|
||||||
).PushSig(keys.key2).Add(CScript() << OP_NOP8).PushRedeem().ScriptError(SCRIPT_ERR_SIG_PUSHONLY));
|
).PushSig(keys.key2).Opcode(OP_NOP8).PushRedeem().ScriptError(SCRIPT_ERR_SIG_PUSHONLY));
|
||||||
tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey1C) << OP_2 << OP_CHECKMULTISIG,
|
tests.push_back(TestBuilder(CScript() << OP_2 << ToByteVector(keys.pubkey1C) << ToByteVector(keys.pubkey1C) << OP_2 << OP_CHECKMULTISIG,
|
||||||
"2-of-2 with two identical keys and sigs pushed", SCRIPT_VERIFY_SIGPUSHONLY
|
"2-of-2 with two identical keys and sigs pushed", SCRIPT_VERIFY_SIGPUSHONLY
|
||||||
).Num(0).PushSig(keys.key1).PushSig(keys.key1));
|
).Num(0).PushSig(keys.key1).PushSig(keys.key1));
|
||||||
@ -1403,24 +1402,6 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
|||||||
BOOST_CHECK(s == expect);
|
BOOST_CHECK(s == expect);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(script_can_append_self)
|
|
||||||
{
|
|
||||||
CScript s, d;
|
|
||||||
|
|
||||||
s = ScriptFromHex("00");
|
|
||||||
s += s;
|
|
||||||
d = ScriptFromHex("0000");
|
|
||||||
BOOST_CHECK(s == d);
|
|
||||||
|
|
||||||
// check doubling a script that's large enough to require reallocation
|
|
||||||
static const char hex[] = "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f";
|
|
||||||
s = CScript() << ParseHex(hex) << OP_CHECKSIG;
|
|
||||||
d = CScript() << ParseHex(hex) << OP_CHECKSIG << ParseHex(hex) << OP_CHECKSIG;
|
|
||||||
s += s;
|
|
||||||
BOOST_CHECK(s == d);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_CONSENSUS_LIB)
|
#if defined(HAVE_CONSENSUS_LIB)
|
||||||
|
|
||||||
/* Test simple (successful) usage of dashconsensus_verify_script */
|
/* Test simple (successful) usage of dashconsensus_verify_script */
|
||||||
|
Loading…
Reference in New Issue
Block a user