Skip to content

Commit e3e49b0

Browse files
authored
Merge pull request #1696 from evoskuil/master
Program initialize is_prevalid() insufficiently prioritized.
2 parents 556716c + 0aeadf9 commit e3e49b0

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

include/bitcoin/system/impl/machine/interpreter_run.ipp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ TEMPLATE
3838
code CLASS::
3939
run() NOEXCEPT
4040
{
41-
// Enforce initial limits, determine early success or failure.
4241
if (const auto ec = state::initialize())
4342
return ec;
4443

include/bitcoin/system/impl/machine/program.ipp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ initialize() const NOEXCEPT
6161
const auto bip141 = is_enabled(flags::bip141_rule);
6262
const auto bip342 = is_enabled(flags::bip342_rule);
6363

64-
// Apply stack element limit (520) to initial witness [bip141][bip342].
65-
if (bip141 && witness_ && !chain::witness::is_push_size(*witness_))
66-
return error::invalid_witness_stack;
64+
// Succeed if any success code, overrides all codes and errors [bip342].
65+
if (bip342 && script_->is_prevalid())
66+
return error::prevalid_script;
6767

68-
// Script size limit (10,000) [0.3.7+], removed [bip342].
69-
if (!bip342 && nops && script_->is_oversized())
70-
return error::invalid_script_size;
68+
// Fail if last op is underflow (same behavior as prefail, invalid code).
69+
if (script_->is_underflow())
70+
return error::invalid_script;
7171

72-
// Stacks element limit (1,000) applied to initial stack [bip342].
72+
// Stack limit (1,000) applied to initial stack [bip342].
7373
if (bip342 && is_stack_overflow())
7474
return error::invalid_stack_size;
7575

76-
// Succeed if any success code, one overrides all codes [bip342].
77-
if (bip342 && script_->is_prevalid())
78-
return error::prevalid_script;
76+
// Apply stack element limit (520) to initial witness [bip342|bip141].
77+
if ((bip342 || bip141) && witness_ && !chain::witness::is_push_size(*witness_))
78+
return error::invalid_witness_stack;
7979

80-
// Fail if last op underflow, lower priority than success codes [bip342].
81-
if (script_->is_underflow())
82-
return error::invalid_script;
80+
// Script size limit (10,000) [0.3.7+], removed [bip342].
81+
if (!bip342 && nops && script_->is_oversized())
82+
return error::invalid_script_size;
8383

8484
// Fail if any op invalid (invalid codes reduced in tapscript).
8585
// Should be after underflow check since underflow is also an invalid op.

0 commit comments

Comments
 (0)