diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -456,26 +456,16 @@ READWRITEAS(CScriptBase, *this); } - 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(opcodetype b) { operator<<(b); } explicit CScript(const CScriptNum &b) { operator<<(b); } // delete non-existent constructor to defend against future introduction // e.g. via prevector explicit CScript(const std::vector &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<<(opcodetype opcode) { @@ -512,15 +502,6 @@ 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 &vchRet) const { return GetScriptOp(pc, end(), opcodeRet, &vchRet); diff --git a/src/test/fuzz/script_ops.cpp b/src/test/fuzz/script_ops.cpp --- a/src/test/fuzz/script_ops.cpp +++ b/src/test/fuzz/script_ops.cpp @@ -16,12 +16,16 @@ CScript script = ConsumeScript(fuzzed_data_provider); while (fuzzed_data_provider.remaining_bytes() > 0) { switch (fuzzed_data_provider.ConsumeIntegralInRange(0, 7)) { - case 0: - script += ConsumeScript(fuzzed_data_provider); + case 0: { + CScript s = ConsumeScript(fuzzed_data_provider); + script = std::move(s); break; - case 1: - script = script + ConsumeScript(fuzzed_data_provider); + } + case 1: { + const CScript &s = ConsumeScript(fuzzed_data_provider); + script = s; break; + } case 2: script << fuzzed_data_provider.ConsumeIntegral(); break; diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -314,9 +314,9 @@ return *this; } - TestBuilder &Add(const CScript &_script) { + TestBuilder &Opcode(const opcodetype &_op) { DoPush(); - spendTx.vin[0].scriptSig += _script; + spendTx.vin[0].scriptSig << _op; return *this; } @@ -1085,7 +1085,7 @@ 0) .Num(0) .PushSigECDSA(keys.key1) - .Add(CScript() << OP_DUP)); + .Opcode(OP_DUP)); tests.push_back( TestBuilder( CScript() << OP_2 << ToByteVector(keys.pubkey1C) @@ -1095,7 +1095,7 @@ SCRIPT_VERIFY_SIGPUSHONLY) .Num(0) .PushSigECDSA(keys.key1) - .Add(CScript() << OP_DUP) + .Opcode(OP_DUP) .SetScriptError(ScriptError::SIG_PUSHONLY)); tests.push_back( TestBuilder( @@ -1103,19 +1103,19 @@ "P2SH(P2PK) with non-push scriptSig but no P2SH or SIGPUSHONLY", 0, true) .PushSigECDSA(keys.key2) - .Add(CScript() << OP_NOP8) + .Opcode(OP_NOP8) .PushRedeem()); tests.push_back( TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG, "P2PK with non-push scriptSig but with P2SH validation", 0) .PushSigECDSA(keys.key2) - .Add(CScript() << OP_NOP8)); + .Opcode(OP_NOP8)); tests.push_back( TestBuilder(CScript() << ToByteVector(keys.pubkey2C) << OP_CHECKSIG, "P2SH(P2PK) with non-push scriptSig but no SIGPUSHONLY", SCRIPT_VERIFY_P2SH, true) .PushSigECDSA(keys.key2) - .Add(CScript() << OP_NOP8) + .Opcode(OP_NOP8) .PushRedeem() .SetScriptError(ScriptError::SIG_PUSHONLY)); tests.push_back( @@ -1123,7 +1123,7 @@ "P2SH(P2PK) with non-push scriptSig but not P2SH", SCRIPT_VERIFY_SIGPUSHONLY, true) .PushSigECDSA(keys.key2) - .Add(CScript() << OP_NOP8) + .Opcode(OP_NOP8) .PushRedeem() .SetScriptError(ScriptError::SIG_PUSHONLY)); tests.push_back( @@ -3208,25 +3208,6 @@ BOOST_CHECK(!script.HasValidOps()); } -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[] = - "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6" - "bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"; - 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) /* Test simple (successful) usage of bitcoinconsensus_verify_script */