Correct Error Code in OP_IF/OP_NOTIF Empty Stack Check #30359
Closed
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.
Description
This pull request addresses an error code inconsistency in the handling of empty stacks for the
OP_IF
andOP_NOTIF
Bitcoin Script opcodes.Currently, if the stack is empty when evaluating these opcodes, the script returns
SCRIPT_ERR_UNBALANCED_CONDITIONAL
, which is misleading. The correct error code for this scenario should beSCRIPT_ERR_INVALID_STACK_OPERATION
, as the issue lies in insufficient stack elements rather than mismatched conditionals.This change modifies the script execution engine to return
SCRIPT_ERR_INVALID_STACK_OPERATION
when an empty stack is encountered duringOP_IF
andOP_NOTIF
processing.Motivation and Improvement
Testing
This change is accompanied by unit tests in the
src/test/
directory that specifically verify the corrected behavior forOP_IF
andOP_NOTIF
with empty stacks.Additional Considerations
While this change might appear minor, its impact on error reporting and debugging is significant. It contributes to a more robust and accurate Bitcoin Script validation process.
Note: Please note that no functional tests have been added as this is a minor fix in the script interpreter's logic, not affecting the overall Bitcoin functionality.
I hope this pull request description is helpful. Please let me know if you have any other questions or need further refinements.