Skip to content

Commit 98fbb2a

Browse files
author
MarcoFalke
committed
Merge #17720: test: add unit test for non-standard "scriptsig-not-pushonly" txs
5aab011 test: add unit test for non-standard "scriptsig-not-pushonly" txs (Sebastian Falbesoner) Pull request description: Approaches another missing unit test of issue #17394: Checks that the function `IsStandardTx()` returns rejection reason "scriptsig-not-pushonly" if any one of the input's scriptSig consists of any other ops than just PUSHs. ACKs for top commit: MarcoFalke: ACK 5aab011 🍟 practicalswift: ACK 5aab011 -- patch looks correct Tree-SHA512: fbe25bcf57e5f0c8d2397eb67e61fe8d9145ba83032789adb2b67d6fcbcd87e6427e9d965e8cd7bbaaea482e39ec2f110f71ef2de079c7d1fba2712848caa9ba
2 parents ac579ad + 5aab011 commit 98fbb2a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/test/transaction_tests.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,40 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
784784
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
785785
BOOST_CHECK_EQUAL(reason, "scriptsig-size");
786786

787+
// Check scriptSig format (non-standard if there are any other ops than just PUSHs)
788+
t.vin[0].scriptSig = CScript()
789+
<< OP_TRUE << OP_0 << OP_1NEGATE << OP_16 // OP_n (single byte pushes: n = 1, 0, -1, 16)
790+
<< std::vector<unsigned char>(75, 0) // OP_PUSHx [...x bytes...]
791+
<< std::vector<unsigned char>(235, 0) // OP_PUSHDATA1 x [...x bytes...]
792+
<< std::vector<unsigned char>(1234, 0) // OP_PUSHDATA2 x [...x bytes...]
793+
<< OP_9;
794+
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
795+
796+
const std::vector<unsigned char> non_push_ops = { // arbitrary set of non-push operations
797+
OP_NOP, OP_VERIFY, OP_IF, OP_ROT, OP_3DUP, OP_SIZE, OP_EQUAL, OP_ADD, OP_SUB,
798+
OP_HASH256, OP_CODESEPARATOR, OP_CHECKSIG, OP_CHECKLOCKTIMEVERIFY };
799+
800+
CScript::const_iterator pc = t.vin[0].scriptSig.begin();
801+
while (pc < t.vin[0].scriptSig.end()) {
802+
opcodetype opcode;
803+
CScript::const_iterator prev_pc = pc;
804+
t.vin[0].scriptSig.GetOp(pc, opcode); // advance to next op
805+
// for the sake of simplicity, we only replace single-byte push operations
806+
if (opcode >= 1 && opcode <= OP_PUSHDATA4)
807+
continue;
808+
809+
int index = prev_pc - t.vin[0].scriptSig.begin();
810+
unsigned char orig_op = *prev_pc; // save op
811+
// replace current push-op with each non-push-op
812+
for (auto op : non_push_ops) {
813+
t.vin[0].scriptSig[index] = op;
814+
BOOST_CHECK(!IsStandardTx(CTransaction(t), reason));
815+
BOOST_CHECK_EQUAL(reason, "scriptsig-not-pushonly");
816+
}
817+
t.vin[0].scriptSig[index] = orig_op; // restore op
818+
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
819+
}
820+
787821
// Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT)
788822
t.vin.clear();
789823
t.vin.resize(2438); // size per input (empty scriptSig): 41 bytes

0 commit comments

Comments
 (0)