File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -267,3 +267,15 @@ std::string CScriptWitness::ToString() const
267
267
}
268
268
return ret + " )" ;
269
269
}
270
+
271
+ bool CScript::HasValidOps () const
272
+ {
273
+ CScript::const_iterator it = begin ();
274
+ while (it < end ()) {
275
+ opcodetype opcode;
276
+ if (!GetOp (it, opcode) || opcode > 0xb9 ) {
277
+ return false ;
278
+ }
279
+ }
280
+ return true ;
281
+ }
Original file line number Diff line number Diff line change @@ -630,6 +630,9 @@ class CScript : public CScriptBase
630
630
bool IsPushOnly (const_iterator pc) const ;
631
631
bool IsPushOnly () const ;
632
632
633
+ /* * Check if the script contains valid OP_CODES */
634
+ bool HasValidOps () const ;
635
+
633
636
/* *
634
637
* Returns whether the script is guaranteed to fail at execution,
635
638
* regardless of the initial stack. This allows outputs to be pruned
Original file line number Diff line number Diff line change @@ -1438,4 +1438,18 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
1438
1438
BOOST_CHECK (s == expect);
1439
1439
}
1440
1440
1441
+ BOOST_AUTO_TEST_CASE (script_HasValidOps)
1442
+ {
1443
+ // Exercise the HasValidOps functionality
1444
+ CScript script;
1445
+ script = ScriptFromHex (" 76a9141234567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac" ); // Normal script
1446
+ BOOST_CHECK (script.HasValidOps ());
1447
+ script = ScriptFromHex (" 76a914ff34567890abcdefa1a2a3a4a5a6a7a8a9a0aaab88ac" );
1448
+ BOOST_CHECK (script.HasValidOps ());
1449
+ script = ScriptFromHex (" ff88ac" ); // Script with OP_INVALIDOPCODE explicit
1450
+ BOOST_CHECK (!script.HasValidOps ());
1451
+ script = ScriptFromHex (" 88acc0" ); // Script with undefined opcode
1452
+ BOOST_CHECK (!script.HasValidOps ());
1453
+ }
1454
+
1441
1455
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments