mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
scripted-diff: Replace ParseHex[<std::byte>]("str") -> "str"_hex[_u8]
Ideally all call sites should accept std::byte instead of uint8_t but those transformations are left to future PRs.
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended 's/\bParseHex\(("[^"]*")\)/\1_hex_u8/g' $(git grep -l ParseHex -- :src ':(exclude)src/test/util_tests.cpp')
sed -i --regexp-extended 's/\bParseHex<std::byte>\(("[^"]*")\)/\1_hex/g' $(git grep -l ParseHex -- :src ':(exclude)src/test/util_tests.cpp')
sed -i --regexp-extended 's/\bScriptFromHex\(("[^"]*")\)/ToScript(\1_hex)/g' src/test/script_tests.cpp
-END VERIFY SCRIPT-
Co-Authored-By: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-Authored-By: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
@@ -1269,7 +1269,7 @@ BOOST_AUTO_TEST_CASE(sign_invalid_miniscript)
|
||||
|
||||
// Create a Taproot output which contains a leaf in which a non-32 bytes push is used where a public key is expected
|
||||
// by the Miniscript parser. This offending Script was found by the RPC fuzzer.
|
||||
const auto invalid_pubkey{ParseHex("173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292")};
|
||||
const auto invalid_pubkey{"173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292"_hex_u8};
|
||||
TaprootBuilder builder;
|
||||
builder.Add(0, {invalid_pubkey}, 0xc0);
|
||||
builder.Finalize(XOnlyPubKey::NUMS_H);
|
||||
@@ -1393,60 +1393,60 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 4);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("0302ff03"); // PUSH 0x02ff03 onto stack
|
||||
d = ScriptFromHex("0302ff03");
|
||||
s = ToScript("0302ff03"_hex); // PUSH 0x02ff03 onto stack
|
||||
d = ToScript("0302ff03"_hex);
|
||||
expect = CScript();
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ToScript("0302ff030302ff03"_hex); // PUSH 0x02ff03 PUSH 0x02ff03
|
||||
d = ScriptFromHex("0302ff03");
|
||||
d = ToScript("0302ff03"_hex);
|
||||
expect = CScript();
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("0302ff030302ff03");
|
||||
d = ScriptFromHex("02");
|
||||
s = ToScript("0302ff030302ff03"_hex);
|
||||
d = ToScript("02"_hex);
|
||||
expect = s; // FindAndDelete matches entire opcodes
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("0302ff030302ff03");
|
||||
d = ScriptFromHex("ff");
|
||||
s = ToScript("0302ff030302ff03"_hex);
|
||||
d = ToScript("ff"_hex);
|
||||
expect = s;
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
// This is an odd edge case: strip of the push-three-bytes
|
||||
// prefix, leaving 02ff03 which is push-two-bytes:
|
||||
s = ScriptFromHex("0302ff030302ff03");
|
||||
d = ScriptFromHex("03");
|
||||
s = ToScript("0302ff030302ff03"_hex);
|
||||
d = ToScript("03"_hex);
|
||||
expect = CScript() << "ff03"_hex_v_u8 << "ff03"_hex_v_u8;
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
// Byte sequence that spans multiple opcodes:
|
||||
s = ScriptFromHex("02feed5169"); // PUSH(0xfeed) OP_1 OP_VERIFY
|
||||
d = ScriptFromHex("feed51");
|
||||
s = ToScript("02feed5169"_hex); // PUSH(0xfeed) OP_1 OP_VERIFY
|
||||
d = ToScript("feed51"_hex);
|
||||
expect = s;
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0); // doesn't match 'inside' opcodes
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("02feed5169"); // PUSH(0xfeed) OP_1 OP_VERIFY
|
||||
d = ScriptFromHex("02feed51");
|
||||
expect = ScriptFromHex("69");
|
||||
s = ToScript("02feed5169"_hex); // PUSH(0xfeed) OP_1 OP_VERIFY
|
||||
d = ToScript("02feed51"_hex);
|
||||
expect = ToScript("69"_hex);
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("516902feed5169");
|
||||
d = ScriptFromHex("feed51");
|
||||
s = ToScript("516902feed5169"_hex);
|
||||
d = ToScript("feed51"_hex);
|
||||
expect = s;
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("516902feed5169");
|
||||
d = ScriptFromHex("02feed51");
|
||||
expect = ScriptFromHex("516969");
|
||||
s = ToScript("516902feed5169"_hex);
|
||||
d = ToScript("02feed51"_hex);
|
||||
expect = ToScript("516969"_hex);
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
@@ -1464,15 +1464,15 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
||||
|
||||
// Another weird edge case:
|
||||
// End with invalid push (not enough data)...
|
||||
s = ScriptFromHex("0003feed");
|
||||
d = ScriptFromHex("03feed"); // ... can remove the invalid push
|
||||
expect = ScriptFromHex("00");
|
||||
s = ToScript("0003feed"_hex);
|
||||
d = ToScript("03feed"_hex); // ... can remove the invalid push
|
||||
expect = ToScript("00"_hex);
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
|
||||
BOOST_CHECK(s == expect);
|
||||
|
||||
s = ScriptFromHex("0003feed");
|
||||
d = ScriptFromHex("00");
|
||||
expect = ScriptFromHex("03feed");
|
||||
s = ToScript("0003feed"_hex);
|
||||
d = ToScript("00"_hex);
|
||||
expect = ToScript("03feed"_hex);
|
||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
|
||||
BOOST_CHECK(s == expect);
|
||||
}
|
||||
@@ -1481,13 +1481,13 @@ BOOST_AUTO_TEST_CASE(script_HasValidOps)
|
||||
{
|
||||
// Exercise the HasValidOps functionality
|
||||
CScript script;
|
||||
script = ScriptFromHex("76a9141234567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac"); // Normal script
|
||||
script = ToScript("76a9141234567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac"_hex); // Normal script
|
||||
BOOST_CHECK(script.HasValidOps());
|
||||
script = ScriptFromHex("76a914ff34567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac");
|
||||
script = ToScript("76a914ff34567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac"_hex);
|
||||
BOOST_CHECK(script.HasValidOps());
|
||||
script = ScriptFromHex("ff88ac"); // Script with OP_INVALIDOPCODE explicit
|
||||
script = ToScript("ff88ac"_hex); // Script with OP_INVALIDOPCODE explicit
|
||||
BOOST_CHECK(!script.HasValidOps());
|
||||
script = ScriptFromHex("88acc0"); // Script with undefined opcode
|
||||
script = ToScript("88acc0"_hex); // Script with undefined opcode
|
||||
BOOST_CHECK(!script.HasValidOps());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user