test: script: boundary at exactly 65535 bytes must use OP_PUSHDATA2
What changed, and why it matters
This commit only adds a new test case to Bitcoin Core's test suite. It verifies that a 65535-byte data push in Bitcoin scripts is considered 'minimal' only when encoded with OP_PUSHDATA2, not OP_PUSHDATA4. The commit does not change any production code, so it cannot directly introduce or fix a live vulnerability. It is a regression test that documents an existing consensus rule boundary.
No immediate action required. Review whether the existing production implementation already correctly enforces this boundary, since the test merely codifies expected behavior. If the test fails on current code, a separate fix would be needed.
Security signals we found
Script minimal-push rule boundary test
No production code change
Consensus-adjacent encoding rule
Regression test only
Evidence from the diff
The diff adds a BOOST_AUTO_TEST_CASE named script_CheckMinimalPush_boundary in src/test/script_tests.cpp. It constructs a 65535-byte vector and asserts that CheckMinimalPush returns true for OP_PUSHDATA2 and false for OP_PUSHDATA4. This aligns with Bitcoin’s script minimal-push rules: pushes of 76–65535 bytes must use OP_PUSHDATA2, while 65536+ bytes require OP_PUSHDATA4. No implementation code is modified.
Changed components
src/test/script_tests.cppInspect captured patch +8 / −0
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 1478cf91..b0787020 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -1455,6 +1455,14 @@ BOOST_AUTO_TEST_CASE(script_IsPushOnly_on_invalid_scripts)
BOOST_CHECK(!CScript(direct, direct+sizeof(direct)).IsPushOnly());
}
+BOOST_AUTO_TEST_CASE(script_CheckMinimalPush_boundary)
+{
+ // Test the boundary at exactly 65535 bytes: must use OP_PUSHDATA2, not OP_PUSHDATA4.
+ std::vector<unsigned char> data(65535, '\x42');
+ BOOST_CHECK(CheckMinimalPush(data, OP_PUSHDATA2));
+ BOOST_CHECK(!CheckMinimalPush(data, OP_PUSHDATA4));
+}
+
BOOST_AUTO_TEST_CASE(script_GetScriptAsm)
{
BOOST_CHECK_EQUAL("OP_CHECKLOCKTIMEVERIFY", ScriptToAsmStr(CScript() << OP_NOP2, true));
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.