Merged
Conversation
|
Collaborator
Author
|
Ok I am going to base the v2 new PR branch changes off this... |
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.



Fix OP_RETURN Script Parsing and Code Quality Improvements
Description of Changes
This PR fixes a critical bug in
Script._build_chunks()where scripts starting with0x00 6a(OP_FALSE OP_RETURN) were incorrectly parsed, and includes several code quality improvements.Bug Fix: OP_RETURN Handling
OP_RETURN(0x6a) were not properly terminating script parsing. WhenOP_RETURNwas encountered, the parser continued to parse subsequent bytes as opcodes instead of treating them as data.OP_RETURNhandling following the TypeScript SDK pattern:OP_IF,OP_NOTIF,OP_VERIF,OP_VERNOTIF/OP_ENDIF)OP_RETURNoutside conditional blocks now terminates parsing and treats all remaining bytes as dataOP_RETURNinside conditional blocks is treated as a normal opcode006a0454657374now correctly parse as 2 chunks instead of 3Code Quality Improvements
Reduced Cognitive Complexity:
_update_conditional_depth()helper method (reduced complexity in_build_chunks())_handle_op_return()helper method_read_push_data()helper method_parse_opcode_token()and_parse_data_token()helpers infrom_asm()methodField Renaming:
self.scripttoself._bytesto avoid confusion with thescriptparameter and improve code clarityTest Improvements:
test_op_return_chunk_parsing()test that verifies the bug fix_create_spend_validator()helper functiontest_r_puzzle()Linked Issues / Tickets
Closes #[issue-number] - Script.chunks iterator mishandles / crashes on "safe" OP_RETURN scripts starting with 0x00 6a
Related to: #135
Testing Procedure
Unit Tests Added
test_op_return_chunk_parsing(): Comprehensive test covering:006a0454657374)Test Results
pytest tests/test_scripts.py -v
Result: 12/12 tests passed