fix(txscript): allocate fresh slice in opcodeInvert to avoid aliasing#777
Merged
ordishs merged 3 commits intoMay 26, 2026
Merged
Conversation
Contributor
|
🤖 Claude Code Review Status: Complete Current Review: Analysis: The change properly fixes the aliasing vulnerability in opcodeInvert. The original implementation used PeekByteArray(0) and mutated bytes in-place, which caused problems when the top stack item shared a backing array with another stack item (e.g., after OP_DUP). Fix verification:
|
Contributor
Benchmark Comparison ReportBaseline: Current: Summary
All benchmark results (sec/op)
Threshold: >10% with p < 0.05 | Generated: 2026-05-22 13:38 UTC |
oskarszoon
approved these changes
May 14, 2026
…ert-immutable # Conflicts: # services/legacy/txscript/opcode_test.go
|
sugh01
approved these changes
May 22, 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.



Closes #4576.
Summary
opcodeInvertusedPeekByteArray(0)and XOR'd bytes in place. AfterOP_DUP(which copies only the slice header), both stack items share the same backing array — soOP_DUP … OP_INVERTmutates the duplicate as well. This diverges from Bitcoin Core / SV Node script semantics.Fix
Pop, allocate a fresh slice, invert into the new slice, push. Stack transformation
a -> ~ais unchanged; the result is now an independent slice with no aliasing.Test plan
go test -race ./services/legacy/txscript/...passes.