Enforce witness entry and per-instruction stack limits - #18
Open
adrienlacombe wants to merge 1 commit into
Open
adrienlacombe wants to merge 1 commit into
adrienlacombe wants to merge 1 commit into
Conversation
This was referenced Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An executor starting with 1,000 items currently accepts a data push followed by
OP_DROP, despite the temporary 1,001-item stack. It also accepts oversized initial Tapscript stacks and witness elements when the script consumes them before later checks.Move the combined main/alt-stack limit check after every instruction, including data pushes and
OP_0, and record the peak before rejecting an overflowing step. Before the first instruction, enforce the initial count in Tapscript and the 520-byte element limit in SegwitV0/Tapscript. Disablingenforce_stack_limitstill disables only the item-count limit. Preserve the opcode on numeric-push failures.The context distinction follows Bitcoin Core v30.0, commit
d0f6d9953a15d7c7111d46dcb76ab2bb18e5dee3: ExecuteWitnessScript checks initial counts only for Tapscript and element sizes for both witness versions; EvalScript checks combined live depth after instructions. Tests preserve the pre-Tapscript ability to consume an initial excess item before the per-instruction check.with_stacksupplies an artificial execution state, so its replacement main/alt stacks now define the initial peak and undergo the same entry checks, instead of retaining the count of the witness vector used to initialize validation weight.Validation:
ba96bc2bd76774c9d1b011461cb79d983c2c43a1, seven of the nine new regression groups fail; the two control groups pass.cargo test --locked --all-features -- --skip fields::passes 11 existing unit tests, nine integration tests, and one doctest.git diff --checkand formatting of the new test pass. The existing lifetime warning insrc/data_structures.rsis unchanged.This is a bounded resource-check repair, not a claim of complete Bitcoin Core compatibility. In particular, the existing lack of Tapscript
OP_SUCCESSxscanning and its precedence over resource checks remains unchanged, as do experimentalOP_CATdefaults and signature-budget behavior.