Reject out-of-range OP_PICK and OP_ROLL indices without panicking - #19
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.
OP_PICKandOP_ROLLcount the selector itself when checking the accessible stack size. With a one-element pool and selector1, the guard passes and the subsequenttop(...).unwrap()panics. A zero selector with no pool also panics. Require both operands and exclude the selector from the pool length so these inputs returnExecError::InvalidStackOperation.The six regression tests exercise both opcodes in Legacy, SegWit v0, and tapscript contexts: first/last valid indices, a one-element pool, exact and larger out-of-range indices, negative indices, missing operands, and preserved numeric-encoding errors. Default execution options and successful stack transformations remain unchanged.
Bitcoin Core v30.3 checks the same two-operand minimum and bounds the index against the stack after removing the selector (pinned source,
49faec4f87f5cd19c88db01a82e5c68b087c8227). An independent complete-Taproot regtest comparison with that release rejected exact-poolOP_PICK/OP_ROLLcases through block validation with “Operation not valid with the current stack size”; this executor panicked on the same script and data inputs before this fix.Validation:
ba96bc2, two of the six new tests fail with the reproduced panics.cargo test --locked --all-features -- --skip fields::passes: 11 existing unit tests, 6 regression tests, and 1 doctest.git diff --checkpasses. Tests use a locally generated, ignoredCargo.lock.Related: #18. This patch is based directly on
ba96bc2and does not depend on that resource-limit fix.