Skip to content

Commit 5e190cd

Browse files
committed
Replace CScript _hex_v_u8 appends with _hex
This will skip vector conversion before serializing to the prevector in CScript.
1 parent cac846c commit 5e190cd

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/kernel/chainparams.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
7373
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
7474
{
7575
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
76-
const CScript genesisOutputScript = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
76+
const CScript genesisOutputScript = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
7777
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
7878
}
7979

@@ -353,7 +353,7 @@ class CTestNet4Params : public CChainParams {
353353
m_assumed_chain_state_size = 0;
354354

355355
const char* testnet4_genesis_msg = "03/May/2024 000000000000000000001ebd58c244970b3aa9d783bb001011fbe8ea8e98e00e";
356-
const CScript testnet4_genesis_script = CScript() << "000000000000000000000000000000000000000000000000000000000000000000"_hex_v_u8 << OP_CHECKSIG;
356+
const CScript testnet4_genesis_script = CScript() << "000000000000000000000000000000000000000000000000000000000000000000"_hex << OP_CHECKSIG;
357357
genesis = CreateGenesisBlock(testnet4_genesis_msg,
358358
testnet4_genesis_script,
359359
1714777860,

src/test/miner_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
608608
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
609609
{
610610
// Note that by default, these tests run with size accounting enabled.
611-
CScript scriptPubKey = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
611+
CScript scriptPubKey = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
612612
std::unique_ptr<CBlockTemplate> pblocktemplate;
613613

614614
CTxMemPool& tx_mempool{*m_node.mempool};

src/test/script_tests.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,13 @@ static CScript ScriptFromHex(const std::string& str)
13681368
return ToScript(*Assert(TryParseHex(str)));
13691369
}
13701370

1371+
BOOST_AUTO_TEST_CASE(script_byte_array_u8_vector_equivalence)
1372+
{
1373+
const CScript scriptPubKey1 = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
1374+
const CScript scriptPubKey2 = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
1375+
BOOST_CHECK(scriptPubKey1 == scriptPubKey2);
1376+
}
1377+
13711378
BOOST_AUTO_TEST_CASE(script_FindAndDelete)
13721379
{
13731380
// Exercise the FindAndDelete functionality
@@ -1421,7 +1428,7 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
14211428
// prefix, leaving 02ff03 which is push-two-bytes:
14221429
s = ToScript("0302ff030302ff03"_hex);
14231430
d = ToScript("03"_hex);
1424-
expect = CScript() << "ff03"_hex_v_u8 << "ff03"_hex_v_u8;
1431+
expect = CScript() << "ff03"_hex << "ff03"_hex;
14251432
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
14261433
BOOST_CHECK(s == expect);
14271434

src/test/transaction_tests.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -852,24 +852,24 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
852852
CheckIsNotStandard(t, "scriptpubkey");
853853

854854
// MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)
855-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
855+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
856856
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY, t.vout[0].scriptPubKey.size());
857857
CheckIsStandard(t);
858858

859859
// MAX_OP_RETURN_RELAY+1-byte TxoutType::NULL_DATA (non-standard)
860-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"_hex_v_u8;
860+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"_hex;
861861
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY + 1, t.vout[0].scriptPubKey.size());
862862
CheckIsNotStandard(t, "scriptpubkey");
863863

864864
// Data payload can be encoded in any way...
865-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ""_hex_v_u8;
865+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ""_hex;
866866
CheckIsStandard(t);
867-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "00"_hex_v_u8 << "01"_hex_v_u8;
867+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "00"_hex << "01"_hex;
868868
CheckIsStandard(t);
869869
// OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
870-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RESERVED << -1 << 0 << "01"_hex_v_u8 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
870+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RESERVED << -1 << 0 << "01"_hex << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
871871
CheckIsStandard(t);
872-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << 0 << "01"_hex_v_u8 << 2 << "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_hex_v_u8;
872+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << 0 << "01"_hex << 2 << "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_hex;
873873
CheckIsStandard(t);
874874

875875
// ...so long as it only contains PUSHDATA's
@@ -883,13 +883,13 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
883883

884884
// Only one TxoutType::NULL_DATA permitted in all cases
885885
t.vout.resize(2);
886-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
886+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
887887
t.vout[0].nValue = 0;
888-
t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
888+
t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
889889
t.vout[1].nValue = 0;
890890
CheckIsNotStandard(t, "multi-op-return");
891891

892-
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
892+
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
893893
t.vout[1].scriptPubKey = CScript() << OP_RETURN;
894894
CheckIsNotStandard(t, "multi-op-return");
895895

src/wallet/test/ismine_tests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
684684
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
685685

686686
scriptPubKey.clear();
687-
scriptPubKey << OP_0 << "aabb"_hex_v_u8;
687+
scriptPubKey << OP_0 << "aabb"_hex;
688688

689689
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
690690
BOOST_CHECK_EQUAL(result, ISMINE_NO);
@@ -699,7 +699,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
699699
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
700700

701701
scriptPubKey.clear();
702-
scriptPubKey << OP_16 << "aabb"_hex_v_u8;
702+
scriptPubKey << OP_16 << "aabb"_hex;
703703

704704
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
705705
BOOST_CHECK_EQUAL(result, ISMINE_NO);

0 commit comments

Comments
 (0)